Skip to content

Commit 9d3743e

Browse files
committed
fixup: template the Uint/Float packers so
1 parent b4df4fe commit 9d3743e

File tree

8 files changed

+139
-77
lines changed

8 files changed

+139
-77
lines changed

src/engine/renderer/Material.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo
153153
alphaGen_t alphaGen = SetAlphaGen( pStage );
154154

155155
const bool styleLightMap = pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP;
156-
gl_genericShaderMaterial->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, mayUseVertexOverbright, styleLightMap );
156+
gl_genericShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, mayUseVertexOverbright, styleLightMap );
157157

158158
Tess_ComputeColor( pStage );
159-
gl_genericShaderMaterial->SetUniform_Color( tess.svars.color );
159+
gl_genericShaderMaterial->SetUniform_Color_Uint( tess.svars.color );
160160

161161
bool hasDepthFade = pStage->hasDepthFade;
162162
if ( hasDepthFade ) {
@@ -183,10 +183,10 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage,
183183
}
184184

185185
// u_ColorModulate
186-
gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen( rgbGen, alphaGen, false, !fullbright );
186+
gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, false, !fullbright );
187187

188188
// u_Color
189-
gl_lightMappingShaderMaterial->SetUniform_Color( tess.svars.color );
189+
gl_lightMappingShaderMaterial->SetUniform_Color_Uint( tess.svars.color );
190190

191191
// u_AlphaThreshold
192192
gl_lightMappingShaderMaterial->SetUniform_AlphaTest( pStage->stateBits );
@@ -1059,7 +1059,7 @@ void BindShaderFog( Material* material ) {
10591059
gl_fogQuake3ShaderMaterial->SetUniform_FogDepthVector( fogDepthVector );
10601060
gl_fogQuake3ShaderMaterial->SetUniform_FogEyeT( eyeT );
10611061

1062-
gl_fogQuake3ShaderMaterial->SetUniform_ColorGlobal( fog->color );
1062+
gl_fogQuake3ShaderMaterial->SetUniform_ColorGlobal_Uint( fog->color );
10631063

10641064
gl_fogQuake3ShaderMaterial->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
10651065
gl_fogQuake3ShaderMaterial->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[glState.stackIndex] );

src/engine/renderer/gl_shader.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,9 @@ GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
22662266
u_ModelMatrix( this ),
22672267
u_ModelViewProjectionMatrix( this ),
22682268
u_ColorModulateColorGen_Float( this ),
2269+
u_ColorModulateColorGen_Uint( this ),
22692270
u_Color_Float( this ),
2271+
u_Color_Uint( this ),
22702272
u_Bones( this ),
22712273
u_VertexInterpolation( this ),
22722274
u_DepthScale( this ),
@@ -2333,7 +2335,9 @@ GLShader_lightMapping::GLShader_lightMapping( GLShaderManager *manager ) :
23332335
u_TextureMatrix( this ),
23342336
u_SpecularExponent( this ),
23352337
u_ColorModulateColorGen_Float( this ),
2338+
u_ColorModulateColorGen_Uint( this ),
23362339
u_Color_Float( this ),
2340+
u_Color_Uint( this ),
23372341
u_AlphaThreshold( this ),
23382342
u_ViewOrigin( this ),
23392343
u_ModelMatrix( this ),
@@ -2460,7 +2464,9 @@ GLShader_forwardLighting_omniXYZ::GLShader_forwardLighting_omniXYZ( GLShaderMana
24602464
u_SpecularExponent( this ),
24612465
u_AlphaThreshold( this ),
24622466
u_ColorModulateColorGen_Float( this ),
2467+
u_ColorModulateColorGen_Uint( this ),
24632468
u_Color_Float( this ),
2469+
u_Color_Uint( this ),
24642470
u_ViewOrigin( this ),
24652471
u_LightOrigin( this ),
24662472
u_LightColor( this ),
@@ -2513,7 +2519,9 @@ GLShader_forwardLighting_projXYZ::GLShader_forwardLighting_projXYZ( GLShaderMana
25132519
u_SpecularExponent( this ),
25142520
u_AlphaThreshold( this ),
25152521
u_ColorModulateColorGen_Float( this ),
2522+
u_ColorModulateColorGen_Uint( this ),
25162523
u_Color_Float( this ),
2524+
u_Color_Uint( this ),
25172525
u_ViewOrigin( this ),
25182526
u_LightOrigin( this ),
25192527
u_LightColor( this ),
@@ -2577,7 +2585,9 @@ GLShader_forwardLighting_directionalSun::GLShader_forwardLighting_directionalSun
25772585
u_SpecularExponent( this ),
25782586
u_AlphaThreshold( this ),
25792587
u_ColorModulateColorGen_Float( this ),
2588+
u_ColorModulateColorGen_Uint( this ),
25802589
u_Color_Float( this ),
2590+
u_Color_Uint( this ),
25812591
u_ViewOrigin( this ),
25822592
u_LightDir( this ),
25832593
u_LightColor( this ),
@@ -2640,6 +2650,7 @@ GLShader_shadowFill::GLShader_shadowFill( GLShaderManager *manager ) :
26402650
u_ModelMatrix( this ),
26412651
u_ModelViewProjectionMatrix( this ),
26422652
u_Color_Float( this ),
2653+
u_Color_Uint( this ),
26432654
u_Bones( this ),
26442655
u_VertexInterpolation( this ),
26452656
GLDeformStage( this ),
@@ -2748,6 +2759,7 @@ GLShader_fogQuake3::GLShader_fogQuake3( GLShaderManager *manager ) :
27482759
u_ModelMatrix( this ),
27492760
u_ModelViewProjectionMatrix( this ),
27502761
u_ColorGlobal_Float( this ),
2762+
u_ColorGlobal_Uint( this ),
27512763
u_Bones( this ),
27522764
u_VertexInterpolation( this ),
27532765
u_FogDistanceVector( this ),
@@ -2769,7 +2781,7 @@ GLShader_fogQuake3Material::GLShader_fogQuake3Material( GLShaderManager* manager
27692781
u_FogMap( this ),
27702782
u_ModelMatrix( this ),
27712783
u_ModelViewProjectionMatrix( this ),
2772-
u_ColorGlobal_Float( this ),
2784+
u_ColorGlobal_Uint( this ),
27732785
u_FogDistanceVector( this ),
27742786
u_FogDepthVector( this ),
27752787
u_FogEyeT( this ),
@@ -2787,6 +2799,7 @@ GLShader_fogGlobal::GLShader_fogGlobal( GLShaderManager *manager ) :
27872799
u_ModelViewProjectionMatrix( this ),
27882800
u_UnprojectMatrix( this ),
27892801
u_Color_Float( this ),
2802+
u_Color_Uint( this ),
27902803
u_FogDistanceVector( this )
27912804
{
27922805
}

src/engine/renderer/gl_shader.h

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ class u_Color_Float :
30513051
{
30523052
}
30533053

3054-
void SetUniform_Color( const Color::Color& color )
3054+
void SetUniform_Color_Float( const Color::Color& color )
30553055
{
30563056
this->SetValue( color.ToArray() );
30573057
}
@@ -3066,12 +3066,24 @@ class u_Color_Uint :
30663066
{
30673067
}
30683068

3069-
void SetUniform_Color( const Color::Color& color )
3069+
void SetUniform_Color_Uint( const Color::Color& color )
30703070
{
30713071
this->SetValue( packUnorm4x8( color.ToArray() ) );
30723072
}
30733073
};
30743074

3075+
template<typename Shader> void SetUniform_Color( Shader* shader, const Color::Color& color )
3076+
{
3077+
if( glConfig2.gpuShader4Available )
3078+
{
3079+
shader->SetUniform_Color_Uint( color );
3080+
}
3081+
else
3082+
{
3083+
shader->SetUniform_Color_Float( color );
3084+
}
3085+
}
3086+
30753087
class u_ColorGlobal_Float :
30763088
GLUniform4f
30773089
{
@@ -3081,7 +3093,7 @@ class u_ColorGlobal_Float :
30813093
{
30823094
}
30833095

3084-
void SetUniform_ColorGlobal( const Color::Color& color )
3096+
void SetUniform_ColorGlobal_Float( const Color::Color& color )
30853097
{
30863098
this->SetValue( color.ToArray() );
30873099
}
@@ -3094,11 +3106,23 @@ class u_ColorGlobal_Uint :
30943106
GLUniform1ui( shader, "u_ColorGlobal", true ) {
30953107
}
30963108

3097-
void SetUniform_ColorGlobal( const Color::Color& color ) {
3109+
void SetUniform_ColorGlobal_Uint( const Color::Color& color ) {
30983110
this->SetValue( packUnorm4x8( color.ToArray() ) );
30993111
}
31003112
};
31013113

3114+
template<typename Shader> void SetUniform_ColorGlobal( Shader* shader, const Color::Color& color )
3115+
{
3116+
if( glConfig2.gpuShader4Available )
3117+
{
3118+
shader->SetUniform_ColorGlobal_Uint( color );
3119+
}
3120+
else
3121+
{
3122+
shader->SetUniform_ColorGlobal_Float( color );
3123+
}
3124+
}
3125+
31023126
class u_Frame :
31033127
GLUniform1ui {
31043128
public:
@@ -3668,7 +3692,7 @@ class u_ColorModulateColorGen_Float :
36683692
{
36693693
}
36703694

3671-
void SetUniform_ColorModulateColorGen(
3695+
void SetUniform_ColorModulateColorGen_Float(
36723696
const colorGen_t colorGen,
36733697
const alphaGen_t alphaGen,
36743698
const bool vertexOverbright = false,
@@ -3703,7 +3727,7 @@ class u_ColorModulateColorGen_Uint :
37033727
GLUniform1ui( shader, "u_ColorModulateColorGen" ) {
37043728
}
37053729

3706-
void SetUniform_ColorModulateColorGen(
3730+
void SetUniform_ColorModulateColorGen_Uint(
37073731
const colorGen_t colorGen,
37083732
const alphaGen_t alphaGen,
37093733
const bool vertexOverbright = false,
@@ -3756,6 +3780,23 @@ class u_ColorModulateColorGen_Uint :
37563780
}
37573781
};
37583782

3783+
template<typename Shader> void SetUniform_ColorModulateColorGen(
3784+
Shader* shader,
3785+
const colorGen_t colorGen,
3786+
const alphaGen_t alphaGen,
3787+
const bool vertexOverbright = false,
3788+
const bool useMapLightFactor = false )
3789+
{
3790+
if( glConfig2.gpuShader4Available )
3791+
{
3792+
shader->SetUniform_ColorModulateColorGen_Uint( colorGen, alphaGen, vertexOverbright, useMapLightFactor );
3793+
}
3794+
else
3795+
{
3796+
shader->SetUniform_ColorModulateColorGen_Float( colorGen, alphaGen, vertexOverbright, useMapLightFactor );
3797+
}
3798+
}
3799+
37593800
class u_FogDistanceVector :
37603801
GLUniform4f
37613802
{
@@ -4054,7 +4095,9 @@ class GLShader_generic :
40544095
public u_ModelMatrix,
40554096
public u_ModelViewProjectionMatrix,
40564097
public u_ColorModulateColorGen_Float,
4098+
public u_ColorModulateColorGen_Uint,
40574099
public u_Color_Float,
4100+
public u_Color_Uint,
40584101
public u_Bones,
40594102
public u_VertexInterpolation,
40604103
public u_DepthScale,
@@ -4115,7 +4158,9 @@ class GLShader_lightMapping :
41154158
public u_TextureMatrix,
41164159
public u_SpecularExponent,
41174160
public u_ColorModulateColorGen_Float,
4161+
public u_ColorModulateColorGen_Uint,
41184162
public u_Color_Float,
4163+
public u_Color_Uint,
41194164
public u_AlphaThreshold,
41204165
public u_ViewOrigin,
41214166
public u_ModelMatrix,
@@ -4212,7 +4257,9 @@ class GLShader_forwardLighting_omniXYZ :
42124257
public u_SpecularExponent,
42134258
public u_AlphaThreshold,
42144259
public u_ColorModulateColorGen_Float,
4260+
public u_ColorModulateColorGen_Uint,
42154261
public u_Color_Float,
4262+
public u_Color_Uint,
42164263
public u_ViewOrigin,
42174264
public u_LightOrigin,
42184265
public u_LightColor,
@@ -4255,7 +4302,9 @@ class GLShader_forwardLighting_projXYZ :
42554302
public u_SpecularExponent,
42564303
public u_AlphaThreshold,
42574304
public u_ColorModulateColorGen_Float,
4305+
public u_ColorModulateColorGen_Uint,
42584306
public u_Color_Float,
4307+
public u_Color_Uint,
42594308
public u_ViewOrigin,
42604309
public u_LightOrigin,
42614310
public u_LightColor,
@@ -4305,7 +4354,9 @@ class GLShader_forwardLighting_directionalSun :
43054354
public u_SpecularExponent,
43064355
public u_AlphaThreshold,
43074356
public u_ColorModulateColorGen_Float,
4357+
public u_ColorModulateColorGen_Uint,
43084358
public u_Color_Float,
4359+
public u_Color_Uint,
43094360
public u_ViewOrigin,
43104361
public u_LightDir,
43114362
public u_LightColor,
@@ -4347,6 +4398,7 @@ class GLShader_shadowFill :
43474398
public u_ModelMatrix,
43484399
public u_ModelViewProjectionMatrix,
43494400
public u_Color_Float,
4401+
public u_Color_Uint,
43504402
public u_Bones,
43514403
public u_VertexInterpolation,
43524404
public GLDeformStage,
@@ -4441,6 +4493,7 @@ class GLShader_fogQuake3 :
44414493
public u_ModelMatrix,
44424494
public u_ModelViewProjectionMatrix,
44434495
public u_ColorGlobal_Float,
4496+
public u_ColorGlobal_Uint,
44444497
public u_Bones,
44454498
public u_VertexInterpolation,
44464499
public u_FogDistanceVector,
@@ -4460,7 +4513,7 @@ class GLShader_fogQuake3Material :
44604513
public u_FogMap,
44614514
public u_ModelMatrix,
44624515
public u_ModelViewProjectionMatrix,
4463-
public u_ColorGlobal_Float,
4516+
public u_ColorGlobal_Uint,
44644517
public u_FogDistanceVector,
44654518
public u_FogDepthVector,
44664519
public u_FogEyeT,
@@ -4477,6 +4530,7 @@ class GLShader_fogGlobal :
44774530
public u_ModelViewProjectionMatrix,
44784531
public u_UnprojectMatrix,
44794532
public u_Color_Float,
4533+
public u_Color_Uint,
44804534
public u_FogDistanceVector
44814535
{
44824536
public:

src/engine/renderer/glsl_source/common.glsl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,21 @@ array must be in the form of uvec4 array[] */
4545

4646
// Common functions
4747

48-
#if defined(USE_MATERIAL_SYSTEM)
48+
#if defined(HAVE_EXT_gpu_shader4)
4949
#define colorPack uint
5050
#define colorModulatePack uint
5151
#else
5252
#define colorPack vec4
5353
#define colorModulatePack vec4
5454
#endif
5555

56-
#if defined(USE_MATERIAL_SYSTEM)
57-
vec4 UnpackColor( const in uint packedColor )
56+
vec4 UnpackColor( const in colorPack packedColor )
5857
{
58+
#if defined(HAVE_EXT_gpu_shader4)
5959
return unpackUnorm4x8( packedColor );
60-
}
61-
#endif
62-
63-
// fogGlobal can't use the colorPack type because there is no Material variant.
64-
vec4 UnpackColor( const in vec4 packedColor )
65-
{
60+
#else
6661
return packedColor;
62+
#endif
6763
}
6864

6965
/* colorMod uint format:
@@ -87,7 +83,7 @@ colorMod[ 3 ]: alpha * f */
8783

8884
vec4 ColorModulateToColor( const in colorModulatePack colorMod )
8985
{
90-
#if defined(USE_MATERIAL_SYSTEM)
86+
#if defined(HAVE_EXT_gpu_shader4)
9187
vec3 colorModArray = vec3( 0.0f, 1.0f, -1.0f );
9288

9389
uint rgbIndex = colorMod & 3u;
@@ -112,7 +108,7 @@ modBits_t ColorModulateToBits( const in colorModulatePack colorMod )
112108
{
113109
modBits_t modBits;
114110

115-
#if defined(USE_MATERIAL_SYSTEM)
111+
#if defined(HAVE_EXT_gpu_shader4)
116112
modBits.alphaAddOne = bool( ( colorMod >> 4u ) & 1u );
117113
modBits.isLightStyle = bool( ( colorMod >> 27u ) & 1u );
118114
#else
@@ -125,7 +121,7 @@ modBits_t ColorModulateToBits( const in colorModulatePack colorMod )
125121

126122
float ColorModulateToLightFactor( const in colorModulatePack colorMod )
127123
{
128-
#if defined(USE_MATERIAL_SYSTEM)
124+
#if defined(HAVE_EXT_gpu_shader4)
129125
return float( colorMod >> 28u );
130126
#else
131127
return abs( colorMod.g );

src/engine/renderer/glsl_source/fogGlobal_fp.glsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2727
uniform sampler2D u_ColorMap; // fog texture
2828
uniform sampler2D u_DepthMap;
2929

30-
// fogGlobal can't use the colorPack type because there is no Material variant.
31-
uniform vec4 u_Color;
30+
uniform colorPack u_Color;
3231

3332
uniform vec4 u_FogDistanceVector;
3433
uniform mat4 u_UnprojectMatrix;

src/engine/renderer/glsl_source/fogQuake3_vp.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2929

3030
uniform float u_Time;
3131

32-
uniform vec4 u_ColorGlobal;
32+
uniform colorPack u_ColorGlobal;
3333

3434
uniform mat4 u_ModelMatrix;
3535
uniform mat4 u_ModelViewProjectionMatrix;

0 commit comments

Comments
 (0)