From bc1b9e39d7749416fa3238b22975296ac606772a Mon Sep 17 00:00:00 2001 From: Hugo Amiard Date: Tue, 13 Sep 2022 16:32:23 +0200 Subject: [PATCH] GL: adapt Buffer/TransformFeedback to use Triple instead of std::tuple. --- doc/snippets/MagnumGL.cpp | 5 ++-- src/Magnum/GL/Buffer.cpp | 25 +++++++++++-------- src/Magnum/GL/Buffer.h | 14 +++++------ src/Magnum/GL/Implementation/BufferState.h | 2 +- .../Implementation/TransformFeedbackState.h | 2 +- src/Magnum/GL/Test/BufferGLTest.cpp | 7 +++--- .../GL/Test/TransformFeedbackGLTest.cpp | 7 +++--- src/Magnum/GL/TransformFeedback.cpp | 21 ++++++++-------- src/Magnum/GL/TransformFeedback.h | 12 ++++----- 9 files changed, 49 insertions(+), 46 deletions(-) diff --git a/doc/snippets/MagnumGL.cpp b/doc/snippets/MagnumGL.cpp index 26a25311f..0ae3196ab 100644 --- a/doc/snippets/MagnumGL.cpp +++ b/doc/snippets/MagnumGL.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "Magnum/Image.h" @@ -196,8 +197,8 @@ MyShader& setTransformFeedback(GL::TransformFeedback& feedback, Int totalCount, GLintptr dataOffset) { feedback.attachBuffers(0, { - std::make_tuple(&positions, positionsOffset, totalCount*sizeof(Vector3)), - std::make_tuple(&data, dataOffset, totalCount*sizeof(Vector2ui)) + {&positions, positionsOffset, GLsizeiptr(totalCount*sizeof(Vector3))}, + {&data, dataOffset, GLsizeiptr(totalCount*sizeof(Vector2ui))} }); return *this; } diff --git a/src/Magnum/GL/Buffer.cpp b/src/Magnum/GL/Buffer.cpp index d916a6ed4..4d26d3c9c 100644 --- a/src/Magnum/GL/Buffer.cpp +++ b/src/Magnum/GL/Buffer.cpp @@ -26,8 +26,8 @@ #include "Buffer.h" -#include #include +#include #ifndef MAGNUM_TARGET_WEBGL #include #endif @@ -151,7 +151,11 @@ void Buffer::unbind(const Target target, const UnsignedInt firstIndex, const std Context::current().state().buffer.bindBasesImplementation(target, firstIndex, {nullptr, count}); } -void Buffer::bind(const Target target, const UnsignedInt firstIndex, Containers::ArrayView> buffers) { +void Buffer::bind(const Target target, const UnsignedInt firstIndex, Containers::ArrayView> buffers) { + Context::current().state().buffer.bindRangesImplementation(target, firstIndex, {buffers.begin(), buffers.size()}); +} + +void Buffer::bind(const Target target, const UnsignedInt firstIndex, std::initializer_list> buffers) { Context::current().state().buffer.bindRangesImplementation(target, firstIndex, {buffers.begin(), buffers.size()}); } @@ -404,24 +408,25 @@ void Buffer::bindImplementationMulti(const Target target, const GLuint firstInde } #endif -void Buffer::bindImplementationFallback(const Target target, const GLuint firstIndex, Containers::ArrayView> buffers) { +void Buffer::bindImplementationFallback(const Target target, const GLuint firstIndex, Containers::ArrayView> buffers) { for(std::size_t i = 0; i != buffers.size(); ++i) { - if(buffers && std::get<0>(buffers[i])) - std::get<0>(buffers[i])->bind(target, firstIndex + i, std::get<1>(buffers[i]), std::get<2>(buffers[i])); + if(buffers && buffers[i].first()) + buffers[i].first()->bind(target, firstIndex + i, buffers[i].second(), buffers[i].third()); else unbind(target, firstIndex + i); } } #ifndef MAGNUM_TARGET_GLES -void Buffer::bindImplementationMulti(const Target target, const GLuint firstIndex, Containers::ArrayView> buffers) { +void Buffer::bindImplementationMulti(const Target target, const GLuint firstIndex, Containers::ArrayView> buffers) { /** @todo use ArrayTuple */ Containers::Array ids{buffers ? buffers.size() : 0}; Containers::Array offsetsSizes{buffers ? buffers.size()*2 : 0}; if(buffers) for(std::size_t i = 0; i != buffers.size(); ++i) { - if(std::get<0>(buffers[i])) { - std::get<0>(buffers[i])->createIfNotAlready(); - ids[i] = std::get<0>(buffers[i])->_id; - std::tie(std::ignore, offsetsSizes[i], offsetsSizes[buffers.size() + i]) = buffers[i]; + if(buffers[i].first()) { + buffers[i].first()->createIfNotAlready(); + ids[i] = buffers[i].first()->_id; + offsetsSizes[i] = buffers[i].second(); + offsetsSizes[buffers.size() + i] = buffers[i].third(); } else { ids[i] = 0; offsetsSizes[i] = 0; diff --git a/src/Magnum/GL/Buffer.h b/src/Magnum/GL/Buffer.h index 3867178c5..cdec63478 100644 --- a/src/Magnum/GL/Buffer.h +++ b/src/Magnum/GL/Buffer.h @@ -31,10 +31,10 @@ */ #include +#include #include #include #include -#include #include "Magnum/Tags.h" #include "Magnum/GL/AbstractObject.h" @@ -766,12 +766,10 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject { * WebGL 1.0, see particular @ref Target values for version * requirements. */ - static void bind(Target target, UnsignedInt firstIndex, Containers::ArrayView> buffers); + static void bind(Target target, UnsignedInt firstIndex, Containers::ArrayView> buffers); /** @overload */ - static void bind(Target target, UnsignedInt firstIndex, std::initializer_list> buffers) { - return bind(target, firstIndex, Containers::arrayView(buffers)); - } + static void bind(Target target, UnsignedInt firstIndex, std::initializer_list> buffers); /** * @brief Bind buffers to given range of indexed targets @@ -1012,7 +1010,7 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject { * @note This function is meant to be used only internally from * @ref AbstractShaderProgram subclasses. See its documentation * for more information. - * @see @ref bind(Target, UnsignedInt, Containers::ArrayView>), + * @see @ref bind(Target, UnsignedInt, Containers::ArrayView>), * @ref maxAtomicCounterBindings(), @ref maxShaderStorageBindings(), * @ref maxUniformBindings(), @ref shaderStorageOffsetAlignment(), * @ref uniformOffsetAlignment(), @ref TransformFeedback::attachBuffer(), @@ -1337,9 +1335,9 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject { static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView buffers); #endif - static void MAGNUM_GL_LOCAL bindImplementationFallback(Target target, GLuint firstIndex, Containers::ArrayView> buffers); + static void MAGNUM_GL_LOCAL bindImplementationFallback(Target target, GLuint firstIndex, Containers::ArrayView> buffers); #ifndef MAGNUM_TARGET_GLES - static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView> buffers); + static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView> buffers); #endif static void MAGNUM_GL_LOCAL copyImplementationDefault(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); diff --git a/src/Magnum/GL/Implementation/BufferState.h b/src/Magnum/GL/Implementation/BufferState.h index 25aaad329..8375fde30 100644 --- a/src/Magnum/GL/Implementation/BufferState.h +++ b/src/Magnum/GL/Implementation/BufferState.h @@ -51,7 +51,7 @@ struct BufferState { #ifndef MAGNUM_TARGET_GLES2 void(*bindBasesImplementation)(Buffer::Target, UnsignedInt, Containers::ArrayView); - void(*bindRangesImplementation)(Buffer::Target, UnsignedInt, Containers::ArrayView>); + void(*bindRangesImplementation)(Buffer::Target, UnsignedInt, Containers::ArrayView>); void(*copyImplementation)(Buffer&, Buffer&, GLintptr, GLintptr, GLsizeiptr); #endif void(Buffer::*createImplementation)(); diff --git a/src/Magnum/GL/Implementation/TransformFeedbackState.h b/src/Magnum/GL/Implementation/TransformFeedbackState.h index 7f157584c..72f6b68e0 100644 --- a/src/Magnum/GL/Implementation/TransformFeedbackState.h +++ b/src/Magnum/GL/Implementation/TransformFeedbackState.h @@ -63,7 +63,7 @@ struct TransformFeedbackState { void(TransformFeedback::*createImplementation)(); void(TransformFeedback::*attachRangeImplementation)(GLuint, Buffer&, GLintptr, GLsizeiptr); void(TransformFeedback::*attachBaseImplementation)(GLuint, Buffer&); - void(TransformFeedback::*attachRangesImplementation)(GLuint, Containers::ArrayView>); + void(TransformFeedback::*attachRangesImplementation)(GLuint, Containers::ArrayView>); void(TransformFeedback::*attachBasesImplementation)(GLuint, Containers::ArrayView); }; diff --git a/src/Magnum/GL/Test/BufferGLTest.cpp b/src/Magnum/GL/Test/BufferGLTest.cpp index ef6d42202..22c04bd16 100644 --- a/src/Magnum/GL/Test/BufferGLTest.cpp +++ b/src/Magnum/GL/Test/BufferGLTest.cpp @@ -24,9 +24,9 @@ */ #include -#include #include #include +#include #include #include "Magnum/GL/Buffer.h" @@ -254,10 +254,9 @@ void BufferGLTest::bindRange() { MAGNUM_VERIFY_NO_GL_ERROR(); - /** @todo C++14: get rid of std::make_tuple */ Buffer::bind(Buffer::Target::Uniform, 7, { - std::make_tuple(&buffer, 256, 13), {}, - std::make_tuple(&buffer, 768, 64)}); + {&buffer, 256, 13}, {}, + {&buffer, 768, 64}}); MAGNUM_VERIFY_NO_GL_ERROR(); } diff --git a/src/Magnum/GL/Test/TransformFeedbackGLTest.cpp b/src/Magnum/GL/Test/TransformFeedbackGLTest.cpp index 08eba636a..130da0934 100644 --- a/src/Magnum/GL/Test/TransformFeedbackGLTest.cpp +++ b/src/Magnum/GL/Test/TransformFeedbackGLTest.cpp @@ -23,8 +23,9 @@ DEALINGS IN THE SOFTWARE. */ -#include #include +#include +#include #include "Magnum/Image.h" #include "Magnum/GL/AbstractShaderProgram.h" @@ -489,8 +490,8 @@ void TransformFeedbackGLTest::attachRanges() { TransformFeedback feedback; feedback.attachBuffers(0, { - std::make_tuple(&output1, 256, 2*sizeof(Vector2)), - std::make_tuple(&output2, 512, 2*sizeof(Float)) + {&output1, 256, 2*sizeof(Vector2)}, + {&output2, 512, 2*sizeof(Float)} }); MAGNUM_VERIFY_NO_GL_ERROR(); diff --git a/src/Magnum/GL/TransformFeedback.cpp b/src/Magnum/GL/TransformFeedback.cpp index 086fac7bc..b0479ea64 100644 --- a/src/Magnum/GL/TransformFeedback.cpp +++ b/src/Magnum/GL/TransformFeedback.cpp @@ -26,10 +26,10 @@ #include "TransformFeedback.h" #ifndef MAGNUM_TARGET_GLES2 -#include #ifndef MAGNUM_TARGET_WEBGL #include #endif +#include #include #include "Magnum/GL/AbstractShaderProgram.h" @@ -207,30 +207,31 @@ void TransformFeedback::attachImplementationDSA(const GLuint index, Buffer& buff } #endif -TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, Containers::ArrayView> buffers) { +TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, Containers::ArrayView> buffers) { (this->*Context::current().state().transformFeedback.attachRangesImplementation)(firstIndex, buffers); return *this; } +TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, std::initializer_list> buffers) { + (this->*Context::current().state().transformFeedback.attachRangesImplementation)(firstIndex, Containers::arrayView(buffers)); + return *this; +} + TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, Containers::ArrayView buffers) { (this->*Context::current().state().transformFeedback.attachBasesImplementation)(firstIndex, buffers); return *this; } -void TransformFeedback::attachImplementationFallback(const GLuint firstIndex, Containers::ArrayView> buffers) { +void TransformFeedback::attachImplementationFallback(const GLuint firstIndex, Containers::ArrayView> buffers) { bindInternal(); Buffer::bind(Buffer::Target(GL_TRANSFORM_FEEDBACK_BUFFER), firstIndex, buffers); } #ifndef MAGNUM_TARGET_GLES -void TransformFeedback::attachImplementationDSA(const GLuint firstIndex, Containers::ArrayView> buffers) { +void TransformFeedback::attachImplementationDSA(const GLuint firstIndex, Containers::ArrayView> buffers) { for(std::size_t i = 0; i != buffers.size(); ++i) { - Buffer* buffer; - GLintptr offset; - GLsizeiptr size; - std::tie(buffer, offset, size) = *(buffers.begin() + i); - - glTransformFeedbackBufferRange(_id, firstIndex + i, buffer ? buffer->id() : 0, offset, size); + Buffer* buffer = buffers[i].first(); + glTransformFeedbackBufferRange(_id, firstIndex + i, buffer ? buffer->id() : 0, buffers[i].second(), buffers[i].third()); } } #endif diff --git a/src/Magnum/GL/TransformFeedback.h b/src/Magnum/GL/TransformFeedback.h index 6b9eaa717..878d9385c 100644 --- a/src/Magnum/GL/TransformFeedback.h +++ b/src/Magnum/GL/TransformFeedback.h @@ -31,8 +31,8 @@ */ #endif +#include #include -#include #include "Magnum/Tags.h" #include "Magnum/GL/AbstractObject.h" @@ -340,12 +340,10 @@ class MAGNUM_GL_EXPORT TransformFeedback: public AbstractObject { * eventually @fn_gl{BindTransformFeedback} and * @fn_gl_keyword{BindBuffersRange} or @fn_gl_keyword{BindBufferRange} */ - TransformFeedback& attachBuffers(UnsignedInt firstIndex, Containers::ArrayView> buffers); + TransformFeedback& attachBuffers(UnsignedInt firstIndex, Containers::ArrayView> buffers); /** @overload */ - TransformFeedback& attachBuffers(UnsignedInt firstIndex, std::initializer_list> buffers) { - return attachBuffers(firstIndex, Containers::arrayView(buffers)); - } + TransformFeedback& attachBuffers(UnsignedInt firstIndex, std::initializer_list> buffers); /** * @brief Attach buffers @@ -439,10 +437,10 @@ class MAGNUM_GL_EXPORT TransformFeedback: public AbstractObject { void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint index, Buffer& buffer); #endif - void MAGNUM_GL_LOCAL attachImplementationFallback(GLuint firstIndex, Containers::ArrayView> buffers); + void MAGNUM_GL_LOCAL attachImplementationFallback(GLuint firstIndex, Containers::ArrayView> buffers); void MAGNUM_GL_LOCAL attachImplementationFallback(GLuint firstIndex, Containers::ArrayView buffers); #ifndef MAGNUM_TARGET_GLES - void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint firstIndex, Containers::ArrayView> buffers); + void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint firstIndex, Containers::ArrayView> buffers); void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint firstIndex, Containers::ArrayView buffers); #endif