- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When my OpenGL app renders multiple textures, it crashes if I try to discard the output by setting GL_NONE in glDrawBuffers.
Is that a bug or there is a specification I am not aware of? NVidia works fine.
Example code below (C#):
GL.DrawBuffers(5, new[] { DrawBuffersEnum.None, DrawBuffersEnum.ColorAttachment5, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.None, DrawBuffersEnum.None, });
shader:
#version 430 core layout(location = 0) out vec4 outColor1; layout(location = 1) out vec4 outFront; layout(location = 2) out vec4 outBack; layout(location = 3) out vec4 outColor2; layout(location = 4) out vec4 outNormal; void main(void) { outColor1 = vec4(0, 1.0, 0, 1.0); // will crash silently }
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...attempting to write to an output in the fragment shader while the corresponding draw buffer is set to GL_NONE i.e., explicitly discarding output can lead to undefined behavior, depending on the GPU driver and platform. According to the OpenGL specification, if a shader writes to a location that is not backed by an active draw buffer e.g., GL_NONE, the behavior is undefined unless the shader explicitly disables that output. While some drivers, like NVIDIA’s, may tolerate this or silently ignore the write, others (including Intel’s driver stack) may crash or behave unpredictably, which seems to be what you're experiencing here.
To ensure cross-vendor compatibility and avoid undefined behavior, you should only write to fragment shader outputs that are actively bound viaglDrawBuffers. For outputs that are not active, you have two safe options:
Don’t write to those outputs at all in the shader, or
Use preprocessor directives or dynamic branching to conditionally write based on your output configuration.
Example workaround:
NVIDIA’s drivers tend to be more lenient in allowing undefined or non-standard behavior. However, relying on this can create portability issues, especially across Intel and AMD drivers, or on platforms strictly following OpenGL specifications.
hope it helps,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you provide sources for that or is it chatgpt?
The preprocessor option will require my to recompile the shader.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page