diff --git a/src/engine/renderer/DetectGLVendors.cpp b/src/engine/renderer/DetectGLVendors.cpp index 93326acb72..b2084ab4e9 100644 --- a/src/engine/renderer/DetectGLVendors.cpp +++ b/src/engine/renderer/DetectGLVendors.cpp @@ -47,6 +47,7 @@ std::string GetGLHardwareVendorName( glHardwareVendor_t hardwareVendor ) "Intel", "Nvidia", "Moore Threads", + "Imagination", "OutOfRange", }; @@ -73,6 +74,8 @@ std::string GetGLDriverVendorName( glDriverVendor_t driverVendor ) "Mesa", "Nvidia", "Moore Threads", + "Imagination", + "GL4ES", "OutOfRange", }; @@ -89,6 +92,19 @@ std::string GetGLDriverVendorName( glDriverVendor_t driverVendor ) return driverVendorNames[ index ]; } +static std::string StripPrefix( const std::string &prefix, const std::string &string ) +{ + if ( Str::IsPrefix( prefix, string ) ) + { + size_t prefixLen = prefix.length(); + size_t stringLen = string.length(); + size_t subLen = stringLen - prefixLen; + return string.substr( prefixLen, subLen ); + } + + return string; +} + void DetectGLVendors( const std::string& vendorString, const std::string& versionString, @@ -125,6 +141,8 @@ void DetectGLVendors( { "NVIDIA Corporation", { glDriverVendor_t::NVIDIA, glHardwareVendor_t::NVIDIA } }, // Moore Threads drivers on Linux and Windows. { "Moore Threads", { glDriverVendor_t::MTHREADS, glHardwareVendor_t::MTHREADS } }, + // Proprietary Imagination driver for PowerVR. + { "Imagination Technologies", { glDriverVendor_t::IMAGINATION, glHardwareVendor_t::IMAGINATION } }, }; auto it = vendorDriverHardware.find( vendorString ); @@ -309,4 +327,39 @@ void DetectGLVendors( hardwareVendor = glHardwareVendor_t::INTEL; return; } + + // Newer GL4ES strings disclosing the underlying technology. + if ( Str::IsPrefix( "GL4ES wrapping ", vendorString ) ) + { + std::string subVendorString = StripPrefix( "GL4ES wrapping ", vendorString ); + std::string subRendererString = StripPrefix( "GL4ES using ", rendererString ); + DetectGLVendors( subVendorString, versionString, subRendererString, hardwareVendor, driverVendor ); + driverVendor = glDriverVendor_t::GL4ES; + } + + /* Older GL4ES string not disclosing the underlying technology, + also had “ptitSeb” as vendorString. */ + if ( rendererString == "GL4ES wrapper" ) + { + driverVendor = glDriverVendor_t::GL4ES; + // Older GL4ES doesn't disclose the underlying hardware. + if ( hardwareVendor == glHardwareVendor_t::UNKNOWN ) + { + hardwareVendor = glHardwareVendor_t::TRANSLATION; + } + return; + } + + /* GL4ES always use such kind of version string: + > 2.1 gl4es wrapper 1.1.7 + And this is unlikely to change. */ + if ( versionString.find( "gl4es wrapper" ) != std::string::npos ) + { + driverVendor = glDriverVendor_t::GL4ES; + if ( hardwareVendor == glHardwareVendor_t::UNKNOWN ) + { + hardwareVendor = glHardwareVendor_t::TRANSLATION; + } + return; + } } diff --git a/src/engine/renderer/DetectGLVendors.h b/src/engine/renderer/DetectGLVendors.h index 414372b381..704e8eca5b 100644 --- a/src/engine/renderer/DetectGLVendors.h +++ b/src/engine/renderer/DetectGLVendors.h @@ -57,6 +57,7 @@ enum class glHardwareVendor_t INTEL, NVIDIA, MTHREADS, + IMAGINATION, NUM_HARDWARE_VENDORS, }; @@ -69,6 +70,8 @@ enum class glDriverVendor_t MESA, NVIDIA, MTHREADS, + IMAGINATION, + GL4ES, NUM_DRIVER_VENDORS, }; diff --git a/src/engine/renderer/GLUtils.h b/src/engine/renderer/GLUtils.h index 9ea2aff90d..166588b251 100644 --- a/src/engine/renderer/GLUtils.h +++ b/src/engine/renderer/GLUtils.h @@ -129,6 +129,10 @@ struct GLConfig bool gpuShader4Available; bool gpuShader5Available; bool textureGatherAvailable; + bool texture3DAvailable; + bool mat3x2Available; + bool assumeSmoothstep; + bool incrementalShaderCompilation; int maxDrawBuffers; float maxTextureAnisotropy; diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index d0e1012360..fd28ab6d62 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -490,17 +490,43 @@ static void AddConst( std::string& str, const std::string& name, float v1, float } #endif -static std::string GenVersionDeclaration( const std::vector &addedExtensions ) { - // Declare version. - std::string str = Str::Format( "#version %d %s\n\n", +static std::string GenVersionLine() { + return Str::Format( "#version %d %s\n", glConfig.shadingLanguageVersion, glConfig.shadingLanguageVersion >= 150 ? ( glConfig.glCoreProfile ? "core" : "compatibility" ) : "" ); +} + +static std::string GenVersionDeclaration( const std::vector &addedExtensions ) { + std::string str; + + if ( !glConfig.incrementalShaderCompilation ) { + /* Add version the line, but commented out, to contribute to the shader cache checksum. + The #version line will be added when compiling the concatenated shader because we cannot + guard such line with some #ifdef, it has to be the first non-comment non-empty line. */ + str += "// "; + } + + // Declare version. + str += GenVersionLine() + "\n"; + + str += +R"(#if !defined(GENERATED_EXTENSIONS_HEADER) +#define GENERATED_EXTENSIONS_HEADER +)"; // Add supported GLSL extensions. for ( const auto& addedExtension : addedExtensions ) { addExtension( str, addedExtension.available, addedExtension.minGlslVersion, addedExtension.name ); } + if ( glConfig.texture3DAvailable ) { + str += "#define HAVE_texture3D 1\n"; + } + + str += +R"(#endif // GENERATED_EXTENSIONS_HEADER + +)"; return str; } @@ -515,8 +541,13 @@ static std::string GenComputeVersionDeclaration() { static std::string GenCompatHeader() { std::string str; + str += +R"(#if !defined(GENERATED_COMPAT_HEADER) +#define GENERATED_COMPAT_HEADER +)"; + // definition of functions missing in early GLSL - if( glConfig.shadingLanguageVersion <= 120 ) { + if( glConfig.shadingLanguageVersion <= 120 && !glConfig.assumeSmoothstep ) { str += "float smoothstep(float edge0, float edge1, float x) { float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); return t * t * (3.0 - 2.0 * t); }\n"; } @@ -549,22 +580,38 @@ R"(vec4 unpackUnorm4x8( uint value ) str += "#define atomicCounterAndARB atomicCounterAnd\n"; } + if ( glConfig.mat3x2Available ) { + str += "#define textureMatrix mat3x2\n"; + } else { + str += "#define textureMatrix mat3\n"; + } + + str += +R"(#endif // GENERATED_COMPAT_HEADER + +)"; + return str; } static std::string GenVertexHeader() { std::string str; + str += +R"(#if !defined(GENERATED_VERTEX_HEADER) +#define GENERATED_VERTEX_HEADER +)"; + // Vertex shader compatibility defines if( glConfig.shadingLanguageVersion > 120 ) { - str = "#define IN in\n" + str += "#define IN in\n" "#define OUT(mode) mode out\n" "#define textureCube texture\n" "#define texture2D texture\n" "#define texture2DProj textureProj\n" "#define texture3D texture\n"; } else { - str = "#define IN attribute\n" + str += "#define IN attribute\n" "#define OUT(mode) varying\n"; } @@ -582,25 +629,35 @@ static std::string GenVertexHeader() { AddDefine( str, "BIND_LIGHTMAP_DATA", BufferBind::LIGHTMAP_DATA ); } + str += +R"(#endif // GENERATED_VERTEX_HEADER + +)"; + return str; } static std::string GenFragmentHeader() { std::string str; + str += +R"(#if !defined(GENERATED_FRAGMENT_HEADER) +#define GENERATED_FRAGMENT_HEADER +)"; + // Fragment shader compatibility defines if( glConfig.shadingLanguageVersion > 120 ) { - str = "#define IN(mode) mode in\n" + str += "#define IN(mode) mode in\n" "#define DECLARE_OUTPUT(type) out type outputColor;\n" "#define textureCube texture\n" "#define texture2D texture\n" "#define texture2DProj textureProj\n" "#define texture3D texture\n"; } else if( glConfig.gpuShader4Available) { - str = "#define IN(mode) varying\n" + str += "#define IN(mode) varying\n" "#define DECLARE_OUTPUT(type) varying out type outputColor;\n"; } else { - str = "#define IN(mode) varying\n" + str += "#define IN(mode) varying\n" "#define outputColor gl_FragColor\n" "#define DECLARE_OUTPUT(type) /* empty*/\n"; } @@ -631,12 +688,22 @@ static std::string GenFragmentHeader() { AddDefine( str, "USE_PUSH_BUFFER", 1 ); } + str += +R"(#endif // GENERATED_FRAGMENT_HEADER + +)"; + return str; } static std::string GenComputeHeader() { std::string str; + str += +R"(#if !defined(GENERATED_COMPUTE_HEADER) +#define GENERATED_COMPUTE_HEADER +)"; + // Compute shader compatibility defines if ( glConfig.usingMaterialSystem ) { AddDefine( str, "MAX_VIEWS", MAX_VIEWS ); @@ -660,6 +727,11 @@ static std::string GenComputeHeader() { AddDefine( str, "USE_PUSH_BUFFER", 1 ); } + str += +R"(#endif // GENERATED_COMPUTE_HEADER + +)"; + return str; } @@ -902,11 +974,7 @@ static bool IsUnusedPermutation( const char *compileMacros ) return false; } -void GLShaderManager::BuildShader( ShaderDescriptor* descriptor ) { - if ( descriptor->id ) { - return; - } - +void GLShaderManager::BuildShader( ShaderDescriptor* descriptor, bool force ) { const int start = Sys::Milliseconds(); const GLchar* text[1] = { descriptor->shaderSource.data() }; @@ -916,29 +984,32 @@ void GLShaderManager::BuildShader( ShaderDescriptor* descriptor ) { GL_CheckErrors(); glShaderSource( shader, 1, text, length ); - glCompileShader( shader ); - GL_CheckErrors(); + if ( glConfig.incrementalShaderCompilation || force ) { + glCompileShader( shader ); - GLint compiled; - glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled ); + GL_CheckErrors(); - if ( !compiled ) { - std::string log = GetInfoLog( shader ); - std::vector infoLog = ParseInfoLog( log ); - PrintShaderSource( descriptor->name, shader, infoLog ); + GLint compiled; + glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled ); - Log::Warn( "Compile log:\n%s", log ); + if ( !compiled ) { + std::string log = GetInfoLog( shader ); + std::vector infoLog = ParseInfoLog( log ); + PrintShaderSource( descriptor->name, shader, infoLog ); - switch ( descriptor->type ) { - case GL_VERTEX_SHADER: - ThrowShaderError( Str::Format( "Couldn't compile vertex shader: %s", descriptor->name ) ); - case GL_FRAGMENT_SHADER: - ThrowShaderError( Str::Format( "Couldn't compile fragment shader: %s", descriptor->name ) ); - case GL_COMPUTE_SHADER: - ThrowShaderError( Str::Format( "Couldn't compile compute shader: %s", descriptor->name ) ); - default: - break; + Log::Warn( "Compile log:\n%s", log ); + + switch ( descriptor->type ) { + case GL_VERTEX_SHADER: + ThrowShaderError( Str::Format( "Couldn't compile vertex shader: %s", descriptor->name ) ); + case GL_FRAGMENT_SHADER: + ThrowShaderError( Str::Format( "Couldn't compile fragment shader: %s", descriptor->name ) ); + case GL_COMPUTE_SHADER: + ThrowShaderError( Str::Format( "Couldn't compile compute shader: %s", descriptor->name ) ); + default: + break; + } } } @@ -947,7 +1018,10 @@ void GLShaderManager::BuildShader( ShaderDescriptor* descriptor ) { const int time = Sys::Milliseconds() - start; compileTime += time; compileCount++; - Log::Debug( "Compilation: %i", time ); + + if ( glConfig.incrementalShaderCompilation || force ) { + Log::Debug( "Compilation: %i", time ); + } } void GLShaderManager::BuildShaderProgram( ShaderProgramDescriptor* descriptor ) { @@ -955,18 +1029,91 @@ void GLShaderManager::BuildShaderProgram( ShaderProgramDescriptor* descriptor ) return; } - const int start = Sys::Milliseconds(); + int start = Sys::Milliseconds(); GLuint program = glCreateProgram(); GL_CheckErrors(); - for ( const GLuint& shader : descriptor->shaders ) { - if ( shader ) { - glAttachShader( program, shader ); - } else { - break; + if ( glConfig.incrementalShaderCompilation ) { + for ( const GLuint& shader : descriptor->shaders ) { + if ( shader ) { + glAttachShader( program, shader ); + } else { + break; + } + } + } + else { + std::unordered_map concatenatedDescriptor = { + { GL_FRAGMENT_SHADER, {} }, + { GL_VERTEX_SHADER, {} }, + { GL_COMPUTE_SHADER, {} }, + }; + + std::unordered_map shaderTypeName = { + { GL_FRAGMENT_SHADER, "fragment" }, + { GL_VERTEX_SHADER, "vertex" }, + { GL_COMPUTE_SHADER, "compute" }, + }; + + for ( const GLuint& shader : descriptor->shaders ) { + if ( shader ) { + GLint shaderType; + glGetShaderiv(shader, GL_SHADER_TYPE, &shaderType); + + int maxLength; + int actualLength; + glGetShaderiv( shader, GL_SHADER_SOURCE_LENGTH, &maxLength ); + GLchar* shaderSource = new GLchar[ maxLength ]; + glGetShaderSource( shader, maxLength, &actualLength, shaderSource ); + + ShaderDescriptor &concatenated = concatenatedDescriptor[ shaderType ]; + + // If first unit of the shader. + if ( concatenated.type == 0 ) { + concatenated.shaderSource = GenVersionLine(); + } + + concatenated.type = shaderType; + concatenated.shaderSource.append( shaderSource, actualLength ); + + delete[] shaderSource; + } else { + break; + } + } + + for ( auto &pair : concatenatedDescriptor ) + { + ShaderDescriptor &concatenated = pair.second; + + if ( concatenated.type != 0 ) + { + Log::Debug( "Building concatenated %s program.", shaderTypeName[ concatenated.type ] ); + // WIP + // Log::Warn( "Concatenated source:\n<<<\n%s\n>>>", concatenated.shaderSource ); + + GLShaderManager::BuildShader( &concatenated, true ); + } + } + + // Reset the attach & link timer, we wasted it when compiling shaders. + start = Sys::Milliseconds(); + + for ( auto &pair : concatenatedDescriptor ) + { + ShaderDescriptor &concatenated = pair.second; + + if ( concatenated.type != 0 ) + { + if ( concatenated.id ) + { + glAttachShader( program, concatenated.id ); + } + } } } + GL_CheckErrors(); BindAttribLocations( program ); @@ -1667,7 +1814,7 @@ std::string GLShaderManager::ShaderPostProcess( GLShader *shader, const std::str " uvec2 u_GlowMap;\n" "};\n\n" + texBuf + - "#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" + "#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" "#define u_DiffuseMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_DiffuseMap\n" "#define u_NormalMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_NormalMap\n" "#define u_HeightMap_initial texData[( baseInstance >> 12 ) & 0xFFF].u_HeightMap\n" @@ -2441,7 +2588,8 @@ GLShader_generic::GLShader_generic() : false, "generic", "generic" ), u_ColorMap( this ), u_DepthMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_ViewOrigin( this ), u_AlphaThreshold( this ), u_ModelMatrix( this ), @@ -2475,7 +2623,8 @@ GLShader_genericMaterial::GLShader_genericMaterial() : true, "generic", "generic" ), u_ColorMap( this ), u_DepthMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_ViewOrigin( this ), u_AlphaThreshold( this ), u_ModelMatrix( this ), @@ -2508,7 +2657,8 @@ GLShader_lightMapping::GLShader_lightMapping() : u_LightGrid1( this ), u_LightGrid2( this ), u_LightTiles( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_SpecularExponent( this ), u_ColorModulateColorGen_Float( this ), u_ColorModulateColorGen_Uint( this ), @@ -2575,7 +2725,8 @@ GLShader_lightMappingMaterial::GLShader_lightMappingMaterial() : u_LightGrid1( this ), u_LightGrid2( this ), u_LightTiles( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_SpecularExponent( this ), u_ColorModulateColorGen_Uint( this ), u_Color_Uint( this ), @@ -2612,7 +2763,8 @@ GLShader_reflection::GLShader_reflection(): u_ColorMapCube( this ), u_NormalMap( this ), u_HeightMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_ViewOrigin( this ), u_ModelMatrix( this ), u_ModelViewProjectionMatrix( this ), @@ -2643,7 +2795,8 @@ GLShader_reflectionMaterial::GLShader_reflectionMaterial() : u_ColorMapCube( this ), u_NormalMap( this ), u_HeightMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_ViewOrigin( this ), u_ModelMatrix( this ), u_ModelViewProjectionMatrix( this ), @@ -2661,7 +2814,8 @@ GLShader_skybox::GLShader_skybox() : false, "skybox", "skybox" ), u_ColorMapCube( this ), u_CloudMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_CloudHeight( this ), u_UseCloudMap( this ), u_AlphaThreshold( this ), @@ -2680,7 +2834,8 @@ GLShader_skyboxMaterial::GLShader_skyboxMaterial() : true, "skybox", "skybox" ), u_ColorMapCube( this ), u_CloudMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_CloudHeight( this ), u_UseCloudMap( this ), u_AlphaThreshold( this ), @@ -2742,7 +2897,8 @@ GLShader_heatHaze::GLShader_heatHaze() : false, "heatHaze", "heatHaze" ), u_CurrentMap( this ), u_NormalMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_DeformMagnitude( this ), u_ModelViewProjectionMatrix( this ), u_ModelViewMatrixTranspose( this ), @@ -2767,7 +2923,8 @@ GLShader_heatHazeMaterial::GLShader_heatHazeMaterial() : true, "heatHaze", "heatHaze" ), u_CurrentMap( this ), u_NormalMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_DeformEnable( this ), u_DeformMagnitude( this ), u_ModelViewProjectionMatrix( this ), @@ -2870,7 +3027,8 @@ GLShader_liquid::GLShader_liquid() : u_LightGrid1( this ), u_LightGrid2( this ), u_HeightMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_ViewOrigin( this ), u_RefractionIndex( this ), u_ModelMatrix( this ), @@ -2914,7 +3072,8 @@ GLShader_liquidMaterial::GLShader_liquidMaterial() : u_LightGrid1( this ), u_LightGrid2( this ), u_HeightMap( this ), - u_TextureMatrix( this ), + u_TextureMatrix_Matrix3( this ), + u_TextureMatrix_Matrix32( this ), u_ViewOrigin( this ), u_RefractionIndex( this ), u_ModelMatrix( this ), @@ -3096,4 +3255,4 @@ GlobalUBOProxy::GlobalUBOProxy() : u_Tonemap( this ), u_TonemapParms( this ), u_Exposure( this ) { -} \ No newline at end of file +} diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index f6fe35dc65..298044f610 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -532,7 +532,7 @@ class GLShaderManager { int cacheSaveTime; uint32_t cacheSaveCount; - void BuildShader( ShaderDescriptor* descriptor ); + void BuildShader( ShaderDescriptor* descriptor, bool force = false ); void BuildShaderProgram( ShaderProgramDescriptor* descriptor ); std::string GetDeformShaderName( const int index ); @@ -801,6 +801,24 @@ class GLUniformMatrix4f : protected GLUniform } }; +class GLUniformMatrix3f : protected GLUniform +{ +protected: + GLUniformMatrix3f( GLShader *shader, const char *name, const UpdateType updateType ) : + GLUniform( shader, name, "mat3", 9, 4, updateType ) { + } + + inline void SetValue( GLboolean transpose, const matrix_t m ) + { + if ( !CacheValue( ( void* ) m ) ) { + return; + } + + ShaderProgramDescriptor* p = _shader->GetProgram(); + glUniformMatrix3fv( p->uniformLocations[ _locationIndex ], 1, transpose, m ); + } +}; + class GLUniformMatrix32f : protected GLUniform { protected: GLUniformMatrix32f( GLShader* shader, const char* name, const UpdateType updateType ) : @@ -1671,16 +1689,41 @@ class u_CurrentMap : } }; -class u_TextureMatrix : +class u_TextureMatrix_Matrix3 : + GLUniformMatrix3f +{ +public: + u_TextureMatrix_Matrix3( GLShader *shader ) : + GLUniformMatrix3f( shader, "u_TextureMatrix", TEXDATA_OR_PUSH ) + { + } + + void SetUniform_TextureMatrix_Matrix3( const matrix_t m ) + { + vec_t m2[9]; + m2[0] = m[0]; + m2[1] = m[1]; + m2[2] = 0; + m2[3] = m[4]; + m2[4] = m[5]; + m2[5] = 0; + m2[6] = m[12]; + m2[7] = m[13]; + m2[8] = 1; + this->SetValue( GL_FALSE, m2 ); + } +}; + +class u_TextureMatrix_Matrix32 : GLUniformMatrix32f { public: - u_TextureMatrix( GLShader *shader ) : + u_TextureMatrix_Matrix32( GLShader *shader ) : GLUniformMatrix32f( shader, "u_TextureMatrix", TEXDATA_OR_PUSH ) { } - void SetUniform_TextureMatrix( const matrix_t m ) + void SetUniform_TextureMatrix_Matrix32( const matrix_t m ) { /* We only actually need these 6 components to get the correct texture transformation, the other ones are unused */ @@ -1695,6 +1738,18 @@ class u_TextureMatrix : } }; +template void SetUniform_TextureMatrix( Shader* shader, const matrix_t m ) +{ + if ( glConfig.mat3x2Available ) + { + shader->SetUniform_TextureMatrix_Matrix32( m ); + } + else + { + shader->SetUniform_TextureMatrix_Matrix3( m ); + } +} + class u_AlphaThreshold : GLUniform1f { @@ -2933,7 +2988,8 @@ class GLShader_generic : public GLShader, public u_ColorMap, public u_DepthMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_ViewOrigin, public u_AlphaThreshold, public u_ModelMatrix, @@ -2963,7 +3019,8 @@ class GLShader_genericMaterial : public GLShader, public u_ColorMap, public u_DepthMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_ViewOrigin, public u_AlphaThreshold, public u_ModelMatrix, @@ -2997,7 +3054,8 @@ class GLShader_lightMapping : public u_LightGrid1, public u_LightGrid2, public u_LightTiles, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_SpecularExponent, public u_ColorModulateColorGen_Float, public u_ColorModulateColorGen_Uint, @@ -3050,7 +3108,8 @@ class GLShader_lightMappingMaterial : public u_LightGrid1, public u_LightGrid2, public u_LightTiles, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_SpecularExponent, public u_ColorModulateColorGen_Uint, public u_Color_Uint, @@ -3088,7 +3147,8 @@ class GLShader_reflection : public u_ColorMapCube, public u_NormalMap, public u_HeightMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_ViewOrigin, public u_ModelMatrix, public u_ModelViewProjectionMatrix, @@ -3114,7 +3174,8 @@ class GLShader_reflectionMaterial : public u_ColorMapCube, public u_NormalMap, public u_HeightMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_ViewOrigin, public u_ModelMatrix, public u_ModelViewProjectionMatrix, @@ -3133,7 +3194,8 @@ class GLShader_skybox : public GLShader, public u_ColorMapCube, public u_CloudMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_CloudHeight, public u_UseCloudMap, public u_AlphaThreshold, @@ -3148,7 +3210,8 @@ class GLShader_skyboxMaterial : public GLShader, public u_ColorMapCube, public u_CloudMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_CloudHeight, public u_UseCloudMap, public u_AlphaThreshold, @@ -3209,7 +3272,8 @@ class GLShader_heatHaze : public GLShader, public u_CurrentMap, public u_NormalMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_DeformMagnitude, public u_ModelViewProjectionMatrix, public u_ModelViewMatrixTranspose, @@ -3230,7 +3294,8 @@ class GLShader_heatHazeMaterial : public GLShader, public u_CurrentMap, public u_NormalMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_DeformEnable, public u_DeformMagnitude, public u_ModelViewProjectionMatrix, @@ -3319,7 +3384,8 @@ class GLShader_liquid : public u_LightGrid1, public u_LightGrid2, public u_HeightMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_ViewOrigin, public u_RefractionIndex, public u_ModelMatrix, @@ -3355,7 +3421,8 @@ class GLShader_liquidMaterial : public u_LightGrid1, public u_LightGrid2, public u_HeightMap, - public u_TextureMatrix, + public u_TextureMatrix_Matrix3, + public u_TextureMatrix_Matrix32, public u_ViewOrigin, public u_RefractionIndex, public u_ModelMatrix, diff --git a/src/engine/renderer/glsl_source/cameraEffects_fp.glsl b/src/engine/renderer/glsl_source/cameraEffects_fp.glsl index cfc557a35f..e2a1dc8e58 100644 --- a/src/engine/renderer/glsl_source/cameraEffects_fp.glsl +++ b/src/engine/renderer/glsl_source/cameraEffects_fp.glsl @@ -54,6 +54,8 @@ void convertToSRGB(inout vec3 color) { #endif } +uniform float u_Exposure; + // Tone mapping is not available when high-precision float framebuffer isn't enabled or supported. #if defined(r_highPrecisionRendering) && defined(HAVE_ARB_texture_float) /* x: contrast @@ -62,7 +64,6 @@ z: shoulderClip w: highlightsCompression */ uniform bool u_Tonemap; uniform vec4 u_TonemapParms; -uniform float u_Exposure; vec3 TonemapLottes( vec3 color ) { // Lottes 2016, "Advanced Techniques and Optimization of HDR Color Pipelines" diff --git a/src/engine/renderer/glsl_source/common.glsl b/src/engine/renderer/glsl_source/common.glsl index e90fd5474b..1b15991fe1 100644 --- a/src/engine/renderer/glsl_source/common.glsl +++ b/src/engine/renderer/glsl_source/common.glsl @@ -109,7 +109,7 @@ ModBits_t ColorModulateToBits( const in colorModulatePack colorMod ) #if defined(HAVE_EXT_gpu_shader4) modBits.useVertexLightFactor = bool( ( colorMod >> 27u ) & 1u ); #else - modBits.useVertexLightFactor = colorMod.g < 0; + modBits.useVertexLightFactor = colorMod.g < 0.0; #endif return modBits; @@ -154,7 +154,7 @@ void ColorModulateColor_lightFactor( ModBits_t modBits = ColorModulateToBits( colorMod ); float lightFactor = ColorModulateToLightFactor( colorMod ); - colorModulation.rgb += vec3( modBits.useVertexLightFactor ? lightFactor : 0 ); + colorModulation.rgb += vec3( modBits.useVertexLightFactor ? lightFactor : 0.0 ); vec4 unpackedColor = UnpackColor( packedColor ); diff --git a/src/engine/renderer/glsl_source/fogQuake3_fp.glsl b/src/engine/renderer/glsl_source/fogQuake3_fp.glsl index e76ea8c5a5..39fb6a43df 100644 --- a/src/engine/renderer/glsl_source/fogQuake3_fp.glsl +++ b/src/engine/renderer/glsl_source/fogQuake3_fp.glsl @@ -39,15 +39,15 @@ void main() #insert material_fp float s = length(var_ScaledViewerOffset); - float t = step( 0, var_FogPlaneDistance ); + float t = step( 0.0, var_FogPlaneDistance ); - if ( u_FogEyeT < 0 ) // eye outside fog + if ( u_FogEyeT < 0.0 ) // eye outside fog { // fraction of the viewer-to-vertex ray which is inside fog - t *= var_FogPlaneDistance / ( max( 0, var_FogPlaneDistance ) - u_FogEyeT ); + t *= var_FogPlaneDistance / ( max( 0.0, var_FogPlaneDistance ) - u_FogEyeT ); } - vec4 color = vec4(1, 1, 1, GetFogAlpha(s, t)); + vec4 color = vec4(1.0, 1.0, 1.0, GetFogAlpha(s, t)); color *= var_Color; diff --git a/src/engine/renderer/glsl_source/generic_vp.glsl b/src/engine/renderer/glsl_source/generic_vp.glsl index b455ad39ee..b91594828e 100644 --- a/src/engine/renderer/glsl_source/generic_vp.glsl +++ b/src/engine/renderer/glsl_source/generic_vp.glsl @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #insert shaderProfiler_vp #if !defined(USE_MATERIAL_SYSTEM) - uniform mat3x2 u_TextureMatrix; + uniform textureMatrix u_TextureMatrix; #endif uniform vec3 u_ViewOrigin; diff --git a/src/engine/renderer/glsl_source/heatHaze_vp.glsl b/src/engine/renderer/glsl_source/heatHaze_vp.glsl index 54b7b97206..869daa0297 100644 --- a/src/engine/renderer/glsl_source/heatHaze_vp.glsl +++ b/src/engine/renderer/glsl_source/heatHaze_vp.glsl @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA uniform float u_Time; #if !defined(USE_MATERIAL_SYSTEM) - uniform mat3x2 u_TextureMatrix; + uniform textureMatrix u_TextureMatrix; #endif uniform mat4 u_ProjectionMatrixTranspose; diff --git a/src/engine/renderer/glsl_source/lightMapping_fp.glsl b/src/engine/renderer/glsl_source/lightMapping_fp.glsl index da72f901e2..f5d22d49f9 100644 --- a/src/engine/renderer/glsl_source/lightMapping_fp.glsl +++ b/src/engine/renderer/glsl_source/lightMapping_fp.glsl @@ -46,10 +46,12 @@ IN(smooth) vec3 var_Binormal; IN(smooth) vec3 var_Normal; uniform sampler2D u_LightMap; -uniform sampler3D u_LightGrid1; - uniform sampler2D u_DeluxeMap; -uniform sampler3D u_LightGrid2; + +#if defined(HAVE_texture3D) + uniform sampler3D u_LightGrid1; + uniform sampler3D u_LightGrid2; +#endif #if defined(USE_LIGHT_MAPPING) || defined(USE_DELUXE_MAPPING) IN(smooth) vec2 var_TexLight; @@ -157,9 +159,15 @@ void main() #else // Compute light color from lightgrid. vec3 ambientColor, lightColor; - ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), lightFactor, ambientColor, lightColor); + #if HAVE_texture3D + ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), lightFactor, ambientColor, lightColor); - color.rgb = ambientColor * r_AmbientScale * diffuse.rgb; + color.rgb = ambientColor * r_AmbientScale * diffuse.rgb; + #else + ambientColor = vec3(1.0); + lightColor = vec3(1.0); + color.rgb = diffuse.rgb; + #endif #endif #if defined(USE_LIGHT_MAPPING) && defined(USE_DELUXE_MAPPING) diff --git a/src/engine/renderer/glsl_source/lightMapping_vp.glsl b/src/engine/renderer/glsl_source/lightMapping_vp.glsl index 125ff94070..08879e19aa 100644 --- a/src/engine/renderer/glsl_source/lightMapping_vp.glsl +++ b/src/engine/renderer/glsl_source/lightMapping_vp.glsl @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #endif #if !defined(USE_MATERIAL_SYSTEM) - uniform mat3x2 u_TextureMatrix; + uniform textureMatrix u_TextureMatrix; #endif #if defined(USE_MODEL_SURFACE) diff --git a/src/engine/renderer/glsl_source/liquid_fp.glsl b/src/engine/renderer/glsl_source/liquid_fp.glsl index 5e918c3b41..cf2103bac4 100644 --- a/src/engine/renderer/glsl_source/liquid_fp.glsl +++ b/src/engine/renderer/glsl_source/liquid_fp.glsl @@ -47,8 +47,11 @@ uniform float u_FresnelBias; uniform mat4 u_ModelMatrix; uniform mat4 u_UnprojectMatrix; -uniform sampler3D u_LightGrid1; -uniform sampler3D u_LightGrid2; +#if HAVE_texture3D + uniform sampler3D u_LightGrid1; + uniform sampler3D u_LightGrid2; +#endif + uniform vec3 u_LightGridOrigin; uniform vec3 u_LightGridScale; @@ -146,8 +149,12 @@ void main() #endif // compute light direction in world space - vec4 texel = texture3D(u_LightGrid2, lightGridPos); - vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0)); + #if HAVE_texture3D + vec4 texel = texture3D(u_LightGrid2, lightGridPos); + vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0)); + #else + vec3 lightDir = vec3(1.0); + #endif vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/src/engine/renderer/glsl_source/liquid_vp.glsl b/src/engine/renderer/glsl_source/liquid_vp.glsl index 08f3ee2626..ad6bbca23f 100644 --- a/src/engine/renderer/glsl_source/liquid_vp.glsl +++ b/src/engine/renderer/glsl_source/liquid_vp.glsl @@ -29,7 +29,7 @@ IN vec3 attr_Binormal; IN vec3 attr_Normal; #if !defined(USE_MATERIAL_SYSTEM) - uniform mat3x2 u_TextureMatrix; + uniform textureMatrix u_TextureMatrix; #endif uniform mat4 u_ModelMatrix; diff --git a/src/engine/renderer/glsl_source/reflection_CB_vp.glsl b/src/engine/renderer/glsl_source/reflection_CB_vp.glsl index b87dc20fe5..0473767b5f 100644 --- a/src/engine/renderer/glsl_source/reflection_CB_vp.glsl +++ b/src/engine/renderer/glsl_source/reflection_CB_vp.glsl @@ -27,7 +27,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #insert vertexAnimation_vp #if !defined(USE_MATERIAL_SYSTEM) - uniform mat3x2 u_TextureMatrix; + uniform textureMatrix u_TextureMatrix; +#endif #endif uniform mat4 u_ModelMatrix; diff --git a/src/engine/renderer/glsl_source/skybox_fp.glsl b/src/engine/renderer/glsl_source/skybox_fp.glsl index 4a4bd38250..9a453de5c0 100644 --- a/src/engine/renderer/glsl_source/skybox_fp.glsl +++ b/src/engine/renderer/glsl_source/skybox_fp.glsl @@ -34,7 +34,7 @@ uniform bool u_UseCloudMap; uniform float u_CloudHeight; #if !defined(USE_MATERIAL_SYSTEM) - uniform mat3x2 u_TextureMatrix; + uniform textureMatrix u_TextureMatrix; #endif uniform float u_AlphaThreshold; diff --git a/src/engine/renderer/glsl_source/vertexAnimation_vp.glsl b/src/engine/renderer/glsl_source/vertexAnimation_vp.glsl index a730672daa..94157be30c 100644 --- a/src/engine/renderer/glsl_source/vertexAnimation_vp.glsl +++ b/src/engine/renderer/glsl_source/vertexAnimation_vp.glsl @@ -41,7 +41,7 @@ void VertexAnimation_P_N( vec3 fromPosition, vec3 toPosition, vec3 toNormal = QuatTransVec( toQTangent, vec3( 0.0, 0.0, 1.0 ) ); position.xyz = 512.0 * mix(fromPosition, toPosition, frac); - position.w = 1; + position.w = 1.0; normal = normalize(mix(fromNormal, toNormal, frac)); } @@ -58,7 +58,7 @@ void VertexFetch(out vec4 position, QTangentToLocalBasis( attr_QTangent2, toLB ); position.xyz = 512.0 * mix(attr_Position, attr_Position2, u_VertexInterpolation); - position.w = 1; + position.w = 1.0; LB.normal = normalize(mix(fromLB.normal, toLB.normal, u_VertexInterpolation)); LB.tangent = normalize(mix(fromLB.tangent, toLB.tangent, u_VertexInterpolation)); diff --git a/src/engine/renderer/tr_backend.cpp b/src/engine/renderer/tr_backend.cpp index 41f26a2de6..15a35b5754 100644 --- a/src/engine/renderer/tr_backend.cpp +++ b/src/engine/renderer/tr_backend.cpp @@ -1241,7 +1241,7 @@ void RB_RunVisTests( ) gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] ); + SetUniform_TextureMatrix( gl_genericShader, tess.svars.texMatrices[ TB_COLORMAP ] ); GL_State( GLS_DEPTHTEST_DISABLE | GLS_COLORMASK_BITS ); glBeginQuery( GL_SAMPLES_PASSED, testState->hQueryRef ); @@ -1806,7 +1806,7 @@ static void RB_RenderDebugUtils() gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); ent = backEnd.refdef.entities; @@ -1880,7 +1880,7 @@ static void RB_RenderDebugUtils() GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); ent = backEnd.refdef.entities; @@ -2171,7 +2171,7 @@ static void RB_RenderDebugUtils() gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); GL_State( GLS_POLYMODE_LINE | GLS_DEPTHFUNC_ALWAYS ); @@ -2254,7 +2254,7 @@ static void RB_RenderDebugUtils() gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1, 0 ); GL_CheckErrors(); @@ -2335,7 +2335,7 @@ static void RB_RenderDebugUtils() gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); GL_CheckErrors(); @@ -2429,7 +2429,7 @@ static void RB_RenderDebugUtils() gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); gl_genericShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[ glState.stackIndex ] ); @@ -2635,7 +2635,7 @@ void DebugDrawBegin( debugDrawMode_t mode, float size ) { gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); // render in world space backEnd.orientation = backEnd.viewParms.world; @@ -3791,7 +3791,7 @@ void RB_ShowImages() // set uniforms gl_genericShader->SetUniform_AlphaTest( GLS_ATEST_NONE ); SetUniform_ColorModulateColorGen( gl_genericShader, colorGen_t::CGEN_VERTEX, alphaGen_t::AGEN_VERTEX ); - gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); + SetUniform_TextureMatrix( gl_genericShader, matrixIdentity ); GL_SelectTexture( 0 ); diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index d03844d401..4ecbd99cd0 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -3421,7 +3421,7 @@ R_LoadLightGrid */ void R_LoadLightGrid( lump_t *l ) { - if ( glConfig.max3DTextureSize == 0 ) + if ( !glConfig.texture3DAvailable ) { Log::Warn( "Grid lighting disabled because of missing 3D texture support." ); diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index 7d1a1d5c15..a541aa27d8 100644 --- a/src/engine/renderer/tr_shade.cpp +++ b/src/engine/renderer/tr_shade.cpp @@ -58,7 +58,7 @@ static void EnableAvailableFeatures() glConfig.realtimeLighting = false; } - if ( glConfig.max3DTextureSize == 0 ) + if ( !glConfig.texture3DAvailable ) { Log::Warn( "Tiled dynamic light renderer disabled because of missing 3D texture support." ); glConfig.realtimeLighting = false; @@ -88,7 +88,7 @@ static void EnableAvailableFeatures() if ( glConfig.colorGrading ) { - if ( glConfig.max3DTextureSize == 0 ) + if ( !glConfig.texture3DAvailable ) { Log::Warn( "Color grading disabled because of missing 3D texture support." ); glConfig.colorGrading = false; @@ -693,7 +693,7 @@ static void DrawTris() gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); - gl_genericShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] ); + SetUniform_TextureMatrix( gl_genericShader, tess.svars.texMatrices[ TB_COLORMAP ] ); gl_genericShader->SetRequiredVertexPointers(); glDepthRange( 0, 0 ); @@ -959,7 +959,7 @@ void Render_generic3D( shaderStage_t *pStage ) gl_genericShader->SetUniform_ColorMapBindless( BindAnimatedImage( 0, &pStage->bundle[TB_COLORMAP] ) ); } - gl_genericShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] ); + SetUniform_TextureMatrix( gl_genericShader, tess.svars.texMatrices[ TB_COLORMAP ] ); if ( hasDepthFade ) { @@ -1138,7 +1138,7 @@ void Render_lightMapping( shaderStage_t *pStage ) if ( pStage->type != stageType_t::ST_LIGHTMAP ) { - gl_lightMappingShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_DIFFUSEMAP ] ); + SetUniform_TextureMatrix( gl_lightMappingShader, tess.svars.texMatrices[ TB_DIFFUSEMAP ] ); } // bind u_NormalMap @@ -1329,7 +1329,7 @@ void Render_reflection_CB( shaderStage_t *pStage ) gl_reflectionShader->SetUniform_NormalScale( normalScale ); } - gl_reflectionShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_NORMALMAP ] ); + SetUniform_TextureMatrix( gl_reflectionShader, tess.svars.texMatrices[ TB_NORMALMAP ] ); // bind u_HeightMap u_depthScale u_reliefOffsetBias if ( pStage->enableReliefMapping ) @@ -1486,7 +1486,7 @@ void Render_heatHaze( shaderStage_t *pStage ) if ( pStage->enableNormalMapping ) { - gl_heatHazeShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_NORMALMAP ] ); + SetUniform_TextureMatrix( gl_heatHazeShader, tess.svars.texMatrices[ TB_NORMALMAP ] ); vec3_t normalScale; SetNormalScale( pStage, normalScale ); @@ -1606,7 +1606,7 @@ void Render_liquid( shaderStage_t *pStage ) gl_liquidShader->SetUniform_NormalScale( normalScale ); } - gl_liquidShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_NORMALMAP ] ); + SetUniform_TextureMatrix( gl_liquidShader, tess.svars.texMatrices[ TB_NORMALMAP ] ); Tess_DrawElements(); diff --git a/src/engine/renderer/tr_sky.cpp b/src/engine/renderer/tr_sky.cpp index 6dbcbf99ca..f00906d589 100644 --- a/src/engine/renderer/tr_sky.cpp +++ b/src/engine/renderer/tr_sky.cpp @@ -145,7 +145,7 @@ void Tess_StageIteratorSky() Tess_ComputeTexMatrices( pStage ); - gl_skyboxShader->SetUniform_TextureMatrix( tess.svars.texMatrices[TB_COLORMAP] ); + SetUniform_TextureMatrix( gl_skyboxShader, tess.svars.texMatrices[TB_COLORMAP] ); gl_skyboxShader->SetUniform_CloudMapBindless( GL_BindToTMU( 1, pStage->bundle[TB_COLORMAP].image[0] ) diff --git a/src/engine/sys/sdl_glimp.cpp b/src/engine/sys/sdl_glimp.cpp index f3e17e7bb3..a6018bbf4c 100644 --- a/src/engine/sys/sdl_glimp.cpp +++ b/src/engine/sys/sdl_glimp.cpp @@ -57,6 +57,18 @@ static Cvar::Range> r_glDebugSeverity( "minimum severity of r_glDebugProfile messages (1=NOTIFICATION, 2=LOW, 3=MEDIUM, 4=HIGH)", Cvar::NONE, 2, 1, 4); +static Cvar::Cvar r_incrementalShaderCompilation( + "r_incrementalShaderCompilation", "Build separate shader units then link them alltogether at the end", + Cvar::NONE, true ); + +static Cvar::Cvar r_useTexture3D( + "r_useTexture3D", "Use texture3D image format and sampler3D GLSL keyword", + Cvar::CHEAT, true ); + +static Cvar::Cvar r_useMat3x2( + "r_useMat3x2", "Use mat3x2 GLSL type", + Cvar::NONE, true ); + // OpenGL extension cvars. /* Driver bug: Mesa versions > 24.0.9 produce garbage rendering when bindless textures are enabled, and the shader compiler crashes with material shaders @@ -137,6 +149,22 @@ static Cvar::Cvar workaround_glDriver_amd_oglp_disableBindlessTexture( "workaround.glDriver.amd.oglp.disableBindlessTexture", "Disable ARB_bindless_texture on AMD OGLP driver", Cvar::NONE, true ); +static Cvar::Cvar workaround_glDriver_gl4es_assumeSmoothstep( + "workaround.glDriver.gl4es.assumeSmoothstep", + "Assume smoothstep is always declared on GL4ES", + Cvar::NONE, true ); +static Cvar::Cvar workaround_glDriver_gl4es_disableIncrementalShaderCompilation( + "workaround.glDriver.gl4es.disableIncrementalShaderCompilation", + "Disable incremental shader compilation on GL4ES", + Cvar::NONE, true ); +static Cvar::Cvar workaround_glDriver_gl4es_disableMat3x2( + "workaround.glDriver.gl4es.disableMat3x2", + "Disable mat3x2 GLSL support on GL4ES", + Cvar::NONE, true ); +static Cvar::Cvar workaround_glDriver_gl4es_disableTexture3D( + "workaround.glDriver.gl4es.disableTexture3D", + "Disable texture3D support on GL4ES", + Cvar::NONE, true ); static Cvar::Cvar workaround_glDriver_mesa_ati_rv300_useFloatVertex( "workaround.glDriver.mesa.ati.rv300.useFloatVertex", "Use float vertex instead of supported-but-slower half-float vertex on Mesa driver on ATI RV300 hardware", @@ -2072,6 +2100,34 @@ static void GLimp_InitExtensions() logger.Notice("...using shading language version %i", glConfig.shadingLanguageVersion ); + glConfig.incrementalShaderCompilation = r_incrementalShaderCompilation.Get(); + + glConfig.mat3x2Available = r_useMat3x2.Get(); + + if ( glConfig.driverVendor == glDriverVendor_t::GL4ES ) + { + if ( glConfig.shadingLanguageVersion <= 120 + && workaround_glDriver_gl4es_assumeSmoothstep.Get() ) + { + logger.Notice( "Found GLSL 1.20 on GL4ES translation layer, assuming smoothstep() is always declared." ); + glConfig.assumeSmoothstep = true; + } + + if ( glConfig.incrementalShaderCompilation + && workaround_glDriver_gl4es_disableIncrementalShaderCompilation.Get() ) + { + logger.Notice( "Found GL4ES translation layer with OpenGL ES backend, disable incremental shader compilation." ); + glConfig.incrementalShaderCompilation = false; + } + + if ( glConfig.mat3x2Available + && workaround_glDriver_gl4es_disableMat3x2.Get() ) + { + logger.Notice( "Found GL4ES translation layer with OpenGL ES backend, disable mat3x2 GLSL support." ); + glConfig.mat3x2Available = false; + } + } + // OpenGL driver constants. @@ -2084,6 +2140,8 @@ static void GLimp_InitExtensions() // Stubbed or broken drivers may report garbage. + glConfig.texture3DAvailable = r_useTexture3D.Get(); + if ( glConfig.maxTextureUnits < 0 ) { Log::Warn( "Bad GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value: %d", glConfig.maxTextureUnits ); @@ -2108,8 +2166,37 @@ static void GLimp_InitExtensions() glConfig.maxCubeMapTextureSize = 0; } + if ( glConfig.max3DTextureSize > 0 ) + { + glConfig.texture3DAvailable = true; + } + else + { + logger.Warn( "Missing 3D texture support because of null max size" ); + } + + if ( glConfig.driverVendor == glDriverVendor_t::GL4ES ) + { + if ( glConfig.texture3DAvailable + && workaround_glDriver_gl4es_disableTexture3D.Get() ) + { + logger.Notice( "Found GL4ES translation layer with OpenGL ES backend, disable 3D texture support." ); + glConfig.texture3DAvailable = false; + } + } + logger.Notice( "...using up to %d texture size.", glConfig.maxTextureSize ); - logger.Notice( "...using up to %d 3D texture size.", glConfig.max3DTextureSize ); + + if ( glConfig.texture3DAvailable ) + { + logger.Notice( "...using up to %d 3D texture size.", glConfig.max3DTextureSize ); + } + else + { + logger.Notice( "...not using 3D textures." ); + glConfig.max3DTextureSize = 0; + } + logger.Notice( "...using up to %d cube map texture size.", glConfig.maxCubeMapTextureSize ); logger.Notice( "...using up to %d texture units.", glConfig.maxTextureUnits ); @@ -2691,6 +2778,10 @@ bool GLimp_Init() Cvar::Latch( workaround_glDriver_amd_adrenalin_disableBindlessTexture ); Cvar::Latch( workaround_glDriver_amd_oglp_disableBindlessTexture ); + Cvar::Latch( workaround_glDriver_gl4es_assumeSmoothstep ); + Cvar::Latch( workaround_glDriver_gl4es_disableIncrementalShaderCompilation ); + Cvar::Latch( workaround_glDriver_gl4es_disableMat3x2 ); + Cvar::Latch( workaround_glDriver_gl4es_disableTexture3D ); Cvar::Latch( workaround_glDriver_mesa_ati_rv300_useFloatVertex ); Cvar::Latch( workaround_glDriver_mesa_ati_rv600_disableHyperZ ); Cvar::Latch( workaround_glDriver_mesa_broadcom_vc4_useFloatVertex ); @@ -2705,6 +2796,10 @@ bool GLimp_Init() Cvar::Latch( workaround_glHardware_intel_useFirstProvokinVertex ); Cvar::Latch( workaround_glHardware_mthreads_disableTextureBarrier ); + Cvar::Latch( r_incrementalShaderCompilation ); + Cvar::Latch( r_useTexture3D ); + Cvar::Latch( r_useMat3x2 ); + /* Enable S3TC on Mesa even if libtxc-dxtn is not available The environment variables is currently always set, it should do nothing with other systems and drivers.