[Interest] How to use serveral textures in a QSGSimpleMaterialShader

Martin Ertl qsmokeonthewater at gmail.com
Thu Jul 24 11:25:16 CEST 2014


Hello Till,

thank you for your hints.
That gave me some input for further search and I found this nice little
piece of code
which shows nearly everything I'd like to do :-)
https://qt.gitorious.org/qt/qtdeclarative/source/4f69825c5bfd93b63f890a8188ece93af1283f1f:src/particles/qquickimageparticle.cpp#L207-297


Just a short summary of the main steps, the link above shows the details:

-> Override QSGSimpleMaterialShader::initialize(), call the initialize()
method of the parent class at the very first action
-> bind() the program
-> define 'which texture unit a given "uniform sampler2D tex" refers to' by
calling
        program()->setUniformValue("uTex0", 0);
        program()->setUniformValue("uTex1", 1);
        ...
-> get a pointer to "QOpenGLFunctions" by calling
"QOpenGLContext::currentContext()->functions();" and store it in a member
variable


-> Then override the "void QSGSimpleMaterialShader::updateState(const State
*state, const State *)" method
-> call "glActiveTexture(GL_TEXTURE0);" on the QOpenGLFunctions pointer
extracted during "initialize()"
-> call "bind()" on first texture texture
-> call "glActiveTexture(GL_TEXTURE1);"
-> "bind()" the second texture.


Have a nice day,
Martin




2014-07-24 10:00 GMT+02:00 Till Oliver Knoll <till.oliver.knoll at gmail.com>:

> Am 24.07.2014 um 09:28 schrieb Till Oliver Knoll <
> till.oliver.knoll at gmail.com>:
>
> > ...
> > In recent (OpenGL >= 4.1?) shader versions there is also a "layout" (or
> "location") qualifier, so you can save the call to glUniform1i - but the
> exact syntax escapes me right now.
>
> >From the "OpenGL SuperBible":
>
> layout (binding = 0) uniform sampler2D foo;
> layout (binding = 1) uniform sampler2D bar;
> etc.
>
> This is the preferred way of assigning sampler uniforms to texture units
> (the "binding" values in the shader code above refer off course to the
> texture units that you "activated" (glActiveTexture) previously before
> "binding" your textures in your application).
>
> Cheers,
>   Oliver
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140724/f4d0da47/attachment.html>


More information about the Interest mailing list