Browse Source

Base class for primitives.

vectorfields
Vladimír Vondruš 15 years ago
parent
commit
8c7486a13d
  1. 11
      modules/FindMagnum.cmake
  2. 1
      src/CMakeLists.txt
  3. 86
      src/Primitives/AbstractPrimitive.h
  4. 7
      src/Primitives/CMakeLists.txt

11
modules/FindMagnum.cmake

@ -2,9 +2,10 @@
# #
# This module depends on Corrade and additionally defines: # This module depends on Corrade and additionally defines:
# #
# MAGNUM_FOUND - True if Magnum library is found # MAGNUM_FOUND - True if Magnum library is found
# MAGNUM_INCLUDE_DIR - Include dir for Magnum # MAGNUM_INCLUDE_DIR - Include dir for Magnum
# MAGNUM_LIBRARY - Magnum library # MAGNUM_LIBRARY - Magnum library
# MAGNUM_PRIMITIVES_LIBRARY - Library with primitives
# #
# MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory # MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory
# MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake modules # MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake modules
@ -13,7 +14,7 @@
find_package(Corrade REQUIRED) 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 # Already in cache
set(MAGNUM_FOUND TRUE) set(MAGNUM_FOUND TRUE)
@ -21,6 +22,7 @@ if (MAGNUM_INCLUDE_DIR AND MAGNUM_LIBRARY)
else() else()
# Libraries # Libraries
find_library(MAGNUM_LIBRARY Magnum) find_library(MAGNUM_LIBRARY Magnum)
find_library(MAGNUM_PRIMITIVES_LIBRARY MagnumPrimitives)
# Paths # Paths
find_path(MAGNUM_INCLUDE_DIR find_path(MAGNUM_INCLUDE_DIR
@ -32,6 +34,7 @@ else()
find_package_handle_standard_args("Magnum" DEFAULT_MSG find_package_handle_standard_args("Magnum" DEFAULT_MSG
MAGNUM_INCLUDE_DIR MAGNUM_INCLUDE_DIR
MAGNUM_LIBRARY MAGNUM_LIBRARY
MAGNUM_PRIMITIVES_LIBRARY
) )
endif() endif()

1
src/CMakeLists.txt

@ -6,6 +6,7 @@ find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
add_subdirectory(Math) add_subdirectory(Math)
add_subdirectory(Primitives)
set(Magnum_SRCS set(Magnum_SRCS
Object.cpp Object.cpp

86
src/Primitives/AbstractPrimitive.h

@ -0,0 +1,86 @@
#ifndef Magnum_Primitives_AbstractPrimitive_h
#define Magnum_Primitives_AbstractPrimitive_h
/*
Copyright © 2010, 2011 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.
*/
/** @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 _IndexType> 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<IndexType>::glType());
}
};
}}
#endif

7
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})
Loading…
Cancel
Save