From d11ccd0e69514517d6bfd937d5add1960f1efaa4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 5 Jul 2014 16:22:52 -0300 Subject: [PATCH] Added love.graphics.getCanvasFormats and love.graphics.getCompressedImageFormats, and removed love.graphics.hasCanvasFormat. The two new functions return tables containing the names of all relevant formats as keys, and boolean values indicating whether the formats are supported. --- changes.txt | 11 +- src/modules/graphics/Graphics.cpp | 1 - src/modules/graphics/Graphics.h | 1 - src/modules/graphics/opengl/Graphics.cpp | 31 ++++++ src/modules/graphics/opengl/Graphics.h | 5 + src/modules/graphics/opengl/wrap_Graphics.cpp | 105 ++++++++---------- src/modules/graphics/opengl/wrap_Graphics.h | 3 +- 7 files changed, 92 insertions(+), 65 deletions(-) diff --git a/changes.txt b/changes.txt index 7288795f5..862ba8149 100644 --- a/changes.txt +++ b/changes.txt @@ -5,13 +5,19 @@ LOVE 0.9.2 [Baby Inspector] * Added Shader:getExternVariable. * Added several new canvas texture formats. - * Added love.graphics.hasCanvasFormat. - * Added an optional duration argument to Joystick:setVibration. + * Added love.graphics.getCanvasFormats. + * Added love.graphics.getCompressedImageFormats. + * Added ParticleSystem:setQuads. + * Added SpriteBatch:flush. + * Added optional duration argument to Joystick:setVibration. * Added love.joystick.loadGamepadMappings and love.joystick.saveGamepadMappings. * Added Joint:setUserData and Joint:getUserData. * Added Body:getWorld. * Added love.window.getDisplayName. + * Deprecated SpriteBatch:bind and SpriteBatch:unbind. + * Deprecated all uses of the name 'FSAA'. + * Fixed shader:getWarnings returning unnecessary information. * Fixed love.filesystem.setIdentity breaking in some situations when called multiple times. * Fixed a potential crash when Shader objects are garbage collected. @@ -20,6 +26,7 @@ LOVE 0.9.2 [Baby Inspector] * Fixed Image:refresh generating mipmaps multiple times if mipmap filtering is enabled. * Fixed Mesh:setDrawRange when the Mesh has a vertex map set. * Fixed internal detection of the 'position' and 'effect' shader functions. + * Fixed Texture memory leak when Meshes are garbage collected. * Renamed all cases of FSAA to MSAA. The FSAA names still exist for backward-compatibility. diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 1b86bcdee..5688e5650 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -176,7 +176,6 @@ StringMap::Entry Graphics::suppor { "mipmap", Graphics::SUPPORT_MIPMAP }, { "dxt", Graphics::SUPPORT_DXT }, { "bc5", Graphics::SUPPORT_BC5 }, - { "instancing", Graphics::SUPPORT_INSTANCING }, { "srgb", Graphics::SUPPORT_SRGB }, }; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 715abe36b..9032b6c77 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -98,7 +98,6 @@ public: SUPPORT_MIPMAP, SUPPORT_DXT, SUPPORT_BC5, - SUPPORT_INSTANCING, SUPPORT_SRGB, SUPPORT_MAX_ENUM }; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 728a0c195..e92fee095 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1123,6 +1123,37 @@ double Graphics::getSystemLimit(SystemLimit limittype) const return limit; } +bool Graphics::isSupported(Support feature) const +{ + switch (feature) + { + case SUPPORT_CANVAS: + return Canvas::isSupported(); + case SUPPORT_HDR_CANVAS: + return Canvas::isFormatSupported(Canvas::FORMAT_HDR); + case SUPPORT_MULTI_CANVAS: + return Canvas::isMultiCanvasSupported(); + case SUPPORT_SHADER: + return Shader::isSupported(); + case SUPPORT_NPOT: + return Image::hasNpot(); + case SUPPORT_SUBTRACTIVE: + return (GLEE_VERSION_1_4 || GLEE_ARB_imaging) || (GLEE_EXT_blend_minmax && GLEE_EXT_blend_subtract); + case SUPPORT_MIPMAP: + return Image::hasMipmapSupport(); + case SUPPORT_DXT: + return Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5); + case SUPPORT_BC5: + return Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5); + case SUPPORT_SRGB: + // sRGB support for the screen is guaranteed if it's supported as a + // Canvas format. + return Canvas::isFormatSupported(Canvas::FORMAT_SRGB); + default: + return false; + } +} + void Graphics::push() { if (userMatrices == matrixLimit) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index b2ba4dfe2..bad07f0d9 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -455,6 +455,11 @@ public: **/ double getSystemLimit(SystemLimit limittype) const; + /** + * Gets whether a graphics feature is supported on this system. + **/ + bool isSupported(Support feature) const; + void push(); void pop(); void rotate(float r); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index d64f939d4..509933968 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -989,79 +989,63 @@ int w_getShader(lua_State *L) int w_isSupported(lua_State *L) { bool supported = true; - size_t len = lua_gettop(L); - Graphics::Support support; - for (unsigned int i = 1; i <= len; i++) + + for (int i = 1; i <= lua_gettop(L); i++) { const char *str = luaL_checkstring(L, i); - if (!Graphics::getConstant(str, support)) + Graphics::Support feature; + if (!Graphics::getConstant(str, feature)) return luaL_error(L, "Invalid graphics feature: %s", str); - switch (support) + if (!instance->isSupported(feature)) { - case Graphics::SUPPORT_CANVAS: - if (!Canvas::isSupported()) - supported = false; - break; - case Graphics::SUPPORT_HDR_CANVAS: - if (!Canvas::isFormatSupported(Canvas::FORMAT_HDR)) - supported = false; - break; - case Graphics::SUPPORT_MULTI_CANVAS: - if (!Canvas::isMultiCanvasSupported()) - supported = false; - break; - case Graphics::SUPPORT_SHADER: - if (!Shader::isSupported()) - supported = false; - break; - case Graphics::SUPPORT_NPOT: - if (!Image::hasNpot()) - supported = false; - break; - case Graphics::SUPPORT_SUBTRACTIVE: - if (!((GLEE_VERSION_1_4 || GLEE_ARB_imaging) || (GLEE_EXT_blend_minmax && GLEE_EXT_blend_subtract))) - supported = false; - break; - case Graphics::SUPPORT_MIPMAP: - if (!Image::hasMipmapSupport()) - supported = false; - break; - case Graphics::SUPPORT_DXT: - if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_DXT5)) - supported = false; - break; - case Graphics::SUPPORT_BC5: - if (!Image::hasCompressedTextureSupport(image::CompressedData::FORMAT_BC5)) - supported = false; - break; - case Graphics::SUPPORT_INSTANCING: - if (!GLEE_ARB_draw_instanced) - supported = false; - break; - case Graphics::SUPPORT_SRGB: - if (!Canvas::isFormatSupported(Canvas::FORMAT_SRGB)) - supported = false; - break; - default: supported = false; - } - if (!supported) break; + } } - lua_pushboolean(L, supported); + + luax_pushboolean(L, supported); return 1; } -int w_hasCanvasFormat(lua_State *L) +int w_getCanvasFormats(lua_State *L) { - const char *str = luaL_checkstring(L, 1); - Canvas::Format format; + lua_createtable(L, 0, (int) Canvas::FORMAT_MAX_ENUM); - if (!Canvas::getConstant(str, format)) - return luaL_error(L, "Invalid canvas format: %s", str); + for (int i = 0; i < (int) Canvas::FORMAT_MAX_ENUM; i++) + { + Canvas::Format format = (Canvas::Format) i; + const char *name = nullptr; + + if (!Canvas::getConstant(format, name)) + continue; + + luax_pushboolean(L, Canvas::isFormatSupported(format)); + lua_setfield(L, -2, name); + } + + return 1; +} + +int w_getCompressedImageFormats(lua_State *L) +{ + lua_createtable(L, 0, (int) image::CompressedData::FORMAT_MAX_ENUM); + + for (int i = 0; i < (int) image::CompressedData::FORMAT_MAX_ENUM; i++) + { + image::CompressedData::Format format = (image::CompressedData::Format) i; + const char *name = nullptr; + + if (format == image::CompressedData::FORMAT_UNKNOWN) + continue; + + if (!image::CompressedData::getConstant(format, name)) + continue; + + luax_pushboolean(L, Image::hasCompressedTextureSupport(format)); + lua_setfield(L, -2, name); + } - luax_pushboolean(L, Canvas::isFormatSupported(format)); return 1; } @@ -1440,7 +1424,8 @@ static const luaL_Reg functions[] = { "getShader", w_getShader }, { "isSupported", w_isSupported }, - { "hasCanvasFormat", w_hasCanvasFormat }, + { "getCanvasFormats", w_getCanvasFormats }, + { "getCompressedImageFormats", w_getCompressedImageFormats }, { "getRendererInfo", w_getRendererInfo }, { "getSystemLimit", w_getSystemLimit }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 9a18bb7f3..7f98a44ea 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -93,7 +93,8 @@ int w_getCanvas(lua_State *L); int w_setShader(lua_State *L); int w_getShader(lua_State *L); int w_isSupported(lua_State *L); -int w_hasCanvasFormat(lua_State *L); +int w_getCanvasFormats(lua_State *L); +int w_getCompressedImageFormats(lua_State *L); int w_getRendererInfo(lua_State *L); int w_getSystemLimit(lua_State *L); int w_draw(lua_State *L);