diff --git a/gfx_es2/gl_state.cpp b/gfx_es2/gl_state.cpp index 19f3b4a9bc..488bdaf950 100644 --- a/gfx_es2/gl_state.cpp +++ b/gfx_es2/gl_state.cpp @@ -35,6 +35,10 @@ void OpenGLState::Restore() { colorMask.restore(); count++; viewport.restore(); count++; + stencilTest.restore(); count++; + stencilOp.restore(); count++; + stencilFunc.restore(); count++; + assert(count == state_count && "OpenGLState::Restore is missing some states"); } @@ -53,4 +57,3 @@ void CheckGLExtensions() { gl_extensions.OES_depth_texture = strstr(extString, "GL_OES_depth_texture") != 0; gl_extensions.EXT_discard_framebuffer = strstr(extString, "GL_EXT_discard_framebuffer") != 0; } - diff --git a/gfx_es2/gl_state.h b/gfx_es2/gl_state.h index eac3b26cd6..c02d8ef083 100644 --- a/gfx_es2/gl_state.h +++ b/gfx_es2/gl_state.h @@ -86,6 +86,28 @@ private: } \ } + #define STATE3(func, p1type, p2type, p3type, p1def, p2def, p3def) \ + class SavedState3_##func { \ + p1type p1; \ + p2type p2; \ + p3type p3; \ + public: \ + SavedState3_##func() : p1(p1def), p2(p2def), p3(p3def) { \ + OpenGLState::state_count++; \ + }; \ + inline void set(p1type newp1, p2type newp2, p3type newp3) { \ + if(newp1 != p1 || newp2 != p2 || newp3 != p3) { \ + p1 = newp1; \ + p2 = newp2; \ + p3 = newp3; \ + func(p1, p2, p3); \ + } \ + } \ + inline void restore() { \ + func(p1, p2, p3); \ + } \ + } + #define STATE4(func, p1type, p2type, p3type, p4type, p1def, p2def, p3def, p4def) \ class SavedState4_##func { \ p1type p1; \ @@ -161,6 +183,10 @@ public: STATE4(glColorMask, bool, bool, bool, bool, true, true, true, true) colorMask; STATE4(glViewport, GLint, GLint, GLsizei, GLsizei, 0, 0, 128, 128) viewport; + + BoolState stencilTest; + STATE3(glStencilOp, GLenum, GLenum, GLenum, GL_KEEP, GL_KEEP, GL_KEEP) stencilOp; + STATE3(glStencilFunc, GLenum, GLint, GLuint, GL_ALWAYS, 0, 0xFF) stencilFunc; }; #undef STATE1