From 2ab37ba2a11873c18d51053aaeceff97c2888567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Aug 2013 16:02:05 +0200 Subject: [PATCH] Fixed OpenGL ES 2.0 compatibility. Issues related to lack of glDrawRangeElements(). --- src/Mesh.cpp | 7 ++++++- src/Mesh.h | 8 ++++++++ src/MeshView.cpp | 13 ++++++++++++- src/MeshView.h | 12 ++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 1e613111d..7b770eadb 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -136,7 +136,12 @@ Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, Unsi return *this; } -void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd) { +#ifndef MAGNUM_TARGET_GLES2 +void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd) +#else +void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount) +#endif +{ /* Nothing to draw */ if(!vertexCount && !indexCount) return; diff --git a/src/Mesh.h b/src/Mesh.h index 16859d610..1a93db1d8 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -597,7 +597,11 @@ class MAGNUM_EXPORT Mesh { * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements}. */ void draw() { + #ifndef MAGNUM_TARGET_GLES2 drawInternal(0, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + #else + drawInternal(0, _vertexCount, _indexOffset, _indexCount); + #endif } private: @@ -722,7 +726,11 @@ class MAGNUM_EXPORT Mesh { #endif #endif + #ifndef MAGNUM_TARGET_GLES2 void drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd); + #else + void drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount); + #endif typedef void(Mesh::*CreateImplementation)(); void MAGNUM_LOCAL createImplementationDefault(); diff --git a/src/MeshView.cpp b/src/MeshView.cpp index 302f268e7..9eed8f255 100644 --- a/src/MeshView.cpp +++ b/src/MeshView.cpp @@ -28,16 +28,27 @@ namespace Magnum { -MeshView& MeshView::setIndexRange(Int first, Int count, UnsignedInt start, UnsignedInt end) { +#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 +{ _indexOffset = first*_original->indexSize(); _indexCount = count; + #ifndef MAGNUM_TARGET_GLES2 _indexStart = start; _indexEnd = end; + #endif return *this; } void MeshView::draw() { + #ifndef MAGNUM_TARGET_GLES2 _original->drawInternal(_firstVertex, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + #else + _original->drawInternal(_firstVertex, _vertexCount, _indexOffset, _indexCount); + #endif } } diff --git a/src/MeshView.h b/src/MeshView.h index 3fdb0aa0f..548736754 100644 --- a/src/MeshView.h +++ b/src/MeshView.h @@ -100,7 +100,9 @@ class MAGNUM_EXPORT MeshView { * @return Reference to self (for method chaining) * * Specifying `0` for both @p start and @p end behaves the same as - * @ref setIndexRange(Int, Int). + * @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. */ MeshView& setIndexRange(Int first, Int count, UnsignedInt start, UnsignedInt end); @@ -129,10 +131,16 @@ class MAGNUM_EXPORT MeshView { Int _firstVertex, _vertexCount, _indexCount; GLintptr _indexOffset; + #ifndef MAGNUM_TARGET_GLES2 UnsignedInt _indexStart, _indexEnd; + #endif }; -inline MeshView::MeshView(Mesh& original): _original(&original), _firstVertex(0), _vertexCount(0), _indexCount(0), _indexOffset(0), _indexStart(0), _indexEnd(0) {} +inline MeshView::MeshView(Mesh& original): _original(&original), _firstVertex(0), _vertexCount(0), _indexCount(0), _indexOffset(0) + #ifndef MAGNUM_TARGET_GLES2 + , _indexStart(0), _indexEnd(0) + #endif + {} }