GLSL fragment shader fails to compile with no message

PHPz
Release: 2024-02-14 12:18:09
forward
543 people have browsed it

GLSL 片段着色器无法编译且没有任何消息

php Xiaobian Yuzai found that the GLSL fragment shader encountered problems during compilation, but there was no error message. This can leave developers confused as to what went wrong. Before solving this problem, the first thing to clarify is that no error message is usually because the compiler did not generate any error message, or the error message was ignored. Next, we need to step-by-step troubleshoot the possible causes to find a solution.

Question content

I am using the go-gl bindings for OpenGl.

I defined the sources for both shaders as follows:

<code>const vertexShaderSource = `#version 460 compatibility
layout (location = 0) in vec3 aPos;
void main()
{
    gl_Position = vec4(aPos, 1.0);
}` + "\x00"
const fragmentShaderSource = `#version 460 compatibility
out vec4 FragColor;
void main()
{
    FragColor = vec4(0.5f, 0.1f, 0.1f, 1.0f);
}` + "\x00"
</code>
Copy after login

The vertex shader is created and compiled without issue.

The following is the code to create and compile the fragment shader:

<code>fragmentShader := gl.CreateShader(gl.FRAGMENT_SHADER)
fragmentShaderSourceC := gl.Str(fragmentShaderSource)
gl.ShaderSource(fragmentShader, 1, &fragmentShaderSourceC, nil)
gl.GetShaderiv(fragmentShader, gl.COMPILE_STATUS, &success)
if success != gl.TRUE {
    var length int32
    infoLogC := [LOGSIZE]uint8{}
    gl.GetShaderInfoLog(fragmentShader, LOGSIZE, &length, &infoLogC[0])
    infoLog := gl.GoStr(&infoLogC[0])
    fmt.Printf("Got failure from fragment shader: %s\n", infoLog)
    fmt.Printf("gl version: %s\n", gl.GoStr(gl.GetString(gl.VERSION)))
    fmt.Printf("gl vendor: %s\n", gl.GoStr(gl.GetString(gl.VENDOR)))
    return
}
</code>
Copy after login

Output the following (frustratingly, no informational log messages):

Got failure from fragment shader: 
gl version: 4.6 (Compatibility Profile) Mesa 23.0.4-0ubuntu1~23.04.1
gl vendor: Intel
Copy after login

I tried switching between versions core/compatibility, changing the name of FragColor and different values ​​in vec4.

I also tried commenting out the if block and continuing to create the program. Checking the program's block outputs an error, which is expected since the shader is not compiled: error: linking with uncompiled/unspecializedshader

Any feedback on how to compile the fragment shader?

Solution

Call glShaderSource() Only the code that sets the source shader. It cannotcompile. Then you need to call glCompileShader() separately. < /p>

gl.ShaderSource(fragmentShader, 1, &fragmentShaderSourceC, nil)
gl.CompileShader(fragmentShader)
Copy after login

Cause gl.GetShaderiv() and gl.COMPILE_STATUS result success is gl.FALSE. It's because gl.COMPILE_STATUS will only produce gl.TRUE if the last compilation was successful. However, since you never called gl.CompileShader(), there was no successful compilation before, so you receive gl.FALSE. Also, the info log is empty since there haven't been any errors so far.

The above is the detailed content of GLSL fragment shader fails to compile with no message. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template