|
|
@@ -5,10 +5,6 @@
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
-//==============================================================================
|
|
|
-
|
|
|
-const thread_local BufferObject* BufferObject::lastBindedBo = nullptr;
|
|
|
-
|
|
|
//==============================================================================
|
|
|
BufferObject::~BufferObject()
|
|
|
{
|
|
|
@@ -35,14 +31,14 @@ void BufferObject::create(GLenum target_, U32 sizeInBytes_,
|
|
|
sizeInBytes = sizeInBytes_;
|
|
|
|
|
|
glGenBuffers(1, &glId);
|
|
|
- // XXX Check if zero
|
|
|
+ ANKI_ASSERT(glId != 0);
|
|
|
bind();
|
|
|
glBufferData(target, sizeInBytes, dataPtr, usage);
|
|
|
|
|
|
// make a check
|
|
|
- int bufferSize = 0;
|
|
|
+ GLint bufferSize = 0;
|
|
|
glGetBufferParameteriv(target, GL_BUFFER_SIZE, &bufferSize);
|
|
|
- if(sizeInBytes != (uint)bufferSize)
|
|
|
+ if(sizeInBytes != (U32)bufferSize)
|
|
|
{
|
|
|
destroy();
|
|
|
throw ANKI_EXCEPTION("Data size mismatch");
|
|
|
@@ -55,6 +51,7 @@ void BufferObject::create(GLenum target_, U32 sizeInBytes_,
|
|
|
//==============================================================================
|
|
|
void* BufferObject::map(U32 offset, U32 length, GLuint flags)
|
|
|
{
|
|
|
+ ANKI_ASSERT(isCreated());
|
|
|
ANKI_ASSERT(mapped == false);
|
|
|
bind();
|
|
|
ANKI_ASSERT(offset + length <= sizeInBytes);
|
|
|
@@ -69,6 +66,7 @@ void* BufferObject::map(U32 offset, U32 length, GLuint flags)
|
|
|
//==============================================================================
|
|
|
void BufferObject::unmap()
|
|
|
{
|
|
|
+ ANKI_ASSERT(isCreated());
|
|
|
ANKI_ASSERT(mapped == true);
|
|
|
bind();
|
|
|
glUnmapBuffer(target);
|
|
|
@@ -77,21 +75,6 @@ void BufferObject::unmap()
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-//==============================================================================
|
|
|
-void BufferObject::write(void* buff)
|
|
|
-{
|
|
|
- ANKI_ASSERT(isCreated());
|
|
|
- ANKI_ASSERT(usage != GL_STATIC_DRAW);
|
|
|
- bind();
|
|
|
-#if 0
|
|
|
- void* mapped = glMapBuffer(target, GL_WRITE_ONLY);
|
|
|
- memcpy(mapped, buff, sizeInBytes);
|
|
|
- glUnmapBuffer(target);
|
|
|
-#else
|
|
|
- glBufferData(target, sizeInBytes, buff, usage);
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
//==============================================================================
|
|
|
void BufferObject::write(void* buff, U32 offset, U32 size)
|
|
|
{
|
|
|
@@ -99,12 +82,12 @@ void BufferObject::write(void* buff, U32 offset, U32 size)
|
|
|
ANKI_ASSERT(usage != GL_STATIC_DRAW);
|
|
|
ANKI_ASSERT(offset + size <= sizeInBytes);
|
|
|
bind();
|
|
|
- void* mapped = glMapBufferRange(target, offset, size,
|
|
|
- GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT/*
|
|
|
- | GL_MAP_FLUSH_EXPLICIT_BIT*/);
|
|
|
- ANKI_ASSERT(mapped != nullptr);
|
|
|
+
|
|
|
+ void* mapped = map(offset, size,
|
|
|
+ GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT);
|
|
|
+
|
|
|
memcpy(mapped, buff, size);
|
|
|
- glUnmapBuffer(target);
|
|
|
+ unmap();
|
|
|
}
|
|
|
|
|
|
} // end namespace anki
|