From 034fce91477c191930184a7230c142fa2d176188 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 4 Apr 2012 12:19:17 -0300 Subject: [PATCH] improve clipping performance --- src/framework/graphics/graphics.cpp | 15 +++++++++++---- src/framework/platform/win32window.cpp | 2 +- src/framework/platform/x11window.cpp | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 062da5ea..2ba60eca 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -135,7 +135,7 @@ void Graphics::resize(const Size& size) void Graphics::beginRender() { glClearColor(0, 0, 0, 1); - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } void Graphics::endRender() @@ -154,10 +154,17 @@ void Graphics::endRender() void Graphics::beginClipping(const Rect& clipRect) { + static uint8 depth = 0; + + depth++; + if(depth == 0) { + glClear(GL_STENCIL_BUFFER_BIT); + depth = 1; + } + // setup stencil buffer for writing - glClear(GL_STENCIL_BUFFER_BIT); glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_ALWAYS, 1, 1); + glStencilFunc(GL_ALWAYS, depth, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // draw the clipping area into the stencil buffer @@ -166,7 +173,7 @@ void Graphics::beginClipping(const Rect& clipRect) // set stencil buffer for clipping glColorMask(1, 1, 1, 1); - glStencilFunc(GL_EQUAL, 1, 1); + glStencilFunc(GL_EQUAL, depth, 0xff); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index e260e6cd..b2e64598 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -310,7 +310,7 @@ void WIN32Window::internalChooseGLVisual() 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) - 1, // 1Bit Stencil Buffer + 8, // 8Bit Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 6de33056..56882bf4 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -369,7 +369,7 @@ void X11Window::internalChooseGLVisual() GLX_USE_GL, GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_STENCIL_SIZE, 1, + GLX_STENCIL_SIZE, 8, /* GLX_ACCUM_RED_SIZE, 8, GLX_ACCUM_GREEN_SIZE, 8,