Browse Source

Removing IndexedMesh, part 1: moved enums and related stuff to Mesh.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
688251add9
  1. 52
      src/IndexedMesh.cpp
  2. 45
      src/IndexedMesh.h
  3. 44
      src/Mesh.cpp
  4. 41
      src/Mesh.h
  5. 1
      src/Test/CMakeLists.txt
  6. 55
      src/Test/IndexedMeshTest.cpp
  7. 30
      src/Test/MeshTest.cpp

52
src/IndexedMesh.cpp

@ -15,8 +15,6 @@
#include "IndexedMesh.h"
#include <Utility/Debug.h>
#include "Buffer.h"
#include "Context.h"
#include "Extensions.h"
@ -26,16 +24,6 @@ namespace Magnum {
IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault;
IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault;
std::size_t IndexedMesh::indexSize(IndexType type) {
switch(type) {
case IndexType::UnsignedByte: return 1;
case IndexType::UnsignedShort: return 2;
case IndexType::UnsignedInt: return 4;
}
CORRADE_INTERNAL_ASSERT(false);
}
IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) {
_indexBuffer = buffer;
(this->*bindIndexBufferImplementation)();
@ -87,44 +75,4 @@ void IndexedMesh::bindIndexedImplementationDefault() {
void IndexedMesh::bindIndexedImplementationVAO() {}
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug operator<<(Debug debug, IndexedMesh::IndexType value) {
switch(value) {
#define _c(value) case IndexedMesh::IndexType::value: return debug << "IndexedMesh::IndexType::" #value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
}
return debug << "IndexedMesh::IndexType::(invalid)";
}
#endif
}
namespace Corrade { namespace Utility {
std::string ConfigurationValue<Magnum::IndexedMesh::IndexType>::toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags) {
switch(value) {
#define _c(value) case Magnum::IndexedMesh::IndexType::value: return #value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
}
return "";
}
Magnum::IndexedMesh::IndexType ConfigurationValue<Magnum::IndexedMesh::IndexType>::fromString(const std::string& stringValue, ConfigurationValueFlags) {
#define _c(value) if(stringValue == #value) return Magnum::IndexedMesh::IndexType::value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
return Magnum::IndexedMesh::IndexType::UnsignedInt;
}
}}

45
src/IndexedMesh.h

@ -72,25 +72,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
friend class Context;
public:
/**
* @brief Index type
*
* @see setIndexType(), indexSize()
*/
enum class IndexType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */
UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */
/**
* Unsigned int
* @requires_gles30 %Extension @es_extension{OES,element_index_uint}
*/
UnsignedInt = GL_UNSIGNED_INT
};
/** @brief Size of given index type */
static std::size_t indexSize(IndexType type);
/**
* @brief Constructor
* @param primitive Primitive type
@ -196,32 +177,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
IndexType _indexType;
};
/** @debugoperator{Magnum::IndexedMesh} */
Debug MAGNUM_EXPORT operator<<(Debug debug, IndexedMesh::IndexType value);
}
namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::IndexedMesh} */
template<> struct MAGNUM_EXPORT ConfigurationValue<Magnum::IndexedMesh::IndexType> {
ConfigurationValue() = delete;
/**
* @brief Write enum value as string
*
* If the value is invalid, returns empty string.
*/
static std::string toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags);
/**
* @brief Read enum value as string
*
* If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt".
*/
static Magnum::IndexedMesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags);
};
}}
#endif

44
src/Mesh.cpp

@ -37,6 +37,16 @@ Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &M
Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault;
Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault;
std::size_t Mesh::indexSize(IndexType type) {
switch(type) {
case IndexType::UnsignedByte: return 1;
case IndexType::UnsignedShort: return 2;
case IndexType::UnsignedInt: return 4;
}
CORRADE_INTERNAL_ASSERT(false);
}
Mesh::~Mesh() {
/* Remove current vao from the state */
GLuint& current = Context::current()->state()->mesh->currentVAO;
@ -271,6 +281,18 @@ Debug operator<<(Debug debug, Mesh::Primitive value) {
return debug << "Mesh::Primitive::(invalid)";
}
Debug operator<<(Debug debug, Mesh::IndexType value) {
switch(value) {
#define _c(value) case Mesh::IndexType::value: return debug << "Mesh::IndexType::" #value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
}
return debug << "Mesh::IndexType::(invalid)";
}
#endif
}
@ -306,4 +328,26 @@ Magnum::Mesh::Primitive ConfigurationValue<Magnum::Mesh::Primitive>::fromString(
return Magnum::Mesh::Primitive::Points;
}
std::string ConfigurationValue<Magnum::Mesh::IndexType>::toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags) {
switch(value) {
#define _c(value) case Magnum::Mesh::IndexType::value: return #value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
}
return "";
}
Magnum::Mesh::IndexType ConfigurationValue<Magnum::Mesh::IndexType>::fromString(const std::string& stringValue, ConfigurationValueFlags) {
#define _c(value) if(stringValue == #value) return Magnum::Mesh::IndexType::value;
_c(UnsignedByte)
_c(UnsignedShort)
_c(UnsignedInt)
#undef _c
return Magnum::Mesh::IndexType::UnsignedInt;
}
}}

41
src/Mesh.h

@ -358,6 +358,25 @@ class MAGNUM_EXPORT Mesh {
TriangleFan = GL_TRIANGLE_FAN
};
/**
* @brief Index type
*
* @see setIndexType(), indexSize()
*/
enum class IndexType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */
UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */
/**
* Unsigned int
* @requires_gles30 %Extension @es_extension{OES,element_index_uint}
*/
UnsignedInt = GL_UNSIGNED_INT
};
/** @brief Size of given index type */
static std::size_t indexSize(IndexType type);
/**
* @brief Constructor
* @param primitive Primitive type
@ -753,6 +772,9 @@ class MAGNUM_EXPORT Mesh {
/** @debugoperator{Magnum::Mesh} */
Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value);
/** @debugoperator{Magnum::Mesh} */
Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::IndexType value);
}
namespace Corrade { namespace Utility {
@ -776,6 +798,25 @@ template<> struct MAGNUM_EXPORT ConfigurationValue<Magnum::Mesh::Primitive> {
static Magnum::Mesh::Primitive fromString(const std::string& stringValue, ConfigurationValueFlags);
};
/** @configurationvalue{Magnum::Mesh} */
template<> struct MAGNUM_EXPORT ConfigurationValue<Magnum::Mesh::IndexType> {
ConfigurationValue() = delete;
/**
* @brief Write enum value as string
*
* If the value is invalid, returns empty string.
*/
static std::string toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags);
/**
* @brief Read enum value as string
*
* If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt".
*/
static Magnum::Mesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags);
};
}}
#endif

1
src/Test/CMakeLists.txt

@ -2,7 +2,6 @@ corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum)
corrade_add_test(ArrayTest ArrayTest.cpp)
corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum)
corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum)
corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib)
corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib)

55
src/Test/IndexedMeshTest.cpp

@ -1,55 +0,0 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
#include <sstream>
#include <TestSuite/Tester.h>
#include <Utility/Configuration.h>
#include "IndexedMesh.h"
using namespace Corrade::Utility;
namespace Magnum { namespace Test {
class IndexedMeshTest: public Corrade::TestSuite::Tester {
public:
IndexedMeshTest();
void debug();
void configuration();
};
IndexedMeshTest::IndexedMeshTest() {
addTests(&IndexedMeshTest::debug,
&IndexedMeshTest::configuration);
}
void IndexedMeshTest::debug() {
std::ostringstream o;
Debug(&o) << IndexedMesh::IndexType::UnsignedShort;
CORRADE_COMPARE(o.str(), "IndexedMesh::IndexType::UnsignedShort\n");
}
void IndexedMeshTest::configuration() {
Configuration c;
c.setValue("type", IndexedMesh::IndexType::UnsignedByte);
CORRADE_COMPARE(c.value<std::string>("type"), "UnsignedByte");
CORRADE_COMPARE(c.value<IndexedMesh::IndexType>("type"), IndexedMesh::IndexType::UnsignedByte);
}
}}
CORRADE_TEST_MAIN(Magnum::Test::IndexedMeshTest)

30
src/Test/MeshTest.cpp

@ -27,22 +27,32 @@ class MeshTest: public Corrade::TestSuite::Tester {
public:
MeshTest();
void debug();
void configuration();
void debugPrimitive();
void debugIndexType();
void configurationPrimitive();
void configurationIndexType();
};
MeshTest::MeshTest() {
addTests(&MeshTest::debug,
&MeshTest::configuration);
addTests(&MeshTest::debugPrimitive,
&MeshTest::debugIndexType,
&MeshTest::configurationPrimitive,
&MeshTest::configurationIndexType);
}
void MeshTest::debug() {
void MeshTest::debugPrimitive() {
std::ostringstream o;
Debug(&o) << Mesh::Primitive::TriangleFan;
CORRADE_COMPARE(o.str(), "Mesh::Primitive::TriangleFan\n");
}
void MeshTest::configuration() {
void MeshTest::debugIndexType() {
std::ostringstream o;
Debug(&o) << Mesh::IndexType::UnsignedShort;
CORRADE_COMPARE(o.str(), "Mesh::IndexType::UnsignedShort\n");
}
void MeshTest::configurationPrimitive() {
Configuration c;
c.setValue("primitive", Mesh::Primitive::LineStrip);
@ -50,6 +60,14 @@ void MeshTest::configuration() {
CORRADE_COMPARE(c.value<Mesh::Primitive>("primitive"), Mesh::Primitive::LineStrip);
}
void MeshTest::configurationIndexType() {
Configuration c;
c.setValue("type", Mesh::IndexType::UnsignedByte);
CORRADE_COMPARE(c.value<std::string>("type"), "UnsignedByte");
CORRADE_COMPARE(c.value<Mesh::IndexType>("type"), Mesh::IndexType::UnsignedByte);
}
}}
CORRADE_TEST_MAIN(Magnum::Test::MeshTest)

Loading…
Cancel
Save