From e661459103348e80233cbec87998d5479ea80556 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Tue, 9 Feb 2010 14:30:41 -0500 Subject: [PATCH] Switched Image filter modes to use the new string constant system --- .../macosx/love.xcodeproj/project.pbxproj | 6 ++- src/modules/graphics/Image.cpp | 50 ++++++++++++++++++ src/modules/graphics/Image.h | 52 +++++++++++-------- src/modules/graphics/opengl/Image.cpp | 4 ++ src/modules/graphics/opengl/wrap_Image.cpp | 27 ++++++++-- 5 files changed, 112 insertions(+), 27 deletions(-) create mode 100644 src/modules/graphics/Image.cpp diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index df3288a3c..46e5383f7 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ A9255F461043247300BA1496 /* IL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9255F421043240F00BA1496 /* IL.framework */; }; A9255F52104324D700BA1496 /* Ogg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9255F51104324D700BA1496 /* Ogg.framework */; }; A9255F58104324E100BA1496 /* Ogg.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9255F51104324D700BA1496 /* Ogg.framework */; }; + A93A3AB51121E86E003B04A4 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93A3AB41121E86E003B04A4 /* Image.cpp */; }; A93E6E4910420B4A007D418B /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E4610420B4A007D418B /* OpenAL.framework */; }; A93E6E4A10420B4A007D418B /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E4710420B4A007D418B /* OpenGL.framework */; }; A93E6E4B10420B4A007D418B /* FreeType.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E4810420B4A007D418B /* FreeType.framework */; }; @@ -225,6 +226,7 @@ A9255E021043195A00BA1496 /* Vorbis.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Vorbis.framework; path = /Library/Frameworks/Vorbis.framework; sourceTree = ""; }; A9255F421043240F00BA1496 /* IL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IL.framework; path = /Library/Frameworks/IL.framework; sourceTree = ""; }; A9255F51104324D700BA1496 /* Ogg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Ogg.framework; path = /Library/Frameworks/Ogg.framework; sourceTree = ""; }; + A93A3AB41121E86E003B04A4 /* Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Image.cpp; sourceTree = ""; }; A93E69DE10420ABF007D418B /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = ""; }; A93E69DF10420ABF007D418B /* Data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Data.h; sourceTree = ""; }; A93E69E010420ABF007D418B /* Exception.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Exception.cpp; sourceTree = ""; }; @@ -950,6 +952,7 @@ A93E6A8310420AC2007D418B /* Drawable.h */, A968F0D21083A9D400A895AA /* Graphics.cpp */, A93E6A8410420AC2007D418B /* Graphics.h */, + A93A3AB41121E86E003B04A4 /* Image.cpp */, A93E6A8510420AC2007D418B /* Image.h */, A93E6A8610420AC2007D418B /* opengl */, A93E6AA510420AC3007D418B /* Volatile.cpp */, @@ -1003,8 +1006,8 @@ isa = PBXGroup; children = ( A93E6AA810420AC3007D418B /* devil */, - A98D913E10507BF9008E03F2 /* EncodedImageData.h */, A98D914310507C97008E03F2 /* EncodedImageData.cpp */, + A98D913E10507BF9008E03F2 /* EncodedImageData.h */, A93E6AAD10420AC3007D418B /* Image.h */, A93E6AAE10420AC3007D418B /* ImageData.cpp */, A93E6AAF10420AC3007D418B /* ImageData.h */, @@ -1616,6 +1619,7 @@ A968F0DD1083AA6600A895AA /* Shape.cpp in Sources */, A968F0DE1083AA6600A895AA /* Joint.cpp in Sources */, A9CF0E8610B9EB1000E6F37E /* utf8.cpp in Sources */, + A93A3AB51121E86E003B04A4 /* Image.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/modules/graphics/Image.cpp b/src/modules/graphics/Image.cpp new file mode 100644 index 000000000..a0ac4b793 --- /dev/null +++ b/src/modules/graphics/Image.cpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2006-2010 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "Image.h" + +namespace love +{ +namespace graphics +{ + Image::~Image() + { + } + + bool Image::getConstant(const char * in, FilterMode & out) + { + return filterModes.find(in, out); + } + + bool Image::getConstant(FilterMode in, const char *& out) + { + return filterModes.find(in, out); + } + + StringMap::Entry Image::filterModeEntries[] = + { + { "linear", Image::FILTER_LINEAR }, + { "nearest", Image::FILTER_NEAREST }, + }; + + StringMap Image::filterModes(Image::filterModeEntries, sizeof(Image::filterModeEntries)); + +} // graphics +} // love diff --git a/src/modules/graphics/Image.h b/src/modules/graphics/Image.h index 74e2754f0..91a54e613 100644 --- a/src/modules/graphics/Image.h +++ b/src/modules/graphics/Image.h @@ -1,21 +1,21 @@ -/** -* Copyright (c) 2006-2010 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. +/** +* Copyright (c) 2006-2010 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. **/ #ifndef LOVE_GRAPHICS_IMAGE_H @@ -24,6 +24,7 @@ // LOVE #include #include +#include namespace love { @@ -42,8 +43,9 @@ namespace graphics enum FilterMode { - FILTER_LINEAR, - FILTER_NEAREST + FILTER_LINEAR = 1, + FILTER_NEAREST, + FILTER_MAX_ENUM }; struct Filter @@ -58,7 +60,15 @@ namespace graphics WrapMode t; }; - virtual ~Image(){}; + virtual ~Image(); + + static bool getConstant(const char * in, FilterMode & out); + static bool getConstant(FilterMode in, const char *& out); + + private: + + static StringMap::Entry filterModeEntries[]; + static StringMap filterModes; }; // Image diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 5c5fd1482..e31fa7fbb 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -133,6 +133,8 @@ namespace opengl case FILTER_NEAREST: gmin = GL_NEAREST; break; + default: + break; } switch(f.mag) @@ -143,6 +145,8 @@ namespace opengl case FILTER_NEAREST: gmag = GL_NEAREST; break; + default: + break; } bind(); diff --git a/src/modules/graphics/opengl/wrap_Image.cpp b/src/modules/graphics/opengl/wrap_Image.cpp index b80886441..897a61219 100644 --- a/src/modules/graphics/opengl/wrap_Image.cpp +++ b/src/modules/graphics/opengl/wrap_Image.cpp @@ -48,10 +48,19 @@ namespace opengl int w_Image_setFilter(lua_State * L) { - Image * t = luax_checkimage(L, 1); + Image * t = luax_checkimage(L, 1); Image::Filter f; - f.min = (Image::FilterMode)luaL_checkint(L, 2); - f.mag = (Image::FilterMode)luaL_checkint(L, 3); + Image::FilterMode min; + Image::FilterMode mag; + const char * minstr = luaL_checkstring(L, 2); + const char * magstr = luaL_checkstring(L, 3); + if (!Image::getConstant(minstr, min)) + return luaL_error(L, "Invalid filter mode: %s", minstr); + if (!Image::getConstant(magstr, mag)) + return luaL_error(L, "Invalid filter mode: %s", magstr); + + f.min = min; + f.mag = mag; t->setFilter(f); return 0; } @@ -60,8 +69,16 @@ namespace opengl { Image * t = luax_checkimage(L, 1); Image::Filter f = t->getFilter(); - lua_pushinteger(L, f.min); - lua_pushinteger(L, f.mag); + Image::FilterMode min = f.min; + Image::FilterMode mag = f.mag; + const char * minstr; + const char * magstr; + if (!Image::getConstant(min, minstr)) + return luaL_error(L, "Invalid filter mode: %s", minstr); + if (!Image::getConstant(mag, magstr)) + return luaL_error(L, "Invalid filter mode: %s", magstr); + lua_pushstring(L, minstr); + lua_pushstring(L, magstr); return 2; }