为什么glGetProgramInfoLog返回一个空字符串?

时间:2017-07-14 14:48:41

标签: c++ opengl

我正在处理我知道正确编译的代码库。目前,我已经在我的着色器中引入了一个有目的的拼写错误来模拟错误。此时,代码拒绝编译。然后我可以打电话

 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &params);

发现params现在是108,之前是0,所以我知道有一个与这个着色器相关的日志(我试图编译)。但是,当我打电话时

glGetProgramInfoLog(shader, 512, &size, ErrorLog);

size返回0,ErrorLog仍为空。

这是这种情况下的重要代码:

void Shader::AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType)
{
    GLuint ShaderObj = glCreateShader(ShaderType);
    if (ShaderObj == 0) {
        fprintf(stderr, "Error creating shader type %d\n", ShaderType);
        exit(1);
    }
    const char* pShaderSource = readShaderSource(pShaderText);
    glShaderSource(ShaderObj, 1, (const GLchar**)&pShaderSource, NULL);
    glCompileShader(ShaderObj);
    checkCompileError(ShaderObj, ShaderType);
    glAttachShader(ShaderProgram, ShaderObj);
}


bool Shader::checkCompileError(GLuint shader, GLenum ShaderType)
{
    GLint params = -1;
    GLchar ErrorLog[512] = { 0 };
    GLint size = 0;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &params);
    if (GL_TRUE != params) {
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &params);
        glGetProgramInfoLog(shader, 512, &size, ErrorLog);
        fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, ErrorLog);
        exit(1);
    }
    return true;
} 

1 个答案:

答案 0 :(得分:3)

glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &params);
glGetProgramInfoLog(shader, 512, &size, ErrorLog);
     ^^^^^^^ should be Shader

你正在编译&检查着色器,因此您应该使用glGetShaderInfoLog()

glGetProgramInfoLog()用于获取从glCreateProgram()

获取的完整着色器程序对象的链接日志