From dc2d87a90f50360e833553998f71c408f62db269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Romero?= Date: Wed, 27 Apr 2011 16:35:14 +0200 Subject: [PATCH] Apply patch for issue #219 --- src/modules/graphics/opengl/SpriteBatch.cpp | 7 +++++++ src/modules/graphics/opengl/SpriteBatch.h | 2 ++ src/modules/graphics/opengl/wrap_SpriteBatch.cpp | 11 ++++++++++- src/modules/graphics/opengl/wrap_SpriteBatch.h | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index e0b51b367..ca5762f13 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -171,6 +171,13 @@ namespace opengl glBindBuffer(GL_ARRAY_BUFFER, 0); } + void SpriteBatch::setImage(Image * newimage) + { + image->release(); + image = newimage; + image->retain(); + } + void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const { static Matrix t; diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h index e375b912c..e6290d6fc 100644 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ b/src/modules/graphics/opengl/SpriteBatch.h @@ -96,6 +96,8 @@ namespace opengl void * lock(); void unlock(); + void setImage(Image * newimage); + // Implements Drawable. void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp index b6611f366..f9f6122b2 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp @@ -81,12 +81,21 @@ namespace opengl return 0; } + int w_SpriteBatch_setImage(lua_State * L) + { + SpriteBatch * t = luax_checkspritebatch(L, 1); + Image * image = luax_checktype(L, 2, "Image", GRAPHICS_IMAGE_T); + t->setImage(image); + return 0; + } + static const luaL_Reg functions[] = { { "add", w_SpriteBatch_add }, { "addq", w_SpriteBatch_addq }, { "clear", w_SpriteBatch_clear }, { "lock", w_SpriteBatch_lock }, { "unlock", w_SpriteBatch_unlock }, + { "setImage", w_SpriteBatch_setImage }, { 0, 0 } }; @@ -97,4 +106,4 @@ namespace opengl } // opengl } // graphics -} // love \ No newline at end of file +} // love diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.h b/src/modules/graphics/opengl/wrap_SpriteBatch.h index b85b65899..d2ced3d63 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.h +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.h @@ -36,6 +36,8 @@ namespace opengl int w_SpriteBatch_clear(lua_State * L); int w_SpriteBatch_lock(lua_State * L); int w_SpriteBatch_unlock(lua_State * L); + int w_SpriteBatch_setImage(lua_State * L); + int luaopen_spritebatch(lua_State * L); } // opengl