28 #include "precompiled.h"
53 case GL_NEAREST_MIPMAP_NEAREST:
54 case GL_LINEAR_MIPMAP_NEAREST:
55 case GL_NEAREST_MIPMAP_LINEAR:
56 case GL_LINEAR_MIPMAP_LINEAR:
70 case GL_CLAMP_TO_BORDER:
72 case GL_CLAMP_TO_EDGE:
74 case GL_MIRRORED_REPEAT:
91 case GL_NEAREST_MIPMAP_NEAREST:
92 case GL_LINEAR_MIPMAP_NEAREST:
93 case GL_NEAREST_MIPMAP_LINEAR:
94 case GL_LINEAR_MIPMAP_LINEAR:
106 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
107 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
109 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
110 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
122 const bool alpha = (flags &
TEX_ALPHA) != 0;
123 const bool bgr = (flags &
TEX_BGR ) != 0;
124 const bool grey = (flags &
TEX_GREY ) != 0;
125 const size_t dxt = flags &
TEX_DXT;
133 return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
135 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
138 return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
140 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
155 return GL_LUMINANCE_ALPHA;
163 return bgr? GL_BGR : GL_RGB;
169 return bgr? GL_BGRA_EXT : GL_RGBA;
190 if((q_flags & ~bits) != 0)
248 return half_bpp? GL_LUMINANCE4 : GL_LUMINANCE8;
250 return half_bpp? GL_INTENSITY4 : GL_INTENSITY8;
252 return half_bpp? GL_ALPHA4 : GL_ALPHA8;
255 case GL_LUMINANCE_ALPHA:
256 return half_bpp? GL_LUMINANCE4_ALPHA4 : GL_LUMINANCE8_ALPHA8;
261 return half_bpp? GL_RGB4 : GL_RGB8;
266 return half_bpp? GL_RGBA4 : GL_RGBA8;
271 swprintf_s(buf,
ARRAY_SIZE(buf), L
"choose_int_fmt: fmt 0x%x isn't covered! please add it", fmt);
275 return half_bpp? GL_RGB4 : GL_RGB8;
281 #endif // #if CONFIG2_GLES
331 const GLint filter = ots->
filter;
332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
333 const GLint mag_filter = (filter == GL_NEAREST)? GL_NEAREST : GL_LINEAR;
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
337 const GLint wrap_s = ots->
wrap_s;
338 const GLint wrap_t = ots->
wrap_t;
339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
345 if((wrap_s != GL_CLAMP && wrap_s != GL_REPEAT) || (wrap_t != GL_CLAMP && wrap_t != GL_REPEAT))
353 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
433 Tex* wrapped_tex = va_arg(args,
Tex*);
436 ot->
t = *wrapped_tex;
456 glDeleteTextures(1, &ot->
id);
471 shared_ptr<u8> file;
size_t fileSize;
477 glGenTextures(1, &ot->
id);
544 Tex* wrapped_tex = 0;
545 return h_alloc(H_OglTex, vfs, pathname, flags, wrapped_tex);
554 return h_find(H_OglTex, key);
580 return h_alloc(H_OglTex, vfs, pathname, flags, t);
588 return h_free(ht, H_OglTex);
645 if(ot->state.filter != filter)
648 ot->state.filter = filter;
667 if(ot->state.wrap_s != wrap_s || ot->state.wrap_t != wrap_t)
670 ot->state.wrap_s = wrap_s;
671 ot->state.wrap_t = wrap_t;
683 if(anisotropy < 1.0f)
686 if(ot->state.anisotropy != anisotropy)
689 ot->state.anisotropy = anisotropy;
777 if(cardName == L
"S3 SuperSavage/IXC 1014")
810 *plevels_to_skip = 0;
819 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
834 *plevels_to_skip = 0;
838 if(*plevels_to_skip == 0)
843 GLint w = (GLint)t->
w, h = (GLint)t->
h;
846 (*plevels_to_skip)++;
857 (*plevels_to_skip)++;
875 glTexImage2D(GL_TEXTURE_2D, (GLint)level, up->
int_fmt, (GLsizei)level_w, (GLsizei)level_h, 0, up->
fmt, GL_UNSIGNED_BYTE, level_data);
881 pglCompressedTexImage2DARB(GL_TEXTURE_2D, (GLint)level, up->
fmt, (GLsizei)level_w, (GLsizei)level_h, 0, (GLsizei)level_data_size, level_data);
890 const GLsizei w = (GLsizei)t->
w;
891 const GLsizei h = (GLsizei)t->
h;
892 const size_t bpp = t->
bpp;
934 if(fmt_ovr) ot->fmt = fmt_ovr;
935 if(q_flags_ovr) ot->q_flags = q_flags_ovr;
937 if(int_fmt_ovr) ot->int_fmt = int_fmt_ovr;
946 if(
get_mipmaps(t, ot->state.filter, ot->q_flags, &levels_to_skip) < 0)
948 ot->state.filter = GL_LINEAR;
952 upload_impl(t, ot->fmt, ot->int_fmt, levels_to_skip);
1004 *flags = ot->t.flags;
1058 pglActiveTextureARB((
int)(GL_TEXTURE0+unit));
1063 glDisable(GL_TEXTURE_2D);
1079 glEnable(GL_TEXTURE_2D);
1081 glBindTexture(GL_TEXTURE_2D, ot->id);
static bool fmt_is_s3tc(GLenum fmt)
Status ogl_tex_set_anisotropy(Handle ht, GLfloat anisotropy)
Override default maximum anisotropic filtering for this texture.
Status h_free(Handle &h, H_Type type)
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...
static int have_anistropy
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)
void ogl_tex_override(OglTexOverrides what, OglTexAllow allow)
Override the default decision and force/disallow use of the given feature.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
const int TEX_BASE_LEVEL_ONLY
special value for levels_to_skip: the callback will only be called for the base mipmap level (i...
Status ogl_tex_transform(Handle ht, size_t transforms)
(partially) Transform pixel format of the texture.
static void OglTex_dtor(OglTex *ot)
Status tex_transform_to(Tex *t, size_t new_flags)
Change <t>'s pixel format (2nd version) (note: this is equivalent to tex_transform(t, t->flags^new_flags).
static Status OglTex_validate(const OglTex *ot)
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)
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. ...
Status ogl_tex_free(Handle &ht)
Release this texture reference.
static bool filter_valid(GLint filter)
flags & TEX_DXT is a field indicating compression.
indicates the image contains an alpha channel.
indicates the image is 8bpp greyscale.
static bool wrap_valid(GLint wrap)
#define AH_IS_DEFINED(name)
bool ogl_SquelchError(GLenum err_to_ignore)
ignore and reset the specified OpenGL error.
indicates B and R pixel components are exchanged.
void ah_override_gl_upload_caps()
override default decision on using OpenGL extensions relating to texture upload.
int swprintf_s(wchar_t *buf, size_t max_chars, const wchar_t *fmt,...) WPRINTF_ARGS(3)
static int have_auto_mipmap_gen
Handle h_alloc(H_Type type, const PIVFS &vfs, const VfsPath &pathname, size_t flags,...)
u32 tex_get_average_colour(const Tex *t)
return the ARGB value of the 1x1 mipmap level of the texture.
Status ogl_tex_transform_to(Handle ht, size_t new_flags)
Transform pixel format of the texture.
static void detect_gl_upload_caps()
Status tex_validate(const Tex *t)
Is the texture object valid and self-consistent?
#define H_DEREF(h, type, var)
Status ogl_tex_bind(Handle ht, size_t unit)
Bind texture to the specified unit in preparation for using it in rendering.
#define H_TYPE_DEFINE(type)
bool ogl_tex_has_s3tc()
Return whether native S3TC texture compression support is available.
intptr_t h_get_refcnt(Handle h)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
static void state_latch(OglTexState *ots)
Status ogl_tex_set_wrap(Handle ht, GLint wrap_s, GLint wrap_t)
Override default wrap mode (GL_REPEAT) for this texture.
const String & string() const
#define ONCE(ONCE_code__)
execute the code passed as a parameter only the first time this is reached.
#define UNREACHABLE
"unreachable code" helpers
u8 * tex_get_data(const Tex *t)
rationale: since Tex is a struct, its fields are accessible to callers.
emphatically require full quality for this texture.
static void OglTex_init(OglTex *ot, va_list args)
const Status INVALID_PARAM
static int default_q_flags
Handle h_find(H_Type type, uintptr_t key)
i64 Status
Error handling system.
i64 Handle
`handle' representing a reference to a resource (sound, texture, etc.)
bool ogl_tex_has_anisotropy()
Return whether anisotropic filtering support is available.
T bits(T num, size_t lo_idx, size_t hi_idx)
extract the value of bits hi_idx:lo_idx within num
stores all data describing an image.
static GLint choose_fmt(size_t bpp, size_t flags)
static bool q_flags_valid(int q_flags)
Handle ogl_tex_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load and return a handle to the texture.
store the texture at half its original resolution.
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
u32 fnv_hash(const void *buf, size_t len)
rationale: this algorithm was chosen because it delivers 'good' results for string data and is relati...
we need a special value for DXT1a to avoid having to consider flags & TEX_ALPHA to determine S3TC typ...
static void upload_impl(Tex *t, GLenum fmt, GLint int_fmt, int levels_to_skip)
bool ogl_HaveExtension(const char *ext)
check if an extension is supported by the OpenGL implementation.
void tex_util_foreach_mipmap(size_t w, size_t h, size_t bpp, const u8 *pixels, int levels_to_skip, size_t data_padding, MipmapCB cb, void *RESTRICT cbData)
for a series of mipmaps stored from base to highest, call back for each level.
store the texture at half the normal bit depth (4 bits per pixel component, as opposed to 8)...
static Status OglTex_reload(OglTex *ot, const PIVFS &vfs, const VfsPath &pathname, Handle h)
Status ogl_tex_get_texture_id(Handle ht, GLuint *id)
Return the GL handle of the loaded texture in *id, or 0 on failure.
static bool are_mipmaps_needed(size_t width, size_t height, GLint filter)
Status ogl_tex_set_filter(Handle ht, GLint filter)
Override default filter (see ogl_tex_set_defaults) for this texture.
Status ogl_tex_get_data(Handle ht, u8 **p)
Retrieve pixel data of the texture.
Status ogl_tex_get_format(Handle ht, size_t *flags, GLenum *fmt)
Retrieve pixel format of the texture.
static void warn_if_uploaded(Handle ht, const OglTex *ot)
static GLint default_filter
#define DEBUG_DISPLAY_ERROR(description)
#define WARN_RETURN(status)
void ogl_WarnIfError()
raise a warning (break into the debugger) if an OpenGL error is pending.
void ogl_tex_set_defaults(int q_flags, GLint filter)
Change default settings - these affect performance vs.
const size_t H_STRING_LEN
static Status get_mipmaps(Tex *t, GLint filter, int q_flags, int *plevels_to_skip)
static GLint choose_int_fmt(GLenum fmt, int q_flags)
Status tex_transform(Tex *t, size_t transforms)
Change <t>'s pixel format.
static void state_set_to_defaults(OglTexState *ots)
static Status OglTex_to_string(const OglTex *ot, wchar_t *buf)
size_t flags
see TexFlags and "Format Conversion" in docs.
Status tex_decode(const shared_ptr< u8 > &data, size_t dataSize, Tex *t)
decode an in-memory texture file into texture object.
void tex_free(Tex *t)
free all resources associated with the image and make further use of it impossible.
Status ogl_tex_get_average_colour(Handle ht, u32 *p)
Retrieve ARGB value of 1x1 mipmap level of the texture, i.e.
Status ogl_tex_upload(const Handle ht, GLenum fmt_ovr, int q_flags_ovr, GLint int_fmt_ovr)
Upload texture to OpenGL.
#define RETURN_STATUS_IF_ERR(expression)
Status ogl_tex_get_size(Handle ht, size_t *w, size_t *h, size_t *bpp)
Retrieve dimensions and bit depth of the texture.
const char * ogl_HaveExtensions(int dummy,...)
check if a list of extensions are all supported (as determined by ogl_HaveExtension).