Browse Source

Updated MeshView to reflect changes in Mesh.

Added base vertex specification, not differentiating between vertex and
index count. The old setVertexRange(), setIndexRange(4) and
setIndexRange(2) are now aliases to new setCount(), setBaseVertex(),
setIndexRange(3) and setIndexRangge(1) functions, are marked as
deprecated and will be removed in future release.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
5e06b776cf
  1. 18
      src/Magnum/DebugTools/Implementation/CapsuleRenderer.cpp
  2. 20
      src/Magnum/MeshView.cpp
  3. 107
      src/Magnum/MeshView.h

18
src/Magnum/DebugTools/Implementation/CapsuleRenderer.cpp

@ -46,21 +46,24 @@ AbstractCapsuleRenderer<2>::AbstractCapsuleRenderer(): AbstractShapeRenderer<2>(
/* Bottom hemisphere */
if(!(bottom = ResourceManager::instance().get<MeshView>("capsule2d-bottom"))) {
auto view = new MeshView(*wireframeMesh);
view->setIndexRange(0, rings*4, 0, rings*2+1);
view->setCount(rings*4)
.setIndexRange(0, 0, rings*2+1);
ResourceManager::instance().set(bottom.key(), view, ResourceDataState::Final, ResourcePolicy::Manual);
}
/* Cylinder */
if(!(cylinder = ResourceManager::instance().get<MeshView>("capsule2d-cylinder"))) {
auto view = new MeshView(*wireframeMesh);
view->setIndexRange(rings*4, 4, rings*2+1, rings*2+3);
view->setCount(4)
.setIndexRange(rings*4, rings*2+1, rings*2+3);
ResourceManager::instance().set(cylinder.key(), view, ResourceDataState::Final, ResourcePolicy::Manual);
}
/* Top hemisphere */
if(!(top = ResourceManager::instance().get<MeshView>("capsule2d-top"))) {
auto view = new MeshView(*wireframeMesh);
view->setIndexRange(rings*4+4, rings*4, rings*2+3, rings*4+4);
view->setCount(rings*4)
.setIndexRange(rings*4+4, rings*2+3, rings*4+4);
ResourceManager::instance().set(top.key(), view, ResourceDataState::Final, ResourcePolicy::Manual);
}
}
@ -73,21 +76,24 @@ AbstractCapsuleRenderer<3>::AbstractCapsuleRenderer(): AbstractShapeRenderer<3>(
/* Bottom hemisphere */
if(!(bottom = ResourceManager::instance().get<MeshView>("capsule3d-bottom"))) {
auto view = new MeshView(*wireframeMesh);
view->setIndexRange(0, rings*8, 0, rings*4+1);
view->setCount(rings*8)
.setIndexRange(0, 0, rings*4+1);
ResourceManager::instance().set(bottom.key(), view, ResourceDataState::Final, ResourcePolicy::Manual);
}
/* Cylinder */
if(!(cylinder = ResourceManager::instance().get<MeshView>("capsule3d-cylinder"))) {
auto view = new MeshView(*wireframeMesh);
view->setIndexRange(rings*8, segments*4+8, rings*4+1, rings*4+segments*2+5);
view->setCount(segments*4+8)
.setIndexRange(rings*8, rings*4+1, rings*4+segments*2+5);
ResourceManager::instance().set(cylinder.key(), view, ResourceDataState::Final, ResourcePolicy::Manual);
}
/* Top */
if(!(top = ResourceManager::instance().get<MeshView>("capsule3d-top"))) {
auto view = new MeshView(*wireframeMesh);
view->setIndexRange(rings*8+segments*4+8, rings*8, rings*4+segments*2+5, rings*8+segments*2+6);
view->setCount(rings*8)
.setIndexRange(rings*8+segments*4+8, rings*4+segments*2+5, rings*8+segments*2+6);
ResourceManager::instance().set(top.key(), view, ResourceDataState::Final, ResourcePolicy::Manual);
}
}

20
src/Magnum/MeshView.cpp

@ -29,18 +29,8 @@
namespace Magnum {
#ifndef MAGNUM_TARGET_GLES2
MeshView& MeshView::setIndexRange(Int first, Int count, UnsignedInt start, UnsignedInt end)
#else
MeshView& MeshView::setIndexRange(Int first, Int count, UnsignedInt, UnsignedInt)
#endif
{
MeshView& MeshView::setIndexRange(Int first) {
_indexOffset = _original->_indexOffset + first*_original->indexSize();
_count = count;
#ifndef MAGNUM_TARGET_GLES2
_indexStart = start;
_indexEnd = end;
#endif
return *this;
}
@ -48,18 +38,18 @@ void MeshView::draw(AbstractShaderProgram& shader) {
shader.use();
#ifndef MAGNUM_TARGET_GLES2
_original->drawInternal(_count, _firstVertex, _indexOffset, _indexStart, _indexEnd);
_original->drawInternal(_count, _baseVertex, _indexOffset, _indexStart, _indexEnd);
#else
_original->drawInternal(_count, _firstVertex, _indexOffset);
_original->drawInternal(_count, _baseVertex, _indexOffset);
#endif
}
#ifdef MAGNUM_BUILD_DEPRECATED
void MeshView::draw() {
#ifndef MAGNUM_TARGET_GLES2
_original->drawInternal(_count, _firstVertex, _indexOffset, _indexStart, _indexEnd);
_original->drawInternal(_count, _baseVertex, _indexOffset, _indexStart, _indexEnd);
#else
_original->drawInternal(_count, _firstVertex, _indexOffset);
_original->drawInternal(_count, _baseVertex, _indexOffset);
#endif
}
#endif

107
src/Magnum/MeshView.h

@ -72,48 +72,102 @@ class MAGNUM_EXPORT MeshView {
MeshView& operator=(MeshView&& other) = delete;
/**
* @brief Set vertex range
* @param first First vertex
* @param count Vertex count
* @brief Set vertex/index count
* @return Reference to self (for method chaining)
*
* Default is zero @p offset and zero @p count. If index range is
* non-zero, vertex range is ignored, see main class documentation for
* more information.
* Default is `0`.
*/
MeshView& setVertexRange(Int first, Int count) {
_firstVertex = first;
MeshView& setCount(Int count) {
_count = count;
return *this;
}
/**
* @brief Set base vertex
*
* Sets number of vertices of which the vertex buffer will be offset
* when drawing. Default is `0`.
* @requires_gl Desktop OpenGL is required for base vertex
* specification in indexed meshes.
*/
MeshView& setBaseVertex(Int baseVertex) {
_baseVertex = baseVertex;
return *this;
}
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Set vertex range
* @param first First vertex
* @param count Vertex count
*
* @deprecated Use @ref Magnum::MeshView::setCount() "setCount()" and
* @ref Magnum::MeshView::setBaseVertex() "setBaseVertex()"
* instead.
*/
CORRADE_DEPRECATED("use setCount() and setBaseVertex() instead") MeshView& setVertexRange(Int first, Int count) {
return setCount(count), setBaseVertex(first);
}
#endif
/**
* @brief Set index range
* @param first First vertex
* @param start Minimum array index contained in the buffer
* @param end Maximum array index contained in the buffer
* @return Reference to self (for method chaining)
*
* The @p start and @p end parameters may help to improve memory access
* performance, as only a portion of vertex buffer needs to be
* acccessed. On OpenGL ES 2.0 this function behaves the same as
* @ref setIndexRange(Int), as index range functionality is not
* available there.
* @see @ref setCount()
*/
MeshView& setIndexRange(Int first, UnsignedInt start, UnsignedInt end);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Set index range
* @param first First index
* @param count Index count
* @param start Minimum array index contained in the buffer
* @param end Maximum array index contained in the buffer
*
* @deprecated Use @ref Magnum::MeshView::setCount() "setCount()" and
* @ref Magnum::MeshView::setIndexRange(Int, UnsignedInt, UnsignedInt) "setIndexRange(Int, UnsignedInt, UnsignedInt)"
* instead.
*/
CORRADE_DEPRECATED("use setCount() and setIndexRange(Int, UnsignedInt, UnsignedInt) instead") MeshView& setIndexRange(Int first, Int count, UnsignedInt start, UnsignedInt end) {
return setCount(count), setIndexRange(first, start, end);
}
#endif
/**
* @brief Set index range
* @param first First index
* @return Reference to self (for method chaining)
*
* Specifying `0` for both @p start and @p end behaves the same as
* @ref setIndexRange(Int, Int). On OpenGL ES 2.0 this function behaves
* always as @ref setIndexRange(Int, Int), as this functionality is
* not available there.
* Prefer to use @ref setIndexRange(Int, UnsignedInt, UnsignedInt) for
* better performance.
* @see @ref setCount()
*/
MeshView& setIndexRange(Int first, Int count, UnsignedInt start, UnsignedInt end);
MeshView& setIndexRange(Int first);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Set index range
* @param first First index
* @param count Index count
* @return Reference to self (for method chaining)
*
* Prefer to use @ref setIndexRange(Int, Int, UnsignedInt, UnsignedInt)
* for better performance.
* @deprecated Use @ref Magnum::MeshView::setCount() "setCount()" and
* @ref Magnum::MeshView::setIndexRange(Int) "setIndexRange(Int)"
* instead.
*/
MeshView& setIndexRange(Int first, Int count) {
return setIndexRange(first, count, 0, 0);
CORRADE_DEPRECATED("use setCount() and setIndexRange(Int) instead") MeshView& setIndexRange(Int first, Int count) {
return setCount(count), setIndexRange(first);
}
#endif
/**
* @brief Draw the mesh
@ -135,19 +189,32 @@ class MAGNUM_EXPORT MeshView {
private:
Mesh* _original;
Int _firstVertex, _count;
Int _count, _baseVertex;
GLintptr _indexOffset;
#ifndef MAGNUM_TARGET_GLES2
UnsignedInt _indexStart, _indexEnd;
#endif
};
inline MeshView::MeshView(Mesh& original): _original(&original), _firstVertex(0), _count(0), _indexOffset(0)
inline MeshView::MeshView(Mesh& original): _original(&original), _count(0), _baseVertex(0), _indexOffset(0)
#ifndef MAGNUM_TARGET_GLES2
, _indexStart(0), _indexEnd(0)
#endif
{}
inline MeshView& MeshView::setIndexRange(Int first, UnsignedInt start, UnsignedInt end) {
setIndexRange(first);
#ifndef MAGNUM_TARGET_GLES2
_indexStart = start;
_indexEnd = end;
#else
static_cast<void>(start);
static_cast<void>(end);
#endif
return *this;
}
}
#endif

Loading…
Cancel
Save