GL_INFO_LOG_LENGTH returns 1

GL_INFO_LOG_LENGTH returns 1

编辑:澄清。我不是在检查编译是否失败,我只是在寻找 logs。我稍后会在代码中检查 COMPILE_STATUS。 (见本篇未用到的GLint isCompiled

为什么这个return1,应该是0

glGetShaderiv(compiled, GL_INFO_LOG_LENGTH, &infoLogLength);

    GLuint compiled = glCreateShader(shader->Type);
    GLchar const *shader_source = code.c_str();
    GLint const shader_length = code.size();

    glCheck(glShaderSource(compiled, 1, &shader_source, &shader_length));
    glCheck(glCompileShader(compiled));

    GLint isCompiled = 0;
    char msg[512];

    // Check if everything went ok
    glGetShaderiv(compiled, GL_COMPILE_STATUS, &isCompiled);

    // Getting information about the compile
    GLsizei infoLogLength = 0;
    glGetShaderiv(compiled, GL_INFO_LOG_LENGTH, &infoLogLength);
    if (infoLogLength > 0)
    {
        glGetShaderInfoLog(compiled, 512, &infoLogLength, msg);
        printf("Shader [%s:%s] error when compiling[%d]: \n%s", shader->Name.c_str(), GetShaderTypeAsString(shader->Type).c_str(), infoLogLength, msg);
    }

输出:

Shader [dust_particle_VS.glsl:Vertex Sader] error when compiling[1]:

着色器似乎工作正常,游戏运行没有问题。 我只是在想,这可能是一些可能对我有所帮助的警告。

即使着色器已成功编译,实施也可以为您提供信息日志。或者更重要的是,在成功编译着色器后,信息日志不需要为空。来自规范:

A string that contains information about the last compilation attempt on a shader object, last link or validation attempt on a program object, or last validation attempt on a program pipeline object, called the info log, can be obtained...

请注意,它没有说 "last failed compilation attempt" 或任何类似的内容。因此,信息日志长度是 0、1 还是其他任何值都没有关系;信息日志的长度无法告诉您编译是成功还是失败。事实上,即使编译成功,某些实现也会在信息日志中向您发出警告。

查看编译状态是判断编译成功与否的方式,不是信息日志。

7.13 的 OpenGLs 4.6 specs 说:

void GetShaderiv( uint shader, enum pname, int *params );

...

If pname is INFO_LOG_LENGTH, the length of the info log, including a null terminator, is returned. If there is an empty info log, zero is returned.

以后:

void GetShaderInfoLog( uint shader, sizei bufSize, sizei *length, char *infoLog );

...

These commands return an info log string for the corresponding type of object in infoLog. This string will be null-terminated even if the INFO_LOG_LENGTH query returns zero.

据我了解,这些句子的查询 INFO_LOG_LENGTH 必须 return zero 用于空信息日志字符串。如果您检索此字符串,它将至少包含一个空字符。

我的猜测是您使用的驱动程序计数(在某些情况下)即使是空日志也是 null-terminated 个字符。

换句话说,似乎是一个驱动程序错误。
不大,因为正如@NicoBolas 所说,您不会将 info-log 用作 fail-check,但在失败时提供信息;在这种情况下,驱动程序可能会设置一个长于 1 的字符串。