throw exception if VBO is not bound when allocate is called, reset VBO offset on ID generation
This commit is contained in:
parent
b9dd2836f2
commit
ba8f4753bf
@ -65,7 +65,7 @@ GLuint GLObject::id() const
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Cannot get ID for GL object that has no ID set yet");
|
||||
throw std::runtime_error("Cannot get ID for GL object that has no ID generated yet");
|
||||
}
|
||||
}
|
||||
|
||||
|
30
src/VBO.cpp
30
src/VBO.cpp
@ -9,14 +9,40 @@
|
||||
+-------------*/
|
||||
|
||||
#include "VBO.hpp"
|
||||
|
||||
using namespace sb;
|
||||
|
||||
VBO::VBO() : Buffer(GL_ARRAY_BUFFER) {}
|
||||
|
||||
void VBO::generate()
|
||||
{
|
||||
Buffer::generate();
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
void VBO::allocate(GLsizeiptr size, GLenum usage)
|
||||
{
|
||||
/* Create data store */
|
||||
glBufferData(target(), size, nullptr, usage);
|
||||
/* Create data store, making sure the buffer currently bound matches this object's ID */
|
||||
GLint bound_id;
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &bound_id);
|
||||
if (static_cast<GLuint>(bound_id) == id())
|
||||
{
|
||||
glBufferData(target(), size, nullptr, usage);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream message;
|
||||
message << "Error allocating vertex memory for " << *this << ": ";
|
||||
if (bound_id == 0)
|
||||
{
|
||||
message << "no buffer is currently bound";
|
||||
}
|
||||
else
|
||||
{
|
||||
message << "currently bound buffer ID " << bound_id << " does not match " << *this;
|
||||
}
|
||||
throw std::runtime_error(message.str());
|
||||
}
|
||||
|
||||
/* Debug */
|
||||
std::ostringstream message;
|
||||
|
@ -54,6 +54,12 @@ namespace sb
|
||||
*/
|
||||
VBO();
|
||||
|
||||
/*!
|
||||
* Generate an ID for VBO using the base class's generate function. Reset the offset to 0 because any data previously stored will be
|
||||
* automatically freed once a new ID is generated.
|
||||
*/
|
||||
void generate();
|
||||
|
||||
/*!
|
||||
* Allocate size bytes of unintialized vertex buffer memory on the GPU.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user