Created
May 27, 2011 07:14
-
-
Save neonux/994788 to your computer and use it in GitHub Desktop.
Enforcing depth/stencil:false through DEPTH_TEST/STENCIL_TEST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== in bindFramebuffer(framebuffer) == | |
if (framebuffer == this.DEFAULT_FRAMEBUFFER) { | |
if (!this.contextAttributes.stencil && this.stencilTestEnabled) { | |
// An implementation must make sure no side-effect is possible when | |
// stencil buffer was not explicitly requested by the application. | |
glDisable(STENCIL_TEST); | |
} | |
} else if (this.boundFramebuffer == this.DEFAULT_FRAMEBUFFER && this.stencilTestDirty) { | |
// Currently bound framebuffer is default, now binding to another framebuffer | |
// Enable STENCIL_TEST if it was enabled before binding default framebuffer | |
if (this.stencilTestEnabled) { | |
glEnable(STENCIL_TEST); | |
} | |
this.stencilTestDirty = false; | |
} | |
//...glBindFrameBuffer | |
== in enable(cap) == | |
if (cap == STENCIL_TEST) { | |
this.stencilTestEnabled = true; | |
if (this.boundFramebuffer == DEFAULT_FRAMEBUFFER && !this.contextAttributes.stencil) { | |
this.stencilTestDirty = true; | |
return; | |
// return and not enable the bit since the context did not request a stencil buffer | |
// dirty flag so we later enable it if we bind to another framebuffer | |
} | |
} | |
//...glEnable(cap) | |
== in disable(cap) == | |
if (cap == STENCIL_TEST) { | |
// always go on and disable STENCIL_TEST, clear state flags | |
this.stencilTestEnabled = false; | |
this.stencilTestDirty = false; | |
} | |
//...glDisable(cap) | |
== in isEnabled(cap) == | |
if (cap == STENCIL_TEST) { | |
if (this.boundFrameBuffer == this.DEFAULT_FRAMEBUFFER && !this.contextAttributes.stencil) { | |
return false; | |
} | |
return this.stencilTestEnabled; | |
} | |
//...isEnabled(cap) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment