From 4c1f226544aa8f9f638c80db4d5efc85cefaacac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 22:16:22 +0200 Subject: [PATCH] Warn about improper Buffer target hint in NaCl. Slightly eases up the porting. --- doc/best-practices.dox | 5 ++++- src/Mesh.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/best-practices.dox b/doc/best-practices.dox index 7517541ca..6dba060be 100644 --- a/doc/best-practices.dox +++ b/doc/best-practices.dox @@ -57,11 +57,14 @@ information. As noted in the above link, buffers in NaCl implementation need to be bound only to one unique target, i.e., Buffer bound to @ref Buffer::Target "Target::Array" -cannot be later rebound to @ref Buffer::Target "Target::Element". However, +cannot be later rebound to @ref Buffer::Target "Target::ElementArray". However, %Magnum by default uses any sufficient target when binding the buffer internally (e.g. for setting data or copying). To avoid this, set target hint to desired target, either in constructor or using Buffer::setTargetHint(). +To ease up the development, @ref Mesh checks proper target hint when adding +vertex and index buffers. + @subsection best-practices-powervr PowerVR hardware - [PowerVR Performance Recommendations](http://www.imgtec.com/powervr/insider/docs/PowerVR.Performance%20Recommendations.1.0.28.External.pdf) [PDF] diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 995552711..368ec21a3 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -118,6 +118,11 @@ Mesh& Mesh::operator=(Mesh&& other) { } Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { + #ifdef CORRADE_TARGET_NACL + CORRADE_ASSERT(buffer->targetHint() == Buffer::Target::ElementArray, + "Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer->targetHint(), this); + #endif + indexOffset = offset; indexType = type; #ifndef MAGNUM_TARGET_GLES2 @@ -235,10 +240,20 @@ void Mesh::destroyImplementationVAO() { } void Mesh::attributePointerImplementationDefault(const Attribute& attribute) { + #ifdef CORRADE_TARGET_NACL + CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, + "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), ); + #endif + attributes.push_back(attribute); } void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { + #ifdef CORRADE_TARGET_NACL + CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, + "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), ); + #endif + bindVAO(vao); vertexAttribPointer(attribute); }