尽管链接和验证成功,为什么着色器程序无法编译?
Why does the shader program fail to compile despite linking and validating successfully?
着色器程序没有 link 尽管顶点和片段着色器编译成功。使用 glGetProgramInfoLog()
没有检索到错误消息。然而,GL_FALSE
的值在 success
缓冲区变量中被检索(GLException
被抛出一条空消息)。这是代码:
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;
}
这是包含两个着色器的文件的 link(在程序中,每个着色器实际上包含在其自己的 String[]
变量中)。
P.S.: 我在 C++ 中有相同的代码结构,它可以完美地工作。
gl.glGetProgramiv(id, GL4.GL_COMPILE_STATUS, success); // GL_FALSE
程序对象没有编译状态,只有着色器有。尝试在程序对象上查询 GL_COMPILE_STATUS
只会得到 GL_INVALID_ENUM
值,并且不会以任何方式修改 success
值的内容。
着色器程序没有 link 尽管顶点和片段着色器编译成功。使用 glGetProgramInfoLog()
没有检索到错误消息。然而,GL_FALSE
的值在 success
缓冲区变量中被检索(GLException
被抛出一条空消息)。这是代码:
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;
}
这是包含两个着色器的文件的 link(在程序中,每个着色器实际上包含在其自己的 String[]
变量中)。
P.S.: 我在 C++ 中有相同的代码结构,它可以完美地工作。
gl.glGetProgramiv(id, GL4.GL_COMPILE_STATUS, success); // GL_FALSE
程序对象没有编译状态,只有着色器有。尝试在程序对象上查询 GL_COMPILE_STATUS
只会得到 GL_INVALID_ENUM
值,并且不会以任何方式修改 success
值的内容。