Browse Source

Mesh: warn about improper buffer binding also on Emscripten.

It seems that rebinding is forbidden by law also in WebGL. Also updated
Best Practices docs to note that.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
ed5ee5c3c2
  1. 16
      doc/best-practices.dox
  2. 6
      src/Mesh.cpp

16
doc/best-practices.dox

@ -57,17 +57,17 @@ information.
- [Best practices for 3D graphics](https://developers.google.com/native-client/beta/devguide/coding/3D-graphics#best-practices) - [Best practices for 3D graphics](https://developers.google.com/native-client/beta/devguide/coding/3D-graphics#best-practices)
@subsubsection best-practices-nacl-buffer-types Native Client requires unique buffer binding @subsection best-practices-web-buffer-types Native Client and Emscripten require unique buffer binding
As noted in the above link, buffers in NaCl implementation need to be bound As noted in the above link, buffers in NaCl implementation and and also in
only to one unique target, i.e., @ref Buffer bound to @ref Buffer::Target::Array WebGL need to be bound only to one unique target, i.e., @ref Buffer bound to
cannot be later rebound to @ref Buffer::Target::ElementArray. However, %Magnum @ref Buffer::Target::Array cannot be later rebound to @ref Buffer::Target::ElementArray.
by default uses any sufficient target when binding the buffer internally (e.g. However, %Magnum by default uses any sufficient target when binding the buffer
for setting data or copying). To avoid this, set target hint to desired target, internally (e.g. for setting data or copying). To avoid this, set target hint
either in constructor or using @ref Buffer::setTargetHint(). to desired target, either in constructor or using @ref Buffer::setTargetHint().
To ease up the development, @ref Mesh checks proper target hint when adding To ease up the development, @ref Mesh checks proper target hint when adding
vertex and index buffers. vertex and index buffers in both Native Client and Emscripten.
@section best-practices-hw Hardware-specific @section best-practices-hw Hardware-specific

6
src/Mesh.cpp

@ -138,7 +138,7 @@ Mesh& Mesh::operator=(Mesh&& other) noexcept {
} }
Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) {
#ifdef CORRADE_TARGET_NACL #if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN)
CORRADE_ASSERT(buffer.targetHint() == Buffer::Target::ElementArray, CORRADE_ASSERT(buffer.targetHint() == Buffer::Target::ElementArray,
"Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer.targetHint(), *this); "Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer.targetHint(), *this);
#endif #endif
@ -265,7 +265,7 @@ void Mesh::destroyImplementationVAO() {
} }
void Mesh::attributePointerImplementationDefault(const Attribute& attribute) { void Mesh::attributePointerImplementationDefault(const Attribute& attribute) {
#ifdef CORRADE_TARGET_NACL #if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN)
CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, 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(), ); "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), );
#endif #endif
@ -274,7 +274,7 @@ void Mesh::attributePointerImplementationDefault(const Attribute& attribute) {
} }
void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { void Mesh::attributePointerImplementationVAO(const Attribute& attribute) {
#ifdef CORRADE_TARGET_NACL #if defined(CORRADE_TARGET_NACL) || defined(CORRADE_TARGET_EMSCRIPTEN)
CORRADE_ASSERT(attribute.buffer->targetHint() == Buffer::Target::Array, 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(), ); "Mesh::addVertexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::Array << "but got" << attribute.buffer->targetHint(), );
#endif #endif

Loading…
Cancel
Save