Browse Source

Shaders: added NoCreate constructors to all classes.

Makes it possible to have instance of them even before any context is
active.
pull/196/head
Vladimír Vondruš 9 years ago
parent
commit
1e8a5c927b
  1. 1
      src/Magnum/Shaders/AbstractVector.h
  2. 12
      src/Magnum/Shaders/DistanceFieldVector.h
  3. 12
      src/Magnum/Shaders/Flat.h
  4. 12
      src/Magnum/Shaders/MeshVisualizer.h
  5. 12
      src/Magnum/Shaders/Phong.h
  6. 7
      src/Magnum/Shaders/Test/CMakeLists.txt
  7. 64
      src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp
  8. 64
      src/Magnum/Shaders/Test/FlatTest.cpp
  9. 53
      src/Magnum/Shaders/Test/MeshVisualizerTest.cpp
  10. 53
      src/Magnum/Shaders/Test/PhongTest.cpp
  11. 64
      src/Magnum/Shaders/Test/VectorTest.cpp
  12. 64
      src/Magnum/Shaders/Test/VertexColorTest.cpp
  13. 12
      src/Magnum/Shaders/Vector.h
  14. 12
      src/Magnum/Shaders/VertexColor.h

1
src/Magnum/Shaders/AbstractVector.h

@ -66,6 +66,7 @@ template<UnsignedInt dimensions> class AbstractVector: public AbstractShaderProg
protected: protected:
enum: Int { VectorTextureLayer = 15 }; enum: Int { VectorTextureLayer = 15 };
explicit AbstractVector(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {}
explicit AbstractVector() = default; explicit AbstractVector() = default;
~AbstractVector() = default; ~AbstractVector() = default;
}; };

12
src/Magnum/Shaders/DistanceFieldVector.h

@ -95,6 +95,18 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
public: public:
explicit DistanceFieldVector(); explicit DistanceFieldVector();
/**
* @brief Construct without creating the underlying OpenGL object
*
* The constructed instance is equivalent to moved-from state. Useful
* in cases where you will overwrite the instance later anyway. Move
* another object over it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
*/
explicit DistanceFieldVector(NoCreateT) noexcept: AbstractVector<dimensions>{NoCreate} {}
/** /**
* @brief Set transformation and projection matrix * @brief Set transformation and projection matrix
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)

12
src/Magnum/Shaders/Flat.h

@ -170,6 +170,18 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
*/ */
explicit Flat(Flags flags = Flags()); explicit Flat(Flags flags = Flags());
/**
* @brief Construct without creating the underlying OpenGL object
*
* The constructed instance is equivalent to moved-from state. Useful
* in cases where you will overwrite the instance later anyway. Move
* another object over it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
*/
explicit Flat(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {}
/** @brief Flags */ /** @brief Flags */
Flags flags() const { return _flags; } Flags flags() const { return _flags; }

12
src/Magnum/Shaders/MeshVisualizer.h

@ -206,6 +206,18 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
*/ */
explicit MeshVisualizer(Flags flags = Flags()); explicit MeshVisualizer(Flags flags = Flags());
/**
* @brief Construct without creating the underlying OpenGL object
*
* The constructed instance is equivalent to moved-from state. Useful
* in cases where you will overwrite the instance later anyway. Move
* another object over it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
*/
explicit MeshVisualizer(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {}
/** /**
* @brief Set transformation and projection matrix * @brief Set transformation and projection matrix
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)

12
src/Magnum/Shaders/Phong.h

@ -196,6 +196,18 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
*/ */
explicit Phong(Flags flags = Flags()); explicit Phong(Flags flags = Flags());
/**
* @brief Construct without creating the underlying OpenGL object
*
* The constructed instance is equivalent to moved-from state. Useful
* in cases where you will overwrite the instance later anyway. Move
* another object over it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
*/
explicit Phong(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {}
/** @brief Flags */ /** @brief Flags */
Flags flags() const { return _flags; } Flags flags() const { return _flags; }

7
src/Magnum/Shaders/Test/CMakeLists.txt

@ -23,6 +23,13 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
corrade_add_test(ShadersDistanceFieldVectorTest DistanceFieldVectorTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersFlatTest FlatTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersMeshVisualizerTest MeshVisualizerTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersPhongTest PhongTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersVectorTest VectorTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersVertexColorTest VertexColorTest.cpp LIBRARIES MagnumShaders)
if(BUILD_GL_TESTS) if(BUILD_GL_TESTS)
corrade_add_test(ShadersDistanceFieldVectorGLTest DistanceFieldVectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersDistanceFieldVectorGLTest DistanceFieldVectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester)
corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester)

64
src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp

@ -0,0 +1,64 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 <Corrade/TestSuite/Tester.h>
#include "Magnum/Shaders/DistanceFieldVector.h"
namespace Magnum { namespace Shaders { namespace Test {
struct DistanceFieldVectorTest: TestSuite::Tester {
explicit DistanceFieldVectorTest();
void constructNoCreate2D();
void constructNoCreate3D();
};
DistanceFieldVectorTest::DistanceFieldVectorTest() {
addTests({&DistanceFieldVectorTest::constructNoCreate2D,
&DistanceFieldVectorTest::constructNoCreate3D});
}
void DistanceFieldVectorTest::constructNoCreate2D() {
{
Shaders::DistanceFieldVector2D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
void DistanceFieldVectorTest::constructNoCreate3D() {
{
Shaders::DistanceFieldVector3D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::DistanceFieldVectorTest)

64
src/Magnum/Shaders/Test/FlatTest.cpp

@ -0,0 +1,64 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 <Corrade/TestSuite/Tester.h>
#include "Magnum/Shaders/Flat.h"
namespace Magnum { namespace Shaders { namespace Test {
struct FlatTest: TestSuite::Tester {
explicit FlatTest();
void constructNoCreate2D();
void constructNoCreate3D();
};
FlatTest::FlatTest() {
addTests({&FlatTest::constructNoCreate2D,
&FlatTest::constructNoCreate3D});
}
void FlatTest::constructNoCreate2D() {
{
Shaders::Flat2D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
void FlatTest::constructNoCreate3D() {
{
Shaders::Flat3D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::FlatTest)

53
src/Magnum/Shaders/Test/MeshVisualizerTest.cpp

@ -0,0 +1,53 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 <Corrade/TestSuite/Tester.h>
#include "Magnum/Shaders/MeshVisualizer.h"
namespace Magnum { namespace Shaders { namespace Test {
struct MeshVisualizerTest: TestSuite::Tester {
explicit MeshVisualizerTest();
void constructNoCreate();
};
MeshVisualizerTest::MeshVisualizerTest() {
addTests({&MeshVisualizerTest::constructNoCreate});
}
void MeshVisualizerTest::constructNoCreate() {
{
Shaders::MeshVisualizer shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::MeshVisualizerTest)

53
src/Magnum/Shaders/Test/PhongTest.cpp

@ -0,0 +1,53 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 <Corrade/TestSuite/Tester.h>
#include "Magnum/Shaders/Phong.h"
namespace Magnum { namespace Shaders { namespace Test {
struct PhongTest: TestSuite::Tester {
explicit PhongTest();
void constructNoCreate();
};
PhongTest::PhongTest() {
addTests({&PhongTest::constructNoCreate});
}
void PhongTest::constructNoCreate() {
{
Shaders::Phong shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::PhongTest)

64
src/Magnum/Shaders/Test/VectorTest.cpp

@ -0,0 +1,64 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 <Corrade/TestSuite/Tester.h>
#include "Magnum/Shaders/Vector.h"
namespace Magnum { namespace Shaders { namespace Test {
struct VectorTest: TestSuite::Tester {
explicit VectorTest();
void constructNoCreate2D();
void constructNoCreate3D();
};
VectorTest::VectorTest() {
addTests({&VectorTest::constructNoCreate2D,
&VectorTest::constructNoCreate3D});
}
void VectorTest::constructNoCreate2D() {
{
Shaders::Vector2D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
void VectorTest::constructNoCreate3D() {
{
Shaders::Vector3D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::VectorTest)

64
src/Magnum/Shaders/Test/VertexColorTest.cpp

@ -0,0 +1,64 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 <Corrade/TestSuite/Tester.h>
#include "Magnum/Shaders/VertexColor.h"
namespace Magnum { namespace Shaders { namespace Test {
struct VertexColorTest: TestSuite::Tester {
explicit VertexColorTest();
void constructNoCreate2D();
void constructNoCreate3D();
};
VertexColorTest::VertexColorTest() {
addTests({&VertexColorTest::constructNoCreate2D,
&VertexColorTest::constructNoCreate3D});
}
void VertexColorTest::constructNoCreate2D() {
{
Shaders::VertexColor2D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
void VertexColorTest::constructNoCreate3D() {
{
Shaders::VertexColor3D shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::VertexColorTest)

12
src/Magnum/Shaders/Vector.h

@ -89,6 +89,18 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
public: public:
explicit Vector(); explicit Vector();
/**
* @brief Construct without creating the underlying OpenGL object
*
* The constructed instance is equivalent to moved-from state. Useful
* in cases where you will overwrite the instance later anyway. Move
* another object over it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
*/
explicit Vector(NoCreateT) noexcept: AbstractVector<dimensions>{NoCreate} {}
/** /**
* @brief Set transformation and projection matrix * @brief Set transformation and projection matrix
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)

12
src/Magnum/Shaders/VertexColor.h

@ -105,6 +105,18 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColor: public
explicit VertexColor(); explicit VertexColor();
/**
* @brief Construct without creating the underlying OpenGL object
*
* The constructed instance is equivalent to moved-from state. Useful
* in cases where you will overwrite the instance later anyway. Move
* another object over it to make it useful.
*
* This function can be safely used for constructing (and later
* destructing) objects even without any OpenGL context being active.
*/
explicit VertexColor(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {}
/** /**
* @brief Set transformation and projection matrix * @brief Set transformation and projection matrix
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)

Loading…
Cancel
Save