From 44997465a7ababbfb17abfad9932fd87f66617b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2019 11:49:01 +0100 Subject: [PATCH] DebugTools: test ForceRenderer and ObjectRenderer. I spent some time trying ForceRenderer3D to produce the same image as ForceRenderer2D but it *does not want* to show the arrowhead to me, so I gave up. --- src/Magnum/DebugTools/Test/CMakeLists.txt | 24 +++ .../DebugTools/Test/ForceRenderer2D.tga | Bin 0 -> 16402 bytes .../DebugTools/Test/ForceRenderer3D.tga | Bin 0 -> 16402 bytes .../DebugTools/Test/ForceRendererGLTest.cpp | 161 ++++++++++++++++++ .../DebugTools/Test/ObjectRenderer2D.tga | Bin 0 -> 16402 bytes .../DebugTools/Test/ObjectRenderer3D.tga | Bin 0 -> 16402 bytes .../DebugTools/Test/ObjectRendererGLTest.cpp | 153 +++++++++++++++++ 7 files changed, 338 insertions(+) create mode 100644 src/Magnum/DebugTools/Test/ForceRenderer2D.tga create mode 100644 src/Magnum/DebugTools/Test/ForceRenderer3D.tga create mode 100644 src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp create mode 100644 src/Magnum/DebugTools/Test/ObjectRenderer2D.tga create mode 100644 src/Magnum/DebugTools/Test/ObjectRenderer3D.tga create mode 100644 src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp diff --git a/src/Magnum/DebugTools/Test/CMakeLists.txt b/src/Magnum/DebugTools/Test/CMakeLists.txt index 7847ed2be..fb2ab7c5f 100644 --- a/src/Magnum/DebugTools/Test/CMakeLists.txt +++ b/src/Magnum/DebugTools/Test/CMakeLists.txt @@ -135,5 +135,29 @@ if(TARGET_GL) endif() endif() endif() + + if(WITH_SCENEGRAPH AND WITH_TRADE) + corrade_add_test(DebugToolsForceRendererGLTest ForceRendererGLTest.cpp LIBRARIES MagnumDebugTools MagnumOpenGLTester) + corrade_add_test(DebugToolsObjectRendererGLTest ObjectRendererGLTest.cpp LIBRARIES MagnumDebugTools MagnumOpenGLTester) + set_target_properties( + DebugToolsForceRendererGLTest + DebugToolsObjectRendererGLTest + PROPERTIES FOLDER "Magnum/DebugTools/Test") + if(NOT BUILD_PLUGINS_STATIC) + target_include_directories(DebugToolsForceRendererGLTest PRIVATE $) + target_include_directories(DebugToolsObjectRendererGLTest PRIVATE $) + else() + target_include_directories(DebugToolsForceRendererGLTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_include_directories(DebugToolsObjectRendererGLTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + if(WITH_ANYIMAGEIMPORTER) + target_link_libraries(DebugToolsForceRendererGLTest PRIVATE AnyImageImporter) + target_link_libraries(DebugToolsObjectRendererGLTest PRIVATE AnyImageImporter) + endif() + if(WITH_TGAIMPORTER) + target_link_libraries(DebugToolsForceRendererGLTest PRIVATE TgaImporter) + target_link_libraries(DebugToolsObjectRendererGLTest PRIVATE TgaImporter) + endif() + endif() + endif() endif() endif() diff --git a/src/Magnum/DebugTools/Test/ForceRenderer2D.tga b/src/Magnum/DebugTools/Test/ForceRenderer2D.tga new file mode 100644 index 0000000000000000000000000000000000000000..f01e2c7f7ad934e2bfff0dbeb58ee1fbf735f9fb GIT binary patch literal 16402 zcmeI#!3~5k3`9|jMzTH70M%^&9b|=&waAAYIO2zdLX^`?{)|k-7Wo`;#3#lW)5`-4 zU;qOczyJm?fB_6(00S7n00veJeD^t5=N-;?FeVRpaAq9`Jix&~{o qJM2&Go%E;Px^}p08vp-@yx;`}Fn|FJU;qOczyJm?fB_6VVc-X=NcD^W literal 0 HcmV?d00001 diff --git a/src/Magnum/DebugTools/Test/ForceRenderer3D.tga b/src/Magnum/DebugTools/Test/ForceRenderer3D.tga new file mode 100644 index 0000000000000000000000000000000000000000..bf534561981148b0f3010c5b4421f119355dd000 GIT binary patch literal 16402 zcmeI!!3l*x3&)$02W-(-*_0~x$s=RgJ=%$q?MbU_z%p>JS&U=QqpJ+KGU zfG+5QF6crVum|>_Ex484%J#q>*aP=L8?XoVpe?u$+y`yJ`}>cOg)A6gfB^;=V1NMz L7+`<_2L22@%`fRb literal 0 HcmV?d00001 diff --git a/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp b/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp new file mode 100644 index 000000000..4463632ed --- /dev/null +++ b/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp @@ -0,0 +1,161 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + 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/Image.h" +#include "Magnum/PixelFormat.h" +#include "Magnum/DebugTools/CompareImage.h" +#include "Magnum/DebugTools/ForceRenderer.h" +#include "Magnum/DebugTools/ResourceManager.h" +#include "Magnum/GL/Framebuffer.h" +#include "Magnum/GL/OpenGLTester.h" +#include "Magnum/GL/Renderbuffer.h" +#include "Magnum/GL/RenderbufferFormat.h" +#include "Magnum/SceneGraph/Camera.h" +#include "Magnum/SceneGraph/Scene.h" +#include "Magnum/SceneGraph/MatrixTransformation2D.h" +#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/Trade/AbstractImporter.h" + +#include "configure.h" + +namespace Magnum { namespace DebugTools { namespace Test { namespace { + +struct ForceRendererGLTest: GL::OpenGLTester { + explicit ForceRendererGLTest(); + + void render2D(); + void render3D(); + + private: + PluginManager::Manager _manager{"nonexistent"}; +}; + +ForceRendererGLTest::ForceRendererGLTest() { + addTests({&ForceRendererGLTest::render2D, + &ForceRendererGLTest::render3D}); + + /* Load the plugins directly from the build tree. Otherwise they're either + static and already loaded or not present in the build tree */ + #ifdef ANYIMAGEIMPORTER_PLUGIN_FILENAME + CORRADE_INTERNAL_ASSERT(_manager.load(ANYIMAGEIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); + #endif + #ifdef TGAIMPORTER_PLUGIN_FILENAME + CORRADE_INTERNAL_ASSERT(_manager.load(TGAIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); + #endif +} + +using namespace Math::Literals; + +void ForceRendererGLTest::render2D() { + SceneGraph::Scene scene; + + SceneGraph::DrawableGroup2D drawables; + SceneGraph::Camera2D camera{scene}; + camera.setProjectionMatrix(Matrix3::projection({4.0f, 4.0f})); + + ResourceManager manager; + manager.set("my", ForceRendererOptions{}.setColor(0xff3366_rgbf)); + + SceneGraph::Object object{&scene}; + object.translate({-1.0f, -1.0f}); + Vector2 force{2.0f, 2.0f}; + ForceRenderer2D renderer{object, {}, force, "my", &drawables}; + + GL::Renderbuffer color; + color.setStorage( + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + GL::RenderbufferFormat::RGBA8, + #else + GL::RenderbufferFormat::RGBA4, + #endif + {64, 64}); + GL::Framebuffer framebuffer{{{}, {64, 64}}}; + framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color) + .clear(GL::FramebufferClear::Color) + .bind(); + + camera.draw(drawables); + + MAGNUM_VERIFY_NO_GL_ERROR(); + CORRADE_COMPARE_WITH( + framebuffer.read({{}, {64, 64}}, {PixelFormat::RGBA8Unorm}), + Utility::Directory::join(DEBUGTOOLS_TEST_DIR, "ForceRenderer2D.tga"), + CompareImageToFile{_manager}); +} + +void ForceRendererGLTest::render3D() { + SceneGraph::Scene scene; + + SceneGraph::DrawableGroup3D drawables; + SceneGraph::Object cameraObject{&scene}; + cameraObject.rotateY(90.0_degf); + SceneGraph::Camera3D camera{cameraObject}; + camera.setProjectionMatrix(Matrix4::orthographicProjection({4.0f, 4.0f}, 0.1f, 1.0f)); + + ResourceManager manager; + manager.set("my", ForceRendererOptions{}.setColor(0xff3366_rgbf)); + + SceneGraph::Object object{&scene}; + object + .rotateY(-90.0_degf) + .translate({-0.5f, -1.0f, 1.0f}); + Vector3 force{2.0f, 2.0f, 0.0f}; + ForceRenderer3D renderer{object, {}, force, "my", &drawables}; + + GL::Renderbuffer color; + color.setStorage( + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + GL::RenderbufferFormat::RGBA8, + #else + GL::RenderbufferFormat::RGBA4, + #endif + {64, 64}); + GL::Framebuffer framebuffer{{{}, {64, 64}}}; + framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color) + .clear(GL::FramebufferClear::Color) + .bind(); + + camera.draw(drawables); + + MAGNUM_VERIFY_NO_GL_ERROR(); + { + CORRADE_EXPECT_FAIL("I'm unable to convince it to orient the arrowhead correctly in 3D."); + CORRADE_COMPARE_WITH( + framebuffer.read({{}, {64, 64}}, {PixelFormat::RGBA8Unorm}), + Utility::Directory::join(DEBUGTOOLS_TEST_DIR, "ForceRenderer2D.tga"), + CompareImageToFile{_manager}); + } + CORRADE_COMPARE_WITH( + framebuffer.read({{}, {64, 64}}, {PixelFormat::RGBA8Unorm}), + Utility::Directory::join(DEBUGTOOLS_TEST_DIR, "ForceRenderer3D.tga"), + CompareImageToFile{_manager}); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::DebugTools::Test::ForceRendererGLTest) diff --git a/src/Magnum/DebugTools/Test/ObjectRenderer2D.tga b/src/Magnum/DebugTools/Test/ObjectRenderer2D.tga new file mode 100644 index 0000000000000000000000000000000000000000..cbb9225706b56277f08081b485ac03c5bca960b0 GIT binary patch literal 16402 zcmeH}K?(vf3`K(%sYjXnUn)`|5W5(vEBpTwN;}wvFM0W6#3Sl+#TCyOVhkY*U_R%+ z)~_!09xKf0P8~Y)&V7YDj?BGpk&*q`?F_$n|EKRb;O&5W|Cs?YzfEmC6 zcL&`0c@K~Q%m5C!JK)aGdw>jZp8=5c2(w;Yw{Lz jKd<-HpPkv&dkdd#hSOVmivu`-12}*KIDi8^M&ug^D9H+*KbsZ7L{|4J%7)tTJ$-` z@fp8Z-Rtm)-?{I zy#1&5d3(>=pZnd%+-L5)?`>9m_@CE*dY`xV?0eYvtlkUm&$6z4;#PF;^T;P|#qqiO vy|~Bd&fW7hcAb4b%UHe7!VBm6dmrjUeQ*E=Z~zBz00(dY2XFufc6HzZ{T%Kp literal 0 HcmV?d00001 diff --git a/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp b/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp new file mode 100644 index 000000000..82907337c --- /dev/null +++ b/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp @@ -0,0 +1,153 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + 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/Image.h" +#include "Magnum/PixelFormat.h" +#include "Magnum/DebugTools/CompareImage.h" +#include "Magnum/DebugTools/ObjectRenderer.h" +#include "Magnum/DebugTools/ResourceManager.h" +#include "Magnum/GL/Framebuffer.h" +#include "Magnum/GL/OpenGLTester.h" +#include "Magnum/GL/Renderbuffer.h" +#include "Magnum/GL/RenderbufferFormat.h" +#include "Magnum/SceneGraph/Camera.h" +#include "Magnum/SceneGraph/Scene.h" +#include "Magnum/SceneGraph/MatrixTransformation2D.h" +#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/Trade/AbstractImporter.h" + +#include "configure.h" + +namespace Magnum { namespace DebugTools { namespace Test { namespace { + +struct ObjectRendererGLTest: GL::OpenGLTester { + explicit ObjectRendererGLTest(); + + void render2D(); + void render3D(); + + private: + PluginManager::Manager _manager{"nonexistent"}; +}; + +ObjectRendererGLTest::ObjectRendererGLTest() { + addTests({&ObjectRendererGLTest::render2D, + &ObjectRendererGLTest::render3D}); + + /* Load the plugins directly from the build tree. Otherwise they're either + static and already loaded or not present in the build tree */ + #ifdef ANYIMAGEIMPORTER_PLUGIN_FILENAME + CORRADE_INTERNAL_ASSERT(_manager.load(ANYIMAGEIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); + #endif + #ifdef TGAIMPORTER_PLUGIN_FILENAME + CORRADE_INTERNAL_ASSERT(_manager.load(TGAIMPORTER_PLUGIN_FILENAME) & PluginManager::LoadState::Loaded); + #endif +} + +using namespace Math::Literals; + +void ObjectRendererGLTest::render2D() { + SceneGraph::Scene scene; + + SceneGraph::DrawableGroup2D drawables; + SceneGraph::Camera2D camera{scene}; + camera.setProjectionMatrix(Matrix3::projection({4.0f, 4.0f})); + + ResourceManager manager; + manager.set("my", ObjectRendererOptions{}.setSize(2.2f)); + + SceneGraph::Object object{&scene}; + object + .rotate(-17.3_degf) + .translate({-1.0f, -1.0f}); + ObjectRenderer2D renderer{object, "my", &drawables}; + + GL::Renderbuffer color; + color.setStorage( + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + GL::RenderbufferFormat::RGBA8, + #else + GL::RenderbufferFormat::RGBA4, + #endif + {64, 64}); + GL::Framebuffer framebuffer{{{}, {64, 64}}}; + framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color) + .clear(GL::FramebufferClear::Color) + .bind(); + + camera.draw(drawables); + + MAGNUM_VERIFY_NO_GL_ERROR(); + CORRADE_COMPARE_WITH( + framebuffer.read({{}, {64, 64}}, {PixelFormat::RGBA8Unorm}), + Utility::Directory::join(DEBUGTOOLS_TEST_DIR, "ObjectRenderer2D.tga"), + CompareImageToFile{_manager}); +} + +void ObjectRendererGLTest::render3D() { + SceneGraph::Scene scene; + + SceneGraph::DrawableGroup3D drawables; + SceneGraph::Camera3D camera{scene}; + camera.setProjectionMatrix(Matrix4::orthographicProjection({4.0f, 4.0f}, 0.1f, 2.0f)); + + ResourceManager manager; + manager.set("my", ObjectRendererOptions{}.setSize(2.2f)); + + SceneGraph::Object object{&scene}; + object + .rotateZ(17.3_degf) + .rotateY(45.0_degf) + .translate({-1.0f, -1.0f, -1.0f}); + ObjectRenderer3D renderer{object, "my", &drawables}; + + GL::Renderbuffer color; + color.setStorage( + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + GL::RenderbufferFormat::RGBA8, + #else + GL::RenderbufferFormat::RGBA4, + #endif + {64, 64}); + GL::Framebuffer framebuffer{{{}, {64, 64}}}; + framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color) + .clear(GL::FramebufferClear::Color) + .bind(); + + camera.draw(drawables); + + MAGNUM_VERIFY_NO_GL_ERROR(); + CORRADE_COMPARE_WITH( + framebuffer.read({{}, {64, 64}}, {PixelFormat::RGBA8Unorm}), + Utility::Directory::join(DEBUGTOOLS_TEST_DIR, "ObjectRenderer3D.tga"), + CompareImageToFile{_manager}); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::DebugTools::Test::ObjectRendererGLTest)