Browse Source

Added Mesh::drawInternal().

Exposes explicit draw parameters like vertex/index offset etc.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
39033d2480
  1. 14
      src/Mesh.cpp
  2. 7
      src/Mesh.h

14
src/Mesh.cpp

@ -136,25 +136,25 @@ Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, Unsi
return *this; return *this;
} }
void Mesh::draw() { void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd) {
/* Nothing to draw */ /* Nothing to draw */
if(!_vertexCount && !_indexCount) return; if(!vertexCount && !indexCount) return;
(this->*bindImplementation)(); (this->*bindImplementation)();
/* Non-indexed mesh */ /* Non-indexed mesh */
if(!_indexCount) if(!indexCount)
glDrawArrays(static_cast<GLenum>(_primitive), 0, _vertexCount); glDrawArrays(static_cast<GLenum>(_primitive), firstVertex, vertexCount);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/* Indexed mesh with specified range */ /* Indexed mesh with specified range */
else if(_indexEnd) else if(indexEnd)
glDrawRangeElements(static_cast<GLenum>(_primitive), _indexStart, _indexEnd, _indexCount, static_cast<GLenum>(_indexType), reinterpret_cast<GLvoid*>(_indexOffset)); glDrawRangeElements(static_cast<GLenum>(_primitive), indexStart, indexEnd, indexCount, static_cast<GLenum>(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
#endif #endif
/* Indexed mesh without specified range */ /* Indexed mesh without specified range */
else else
glDrawElements(static_cast<GLenum>(_primitive), _indexCount, static_cast<GLenum>(_indexType), reinterpret_cast<GLvoid*>(_indexOffset)); glDrawElements(static_cast<GLenum>(_primitive), indexCount, static_cast<GLenum>(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
(this->*unbindImplementation)(); (this->*unbindImplementation)();
} }

7
src/Mesh.h

@ -584,7 +584,9 @@ class MAGNUM_EXPORT Mesh {
* or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object}
* is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements}. * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements}.
*/ */
void draw(); void draw() {
drawInternal(0, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd);
}
private: private:
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
@ -708,6 +710,8 @@ class MAGNUM_EXPORT Mesh {
#endif #endif
#endif #endif
void drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd);
typedef void(Mesh::*CreateImplementation)(); typedef void(Mesh::*CreateImplementation)();
void MAGNUM_LOCAL createImplementationDefault(); void MAGNUM_LOCAL createImplementationDefault();
void MAGNUM_LOCAL createImplementationVAO(); void MAGNUM_LOCAL createImplementationVAO();
@ -792,7 +796,6 @@ template<class ...T> inline Mesh& Mesh::addVertexBuffer(Buffer& buffer, GLintptr
return *this; return *this;
} }
} }
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {

Loading…
Cancel
Save