mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Changed SpriteBatch:add/set to do an internal bind, and love.graphics.draw(SpriteBatch) to do an internal unbind. Removed SpriteBatch:bind/unbind, and added SpriteBatch:flush.
Resolves issue #886. --HG-- branch : minor
This commit is contained in:
@@ -160,17 +160,9 @@ void SpriteBatch::clear()
|
|||||||
next = 0;
|
next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *SpriteBatch::lock()
|
void SpriteBatch::flush()
|
||||||
{
|
{
|
||||||
VertexBuffer::Bind bind(*array_buf);
|
VertexBuffer::Bind bind(*array_buf);
|
||||||
|
|
||||||
return array_buf->map();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpriteBatch::unlock()
|
|
||||||
{
|
|
||||||
VertexBuffer::Bind bind(*array_buf);
|
|
||||||
|
|
||||||
array_buf->unmap();
|
array_buf->unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,14 +211,18 @@ void SpriteBatch::setBufferSize(int newsize)
|
|||||||
if (newsize == size)
|
if (newsize == size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Map (lock) the old VertexBuffer to get a pointer to its data.
|
// Map the old VertexBuffer to get a pointer to its data.
|
||||||
void *old_data = lock();
|
void *old_data = nullptr;
|
||||||
|
{
|
||||||
|
VertexBuffer::Bind bind(*array_buf);
|
||||||
|
old_data = array_buf->map();
|
||||||
|
}
|
||||||
|
|
||||||
size_t vertex_size = sizeof(Vertex) * 4 * newsize;
|
size_t vertex_size = sizeof(Vertex) * 4 * newsize;
|
||||||
|
|
||||||
VertexBuffer *new_array_buf = 0;
|
VertexBuffer *new_array_buf = nullptr;
|
||||||
VertexIndex *new_element_buf = 0;
|
VertexIndex *new_element_buf = nullptr;
|
||||||
void *new_data = 0;
|
void *new_data = nullptr;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -241,7 +237,12 @@ void SpriteBatch::setBufferSize(int newsize)
|
|||||||
{
|
{
|
||||||
delete new_array_buf;
|
delete new_array_buf;
|
||||||
delete new_element_buf;
|
delete new_element_buf;
|
||||||
unlock();
|
|
||||||
|
{
|
||||||
|
VertexBuffer::Bind bind(*array_buf);
|
||||||
|
array_buf->unmap();
|
||||||
|
}
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,8 +259,11 @@ void SpriteBatch::setBufferSize(int newsize)
|
|||||||
|
|
||||||
next = std::min(next, newsize);
|
next = std::min(next, newsize);
|
||||||
|
|
||||||
// But we should unmap (unlock) the new one!
|
// But we should unmap the new one!
|
||||||
unlock();
|
{
|
||||||
|
VertexBuffer::Bind bind(*new_array_buf);
|
||||||
|
new_array_buf->unmap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpriteBatch::getBufferSize() const
|
int SpriteBatch::getBufferSize() const
|
||||||
@@ -269,7 +273,7 @@ int SpriteBatch::getBufferSize() const
|
|||||||
|
|
||||||
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||||
{
|
{
|
||||||
const size_t vertex_offset = offsetof(Vertex, x);
|
const size_t pos_offset = offsetof(Vertex, x);
|
||||||
const size_t texel_offset = offsetof(Vertex, s);
|
const size_t texel_offset = offsetof(Vertex, s);
|
||||||
const size_t color_offset = offsetof(Vertex, r);
|
const size_t color_offset = offsetof(Vertex, r);
|
||||||
|
|
||||||
@@ -288,6 +292,9 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
|||||||
VertexBuffer::Bind array_bind(*array_buf);
|
VertexBuffer::Bind array_bind(*array_buf);
|
||||||
VertexBuffer::Bind element_bind(*element_buf->getVertexBuffer());
|
VertexBuffer::Bind element_bind(*element_buf->getVertexBuffer());
|
||||||
|
|
||||||
|
// Make sure the VBO isn't mapped when we draw (sends data to GPU if needed.)
|
||||||
|
array_buf->unmap();
|
||||||
|
|
||||||
Color curcolor = gl.getColor();
|
Color curcolor = gl.getColor();
|
||||||
|
|
||||||
// Apply per-sprite color, if a color is set.
|
// Apply per-sprite color, if a color is set.
|
||||||
@@ -298,7 +305,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
|||||||
}
|
}
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(vertex_offset));
|
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(pos_offset));
|
||||||
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(texel_offset));
|
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(texel_offset));
|
||||||
@@ -323,7 +330,13 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
|||||||
void SpriteBatch::addv(const Vertex *v, int index)
|
void SpriteBatch::addv(const Vertex *v, int index)
|
||||||
{
|
{
|
||||||
static const int sprite_size = 4 * sizeof(Vertex); // bytecount
|
static const int sprite_size = 4 * sizeof(Vertex); // bytecount
|
||||||
|
|
||||||
VertexBuffer::Bind bind(*array_buf);
|
VertexBuffer::Bind bind(*array_buf);
|
||||||
|
|
||||||
|
// Always keep the VBO mapped when adding data for now (it'll be unmapped
|
||||||
|
// on draw.)
|
||||||
|
array_buf->map();
|
||||||
|
|
||||||
array_buf->fill(index * sprite_size, sprite_size, v);
|
array_buf->fill(index * sprite_size, sprite_size, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ public:
|
|||||||
int addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
|
int addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void *lock();
|
void flush();
|
||||||
void unlock();
|
|
||||||
|
|
||||||
void setTexture(Texture *newtexture);
|
void setTexture(Texture *newtexture);
|
||||||
Texture *getTexture();
|
Texture *getTexture();
|
||||||
|
|||||||
@@ -118,17 +118,10 @@ int w_SpriteBatch_clear(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_SpriteBatch_bind(lua_State *L)
|
int w_SpriteBatch_flush(lua_State *L)
|
||||||
{
|
{
|
||||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||||
EXCEPT_GUARD(t->lock();)
|
t->flush();
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_SpriteBatch_unbind(lua_State *L)
|
|
||||||
{
|
|
||||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
|
||||||
t->unlock();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,8 +232,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "add", w_SpriteBatch_add },
|
{ "add", w_SpriteBatch_add },
|
||||||
{ "set", w_SpriteBatch_set },
|
{ "set", w_SpriteBatch_set },
|
||||||
{ "clear", w_SpriteBatch_clear },
|
{ "clear", w_SpriteBatch_clear },
|
||||||
{ "bind", w_SpriteBatch_bind },
|
{ "flush", w_SpriteBatch_flush },
|
||||||
{ "unbind", w_SpriteBatch_unbind },
|
|
||||||
{ "setTexture", w_SpriteBatch_setTexture },
|
{ "setTexture", w_SpriteBatch_setTexture },
|
||||||
{ "getTexture", w_SpriteBatch_getTexture },
|
{ "getTexture", w_SpriteBatch_getTexture },
|
||||||
{ "setColor", w_SpriteBatch_setColor },
|
{ "setColor", w_SpriteBatch_setColor },
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ int w_SpriteBatch_addg(lua_State *L);
|
|||||||
int w_SpriteBatch_set(lua_State *L);
|
int w_SpriteBatch_set(lua_State *L);
|
||||||
int w_SpriteBatch_setg(lua_State *L);
|
int w_SpriteBatch_setg(lua_State *L);
|
||||||
int w_SpriteBatch_clear(lua_State *L);
|
int w_SpriteBatch_clear(lua_State *L);
|
||||||
int w_SpriteBatch_bind(lua_State *L);
|
int w_SpriteBatch_flush(lua_State *L);
|
||||||
int w_SpriteBatch_unbind(lua_State *L);
|
|
||||||
int w_SpriteBatch_setTexture(lua_State *L);
|
int w_SpriteBatch_setTexture(lua_State *L);
|
||||||
int w_SpriteBatch_getTexture(lua_State *L);
|
int w_SpriteBatch_getTexture(lua_State *L);
|
||||||
int w_SpriteBatch_setColor(lua_State *L);
|
int w_SpriteBatch_setColor(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user