Browse Source

GL: adapt Buffer/TransformFeedback to use Triple instead of std::tuple.

pull/594/head
Hugo Amiard 4 years ago committed by Vladimír Vondruš
parent
commit
bc1b9e39d7
  1. 5
      doc/snippets/MagnumGL.cpp
  2. 25
      src/Magnum/GL/Buffer.cpp
  3. 14
      src/Magnum/GL/Buffer.h
  4. 2
      src/Magnum/GL/Implementation/BufferState.h
  5. 2
      src/Magnum/GL/Implementation/TransformFeedbackState.h
  6. 7
      src/Magnum/GL/Test/BufferGLTest.cpp
  7. 7
      src/Magnum/GL/Test/TransformFeedbackGLTest.cpp
  8. 21
      src/Magnum/GL/TransformFeedback.cpp
  9. 12
      src/Magnum/GL/TransformFeedback.h

5
doc/snippets/MagnumGL.cpp

@ -27,6 +27,7 @@
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Containers/Reference.h>
#include <Corrade/Containers/Triple.h>
#include <Corrade/TestSuite/Tester.h>
#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;
}

25
src/Magnum/GL/Buffer.cpp

@ -26,8 +26,8 @@
#include "Buffer.h"
#include <tuple>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Triple.h>
#ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h>
#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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
void Buffer::bind(const Target target, const UnsignedInt firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
Context::current().state().buffer.bindRangesImplementation(target, firstIndex, {buffers.begin(), buffers.size()});
}
void Buffer::bind(const Target target, const UnsignedInt firstIndex, std::initializer_list<Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> 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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
void Buffer::bindImplementationFallback(const Target target, const GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> 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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
void Buffer::bindImplementationMulti(const Target target, const GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
/** @todo use ArrayTuple */
Containers::Array<GLuint> ids{buffers ? buffers.size() : 0};
Containers::Array<GLintptr> 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;

14
src/Magnum/GL/Buffer.h

@ -31,10 +31,10 @@
*/
#include <cstddef>
#include <utility>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/EnumSet.h>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/StlForwardTuple.h>
#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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
static void bind(Target target, UnsignedInt firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers);
/** @overload */
static void bind(Target target, UnsignedInt firstIndex, std::initializer_list<std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
return bind(target, firstIndex, Containers::arrayView(buffers));
}
static void bind(Target target, UnsignedInt firstIndex, std::initializer_list<Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> 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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>>),
* @see @ref bind(Target, UnsignedInt, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>>),
* @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<Buffer* const> buffers);
#endif
static void MAGNUM_GL_LOCAL bindImplementationFallback(Target target, GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
static void MAGNUM_GL_LOCAL bindImplementationFallback(Target target, GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers);
#ifndef MAGNUM_TARGET_GLES
static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers);
#endif
static void MAGNUM_GL_LOCAL copyImplementationDefault(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);

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

@ -51,7 +51,7 @@ struct BufferState {
#ifndef MAGNUM_TARGET_GLES2
void(*bindBasesImplementation)(Buffer::Target, UnsignedInt, Containers::ArrayView<Buffer* const>);
void(*bindRangesImplementation)(Buffer::Target, UnsignedInt, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>>);
void(*bindRangesImplementation)(Buffer::Target, UnsignedInt, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>>);
void(*copyImplementation)(Buffer&, Buffer&, GLintptr, GLintptr, GLsizeiptr);
#endif
void(Buffer::*createImplementation)();

2
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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>>);
void(TransformFeedback::*attachRangesImplementation)(GLuint, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>>);
void(TransformFeedback::*attachBasesImplementation)(GLuint, Containers::ArrayView<Buffer* const>);
};

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

@ -24,9 +24,9 @@
*/
#include <array>
#include <tuple>
#include <vector>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Triple.h>
#include <Corrade/TestSuite/Compare/Container.h>
#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();
}

7
src/Magnum/GL/Test/TransformFeedbackGLTest.cpp

@ -23,8 +23,9 @@
DEALINGS IN THE SOFTWARE.
*/
#include <tuple>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Containers/Reference.h>
#include <Corrade/Containers/Triple.h>
#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();

21
src/Magnum/GL/TransformFeedback.cpp

@ -26,10 +26,10 @@
#include "TransformFeedback.h"
#ifndef MAGNUM_TARGET_GLES2
#include <tuple>
#ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h>
#endif
#include <Corrade/Containers/Triple.h>
#include <Corrade/Utility/Assert.h>
#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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
(this->*Context::current().state().transformFeedback.attachRangesImplementation)(firstIndex, buffers);
return *this;
}
TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, std::initializer_list<Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
(this->*Context::current().state().transformFeedback.attachRangesImplementation)(firstIndex, Containers::arrayView(buffers));
return *this;
}
TransformFeedback& TransformFeedback::attachBuffers(const UnsignedInt firstIndex, Containers::ArrayView<Buffer* const> buffers) {
(this->*Context::current().state().transformFeedback.attachBasesImplementation)(firstIndex, buffers);
return *this;
}
void TransformFeedback::attachImplementationFallback(const GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
void TransformFeedback::attachImplementationFallback(const GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
bindInternal();
Buffer::bind(Buffer::Target(GL_TRANSFORM_FEEDBACK_BUFFER), firstIndex, buffers);
}
#ifndef MAGNUM_TARGET_GLES
void TransformFeedback::attachImplementationDSA(const GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
void TransformFeedback::attachImplementationDSA(const GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> 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

12
src/Magnum/GL/TransformFeedback.h

@ -31,8 +31,8 @@
*/
#endif
#include <utility>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Utility/StlForwardTuple.h>
#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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
TransformFeedback& attachBuffers(UnsignedInt firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers);
/** @overload */
TransformFeedback& attachBuffers(UnsignedInt firstIndex, std::initializer_list<std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers) {
return attachBuffers(firstIndex, Containers::arrayView(buffers));
}
TransformFeedback& attachBuffers(UnsignedInt firstIndex, std::initializer_list<Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> 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<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
void MAGNUM_GL_LOCAL attachImplementationFallback(GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers);
void MAGNUM_GL_LOCAL attachImplementationFallback(GLuint firstIndex, Containers::ArrayView<Buffer* const> buffers);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers);
void MAGNUM_GL_LOCAL attachImplementationDSA(GLuint firstIndex, Containers::ArrayView<Buffer* const> buffers);
#endif

Loading…
Cancel
Save