1

I have a function that checks whether or not the vertex/fragment shared was compiled successfully and is valid to use within LWJGL

public static boolean isShaderValid(int shaderToCheck) {
    IntBuffer iVal = BufferUtils.createIntBuffer(1);
    glGetObjectParameterARB(shaderToCheck, GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
    int length = iVal.get();
    boolean isValid = length>1;
    if (isValid && verboseValidityCheck) {
        printShaderLogInfo(shaderToCheck, iVal, length);
    }
    return isValid;
}

This however, ALWAYS returns false, even though when I skip this check and just use the shader, it works fine. So, what is wrong with this shader validity check?

codemonkey
  • 463
  • 3
  • 15

2 Answers2

1

This part

boolean isValid = length>1;

will get you a False value for any empty Info Log.

An empty Info Log for a shader is fine as far as I know, so could get a False result with any perfectly validating shader.

Darkwings
  • 76
  • 3
0

It's not appropriate to use the infolog length to check the validity of a shader.

I'm not sure if you're referring to a program or a shader here, but you should call glGetProgramiv or glGetShaderiv with GL_LINK_STATUS/GL_COMPILE_STATUS respectively to get a boolean pass/fail result.

The info log length is only useful when you want to allocate a buffer of chars to retrieve the log, and the contents of the log are completely up to the GPU vendor and arbitrary.

It could easily return "Compile Successful" in the infolog after shader compilation, which would make your length check to be useless.

Tim
  • 35,413
  • 11
  • 95
  • 121