Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stencil test #58

Merged
merged 4 commits into from
Aug 3, 2024
Merged

Stencil test #58

merged 4 commits into from
Aug 3, 2024

Conversation

mardy
Copy link
Collaborator

@mardy mardy commented Jul 26, 2024

Finally it's here :-)

This is a big changeset all in one commit, but that's because I didn't find it worthwhile splitting it into smaller chunks (if you disagree, please let me know, I can try to come up with some splits).

The code has some inline comments, but for an overview one should read the "Stencil Test" section in the OpenGL 1.5 specification first, then the documentation changes from the second commit of this PR.

This has been tested with the tutorial №27 from swiftless.com and with the dinoshade.c program that can be found online in the examples of the GLU library.

The stencil functionality is not directly implemented by the GX API, so
we have to emulate it by using an additional TEV stage to mask out the
pixels we don't want to draw and perform some drawing operations on an
offscreen EFB in order to build the stencil buffer in the first place.
We should not rely on the fact that the _ogx_efb_restore_texobj()
function will only e called when color updates are enabled -- or, at the
very least, if we accept this requirement we should document it. It's
more robust if we always enable color updates within the function and
set the dirty bit, as we do for all other GX settings that we modify.
Draw to the stencil buffer before drawing the graphic primitive,
otherwise the stencil drawing operations which perform a Z-buffer test
(the `zpass` and `zfail` ones set with glStencilOp) will be affected by
it.
When moving the stencil drawing operations before the main drawing,
special care must be taken to avoid using the updated stencil buffer
already when drawing the current primitive (which should be drawn using
the old stencil buffer). We use the `draw_count` variable to achieve
this.
@mardy
Copy link
Collaborator Author

mardy commented Jul 31, 2024

Added a couple of commits to fix one issue with the Z-buffer being wrongly updated before the stencil test.

@WinterMute WinterMute merged commit 0fe8c22 into devkitPro:master Aug 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants