Browse Source

Merge branch 'master' into compatibility

Vladimír Vondruš 14 years ago
parent
commit
52e345dd9e
  1. 1
      src/Extensions.h
  2. 2
      src/Physics/CMakeLists.txt
  3. 10
      src/Physics/DebugDrawResourceManager.cpp
  4. 7
      src/Physics/DebugDrawResourceManager.h
  5. 70
      src/Physics/Implementation/AbstractBoxRenderer.cpp
  6. 40
      src/Physics/Implementation/AbstractBoxRenderer.h
  7. 32
      src/Physics/Implementation/AbstractShapeRenderer.cpp
  8. 50
      src/Physics/Implementation/AbstractShapeRenderer.h
  9. 38
      src/Physics/Implementation/AxisAlignedBoxRenderer.cpp
  10. 38
      src/Physics/Implementation/AxisAlignedBoxRenderer.h
  11. 44
      src/Physics/Implementation/BoxRenderer.cpp
  12. 19
      src/Physics/Implementation/BoxRenderer.h
  13. 25
      src/ResourceManager.h

1
src/Extensions.h

@ -51,6 +51,7 @@ namespace Extensions {
namespace GL { namespace GL {
#line 1 #line 1
namespace AMD { namespace AMD {
_extension(GL,AMD,vertex_shader_layer, GL210, None) // #417
_extension(GL,AMD,shader_trinary_minmax, GL210, None) // #428 _extension(GL,AMD,shader_trinary_minmax, GL210, None) // #428
} namespace APPLE { } namespace APPLE {
_extension(GL,APPLE,flush_buffer_range, GL210, GL300) // #321 _extension(GL,APPLE,flush_buffer_range, GL210, GL300) // #321

2
src/Physics/CMakeLists.txt

@ -12,7 +12,9 @@ set(MagnumPhysics_SRCS
ShapeGroup.cpp ShapeGroup.cpp
Sphere.cpp Sphere.cpp
Implementation/AbstractBoxRenderer.cpp
Implementation/AbstractDebugRenderer.cpp Implementation/AbstractDebugRenderer.cpp
Implementation/AxisAlignedBoxRenderer.cpp
Implementation/BoxRenderer.cpp) Implementation/BoxRenderer.cpp)
set(MagnumPhysics_HEADERS set(MagnumPhysics_HEADERS

10
src/Physics/DebugDrawResourceManager.cpp

@ -13,6 +13,8 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE
#include "DebugDrawResourceManager.h" #include "DebugDrawResourceManager.h"
#include "AbstractShaderProgram.h" #include "AbstractShaderProgram.h"
@ -21,9 +23,11 @@
#include "ResourceManager.h" #include "ResourceManager.h"
#include "Shaders/FlatShader.h" #include "Shaders/FlatShader.h"
#include "AbstractShape.h" #include "AbstractShape.h"
#include "AxisAlignedBox.h"
#include "Box.h" #include "Box.h"
#include "ObjectShape.h" #include "ObjectShape.h"
#include "ShapeGroup.h" #include "ShapeGroup.h"
#include "Implementation/AxisAlignedBoxRenderer.h"
#include "Implementation/BoxRenderer.h" #include "Implementation/BoxRenderer.h"
#include "Implementation/DebugRenderer.h" #include "Implementation/DebugRenderer.h"
@ -39,11 +43,13 @@ template<std::uint8_t dimensions> SceneGraph::Drawable<dimensions>* DebugDrawRes
return renderer; return renderer;
} }
template SceneGraph::Drawable<2>* DebugDrawResourceManager::createDebugRenderer(ObjectShape<2>* shape, ResourceKey options); template SceneGraph::Drawable<2> PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<2>* shape, ResourceKey options);
template SceneGraph::Drawable<3>* DebugDrawResourceManager::createDebugRenderer(ObjectShape<3>* shape, ResourceKey options); template SceneGraph::Drawable<3> PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<3>* shape, ResourceKey options);
void DebugDrawResourceManager::createDebugMesh(Implementation::DebugRenderer<2>* renderer, AbstractShape2D* shape) { void DebugDrawResourceManager::createDebugMesh(Implementation::DebugRenderer<2>* renderer, AbstractShape2D* shape) {
switch(shape->type()) { switch(shape->type()) {
case AbstractShape2D::Type::AxisAlignedBox:
renderer->addRenderer(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast<AxisAlignedBox2D*>(shape)));
case AbstractShape2D::Type::Box: case AbstractShape2D::Type::Box:
renderer->addRenderer(new Implementation::BoxRenderer<2>(*static_cast<Box2D*>(shape))); renderer->addRenderer(new Implementation::BoxRenderer<2>(*static_cast<Box2D*>(shape)));
break; break;

7
src/Physics/DebugDrawResourceManager.h

@ -21,7 +21,12 @@
#include "Magnum.h" #include "Magnum.h"
#include "Color.h" #include "Color.h"
#ifndef MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE
#define MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE
#endif
#include "ResourceManager.h" #include "ResourceManager.h"
#include "SceneGraph/SceneGraph.h" #include "SceneGraph/SceneGraph.h"
#include "magnumPhysicsVisibility.h" #include "magnumPhysicsVisibility.h"
@ -41,6 +46,8 @@ namespace Physics { namespace Implementation {
}} }}
#endif #endif
extern template ResourceManager<AbstractShaderProgram, Buffer, Mesh, Physics::Implementation::Options> PHYSICS_EXPORT *& ResourceManager<AbstractShaderProgram, Buffer, Mesh, Physics::Implementation::Options>::internalInstance();
namespace Physics { namespace Physics {
template<std::uint8_t> class AbstractShape; template<std::uint8_t> class AbstractShape;

70
src/Physics/Implementation/AbstractBoxRenderer.cpp

@ -0,0 +1,70 @@
/*
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 "AbstractBoxRenderer.h"
#include "Buffer.h"
#include "Physics/DebugDrawResourceManager.h"
#include "Primitives/Cube.h"
#include "Primitives/Square.h"
#include "Shaders/FlatShader.h"
namespace Magnum { namespace Physics { namespace Implementation {
namespace {
template<std::uint8_t> struct BoxMesh {};
template<> struct BoxMesh<2> {
static ResourceKey shader() { return {"shader2d"}; }
static ResourceKey key() { return {"box2d"}; }
static Mesh* mesh(Buffer* buffer) {
Primitives::Square square;
Mesh* mesh = new Mesh;
buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw);
return mesh->setPrimitive(square.primitive())
->setVertexCount(square.positions(0)->size())
->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position());
}
};
template<> struct BoxMesh<3> {
static ResourceKey shader() { return {"shader3d"}; }
static ResourceKey key() { return {"box3d"}; }
static Mesh* mesh(Buffer* buffer) {
Primitives::Cube cube;
Mesh* mesh = new Mesh;
buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw);
return mesh->setPrimitive(cube.primitive())
->setVertexCount(cube.positions(0)->size())
->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position());
}
};
}
template<std::uint8_t dimensions> AbstractBoxRenderer<dimensions>::AbstractBoxRenderer(): AbstractDebugRenderer<dimensions>(BoxMesh<dimensions>::shader(), BoxMesh<dimensions>::key()), buffer(DebugDrawResourceManager::instance()->get<Buffer>(BoxMesh<dimensions>::key())) {
if(!this->mesh) {
DebugDrawResourceManager::instance()->set(this->buffer.key(), new Buffer, ResourceDataState::Final, ResourcePolicy::Manual);
DebugDrawResourceManager::instance()->set<Mesh>(this->mesh.key(), BoxMesh<dimensions>::mesh(buffer), ResourceDataState::Final, ResourcePolicy::Manual);
}
}
template<std::uint8_t dimensions> AbstractBoxRenderer<dimensions>::~AbstractBoxRenderer() {}
template class AbstractBoxRenderer<2>;
template class AbstractBoxRenderer<3>;
}}}

40
src/Physics/Implementation/AbstractBoxRenderer.h

@ -0,0 +1,40 @@
#ifndef Magnum_Physics_Implementation_AbstractBoxRenderer_h
#define Magnum_Physics_Implementation_AbstractBoxRenderer_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 "AbstractDebugRenderer.h"
#include "magnumCompatibility.h"
namespace Magnum {
class Buffer;
namespace Physics { namespace Implementation {
template<std::uint8_t dimensions> class AbstractBoxRenderer: public AbstractDebugRenderer<dimensions> {
public:
AbstractBoxRenderer();
~AbstractBoxRenderer();
protected:
Resource<Buffer> buffer;
};
}}}
#endif

32
src/Physics/Implementation/AbstractShapeRenderer.cpp

@ -0,0 +1,32 @@
/*
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 "AbstractShapeRenderer.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> AbstractShapeRenderer<dimensions>::AbstractShapeRenderer(ResourceKey shader, ResourceKey mesh): shader(DebugDrawResourceManager::instance()->get<AbstractShaderProgram, Shaders::FlatShader<dimensions>>(shader)), mesh(DebugDrawResourceManager::instance()->get<Mesh>(mesh)) {}
template<std::uint8_t dimensions> AbstractShapeRenderer<dimensions>::~AbstractShapeRenderer() {}
template class AbstractShapeRenderer<2>;
template class AbstractShapeRenderer<3>;
}}}

50
src/Physics/Implementation/AbstractShapeRenderer.h

@ -0,0 +1,50 @@
#ifndef Magnum_Physics_Implementation_AbstractShapeRenderer_h
#define Magnum_Physics_Implementation_AbstractShapeRenderer_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"
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 AbstractShapeRenderer {
public:
AbstractShapeRenderer(ResourceKey shader, ResourceKey mesh);
virtual ~AbstractShapeRenderer();
virtual void draw(Resource<Options>& options, const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, GLfloat>* camera) = 0;
protected:
Resource<AbstractShaderProgram, Shaders::FlatShader<dimensions>> shader;
Resource<Mesh> mesh;
};
}}}
#endif

38
src/Physics/Implementation/AxisAlignedBoxRenderer.cpp

@ -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.
*/
#include "AxisAlignedBoxRenderer.h"
#include "Mesh.h"
#include "Physics/DebugDrawResourceManager.h"
#include "SceneGraph/AbstractCamera.h"
#include "Shaders/FlatShader.h"
namespace Magnum { namespace Physics { namespace Implementation {
template<std::uint8_t dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<Options>& options, const typename DimensionTraits<dimensions, GLfloat>::MatrixType&, typename SceneGraph::AbstractCamera<dimensions>* camera) {
typename DimensionTraits<dimensions>::MatrixType transformation =
DimensionTraits<dimensions>::MatrixType::translation(axisAlignedBox.transformedPosition())*
DimensionTraits<dimensions>::MatrixType::scaling(axisAlignedBox.transformedSize());
this->shader->setTransformationProjection(camera->projectionMatrix()*camera->cameraMatrix()*transformation)
->setColor(options->color)
->use();
this->mesh->draw();
}
template class AxisAlignedBoxRenderer<2>;
template class AxisAlignedBoxRenderer<3>;
}}}

38
src/Physics/Implementation/AxisAlignedBoxRenderer.h

@ -0,0 +1,38 @@
#ifndef Magnum_Physics_Implementation_AxisAlignedBoxRenderer_h
#define Magnum_Physics_Implementation_AxisAlignedBoxRenderer_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 "AbstractBoxRenderer.h"
#include "Physics/AxisAlignedBox.h"
#include "magnumCompatibility.h"
namespace Magnum { namespace Physics { namespace Implementation {
template<std::uint8_t dimensions> class AxisAlignedBoxRenderer: public AbstractBoxRenderer<dimensions> {
public:
inline AxisAlignedBoxRenderer(AxisAlignedBox<dimensions>& axisAlignedBox): axisAlignedBox(axisAlignedBox) {}
void draw(Resource<Options>& options, const typename DimensionTraits<dimensions>::MatrixType& transformation, typename SceneGraph::AbstractCamera<dimensions>* camera) override;
private:
AxisAlignedBox<dimensions>& axisAlignedBox;
};
}}}
#endif

44
src/Physics/Implementation/BoxRenderer.cpp

@ -15,55 +15,13 @@
#include "BoxRenderer.h" #include "BoxRenderer.h"
#include "Buffer.h" #include "Mesh.h"
#include "Physics/Box.h"
#include "Physics/DebugDrawResourceManager.h" #include "Physics/DebugDrawResourceManager.h"
#include "Primitives/Cube.h"
#include "Primitives/Square.h"
#include "SceneGraph/AbstractCamera.h" #include "SceneGraph/AbstractCamera.h"
#include "Shaders/FlatShader.h" #include "Shaders/FlatShader.h"
namespace Magnum { namespace Physics { namespace Implementation { namespace Magnum { namespace Physics { namespace Implementation {
namespace {
template<std::uint8_t> struct BoxMesh {};
template<> struct BoxMesh<2> {
static ResourceKey shader() { return {"shader2d"}; }
static ResourceKey key() { return {"box2d"}; }
static Mesh* mesh(Buffer* buffer) {
Primitives::Square square;
Mesh* mesh = new Mesh;
buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw);
return mesh->setPrimitive(square.primitive())
->setVertexCount(square.positions(0)->size())
->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position());
}
};
template<> struct BoxMesh<3> {
static ResourceKey shader() { return {"shader3d"}; }
static ResourceKey key() { return {"box3d"}; }
static Mesh* mesh(Buffer* buffer) {
Primitives::Cube cube;
Mesh* mesh = new Mesh;
buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw);
return mesh->setPrimitive(cube.primitive())
->setVertexCount(cube.positions(0)->size())
->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position());
}
};
}
template<std::uint8_t dimensions> BoxRenderer<dimensions>::BoxRenderer(Box<dimensions>& box): AbstractDebugRenderer<dimensions>(BoxMesh<dimensions>::shader(), BoxMesh<dimensions>::key()), buffer(DebugDrawResourceManager::instance()->get<Buffer>(BoxMesh<dimensions>::key())), box(box) {
if(!this->mesh) {
DebugDrawResourceManager::instance()->set(this->buffer.key(), new Buffer, ResourceDataState::Final, ResourcePolicy::Manual);
DebugDrawResourceManager::instance()->set<Mesh>(this->mesh.key(), BoxMesh<dimensions>::mesh(buffer), ResourceDataState::Final, ResourcePolicy::Manual);
}
}
template<std::uint8_t dimensions> void BoxRenderer<dimensions>::draw(Resource<Options>& options, const typename DimensionTraits<dimensions, GLfloat>::MatrixType&, typename SceneGraph::AbstractCamera<dimensions>* camera) { template<std::uint8_t dimensions> void BoxRenderer<dimensions>::draw(Resource<Options>& options, const typename DimensionTraits<dimensions, GLfloat>::MatrixType&, typename SceneGraph::AbstractCamera<dimensions>* camera) {
this->shader->setTransformationProjection(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) this->shader->setTransformationProjection(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation())
->setColor(options->color) ->setColor(options->color)

19
src/Physics/Implementation/BoxRenderer.h

@ -15,28 +15,21 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "AbstractDebugRenderer.h" #include "AbstractBoxRenderer.h"
#include "magnumCompatibility.h" #include "Physics/Box.h"
namespace Magnum {
class Buffer;
namespace Physics { #include "magnumCompatibility.h"
template<std::uint8_t> class Box;
namespace Implementation { namespace Magnum { namespace Physics { namespace Implementation {
template<std::uint8_t dimensions> class BoxRenderer: public AbstractDebugRenderer<dimensions> { template<std::uint8_t dimensions> class BoxRenderer: public AbstractBoxRenderer<dimensions> {
public: public:
BoxRenderer(Box<dimensions>& box); inline BoxRenderer(Box<dimensions>& box): box(box) {}
void draw(Resource<Options>& options, const typename DimensionTraits<dimensions>::MatrixType& transformation, typename SceneGraph::AbstractCamera<dimensions, GLfloat>* camera) override; void draw(Resource<Options>& options, const typename DimensionTraits<dimensions>::MatrixType& transformation, typename SceneGraph::AbstractCamera<dimensions, GLfloat>* camera) override;
private: private:
Resource<Buffer> buffer;
Box<dimensions>& box; Box<dimensions>& box;
}; };

25
src/ResourceManager.h

@ -461,7 +461,10 @@ cube->draw();
template<class... Types> class ResourceManager: protected Implementation::ResourceManagerData<Types>... { template<class... Types> class ResourceManager: protected Implementation::ResourceManagerData<Types>... {
public: public:
/** @brief Global instance */ /** @brief Global instance */
inline static ResourceManager<Types...>* instance() { return _instance; } inline static ResourceManager<Types...>* instance() {
CORRADE_ASSERT(internalInstance(), "ResourceManager::instance(): no instance exists", nullptr);
return internalInstance();
}
/** /**
* @brief Constructor * @brief Constructor
@ -472,8 +475,8 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
* @see instance() * @see instance()
*/ */
inline ResourceManager() { inline ResourceManager() {
CORRADE_ASSERT(!_instance, "ResourceManager: another instance is already created!", ); CORRADE_ASSERT(!internalInstance(), "ResourceManager::ResourceManager(): another instance is already created", );
_instance = this; internalInstance() = this;
} }
/** /**
@ -482,7 +485,10 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
* Sets global instance pointer to `nullptr`. * Sets global instance pointer to `nullptr`.
* @see instance() * @see instance()
*/ */
inline ~ResourceManager() { _instance = nullptr; } inline ~ResourceManager() {
CORRADE_INTERNAL_ASSERT(internalInstance() == this);
internalInstance() = nullptr;
}
/** @brief Count of resources of given type */ /** @brief Count of resources of given type */
template<class T> inline std::size_t count() { template<class T> inline std::size_t count() {
@ -567,16 +573,21 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
} }
inline void freeInternal() const {} inline void freeInternal() const {}
static ResourceManager<Types...>* _instance; static ResourceManager<Types...>*& internalInstance();
}; };
#ifndef MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE
template<class ...Types> ResourceManager<Types...>*& ResourceManager<Types...>::internalInstance() {
static ResourceManager<Types...>* _instance(nullptr);
return _instance;
}
#endif
/** @debugoperator{Magnum::ResourceKey} */ /** @debugoperator{Magnum::ResourceKey} */
template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) {
return debug << static_cast<const Corrade::Utility::HashDigest<sizeof(std::size_t)>&>(value); return debug << static_cast<const Corrade::Utility::HashDigest<sizeof(std::size_t)>&>(value);
} }
template<class ...Types> ResourceManager<Types...>* ResourceManager<Types...>::_instance(nullptr);
} }
#endif #endif

Loading…
Cancel
Save