Browse Source

Warn and assertion fail when mesh has no vertices/indexes before drawing.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
5d3f54edb2
  1. 12
      src/IndexedMesh.cpp
  2. 3
      src/IndexedMesh.h
  3. 7
      src/Mesh.cpp
  4. 2
      src/Mesh.h

12
src/IndexedMesh.cpp

@ -15,7 +15,10 @@
#include "IndexedMesh.h" #include "IndexedMesh.h"
#include <cassert>
using namespace std; using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace Magnum {
@ -48,4 +51,13 @@ void IndexedMesh::draw() {
glDisableVertexAttribArray(*it); glDisableVertexAttribArray(*it);
} }
void IndexedMesh::finalize() {
if(!_indexCount) {
Error() << "IndexedMesh: the mesh has zero index count!";
assert(0);
}
Mesh::finalize();
}
} }

3
src/IndexedMesh.h

@ -76,6 +76,9 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
*/ */
void draw(); void draw();
protected:
void finalize();
private: private:
Buffer _indexBuffer; Buffer _indexBuffer;
GLsizei _indexCount; GLsizei _indexCount;

7
src/Mesh.cpp

@ -16,9 +16,11 @@
#include "Mesh.h" #include "Mesh.h"
#include "Buffer.h" #include "Buffer.h"
#include <cassert>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace Magnum {
@ -68,6 +70,11 @@ void Mesh::finalize() {
/* Already finalized */ /* Already finalized */
if(finalized) return; if(finalized) return;
if(!_vertexCount) {
Error() << "Mesh: the mesh has zero vertex count!";
assert(0);
}
/* Finalize attribute positions for every buffer */ /* Finalize attribute positions for every buffer */
for(map<Buffer*, pair<bool, vector<Attribute> > >::iterator it = _buffers.begin(); it != _buffers.end(); ++it) { for(map<Buffer*, pair<bool, vector<Attribute> > >::iterator it = _buffers.begin(); it != _buffers.end(); ++it) {
/* Avoid confustion */ /* Avoid confustion */

2
src/Mesh.h

@ -214,7 +214,7 @@ class MAGNUM_EXPORT Mesh {
* Computes location and stride of each attribute in its buffer. After * Computes location and stride of each attribute in its buffer. After
* this function is called, no new attribute can be bound. * this function is called, no new attribute can be bound.
*/ */
void finalize(); virtual void finalize();
/** /**
* @brief Set the mesh dirty * @brief Set the mesh dirty

Loading…
Cancel
Save