[Cogl] [PATCH v2] cogl-gles2-context: Append wrapper shader to user shaders

Neil Roberts neil at linux.intel.com
Tue Aug 28 06:28:07 PDT 2012


> Something I'm a bit unsure about is what happens for applications that
> are creating multiple vertex shaders to be linked together with one
> main function (with non SGX drivers) and how we can be sure to only
> append to the shader containing the main function instead of appending
> multiple wrappers which I suspect will lead to a link failure.

I just noticed that in the GLES 2 spec it says that glAttachShader will
generate an error if you try to attach more than one shader of the same
type to a program. In that case I guess we don't need to worry about
trying to work out which shader has the main function because we can
attach the wrapper to the one and only vertex shader. We also won't have
to special case the workaround for SGX so we can just use it in all
cases.

I think it would still be worth trying to make it so that
glGetShaderSource filters out the added shader snippet. This would
probably be quite simple if we put in a begin and end marker in a
comment around the snippet.

It might also be worth at some point making Cogl directly detect this
error condition and fake its own GL_INVALID_OPERATION error. Otherwise
when it is used on Mesa it won't generate the error but it will
presumably instead give a confusing link error about having two main
functions. We were discussing implementing a separate error queue for
the CoglGLESContext anyway because in some parts it would be nice if
Cogl was able to check whether a GL call caused an error without having
to consume the error. I think it would be fine to leave that for a
separate patch though.

In the meantime I think it would be OK to go ahead with both the
proposed patches, however one concern is that we probably shouldn't be
attaching anything to the beginning of the shader. If the application is
providing a '#version' or '#extension' pragma then we can't put anything
before that because they must be at the beginning to work. I don't think
there would be any problem with declaring the flip uniform in the middle
of the shader source so there's probably no need to split the wrapper
shader into two strings. Instead we can just always append the single
wrapper string to the end of the shader.

Regards,
- Neil


More information about the Cogl mailing list