diff --git a/src/Magnum/AbstractFramebuffer.cpp b/src/Magnum/AbstractFramebuffer.cpp index f205c4f2d..2bf1f5b97 100644 --- a/src/Magnum/AbstractFramebuffer.cpp +++ b/src/Magnum/AbstractFramebuffer.cpp @@ -222,7 +222,7 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Buf if(image.size() != size) image.setData(image.format(), image.type(), size, nullptr, usage); - image.buffer().bind(Buffer::Target::PixelPack); + image.buffer().bindInternal(Buffer::Target::PixelPack); (Context::current()->state().framebuffer->readImplementation)(offset, size, image.format(), image.type(), image.dataSize(size), nullptr); } #endif diff --git a/src/Magnum/AbstractTexture.cpp b/src/Magnum/AbstractTexture.cpp index fa22cba23..9d78a49ff 100644 --- a/src/Magnum/AbstractTexture.cpp +++ b/src/Magnum/AbstractTexture.cpp @@ -1156,7 +1156,7 @@ template void AbstractTexture::image(GLenum target, GLin if(image.size() != size) image.setData(image.format(), image.type(), size, nullptr, usage); - image.buffer().bind(Buffer::Target::PixelPack); + image.buffer().bindInternal(Buffer::Target::PixelPack); (this->*Context::current()->state().texture->getImageImplementation)(target, level, image.format(), image.type(), dataSize, nullptr); } @@ -1224,78 +1224,78 @@ void AbstractTexture::DataHelper<3>::setStorageMultisample(AbstractTexture& text #ifndef MAGNUM_TARGET_GLES void AbstractTexture::DataHelper<1>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, const ImageReference1D& image) { - Buffer::unbind(Buffer::Target::PixelUnpack); + Buffer::unbindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->image1DImplementation)(target, level, internalFormat, image.size(), image.format(), image.type(), image.data()); } void AbstractTexture::DataHelper<1>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, BufferImage1D& image) { - image.buffer().bind(Buffer::Target::PixelUnpack); + image.buffer().bindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->image1DImplementation)(target, level, internalFormat, image.size(), image.format(), image.type(), nullptr); } void AbstractTexture::DataHelper<1>::setSubImage(AbstractTexture& texture, const GLenum target, const GLint level, const Math::Vector<1, GLint>& offset, const ImageReference1D& image) { - Buffer::unbind(Buffer::Target::PixelUnpack); + Buffer::unbindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->subImage1DImplementation)(target, level, offset, image.size(), image.format(), image.type(), image.data()); } void AbstractTexture::DataHelper<1>::setSubImage(AbstractTexture& texture, const GLenum target, const GLint level, const Math::Vector<1, GLint>& offset, BufferImage1D& image) { - image.buffer().bind(Buffer::Target::PixelUnpack); + image.buffer().bindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->subImage1DImplementation)(target, level, offset, image.size(), image.format(), image.type(), nullptr); } #endif void AbstractTexture::DataHelper<2>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, const ImageReference2D& image) { #ifndef MAGNUM_TARGET_GLES2 - Buffer::unbind(Buffer::Target::PixelUnpack); + Buffer::unbindInternal(Buffer::Target::PixelUnpack); #endif (texture.*Context::current()->state().texture->image2DImplementation)(target, level, internalFormat, image.size(), image.format(), image.type(), image.data()); } #ifndef MAGNUM_TARGET_GLES2 void AbstractTexture::DataHelper<2>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, BufferImage2D& image) { - image.buffer().bind(Buffer::Target::PixelUnpack); + image.buffer().bindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->image2DImplementation)(target, level, internalFormat, image.size(), image.format(), image.type(), nullptr); } #endif void AbstractTexture::DataHelper<2>::setSubImage(AbstractTexture& texture, const GLenum target, const GLint level, const Vector2i& offset, const ImageReference2D& image) { #ifndef MAGNUM_TARGET_GLES2 - Buffer::unbind(Buffer::Target::PixelUnpack); + Buffer::unbindInternal(Buffer::Target::PixelUnpack); #endif (texture.*Context::current()->state().texture->subImage2DImplementation)(target, level, offset, image.size(), image.format(), image.type(), image.data()); } #ifndef MAGNUM_TARGET_GLES2 void AbstractTexture::DataHelper<2>::setSubImage(AbstractTexture& texture, const GLenum target, const GLint level, const Vector2i& offset, BufferImage2D& image) { - image.buffer().bind(Buffer::Target::PixelUnpack); + image.buffer().bindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->subImage2DImplementation)(target, level, offset, image.size(), image.format(), image.type(), nullptr); } #endif void AbstractTexture::DataHelper<3>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, const ImageReference3D& image) { #ifndef MAGNUM_TARGET_GLES2 - Buffer::unbind(Buffer::Target::PixelUnpack); + Buffer::unbindInternal(Buffer::Target::PixelUnpack); #endif (texture.*Context::current()->state().texture->image3DImplementation)(target, level, internalFormat, image.size(), image.format(), image.type(), image.data()); } #ifndef MAGNUM_TARGET_GLES2 void AbstractTexture::DataHelper<3>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, BufferImage3D& image) { - image.buffer().bind(Buffer::Target::PixelUnpack); + image.buffer().bindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->image3DImplementation)(target, level, internalFormat, image.size(), image.format(), image.type(), nullptr); } #endif void AbstractTexture::DataHelper<3>::setSubImage(AbstractTexture& texture, const GLenum target, const GLint level, const Vector3i& offset, const ImageReference3D& image) { #ifndef MAGNUM_TARGET_GLES2 - Buffer::unbind(Buffer::Target::PixelUnpack); + Buffer::unbindInternal(Buffer::Target::PixelUnpack); #endif (texture.*Context::current()->state().texture->subImage3DImplementation)(target, level, offset, image.size(), image.format(), image.type(), image.data()); } #ifndef MAGNUM_TARGET_GLES2 void AbstractTexture::DataHelper<3>::setSubImage(AbstractTexture& texture, const GLenum target, const GLint level, const Vector3i& offset, BufferImage3D& image) { - image.buffer().bind(Buffer::Target::PixelUnpack); + image.buffer().bindInternal(Buffer::Target::PixelUnpack); (texture.*Context::current()->state().texture->subImage3DImplementation)(target, level, offset, image.size(), image.format(), image.type(), nullptr); } #endif diff --git a/src/Magnum/Buffer.cpp b/src/Magnum/Buffer.cpp index e6c704ba5..83bc6fa4f 100644 --- a/src/Magnum/Buffer.cpp +++ b/src/Magnum/Buffer.cpp @@ -161,7 +161,7 @@ Buffer& Buffer::setLabelInternal(const Containers::ArrayReference la return *this; } -void Buffer::bind(Target target, GLuint id) { +void Buffer::bindInternal(Target target, GLuint id) { GLuint& bound = Context::current()->state().buffer->bindings[Implementation::BufferState::indexForTarget(target)]; /* Already bound, nothing to do */ @@ -172,7 +172,7 @@ void Buffer::bind(Target target, GLuint id) { glBindBuffer(GLenum(target), id); } -Buffer::Target Buffer::bindInternal(Target hint) { +Buffer::Target Buffer::bindSomewhereInternal(Target hint) { GLuint* bindings = Context::current()->state().buffer->bindings; GLuint& hintBinding = bindings[Implementation::BufferState::indexForTarget(hint)]; @@ -269,7 +269,7 @@ void Buffer::subDataInternal(GLintptr offset, GLsizeiptr size, GLvoid* data) { #ifndef MAGNUM_TARGET_GLES2 void Buffer::copyImplementationDefault(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { - glCopyBufferSubData(GLenum(read.bindInternal(Target::CopyRead)), GLenum(write.bindInternal(Target::CopyWrite)), readOffset, writeOffset, size); + glCopyBufferSubData(GLenum(read.bindSomewhereInternal(Target::CopyRead)), GLenum(write.bindSomewhereInternal(Target::CopyWrite)), readOffset, writeOffset, size); } #ifndef MAGNUM_TARGET_GLES @@ -280,7 +280,7 @@ void Buffer::copyImplementationDSA(Buffer& read, Buffer& write, GLintptr readOff #endif void Buffer::getParameterImplementationDefault(const GLenum value, GLint* const data) { - glGetBufferParameteriv(GLenum(bindInternal(_targetHint)), value, data); + glGetBufferParameteriv(GLenum(bindSomewhereInternal(_targetHint)), value, data); } #ifndef MAGNUM_TARGET_GLES @@ -291,7 +291,7 @@ void Buffer::getParameterImplementationDSA(const GLenum value, GLint* const data #ifndef MAGNUM_TARGET_GLES void Buffer::getSubDataImplementationDefault(const GLintptr offset, const GLsizeiptr size, GLvoid* const data) { - glGetBufferSubData(GLenum(bindInternal(_targetHint)), offset, size, data); + glGetBufferSubData(GLenum(bindSomewhereInternal(_targetHint)), offset, size, data); } void Buffer::getSubDataImplementationDSA(const GLintptr offset, const GLsizeiptr size, GLvoid* const data) { @@ -300,7 +300,7 @@ void Buffer::getSubDataImplementationDSA(const GLintptr offset, const GLsizeiptr #endif void Buffer::dataImplementationDefault(GLsizeiptr size, const GLvoid* data, BufferUsage usage) { - glBufferData(GLenum(bindInternal(_targetHint)), size, data, GLenum(usage)); + glBufferData(GLenum(bindSomewhereInternal(_targetHint)), size, data, GLenum(usage)); } #ifndef MAGNUM_TARGET_GLES @@ -310,7 +310,7 @@ void Buffer::dataImplementationDSA(GLsizeiptr size, const GLvoid* data, BufferUs #endif void Buffer::subDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { - glBufferSubData(GLenum(bindInternal(_targetHint)), offset, size, data); + glBufferSubData(GLenum(bindSomewhereInternal(_targetHint)), offset, size, data); } #ifndef MAGNUM_TARGET_GLES @@ -337,7 +337,7 @@ void Buffer::invalidateSubImplementationARB(GLintptr offset, GLsizeiptr length) void* Buffer::mapImplementationDefault(MapAccess access) { #ifndef MAGNUM_TARGET_GLES - return glMapBuffer(GLenum(bindInternal(_targetHint)), GLenum(access)); + return glMapBuffer(GLenum(bindSomewhereInternal(_targetHint)), GLenum(access)); #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) return glMapBufferOES(GLenum(bindInternal(_targetHint)), GLenum(access)); #else @@ -354,7 +354,7 @@ void* Buffer::mapImplementationDSA(MapAccess access) { void* Buffer::mapRangeImplementationDefault(GLintptr offset, GLsizeiptr length, MapFlags access) { #ifndef MAGNUM_TARGET_GLES2 - return glMapBufferRange(GLenum(bindInternal(_targetHint)), offset, length, GLenum(access)); + return glMapBufferRange(GLenum(bindSomewhereInternal(_targetHint)), offset, length, GLenum(access)); #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) return glMapBufferRangeEXT(GLenum(bindInternal(_targetHint)), offset, length, GLenum(access)); #else @@ -373,7 +373,7 @@ void* Buffer::mapRangeImplementationDSA(GLintptr offset, GLsizeiptr length, MapF void Buffer::flushMappedRangeImplementationDefault(GLintptr offset, GLsizeiptr length) { #ifndef MAGNUM_TARGET_GLES2 - glFlushMappedBufferRange(GLenum(bindInternal(_targetHint)), offset, length); + glFlushMappedBufferRange(GLenum(bindSomewhereInternal(_targetHint)), offset, length); #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) glFlushMappedBufferRangeEXT(GLenum(bindInternal(_targetHint)), offset, length); #else @@ -391,7 +391,7 @@ void Buffer::flushMappedRangeImplementationDSA(GLintptr offset, GLsizeiptr lengt bool Buffer::unmapImplementationDefault() { #ifndef MAGNUM_TARGET_GLES2 - return glUnmapBuffer(GLenum(bindInternal(_targetHint))); + return glUnmapBuffer(GLenum(bindSomewhereInternal(_targetHint))); #elif !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_NACL) return glUnmapBufferOES(GLenum(bindInternal(_targetHint))); #else diff --git a/src/Magnum/Buffer.h b/src/Magnum/Buffer.h index 8f867aae8..31dc9ecec 100644 --- a/src/Magnum/Buffer.h +++ b/src/Magnum/Buffer.h @@ -504,14 +504,6 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { static Int maxUniformBindings(); #endif - /** - * @brief Unbind any buffer from given target - * @param target %Target - * - * @see @fn_gl{BindBuffer} - */ - static void unbind(Target target) { bind(target, 0); } - #ifndef MAGNUM_TARGET_GLES2 /** * @brief Copy one buffer to another @@ -622,18 +614,6 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { return *this; } - /** - * @brief Bind buffer - * @param target %Target - * - * @see @fn_gl{BindBuffer} - * @todo Allow binding to Target::ElementArray only if VAO is bound - * to avoid potential issues? - * @todo Don't allow user to bind buffers? - * @bug Binding to ElementArray if any VAO is active will corrupt the mesh - */ - void bind(Target target) { bind(target, _id); } - /** * @brief %Buffer size * @@ -868,11 +848,18 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { void unmapSub(); #endif + #ifdef DOXYGEN_GENERATING_OUTPUT + private: + #endif + /* There should be no need to use these from user code */ + static void unbindInternal(Target target) { bindInternal(target, 0); } + void bindInternal(Target target) { bindInternal(target, _id); } + private: Buffer& setLabelInternal(Containers::ArrayReference label); - static void bind(Target hint, GLuint id); - Target MAGNUM_LOCAL bindInternal(Target hint); + static void bindInternal(Target hint, GLuint id); + Target MAGNUM_LOCAL bindSomewhereInternal(Target hint); #ifndef MAGNUM_TARGET_GLES2 static void MAGNUM_LOCAL copyImplementationDefault(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); diff --git a/src/Magnum/Mesh.cpp b/src/Magnum/Mesh.cpp index 5028a0e45..b7b654da7 100644 --- a/src/Magnum/Mesh.cpp +++ b/src/Magnum/Mesh.cpp @@ -355,7 +355,7 @@ void Mesh::attributePointerImplementationDSA(const Attribute& attribute) { void Mesh::vertexAttribPointer(const Attribute& attribute) { glEnableVertexAttribArray(attribute.location); - attribute.buffer->bind(Buffer::Target::Array); + attribute.buffer->bindInternal(Buffer::Target::Array); glVertexAttribPointer(attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, reinterpret_cast(attribute.offset)); if(attribute.divisor) { #ifndef MAGNUM_TARGET_GLES2 @@ -390,7 +390,7 @@ void Mesh::attributePointerImplementationDSA(const IntegerAttribute& attribute) void Mesh::vertexAttribPointer(const IntegerAttribute& attribute) { glEnableVertexAttribArray(attribute.location); - attribute.buffer->bind(Buffer::Target::Array); + attribute.buffer->bindInternal(Buffer::Target::Array); glVertexAttribIPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast(attribute.offset)); if(attribute.divisor) glVertexAttribDivisor(attribute.location, attribute.divisor); } @@ -418,7 +418,7 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { void Mesh::vertexAttribPointer(const LongAttribute& attribute) { glEnableVertexAttribArray(attribute.location); - attribute.buffer->bind(Buffer::Target::Array); + attribute.buffer->bindInternal(Buffer::Target::Array); glVertexAttribLPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast(attribute.offset)); if(attribute.divisor) glVertexAttribDivisor(attribute.location, attribute.divisor); } @@ -465,7 +465,7 @@ void Mesh::bindIndexBufferImplementationVAO(Buffer& buffer) { /** @todo Do this cleaner way */ Context::current()->state().buffer->bindings[Implementation::BufferState::indexForTarget(Buffer::Target::ElementArray)] = 0; - buffer.bind(Buffer::Target::ElementArray); + buffer.bindInternal(Buffer::Target::ElementArray); } void Mesh::bindImplementationDefault() { @@ -484,7 +484,7 @@ void Mesh::bindImplementationDefault() { #endif /* Bind index buffer, if the mesh is indexed */ - if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); + if(_indexBuffer) _indexBuffer->bindInternal(Buffer::Target::ElementArray); } void Mesh::bindImplementationVAO() {