From 7b43ab5fc24c345170b78a264931ecca612ebe8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 28 Aug 2019 11:10:36 +0200 Subject: [PATCH] GL: create the buffer passed to setBuffer() if it's not already. --- doc/changelog.dox | 5 +++++ src/Magnum/GL/Buffer.cpp | 2 +- src/Magnum/GL/Buffer.h | 7 +++++-- src/Magnum/GL/BufferTexture.cpp | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 964a559a8..bbc53c673 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -579,6 +579,11 @@ See also: @fn_gl{GetString} returning a @cpp nullptr @ce - @ref GL::Texture::imageSize() was present on WebGL 2 by mistake (see [mosra/magnum#365](https://github.com/mosra/magnum/pull/365)) +- @ref GL::BufferTexture::setBuffer() now creates the passed buffer if not + already (and if it was not created by @fn_gl{CreateBuffers}). Before that, + passing a freshly created @ref GL::Buffer to it was causing + @ref GL::Renderer::Error::InvalidOperation on systems without + @gl_extension{ARB,direct_state_access}. @subsection changelog-latest-docs Documentation diff --git a/src/Magnum/GL/Buffer.cpp b/src/Magnum/GL/Buffer.cpp index 19c72fd5c..b0310410c 100644 --- a/src/Magnum/GL/Buffer.cpp +++ b/src/Magnum/GL/Buffer.cpp @@ -210,7 +210,7 @@ void Buffer::setTargetHintImplementationSwiftShader(const TargetHint hint) { } #endif -inline void Buffer::createIfNotAlready() { +void Buffer::createIfNotAlready() { if(_flags & ObjectFlag::Created) return; /* glGen*() does not create the object, just reserves the name. Some diff --git a/src/Magnum/GL/Buffer.h b/src/Magnum/GL/Buffer.h index a543baaf8..2c9ae547b 100644 --- a/src/Magnum/GL/Buffer.h +++ b/src/Magnum/GL/Buffer.h @@ -221,8 +221,6 @@ by OpenGL in order to preserve the data. If running on OpenGL ES or extension functions do nothing. */ class MAGNUM_GL_EXPORT Buffer: public AbstractObject { - friend Implementation::BufferState; - public: /** * @brief Buffer target @@ -1155,6 +1153,11 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject { void bindInternal(TargetHint target) { bindInternal(target, this); } private: + friend Implementation::BufferState; + #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + friend BufferTexture; /* calls createIfNotAlready() */ + #endif + static void bindInternal(TargetHint hint, Buffer* buffer); TargetHint MAGNUM_GL_LOCAL bindSomewhereInternal(TargetHint hint); diff --git a/src/Magnum/GL/BufferTexture.cpp b/src/Magnum/GL/BufferTexture.cpp index c33af0b76..b38a0c262 100644 --- a/src/Magnum/GL/BufferTexture.cpp +++ b/src/Magnum/GL/BufferTexture.cpp @@ -79,11 +79,13 @@ Int BufferTexture::size() { } BufferTexture& BufferTexture::setBuffer(const BufferTextureFormat internalFormat, Buffer& buffer) { + buffer.createIfNotAlready(); (this->*Context::current().state().texture->setBufferImplementation)(internalFormat, buffer); return *this; } BufferTexture& BufferTexture::setBuffer(const BufferTextureFormat internalFormat, Buffer& buffer, const GLintptr offset, const GLsizeiptr size) { + buffer.createIfNotAlready(); (this->*Context::current().state().texture->setBufferRangeImplementation)(internalFormat, buffer, offset, size); return *this; }