我有一个钩子,允许我渲染我自己的模型。对于这个模型,我想使用自定义顶点着色器。现在的问题是外部程序仍然使用旧的着色器/程序方法(glUseProgram)渲染,我希望在切换到新的4.4 ProgramPipeline时保持程序兼容,同时提供相同的功能,即使用户没有& #39; t支持OpenGL 4.x.现在我想我可以做到以下几点:
//Start of hook
int currProgram = glGetInteger(GL_CURRENT_PROGRAM);
int currVertexShader;
int currPipeline;
if (supportsPipelines) {
glUseProgramStages(pipelineName, EXTERNAL_SHADER_BITS, currProgram);
glUseProgram(0);
// How do I store the currently selected pipeline, if any?
glBindProgramPipeline(currPipeline);
} else {
if(currProgram == 0) {
glUseProgram(programName);
} else {
// Fiddle with the shaders ?
}
}
// Do some rendering
// How do I pop back into the original configuration?
答案 0 :(得分:1)
存储当前管道:
GLint prevPipeline = 0;
glGetIntegerv(GL_PROGRAM_PIPELINE_BINDING, &previousPipeline);
// assorted error checking
并恢复它:
glBindProgramPipeline(prevPipeline);