Pyrogenesis
trunk
|
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs.h"
#include "lib/ogl.h"
#include "lib/tex/tex.h"
Go to the source code of this file.
Enumerations | |
enum | OglTexQualityFlags { OGL_TEX_FULL_QUALITY = 0x20, OGL_TEX_HALF_BPP = 0x10, OGL_TEX_HALF_RES = 0x01 } |
Quality flags for texture uploads. More... | |
enum | OglTexOverrides { OGL_TEX_S3TC, OGL_TEX_AUTO_MIPMAP_GEN, OGL_TEX_ANISOTROPY } |
enum | OglTexAllow { OGL_TEX_DISABLE, OGL_TEX_ENABLE } |
Functions | |
void | ogl_tex_set_defaults (int q_flags, GLint filter) |
Change default settings - these affect performance vs. More... | |
Handle | ogl_tex_load (const PIVFS &vfs, const VfsPath &pathname, size_t flags=0) |
Load and return a handle to the texture. More... | |
Handle | ogl_tex_find (const VfsPath &pathname) |
Find and return an existing texture object, if it has already been loaded and is still in memory. More... | |
Handle | ogl_tex_wrap (Tex *t, const PIVFS &vfs, const VfsPath &pathname, size_t flags=0) |
Make the Tex object ready for use as an OpenGL texture and return a handle to it. More... | |
Status | ogl_tex_free (Handle &ht) |
Release this texture reference. More... | |
Status | ogl_tex_set_filter (Handle ht, GLint filter) |
Override default filter (see ogl_tex_set_defaults) for this texture. More... | |
Status | ogl_tex_set_wrap (Handle ht, GLint wrap_s, GLint wrap_t) |
Override default wrap mode (GL_REPEAT) for this texture. More... | |
Status | ogl_tex_set_anisotropy (Handle ht, GLfloat anisotropy) |
Override default maximum anisotropic filtering for this texture. More... | |
void | ogl_tex_override (OglTexOverrides what, OglTexAllow allow) |
Override the default decision and force/disallow use of the given feature. More... | |
Status | ogl_tex_upload (const Handle ht, GLenum fmt_ovr=0, int q_flags_ovr=0, GLint int_fmt_ovr=0) |
Upload texture to OpenGL. More... | |
Status | ogl_tex_get_size (Handle ht, size_t *w, size_t *h, size_t *bpp) |
Retrieve dimensions and bit depth of the texture. More... | |
Status | ogl_tex_get_format (Handle ht, size_t *flags, GLenum *fmt) |
Retrieve pixel format of the texture. More... | |
Status | ogl_tex_get_data (Handle ht, u8 **p) |
Retrieve pixel data of the texture. More... | |
Status | ogl_tex_get_uploaded_size (Handle ht, size_t *size) |
Retrieve number of bytes uploaded for the texture, including mipmaps. More... | |
Status | ogl_tex_get_average_color (Handle ht, u32 *p) |
Retrieve ARGB value of 1x1 mipmap level of the texture, i.e. More... | |
Status | ogl_tex_bind (Handle ht, size_t unit=0) |
Bind texture to the specified unit in preparation for using it in rendering. More... | |
Status | ogl_tex_get_texture_id (Handle ht, GLuint *id) |
Return the GL handle of the loaded texture in *id, or 0 on failure. More... | |
Status | ogl_tex_transform (Handle ht, size_t flags) |
(partially) Transform pixel format of the texture. More... | |
Status | ogl_tex_transform_to (Handle ht, size_t new_flags) |
Transform pixel format of the texture. More... | |
bool | ogl_tex_has_s3tc () |
Return whether native S3TC texture compression support is available. More... | |
bool | ogl_tex_has_anisotropy () |
Return whether anisotropic filtering support is available. More... | |
enum OglTexAllow |
enum OglTexOverrides |
enum OglTexQualityFlags |
Quality flags for texture uploads.
Specify any of them to override certain aspects of the default.
Bind texture to the specified unit in preparation for using it in rendering.
ht | Texture handle. If 0, texturing is disabled on this unit. |
unit | Texture Mapping Unit number, typically 0 for the first. |
Side Effects:
Notes:
Find and return an existing texture object, if it has already been loaded and is still in memory.
pathname | fn VFS filename of texture. |
Release this texture reference.
When the count reaches zero, all of its associated resources are freed and further use made impossible.
ht | Texture handle. |
Retrieve ARGB value of 1x1 mipmap level of the texture, i.e.
the average color of the whole texture.
ht | Texture handle |
p | will be filled with ARGB value (or 0 if texture does not have mipmaps) |
Must be called before uploading (raises a warning if called afterwards).
Retrieve pixel data of the texture.
ht | Texture handle |
p | will be filled with pointer to texels. |
Note: this memory is freed after a successful ogl_tex_upload for this texture. After that, the pointer we retrieve is NULL but the function doesn't fail (negative return value) by design. If you still need to get at the data, add a reference before uploading it or read directly from OpenGL (discouraged).
Retrieve pixel format of the texture.
ht | Texture handle |
flags | optional; will be filled with TexFlags |
fmt | optional; will be filled with GL format (it is determined during ogl_tex_upload and 0 before then) |
Retrieve dimensions and bit depth of the texture.
ht | Texture handle |
w | optional; will be filled with width |
h | optional; will be filled with height |
bpp | optional; will be filled with bits per pixel |
Return the GL handle of the loaded texture in *id, or 0 on failure.
Retrieve number of bytes uploaded for the texture, including mipmaps.
size will be 0 if the texture has not been uploaded yet.
ht | Texture handle |
size | Will be filled with size in bytes |
bool ogl_tex_has_anisotropy | ( | ) |
Return whether anisotropic filtering support is available.
(The anisotropy might still be disabled or overridden by the driver configuration.)
ogl_tex_upload must be called at least once before this.
bool ogl_tex_has_s3tc | ( | ) |
Return whether native S3TC texture compression support is available.
If not, textures will be decompressed automatically, hurting performance.
ogl_tex_upload must be called at least once before this.
Load and return a handle to the texture.
vfs | |
pathname | |
flags | h_alloc flags. |
void ogl_tex_override | ( | OglTexOverrides | what, |
OglTexAllow | allow | ||
) |
Override the default decision and force/disallow use of the given feature.
Typically called from ah_override_gl_upload_caps.
what | Feature to influence. |
allow | Disable/enable flag. |
Override default maximum anisotropic filtering for this texture.
ht | Texture handle |
anisotropy | Anisotropy value (must not be less than 1.0; should usually be a power of two) |
Must be called before uploading (raises a warning if called afterwards).
void ogl_tex_set_defaults | ( | int | q_flags, |
GLint | filter | ||
) |
Change default settings - these affect performance vs.
quality. May be overridden for individual textures via parameter to ogl_tex_upload or ogl_tex_set_filter, respectively.
q_flags | quality flags. Pass 0 to keep the current setting (initially OGL_TEX_FULL_QUALITY), or any combination of OglTexQualityFlags. |
filter | mag/minification filter. Pass 0 to keep the current setting (initially GL_LINEAR), or any valid OpenGL minification filter. |
Override default filter (see ogl_tex_set_defaults) for this texture.
ht | Texture handle |
filter | OpenGL minification and magnification filter (rationale: see OglTexState) |
Must be called before uploading (raises a warning if called afterwards).
Override default wrap mode (GL_REPEAT) for this texture.
ht | Texture handle |
wrap_s | OpenGL wrap mode for S coordinates |
wrap_t | OpenGL wrap mode for T coordinates |
Must be called before uploading (raises a warning if called afterwards).
(partially) Transform pixel format of the texture.
ht | Texture handle. |
flags | the TexFlags that are to be changed. |
Must be called before uploading (raises a warning if called afterwards).
Transform pixel format of the texture.
ht | Texture handle. |
new_flags | Flags desired new TexFlags indicating pixel format. |
Must be called before uploading (raises a warning if called afterwards).
Note: this is equivalent to ogl_tex_transform(ht, ht_flags^new_flags).
Status ogl_tex_upload | ( | const Handle | ht, |
GLenum | fmt_ovr = 0 , |
||
int | q_flags_ovr = 0 , |
||
GLint | int_fmt_ovr = 0 |
||
) |
Upload texture to OpenGL.
ht | Texture handle |
fmt_ovr | optional override for OpenGL format (e.g. GL_RGB), which is decided from bpp / Tex flags |
q_flags_ovr | optional override for global default OglTexQualityFlags |
int_fmt_ovr | optional override for OpenGL internal format (e.g. GL_RGB8), which is decided from fmt / q_flags. |
Side Effects:
Make the Tex object ready for use as an OpenGL texture and return a handle to it.
This will be as if its contents had been loaded by ogl_tex_load.
t | Texture object. |
vfs | |
pathname | filename or description of texture. not strictly needed, but would allow h_filename to return meaningful info for purposes of debugging. |
flags |
note: because we cannot guarantee that callers will pass distinct "filenames", caching is disabled for the created object. this avoids mistakenly reusing previous objects that share the same comment.
we need only add bookkeeping information and "wrap" it in a resource object (accessed via Handle), hence the name.