Pyrogenesis
13997
|
#include "precompiled.h"
#include "ogl_tex.h"
#include <cstdio>
#include "lib/app_hooks.h"
#include "lib/ogl.h"
#include "lib/bits.h"
#include "lib/sysdep/gfx.h"
#include "lib/tex/tex.h"
#include "lib/res/h_mgr.h"
#include "lib/fnv_hash.h"
Go to the source code of this file.
Classes | |
struct | OglTexState |
struct | OglTex |
struct | UploadParams |
Enumerations | |
enum | OglTexFlags { OT_IS_UPLOADED = 1, OT_TEX_VALID = 2, OT_NEED_AUTO_UPLOAD = 4, OT_ALL_FLAGS = OT_IS_UPLOADED|OT_TEX_VALID|OT_NEED_AUTO_UPLOAD } |
Functions | |
static bool | filter_valid (GLint filter) |
static bool | wrap_valid (GLint wrap) |
static bool | are_mipmaps_needed (size_t width, size_t height, GLint filter) |
static bool | fmt_is_s3tc (GLenum fmt) |
static GLint | choose_fmt (size_t bpp, size_t flags) |
static bool | q_flags_valid (int q_flags) |
void | ogl_tex_set_defaults (int q_flags, GLint filter) |
Change default settings - these affect performance vs. More... | |
static GLint | choose_int_fmt (GLenum fmt, int q_flags) |
static void | state_set_to_defaults (OglTexState *ots) |
static void | state_latch (OglTexState *ots) |
H_TYPE_DEFINE (OglTex) | |
static void | OglTex_init (OglTex *ot, va_list args) |
static void | OglTex_dtor (OglTex *ot) |
static Status | OglTex_reload (OglTex *ot, const PIVFS &vfs, const VfsPath &pathname, Handle h) |
static Status | OglTex_validate (const OglTex *ot) |
static Status | OglTex_to_string (const OglTex *ot, wchar_t *buf) |
Handle | ogl_tex_load (const PIVFS &vfs, const VfsPath &pathname, size_t flags) |
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) |
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... | |
static void | warn_if_uploaded (Handle ht, const OglTex *ot) |
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... | |
static void | detect_gl_upload_caps () |
static Status | get_mipmaps (Tex *t, GLint filter, int q_flags, int *plevels_to_skip) |
static void | upload_level (size_t level, size_t level_w, size_t level_h, const u8 *RESTRICT level_data, size_t level_data_size, void *RESTRICT cbData) |
static void | upload_compressed_level (size_t level, size_t level_w, size_t level_h, const u8 *RESTRICT level_data, size_t level_data_size, void *RESTRICT cbData) |
static void | upload_impl (Tex *t, GLenum fmt, GLint int_fmt, int levels_to_skip) |
Status | ogl_tex_upload (const Handle ht, GLenum fmt_ovr, int q_flags_ovr, GLint int_fmt_ovr) |
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_average_colour (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) |
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 transforms) |
(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... | |
Variables | |
static GLint | default_filter = GL_LINEAR |
static int | default_q_flags = OGL_TEX_FULL_QUALITY |
static int | have_auto_mipmap_gen = -1 |
static int | have_s3tc = -1 |
static int | have_anistropy = -1 |
enum OglTexFlags |
Enumerator | |
---|---|
OT_IS_UPLOADED | |
OT_TEX_VALID | |
OT_NEED_AUTO_UPLOAD | |
OT_ALL_FLAGS |
Definition at line 386 of file ogl_tex.cpp.
|
static |
Definition at line 82 of file ogl_tex.cpp.
|
static |
Definition at line 120 of file ogl_tex.cpp.
|
static |
Definition at line 223 of file ogl_tex.cpp.
|
static |
Definition at line 737 of file ogl_tex.cpp.
|
static |
Definition at line 47 of file ogl_tex.cpp.
|
static |
Definition at line 102 of file ogl_tex.cpp.
Definition at line 790 of file ogl_tex.cpp.
H_TYPE_DEFINE | ( | OglTex | ) |
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:
Definition at line 1054 of file ogl_tex.cpp.
Find and return an existing texture object, if it has already been loaded and is still in memory.
pathname | fn VFS filename of texture. |
Definition at line 551 of file ogl_tex.cpp.
Release this texture reference.
When the count reaches zero, all of its associated resources are freed and further use made impossible.
ht | Texture handle. |
Definition at line 586 of file ogl_tex.cpp.
Retrieve ARGB value of 1x1 mipmap level of the texture, i.e.
the average colour 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).
Definition at line 1030 of file ogl_tex.cpp.
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).
Definition at line 1021 of file ogl_tex.cpp.
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) |
Definition at line 999 of file ogl_tex.cpp.
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 |
Definition at line 982 of file ogl_tex.cpp.
Return the GL handle of the loaded texture in *id, or 0 on failure.
Definition at line 1085 of file ogl_tex.cpp.
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.
Definition at line 1123 of file ogl_tex.cpp.
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.
Definition at line 1114 of file ogl_tex.cpp.
Load and return a handle to the texture.
vfs | |
pathname | |
flags | h_alloc flags. |
Definition at line 542 of file ogl_tex.cpp.
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. |
Definition at line 711 of file ogl_tex.cpp.
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).
Definition at line 679 of file ogl_tex.cpp.
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. |
Definition at line 206 of file ogl_tex.cpp.
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).
Definition at line 638 of file ogl_tex.cpp.
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).
Definition at line 657 of file ogl_tex.cpp.
(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).
Definition at line 1095 of file ogl_tex.cpp.
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).
Definition at line 1105 of file ogl_tex.cpp.
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:
Definition at line 912 of file ogl_tex.cpp.
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.
Definition at line 570 of file ogl_tex.cpp.
|
static |
Definition at line 446 of file ogl_tex.cpp.
|
static |
Definition at line 431 of file ogl_tex.cpp.
|
static |
Definition at line 461 of file ogl_tex.cpp.
Definition at line 533 of file ogl_tex.cpp.
Definition at line 487 of file ogl_tex.cpp.
|
static |
Definition at line 186 of file ogl_tex.cpp.
|
static |
Definition at line 328 of file ogl_tex.cpp.
|
static |
Definition at line 317 of file ogl_tex.cpp.
|
static |
Definition at line 878 of file ogl_tex.cpp.
|
static |
Definition at line 888 of file ogl_tex.cpp.
|
static |
Definition at line 872 of file ogl_tex.cpp.
Definition at line 605 of file ogl_tex.cpp.
|
static |
Definition at line 64 of file ogl_tex.cpp.
|
static |
Definition at line 183 of file ogl_tex.cpp.
|
static |
Definition at line 184 of file ogl_tex.cpp.
|
static |
Definition at line 707 of file ogl_tex.cpp.
|
static |
Definition at line 705 of file ogl_tex.cpp.
|
static |
Definition at line 706 of file ogl_tex.cpp.