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;
}
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<GLenum>(_primitive), 0, _vertexCount);
if(!indexCount)
glDrawArrays(static_cast<GLenum>(_primitive), firstVertex, vertexCount);
#ifndef MAGNUM_TARGET_GLES2
/* Indexed mesh with specified range */
else if(_indexEnd)
glDrawRangeElements(static_cast<GLenum>(_primitive), _indexStart, _indexEnd, _indexCount, static_cast<GLenum>(_indexType), reinterpret_cast<GLvoid*>(_indexOffset));
else if(indexEnd)
glDrawRangeElements(static_cast<GLenum>(_primitive), indexStart, indexEnd, indexCount, static_cast<GLenum>(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
#endif
/* Indexed mesh without specified range */
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)();
}

7
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<class ...T> inline Mesh& Mesh::addVertexBuffer(Buffer& buffer, GLintptr
return *this;
}
}
namespace Corrade { namespace Utility {

Loading…
Cancel
Save