Skip to content

igl | opengl | Use glClearBufferfv to set different clear color for multiple render targets.#285

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

igl | opengl | Use glClearBufferfv to set different clear color for multiple render targets.#285
vinsentli wants to merge 2 commits into
facebook:mainfrom
vinsentli:glClearBufferfv_3

Conversation

@vinsentli

Copy link
Copy Markdown
Contributor

No description provided.

@meta-cla meta-cla Bot added the cla signed label Aug 14, 2025
@pixelperfect3

Copy link
Copy Markdown

Android builds failing, please fix

@vinsentli

vinsentli commented Aug 14, 2025

Copy link
Copy Markdown
Contributor Author

Android builds failing, please fix

@pixelperfect3
This PR depands on the previous PR.

@corporateshark corporateshark left a comment

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.

#283 was merged. Please rebase onto the latest main.

Comment thread src/igl/opengl/Framebuffer.cpp
@vinsentli

Copy link
Copy Markdown
Contributor Author

#283 was merged. Please rebase onto the latest main.

done

Comment thread src/igl/opengl/Framebuffer.cpp
@vinsentli

Copy link
Copy Markdown
Contributor Author

@corporateshark
The value of GL_DRAW_BUFFER0 is 0x8825。
If use (GL_DRAW_BUFFER0 + (GLint)index) for 2nd param, glClearBufferfv() will return GL_INVALID_VALUE.

@corporateshark

Copy link
Copy Markdown
Contributor

clearBufferfv

Oh, this one has slightly different spec. I see.

If buffer is GL_COLOR, a particular draw buffer GL_DRAW_BUFFERi is specified by passing i as drawbuffer.
@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 D80472407.

Comment thread src/igl/opengl/Framebuffer.cpp Outdated
renderPass_.colorAttachments[index].loadAction == LoadAction::Clear) {
auto clearColor = renderPass_.colorAttachments[index].clearColor;
getContext().colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
if (getContext().deviceFeatures().hasInternalFeature(InternalFeatures::ClearBufferfv)) {

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.

This check must wrap the entire loop. As is, if InternalFeatures::ClearBufferfv isn't supported, you're leaving glClearColor set to the color of the last available color attachment, which is a significant change in behavior.

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.

The function InternalFeatures::ClearBufferfv is ​supported in OpenGL ES 3.0 but not in OpenGL ES 2.0. However, since ​MRT (Multiple Render Targets) is inherently unsupported in OpenGL ES 2.0, the scenario you described ​cannot occur​ in practice.

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.

On the non-ES world, MRT was introduced in OpenGL 2.0 while glClearBuffer is introduced in OpenGL 3.0.

To be safe, let's avoid any versioning assumptions and make the logic sound by itself.

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

add iglClearBufferfv

revert

opt

Revert "opt"

This reverts commit 6b37c9a.
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@corporateshark merged this pull request in ac37006.

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