Browse Source

Use CORRADE_ASSERT() instead of cassert and direct error output.

Unlike previous solution this can be compiled without any impact on
performance at all.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
64665872cc
  1. 17
      src/AbstractShaderProgram.cpp
  2. 10
      src/IndexedMesh.cpp
  3. 9
      src/Mesh.cpp
  4. 6
      src/MeshTools/CMakeLists.txt
  5. 9
      src/MeshTools/CombineIndexedArrays.h
  6. 6
      src/MeshTools/FlipNormals.cpp
  7. 6
      src/MeshTools/GenerateFlatNormals.cpp
  8. 15
      src/MeshTools/Interleave.h
  9. 5
      src/MeshTools/Subdivide.h
  10. 7
      src/MeshTools/Test/CMakeLists.txt
  11. 2
      src/MeshTools/Test/CombineIndexedArraysTest.cpp
  12. 4
      src/MeshTools/Test/InterleaveTest.cpp
  13. 8
      src/Primitives/Capsule.cpp
  14. 7
      src/Primitives/UVSphere.cpp

17
src/AbstractShaderProgram.cpp

@ -15,7 +15,6 @@
#include "AbstractShaderProgram.h"
#include <cassert>
#include <fstream>
#define LINKER_MESSAGE_MAX_LENGTH 1024
@ -51,19 +50,13 @@ bool AbstractShaderProgram::attachShader(Shader* shader) {
}
void AbstractShaderProgram::bindAttribute(GLuint location, const string& name) {
if(state != Initialized) {
Error() << "AbstractShaderProgram: attribute cannot be bound after linking.";
assert(0);
}
CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: attribute cannot be bound after linking.", )
glBindAttribLocation(program, location, name.c_str());
}
void AbstractShaderProgram::bindFragmentDataLocation(GLuint location, const std::string& name) {
if(state != Initialized) {
Error() << "AbstractShaderProgram: fragment data location cannot be bound after linking.";
assert(0);
}
CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: fragment data location cannot be bound after linking.", )
glBindFragDataLocation(program, location, name.c_str());
}
@ -102,11 +95,7 @@ void AbstractShaderProgram::link() {
}
GLint AbstractShaderProgram::uniformLocation(const std::string& name) {
if(state != Linked) {
Error() << "AbstractShaderProgram: uniform location cannot be retrieved before linking.";
assert(0);
return -1;
}
CORRADE_ASSERT(state == Linked, "AbstractShaderProgram: uniform location cannot be retrieved before linking.", -1)
GLint location = glGetUniformLocation(program, name.c_str());
if(location == -1)

10
src/IndexedMesh.cpp

@ -15,11 +15,6 @@
#include "IndexedMesh.h"
#include <cassert>
using namespace std;
using namespace Corrade::Utility;
namespace Magnum {
void IndexedMesh::draw() {
@ -37,10 +32,7 @@ void IndexedMesh::draw() {
void IndexedMesh::finalize() {
if(isFinalized()) return;
if(!_indexCount) {
Error() << "IndexedMesh: the mesh has zero index count!";
assert(0);
}
CORRADE_ASSERT(_indexCount, "IndexedMesh: the mesh has zero index count!", )
/* Finalize attribute positions */
Mesh::finalize();

9
src/Mesh.cpp

@ -16,11 +16,7 @@
#include "Mesh.h"
#include "Buffer.h"
#include <cassert>
#include <iostream>
using namespace std;
using namespace Corrade::Utility;
namespace Magnum {
@ -57,10 +53,7 @@ void Mesh::finalize() {
/* Already finalized */
if(finalized) return;
if(!_vertexCount) {
Error() << "Mesh: the mesh has zero vertex count!";
assert(0);
}
CORRADE_ASSERT(_vertexCount, "Mesh: the mesh has zero vertex count!", )
/* Enable vertex arrays for all attributes */
for(set<GLuint>::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it)

6
src/MeshTools/CMakeLists.txt

@ -16,5 +16,11 @@ install(TARGETS MagnumMeshTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
if(BUILD_TESTS)
enable_testing()
# Library with graceful assert for testing
add_library(MagnumMeshToolsTestLib SHARED ${MagnumMeshTools_SRCS})
set_target_properties(MagnumMeshToolsTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)
target_link_libraries(MagnumMeshToolsTestLib ${MAGNUM_LIBRARY})
add_subdirectory(Test)
endif()

9
src/MeshTools/CombineIndexedArrays.h

@ -19,7 +19,6 @@
* @brief Function Magnum::MeshTools::combineIndexedArrays()
*/
#include <cassert>
#include <vector>
#include <numeric>
#include <tuple>
@ -58,12 +57,8 @@ class CombineIndexedArrays {
private:
template<class ...T> inline static size_t indexCount(const std::vector<unsigned int>& first, const std::vector<T>&... next) {
size_t count = indexCount(next...);
if(sizeof...(next) != 0 && count != first.size()) {
Corrade::Utility::Error() << "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.";
assert(0);
return 0;
}
CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0)
return first.size();
}

6
src/MeshTools/FlipNormals.cpp

@ -16,15 +16,11 @@
#include "FlipNormals.h"
using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace MeshTools {
void flipFaceWinding(vector<unsigned int>& indices) {
if(indices.size()%3 != 0) {
Error() << "MeshTools::flipNormals(): index count is not divisible by 3!";
return;
}
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", )
for(size_t i = 0; i != indices.size(); i += 3)
swap(indices[i+1], indices[i+2]);

6
src/MeshTools/GenerateFlatNormals.cpp

@ -18,15 +18,11 @@
#include "MeshTools/Clean.h"
using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace MeshTools {
tuple<vector<unsigned int>, vector<Vector3>> generateFlatNormals(const std::vector< unsigned int >& indices, const vector< Vector4 >& vertices) {
if(indices.size()%3 != 0) {
Error() << "MeshTools::generateFlatNormals(): index count is not divisible by 3!";
return tuple<vector<unsigned int>, vector<Vector3>>();
}
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple<vector<unsigned int>, vector<Vector3>>()))
/* Create normal for every triangle (assuming counterclockwise winding) */
vector<unsigned int> normalIndices;

15
src/MeshTools/Interleave.h

@ -19,7 +19,6 @@
* @brief Function Magnum::MeshTools::interleave()
*/
#include <cassert>
#include <cstring>
#include <vector>
#include <limits>
@ -54,11 +53,7 @@ class Interleave {
}
template<class ...T> void operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<T>&... attributes) {
if(!mesh->isInterleaved(buffer)) {
Corrade::Utility::Error() << "MeshTools::interleave(): the buffer is not interleaved, nothing done";
assert(0);
return;
}
CORRADE_ASSERT(mesh->isInterleaved(buffer), "MeshTools::interleave(): the buffer is not interleaved, nothing done", )
operator()(attributes...);
@ -69,12 +64,8 @@ class Interleave {
}
template<class T, class ...U> inline static size_t attributeCount(const std::vector<T>& first, const std::vector<U>&... next) {
size_t count = attributeCount(next...);
if(sizeof...(next) != 0 && count != first.size()) {
Corrade::Utility::Error() << "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.";
assert(0);
return 0;
}
CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0)
return first.size();
}

5
src/MeshTools/Subdivide.h

@ -32,10 +32,7 @@ template<class Vertex, class Interpolator> class Subdivide {
inline Subdivide(std::vector<unsigned int>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
void operator()(Interpolator interpolator) {
if(indices.size()%3 != 0) {
Corrade::Utility::Error() << "MeshTools::subdivide(): index count is not divisible by 3!";
return;
}
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", )
size_t indexCount = indices.size();
indices.reserve(indices.size()*4);

7
src/MeshTools/Test/CMakeLists.txt

@ -1,9 +1,12 @@
corrade_add_test(CleanTest CleanTest.h CleanTest.cpp ${CORRADE_UTILITY_LIBRARY})
corrade_add_test(CombineIndexedArraysTest CombineIndexedArraysTest.h CombineIndexedArraysTest.cpp ${CORRADE_UTILITY_LIBRARY})
corrade_add_test(CompressIndicesTest CompressIndicesTest.h CompressIndicesTest.cpp ${CORRADE_UTILITY_LIBRARY} ${MAGNUM_LIBRARY})
corrade_add_test(FlipNormalsTest FlipNormalsTest.h FlipNormalsTest.cpp ${MAGNUM_MESHTOOLS_LIBRARY})
corrade_add_test(GenerateFlatNormalsTest GenerateFlatNormalsTest.h GenerateFlatNormalsTest.cpp ${MAGNUM_MESHTOOLS_LIBRARY})
corrade_add_test(FlipNormalsTest FlipNormalsTest.h FlipNormalsTest.cpp MagnumMeshToolsTestLib)
corrade_add_test(GenerateFlatNormalsTest GenerateFlatNormalsTest.h GenerateFlatNormalsTest.cpp MagnumMeshToolsTestLib)
corrade_add_test(InterleaveTest InterleaveTest.h InterleaveTest.cpp ${CORRADE_UTILITY_LIBRARY})
corrade_add_test(SubdivideTest SubdivideTest.h SubdivideTest.cpp ${CORRADE_UTILITY_LIBRARY})
corrade_add_test(SubdivideCleanBenchmark SubdivideCleanBenchmark.h SubdivideCleanBenchmark.cpp ${CORRADE_UTILITY_LIBRARY} ${MAGNUM_PRIMITIVES_LIBRARY})
corrade_add_test(TipsifyTest TipsifyTest.h TipsifyTest.cpp ${MAGNUM_MESHTOOLS_LIBRARY})
# Graceful assert for testing
set_target_properties(CombineIndexedArraysTest InterleaveTest SubdivideTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)

2
src/MeshTools/Test/CombineIndexedArraysTest.cpp

@ -15,8 +15,6 @@
#include "CombineIndexedArraysTest.h"
#define NDEBUG
#include <sstream>
#include <QtTest/QTest>

4
src/MeshTools/Test/InterleaveTest.cpp

@ -15,10 +15,6 @@
#include "InterleaveTest.h"
#ifndef NDEBUG
#define NDEBUG
#endif
#include <sstream>
#include <QtTest/QTest>

8
src/Primitives/Capsule.cpp

@ -15,18 +15,12 @@
#include "Capsule.h"
#include <cassert>
using namespace std;
using namespace Corrade::Utility;
namespace Magnum { namespace Primitives {
Capsule::Capsule(unsigned int rings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData(Mesh::Primitive::Triangles, new vector<unsigned int>, {new vector<Vector4>()}, {new vector<Vector3>()}, textureCoords == TextureCoords::Generate ? vector<vector<Vector2>*>{new vector<Vector2>()} : vector<vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {
if(rings < 1 || segments < 3) {
Error() << "Capsule must have at least one ring and three segments";
assert(0);
}
CORRADE_ASSERT(rings >= 1 && segments >= 3, "Capsule must have at least one ring and three segments", )
GLfloat height = 2.0f+length;
GLfloat textureCoordsVIncrement = 1.0f/(rings*height);

7
src/Primitives/UVSphere.cpp

@ -13,8 +13,6 @@
GNU Lesser General Public License version 3 for more details.
*/
#include <cassert>
#include "UVSphere.h"
using namespace std;
@ -23,10 +21,7 @@ using namespace Corrade::Utility;
namespace Magnum { namespace Primitives {
UVSphere::UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords): Capsule(segments, textureCoords) {
if(rings < 2 || segments < 3) {
Error() << "UVSphere must have at least two rings and three segments";
assert(0);
}
CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", )
GLfloat textureCoordsVIncrement = 1.0f/rings;
GLfloat ringAngleIncrement = PI/rings;

Loading…
Cancel
Save