Skip to content

igl | opengl | Fix glDrawBuffers() will fail if the set color_attachment_N indices are not consecutive.#286

Closed
vinsentli wants to merge 2 commits into
facebook:mainfrom
vinsentli:glDrawBuffers
Closed

igl | opengl | Fix glDrawBuffers() will fail if the set color_attachment_N indices are not consecutive.#286
vinsentli wants to merge 2 commits into
facebook:mainfrom
vinsentli:glDrawBuffers

Conversation

@vinsentli

Copy link
Copy Markdown
Contributor

https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glDrawBuffers.xhtml

GL_INVALID_OPERATION is generated if the GL is bound to a framebuffer object and the ith buffer listed in bufs is anything other than GL_NONE or GL_COLOR_ATTACHMENTSi.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@corporateshark has imported this pull request. If you are a Meta employee, you can view this in D80443133.

std::sort(drawBuffers.begin(), drawBuffers.end());

if (drawBuffers.size() > 1) {
getContext().drawBuffers(static_cast<GLsizei>(drawBuffers.size()), drawBuffers.data());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition if (drawBuffers.size() > 1) on line 595 may not behave as intended after this change. Since the code now always pushes either a color attachment or GL_NONE for each slot, the drawBuffers vector will always have exactly IGL_COLOR_ATTACHMENTS_MAX elements. This means glDrawBuffers() will always be called, even when there are no actual color attachments or only one color attachment. Consider checking if there are multiple actual color attachments (non-GL_NONE values) instead of just checking the vector size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@corporateshark merged this pull request in adb891c.

@vinsentli vinsentli deleted the glDrawBuffers branch August 20, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants