How it works...

The glCreateShaderProgramv function provides a simple way to create a separable shader program consisting of a single stage. We pass the shader stage and the code string to function which creates a shader object, compiles it, creates a separable program, attaches the shader, and links the program, and returns the name of the new shader program. We should check for errors immediately after each call. All errors will be in the program info log. The Linking a shader program recipe details how to check for errors.

Once we have the shader programs, we create the pipelines. We create two pipeline objects using glCreateProgramPipelines. Then, we set the stages for each pipeline using glUseProgramStages. The first argument to glUseProgramStages is the pipeline name, the second is a bit string indicating the stages that are to be used from the program, and the last argument is the program name. The bit string for the second argument can be composed of some combination of GL_VERTEX_SHADER_BIT, GL_FRAGMENT_SHADER_BIT, and so on. Use the bitwise OR operator (|) to combine bits.

As mentioned earlier, when using program pipelines, it is a good idea to use glProgramUniform rather than glUniform to set uniform variables. It can be difficult to determine the program that is being affected when using glUniform due to the fact that a pipeline can and usually does involve multiple programs. There is a function called glActiveShaderProgram that can be used to specify the program affected by glUniform calls, or you can simply use glUseProgram. However, there's no need to bother with any of that, because glProgramUniform makes it clear and simple. With glProgramUniform, we specify the target program directly as the first argument.

Before rendering with pipelines, it is important to make sure that there is no program that is currently bound to the GL context via glUseProgram. If there is, it will be used instead of the pipeline. Therefore, you might want to call glUseProgram(0) before rendering, just to be sure.

Finally, we use glBindProgramPipeline to enable one of our pipelines before rendering. In this example, the first draw will use the vertex shader and the first fragment shader. The second draw will use the vertex shader and the second fragment shader.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.42.196