Skip to content

Commit d970a14

Browse files
committed
GLSL: Implement support for static const
In GLSL 'const' means 'static const'; this change fixes translation of static const variables by removing the `uniform` keyword and adding `const` instead. This means that `static const` variables are automatically set when the shader is bound and can be optimized by the driver, which matches HLSL behavior.
1 parent e442e51 commit d970a14

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/GLSLGenerator.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,8 @@ void GLSLGenerator::OutputStatements(int indent, HLSLStatement* statement, const
996996
if (indent == 0)
997997
{
998998
// At the top level, we need the "uniform" keyword.
999-
m_writer.Write("uniform ");
999+
if ((declaration->type.flags & HLSLTypeFlag_Static) == 0)
1000+
m_writer.Write("uniform ");
10001001
}
10011002
OutputDeclaration(declaration);
10021003
m_writer.EndLine(";");
@@ -1794,6 +1795,11 @@ void GLSLGenerator::OutputDeclaration(const HLSLType& type, const char* name)
17941795

17951796
void GLSLGenerator::OutputDeclarationType( const HLSLType& type )
17961797
{
1798+
if ((type.flags & HLSLTypeFlag_Const) && (type.flags & HLSLTypeFlag_Static))
1799+
{
1800+
m_writer.Write("const ");
1801+
}
1802+
17971803
m_writer.Write( "%s ", GetTypeName( type ) );
17981804
}
17991805

0 commit comments

Comments
 (0)