Merge default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-08-13 12:41:14 -03:00
23 changed files with 526 additions and 32 deletions
+6 -5
View File
@@ -58,12 +58,10 @@ GLBuffer::GLBuffer(size_t size, const void *data, GLenum target, GLenum usage, u
if (data != nullptr)
memcpy(memory_map, data, size);
bool ok = load(data != nullptr);
if (!ok)
if (!load(data != nullptr))
{
delete[] memory_map;
throw love::Exception("Could not load VBO.");
throw love::Exception("Could not load vertex buffer (out of VRAM?)");
}
}
@@ -221,13 +219,16 @@ bool GLBuffer::load(bool restore)
GLBuffer::Bind bind(*this);
while (glGetError() != GL_NO_ERROR)
/* Clear the error buffer. */;
// Copy the old buffer only if 'restore' was requested.
const GLvoid *src = restore ? memory_map : nullptr;
// Note that if 'src' is '0', no data will be copied.
glBufferData(getTarget(), (GLsizeiptr) getSize(), src, getUsage());
return true;
return (glGetError() == GL_NO_ERROR);
}
void GLBuffer::unload()
+8 -4
View File
@@ -166,14 +166,18 @@ void SpriteBatch::setBufferSize(int newsize)
size_t vertex_size = sizeof(Vertex) * 4 * newsize;
GLBuffer *new_array_buf = nullptr;
int new_next = std::min(next, newsize);
try
{
new_array_buf = new GLBuffer(vertex_size, nullptr, array_buf->getTarget(), array_buf->getUsage(), array_buf->getMapFlags());
// Copy as much of the old data into the new GLBuffer as can fit.
GLBuffer::Bind bind(*new_array_buf);
void *new_data = new_array_buf->map();
memcpy(new_data, old_data, sizeof(Vertex) * 4 * std::min(newsize, size));
// Copy as much of the old data into the new GLBuffer as can fit.
size_t copy_size = sizeof(Vertex) * 4 * new_next;
memcpy(new_array_buf->map(), old_data, copy_size);
new_array_buf->setMappedRangeModified(0, copy_size);
quad_indices = QuadIndices(newsize);
}
@@ -189,7 +193,7 @@ void SpriteBatch::setBufferSize(int newsize)
array_buf = new_array_buf;
size = newsize;
next = std::min(next, newsize);
next = new_next;
}
int SpriteBatch::getBufferSize() const