matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
491 stars 72 forks source link

Allocation of oglplus::Buffer without data #68

Closed nnooney closed 10 years ago

nnooney commented 10 years ago

Hi,

I want to allocate storage space in a buffer without filling it with data, so that I can later map it with oglplus::BufferRawMap and fill parts of it with data.

In the OpenGL documentation, I can do this by setting the argument data to NULL in the call to glBufferData(). Looking through the oglplus documentation, I see that the calls to oglplus::Buffer.Data() all require some data to initialize the buffer.

Is there a way to allocate a buffer without also filling it with data?

matus-chochlik commented 10 years ago

Hi, you can use for example:

oglplus::Buffer buf;
buf.Bind(Buffer::Target::Array);
Buffer::Data<GLfloat>(Buffer::Target::Array, size, nullptr);

which translates to

glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*size, NULL, GL_STATIC_DRAW);
nnooney commented 10 years ago

That works perfectly! Thank you very much.

Since I know the number of bytes I want the Buffer to be, I used: Buffer::Data<GLbyte>(Buffer::Target::Array, size, nullptr);

matus-chochlik commented 10 years ago

I've also added a new function called Resize to Buffer so you can rewrite your code in the following way:

Buffer::Resize(BufferTarget::Array, BufferSize::Of<GLbyte>(size));