From e02a2679c2616d19615f054fcdb481dd10a4195d Mon Sep 17 00:00:00 2001 From: vrld Date: Thu, 9 Feb 2012 13:19:52 +0100 Subject: [PATCH] Add love.graphics.getPixelEffect() (issue #372) -- thanks, slime73! --- src/modules/graphics/opengl/PixelEffect.cpp | 4 ++++ src/modules/graphics/opengl/PixelEffect.h | 2 ++ src/modules/graphics/opengl/wrap_Graphics.cpp | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/modules/graphics/opengl/PixelEffect.cpp b/src/modules/graphics/opengl/PixelEffect.cpp index ac33c28a0..5ee6db98a 100644 --- a/src/modules/graphics/opengl/PixelEffect.cpp +++ b/src/modules/graphics/opengl/PixelEffect.cpp @@ -44,6 +44,8 @@ namespace graphics { namespace opengl { + PixelEffect * PixelEffect::current = NULL; + std::map PixelEffect::_texture_unit_pool; GLint PixelEffect::_current_texture_unit = 0; GLint PixelEffect::_max_texture_units = 0; @@ -180,11 +182,13 @@ namespace opengl void PixelEffect::attach() { glUseProgram(_program); + current = this; } void PixelEffect::detach() { glUseProgram(0); + current = NULL; } void PixelEffect::sendFloat(const std::string& name, int size, const GLfloat* vec, int count) diff --git a/src/modules/graphics/opengl/PixelEffect.h b/src/modules/graphics/opengl/PixelEffect.h index 552e4ad0f..8a86185ac 100644 --- a/src/modules/graphics/opengl/PixelEffect.h +++ b/src/modules/graphics/opengl/PixelEffect.h @@ -49,6 +49,8 @@ namespace opengl static void detach(); static std::string getGLSLVersion(); static bool isSupported(); + + static PixelEffect * current; void sendFloat(const std::string& name, int size, const GLfloat* vec, int count); void sendMatrix(const std::string& name, int size, const GLfloat* m, int count); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 2360df2b4..d98407697 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -754,6 +754,20 @@ namespace opengl effect->attach(); return 0; } + + int w_getPixelEffect(lua_State * L) + { + PixelEffect * effect = PixelEffect::current; + if (effect) + { + effect->retain(); + luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void*) effect); + } + else + lua_pushnil(L); + + return 1; + } int w_isSupported(lua_State * L) { @@ -1214,6 +1228,7 @@ namespace opengl { "getCanvas", w_getCanvas }, { "setPixelEffect", w_setPixelEffect }, + { "getPixelEffect", w_getPixelEffect }, { "isSupported", w_isSupported },