简体   繁体   中英

qt multiple QGLShaderProgram for one texture

I use two QGLShaderProgram for processing the texture.

ShaderProgram1->bind(); // QGLShaderProgram
ShaderProgram2->bind();

glBegin(GL_TRIANGLE_STRIP);
...
glEnd();

ShaderProgram1->release();
ShaderProgram2->release();

The texture should be processed with Shaderprogram1 and then ShaderProgram2. But when I call ShaderProgram2->bind() automatically fires ShaderProgram1->release() and only one shader works. How do I bind both shaders?

You don't.

Unless these are separate shaders (and even they don't work that way), each rendering operation will apply a single set of shaders to the rendered primitive. That means a single Vertex Shader, followed by any Tessellation Shaders, followed by optionally a single Geometry Shader, followed by a single Fragment Shader.

If you want to daisy-chain shaders, you have to do that within the shaders themselves.

I know this is a very old question, but I just wanted to add my two cents here for anyone who might stumble upon this. If you want to run multiple shaders that use the same texture, you should set the active texture at the start of the update loop. Then, you must run the shaders one at a time. One shader has to complete before the other may begin. So instead, it would look like this.

ShaderProgram1->bind();
...
ShaderProgram1->release();

ShaderProgram2->bind();
...
ShaderProgram2->release();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM