From 30d6968ef978d01c617272907598b789f2a81bbc Mon Sep 17 00:00:00 2001 From: vrld Date: Mon, 30 May 2011 14:45:33 +0200 Subject: [PATCH] Rename 'defineMask' to 'newMask'. Add inverted mask (issue #226). --- src/modules/graphics/opengl/Graphics.cpp | 4 ++-- src/modules/graphics/opengl/Graphics.h | 4 +++- src/modules/graphics/opengl/wrap_Graphics.cpp | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index ce76d5426..fa94a7853 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -437,9 +437,9 @@ namespace opengl glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); } - void Graphics::useMask() + void Graphics::useMask(bool invert) { - glStencilFunc(GL_EQUAL, 1, 1); + glStencilFunc(GL_EQUAL, (int)(!invert), 1); // invert ? 0 : 1 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 8be7661f2..ee1c09fc6 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -242,8 +242,10 @@ namespace opengl /** * Set stencil function to mask the following drawing calls using * the current stencil buffer + * @param invert Invert the mask, i.e. draw everywhere expect where + * the mask is defined. */ - void useMask(); + void useMask(bool invert = false); /** * Disables the stencil buffer diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 4983116b2..8fdb63f64 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -144,7 +144,7 @@ namespace opengl return instance->getScissor(L); } - int w_defineMask(lua_State * L) + int w_newMask(lua_State * L) { // just return the function if (!lua_isfunction(L, 1)) @@ -153,7 +153,7 @@ namespace opengl return 1; } - int w_setMask(lua_State * L) + static int setMask(lua_State * L, bool invert) { // no argument -> clear mask if (lua_isnoneornil(L, 1)) { @@ -166,11 +166,21 @@ namespace opengl instance->defineMask(); lua_call(L, lua_gettop(L) - 1, 0); // call mask(...) - instance->useMask(); + instance->useMask(invert); return 0; } + int w_setMask(lua_State * L) + { + return setMask(L, false); + } + + int w_setInvertedMask(lua_State * L) + { + return setMask(L, true); + } + int w_newImage(lua_State * L) { // Convert to File, if necessary. @@ -1047,8 +1057,9 @@ namespace opengl { "setScissor", w_setScissor }, { "getScissor", w_getScissor }, - { "defineMask", w_defineMask }, + { "newMask", w_newMask }, { "setMask", w_setMask }, + { "setInvertedMask", w_setInvertedMask }, { "point", w_point }, { "line", w_line },