mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add string mapping for spritebatch usage parameter (issue #264)
This commit is contained in:
@@ -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;
|
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<SpriteBatch::UsageHint, SpriteBatch::USAGE_MAX_ENUM>::Entry SpriteBatch::usageHintEntries[] =
|
||||||
|
{
|
||||||
|
{"dynamic", SpriteBatch::USAGE_DYNAMIC},
|
||||||
|
{"static", SpriteBatch::USAGE_STATIC},
|
||||||
|
{"stream", SpriteBatch::USAGE_STREAM},
|
||||||
|
};
|
||||||
|
|
||||||
|
StringMap<SpriteBatch::UsageHint, SpriteBatch::USAGE_MAX_ENUM> SpriteBatch::usageHints(usageHintEntries, sizeof(usageHintEntries));
|
||||||
} // opengl
|
} // opengl
|
||||||
} // graphics
|
} // graphics
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <common/Object.h>
|
#include <common/Object.h>
|
||||||
#include <common/Vector.h>
|
#include <common/Vector.h>
|
||||||
#include <common/Matrix.h>
|
#include <common/Matrix.h>
|
||||||
|
#include <common/StringMap.h>
|
||||||
#include <graphics/Drawable.h>
|
#include <graphics/Drawable.h>
|
||||||
#include <graphics/Volatile.h>
|
#include <graphics/Volatile.h>
|
||||||
#include <graphics/Color.h>
|
#include <graphics/Color.h>
|
||||||
@@ -73,9 +74,10 @@ namespace opengl
|
|||||||
|
|
||||||
enum UsageHint
|
enum UsageHint
|
||||||
{
|
{
|
||||||
USAGE_DYNAMIC,
|
USAGE_DYNAMIC = 1,
|
||||||
USAGE_STATIC,
|
USAGE_STATIC,
|
||||||
USAGE_STREAM
|
USAGE_STREAM,
|
||||||
|
USAGE_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
SpriteBatch(Image * image, int size, int usage);
|
SpriteBatch(Image * image, int size, int usage);
|
||||||
@@ -108,6 +110,9 @@ namespace opengl
|
|||||||
// Implements Drawable.
|
// Implements Drawable.
|
||||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
|
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:
|
private:
|
||||||
|
|
||||||
void addv(const vertex * v);
|
void addv(const vertex * v);
|
||||||
@@ -121,6 +126,9 @@ namespace opengl
|
|||||||
*/
|
*/
|
||||||
void setColorv(vertex * v, const Color & color);
|
void setColorv(vertex * v, const Color & color);
|
||||||
|
|
||||||
|
static StringMap<UsageHint, USAGE_MAX_ENUM>::Entry usageHintEntries[];
|
||||||
|
static StringMap<UsageHint, USAGE_MAX_ENUM> usageHints;
|
||||||
|
|
||||||
}; // SpriteBatch
|
}; // SpriteBatch
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
|
|||||||
@@ -323,7 +323,12 @@ namespace opengl
|
|||||||
{
|
{
|
||||||
Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
|
Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
|
||||||
int size = luaL_optint(L, 2, 1000);
|
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;
|
SpriteBatch * t = NULL;
|
||||||
try {
|
try {
|
||||||
t = instance->newSpriteBatch(image, size, usage);
|
t = instance->newSpriteBatch(image, size, usage);
|
||||||
|
|||||||
Reference in New Issue
Block a user