Skip to content

Commit caae8f9

Browse files
committed
renderer: generic texture3D disablement
1 parent 6081f1f commit caae8f9

6 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
@@ -516,6 +516,10 @@ R"(#if !defined(GENERATED_EXTENSIONS_HEADER)
516516
addExtension( str, addedExtension.available, addedExtension.minGlslVersion, addedExtension.name );
517517
}
518518

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

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/sys/sdl_glimp.cpp

Lines changed: 29 additions & 3 deletions
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 );
@@ -2115,6 +2119,8 @@ static void GLimp_InitExtensions()
21152119

21162120
// Stubbed or broken drivers may report garbage.
21172121

2122+
glConfig.texture3DAvailable = r_useTexture3D.Get();
2123+
21182124
if ( glConfig.maxTextureUnits < 0 )
21192125
{
21202126
Log::Warn( "Bad GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value: %d", glConfig.maxTextureUnits );
@@ -2139,8 +2145,27 @@ static void GLimp_InitExtensions()
21392145
glConfig.maxCubeMapTextureSize = 0;
21402146
}
21412147

2148+
if ( glConfig.max3DTextureSize > 0 )
2149+
{
2150+
glConfig.texture3DAvailable = true;
2151+
}
2152+
else
2153+
{
2154+
logger.Warn( "Missing 3D texture support because of null max size" );
2155+
}
2156+
21422157
logger.Notice( "...using up to %d texture size.", glConfig.maxTextureSize );
2143-
logger.Notice( "...using up to %d 3D texture size.", glConfig.max3DTextureSize );
2158+
2159+
if ( glConfig.texture3DAvailable )
2160+
{
2161+
logger.Notice( "...using up to %d 3D texture size.", glConfig.max3DTextureSize );
2162+
}
2163+
else
2164+
{
2165+
logger.Notice( "...not using 3D textures." );
2166+
glConfig.max3DTextureSize = 0;
2167+
}
2168+
21442169
logger.Notice( "...using up to %d cube map texture size.", glConfig.maxCubeMapTextureSize );
21452170
logger.Notice( "...using up to %d texture units.", glConfig.maxTextureUnits );
21462171

@@ -2755,7 +2780,7 @@ static void GLimp_EnableAvailableFeatures()
27552780
glConfig.realtimeLighting = false;
27562781
}
27572782

2758-
if ( glConfig.max3DTextureSize == 0 )
2783+
if ( !glConfig.texture3DAvailable )
27592784
{
27602785
Log::Warn( "Tiled dynamic light renderer disabled because of missing 3D texture support." );
27612786
glConfig.realtimeLighting = false;
@@ -2789,7 +2814,7 @@ static void GLimp_EnableAvailableFeatures()
27892814

27902815
if ( glConfig.colorGrading )
27912816
{
2792-
if ( glConfig.max3DTextureSize == 0 )
2817+
if ( !glConfig.texture3DAvailable )
27932818
{
27942819
Log::Warn( "Color grading disabled because of missing 3D texture support." );
27952820
glConfig.colorGrading = false;
@@ -2966,6 +2991,7 @@ bool GLimp_Init()
29662991
Cvar::Latch( workaround_glHardware_mthreads_disableTextureBarrier );
29672992

29682993
Cvar::Latch( r_incrementalShaderCompilation );
2994+
Cvar::Latch( r_useTexture3D );
29692995
Cvar::Latch( r_useMat3x2 );
29702996

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

0 commit comments

Comments
 (0)