From 39033d2480096c487fead1ce8d488378a8e21303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 8 Aug 2013 13:27:41 +0200 Subject: [PATCH] Added Mesh::drawInternal(). Exposes explicit draw parameters like vertex/index offset etc. --- src/Mesh.cpp | 14 +++++++------- src/Mesh.h | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 4332cb6c6..1e613111d 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -136,25 +136,25 @@ Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, Unsi return *this; } -void Mesh::draw() { +void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd) { /* Nothing to draw */ - if(!_vertexCount && !_indexCount) return; + if(!vertexCount && !indexCount) return; (this->*bindImplementation)(); /* Non-indexed mesh */ - if(!_indexCount) - glDrawArrays(static_cast(_primitive), 0, _vertexCount); + if(!indexCount) + glDrawArrays(static_cast(_primitive), firstVertex, vertexCount); #ifndef MAGNUM_TARGET_GLES2 /* Indexed mesh with specified range */ - else if(_indexEnd) - glDrawRangeElements(static_cast(_primitive), _indexStart, _indexEnd, _indexCount, static_cast(_indexType), reinterpret_cast(_indexOffset)); + else if(indexEnd) + glDrawRangeElements(static_cast(_primitive), indexStart, indexEnd, indexCount, static_cast(_indexType), reinterpret_cast(indexOffset)); #endif /* Indexed mesh without specified range */ else - glDrawElements(static_cast(_primitive), _indexCount, static_cast(_indexType), reinterpret_cast(_indexOffset)); + glDrawElements(static_cast(_primitive), indexCount, static_cast(_indexType), reinterpret_cast(indexOffset)); (this->*unbindImplementation)(); } diff --git a/src/Mesh.h b/src/Mesh.h index 2a920e03a..19369e0a5 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -584,7 +584,9 @@ class MAGNUM_EXPORT Mesh { * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements}. */ - void draw(); + void draw() { + drawInternal(0, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + } private: #ifndef DOXYGEN_GENERATING_OUTPUT @@ -708,6 +710,8 @@ class MAGNUM_EXPORT Mesh { #endif #endif + void drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd); + typedef void(Mesh::*CreateImplementation)(); void MAGNUM_LOCAL createImplementationDefault(); void MAGNUM_LOCAL createImplementationVAO(); @@ -792,7 +796,6 @@ template inline Mesh& Mesh::addVertexBuffer(Buffer& buffer, GLintptr return *this; } - } namespace Corrade { namespace Utility {