mirror of https://github.com/mosra/magnum.git
Browse Source
Also cleaned up the code and split renderer creation from resource manager.pull/7/head
32 changed files with 456 additions and 407 deletions
@ -0,0 +1,24 @@ |
|||||||
|
set(MagnumDebugTools_SRCS |
||||||
|
Profiler.cpp |
||||||
|
ResourceManager.cpp |
||||||
|
ShapeRenderer.cpp |
||||||
|
|
||||||
|
Implementation/AbstractBoxRenderer.cpp |
||||||
|
Implementation/AbstractShapeRenderer.cpp |
||||||
|
Implementation/AxisAlignedBoxRenderer.cpp |
||||||
|
Implementation/BoxRenderer.cpp) |
||||||
|
|
||||||
|
set(MagnumDebugTools_HEADERS |
||||||
|
DebugTools.h |
||||||
|
Profiler.h |
||||||
|
ResourceManager.h |
||||||
|
ShapeRenderer.h |
||||||
|
|
||||||
|
magnumDebugToolsVisibility.h) |
||||||
|
|
||||||
|
add_library(MagnumDebugTools SHARED ${MagnumDebugTools_SRCS}) |
||||||
|
|
||||||
|
target_link_libraries(MagnumDebugTools Magnum MagnumPhysics MagnumPrimitives MagnumSceneGraph MagnumShaders) |
||||||
|
|
||||||
|
install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) |
||||||
|
install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
#ifndef Magnum_DebugTools_DebugTools_h |
||||||
|
#define Magnum_DebugTools_DebugTools_h |
||||||
|
/*
|
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Forward declarations for Magnum::DebugTools namespace |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <cstdint> |
||||||
|
|
||||||
|
namespace Magnum { namespace DebugTools { |
||||||
|
|
||||||
|
class Profiler; |
||||||
|
class ResourceManager; |
||||||
|
template<std::uint8_t> class ShapeRenderer; |
||||||
|
struct ShapeRendererOptions; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
/*
|
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
#define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE |
||||||
|
|
||||||
|
#include "ResourceManager.h" |
||||||
|
|
||||||
|
#include "Buffer.h" |
||||||
|
#include "Mesh.h" |
||||||
|
#include "Shaders/FlatShader.h" |
||||||
|
#include "ShapeRenderer.h" |
||||||
|
|
||||||
|
namespace Magnum { |
||||||
|
|
||||||
|
template class ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ShapeRendererOptions>; |
||||||
|
|
||||||
|
namespace DebugTools { |
||||||
|
|
||||||
|
ResourceManager::ResourceManager() { |
||||||
|
setFallback(new ShapeRendererOptions); |
||||||
|
set<AbstractShaderProgram>("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); |
||||||
|
} |
||||||
|
|
||||||
|
ResourceManager::~ResourceManager() {} |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
#ifndef Magnum_DebugTools_ResourceManager_h |
||||||
|
#define Magnum_DebugTools_ResourceManager_h |
||||||
|
/*
|
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class Magnum::DebugTools::ResourceManager |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum.h" |
||||||
|
|
||||||
|
#ifndef MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE |
||||||
|
#define MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE |
||||||
|
#endif |
||||||
|
#include "../ResourceManager.h" |
||||||
|
|
||||||
|
#include "SceneGraph/SceneGraph.h" |
||||||
|
#include "Physics/Physics.h" |
||||||
|
#include "DebugTools.h" |
||||||
|
|
||||||
|
#include "magnumDebugToolsVisibility.h" |
||||||
|
|
||||||
|
namespace Magnum { |
||||||
|
|
||||||
|
extern template ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ShapeRendererOptions> MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ShapeRendererOptions>::internalInstance(); |
||||||
|
|
||||||
|
namespace DebugTools { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief %Resource manager for debug tools |
||||||
|
|
||||||
|
Stores various data used by debug renderers. |
||||||
|
*/ |
||||||
|
class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ShapeRendererOptions> { |
||||||
|
public: |
||||||
|
explicit ResourceManager(); |
||||||
|
~ResourceManager(); |
||||||
|
}; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,75 @@ |
|||||||
|
/*
|
||||||
|
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 "ShapeRenderer.h" |
||||||
|
|
||||||
|
#include "ResourceManager.h" |
||||||
|
#include "Physics/AbstractShape.h" |
||||||
|
#include "Physics/AxisAlignedBox.h" |
||||||
|
#include "Physics/Box.h" |
||||||
|
#include "Physics/ObjectShape.h" |
||||||
|
#include "Physics/ShapeGroup.h" |
||||||
|
|
||||||
|
#include "Implementation/AxisAlignedBoxRenderer.h" |
||||||
|
#include "Implementation/BoxRenderer.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace DebugTools { |
||||||
|
|
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
namespace Implementation { |
||||||
|
|
||||||
|
template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractShape<2>* shape) { |
||||||
|
switch(shape->type()) { |
||||||
|
case Physics::AbstractShape2D::Type::AxisAlignedBox: |
||||||
|
renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast<Physics::AxisAlignedBox2D*>(shape))); |
||||||
|
case Physics::AbstractShape2D::Type::Box: |
||||||
|
renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast<Physics::Box2D*>(shape))); |
||||||
|
break; |
||||||
|
case Physics::AbstractShape2D::Type::ShapeGroup: { |
||||||
|
Physics::ShapeGroup2D* group = static_cast<Physics::ShapeGroup2D*>(shape); |
||||||
|
if(group->first()) createDebugMesh(renderer, group->first()); |
||||||
|
if(group->second()) createDebugMesh(renderer, group->second()); |
||||||
|
} break; |
||||||
|
default: |
||||||
|
Warning() << "DebugTools::ShapeRenderer2D::createShapeRenderer(): type" << shape->type() << "not implemented"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
template<> void createDebugMesh(ShapeRenderer<3>*, Physics::AbstractShape<3>* shape) { |
||||||
|
switch(shape->type()) { |
||||||
|
default: |
||||||
|
Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
template<std::uint8_t dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Physics::ObjectShape<dimensions>* shape, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(shape->object(), drawables), options(ResourceManager::instance()->get<ShapeRendererOptions>(options)) { |
||||||
|
Implementation::createDebugMesh(this, shape->shape()); |
||||||
|
} |
||||||
|
|
||||||
|
template<std::uint8_t dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() { |
||||||
|
for(auto i: renderers) delete i; |
||||||
|
} |
||||||
|
|
||||||
|
template<std::uint8_t dimensions> void ShapeRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) { |
||||||
|
for(auto i: renderers) i->draw(options, transformationMatrix, camera); |
||||||
|
} |
||||||
|
|
||||||
|
template class ShapeRenderer<2>; |
||||||
|
template class ShapeRenderer<3>; |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,119 @@ |
|||||||
|
#ifndef Magnum_DebugTools_ShapeRenderer_h |
||||||
|
#define Magnum_DebugTools_ShapeRenderer_h |
||||||
|
/*
|
||||||
|
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 "Color.h" |
||||||
|
#include "Resource.h" |
||||||
|
#include "SceneGraph/Drawable.h" |
||||||
|
#include "Physics/Physics.h" |
||||||
|
|
||||||
|
#include "magnumDebugToolsVisibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace DebugTools { |
||||||
|
|
||||||
|
template<std::uint8_t> class ShapeRenderer; |
||||||
|
|
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
namespace Implementation { |
||||||
|
template<std::uint8_t> class AbstractShapeRenderer; |
||||||
|
|
||||||
|
template<std::uint8_t dimensions> void createDebugMesh(ShapeRenderer<dimensions>* renderer, Physics::AbstractShape<dimensions>* shape); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Shape renderer options |
||||||
|
|
||||||
|
See ShapeRenderer documentation for more information. |
||||||
|
*/ |
||||||
|
struct ShapeRendererOptions { |
||||||
|
Color3<> color; /**< @brief Color */ |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Shape renderer |
||||||
|
|
||||||
|
Creates renderers for object collision shape. |
||||||
|
|
||||||
|
@section ShapeRenderer-usage Basic usage |
||||||
|
|
||||||
|
ResourceManager must be instanced for the whole lifetime of debug |
||||||
|
renderers. You can specify options via Options struct - add it to the manager |
||||||
|
and then create debug renderer with the same options key. This way you can |
||||||
|
easily share the same options with more renderers. If no options for given key |
||||||
|
exist, default is used. |
||||||
|
|
||||||
|
Example code: |
||||||
|
@code |
||||||
|
// Instance the manager at first
|
||||||
|
DebugTools::ResourceManager manager; |
||||||
|
|
||||||
|
// Group of drawables, preferrably dedicated for debug renderers, so you can
|
||||||
|
// easily enable or disable debug draw
|
||||||
|
SceneGraph::DrawableGroup2D debugDrawables; |
||||||
|
|
||||||
|
// Create some options
|
||||||
|
auto o = new DebugTools::ShapeRendererOptions { |
||||||
|
{1.0f, 0.0f, 0.0f} // Red color
|
||||||
|
}; |
||||||
|
manager->set<DebugTools::ShapeRendererOptions>("red", o, ResourceDataState::Final, ResourcePolicy::Persistent); |
||||||
|
|
||||||
|
// Create debug renderer for given shape, use "red" options for it
|
||||||
|
Physics::ObjectShape2D* shape; |
||||||
|
debugDrawables.add(new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables)); |
||||||
|
@endcode |
||||||
|
|
||||||
|
@see ShapeRenderer2D, ShapeRenderer3D |
||||||
|
*/ |
||||||
|
template<std::uint8_t dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable<dimensions> { |
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
friend void Implementation::createDebugMesh<>(ShapeRenderer<dimensions>*, Physics::AbstractShape<dimensions>*); |
||||||
|
#endif |
||||||
|
|
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param shape Shape for which to create debug renderer |
||||||
|
* @param options Options resource key. See |
||||||
|
* @ref ShapeRenderer-usage "class documentation" for more |
||||||
|
* information. |
||||||
|
* @param drawables Drawable group |
||||||
|
* |
||||||
|
* @attention @p shape must be available for the whole lifetime of |
||||||
|
* this class |
||||||
|
*/ |
||||||
|
explicit ShapeRenderer(Physics::ObjectShape<dimensions>* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr); |
||||||
|
|
||||||
|
~ShapeRenderer(); |
||||||
|
|
||||||
|
protected: |
||||||
|
/** @todoc Remove GLfloat when Doxygen properly treats this as override */ |
||||||
|
void draw(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, GLfloat>* camera) override; |
||||||
|
|
||||||
|
private: |
||||||
|
Resource<ShapeRendererOptions> options; |
||||||
|
std::vector<Implementation::AbstractShapeRenderer<dimensions>*> renderers; |
||||||
|
}; |
||||||
|
|
||||||
|
/** @brief Two-dimensional shape renderer */ |
||||||
|
typedef ShapeRenderer<2> ShapeRenderer2D; |
||||||
|
|
||||||
|
/** @brief Three-dimensional shape renderer */ |
||||||
|
typedef ShapeRenderer<3> ShapeRenderer3D; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
#ifndef Magnum_DebugTools_magnumDebugToolsVisibility_h |
||||||
|
#define Magnum_DebugTools_magnumDebugToolsVisibility_h |
||||||
|
/*
|
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifdef _WIN32 |
||||||
|
#ifdef MagnumDebugTools_EXPORTS |
||||||
|
#define MAGNUM_DEBUGTOOLS_EXPORT __declspec(dllexport) |
||||||
|
#else |
||||||
|
#define MAGNUM_DEBUGTOOLS_EXPORT __declspec(dllimport) |
||||||
|
#endif |
||||||
|
#else |
||||||
|
#define MAGNUM_DEBUGTOOLS_EXPORT __attribute__ ((visibility ("default"))) |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
@ -1,76 +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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE |
|
||||||
|
|
||||||
#include "DebugDrawResourceManager.h" |
|
||||||
|
|
||||||
#include "AbstractShaderProgram.h" |
|
||||||
#include "Buffer.h" |
|
||||||
#include "Mesh.h" |
|
||||||
#include "ResourceManager.h" |
|
||||||
#include "Shaders/FlatShader.h" |
|
||||||
#include "AbstractShape.h" |
|
||||||
#include "AxisAlignedBox.h" |
|
||||||
#include "Box.h" |
|
||||||
#include "ObjectShape.h" |
|
||||||
#include "ShapeGroup.h" |
|
||||||
#include "Implementation/AxisAlignedBoxRenderer.h" |
|
||||||
#include "Implementation/BoxRenderer.h" |
|
||||||
#include "Implementation/DebugRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { |
|
||||||
|
|
||||||
template class ResourceManager<AbstractShaderProgram, Buffer, Mesh, Physics::Implementation::Options>; |
|
||||||
|
|
||||||
namespace Physics { |
|
||||||
|
|
||||||
template<std::uint8_t dimensions> SceneGraph::Drawable<dimensions>* DebugDrawResourceManager::createDebugRenderer(ObjectShape<dimensions>* shape, ResourceKey options) { |
|
||||||
Implementation::DebugRenderer<dimensions>* renderer = new Implementation::DebugRenderer<dimensions>(shape->object(), instance()->get<Options>(options)); |
|
||||||
createDebugMesh(renderer, shape->shape()); |
|
||||||
return renderer; |
|
||||||
} |
|
||||||
|
|
||||||
template SceneGraph::Drawable<2> MAGNUM_PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<2>* shape, ResourceKey options); |
|
||||||
template SceneGraph::Drawable<3> MAGNUM_PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<3>* shape, ResourceKey options); |
|
||||||
|
|
||||||
void DebugDrawResourceManager::createDebugMesh(Implementation::DebugRenderer<2>* renderer, AbstractShape2D* shape) { |
|
||||||
switch(shape->type()) { |
|
||||||
case AbstractShape2D::Type::AxisAlignedBox: |
|
||||||
renderer->addRenderer(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast<AxisAlignedBox2D*>(shape))); |
|
||||||
case AbstractShape2D::Type::Box: |
|
||||||
renderer->addRenderer(new Implementation::BoxRenderer<2>(*static_cast<Box2D*>(shape))); |
|
||||||
break; |
|
||||||
case AbstractShape2D::Type::ShapeGroup: { |
|
||||||
ShapeGroup2D* group = static_cast<ShapeGroup2D*>(shape); |
|
||||||
if(group->first()) createDebugMesh(renderer, group->first()); |
|
||||||
if(group->second()) createDebugMesh(renderer, group->second()); |
|
||||||
break; |
|
||||||
} |
|
||||||
default: |
|
||||||
Warning() << "Physics::DebugDrawResourceManager::createDebugRenderer(): type" << shape->type() << "not implemented"; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DebugDrawResourceManager::createDebugMesh(Implementation::DebugRenderer<3>*, AbstractShape3D*) {} |
|
||||||
|
|
||||||
DebugDrawResourceManager::DebugDrawResourceManager() { |
|
||||||
setFallback<Options>(new Options); |
|
||||||
set<AbstractShaderProgram>("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); |
|
||||||
} |
|
||||||
|
|
||||||
DebugDrawResourceManager::~DebugDrawResourceManager() {} |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,117 +0,0 @@ |
|||||||
#ifndef Magnum_Physics_DebugDrawResourceManager_h |
|
||||||
#define Magnum_Physics_DebugDrawResourceManager_h |
|
||||||
/*
|
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
* @brief Class Magnum::Physics::DebugDrawResourceManager |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum.h" |
|
||||||
#include "Color.h" |
|
||||||
|
|
||||||
#ifndef MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE |
|
||||||
#define MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE |
|
||||||
#endif |
|
||||||
#include "ResourceManager.h" |
|
||||||
|
|
||||||
#include "SceneGraph/SceneGraph.h" |
|
||||||
#include "Physics.h" |
|
||||||
|
|
||||||
#include "magnumPhysicsVisibility.h" |
|
||||||
|
|
||||||
namespace Magnum { |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
namespace Physics { namespace Implementation { |
|
||||||
struct Options { |
|
||||||
Color3<> color; |
|
||||||
}; |
|
||||||
template<std::uint8_t> class DebugRenderer; |
|
||||||
}} |
|
||||||
#endif |
|
||||||
|
|
||||||
extern template ResourceManager<AbstractShaderProgram, Buffer, Mesh, Physics::Implementation::Options> MAGNUM_PHYSICS_EXPORT *& ResourceManager<AbstractShaderProgram, Buffer, Mesh, Physics::Implementation::Options>::internalInstance(); |
|
||||||
|
|
||||||
namespace Physics { |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief %Resource manager for physics debug draw |
|
||||||
|
|
||||||
Can create objects which draw object collision shape for debugging purposes. |
|
||||||
|
|
||||||
@section DebugDrawResourceManager-usage Basic usage |
|
||||||
The manager must be instanced for the whole lifetime of debug draw objects. |
|
||||||
To create debug renderers, call createDebugRenderer() and add the resulting |
|
||||||
drawable to some group. You can specify options via Options struct - add it to |
|
||||||
the manager and then create debug renderer with the same options key. This way |
|
||||||
you can easily share the same options with more renderers. If no options for |
|
||||||
given key exist, default is used. |
|
||||||
|
|
||||||
Example code: |
|
||||||
@code |
|
||||||
// Group of drawables,preferrably dedicated for debug renderers, so you can
|
|
||||||
// easily enable or disable debug draw
|
|
||||||
DrawableGroup2D group; |
|
||||||
|
|
||||||
// Instance the manager at first
|
|
||||||
DebugDrawResourceManager manager; |
|
||||||
|
|
||||||
// Create some options
|
|
||||||
auto o = new DebugDrawResourceManager::Options { |
|
||||||
{1.0f, 0.0f, 0.0f} // Red color
|
|
||||||
}; |
|
||||||
manager->set<DebugDrawResourceManager::Options>("red", o, ResourceDataState::Final, ResourcePolicy::Persistent); |
|
||||||
|
|
||||||
// Create debug renderer for given shape, use "red" options for it. Don't
|
|
||||||
// forget to add it to some drawable group.
|
|
||||||
ObjectShape2D* shape; |
|
||||||
group.add(DebugDrawResourceManager::createDebugRenderer(shape, "red")); |
|
||||||
@endcode |
|
||||||
*/ |
|
||||||
class MAGNUM_PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager<AbstractShaderProgram, Buffer, Mesh, Physics::Implementation::Options> { |
|
||||||
public: |
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
/** @brief %Options */ |
|
||||||
struct Options { |
|
||||||
Color3<> color; /**< @brief Color */ |
|
||||||
}; |
|
||||||
#else |
|
||||||
typedef Implementation::Options Options; |
|
||||||
#endif |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create debug renderer for given shape |
|
||||||
* @param shape Shape for which to create debug renderer |
|
||||||
* @param options Options resource key. See |
|
||||||
* @ref DebugDrawResourceManager-usage "class documentation" for |
|
||||||
* more information. |
|
||||||
* |
|
||||||
* Returned drawable is not part of any group, you have to add it to |
|
||||||
* one yourself. |
|
||||||
*/ |
|
||||||
template<std::uint8_t dimensions> static SceneGraph::Drawable<dimensions>* createDebugRenderer(ObjectShape<dimensions>* shape, ResourceKey options = ResourceKey()); |
|
||||||
|
|
||||||
explicit DebugDrawResourceManager(); |
|
||||||
~DebugDrawResourceManager(); |
|
||||||
|
|
||||||
private: |
|
||||||
static void createDebugMesh(Implementation::DebugRenderer<2>* renderer, AbstractShape2D* shape); |
|
||||||
static void createDebugMesh(Implementation::DebugRenderer<3>* renderer, AbstractShape3D* shape); |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,32 +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 "AbstractDebugRenderer.h" |
|
||||||
|
|
||||||
#include "AbstractShaderProgram.h" |
|
||||||
#include "Mesh.h" |
|
||||||
#include "Physics/DebugDrawResourceManager.h" |
|
||||||
#include "Shaders/FlatShader.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Physics { namespace Implementation { |
|
||||||
|
|
||||||
template<std::uint8_t dimensions> AbstractDebugRenderer<dimensions>::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh): shader(DebugDrawResourceManager::instance()->get<AbstractShaderProgram, Shaders::FlatShader<dimensions>>(shader)), mesh(DebugDrawResourceManager::instance()->get<Mesh>(mesh)) {} |
|
||||||
|
|
||||||
template<std::uint8_t dimensions> AbstractDebugRenderer<dimensions>::~AbstractDebugRenderer() {} |
|
||||||
|
|
||||||
template class AbstractDebugRenderer<2>; |
|
||||||
template class AbstractDebugRenderer<3>; |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,42 +0,0 @@ |
|||||||
#ifndef Magnum_Physics_Implementation_AbstractDebugRenderer_h |
|
||||||
#define Magnum_Physics_Implementation_AbstractDebugRenderer_h |
|
||||||
/*
|
|
||||||
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 "DimensionTraits.h" |
|
||||||
#include "ResourceManager.h" |
|
||||||
#include "SceneGraph/SceneGraph.h" |
|
||||||
#include "Shaders/Shaders.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Physics { namespace Implementation { |
|
||||||
|
|
||||||
struct Options; |
|
||||||
|
|
||||||
template<std::uint8_t dimensions> class AbstractDebugRenderer { |
|
||||||
public: |
|
||||||
AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh); |
|
||||||
|
|
||||||
virtual ~AbstractDebugRenderer(); |
|
||||||
|
|
||||||
virtual void draw(Resource<Options>& options, const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) = 0; |
|
||||||
|
|
||||||
protected: |
|
||||||
Resource<AbstractShaderProgram, Shaders::FlatShader<dimensions>> shader; |
|
||||||
Resource<Mesh> mesh; |
|
||||||
}; |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,58 +0,0 @@ |
|||||||
#ifndef Magnum_Physics_Implementation_DebugRenderer_h |
|
||||||
#define Magnum_Physics_Implementation_DebugRenderer_h |
|
||||||
/*
|
|
||||||
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 "ResourceManager.h" |
|
||||||
#include "SceneGraph/Drawable.h" |
|
||||||
#include "AbstractDebugRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { |
|
||||||
|
|
||||||
class AbstractShaderProgram; |
|
||||||
class Mesh; |
|
||||||
|
|
||||||
namespace Shaders { |
|
||||||
template<std::uint8_t> class FlatShader; |
|
||||||
} |
|
||||||
|
|
||||||
namespace Physics { namespace Implementation { |
|
||||||
|
|
||||||
struct Options; |
|
||||||
|
|
||||||
template<std::uint8_t dimensions> class DebugRenderer: public SceneGraph::Drawable<dimensions> { |
|
||||||
public: |
|
||||||
DebugRenderer(SceneGraph::AbstractObject<dimensions>* object, Resource<Options>&& options): SceneGraph::Drawable<dimensions>(object), options(options) {} |
|
||||||
|
|
||||||
inline ~DebugRenderer() { |
|
||||||
for(auto i: renderers) delete i; |
|
||||||
} |
|
||||||
|
|
||||||
inline void addRenderer(AbstractDebugRenderer<dimensions>* renderer) { |
|
||||||
renderers.push_back(renderer); |
|
||||||
} |
|
||||||
|
|
||||||
inline void draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) override { |
|
||||||
for(auto i: renderers) i->draw(options, transformationMatrix, camera); |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
Resource<Options> options; |
|
||||||
std::vector<AbstractDebugRenderer<dimensions>*> renderers; |
|
||||||
}; |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
Loading…
Reference in new issue