You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just hit a problem with the design of ShaderProgram (maybe also something a bit stupid about OpenGL?)
If a shader has two different kinds of sampler in it (e.g. sampler2D, sampler3D, samplerCube etc.), then until a uniform is set these are all bound to unit 0. Running GLSL validation on this will fail, since different texture types cannot be bound to the same unit.
The solution is to perform actions in this order (e.g. typically this would be during onCreate):
create shaders & program object
attach shaders to program
link program
bind program
send uniforms to give each sampler a unique unit *
unbind program
validate program
However in the current design of ShaderProgram, the link() method also performs validation. I've hacked a boolean argument to this to prevent validation if needed, and added a separate validate_linked() method, for the particular case I'm using now. But I expect that this hack is not a long-term solution.
Any user copying example code and adding a different sampler to the shader is going to see this confusing error, and isn't likely to find the solution (adding uniform setters between link() and validate_linked()) without quite a lot of work.
Validation Failed: Sampler error:
Samplers of different types use the same texture image unit.
or -
A sampler's texture unit is out of range (greater than max allowed or negative).
I don't have an immediate idea for a solution through. It's hard to automate, since the number of samplers are not easily known. One possibility is to defer validation until the shader is actually used, but this still requires setting the uniforms beforehand.
Open to suggestions!
The text was updated successfully, but these errors were encountered:
Just hit a problem with the design of ShaderProgram (maybe also something a bit stupid about OpenGL?)
If a shader has two different kinds of sampler in it (e.g. sampler2D, sampler3D, samplerCube etc.), then until a uniform is set these are all bound to unit 0. Running GLSL validation on this will fail, since different texture types cannot be bound to the same unit.
The solution is to perform actions in this order (e.g. typically this would be during onCreate):
create shaders & program object
attach shaders to program
link program
bind program
unbind program
validate program
However in the current design of ShaderProgram, the link() method also performs validation. I've hacked a boolean argument to this to prevent validation if needed, and added a separate validate_linked() method, for the particular case I'm using now. But I expect that this hack is not a long-term solution.
Any user copying example code and adding a different sampler to the shader is going to see this confusing error, and isn't likely to find the solution (adding uniform setters between link() and validate_linked()) without quite a lot of work.
Validation Failed: Sampler error:
Samplers of different types use the same texture image unit.
A sampler's texture unit is out of range (greater than max allowed or negative).
I don't have an immediate idea for a solution through. It's hard to automate, since the number of samplers are not easily known. One possibility is to defer validation until the shader is actually used, but this still requires setting the uniforms beforehand.
Open to suggestions!
The text was updated successfully, but these errors were encountered: