Skip to content

Commit

Permalink
rendergl: Check for GL 4.6 anisotropic TF extension
Browse files Browse the repository at this point in the history
OpenGL 4.6 has brought an extension for anisotropic filtering that can work
alongside our existing GL_EXT_texture_filter_anisotropic code: check for
this new extension and, if supported, make use of it.

Link: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_filter_anisotropic.txt
  • Loading branch information
voidanix committed Jan 6, 2023
1 parent a43d7db commit c18e4b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/engine/rendergl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,14 @@ void gl_checkextensions()
if(glversion < 300 && dbgexts) conoutf("\frUsing GL_ARB_texture_compression_rgtc extension.");
}

if(hasext("GL_EXT_texture_filter_anisotropic"))
{
if ((glversion >= 460 || hasext("GL_ARB_texture_filter_anisotropic")) ||
hasext("GL_EXT_texture_filter_anisotropic")) {
GLint val;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &val);
hwmaxanisotropy = val;
hasAF = true;
if(dbgexts) conoutf("\frUsing GL_EXT_texture_filter_anisotropic extension.");
if (dbgexts)
conoutf("\frUsing GL_*_texture_filter_anisotropic extension.");
}

if(glversion >= 300 || hasext("GL_EXT_gpu_shader4"))
Expand Down
3 changes: 2 additions & 1 deletion src/engine/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ void setuptexparameters(int tnum, void *pixels, int clamp, int filter, GLenum fo
glBindTexture(target, tnum);
glTexParameteri(target, GL_TEXTURE_WRAP_S, clamp&1 ? GL_CLAMP_TO_EDGE : (clamp&0x100 ? GL_MIRRORED_REPEAT : GL_REPEAT));
if(target!=GL_TEXTURE_1D) glTexParameteri(target, GL_TEXTURE_WRAP_T, clamp&2 ? GL_CLAMP_TO_EDGE : (clamp&0x200 ? GL_MIRRORED_REPEAT : GL_REPEAT));
if(target==GL_TEXTURE_2D && hasAF && min(anisotropy, hwmaxanisotropy) > 0 && filter > 1) glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, min(anisotropy, hwmaxanisotropy));
if (target == GL_TEXTURE_2D && hasAF && min(anisotropy, hwmaxanisotropy) > 0 && filter > 1)
glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY, min(anisotropy, hwmaxanisotropy));
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter && bilinear ? GL_LINEAR : GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
filter > 1 ?
Expand Down
8 changes: 4 additions & 4 deletions src/shared/glexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ extern PFNGLDRAWBUFFERSPROC glDrawBuffers_;
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
#endif

#ifndef GL_EXT_texture_filter_anisotropic
#define GL_EXT_texture_filter_anisotropic 1
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
#ifndef GL_ARB_texture_filter_anisotropic
#define GL_ARB_texture_filter_anisotropic 1
#define GL_TEXTURE_MAX_ANISOTROPY 0x84FE
#define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
#endif

#ifndef GL_EXT_texture_compression_s3tc
Expand Down

0 comments on commit c18e4b6

Please sign in to comment.