paroj / gltut

Learning Modern 3D Graphics Programming
https://paroj.github.io/gltut/
MIT License
1.57k stars 377 forks source link

GL_INVALID_VALUE in the "Gamma Ramp" example #89

Closed paroj closed 8 years ago

paroj commented 10 years ago

Originally reported by: Giuseppe Barbieri (Bitbucket: giuseppe_barbieri, GitHub: Unknown)


If I try to run the "Gamma Ramp" example I get the following

43.png

#!c++

Error from API, High priority
Message: GL_INVALID_VALUE error generated. Handle does not refer to a shader or
program object.
Error from API, High priority
Message: GL_INVALID_OPERATION error generated. Shader is already attached.
Error from API, High priority
Message: GL_INVALID_OPERATION error generated. <shader> is not attached to <prog
ram>.
Error from API, High priority
Message: GL_INVALID_VALUE error generated. Handle does not refer to a shader or
program object.
Error from API, High priority
Message: GL_INVALID_VALUE error generated. Handle does not refer to a shader or
program object.
Error from API, High priority
Message: GL_INVALID_VALUE error generated. Handle does not refer to a shader or
program object.
Error from API, High priority
Message: GL_INVALID_VALUE error generated. Uniform block index exceeds the maxim
um supported uniform buffers.
Other from API,  priority
Message: Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, us
age hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer objec
t operations.
Other from API,  priority
Message: Buffer detailed info: Buffer object 2 (bound to GL_UNIFORM_BUFFER (0),
and GL_UNIFORM_BUFFER_EXT, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory
as the source for buffer object operations.
Other from API,  priority
Message: Buffer detailed info: Buffer object 2 (bound to GL_UNIFORM_BUFFER (0),
usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer ob
ject operations.
Other from API,  priority
Message: Buffer detailed info: Buffer object 2 (bound to GL_UNIFORM_BUFFER (0),
usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer ob
ject operations.

Process returned 0 (0x0)   execution time : 1.594 s
Press any key to continue.

paroj commented 8 years ago

Original comment by Sand3r (Bitbucket: Sand3r, GitHub: Sand3r):


It is caused by the Framework::CreateProgram function which after the program linking calls the glDeleteShader on each entity of the shaderList vector.

The simplest solution is to replace the current InitializeProgram() code to:

#!c++

void InitializeProgram()
{
    std::vector<GLuint> shaderList;

    shaderList.push_back(Framework::LoadShader(GL_VERTEX_SHADER, "screenCoords.vert"));
    shaderList.push_back(Framework::LoadShader(GL_FRAGMENT_SHADER, "textureNoGamma.frag"));

    g_noGammaProgram = Framework::CreateProgram(shaderList);

    shaderList.clear();
    shaderList.push_back(Framework::LoadShader(GL_VERTEX_SHADER, "screenCoords.vert"));
    shaderList.push_back(Framework::LoadShader(GL_FRAGMENT_SHADER, "textureGamma.frag"));

    g_gammaProgram = Framework::CreateProgram(shaderList);

    GLuint projectionBlock = glGetUniformBlockIndex(g_noGammaProgram, "Projection");
    glUniformBlockBinding(g_noGammaProgram, projectionBlock, g_projectionBlockIndex);

    GLuint colorTextureUnif = glGetUniformLocation(g_noGammaProgram, "colorTexture");
    glUseProgram(g_noGammaProgram);
    glUniform1i(colorTextureUnif, g_gammaRampTextureUnit);
    glUseProgram(0);

    projectionBlock = glGetUniformBlockIndex(g_gammaProgram, "Projection");
    glUniformBlockBinding(g_gammaProgram, projectionBlock, g_projectionBlockIndex);

    colorTextureUnif = glGetUniformLocation(g_gammaProgram, "colorTexture");
    glUseProgram(g_gammaProgram);
    glUniform1i(colorTextureUnif, g_gammaRampTextureUnit);
    glUseProgram(0);
}

Pull request addressing this problem has been sent https://bitbucket.org/alfonse/gltut/pull-requests/7/fixed-the-bug-that-corrupted-the-gamma/diff