Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design issue with ShaderProgram and different sampler types #6

Open
grrrwaaa opened this issue Aug 28, 2012 · 0 comments
Open

Design issue with ShaderProgram and different sampler types #6

grrrwaaa opened this issue Aug 28, 2012 · 0 comments

Comments

@grrrwaaa
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant