Browse Source

Check for mesh emptiness even before binding the shader.

Prevents unnecessary state touching.
pull/187/head^2
Vladimír Vondruš 10 years ago
parent
commit
b6dbc8fc58
  1. 6
      src/Magnum/Mesh.cpp
  2. 6
      src/Magnum/MeshView.cpp
  3. 18
      src/Magnum/Test/MeshGLTest.cpp

6
src/Magnum/Mesh.cpp

@ -245,6 +245,9 @@ Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, Unsi
}
void Mesh::draw(AbstractShaderProgram& shader) {
/* Nothing to draw, exit without touching any state */
if(!_count || !_instanceCount) return;
shader.use();
#ifndef MAGNUM_TARGET_GLES
@ -266,9 +269,6 @@ void Mesh::drawInternal(Int count, Int baseVertex, Int instanceCount, GLintptr i
{
const Implementation::MeshState& state = *Context::current().state().mesh;
/* Nothing to draw */
if(!count || !instanceCount) return;
(this->*state.bindImplementation)();
/* Non-instanced mesh */

6
src/Magnum/MeshView.cpp

@ -130,6 +130,9 @@ void MeshView::multiDrawImplementationDefault(std::initializer_list<std::referen
#ifdef MAGNUM_TARGET_GLES
void MeshView::multiDrawImplementationFallback(std::initializer_list<std::reference_wrapper<MeshView>> meshes) {
for(MeshView& mesh: meshes) {
/* Nothing to draw in this mesh */
if(!mesh._count) continue;
#ifndef MAGNUM_TARGET_GLES2
mesh._original.get().drawInternal(mesh._count, mesh._baseVertex, mesh._instanceCount, mesh._indexOffset, mesh._indexStart, mesh._indexEnd);
#else
@ -145,6 +148,9 @@ MeshView& MeshView::setIndexRange(Int first) {
}
void MeshView::draw(AbstractShaderProgram& shader) {
/* Nothing to draw, exit without touching any state */
if(!_count || !_instanceCount) return;
shader.use();
#ifndef MAGNUM_TARGET_GLES

18
src/Magnum/Test/MeshGLTest.cpp

@ -1853,19 +1853,23 @@ MultiChecker::MultiChecker(AbstractShaderProgram&& shader, Mesh& mesh): framebuf
mesh.setPrimitive(MeshPrimitive::Points)
.setCount(2);
/* Set zero count so we test mesh skipping */
MeshView a{mesh};
a.setCount(0);
/* Skip first vertex so we test also offsets */
MeshView a(mesh);
a.setCount(1)
MeshView b{mesh};
b.setCount(1)
.setBaseVertex(mesh.baseVertex());
MeshView b(mesh);
b.setCount(1);
MeshView c{mesh};
c.setCount(1);
if(mesh.isIndexed()) {
b.setBaseVertex(mesh.baseVertex())
c.setBaseVertex(mesh.baseVertex())
.setIndexRange(1);
} else b.setBaseVertex(1);
} else c.setBaseVertex(1);
MeshView::draw(shader, {a, b});
MeshView::draw(shader, {a, b, c});
}
template<class T> T MultiChecker::get(PixelFormat format, PixelType type) {

Loading…
Cancel
Save