diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index 3bbe050d1..3976931b5 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -243,6 +243,24 @@ namespace opengl v[3].r = color.r; v[3].g = color.g; v[3].b = color.b; v[3].a = color.a; } + bool SpriteBatch::getConstant(const char * in, UsageHint & out) + { + return usageHints.find(in, out); + } + + bool SpriteBatch::getConstant(UsageHint in, const char *& out) + { + return usageHints.find(in, out); + } + + StringMap::Entry SpriteBatch::usageHintEntries[] = + { + {"dynamic", SpriteBatch::USAGE_DYNAMIC}, + {"static", SpriteBatch::USAGE_STATIC}, + {"stream", SpriteBatch::USAGE_STREAM}, + }; + + StringMap SpriteBatch::usageHints(usageHintEntries, sizeof(usageHintEntries)); } // opengl } // graphics } // love diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h index 0c5fd55c0..40300ce9a 100644 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ b/src/modules/graphics/opengl/SpriteBatch.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -73,9 +74,10 @@ namespace opengl enum UsageHint { - USAGE_DYNAMIC, + USAGE_DYNAMIC = 1, USAGE_STATIC, - USAGE_STREAM + USAGE_STREAM, + USAGE_MAX_ENUM }; SpriteBatch(Image * image, int size, int usage); @@ -108,6 +110,9 @@ namespace opengl // Implements Drawable. void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const; + static bool getConstant(const char * in, UsageHint & out); + static bool getConstant(UsageHint in, const char *& out); + private: void addv(const vertex * v); @@ -121,6 +126,9 @@ namespace opengl */ void setColorv(vertex * v, const Color & color); + static StringMap::Entry usageHintEntries[]; + static StringMap usageHints; + }; // SpriteBatch } // opengl diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 6319835e4..ccc808b30 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -323,7 +323,12 @@ namespace opengl { Image * image = luax_checktype(L, 1, "Image", GRAPHICS_IMAGE_T); int size = luaL_optint(L, 2, 1000); - int usage = luaL_optint(L, 3, SpriteBatch::USAGE_DYNAMIC); + SpriteBatch::UsageHint usage = SpriteBatch::USAGE_DYNAMIC; + if (lua_gettop(L) > 2) + { + if (!SpriteBatch::getConstant(luaL_checkstring(L, 3), usage)) + usage = SpriteBatch::USAGE_DYNAMIC; + } SpriteBatch * t = NULL; try { t = instance->newSpriteBatch(image, size, usage);