Skip to content

Commit 93467b6

Browse files
committed
renderer: add alternate code path for when mat3x2 isn't available, use it on GL4ES
1 parent 8e944ba commit 93467b6

13 files changed

Lines changed: 156 additions & 50 deletions

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 mat3x2Available;
131132
bool assumeSmoothstep;
132133
bool incrementalShaderCompilation;
133134
int maxDrawBuffers;

src/engine/renderer/gl_shader.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ R"(vec4 unpackUnorm4x8( uint value )
574574
str += "#define atomicCounterAndARB atomicCounterAnd\n";
575575
}
576576

577+
if ( glConfig.mat3x2Available ) {
578+
str += "#define textureMatrix mat3x2\n";
579+
} else {
580+
str += "#define textureMatrix mat3\n";
581+
}
582+
577583
str +=
578584
R"(#endif // GENERATED_COMPAT_HEADER
579585
@@ -1831,7 +1837,7 @@ std::string GLShaderManager::ShaderPostProcess( GLShader *shader, const std::str
18311837
" uvec2 u_GlowMap;\n"
18321838
"};\n\n"
18331839
+ texBuf +
1834-
"#define u_TextureMatrix mat3x2( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.xy, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.zw, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix2 )\n"
1840+
"#define u_TextureMatrix textureMatrix( texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.xy, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix.zw, texData[( baseInstance >> 12 ) & 0xFFF].u_TextureMatrix2 )\n"
18351841
"#define u_DiffuseMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_DiffuseMap\n"
18361842
"#define u_NormalMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_NormalMap\n"
18371843
"#define u_HeightMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_HeightMap\n"
@@ -2578,7 +2584,8 @@ GLShader_generic::GLShader_generic() :
25782584
false, "generic", "generic" ),
25792585
u_ColorMap( this ),
25802586
u_DepthMap( this ),
2581-
u_TextureMatrix( this ),
2587+
u_TextureMatrix_Matrix3( this ),
2588+
u_TextureMatrix_Matrix32( this ),
25822589
u_ViewOrigin( this ),
25832590
u_AlphaThreshold( this ),
25842591
u_ModelMatrix( this ),
@@ -2612,7 +2619,8 @@ GLShader_genericMaterial::GLShader_genericMaterial() :
26122619
true, "generic", "generic" ),
26132620
u_ColorMap( this ),
26142621
u_DepthMap( this ),
2615-
u_TextureMatrix( this ),
2622+
u_TextureMatrix_Matrix3( this ),
2623+
u_TextureMatrix_Matrix32( this ),
26162624
u_ViewOrigin( this ),
26172625
u_AlphaThreshold( this ),
26182626
u_ModelMatrix( this ),
@@ -2645,7 +2653,8 @@ GLShader_lightMapping::GLShader_lightMapping() :
26452653
u_LightGrid1( this ),
26462654
u_LightGrid2( this ),
26472655
u_LightTiles( this ),
2648-
u_TextureMatrix( this ),
2656+
u_TextureMatrix_Matrix3( this ),
2657+
u_TextureMatrix_Matrix32( this ),
26492658
u_SpecularExponent( this ),
26502659
u_ColorModulateColorGen_Float( this ),
26512660
u_ColorModulateColorGen_Uint( this ),
@@ -2713,7 +2722,8 @@ GLShader_lightMappingMaterial::GLShader_lightMappingMaterial() :
27132722
u_LightGrid1( this ),
27142723
u_LightGrid2( this ),
27152724
u_LightTiles( this ),
2716-
u_TextureMatrix( this ),
2725+
u_TextureMatrix_Matrix3( this ),
2726+
u_TextureMatrix_Matrix32( this ),
27172727
u_SpecularExponent( this ),
27182728
u_ColorModulateColorGen_Uint( this ),
27192729
u_Color_Uint( this ),
@@ -2751,7 +2761,8 @@ GLShader_reflection::GLShader_reflection():
27512761
u_ColorMapCube( this ),
27522762
u_NormalMap( this ),
27532763
u_HeightMap( this ),
2754-
u_TextureMatrix( this ),
2764+
u_TextureMatrix_Matrix3( this ),
2765+
u_TextureMatrix_Matrix32( this ),
27552766
u_ViewOrigin( this ),
27562767
u_ModelMatrix( this ),
27572768
u_ModelViewProjectionMatrix( this ),
@@ -2782,7 +2793,8 @@ GLShader_reflectionMaterial::GLShader_reflectionMaterial() :
27822793
u_ColorMapCube( this ),
27832794
u_NormalMap( this ),
27842795
u_HeightMap( this ),
2785-
u_TextureMatrix( this ),
2796+
u_TextureMatrix_Matrix3( this ),
2797+
u_TextureMatrix_Matrix32( this ),
27862798
u_ViewOrigin( this ),
27872799
u_ModelMatrix( this ),
27882800
u_ModelViewProjectionMatrix( this ),
@@ -2800,7 +2812,8 @@ GLShader_skybox::GLShader_skybox() :
28002812
false, "skybox", "skybox" ),
28012813
u_ColorMapCube( this ),
28022814
u_CloudMap( this ),
2803-
u_TextureMatrix( this ),
2815+
u_TextureMatrix_Matrix3( this ),
2816+
u_TextureMatrix_Matrix32( this ),
28042817
u_CloudHeight( this ),
28052818
u_UseCloudMap( this ),
28062819
u_AlphaThreshold( this ),
@@ -2819,7 +2832,8 @@ GLShader_skyboxMaterial::GLShader_skyboxMaterial() :
28192832
true, "skybox", "skybox" ),
28202833
u_ColorMapCube( this ),
28212834
u_CloudMap( this ),
2822-
u_TextureMatrix( this ),
2835+
u_TextureMatrix_Matrix3( this ),
2836+
u_TextureMatrix_Matrix32( this ),
28232837
u_CloudHeight( this ),
28242838
u_UseCloudMap( this ),
28252839
u_AlphaThreshold( this ),
@@ -2850,7 +2864,8 @@ GLShader_heatHaze::GLShader_heatHaze() :
28502864
false, "heatHaze", "heatHaze" ),
28512865
u_CurrentMap( this ),
28522866
u_NormalMap( this ),
2853-
u_TextureMatrix( this ),
2867+
u_TextureMatrix_Matrix3( this ),
2868+
u_TextureMatrix_Matrix32( this ),
28542869
u_DeformMagnitude( this ),
28552870
u_ModelViewProjectionMatrix( this ),
28562871
u_ModelViewMatrixTranspose( this ),
@@ -2875,7 +2890,8 @@ GLShader_heatHazeMaterial::GLShader_heatHazeMaterial() :
28752890
true, "heatHaze", "heatHaze" ),
28762891
u_CurrentMap( this ),
28772892
u_NormalMap( this ),
2878-
u_TextureMatrix( this ),
2893+
u_TextureMatrix_Matrix3( this ),
2894+
u_TextureMatrix_Matrix32( this ),
28792895
u_DeformEnable( this ),
28802896
u_DeformMagnitude( this ),
28812897
u_ModelViewProjectionMatrix( this ),
@@ -2978,7 +2994,8 @@ GLShader_liquid::GLShader_liquid() :
29782994
u_LightGrid1( this ),
29792995
u_LightGrid2( this ),
29802996
u_HeightMap( this ),
2981-
u_TextureMatrix( this ),
2997+
u_TextureMatrix_Matrix3( this ),
2998+
u_TextureMatrix_Matrix32( this ),
29822999
u_ViewOrigin( this ),
29833000
u_RefractionIndex( this ),
29843001
u_ModelMatrix( this ),
@@ -3022,7 +3039,8 @@ GLShader_liquidMaterial::GLShader_liquidMaterial() :
30223039
u_LightGrid1( this ),
30233040
u_LightGrid2( this ),
30243041
u_HeightMap( this ),
3025-
u_TextureMatrix( this ),
3042+
u_TextureMatrix_Matrix3( this ),
3043+
u_TextureMatrix_Matrix32( this ),
30263044
u_ViewOrigin( this ),
30273045
u_RefractionIndex( this ),
30283046
u_ModelMatrix( this ),

src/engine/renderer/gl_shader.h

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,24 @@ class GLUniformMatrix4f : protected GLUniform
807807
}
808808
};
809809

810+
class GLUniformMatrix3f : protected GLUniform
811+
{
812+
protected:
813+
GLUniformMatrix3f( GLShader *shader, const char *name, const UpdateType updateType ) :
814+
GLUniform( shader, name, "mat3", 9, 4, updateType ) {
815+
}
816+
817+
inline void SetValue( GLboolean transpose, const matrix_t m )
818+
{
819+
if ( !CacheValue( ( void* ) m ) ) {
820+
return;
821+
}
822+
823+
ShaderProgramDescriptor* p = _shader->GetProgram();
824+
glUniformMatrix3fv( p->uniformLocations[ _locationIndex ], 1, transpose, m );
825+
}
826+
};
827+
810828
class GLUniformMatrix32f : protected GLUniform {
811829
protected:
812830
GLUniformMatrix32f( GLShader* shader, const char* name, const UpdateType updateType ) :
@@ -1706,16 +1724,41 @@ class u_CurrentMap :
17061724
}
17071725
};
17081726

1709-
class u_TextureMatrix :
1727+
class u_TextureMatrix_Matrix3 :
1728+
GLUniformMatrix3f
1729+
{
1730+
public:
1731+
u_TextureMatrix_Matrix3( GLShader *shader ) :
1732+
GLUniformMatrix3f( shader, "u_TextureMatrix", TEXDATA_OR_PUSH )
1733+
{
1734+
}
1735+
1736+
void SetUniform_TextureMatrix_Matrix3( const matrix_t m )
1737+
{
1738+
vec_t m2[9];
1739+
m2[0] = m[0];
1740+
m2[1] = m[1];
1741+
m2[2] = 0;
1742+
m2[3] = m[4];
1743+
m2[4] = m[5];
1744+
m2[5] = 0;
1745+
m2[6] = m[12];
1746+
m2[7] = m[13];
1747+
m2[8] = 1;
1748+
this->SetValue( GL_FALSE, m2 );
1749+
}
1750+
};
1751+
1752+
class u_TextureMatrix_Matrix32 :
17101753
GLUniformMatrix32f
17111754
{
17121755
public:
1713-
u_TextureMatrix( GLShader *shader ) :
1756+
u_TextureMatrix_Matrix32( GLShader *shader ) :
17141757
GLUniformMatrix32f( shader, "u_TextureMatrix", TEXDATA_OR_PUSH )
17151758
{
17161759
}
17171760

1718-
void SetUniform_TextureMatrix( const matrix_t m )
1761+
void SetUniform_TextureMatrix_Matrix32( const matrix_t m )
17191762
{
17201763
/* We only actually need these 6 components to get the correct texture transformation,
17211764
the other ones are unused */
@@ -1730,6 +1773,18 @@ class u_TextureMatrix :
17301773
}
17311774
};
17321775

1776+
template<typename Shader> void SetUniform_TextureMatrix( Shader* shader, const matrix_t m )
1777+
{
1778+
if ( glConfig.mat3x2Available )
1779+
{
1780+
shader->SetUniform_TextureMatrix_Matrix32( m );
1781+
}
1782+
else
1783+
{
1784+
shader->SetUniform_TextureMatrix_Matrix3( m );
1785+
}
1786+
}
1787+
17331788
class u_AlphaThreshold :
17341789
GLUniform1f
17351790
{
@@ -2934,7 +2989,8 @@ class GLShader_generic :
29342989
public GLShader,
29352990
public u_ColorMap,
29362991
public u_DepthMap,
2937-
public u_TextureMatrix,
2992+
public u_TextureMatrix_Matrix3,
2993+
public u_TextureMatrix_Matrix32,
29382994
public u_ViewOrigin,
29392995
public u_AlphaThreshold,
29402996
public u_ModelMatrix,
@@ -2964,7 +3020,8 @@ class GLShader_genericMaterial :
29643020
public GLShader,
29653021
public u_ColorMap,
29663022
public u_DepthMap,
2967-
public u_TextureMatrix,
3023+
public u_TextureMatrix_Matrix3,
3024+
public u_TextureMatrix_Matrix32,
29683025
public u_ViewOrigin,
29693026
public u_AlphaThreshold,
29703027
public u_ModelMatrix,
@@ -2998,7 +3055,8 @@ class GLShader_lightMapping :
29983055
public u_LightGrid1,
29993056
public u_LightGrid2,
30003057
public u_LightTiles,
3001-
public u_TextureMatrix,
3058+
public u_TextureMatrix_Matrix3,
3059+
public u_TextureMatrix_Matrix32,
30023060
public u_SpecularExponent,
30033061
public u_ColorModulateColorGen_Float,
30043062
public u_ColorModulateColorGen_Uint,
@@ -3052,7 +3110,8 @@ class GLShader_lightMappingMaterial :
30523110
public u_LightGrid1,
30533111
public u_LightGrid2,
30543112
public u_LightTiles,
3055-
public u_TextureMatrix,
3113+
public u_TextureMatrix_Matrix3,
3114+
public u_TextureMatrix_Matrix32,
30563115
public u_SpecularExponent,
30573116
public u_ColorModulateColorGen_Uint,
30583117
public u_Color_Uint,
@@ -3091,7 +3150,8 @@ class GLShader_reflection :
30913150
public u_ColorMapCube,
30923151
public u_NormalMap,
30933152
public u_HeightMap,
3094-
public u_TextureMatrix,
3153+
public u_TextureMatrix_Matrix3,
3154+
public u_TextureMatrix_Matrix32,
30953155
public u_ViewOrigin,
30963156
public u_ModelMatrix,
30973157
public u_ModelViewProjectionMatrix,
@@ -3117,7 +3177,8 @@ class GLShader_reflectionMaterial :
31173177
public u_ColorMapCube,
31183178
public u_NormalMap,
31193179
public u_HeightMap,
3120-
public u_TextureMatrix,
3180+
public u_TextureMatrix_Matrix3,
3181+
public u_TextureMatrix_Matrix32,
31213182
public u_ViewOrigin,
31223183
public u_ModelMatrix,
31233184
public u_ModelViewProjectionMatrix,
@@ -3136,7 +3197,8 @@ class GLShader_skybox :
31363197
public GLShader,
31373198
public u_ColorMapCube,
31383199
public u_CloudMap,
3139-
public u_TextureMatrix,
3200+
public u_TextureMatrix_Matrix3,
3201+
public u_TextureMatrix_Matrix32,
31403202
public u_CloudHeight,
31413203
public u_UseCloudMap,
31423204
public u_AlphaThreshold,
@@ -3151,7 +3213,8 @@ class GLShader_skyboxMaterial :
31513213
public GLShader,
31523214
public u_ColorMapCube,
31533215
public u_CloudMap,
3154-
public u_TextureMatrix,
3216+
public u_TextureMatrix_Matrix3,
3217+
public u_TextureMatrix_Matrix32,
31553218
public u_CloudHeight,
31563219
public u_UseCloudMap,
31573220
public u_AlphaThreshold,
@@ -3180,7 +3243,8 @@ class GLShader_heatHaze :
31803243
public GLShader,
31813244
public u_CurrentMap,
31823245
public u_NormalMap,
3183-
public u_TextureMatrix,
3246+
public u_TextureMatrix_Matrix3,
3247+
public u_TextureMatrix_Matrix32,
31843248
public u_DeformMagnitude,
31853249
public u_ModelViewProjectionMatrix,
31863250
public u_ModelViewMatrixTranspose,
@@ -3201,7 +3265,8 @@ class GLShader_heatHazeMaterial :
32013265
public GLShader,
32023266
public u_CurrentMap,
32033267
public u_NormalMap,
3204-
public u_TextureMatrix,
3268+
public u_TextureMatrix_Matrix3,
3269+
public u_TextureMatrix_Matrix32,
32053270
public u_DeformEnable,
32063271
public u_DeformMagnitude,
32073272
public u_ModelViewProjectionMatrix,
@@ -3290,7 +3355,8 @@ class GLShader_liquid :
32903355
public u_LightGrid1,
32913356
public u_LightGrid2,
32923357
public u_HeightMap,
3293-
public u_TextureMatrix,
3358+
public u_TextureMatrix_Matrix3,
3359+
public u_TextureMatrix_Matrix32,
32943360
public u_ViewOrigin,
32953361
public u_RefractionIndex,
32963362
public u_ModelMatrix,
@@ -3326,7 +3392,8 @@ class GLShader_liquidMaterial :
33263392
public u_LightGrid1,
33273393
public u_LightGrid2,
33283394
public u_HeightMap,
3329-
public u_TextureMatrix,
3395+
public u_TextureMatrix_Matrix3,
3396+
public u_TextureMatrix_Matrix32,
33303397
public u_ViewOrigin,
33313398
public u_RefractionIndex,
33323399
public u_ModelMatrix,

src/engine/renderer/glsl_source/generic_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
#insert shaderProfiler_vp
3030

3131
#if !defined(USE_MATERIAL_SYSTEM)
32-
uniform mat3x2 u_TextureMatrix;
32+
uniform textureMatrix u_TextureMatrix;
3333
#endif
3434

3535
uniform vec3 u_ViewOrigin;

src/engine/renderer/glsl_source/heatHaze_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
uniform float u_Time;
3030

3131
#if !defined(USE_MATERIAL_SYSTEM)
32-
uniform mat3x2 u_TextureMatrix;
32+
uniform textureMatrix u_TextureMatrix;
3333
#endif
3434

3535
uniform mat4 u_ProjectionMatrixTranspose;

src/engine/renderer/glsl_source/lightMapping_vp.glsl

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

3939
#if !defined(USE_MATERIAL_SYSTEM)
40-
uniform mat3x2 u_TextureMatrix;
40+
uniform textureMatrix u_TextureMatrix;
4141
#endif
4242

4343
uniform mat4 u_ModelMatrix;

src/engine/renderer/glsl_source/liquid_vp.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ IN vec3 attr_Binormal;
2929
IN vec3 attr_Normal;
3030

3131
#if !defined(USE_MATERIAL_SYSTEM)
32-
uniform mat3x2 u_TextureMatrix;
32+
uniform textureMatrix u_TextureMatrix;
3333
#endif
3434

3535
uniform mat4 u_ModelMatrix;

0 commit comments

Comments
 (0)