Shader program does not link despite the vertex and fragment shaders compiling successfuly. No error message is retreived using glGetProgramInfoLog()
. A value of GL_FALSE
is, however, retreived within the success
buffer variable (the GLException
is thrown with an empty message). Here is the code:
private int compileProgram(String[] vertexShaderSource, String[] fragmentShaderSource)
throws GLException {
// compiling vertex and fragment shaders from source
int vertexShader = compileShader(GL4.GL_VERTEX_SHADER, vertexShaderSource); // OK
int fragmentShader = compileShader(GL4.GL_FRAGMENT_SHADER, fragmentShaderSource); // OK
int id = gl.glCreateProgram(); // OK
// attaching the shaders to the shader program and linking it
gl.glAttachShader(id, vertexShader);
gl.glAttachShader(id, fragmentShader);
gl.glLinkProgram(id);
gl.glDeleteShader(vertexShader);
gl.glDeleteShader(fragmentShader);
IntBuffer success = IntBuffer.allocate(1);
gl.glGetProgramiv(id, GL4.GL_COMPILE_STATUS, success); // GL_FALSE
// checking for errors
if (success.get(0) == GL4.GL_FALSE) {
IntBuffer infoLogLength = IntBuffer.allocate(1);
gl.glGetProgramiv(id, GL4.GL_INFO_LOG_LENGTH, infoLogLength);
ByteBuffer infoLog = ByteBuffer.allocate(infoLogLength.get(0));
gl.glGetProgramInfoLog(id, infoLogLength.get(0), infoLogLength, infoLog);
// Empty error message
String errorMessage = new String(infoLog.array(), Charset.forName("UTF-8"));
throw new GLException(errorMessage);
}
return id;
}
Here is a link to the file containing the two shaders (in the program, each shader is actually contained within its own String[]
variable).
P.S.: I have the same code structure in C++ and it works flawlessly.
gl.glGetProgramiv(id, GL4.GL_COMPILE_STATUS, success); // GL_FALSE
Program object do not have a compile status, only shaders do. Trying to query GL_COMPILE_STATUS
on a program object will only result in a GL_INVALID_ENUM
value, and the content of your success
value will not be modified in any way.