0

我有一个钩子可以让我渲染我自己的模型。对于这个模型,我想使用自定义顶点着色器。现在的问题是外部程序仍然使用旧的着色器/程序方法(glUseProgram)进行渲染,我希望在切换到新的 4.4 ProgramPipeline 时保持我的程序兼容,同时即使用户不提供相同的功能'不支持 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?
4

1 回答 1

1

要存储当前管道:

GLint prevPipeline = 0;
glGetIntegerv(GL_PROGRAM_PIPELINE_BINDING, &previousPipeline);
// assorted error checking

并恢复它:

glBindProgramPipeline(prevPipeline);
于 2014-07-14T08:39:05.767 回答