Browse Source

Better handling of compiled-in resources in static build.

Each class/function that needs to access the resources first checks
whether the group exists and the group is registered if not. Thus there
is now no difference and annoying special cases when using static build.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
9d326d4ff1
  1. 4
      src/Magnum/Shaders/CMakeLists.txt
  2. 5
      src/Magnum/Shaders/DistanceFieldVector.cpp
  3. 5
      src/Magnum/Shaders/Flat.cpp
  4. 6
      src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h
  5. 5
      src/Magnum/Shaders/MeshVisualizer.cpp
  6. 5
      src/Magnum/Shaders/Phong.cpp
  7. 4
      src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp
  8. 4
      src/Magnum/Shaders/Test/FlatGLTest.cpp
  9. 4
      src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp
  10. 4
      src/Magnum/Shaders/Test/PhongGLTest.cpp
  11. 4
      src/Magnum/Shaders/Test/VectorGLTest.cpp
  12. 4
      src/Magnum/Shaders/Test/VertexColorGLTest.cpp
  13. 5
      src/Magnum/Shaders/Vector.cpp
  14. 5
      src/Magnum/Shaders/VertexColor.cpp
  15. 42
      src/Magnum/Shaders/resourceImport.hpp
  16. 4
      src/Magnum/TextureTools/CMakeLists.txt
  17. 9
      src/Magnum/TextureTools/DistanceField.cpp
  18. 42
      src/Magnum/TextureTools/resourceImport.hpp

4
src/Magnum/Shaders/CMakeLists.txt

@ -52,10 +52,6 @@ set(MagnumShaders_HEADERS
# Header files to display in project view of IDEs only
set(MagnumShaders_PRIVATE_HEADERS Implementation/CreateCompatibilityShader.h)
if(BUILD_STATIC)
set(MagnumShaders_HEADERS ${MagnumShaders_HEADERS} resourceImport.hpp)
endif()
# Shaders library
add_library(MagnumShaders ${SHARED_OR_STATIC}
${MagnumShaders_SRCS}

5
src/Magnum/Shaders/DistanceFieldVector.cpp

@ -42,6 +42,11 @@ namespace {
}
template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldVector(): transformationProjectionMatrixUniform(0), colorUniform(1), outlineColorUniform(2), outlineRangeUniform(3), smoothnessUniform(4) {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders"))
importShaderResources();
#endif
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES

5
src/Magnum/Shaders/Flat.cpp

@ -45,6 +45,11 @@ namespace {
}
template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): transformationProjectionMatrixUniform(0), colorUniform(1), _flags(flags) {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders"))
importShaderResources();
#endif
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES

6
src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h

@ -31,6 +31,12 @@
#include "Magnum/Extensions.h"
#include "Magnum/Shader.h"
#ifdef MAGNUM_BUILD_STATIC
static void importShaderResources() {
CORRADE_RESOURCE_INITIALIZE(MagnumShaders_RCS)
}
#endif
namespace Magnum { namespace Shaders { namespace Implementation {
inline Shader createCompatibilityShader(const Utility::Resource& rs, Version version, Shader::Type type) {

5
src/Magnum/Shaders/MeshVisualizer.cpp

@ -47,6 +47,11 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::standard_derivatives);
#endif
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders"))
importShaderResources();
#endif
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES

5
src/Magnum/Shaders/Phong.cpp

@ -45,6 +45,11 @@ namespace {
}
Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatrixUniform(1), normalMatrixUniform(2), lightUniform(3), diffuseColorUniform(4), ambientColorUniform(5), specularColorUniform(6), lightColorUniform(7), shininessUniform(8), _flags(flags) {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders"))
importShaderResources();
#endif
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES

4
src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp

@ -26,10 +26,6 @@
#include "Magnum/Shaders/DistanceFieldVector.h"
#include "Magnum/Test/AbstractOpenGLTester.h"
#ifdef MAGNUM_BUILD_STATIC
#include "Magnum/Shaders/resourceImport.hpp"
#endif
namespace Magnum { namespace Shaders { namespace Test {
struct DistanceFieldVectorGLTest: Magnum::Test::AbstractOpenGLTester {

4
src/Magnum/Shaders/Test/FlatGLTest.cpp

@ -26,10 +26,6 @@
#include "Magnum/Shaders/Flat.h"
#include "Magnum/Test/AbstractOpenGLTester.h"
#ifdef MAGNUM_BUILD_STATIC
#include "Magnum/Shaders/resourceImport.hpp"
#endif
namespace Magnum { namespace Shaders { namespace Test {
struct FlatGLTest: Magnum::Test::AbstractOpenGLTester {

4
src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp

@ -28,10 +28,6 @@
#include "Magnum/Shaders/MeshVisualizer.h"
#include "Magnum/Test/AbstractOpenGLTester.h"
#ifdef MAGNUM_BUILD_STATIC
#include "Magnum/Shaders/resourceImport.hpp"
#endif
namespace Magnum { namespace Shaders { namespace Test {
struct MeshVisualizerGLTest: Magnum::Test::AbstractOpenGLTester {

4
src/Magnum/Shaders/Test/PhongGLTest.cpp

@ -26,10 +26,6 @@
#include "Magnum/Shaders/Phong.h"
#include "Magnum/Test/AbstractOpenGLTester.h"
#ifdef MAGNUM_BUILD_STATIC
#include "Magnum/Shaders/resourceImport.hpp"
#endif
namespace Magnum { namespace Shaders { namespace Test {
struct PhongGLTest: Magnum::Test::AbstractOpenGLTester {

4
src/Magnum/Shaders/Test/VectorGLTest.cpp

@ -26,10 +26,6 @@
#include "Magnum/Shaders/Vector.h"
#include "Magnum/Test/AbstractOpenGLTester.h"
#ifdef MAGNUM_BUILD_STATIC
#include "Magnum/Shaders/resourceImport.hpp"
#endif
namespace Magnum { namespace Shaders { namespace Test {
struct VectorGLTest: Magnum::Test::AbstractOpenGLTester {

4
src/Magnum/Shaders/Test/VertexColorGLTest.cpp

@ -26,10 +26,6 @@
#include "Magnum/Shaders/VertexColor.h"
#include "Magnum/Test/AbstractOpenGLTester.h"
#ifdef MAGNUM_BUILD_STATIC
#include "Magnum/Shaders/resourceImport.hpp"
#endif
namespace Magnum { namespace Shaders { namespace Test {
struct VertexColorGLTest: Magnum::Test::AbstractOpenGLTester {

5
src/Magnum/Shaders/Vector.cpp

@ -42,6 +42,11 @@ namespace {
}
template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationProjectionMatrixUniform(0), backgroundColorUniform(1), colorUniform(2) {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders"))
importShaderResources();
#endif
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES

5
src/Magnum/Shaders/VertexColor.cpp

@ -42,6 +42,11 @@ namespace {
}
template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor(): transformationProjectionMatrixUniform(0) {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders"))
importShaderResources();
#endif
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES

42
src/Magnum/Shaders/resourceImport.hpp

@ -1,42 +0,0 @@
#ifndef Magnum_Shaders_resourceImport_hpp
#define Magnum_Shaders_resourceImport_hpp
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/configure.h"
#ifdef MAGNUM_BUILD_STATIC
#include <Corrade/Utility/Resource.h>
#include <Corrade/Utility/Macros.h>
static int magnumShadersResourceImport() {
CORRADE_RESOURCE_INITIALIZE(MagnumShaders_RCS)
return 0;
} CORRADE_AUTOMATIC_INITIALIZER(magnumShadersResourceImport)
#else
#error this header is available only in static build
#endif
#endif

4
src/Magnum/TextureTools/CMakeLists.txt

@ -36,10 +36,6 @@ set(MagnumTextureTools_HEADERS
visibility.h)
if(BUILD_STATIC)
list(APPEND MagnumTextureTools_HEADERS resourceImport.hpp)
endif()
# TextureTools library
add_library(MagnumTextureTools ${SHARED_OR_STATIC}
${MagnumTextureTools_SRCS}

9
src/Magnum/TextureTools/DistanceField.cpp

@ -38,6 +38,10 @@
#include "Magnum/Texture.h"
#include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h"
static void importTextureToolResources() {
CORRADE_RESOURCE_INITIALIZE(MagnumTextureTools_RCS)
}
namespace Magnum { namespace TextureTools {
namespace {
@ -77,6 +81,11 @@ class DistanceFieldShader: public AbstractShaderProgram {
};
DistanceFieldShader::DistanceFieldShader(): radiusUniform(0), scalingUniform(1) {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumTextureTools"))
importTextureToolResources();
#endif
Utility::Resource rs("MagnumTextureTools");
#ifndef MAGNUM_TARGET_GLES

42
src/Magnum/TextureTools/resourceImport.hpp

@ -1,42 +0,0 @@
#ifndef Magnum_TextureTools_resourceImport_hpp
#define Magnum_TextureTools_resourceImport_hpp
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/configure.h"
#ifdef MAGNUM_BUILD_STATIC
#include <Corrade/Utility/Resource.h>
#include <Corrade/Utility/Macros.h>
static int magnumTextureToolsResourceImport() {
CORRADE_RESOURCE_INITIALIZE(MagnumTextureTools_RCS)
return 0;
} CORRADE_AUTOMATIC_INITIALIZER(magnumTextureToolsResourceImport)
#else
#error this header is available only in static build
#endif
#endif
Loading…
Cancel
Save