diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 0365a75d4..fb728503c 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -67,6 +67,7 @@ set(Magnum_SRCS Trade/AbstractImporter.cpp Trade/AbstractMaterialData.cpp Trade/ImageData.cpp + Trade/LightData.cpp Trade/MeshData2D.cpp Trade/MeshData3D.cpp Trade/MeshObjectData2D.cpp diff --git a/src/Magnum/Trade/LightData.cpp b/src/Magnum/Trade/LightData.cpp new file mode 100644 index 000000000..68c04b0e6 --- /dev/null +++ b/src/Magnum/Trade/LightData.cpp @@ -0,0 +1,46 @@ +/* + 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 "LightData.h" + +namespace Magnum { namespace Trade { + +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug& operator<<(Debug& debug, const LightData::Type value) { + switch(value) { + /* LCOV_EXCL_START */ + #define _c(value) case LightData::Type::value: return debug << "Trade::LightData::Type::" #value; + _c(Infinite) + _c(Point) + _c(Spot) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "Trade::LightData::Type(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} +#endif + +}} diff --git a/src/Magnum/Trade/LightData.h b/src/Magnum/Trade/LightData.h index 3a8163f6d..753430379 100644 --- a/src/Magnum/Trade/LightData.h +++ b/src/Magnum/Trade/LightData.h @@ -29,14 +29,84 @@ * @brief Class @ref Magnum::Trade::LightData */ -#include +#include "Magnum/Magnum.h" +#include "Magnum/Math/Color.h" namespace Magnum { namespace Trade { /** @brief Light data */ -class LightData {}; +class LightData { + public: + /** + * @brief Light type + * + * @see @ref type() + */ + enum class Type: UnsignedByte { + /** + * Light at position that is infinitely far away so its rays are + * parallel. The light rays point in a direction of negative Z + * axis. + */ + Infinite, + + /** Point light, radiating in all directions */ + Point, + + /** + * Spot light, radiating in a limited range of direction. The + * primary direction is negative Z axis. + */ + Spot + }; + + /** + * @brief Constructor + * @param color Light color + * @param intensity Light intensity + * @param importerState Importer-specific state + */ + constexpr explicit LightData(Type type, const Color3& color, Float intensity, const void* importerState = nullptr) noexcept: _type{type}, _color{color}, _intensity{intensity}, _importerState{importerState} {} + + /** @brief Copying is not allowed */ + LightData(const LightData&) = delete; + + /** @brief Move constructor */ + LightData(LightData&&) noexcept = default; + + /** @brief Copying is not allowed */ + LightData& operator=(const LightData&) = delete; + + /** @brief Move assignment */ + LightData& operator=(LightData&&) noexcept = default; + + /** @brief Light type */ + constexpr Type type() const { return _type; } + + /** @brief Light color */ + constexpr Color3 color() const { return _color; } + + /** @brief Light intensity */ + constexpr Float intensity() const { return _intensity; } + + /** + * @brief Importer-specific state + * + * See @ref AbstractImporter::importerState() for more information. + */ + const void* importerState() const { return _importerState; } + + private: + Type _type; + Vector3 _color; + Float _intensity; + const void* _importerState; +}; + +/** @debugoperatorenum{Magnum::Trade::LightData::Type} */ +MAGNUM_EXPORT Debug& operator<<(Debug& debug, LightData::Type value); }} diff --git a/src/Magnum/Trade/Test/CMakeLists.txt b/src/Magnum/Trade/Test/CMakeLists.txt index 7268fef08..674f031a3 100644 --- a/src/Magnum/Trade/Test/CMakeLists.txt +++ b/src/Magnum/Trade/Test/CMakeLists.txt @@ -40,6 +40,7 @@ corrade_add_test(TradeAbstractImporterTest AbstractImporterTest.cpp LIBRARIES Ma target_include_directories(TradeAbstractImporterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) corrade_add_test(TradeCameraDataTest CameraDataTest.cpp LIBRARIES Magnum) corrade_add_test(TradeImageDataTest ImageDataTest.cpp LIBRARIES Magnum) +corrade_add_test(TradeLightDataTest LightDataTest.cpp LIBRARIES Magnum) corrade_add_test(TradeMaterialDataTest MaterialDataTest.cpp LIBRARIES Magnum) corrade_add_test(TradeMeshData2DTest MeshData2DTest.cpp LIBRARIES Magnum) corrade_add_test(TradeMeshData3DTest MeshData3DTest.cpp LIBRARIES Magnum) diff --git a/src/Magnum/Trade/Test/LightDataTest.cpp b/src/Magnum/Trade/Test/LightDataTest.cpp new file mode 100644 index 000000000..54d3e6381 --- /dev/null +++ b/src/Magnum/Trade/Test/LightDataTest.cpp @@ -0,0 +1,101 @@ +/* + 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 + +#include "Magnum/Trade/LightData.h" + +namespace Magnum { namespace Trade { namespace Test { + +struct LightDataTest: TestSuite::Tester { + explicit LightDataTest(); + + void construct(); + void constructCopy(); + void constructMove(); + + void debugType(); +}; + +LightDataTest::LightDataTest() { + addTests({&LightDataTest::construct, + &LightDataTest::constructCopy, + &LightDataTest::constructMove, + + &LightDataTest::debugType}); +} + +void LightDataTest::construct() { + using namespace Math::Literals; + const int a{}; + LightData data{LightData::Type::Infinite, 0xccff33_rgbf, 0.8f, &a}; + + CORRADE_COMPARE(data.type(), LightData::Type::Infinite); + CORRADE_COMPARE(data.color(), 0xccff33_rgbf); + CORRADE_COMPARE(data.intensity(), 0.8f); + CORRADE_COMPARE(data.importerState(), &a); +} + +void LightDataTest::constructCopy() { + CORRADE_VERIFY(!(std::is_constructible{})); + CORRADE_VERIFY(!(std::is_assignable{})); +} + +void LightDataTest::constructMove() { + using namespace Math::Literals; + const int a{}; + LightData data{LightData::Type::Infinite, 0xccff33_rgbf, 0.8f, &a}; + + CORRADE_COMPARE(data.type(), LightData::Type::Infinite); + CORRADE_COMPARE(data.color(), 0xccff33_rgbf); + CORRADE_COMPARE(data.intensity(), 0.8f); + CORRADE_COMPARE(data.importerState(), &a); + + LightData b{std::move(data)}; + CORRADE_COMPARE(b.type(), LightData::Type::Infinite); + CORRADE_COMPARE(b.color(), 0xccff33_rgbf); + CORRADE_COMPARE(b.intensity(), 0.8f); + CORRADE_COMPARE(b.importerState(), &a); + + const int c{}; + LightData d{LightData::Type::Point, 0xdead00_rgbf, 1.6f, &c}; + d = std::move(b); + CORRADE_COMPARE(d.type(), LightData::Type::Infinite); + CORRADE_COMPARE(d.color(), 0xccff33_rgbf); + CORRADE_COMPARE(d.intensity(), 0.8f); + CORRADE_COMPARE(d.importerState(), &a); +} + +void LightDataTest::debugType() { + std::ostringstream out; + + Debug(&out) << LightData::Type::Spot << LightData::Type(0xbe); + CORRADE_COMPARE(out.str(), "Trade::LightData::Type::Spot Trade::LightData::Type(0xbe)\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::LightDataTest)