diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ab022437..f307a54d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EV cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) -cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) option(WITH_GLXWINDOWCONTEXT "Build GlxWindowContext library" OFF) cmake_dependent_option(WITH_XEGLWINDOWCONTEXT "Build XEglWindowContext library" OFF "TARGET_GLES" OFF) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 1e6e4e97f..76175adcc 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -16,8 +16,8 @@ # libraries. Additional dependencies are specified by the components. The # optional components are: # MeshTools - MeshTools library -# Physics - Physics library (depends on Primitives and SceneGraph -# components) +# Physics - Physics library (depends on Primitives, SceneGraph and +# Shaders components) # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 837b068a4..1dc1bf4cf 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -1,7 +1,3 @@ -corrade_add_resource(MagnumPhysics_RCS MagnumPhysics - Implementation/ShapeShader2D.vert ALIAS ShapeShader2D.vert - Implementation/ShapeShader2D.frag ALIAS ShapeShader2D.frag) - set(MagnumPhysics_SRCS AbstractShape.cpp AxisAlignedBox.cpp @@ -17,9 +13,7 @@ set(MagnumPhysics_SRCS Sphere.cpp Implementation/AbstractDebugRenderer.cpp - Implementation/BoxRenderer.cpp - Implementation/ShapeShader.cpp - ${MagnumPhysics_RCS}) + Implementation/BoxRenderer.cpp) set(MagnumPhysics_HEADERS AbstractShape.h AxisAlignedBox.h @@ -39,7 +33,7 @@ set(MagnumPhysics_HEADERS add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS}) -target_link_libraries(MagnumPhysics Magnum MagnumPrimitives MagnumSceneGraph) +target_link_libraries(MagnumPhysics Magnum MagnumPrimitives MagnumSceneGraph MagnumShaders) install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp index 539e677f8..f048a5816 100644 --- a/src/Physics/DebugDrawResourceManager.cpp +++ b/src/Physics/DebugDrawResourceManager.cpp @@ -18,13 +18,13 @@ #include "AbstractShaderProgram.h" #include "Buffer.h" #include "Mesh.h" +#include "Shaders/FlatShader.h" #include "AbstractShape.h" #include "Box.h" #include "ShapedObject.h" #include "ShapeGroup.h" #include "Implementation/AbstractDebugRenderer.h" #include "Implementation/BoxRenderer.h" -#include "Implementation/ShapeShader.h" namespace Magnum { @@ -52,7 +52,7 @@ SceneGraph::Object2D* DebugDrawResourceManager::createDebugMesh(SceneGraph::Obje DebugDrawResourceManager::DebugDrawResourceManager() { setFallback(new Options); - set("shader2d", new Implementation::ShapeShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); + set("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); } DebugDrawResourceManager::~DebugDrawResourceManager() {} diff --git a/src/Physics/Implementation/AbstractDebugRenderer.cpp b/src/Physics/Implementation/AbstractDebugRenderer.cpp index 76bcfcf22..63235f8bb 100644 --- a/src/Physics/Implementation/AbstractDebugRenderer.cpp +++ b/src/Physics/Implementation/AbstractDebugRenderer.cpp @@ -18,11 +18,11 @@ #include "AbstractShaderProgram.h" #include "Mesh.h" #include "Physics/DebugDrawResourceManager.h" -#include "ShapeShader.h" +#include "Shaders/FlatShader.h" namespace Magnum { namespace Physics { namespace Implementation { -template AbstractDebugRenderer::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)), options(DebugDrawResourceManager::instance()->get(options)) {} +template AbstractDebugRenderer::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)), options(DebugDrawResourceManager::instance()->get(options)) {} template class AbstractDebugRenderer<2>; template class AbstractDebugRenderer<3>; diff --git a/src/Physics/Implementation/AbstractDebugRenderer.h b/src/Physics/Implementation/AbstractDebugRenderer.h index 63400b22b..ed236b60d 100644 --- a/src/Physics/Implementation/AbstractDebugRenderer.h +++ b/src/Physics/Implementation/AbstractDebugRenderer.h @@ -24,18 +24,20 @@ namespace Magnum { class AbstractShaderProgram; class Mesh; +namespace Shaders { + template class FlatShader; +} + namespace Physics { namespace Implementation { struct Options; -template class ShapeShader; - template class AbstractDebugRenderer: public SceneGraph::AbstractObject::ObjectType { public: AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent); protected: - Resource> shader; + Resource> shader; Resource mesh; Resource options; }; diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/Physics/Implementation/BoxRenderer.cpp index c428335d2..472af6781 100644 --- a/src/Physics/Implementation/BoxRenderer.cpp +++ b/src/Physics/Implementation/BoxRenderer.cpp @@ -20,7 +20,7 @@ #include "Physics/DebugDrawResourceManager.h" #include "Primitives/Cube.h" #include "Primitives/Square.h" -#include "ShapeShader.h" +#include "Shaders/FlatShader.h" namespace Magnum { namespace Physics { namespace Implementation { @@ -37,7 +37,7 @@ namespace { buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); return mesh->setPrimitive(square.primitive()) ->setVertexCount(square.positions(0)->size()) - ->addVertexBuffer(buffer, Implementation::ShapeShader<2>::Position()); + ->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position()); } }; @@ -51,7 +51,7 @@ namespace { buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); return mesh->setPrimitive(cube.primitive()) ->setVertexCount(cube.positions(0)->size()) - ->addVertexBuffer(buffer, Implementation::ShapeShader<2>::Position()); + ->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position()); } }; } diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 020acb2b7..53b99a0f2 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,8 +1,12 @@ -corrade_add_resource(MagnumShaders_RCS MagnumShaders PhongShader.frag PhongShader.vert) +corrade_add_resource(MagnumShaders_RCS MagnumShaders + FlatShader2D.vert FlatShader2D.frag + PhongShader.frag PhongShader.vert) set(MagnumShaders_SRCS + FlatShader.cpp PhongShader.cpp ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS + FlatShader.h PhongShader.h magnumShadersVisibility.h) diff --git a/src/Physics/Implementation/ShapeShader.cpp b/src/Shaders/FlatShader.cpp similarity index 67% rename from src/Physics/Implementation/ShapeShader.cpp rename to src/Shaders/FlatShader.cpp index c7cf1096f..4d6df9a03 100644 --- a/src/Physics/Implementation/ShapeShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -13,30 +13,30 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ShapeShader.h" +#include "FlatShader.h" #include #include "Shader.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace Shaders { namespace { template struct ShaderName {}; template<> struct ShaderName<2> { - constexpr static const char* Vertex = "ShapeShader2D.vert"; - constexpr static const char* Fragment = "ShapeShader2D.frag"; + constexpr static const char* Vertex = "FlatShader2D.vert"; + constexpr static const char* Fragment = "FlatShader2D.frag"; }; template<> struct ShaderName<3> { - constexpr static const char* Vertex = "ShapeShader3D.vert"; - constexpr static const char* Fragment = "ShapeShader3D.frag"; + constexpr static const char* Vertex = "FlatShader3D.vert"; + constexpr static const char* Fragment = "FlatShader3D.frag"; }; } -template ShapeShader::ShapeShader() { - Corrade::Utility::Resource resource("MagnumPhysics"); +template FlatShader::FlatShader() { + Corrade::Utility::Resource resource("MagnumShaders"); attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, resource.get(ShaderName::Vertex))); attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, resource.get(ShaderName::Fragment))); @@ -46,7 +46,7 @@ template ShapeShader::ShapeShader() { colorUniform = uniformLocation("color"); } -template class ShapeShader<2>; -template class ShapeShader<3>; +template class FlatShader<2>; +template class FlatShader<3>; -}}} +}} diff --git a/src/Physics/Implementation/ShapeShader.h b/src/Shaders/FlatShader.h similarity index 55% rename from src/Physics/Implementation/ShapeShader.h rename to src/Shaders/FlatShader.h index b1d1eac98..f2e247a2d 100644 --- a/src/Physics/Implementation/ShapeShader.h +++ b/src/Shaders/FlatShader.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Physics_Implementation_ShapeShader_h -#define Magnum_Physics_Implementation_ShapeShader_h +#ifndef Magnum_Shaders_FlatShader_h +#define Magnum_Shaders_FlatShader_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -15,26 +15,46 @@ GNU Lesser General Public License version 3 for more details. */ +/** @file + * @brief Class Magnum::Shaders::FlatShader + */ + #include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "AbstractShaderProgram.h" #include "Color.h" #include "DimensionTraits.h" -namespace Magnum { namespace Physics { namespace Implementation { +#include "magnumShadersVisibility.h" + +namespace Magnum { namespace Shaders { + +/** +@brief Flat shader -template class ShapeShader: public AbstractShaderProgram { +Draws whole mesh with one color. +*/ +template class SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: + /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::PointType> Position; - ShapeShader(); + FlatShader(); - ShapeShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { + /** + * @brief Set transformation and projection matrix + * @return Pointer to self (for method chaining) + */ + FlatShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionUniform, matrix); return this; } - ShapeShader* setColor(const Color3& color) { + /** + * @brief Set color + * @return Pointer to self (for method chaining) + */ + FlatShader* setColor(const Color3& color) { setUniform(colorUniform, color); return this; } @@ -44,9 +64,6 @@ template class ShapeShader: public AbstractShaderProgra colorUniform; }; -extern template class ShapeShader<2>; -extern template class ShapeShader<3>; - -}}} +}} #endif diff --git a/src/Physics/Implementation/ShapeShader2D.frag b/src/Shaders/FlatShader2D.frag similarity index 100% rename from src/Physics/Implementation/ShapeShader2D.frag rename to src/Shaders/FlatShader2D.frag diff --git a/src/Physics/Implementation/ShapeShader2D.vert b/src/Shaders/FlatShader2D.vert similarity index 100% rename from src/Physics/Implementation/ShapeShader2D.vert rename to src/Shaders/FlatShader2D.vert