Browse Source

GL: remove Buffer::set[Sub]Data() taking std::array / std::vector.

Instead make use of the ArrayView STL compatibility. To avoid breaking
almost all existing code the Corrade/Containers/ArrayViewStl.h header is
included implicitly when MAGNUM_BUILD_DEPRECATED is defined, but this
will get removed in some future release to speed up the compilation.
pull/332/head
Vladimír Vondruš 7 years ago
parent
commit
b77651cf93
  1. 9
      doc/changelog.dox
  2. 1
      doc/snippets/MagnumGL.cpp
  3. 1
      doc/snippets/MagnumShaders.cpp
  4. 33
      src/Magnum/GL/Buffer.h
  5. 2
      src/Magnum/GL/Implementation/BufferState.h
  6. 40
      src/Magnum/GL/Test/BufferGLTest.cpp
  7. 12
      src/Magnum/GL/Test/MeshGLTest.cpp
  8. 1
      src/Magnum/Text/Renderer.cpp

9
doc/changelog.dox

@ -106,6 +106,9 @@ See also:
- Detection of SwiftShader and ARM Mali drivers with - Detection of SwiftShader and ARM Mali drivers with
@ref GL::Context::DetectedDriver::SwiftShader and @ref GL::Context::DetectedDriver::SwiftShader and
@ref GL::Context::DetectedDriver::ArmMali @ref GL::Context::DetectedDriver::ArmMali
- It's now possible to pass @ref std::initializer_list to
@ref GL::Buffer::setData() / @ref GL::Buffer::setSubData() for a succint
upload of basic types
@subsubsection changelog-latest-new-math Math library @subsubsection changelog-latest-new-math Math library
@ -329,6 +332,12 @@ See also:
deprecated in favor of deprecated in favor of
@ref Text::AbstractFont::openData(Containers::ArrayView<const char>, Float) @ref Text::AbstractFont::openData(Containers::ArrayView<const char>, Float)
and @ref Text::AbstractFont::setFileCallback() and @ref Text::AbstractFont::setFileCallback()
- @ref GL::Buffer::setData() and @ref GL::Buffer::setSubData() no longer has
overloads taking @ref std::vector / @ref std::array, but instead relies on
@ref Corrade/Containers/ArrayViewStl.h to provide conversion from these to
@ref Corrade::Containers::ArrayView. This header is included automatically
when @ref MAGNUM_BUILD_DEPRECATED is enabled, include it explicitly to stay
forward compatible.
@subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs

1
doc/snippets/MagnumGL.cpp

@ -23,6 +23,7 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/Reference.h> #include <Corrade/Containers/Reference.h>
#include "Magnum/Image.h" #include "Magnum/Image.h"

1
doc/snippets/MagnumShaders.cpp

@ -25,6 +25,7 @@
#include <numeric> #include <numeric>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include "Magnum/GL/Buffer.h" #include "Magnum/GL/Buffer.h"
#include "Magnum/GL/DefaultFramebuffer.h" #include "Magnum/GL/DefaultFramebuffer.h"

33
src/Magnum/GL/Buffer.h

@ -30,8 +30,6 @@
*/ */
#include <cstddef> #include <cstddef>
#include <array>
#include <vector>
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/EnumSet.h> #include <Corrade/Containers/EnumSet.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
@ -41,6 +39,11 @@
#include "Magnum/GL/AbstractObject.h" #include "Magnum/GL/AbstractObject.h"
#include "Magnum/GL/GL.h" #include "Magnum/GL/GL.h"
#ifdef MAGNUM_BUILD_DEPRECATED
/** @todo remove once people get used to including this where needed */
#include <Corrade/Containers/ArrayViewStl.h>
#endif
namespace Magnum { namespace GL { namespace Magnum { namespace GL {
/** /**
@ -148,8 +151,8 @@ more information about automatic conversions etc.
@snippet MagnumGL.cpp Buffer-setdata @snippet MagnumGL.cpp Buffer-setdata
There is also overload for array-like containers from STL, such as If you @cpp #include @ce @ref Corrade/Containers/ArrayViewStl.h, you can also
@ref std::vector or @link std::array @endlink: pass directly STL types such as @ref std::vector or @link std::array @endlink:
@snippet MagnumGL.cpp Buffer-setdata-stl @snippet MagnumGL.cpp Buffer-setdata-stl
@ -991,15 +994,8 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
Buffer& setData(Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw); Buffer& setData(Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw);
/** @overload */ /** @overload */
template<class T> Buffer& setData(const std::vector<T>& data, BufferUsage usage = BufferUsage::StaticDraw) { template<class T> Buffer& setData(std::initializer_list<T> data, BufferUsage usage = BufferUsage::StaticDraw) {
setData({data.data(), data.size()}, usage); return setData({data.begin(), data.size()}, usage);
return *this;
}
/** @overload */
template<std::size_t size, class T> Buffer& setData(const std::array<T, size>& data, BufferUsage usage = BufferUsage::StaticDraw) {
setData({data.data(), data.size()}, usage);
return *this;
} }
/** /**
@ -1017,15 +1013,8 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
Buffer& setSubData(GLintptr offset, Containers::ArrayView<const void> data); Buffer& setSubData(GLintptr offset, Containers::ArrayView<const void> data);
/** @overload */ /** @overload */
template<class T> Buffer& setSubData(GLintptr offset, const std::vector<T>& data) { template<class T> Buffer& setSubData(GLintptr offset, std::initializer_list<T> data) {
setSubData(offset, {data.data(), data.size()}); return setSubData(offset, {data.begin(), data.size()});
return *this;
}
/** @overload */
template<std::size_t size, class T> Buffer& setSubData(GLintptr offset, const std::array<T, size>& data) {
setSubData(offset, {data.data(), data.size()});
return *this;
} }
/** /**

2
src/Magnum/GL/Implementation/BufferState.h

@ -25,6 +25,8 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <vector>
#include "Magnum/GL/Buffer.h" #include "Magnum/GL/Buffer.h"
namespace Magnum { namespace GL { namespace Implementation { namespace Magnum { namespace GL { namespace Implementation {

40
src/Magnum/GL/Test/BufferGLTest.cpp

@ -214,54 +214,54 @@ void BufferGLTest::data() {
/* Plain array */ /* Plain array */
constexpr Int data[] = {2, 7, 5, 13, 25}; constexpr Int data[] = {2, 7, 5, 13, 25};
buffer.setData({data, 5}, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4); CORRADE_COMPARE(buffer.size(), 5*4);
/* STL vector */ /** @todo How to verify the contents in ES? */
std::vector<Int> data2{2, 7, 5, 13, 25}; #ifndef MAGNUM_TARGET_GLES
buffer.setData(data2, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4); CORRADE_COMPARE_AS(Containers::arrayCast<Int>(buffer.data()),
Containers::arrayView(data),
TestSuite::Compare::Container);
#endif
/* STL array */ /* STL initializer list */
std::array<Int, 5> data3{{2, 7, 5, 13, 25}}; buffer.setData({2, 7, 5, 13, 25}, BufferUsage::StaticDraw);
buffer.setData(data3, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4); CORRADE_COMPARE(buffer.size(), 5*4);
/** @todo How to verify the contents in ES? */ /** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
auto contents = buffer.data();
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE_AS(Containers::arrayCast<Int>(contents), CORRADE_COMPARE_AS(Containers::arrayCast<Int>(buffer.data()),
Containers::arrayView(data), Containers::arrayView(data),
TestSuite::Compare::Container); TestSuite::Compare::Container);
#endif #endif
/* Plain array */ /* Plain array */
constexpr Int subData[] = {125, 3, 15}; constexpr Int subData[] = {125, 3, 15};
buffer.setSubData(4, {subData, 3}); buffer.setSubData(4, subData);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4); CORRADE_COMPARE(buffer.size(), 5*4);
/* STL vector */ /** @todo How to verify the contents in ES? */
std::vector<Int> subData2{125, 3, 15}; #ifndef MAGNUM_TARGET_GLES
buffer.setSubData(4, subData2);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4); CORRADE_COMPARE_AS(Containers::arrayCast<Int>(buffer.subData(4, 3*4)),
Containers::arrayView(subData),
TestSuite::Compare::Container);
#endif
/* STL array */ /* STL initializer list */
std::array<Int, 3> subData3{{125, 3, 15}}; buffer.setSubData(4, {125, 3, 15});
buffer.setSubData(4, subData3);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4); CORRADE_COMPARE(buffer.size(), 5*4);
/** @todo How to verify the contents in ES? */ /** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
auto subContents = buffer.subData(4, 3*4);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE_AS(Containers::arrayCast<Int>(subContents), CORRADE_COMPARE_AS(Containers::arrayCast<Int>(buffer.subData(4, 3*4)),
Containers::arrayView(subData), Containers::arrayView(subData),
TestSuite::Compare::Container); TestSuite::Compare::Container);
#endif #endif

12
src/Magnum/GL/Test/MeshGLTest.cpp

@ -2236,7 +2236,7 @@ void MeshGLTest::unbindVAOWhenSettingIndexBufferData() {
buffer.setData(data, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
Buffer indices{Buffer::TargetHint::ElementArray}; Buffer indices{Buffer::TargetHint::ElementArray};
indices.setData(std::vector<UnsignedByte>{5, 0}, BufferUsage::StaticDraw); indices.setData(std::initializer_list<UnsignedByte>{5, 0}, BufferUsage::StaticDraw);
Mesh mesh; Mesh mesh;
mesh.addVertexBuffer(buffer, 4, Attribute{}) mesh.addVertexBuffer(buffer, 4, Attribute{})
@ -2244,7 +2244,7 @@ void MeshGLTest::unbindVAOWhenSettingIndexBufferData() {
/* This buffer should have no effect on the mesh above */ /* This buffer should have no effect on the mesh above */
Buffer otherIndices{Buffer::TargetHint::ElementArray}; Buffer otherIndices{Buffer::TargetHint::ElementArray};
otherIndices.setData(std::vector<UnsignedByte>{100, 1}, BufferUsage::StaticDraw); otherIndices.setData(std::initializer_list<UnsignedByte>{100, 1}, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -2304,7 +2304,7 @@ void MeshGLTest::unbindIndexBufferWhenBindingVao() {
nonindexed.addVertexBuffer(vertices, 0, Attribute{}); nonindexed.addVertexBuffer(vertices, 0, Attribute{});
/* Fill index buffer for the indexed mesh */ /* Fill index buffer for the indexed mesh */
indices.setData(std::vector<UnsignedByte>{5, 1}, BufferUsage::StaticDraw); indices.setData(std::initializer_list<UnsignedByte>{5, 1}, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -2359,7 +2359,7 @@ void MeshGLTest::resetIndexBufferBindingWhenBindingVao() {
/* Create an index buffer and fill it (the VAO is bound now, so it'll get /* Create an index buffer and fill it (the VAO is bound now, so it'll get
unbound to avoid messing with its state). */ unbound to avoid messing with its state). */
Buffer indices{Buffer::TargetHint::ElementArray}; Buffer indices{Buffer::TargetHint::ElementArray};
indices.setData(std::vector<UnsignedByte>{5, 1}); indices.setData(std::initializer_list<UnsignedByte>{5, 1});
/* Add the index buffer. The VAO is unbound, so it gets bound. That resets /* Add the index buffer. The VAO is unbound, so it gets bound. That resets
the element array buffer binding and then the buffer gets bound to the the element array buffer binding and then the buffer gets bound to the
@ -2411,7 +2411,7 @@ void MeshGLTest::unbindVAOBeforeEnteringExternalSection() {
buffer.setData(data, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
Buffer indices{Buffer::TargetHint::ElementArray}; Buffer indices{Buffer::TargetHint::ElementArray};
indices.setData(std::vector<UnsignedByte>{5, 0}, BufferUsage::StaticDraw); indices.setData(std::initializer_list<UnsignedByte>{5, 0}, BufferUsage::StaticDraw);
Mesh mesh; Mesh mesh;
mesh.addVertexBuffer(buffer, 4, Attribute{}) mesh.addVertexBuffer(buffer, 4, Attribute{})
@ -2462,7 +2462,7 @@ void MeshGLTest::bindScratchVaoWhenEnteringExternalSection() {
buffer.setData(data, BufferUsage::StaticDraw); buffer.setData(data, BufferUsage::StaticDraw);
Buffer indices{Buffer::TargetHint::ElementArray}; Buffer indices{Buffer::TargetHint::ElementArray};
indices.setData(std::vector<UnsignedByte>{5, 0}, BufferUsage::StaticDraw); indices.setData(std::initializer_list<UnsignedByte>{5, 0}, BufferUsage::StaticDraw);
Mesh mesh; Mesh mesh;
mesh.addVertexBuffer(buffer, 4, Attribute{}) mesh.addVertexBuffer(buffer, 4, Attribute{})

1
src/Magnum/Text/Renderer.cpp

@ -26,6 +26,7 @@
#include "Renderer.h" #include "Renderer.h"
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include "Magnum/Mesh.h" #include "Magnum/Mesh.h"
#include "Magnum/GL/Context.h" #include "Magnum/GL/Context.h"

Loading…
Cancel
Save