Browse Source

GL: use Containers::Iterable also in AbstractShaderProgram::draw().

Forgot about this case in 4ff655740e.
pull/610/head
Vladimír Vondruš 4 years ago
parent
commit
a475c92d99
  1. 1
      doc/snippets/MagnumShaders-gl.cpp
  2. 10
      src/Magnum/GL/AbstractShaderProgram.cpp
  3. 16
      src/Magnum/GL/AbstractShaderProgram.h
  4. 2
      src/Magnum/GL/Implementation/MeshState.h
  5. 23
      src/Magnum/GL/MeshView.cpp
  6. 4
      src/Magnum/GL/MeshView.h
  7. 3
      src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp

1
doc/snippets/MagnumShaders-gl.cpp

@ -26,6 +26,7 @@
#include <numeric>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Utility/FormatStl.h>
#include "Magnum/ImageView.h"

10
src/Magnum/GL/AbstractShaderProgram.cpp

@ -474,15 +474,15 @@ AbstractShaderProgram& AbstractShaderProgram::draw(Mesh& mesh, const Containers:
#endif
#endif
AbstractShaderProgram& AbstractShaderProgram::draw(Containers::ArrayView<const Containers::Reference<MeshView>> meshes) {
AbstractShaderProgram& AbstractShaderProgram::draw(const Containers::Iterable<MeshView>& meshes) {
if(meshes.isEmpty()) return *this;
use();
#ifndef CORRADE_NO_ASSERT
const Mesh* original = &*meshes.front()->_original;
const Mesh* original = &*meshes.front()._original;
for(std::size_t i = 0; i != meshes.size(); ++i)
CORRADE_ASSERT(&*meshes[i]->_original == original, "GL::AbstractShaderProgram::draw(): all meshes must be views of the same original mesh, expected" << original << "but got" << &*meshes[i]->_original << "at index" << i, *this);
CORRADE_ASSERT(&*meshes[i]._original == original, "GL::AbstractShaderProgram::draw(): all meshes must be views of the same original mesh, expected" << original << "but got" << &*meshes[i]._original << "at index" << i, *this);
#endif
#ifndef MAGNUM_TARGET_GLES
@ -493,10 +493,6 @@ AbstractShaderProgram& AbstractShaderProgram::draw(Containers::ArrayView<const C
return *this;
}
AbstractShaderProgram& AbstractShaderProgram::draw(std::initializer_list<Containers::Reference<MeshView>> meshes) {
return draw(Containers::arrayView(meshes));
}
#ifndef MAGNUM_TARGET_GLES
AbstractShaderProgram& AbstractShaderProgram::drawTransformFeedback(Mesh& mesh, TransformFeedback& xfb, UnsignedInt stream) {
/* Nothing to draw, exit without touching any state */

16
src/Magnum/GL/AbstractShaderProgram.h

@ -45,7 +45,8 @@
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
/* For attachShaders(), which used to take a std::initializer_list<Reference> */
/* For attachShaders(), which used to take a std::initializer_list<Reference>,
and draw({MeshView}) as well */
#include <Corrade/Containers/Iterable.h>
/* For label() / setLabel(), which used to be a std::string */
#include <Corrade/Containers/StringStl.h>
@ -1254,13 +1255,7 @@ class MAGNUM_GL_EXPORT AbstractShaderProgram: public AbstractObject {
* if the mesh is indexed and @ref MeshView::baseVertex() is not
* `0`
*/
AbstractShaderProgram& draw(Containers::ArrayView<const Containers::Reference<MeshView>> meshes);
/**
* @overload
* @m_since{2020,06}
*/
AbstractShaderProgram& draw(std::initializer_list<Containers::Reference<MeshView>> meshes);
AbstractShaderProgram& draw(const Containers::Iterable<MeshView>& meshes);
#ifndef MAGNUM_TARGET_GLES
/**
@ -2126,10 +2121,7 @@ accidental calls to
} \
_MAGNUM_GL_ABSTRACTSHADERPROGRAM_SUBCLASS_DRAW_IMPLEMENTATION_NOT_32BIT(__VA_ARGS__) \
_MAGNUM_GL_ABSTRACTSHADERPROGRAM_SUBCLASS_DRAW_IMPLEMENTATION_GLES(__VA_ARGS__) \
__VA_ARGS__& draw(Corrade::Containers::ArrayView<const Corrade::Containers::Reference<Magnum::GL::MeshView>> meshes) { \
return static_cast<__VA_ARGS__&>(Magnum::GL::AbstractShaderProgram::draw(meshes)); \
} \
__VA_ARGS__& draw(std::initializer_list<Corrade::Containers::Reference<Magnum::GL::MeshView>> meshes) { \
__VA_ARGS__& draw(const Corrade::Containers::Iterable<Magnum::GL::MeshView>& meshes) { \
return static_cast<__VA_ARGS__&>(Magnum::GL::AbstractShaderProgram::draw(meshes)); \
} \
_MAGNUM_GL_ABSTRACTSHADERPROGRAM_SUBCLASS_DRAW_IMPLEMENTATION_NOT_GLES(__VA_ARGS__)

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

@ -77,7 +77,7 @@ struct MeshState {
#endif
#ifdef MAGNUM_TARGET_GLES
void(*multiDrawViewImplementation)(Containers::ArrayView<const Containers::Reference<MeshView>>);
void(*multiDrawViewImplementation)(const Containers::Iterable<MeshView>&);
void(APIENTRY *multiDrawArraysImplementation)(GLenum, const GLint*, const GLsizei*, GLsizei);
void(APIENTRY *multiDrawElementsImplementation)(GLenum, const GLsizei*, GLenum, const void* const*, GLsizei);
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))

23
src/Magnum/GL/MeshView.cpp

@ -27,6 +27,7 @@
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayTuple.h>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Utility/Assert.h>
#include "Magnum/GL/AbstractShaderProgram.h"
@ -47,11 +48,11 @@ void MeshView::draw(AbstractShaderProgram&& shader, Containers::ArrayView<const
}
void MeshView::draw(AbstractShaderProgram& shader, std::initializer_list<Containers::Reference<MeshView>> meshes) {
shader.draw(meshes);
shader.draw(Containers::arrayView(meshes));
}
void MeshView::draw(AbstractShaderProgram&& shader, std::initializer_list<Containers::Reference<MeshView>> meshes) {
shader.draw(meshes);
shader.draw(Containers::arrayView(meshes));
}
#endif
@ -85,10 +86,10 @@ MeshView& MeshView::draw(AbstractShaderProgram&& shader, TransformFeedback& xfb,
#endif
#endif
void MeshView::multiDrawImplementationDefault(Containers::ArrayView<const Containers::Reference<MeshView>> meshes) {
CORRADE_INTERNAL_ASSERT(meshes.size());
void MeshView::multiDrawImplementationDefault(const Containers::Iterable<MeshView>& meshes) {
CORRADE_INTERNAL_ASSERT(!meshes.isEmpty());
Mesh& original = meshes[0]->_original;
Mesh& original = meshes.front()._original;
/* Gather the parameters */
Containers::ArrayView<UnsignedInt> counts;
@ -110,19 +111,19 @@ void MeshView::multiDrawImplementationDefault(Containers::ArrayView<const Contai
vertex is specified for any of the meshes */
bool useVertexOffsets = !original.isIndexed();
for(std::size_t i = 0; i != meshes.size(); ++i) {
CORRADE_ASSERT(meshes[i]->_instanceCount == 1, "GL::AbstractShaderProgram::draw(): cannot multi-draw instanced meshes", );
CORRADE_ASSERT(meshes[i]._instanceCount == 1, "GL::AbstractShaderProgram::draw(): cannot multi-draw instanced meshes", );
counts[i] = meshes[i]->_count;
vertexOffsets[i] = meshes[i]->_baseVertex;
indexOffsets[i] = meshes[i]->_indexOffset;
if(meshes[i]->_baseVertex) useVertexOffsets = true;
counts[i] = meshes[i]._count;
vertexOffsets[i] = meshes[i]._baseVertex;
indexOffsets[i] = meshes[i]._indexOffset;
if(meshes[i]._baseVertex) useVertexOffsets = true;
}
original.drawInternal(counts, useVertexOffsets ? vertexOffsets : nullptr, indexOffsets);
}
#ifdef MAGNUM_TARGET_GLES
void MeshView::multiDrawImplementationFallback(Containers::ArrayView<const Containers::Reference<MeshView>> meshes) {
void MeshView::multiDrawImplementationFallback(const Containers::Iterable<MeshView>& meshes) {
for(MeshView& mesh: meshes) {
/* Nothing to draw in this mesh */
if(!mesh._count) continue;

4
src/Magnum/GL/MeshView.h

@ -263,9 +263,9 @@ class MAGNUM_GL_EXPORT MeshView {
friend AbstractShaderProgram;
friend Implementation::MeshState;
static MAGNUM_GL_LOCAL void multiDrawImplementationDefault(Containers::ArrayView<const Containers::Reference<MeshView>> meshes);
static MAGNUM_GL_LOCAL void multiDrawImplementationDefault(const Containers::Iterable<MeshView>& meshes);
#ifdef MAGNUM_TARGET_GLES
static MAGNUM_GL_LOCAL void multiDrawImplementationFallback(Containers::ArrayView<const Containers::Reference<MeshView>> meshes);
static MAGNUM_GL_LOCAL void multiDrawImplementationFallback(const Containers::Iterable<MeshView>& meshes);
#endif
Containers::Reference<Mesh> _original;

3
src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp

@ -1192,8 +1192,7 @@ void AbstractShaderProgramGLTest::subclassDraw() {
.draw(mesh, counts, instanceCounts, vertexOffsets, nullptr)
#endif
#endif
.draw(Containers::arrayView<Containers::Reference<MeshView>>({}))
.draw(std::initializer_list<Containers::Reference<MeshView>>{})
.draw(Containers::Iterable<MeshView>{})
#ifndef MAGNUM_TARGET_GLES
.drawTransformFeedback(meshNoInstances, xfb)
.drawTransformFeedback(meshNoInstances, xfb, 0)

Loading…
Cancel
Save