FragColor variable name is implicitly reserved on GL3Plus

Minor issues with the Ogre API that can be trivial to fix
Post Reply
User avatar
altren
Gnome
Posts: 329
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 24
Contact:

FragColor variable name is implicitly reserved on GL3Plus

Post by altren »

Simple fragment glsl shader produce error, that was not trivial to debug:

Code: Select all

ERROR: 0:22: Regular non-array variable 'FragColor' may not be redeclared

Code: Select all

#version 130
precision highp int;
precision highp float;

uniform sampler2D sampleTexture;
in vec4 outUV0;
in vec4 outColor;
out vec4 FragColor;

// Texturing fragment program for GLSL
void main()
{
	FragColor = outColor * texture(sampleTexture, outUV0.xy);
}
It took me a while to figure out, that FragColor is defined inside Ogre's code in RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLShader.cpp :

Code: Select all

        if(shouldUpgradeToVersion150)
        {
            if(belowVersionPos != 0)
                mSource = mSource.erase(0, belowVersionPos); // drop old definition

            // automatically upgrade to glsl150. thank you apple.
            const char* prefixFp =
                    "#version 150\n"
                    "#define varying in\n"
                    "#define texture1D texture\n"
                    "#define texture2D texture\n"
                    "#define texture3D texture\n"
                    "#define textureCube texture\n"
                    "#define texture2DLod textureLod\n"
                    "#define texture2DProj textureProj\n"
                    "#define textureCubeLod textureLod\n"
                    "#define shadow2DProj textureProj\n"
                    "#define gl_FragColor FragColor\n"
                    "out vec4 FragColor;\n";
I suggest to rename FragColor to something that would not clash with user's variables (for example Ogre_FragColor)
I can create pull request if suggested change is ok.
Image
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: FragColor variable name is implicitly reserved on GL3Plus

Post by paroj »

thats a known issue: https://github.com/OGRECave/ogre/issues/841

renaming FragColor wont get you far. Actually I think hitting that name conflict helped you figuring the issue.

As described in the issue the proper fix would be checking whether gl_FragColor is found in the source code. Feel free to make a PR for that.

Or bump your version to #version 150
User avatar
altren
Gnome
Posts: 329
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 24
Contact:

Re: FragColor variable name is implicitly reserved on GL3Plus

Post by altren »

Simply renaming FragColor to FragColor1 in my shader code solved the issue. I guess that this solution is not perfect, but it works for me.
I agree that this is incomplete solution, though
Image
Post Reply