|
@@ -21,6 +21,7 @@
|
|
|
#include "VertexBuffer.h"
|
|
|
|
|
|
#include "common/Exception.h"
|
|
|
+#include <common/config.h>
|
|
|
|
|
|
#include <cstdlib>
|
|
|
#include <cstring>
|
|
@@ -61,13 +62,13 @@ namespace opengl
|
|
|
}
|
|
|
|
|
|
// VertexBuffer::Bind
|
|
|
-
|
|
|
- VertexBuffer::Bind::Bind(VertexBuffer &buf)
|
|
|
- : buf(buf)
|
|
|
- {
|
|
|
- buf.bind();
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ VertexBuffer::Bind::Bind(VertexBuffer &buf)
|
|
|
+ : buf(buf)
|
|
|
+ {
|
|
|
+ buf.bind();
|
|
|
+ }
|
|
|
+
|
|
|
VertexBuffer::Bind::~Bind()
|
|
|
{
|
|
|
buf.unbind();
|
|
@@ -86,23 +87,24 @@ namespace opengl
|
|
|
delete [] buf;
|
|
|
}
|
|
|
|
|
|
- void *VertexArray::map(GLenum access)
|
|
|
- {
|
|
|
- return buf;
|
|
|
- }
|
|
|
-
|
|
|
- void VertexArray::unmap()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- void VertexArray::bind()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- void VertexArray::unbind()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
+ void *VertexArray::map(GLenum access)
|
|
|
+ {
|
|
|
+ LOVE_UNUSED(access);
|
|
|
+ return buf;
|
|
|
+ }
|
|
|
+
|
|
|
+ void VertexArray::unmap()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ void VertexArray::bind()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ void VertexArray::unbind()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
void VertexArray::fill(int offset, int size, const void *data)
|
|
|
{
|
|
|
memcpy(buf + offset, data, size);
|
|
@@ -136,33 +138,33 @@ namespace opengl
|
|
|
unload(false);
|
|
|
}
|
|
|
|
|
|
- void *VBO::map(GLenum access)
|
|
|
- {
|
|
|
- // Don't map twice.
|
|
|
- if (mapped)
|
|
|
- return mapped;
|
|
|
-
|
|
|
- mapped = glMapBufferARB(getTarget(), access);
|
|
|
-
|
|
|
- return mapped;
|
|
|
- }
|
|
|
-
|
|
|
- void VBO::unmap()
|
|
|
- {
|
|
|
- glUnmapBufferARB(getTarget());
|
|
|
- mapped = 0;
|
|
|
- }
|
|
|
-
|
|
|
- void VBO::bind()
|
|
|
- {
|
|
|
- glBindBufferARB(getTarget(), vbo);
|
|
|
- }
|
|
|
-
|
|
|
- void VBO::unbind()
|
|
|
- {
|
|
|
- glBindBufferARB(getTarget(), 0);
|
|
|
- }
|
|
|
-
|
|
|
+ void *VBO::map(GLenum access)
|
|
|
+ {
|
|
|
+ // Don't map twice.
|
|
|
+ if (mapped)
|
|
|
+ return mapped;
|
|
|
+
|
|
|
+ mapped = glMapBufferARB(getTarget(), access);
|
|
|
+
|
|
|
+ return mapped;
|
|
|
+ }
|
|
|
+
|
|
|
+ void VBO::unmap()
|
|
|
+ {
|
|
|
+ glUnmapBufferARB(getTarget());
|
|
|
+ mapped = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ void VBO::bind()
|
|
|
+ {
|
|
|
+ glBindBufferARB(getTarget(), vbo);
|
|
|
+ }
|
|
|
+
|
|
|
+ void VBO::unbind()
|
|
|
+ {
|
|
|
+ glBindBufferARB(getTarget(), 0);
|
|
|
+ }
|
|
|
+
|
|
|
void VBO::fill(int offset, int size, const void *data)
|
|
|
{
|
|
|
if (mapped)
|
|
@@ -176,35 +178,35 @@ namespace opengl
|
|
|
return reinterpret_cast<const void*>(offset);
|
|
|
}
|
|
|
|
|
|
- bool VBO::loadVolatile()
|
|
|
- {
|
|
|
- return load(true);
|
|
|
- }
|
|
|
-
|
|
|
- void VBO::unloadVolatile()
|
|
|
- {
|
|
|
- unload(true);
|
|
|
- }
|
|
|
-
|
|
|
- bool VBO::load(bool restore)
|
|
|
- {
|
|
|
- glGenBuffersARB(1, &vbo);
|
|
|
-
|
|
|
- VertexBuffer::Bind bind(*this);
|
|
|
-
|
|
|
- // Copy the old buffer only if 'restore' was requested.
|
|
|
- const GLvoid *src = restore ? buffer_copy : 0;
|
|
|
-
|
|
|
- // Note that if 'src' is '0', no data will be copied.
|
|
|
- glBufferDataARB(getTarget(), getSize(), src, getUsage());
|
|
|
-
|
|
|
+ bool VBO::loadVolatile()
|
|
|
+ {
|
|
|
+ return load(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ void VBO::unloadVolatile()
|
|
|
+ {
|
|
|
+ unload(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool VBO::load(bool restore)
|
|
|
+ {
|
|
|
+ glGenBuffersARB(1, &vbo);
|
|
|
+
|
|
|
+ VertexBuffer::Bind bind(*this);
|
|
|
+
|
|
|
+ // Copy the old buffer only if 'restore' was requested.
|
|
|
+ const GLvoid *src = restore ? buffer_copy : 0;
|
|
|
+
|
|
|
+ // Note that if 'src' is '0', no data will be copied.
|
|
|
+ glBufferDataARB(getTarget(), getSize(), src, getUsage());
|
|
|
+
|
|
|
// Clean up buffer_copy, if it exists.
|
|
|
delete[] buffer_copy;
|
|
|
- buffer_copy = 0;
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
+ buffer_copy = 0;
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
void VBO::unload(bool save)
|
|
|
{
|
|
|
// Clean up buffer_copy, if it exists.
|