Browse Source

TextureTools: add a NoCreate constructor to DistanceField.

Should have been there for ages already.
pull/168/head
Vladimír Vondruš 2 years ago
parent
commit
e2523097d2
  1. 5
      doc/changelog.dox
  2. 2
      src/Magnum/TextureTools/DistanceField.cpp
  3. 16
      src/Magnum/TextureTools/DistanceField.h
  4. 72
      src/Magnum/TextureTools/Test/CMakeLists.txt
  5. 54
      src/Magnum/TextureTools/Test/DistanceFieldTest.cpp

5
doc/changelog.dox

@ -810,6 +810,11 @@ See also:
needed in order to prevent aligning pixel-perfect fonts to fractional
positions.
@subsubsection changelog-latest-changes-texturetools TextureTools library
- Added a @ref TextureTools::DistanceField::DistanceField(NoCreateT)
constructor allowing to construct the object without a GL context present
@subsubsection changelog-latest-changes-trade Trade library
- A changed signature of the @ref Trade::AbstractImporter::doOpenData(Containers::Array<char>&&, DataFlags)

2
src/Magnum/TextureTools/DistanceField.cpp

@ -171,6 +171,8 @@ DistanceField::DistanceField(const UnsignedInt radius): _state{new State{radius}
}
}
DistanceField::DistanceField(NoCreateT) noexcept {}
DistanceField::DistanceField(DistanceField&&) noexcept = default;
DistanceField::~DistanceField() = default;

16
src/Magnum/TextureTools/DistanceField.h

@ -95,6 +95,22 @@ class MAGNUM_TEXTURETOOLS_EXPORT DistanceField {
*/
explicit DistanceField(UnsignedInt radius);
/**
* @brief Construct without creating the internal OpenGL state
* @m_since_latest
*
* The constructed instance is equivalent to moved-from state, i.e. no
* APIs can be safely called on the object. 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.
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit DistanceField(NoCreateT) noexcept;
/** @brief Copying is not allowed */
DistanceField(const DistanceField&) = delete;

72
src/Magnum/TextureTools/Test/CMakeLists.txt

@ -87,42 +87,46 @@ else()
endif()
endif()
if(MAGNUM_BUILD_GL_TESTS)
# Otherwise CMake complains that Corrade::PluginManager is not found, wtf
find_package(Corrade REQUIRED PluginManager)
if(MAGNUM_TARGET_GL)
corrade_add_test(TextureToolsDistanceFieldTest DistanceFieldTest.cpp LIBRARIES MagnumTextureTools)
set(TextureToolsDistanceFieldGLTest_SRCS DistanceFieldGLTest.cpp)
if(CORRADE_TARGET_IOS)
# TODO: do this in a generic way in corrade_add_test()
set_source_files_properties(DistanceFieldGLTestFiles PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
list(APPEND TextureToolsDistanceFieldGLTest_SRCS DistanceFieldGLTestFiles)
endif()
corrade_add_test(TextureToolsDistanceFieldGLTest ${TextureToolsDistanceFieldGLTest_SRCS}
LIBRARIES
MagnumDebugTools
MagnumGL
MagnumOpenGLTester
MagnumTextureToolsTestLib
MagnumTrade
FILES
DistanceFieldGLTestFiles/input.tga
DistanceFieldGLTestFiles/output.tga)
target_include_directories(TextureToolsDistanceFieldGLTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
if(MAGNUM_BUILD_PLUGINS_STATIC)
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
target_link_libraries(TextureToolsDistanceFieldGLTest PRIVATE AnyImageImporter)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
target_link_libraries(TextureToolsDistanceFieldGLTest PRIVATE TgaImporter)
endif()
else()
# So the plugins get properly built when building the test
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
add_dependencies(TextureToolsDistanceFieldGLTest AnyImageImporter)
if(MAGNUM_BUILD_GL_TESTS)
# Otherwise CMake complains that Corrade::PluginManager is not found, wtf
find_package(Corrade REQUIRED PluginManager)
set(TextureToolsDistanceFieldGLTest_SRCS DistanceFieldGLTest.cpp)
if(CORRADE_TARGET_IOS)
# TODO: do this in a generic way in corrade_add_test()
set_source_files_properties(DistanceFieldGLTestFiles PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
list(APPEND TextureToolsDistanceFieldGLTest_SRCS DistanceFieldGLTestFiles)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
add_dependencies(TextureToolsDistanceFieldGLTest TgaImporter)
corrade_add_test(TextureToolsDistanceFieldGLTest ${TextureToolsDistanceFieldGLTest_SRCS}
LIBRARIES
MagnumDebugTools
MagnumGL
MagnumOpenGLTester
MagnumTextureToolsTestLib
MagnumTrade
FILES
DistanceFieldGLTestFiles/input.tga
DistanceFieldGLTestFiles/output.tga)
target_include_directories(TextureToolsDistanceFieldGLTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
if(MAGNUM_BUILD_PLUGINS_STATIC)
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
target_link_libraries(TextureToolsDistanceFieldGLTest PRIVATE AnyImageImporter)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
target_link_libraries(TextureToolsDistanceFieldGLTest PRIVATE TgaImporter)
endif()
else()
# So the plugins get properly built when building the test
if(MAGNUM_WITH_ANYIMAGEIMPORTER)
add_dependencies(TextureToolsDistanceFieldGLTest AnyImageImporter)
endif()
if(MAGNUM_WITH_TGAIMPORTER)
add_dependencies(TextureToolsDistanceFieldGLTest TgaImporter)
endif()
endif()
endif()
endif()

54
src/Magnum/TextureTools/Test/DistanceFieldTest.cpp

@ -0,0 +1,54 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023 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/TextureTools/DistanceField.h"
namespace Magnum { namespace TextureTools { namespace Test { namespace {
struct DistanceFieldTest: TestSuite::Tester {
explicit DistanceFieldTest();
void constructNoCreate();
};
DistanceFieldTest::DistanceFieldTest() {
addTests({&DistanceFieldTest::constructNoCreate});
}
void DistanceFieldTest::constructNoCreate() {
DistanceField distanceField{NoCreate};
/* Shouldn't crash or try to acces GL */
CORRADE_VERIFY(true);
/* Implicit construction is not allowed */
CORRADE_VERIFY(!std::is_convertible<NoCreateT, DistanceField>::value);
}
}}}}
CORRADE_TEST_MAIN(Magnum::TextureTools::Test::DistanceFieldTest)
Loading…
Cancel
Save