diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index c67860095..ce8f2ae79 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -2,9 +2,10 @@ # # This module depends on Corrade and additionally defines: # -# MAGNUM_FOUND - True if Magnum library is found -# MAGNUM_INCLUDE_DIR - Include dir for Magnum -# MAGNUM_LIBRARY - Magnum library +# MAGNUM_FOUND - True if Magnum library is found +# MAGNUM_INCLUDE_DIR - Include dir for Magnum +# MAGNUM_LIBRARY - Magnum library +# MAGNUM_PRIMITIVES_LIBRARY - Library with primitives # # MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory # MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake modules @@ -13,7 +14,7 @@ find_package(Corrade REQUIRED) -if (MAGNUM_INCLUDE_DIR AND MAGNUM_LIBRARY) +if (MAGNUM_INCLUDE_DIR AND MAGNUM_LIBRARY AND MAGNUM_PRIMITIVES_LIBRARY) # Already in cache set(MAGNUM_FOUND TRUE) @@ -21,6 +22,7 @@ if (MAGNUM_INCLUDE_DIR AND MAGNUM_LIBRARY) else() # Libraries find_library(MAGNUM_LIBRARY Magnum) + find_library(MAGNUM_PRIMITIVES_LIBRARY MagnumPrimitives) # Paths find_path(MAGNUM_INCLUDE_DIR @@ -32,6 +34,7 @@ else() find_package_handle_standard_args("Magnum" DEFAULT_MSG MAGNUM_INCLUDE_DIR MAGNUM_LIBRARY + MAGNUM_PRIMITIVES_LIBRARY ) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af1d19de7..6c0d7bbf9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) add_subdirectory(Math) +add_subdirectory(Primitives) set(Magnum_SRCS Object.cpp diff --git a/src/Primitives/AbstractPrimitive.h b/src/Primitives/AbstractPrimitive.h new file mode 100644 index 000000000..fccbdfcf3 --- /dev/null +++ b/src/Primitives/AbstractPrimitive.h @@ -0,0 +1,86 @@ +#ifndef Magnum_Primitives_AbstractPrimitive_h +#define Magnum_Primitives_AbstractPrimitive_h +/* + Copyright © 2010, 2011 Vladimír Vondruš + + 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. +*/ + +/** @file + * @brief Class Magnum::Primitives::AbstractPrimitive + */ + +#include "TypeTraits.h" + +#include "IndexedMesh.h" + +namespace Magnum { + +class Buffer; +class IndexedMesh; + +namespace Primitives { + +/** +@brief Base class for primitives +@tparam _IndexType Type used for indices. Only unsigned integral types are + allowed, as TypeTraits is used to check whether given type can be used. +*/ +template class AbstractPrimitive { + public: + /** @brief Type used for indices */ + typedef typename TypeTraits<_IndexType>::IndexType IndexType; + + /** @brief Destructor */ + inline virtual ~AbstractPrimitive() {} + + /** @brief Primitive type */ + virtual Mesh::Primitive primitive() const = 0; + + /** @brief Count of vertices */ + virtual size_t vertexCount() const = 0; + + /** @brief Count of indices */ + virtual size_t indexCount() const = 0; + + /** + * @brief Build the primitive + * @param mesh Destination mesh + * @param vertexBuffer Vertex buffer where to put the data + * + * Prepares the mesh and fills the vertex and index buffer with the + * data. + * @note Subclasses should call prepareMesh() at the beginning of their + * implementation, unless the mesh is prepared another way (e.g. using + * MeshBuilder). + */ + virtual void build(IndexedMesh* mesh, Buffer* vertexBuffer) = 0; + + protected: + /** + * @brief Prepare the mesh for primitive data + * @param mesh Mesh to prepare + * + * Sets primitive type, vertex count and index count and type on the + * mesh using primitive(), vertexCount(), indexCount() and IndexType. + */ + void prepareMesh(IndexedMesh* mesh) const { + mesh->setPrimitive(primitive()); + mesh->setVertexCount(vertexCount()); + mesh->setIndexCount(indexCount()); + mesh->setIndexType(TypeTraits::glType()); + } +}; + +}} + +#endif diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt new file mode 100644 index 000000000..b44294797 --- /dev/null +++ b/src/Primitives/CMakeLists.txt @@ -0,0 +1,7 @@ +set(MagnumPrimitives_SRCS +) + +add_library(MagnumPrimitives STATIC ${MagnumPrimitives_SRCS}) +target_link_libraries(MagnumPrimitives Magnum) + +install(TARGETS MagnumPrimitives DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})