If a symbol, in your case scopeName, has already been declared previously in the same scope (in your case user global scope), you’ll get a conflict. Second, you cannot use the instance name of an interface block in a variable declaration. When the compiler sees somthing like
uniform int scopeName.varName;
it sees the uniform qualifier, than a basic type which lets it know you’re going to define a uniform variable of type int, and then expects an identifier which hasn’t been declared previously. This can either be followed by an assignment or the end of the statement which is the semicolon. Therefore your statement where you select a member of an instance is invalid.
Why is varName at global scope.
In the same shader, it’s because you shift varName from the uniform block out the global scope by using an instance name, in your case scopeName. Therefore scopeName.varName isn’t the same variable as varName.
If you declare a block in one shader and declare a variable in another shader which bears the name of a block variable there is no conflict because VS1 doesn’t know about anthing in VS2. If, however, you declare the following
uniform Block
{
mat3 blockMat;
};
mat3 blockMat;
then you have the same problem as before. blockMat is declared two times at global scope since no instance name(s) is(are) used for Block which implicitly puts variables from the uniform block at global scope.
Is this expected behavior
Since it’s clearly specified this behaviour is pretty much expected.
How do I handle Name Conflicts (two scopes that contain the same varName)?
Use instance names or use different variable names.
How can i use the scoped uniforms in my second Shader?
You simply declare the block in both shaders to use the data. Depending on the layout you’re using you’ll have to query the offsets of the uniform block in either shader. If you use layout(std140) you are guaranteed to have to same layout across all shaders. Consult the spec on layouts.
Edit: Btw, in GLSL there is no such thing as a forward declartion in the sense of C++'s forward declaration.