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 70c0f8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ static inline bool pvsoccluded(const ivec &bborigin, int size)
}

// rendergl
extern bool hasVAO, hasFBO, hasAFBO, hasDS, hasTF, hasTRG, hasTSW, hasS3TC, hasFXT1, hasLATC, hasRGTC, hasAF, hasFBB, hasUBO, hasMBR;
extern int glversion, glslversion, glcompat;
extern bool hasVAO, hasFBO, hasAFBO, hasDS, hasTF, hasTRG, hasTSW, hasS3TC, hasFXT1, hasLATC, hasRGTC, hasFBB, hasUBO, hasMBR;
extern int glversion, glslversion, glcompat, hasAF;
extern char *gfxvendor, *gfxrenderer, *gfxversion;

enum { DRAWTEX_NONE = 0, DRAWTEX_ENVMAP, DRAWTEX_MINIMAP, DRAWTEX_MODELPREVIEW };
Expand Down
21 changes: 15 additions & 6 deletions src/engine/rendergl.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// rendergl.cpp: core opengl rendering stuff
#include "engine.h"

bool hasVAO = false, hasFBO = false, hasAFBO = false, hasDS = false, hasTF = false, hasTRG = false, hasTSW = false, hasS3TC = false, hasFXT1 = false, hasLATC = false, hasRGTC = false, hasAF = false, hasFBB = false, hasUBO = false, hasMBR = false;
bool hasVAO = false, hasFBO = false, hasAFBO = false, hasDS = false, hasTF = false, hasTRG = false, hasTSW = false, hasS3TC = false, hasFXT1 = false, hasLATC = false, hasRGTC = false, hasFBB = false, hasUBO = false, hasMBR = false;
int hasAF = 0;

VAR(IDF_READONLY, glversion, 1, 0, 0);
VAR(IDF_READONLY, glslversion, 1, 0, 0);
Expand Down Expand Up @@ -562,13 +563,21 @@ 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);

if (hasext("GL_ARB_texture_filter_anisotropic")) {
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &val);
hasAF = 1;
} else {
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
hasAF = 2;
}

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
7 changes: 6 additions & 1 deletion src/engine/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,12 @@ 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 && min(anisotropy, hwmaxanisotropy) > 0 && filter > 1) {
if (hasAF == 1)
glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY, min(anisotropy, hwmaxanisotropy));
else if (hasAF == 2)
glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 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

0 comments on commit 70c0f8f

Please sign in to comment.