@@ -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+
810828class 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{
17121755public:
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+
17331788class 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,
0 commit comments