diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 9d6b22e38..92ec20d9e 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -88,6 +88,16 @@ namespace graphics return pointStyles.find(in, out); } + bool Graphics::getConstant(const char * in, Support & out) + { + return support.find(in, out); + } + + bool Graphics::getConstant(Support in, const char *& out) + { + return support.find(in, out); + } + StringMap::Entry Graphics::drawModeEntries[] = { { "line", Graphics::DRAW_LINE }, @@ -139,5 +149,13 @@ namespace graphics StringMap Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries)); + StringMap::Entry Graphics::supportEntries[] = + { + { "framebuffers", Graphics::SUPPORT_FRAMEBUFFERS }, + { "pixeleffects", Graphics::SUPPORT_PIXELEFFECTS } + }; + + StringMap Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries)); + } // graphics } // love diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 24923bd44..e48edaca1 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -78,6 +78,13 @@ namespace graphics POINT_MAX_ENUM }; + enum Support + { + SUPPORT_FRAMEBUFFERS = 1, + SUPPORT_PIXELEFFECTS, + SUPPORT_MAX_ENUM + }; + virtual ~Graphics(); static bool getConstant(const char * in, DrawMode & out); @@ -98,6 +105,9 @@ namespace graphics static bool getConstant(const char * in, PointStyle & out); static bool getConstant(PointStyle in, const char *& out); + static bool getConstant(const char * in, Support & out); + static bool getConstant(Support in, const char *& out); + private: static StringMap::Entry drawModeEntries[]; @@ -118,6 +128,9 @@ namespace graphics static StringMap::Entry pointStyleEntries[]; static StringMap pointStyles; + static StringMap::Entry supportEntries[]; + static StringMap support; + }; // Graphics } // graphics diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 11f7c8cff..e5ad3aeee 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -183,6 +183,19 @@ namespace opengl unloadVolatile(); } + bool Framebuffer::isSupported() + { + if (!strategy) { + if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object) + strategy = &strategyGL3; + else if (GLEE_EXT_framebuffer_object) + strategy = &strategyEXT; + else + strategy = &strategyNone; + } + return (strategy != &strategyNone); + } + void Framebuffer::bindDefaultBuffer() { if (current != NULL) diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index 6becfd600..13fafb4dd 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -22,6 +22,8 @@ namespace opengl Framebuffer(int width, int height); virtual ~Framebuffer(); + static bool isSupported(); + unsigned int getStatus() const { return status; } static Framebuffer* current; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 56df859fd..208dcc376 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -741,9 +741,33 @@ namespace opengl return 0; } - int w_hasPixelEffects(lua_State * L) + int w_isSupported(lua_State * L) { - lua_pushboolean(L, PixelEffect::isSupported()); + bool supported = true; + size_t len = lua_gettop(L); + Graphics::Support support; + for (unsigned int i = 1; i <= len; i++) + { + const char * str = luaL_checkstring(L, i); + if(!Graphics::getConstant(str, support)) + supported = false; + switch(support) + { + case Graphics::SUPPORT_FRAMEBUFFERS: + if (!Framebuffer::isSupported()) + supported = false; + break; + case Graphics::SUPPORT_PIXELEFFECTS: + if (!PixelEffect::isSupported()) + supported = false; + break; + default: + supported = false; + } + if (!supported) + break; + } + lua_pushboolean(L, supported); return 1; } @@ -1149,7 +1173,8 @@ namespace opengl { "setRenderTarget", w_setRenderTarget }, { "setPixelEffect", w_setPixelEffect }, - { "hasPixelEffects", w_hasPixelEffects }, + + { "isSupported", w_isSupported }, { "draw", w_draw }, { "drawq", w_drawq }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 8c45601c2..84fcf913a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -89,7 +89,7 @@ namespace opengl int w_newScreenshot(lua_State * L); int w_setRenderTarget(lua_State * L); int w_setPixelEffect(lua_State * L); - int w_hasPixelEffects(lua_State * L); + int w_isSupported(lua_State * L); int w_getGLSLVersion(lua_State * L); int w_draw(lua_State * L); int w_drawq(lua_State * L); diff --git a/src/modules/graphics/opengl/wrap_PixelEffect.cpp b/src/modules/graphics/opengl/wrap_PixelEffect.cpp index ad7de2f38..907722d99 100644 --- a/src/modules/graphics/opengl/wrap_PixelEffect.cpp +++ b/src/modules/graphics/opengl/wrap_PixelEffect.cpp @@ -31,8 +31,8 @@ namespace opengl return luaL_error(L, "Invalid variable count (expected 1-4, got %d).", count); float values[4] = {0,0,0,0}; - for (int i = 0; i < count; ++i) - values[i] = luaL_checknumber(L, i+1 + 2); + for (unsigned int i = 0; i < count; ++i) + values[i] = (float) luaL_checknumber(L, i+1 + 2); try { effect->sendFloat(name, count, values); @@ -54,8 +54,8 @@ namespace opengl return luaL_error(L, "Invalid matrix size: %dx%d (only 2x2, 3x3 and 4x4 matrices are supported).", count, count); float values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - for (int i = 0; i < count; ++i) - values[i] = luaL_checknumber(L, i+1 + 3); + for (unsigned int i = 0; i < count; ++i) + values[i] = (float) luaL_checknumber(L, i+1 + 3); try { effect->sendFloat(name, size, values);