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

Unbinding oglplus::Buffer #77

Closed nnooney closed 10 years ago

nnooney commented 10 years ago

Hi,

When I try to unbind a buffer in multiple ways I get the following errors:

Method 1:

Buffer vbo;
vbo.Bind(BufferTarget::Array);
// Use the buffer here
vbo.Unbind();
error: ‘oglplus::Buffer’ has no member named ‘Unbind’

Method 2:

Buffer::Unbind(BufferTarget::Array);
error: ‘Unbind’ is not a member of ‘oglplus::Buffer {aka oglplus::Object<oglplus::ObjectOps<oglplus::tag::ExplicitSel, oglplus::tag::Buffer> >}’

Method 3:

NoBuffer::Bind(BufferTarget::Array);
error: cannot call member function ‘void oglplus::ObjCommonOps<oglplus::tag::Buffer>::Bind(oglplus::ObjBindingOps<oglplus::tag::Buffer>::Target) const’ without object

The following method works:

NoBuffer noBuf;
noBuf.Bind(BufferTarget::Array);

Why must I keep track of a NoBuffer object to be able to unbind the buffers? Is there another way to unbind buffers?

matus-chochlik commented 10 years ago

Actually you can also do the following:

NoBuffer().Bind(BufferTarget::Array)

Previously the 'binding object zero' (i.e. unbinding or binding default object) wrappers were quite inconsistent both with the GL and among themselves. Now all objects that can be 'bound' to a binding point (including the special objects with GL name zero - representing a 'no-object' or the 'default-object') have a function called Bind, that is used to bind the specified object to the specified target.

matus-chochlik commented 10 years ago

B.T.W. if you are worried about the performance then this:

NoBuffer().Bind(BufferTarget::Array);

basically translates to the following:

GLuint __name = 0;
glBindBuffer(GL_ARRAY_BUFFER, __name);

which any compiler with a decent optimizer can transform to:

glBindBuffer(GL_ARRAY_BUFFER, 0);

so there should not be any overhead.

nnooney commented 10 years ago

That is a much more consistent way to handle things. And it won't require keeping track of a NoBuffer.