diff --git a/src/Magnum/Shaders/AbstractVector.h b/src/Magnum/Shaders/AbstractVector.h index fb654b91b..76ed4b6e0 100644 --- a/src/Magnum/Shaders/AbstractVector.h +++ b/src/Magnum/Shaders/AbstractVector.h @@ -66,6 +66,7 @@ template class AbstractVector: public AbstractShaderProg protected: enum: Int { VectorTextureLayer = 15 }; + explicit AbstractVector(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {} explicit AbstractVector() = default; ~AbstractVector() = default; }; diff --git a/src/Magnum/Shaders/DistanceFieldVector.h b/src/Magnum/Shaders/DistanceFieldVector.h index 96cad22c3..32091aeb6 100644 --- a/src/Magnum/Shaders/DistanceFieldVector.h +++ b/src/Magnum/Shaders/DistanceFieldVector.h @@ -95,6 +95,18 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector public: 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{NoCreate} {} + /** * @brief Set transformation and projection matrix * @return Reference to self (for method chaining) diff --git a/src/Magnum/Shaders/Flat.h b/src/Magnum/Shaders/Flat.h index c2f1ceb7f..0835f72e1 100644 --- a/src/Magnum/Shaders/Flat.h +++ b/src/Magnum/Shaders/Flat.h @@ -170,6 +170,18 @@ template class MAGNUM_SHADERS_EXPORT Flat: public Abstra */ 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 */ Flags flags() const { return _flags; } diff --git a/src/Magnum/Shaders/MeshVisualizer.h b/src/Magnum/Shaders/MeshVisualizer.h index 8283bf4d8..256b3f5f5 100644 --- a/src/Magnum/Shaders/MeshVisualizer.h +++ b/src/Magnum/Shaders/MeshVisualizer.h @@ -206,6 +206,18 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram { */ 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 * @return Reference to self (for method chaining) diff --git a/src/Magnum/Shaders/Phong.h b/src/Magnum/Shaders/Phong.h index dc5c908c7..93c28a478 100644 --- a/src/Magnum/Shaders/Phong.h +++ b/src/Magnum/Shaders/Phong.h @@ -196,6 +196,18 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { */ 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 */ Flags flags() const { return _flags; } diff --git a/src/Magnum/Shaders/Test/CMakeLists.txt b/src/Magnum/Shaders/Test/CMakeLists.txt index 76e219d95..17ca37558 100644 --- a/src/Magnum/Shaders/Test/CMakeLists.txt +++ b/src/Magnum/Shaders/Test/CMakeLists.txt @@ -23,6 +23,13 @@ # 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) corrade_add_test(ShadersDistanceFieldVectorGLTest DistanceFieldVectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) diff --git a/src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp b/src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp new file mode 100644 index 000000000..77ccf6db9 --- /dev/null +++ b/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š + + 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 + +#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) diff --git a/src/Magnum/Shaders/Test/FlatTest.cpp b/src/Magnum/Shaders/Test/FlatTest.cpp new file mode 100644 index 000000000..d3161bdfb --- /dev/null +++ b/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š + + 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 + +#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) diff --git a/src/Magnum/Shaders/Test/MeshVisualizerTest.cpp b/src/Magnum/Shaders/Test/MeshVisualizerTest.cpp new file mode 100644 index 000000000..f36d3eb57 --- /dev/null +++ b/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š + + 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 + +#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) diff --git a/src/Magnum/Shaders/Test/PhongTest.cpp b/src/Magnum/Shaders/Test/PhongTest.cpp new file mode 100644 index 000000000..4b57f2746 --- /dev/null +++ b/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š + + 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 + +#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) diff --git a/src/Magnum/Shaders/Test/VectorTest.cpp b/src/Magnum/Shaders/Test/VectorTest.cpp new file mode 100644 index 000000000..30accfc13 --- /dev/null +++ b/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š + + 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 + +#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) diff --git a/src/Magnum/Shaders/Test/VertexColorTest.cpp b/src/Magnum/Shaders/Test/VertexColorTest.cpp new file mode 100644 index 000000000..2b40377e5 --- /dev/null +++ b/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š + + 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 + +#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) diff --git a/src/Magnum/Shaders/Vector.h b/src/Magnum/Shaders/Vector.h index 77247dd02..810b4259a 100644 --- a/src/Magnum/Shaders/Vector.h +++ b/src/Magnum/Shaders/Vector.h @@ -89,6 +89,18 @@ template class MAGNUM_SHADERS_EXPORT Vector: public Abst public: 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{NoCreate} {} + /** * @brief Set transformation and projection matrix * @return Reference to self (for method chaining) diff --git a/src/Magnum/Shaders/VertexColor.h b/src/Magnum/Shaders/VertexColor.h index 3449456bd..75c570275 100644 --- a/src/Magnum/Shaders/VertexColor.h +++ b/src/Magnum/Shaders/VertexColor.h @@ -105,6 +105,18 @@ template class MAGNUM_SHADERS_EXPORT VertexColor: public 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 * @return Reference to self (for method chaining)