Skip to content

Instantly share code, notes, and snippets.

@neonux
Created May 27, 2011 07:14
Show Gist options
  • Save neonux/994788 to your computer and use it in GitHub Desktop.
Save neonux/994788 to your computer and use it in GitHub Desktop.
Enforcing depth/stencil:false through DEPTH_TEST/STENCIL_TEST
== 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