Skip to content

Commit 2cc7f4f

Browse files
committed
renderer: generic texture3D disablement
1 parent 93467b6 commit 2cc7f4f

7 files changed

Lines changed: 59 additions & 13 deletions

File tree

src/engine/renderer/GLUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct GLConfig
128128
bool gpuShader4Available;
129129
bool gpuShader5Available;
130130
bool textureGatherAvailable;
131+
bool texture3DAvailable;
131132
bool mat3x2Available;
132133
bool assumeSmoothstep;
133134
bool incrementalShaderCompilation;

src/engine/renderer/gl_shader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ R"(#if !defined(GENERATED_EXTENSIONS_HEADER)
517517
addExtension( str, addedExtension.available, addedExtension.minGlslVersion, addedExtension.name );
518518
}
519519

520+
if ( glConfig.texture3DAvailable ) {
521+
str += "#define HAVE_texture3D 1\n";
522+
}
523+
520524
str +=
521525
R"(#endif // GENERATED_EXTENSIONS_HEADER
522526

src/engine/renderer/glsl_source/lightMapping_fp.glsl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ IN(smooth) vec3 var_Binormal;
4646
IN(smooth) vec3 var_Normal;
4747

4848
uniform sampler2D u_LightMap;
49-
uniform sampler3D u_LightGrid1;
50-
5149
uniform sampler2D u_DeluxeMap;
52-
uniform sampler3D u_LightGrid2;
50+
51+
#if defined(HAVE_texture3D)
52+
uniform sampler3D u_LightGrid1;
53+
uniform sampler3D u_LightGrid2;
54+
#endif
5355

5456
#if defined(USE_LIGHT_MAPPING) || defined(USE_DELUXE_MAPPING)
5557
IN(smooth) vec2 var_TexLight;
@@ -156,9 +158,15 @@ void main()
156158
#endif
157159
vec3 lightDir;
158160
vec3 ambientColor, lightColor;
159-
ReadLightGrid(texel1, texel2, lightFactor, lightDir, ambientColor, lightColor);
161+
#if HAVE_texture3D
162+
ReadLightGrid(texel1, texel2, lightFactor, lightDir, ambientColor, lightColor);
160163

161-
color.rgb = ambientColor * r_AmbientScale * diffuse.rgb;
164+
color.rgb = ambientColor * r_AmbientScale * diffuse.rgb;
165+
#else
166+
ambientColor = vec3(1.0);
167+
lightColor = vec3(1.0);
168+
color.rgb = diffuse.rgb;
169+
#endif
162170
#endif
163171

164172
#if defined(USE_LIGHT_MAPPING) && defined(USE_DELUXE_MAPPING)

src/engine/renderer/glsl_source/liquid_fp.glsl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ uniform float u_FresnelBias;
4747
uniform mat4 u_ModelMatrix;
4848
uniform mat4 u_UnprojectMatrix;
4949

50-
uniform sampler3D u_LightGrid1;
51-
uniform sampler3D u_LightGrid2;
50+
#if HAVE_texture3D
51+
uniform sampler3D u_LightGrid1;
52+
uniform sampler3D u_LightGrid2;
53+
#endif
54+
5255
uniform vec3 u_LightGridOrigin;
5356
uniform vec3 u_LightGridScale;
5457

@@ -146,8 +149,12 @@ void main()
146149
#endif
147150

148151
// compute light direction in world space
149-
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
150-
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
152+
#if HAVE_texture3D
153+
vec4 texel = texture3D(u_LightGrid2, lightGridPos);
154+
vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
155+
#else
156+
vec3 lightDir = vec3(1.0);
157+
#endif
151158

152159
vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0);
153160

src/engine/renderer/tr_bsp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3470,7 +3470,7 @@ R_LoadLightGrid
34703470
*/
34713471
void R_LoadLightGrid( lump_t *l )
34723472
{
3473-
if ( glConfig.max3DTextureSize == 0 )
3473+
if ( !glConfig.texture3DAvailable )
34743474
{
34753475
Log::Warn( "Grid lighting disabled because of missing 3D texture support." );
34763476

src/engine/renderer/tr_shade.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void EnableAvailableFeatures()
5858
glConfig.realtimeLighting = false;
5959
}
6060

61-
if ( glConfig.max3DTextureSize == 0 )
61+
if ( !glConfig.texture3DAvailable )
6262
{
6363
Log::Warn( "Tiled dynamic light renderer disabled because of missing 3D texture support." );
6464
glConfig.realtimeLighting = false;
@@ -88,7 +88,7 @@ static void EnableAvailableFeatures()
8888

8989
if ( glConfig.colorGrading )
9090
{
91-
if ( glConfig.max3DTextureSize == 0 )
91+
if ( !glConfig.texture3DAvailable )
9292
{
9393
Log::Warn( "Color grading disabled because of missing 3D texture support." );
9494
glConfig.colorGrading = false;

src/engine/sys/sdl_glimp.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ static Cvar::Cvar<bool> r_incrementalShaderCompilation(
6161
"r_incrementalShaderCompilation", "Build separate shader units then link them alltogether at the end",
6262
Cvar::NONE, true );
6363

64+
static Cvar::Cvar<bool> r_useTexture3D(
65+
"r_useTexture3D", "Use texture3D image format and sampler3D GLSL keyword",
66+
Cvar::CHEAT, true );
67+
6468
static Cvar::Cvar<bool> r_useMat3x2(
6569
"r_useMat3x2", "Use mat3x2 GLSL type",
6670
Cvar::NONE, true );
@@ -2111,6 +2115,8 @@ static void GLimp_InitExtensions()
21112115

21122116
// Stubbed or broken drivers may report garbage.
21132117

2118+
glConfig.texture3DAvailable = r_useTexture3D.Get();
2119+
21142120
if ( glConfig.maxTextureUnits < 0 )
21152121
{
21162122
Log::Warn( "Bad GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value: %d", glConfig.maxTextureUnits );
@@ -2135,8 +2141,27 @@ static void GLimp_InitExtensions()
21352141
glConfig.maxCubeMapTextureSize = 0;
21362142
}
21372143

2144+
if ( glConfig.max3DTextureSize > 0 )
2145+
{
2146+
glConfig.texture3DAvailable = true;
2147+
}
2148+
else
2149+
{
2150+
logger.Warn( "Missing 3D texture support because of null max size" );
2151+
}
2152+
21382153
logger.Notice( "...using up to %d texture size.", glConfig.maxTextureSize );
2139-
logger.Notice( "...using up to %d 3D texture size.", glConfig.max3DTextureSize );
2154+
2155+
if ( glConfig.texture3DAvailable )
2156+
{
2157+
logger.Notice( "...using up to %d 3D texture size.", glConfig.max3DTextureSize );
2158+
}
2159+
else
2160+
{
2161+
logger.Notice( "...not using 3D textures." );
2162+
glConfig.max3DTextureSize = 0;
2163+
}
2164+
21402165
logger.Notice( "...using up to %d cube map texture size.", glConfig.maxCubeMapTextureSize );
21412166
logger.Notice( "...using up to %d texture units.", glConfig.maxTextureUnits );
21422167

@@ -2775,6 +2800,7 @@ bool GLimp_Init()
27752800
Cvar::Latch( workaround_glHardware_mthreads_disableTextureBarrier );
27762801

27772802
Cvar::Latch( r_incrementalShaderCompilation );
2803+
Cvar::Latch( r_useTexture3D );
27782804
Cvar::Latch( r_useMat3x2 );
27792805

27802806
/* Enable S3TC on Mesa even if libtxc-dxtn is not available

0 commit comments

Comments
 (0)