From 89d6d6de7cb114d3ef353318a40b50fe2c99669d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 18 Jan 2020 19:35:00 +0100 Subject: [PATCH] Shaders: port tests away from MeshDataXD. --- .../Test/DistanceFieldVectorGLTest.cpp | 3 +-- src/Magnum/Shaders/Test/FlatGLTest.cpp | 11 +++++------ .../Shaders/Test/MeshVisualizerGLTest.cpp | 14 ++++---------- src/Magnum/Shaders/Test/PhongGLTest.cpp | 12 ++++++------ src/Magnum/Shaders/Test/VectorGLTest.cpp | 3 +-- src/Magnum/Shaders/Test/VertexColorGLTest.cpp | 19 +++++++++---------- 6 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp b/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp index 010ece013..84e7681d7 100644 --- a/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp +++ b/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp @@ -48,8 +48,7 @@ #include "Magnum/Shaders/DistanceFieldVector.h" #include "Magnum/Trade/AbstractImporter.h" #include "Magnum/Trade/ImageData.h" -#include "Magnum/Trade/MeshData2D.h" -#include "Magnum/Trade/MeshData3D.h" +#include "Magnum/Trade/MeshData.h" #include "configure.h" diff --git a/src/Magnum/Shaders/Test/FlatGLTest.cpp b/src/Magnum/Shaders/Test/FlatGLTest.cpp index 799026f36..e70cf2ef7 100644 --- a/src/Magnum/Shaders/Test/FlatGLTest.cpp +++ b/src/Magnum/Shaders/Test/FlatGLTest.cpp @@ -52,8 +52,7 @@ #include "Magnum/Shaders/Flat.h" #include "Magnum/Trade/AbstractImporter.h" #include "Magnum/Trade/ImageData.h" -#include "Magnum/Trade/MeshData2D.h" -#include "Magnum/Trade/MeshData3D.h" +#include "Magnum/Trade/MeshData.h" #include "configure.h" @@ -640,11 +639,11 @@ template void FlatGLTest::renderVertexColor2D() { !(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); - Trade::MeshData2D circleData = Primitives::circle2DSolid(32, + Trade::MeshData circleData = Primitives::circle2DSolid(32, Primitives::CircleTextureCoords::Generate); /* Highlight a quarter */ - Containers::Array colorData{Containers::DirectInit, circleData.positions(0).size(), 0x999999_rgbf}; + Containers::Array colorData{Containers::DirectInit, circleData.vertexCount(), 0x999999_rgbf}; for(std::size_t i = 8; i != 16; ++i) colorData[i + 1] = 0xffff99_rgbf*1.5f; @@ -694,11 +693,11 @@ template void FlatGLTest::renderVertexColor3D() { !(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); - Trade::MeshData3D sphereData = Primitives::uvSphereSolid(16, 32, + Trade::MeshData sphereData = Primitives::uvSphereSolid(16, 32, Primitives::UVSphereTextureCoords::Generate); /* Highlight the middle rings */ - Containers::Array colorData{Containers::DirectInit, sphereData.positions(0).size(), 0x999999_rgbf}; + Containers::Array colorData{Containers::DirectInit, sphereData.vertexCount(), 0x999999_rgbf}; for(std::size_t i = 6*33; i != 9*33; ++i) colorData[i + 1] = 0xffff99_rgbf*1.5f; diff --git a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp index a4326883d..1a574cdfc 100644 --- a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp +++ b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp @@ -51,8 +51,7 @@ #include "Magnum/Primitives/UVSphere.h" #include "Magnum/Shaders/MeshVisualizer.h" #include "Magnum/Trade/AbstractImporter.h" -#include "Magnum/Trade/MeshData2D.h" -#include "Magnum/Trade/MeshData3D.h" +#include "Magnum/Trade/MeshData.h" #include "configure.h" @@ -409,24 +408,19 @@ void MeshVisualizerGLTest::renderWireframe() { #endif #endif - const Trade::MeshData3D sphereData = Primitives::icosphereSolid(1); + const Trade::MeshData sphereData = Primitives::icosphereSolid(1); GL::Mesh sphere{NoCreate}; if(data.flags & MeshVisualizer::Flag::NoGeometryShader) { - sphere = GL::Mesh{}; - sphere.setCount(sphereData.indices().size()); - /* Duplicate the vertices */ - GL::Buffer positions; - positions.setData(MeshTools::duplicate(Containers::stridedArrayView(sphereData.indices()), Containers::stridedArrayView(sphereData.positions(0)))); - sphere.addVertexBuffer(std::move(positions), 0, MeshVisualizer::Position{}); + sphere = MeshTools::compile(MeshTools::duplicate(sphereData)); /* Supply also the vertex ID, if needed */ #ifndef MAGNUM_TARGET_GLES2 if(!GL::Context::current().isExtensionSupported()) #endif { - Containers::Array vertexIndex{sphereData.indices().size()}; + Containers::Array vertexIndex{sphereData.indexCount()}; std::iota(vertexIndex.begin(), vertexIndex.end(), 0.0f); GL::Buffer vertexId; diff --git a/src/Magnum/Shaders/Test/PhongGLTest.cpp b/src/Magnum/Shaders/Test/PhongGLTest.cpp index 424861056..0e5b73d6d 100644 --- a/src/Magnum/Shaders/Test/PhongGLTest.cpp +++ b/src/Magnum/Shaders/Test/PhongGLTest.cpp @@ -51,8 +51,8 @@ #include "Magnum/Primitives/UVSphere.h" #include "Magnum/Shaders/Phong.h" #include "Magnum/Trade/AbstractImporter.h" -#include "Magnum/Trade/MeshData3D.h" #include "Magnum/Trade/ImageData.h" +#include "Magnum/Trade/MeshData.h" #include "configure.h" @@ -506,12 +506,12 @@ void PhongGLTest::renderDefaults() { /* The light is at the center by default, so we scale the sphere to half and move the vertices back a bit to avoid a fully-black render but still have the thing in the default [-1; 1] cube */ - Trade::MeshData3D meshData = Primitives::uvSphereSolid(16, 32); + Trade::MeshData meshData = Primitives::uvSphereSolid(16, 32); Matrix4 transformation = Matrix4::translation(Vector3::zAxis(-1.0f))*Matrix4::scaling(Vector3(1.0f, 1.0f, 0.25f)); - MeshTools::transformPointsInPlace(transformation, meshData.positions(0)); + MeshTools::transformPointsInPlace(transformation, meshData.mutableAttribute(Trade::MeshAttribute::Position)); /** @todo use Matrix4::normalMatrix() */ - MeshTools::transformVectorsInPlace(transformation.inverted().transposed(), meshData.normals(0)); + MeshTools::transformVectorsInPlace(transformation.inverted().transposed(), meshData.mutableAttribute(Trade::MeshAttribute::Normal)); GL::Mesh sphere = MeshTools::compile(meshData); Phong shader; @@ -854,11 +854,11 @@ template void PhongGLTest::renderVertexColor() { !(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); - Trade::MeshData3D sphereData = Primitives::uvSphereSolid(16, 32, + Trade::MeshData sphereData = Primitives::uvSphereSolid(16, 32, Primitives::UVSphereTextureCoords::Generate); /* Highlight the middle rings */ - Containers::Array colorData{Containers::DirectInit, sphereData.positions(0).size(), 0x999999_rgbf}; + Containers::Array colorData{Containers::DirectInit, sphereData.vertexCount(), 0x999999_rgbf}; for(std::size_t i = 6*33; i != 9*33; ++i) colorData[i + 1] = 0xffff99_rgbf*1.5f; diff --git a/src/Magnum/Shaders/Test/VectorGLTest.cpp b/src/Magnum/Shaders/Test/VectorGLTest.cpp index 6cf2abccc..4abe9c71f 100644 --- a/src/Magnum/Shaders/Test/VectorGLTest.cpp +++ b/src/Magnum/Shaders/Test/VectorGLTest.cpp @@ -48,8 +48,7 @@ #include "Magnum/Shaders/Vector.h" #include "Magnum/Trade/AbstractImporter.h" #include "Magnum/Trade/ImageData.h" -#include "Magnum/Trade/MeshData2D.h" -#include "Magnum/Trade/MeshData3D.h" +#include "Magnum/Trade/MeshData.h" #include "configure.h" diff --git a/src/Magnum/Shaders/Test/VertexColorGLTest.cpp b/src/Magnum/Shaders/Test/VertexColorGLTest.cpp index 3c0dc7e20..85cf56ab5 100644 --- a/src/Magnum/Shaders/Test/VertexColorGLTest.cpp +++ b/src/Magnum/Shaders/Test/VertexColorGLTest.cpp @@ -44,8 +44,7 @@ #include "Magnum/Primitives/UVSphere.h" #include "Magnum/Shaders/VertexColor.h" #include "Magnum/Trade/AbstractImporter.h" -#include "Magnum/Trade/MeshData2D.h" -#include "Magnum/Trade/MeshData3D.h" +#include "Magnum/Trade/MeshData.h" #include "configure.h" @@ -197,11 +196,11 @@ void VertexColorGLTest::renderTeardown() { template void VertexColorGLTest::renderDefaults2D() { setTestCaseTemplateName(T::Size == 3 ? "Color3" : "Color4"); - Trade::MeshData2D circleData = Primitives::circle2DSolid(32, + Trade::MeshData circleData = Primitives::circle2DSolid(32, Primitives::CircleTextureCoords::Generate); /* All a single color */ - Containers::Array colorData{Containers::DirectInit, circleData.positions(0).size(), 0xffffff_rgbf}; + Containers::Array colorData{Containers::DirectInit, circleData.vertexCount(), 0xffffff_rgbf}; GL::Buffer colors; colors.setData(colorData); @@ -238,11 +237,11 @@ template void VertexColorGLTest::renderDefaults3D() { !(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); - Trade::MeshData3D sphereData = Primitives::uvSphereSolid(16, 32, + Trade::MeshData sphereData = Primitives::uvSphereSolid(16, 32, Primitives::UVSphereTextureCoords::Generate); /* All a single color */ - Containers::Array colorData{Containers::DirectInit, sphereData.positions(0).size(), 0xffffff_rgbf}; + Containers::Array colorData{Containers::DirectInit, sphereData.vertexCount(), 0xffffff_rgbf}; GL::Buffer colors; colors.setData(colorData); @@ -271,11 +270,11 @@ template void VertexColorGLTest::renderDefaults3D() { template void VertexColorGLTest::render2D() { setTestCaseTemplateName(T::Size == 3 ? "Color3" : "Color4"); - Trade::MeshData2D circleData = Primitives::circle2DSolid(32, + Trade::MeshData circleData = Primitives::circle2DSolid(32, Primitives::CircleTextureCoords::Generate); /* Highlight a quarter */ - Containers::Array colorData{Containers::DirectInit, circleData.positions(0).size(), 0x9999ff_rgbf}; + Containers::Array colorData{Containers::DirectInit, circleData.vertexCount(), 0x9999ff_rgbf}; for(std::size_t i = 8; i != 16; ++i) colorData[i + 1] = 0xffff99_rgbf; @@ -316,11 +315,11 @@ template void VertexColorGLTest::render3D() { !(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded)) CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found."); - Trade::MeshData3D sphereData = Primitives::uvSphereSolid(16, 32, + Trade::MeshData sphereData = Primitives::uvSphereSolid(16, 32, Primitives::UVSphereTextureCoords::Generate); /* Highlight the middle rings */ - Containers::Array colorData{Containers::DirectInit, sphereData.positions(0).size(), 0x9999ff_rgbf}; + Containers::Array colorData{Containers::DirectInit, sphereData.vertexCount(), 0x9999ff_rgbf}; for(std::size_t i = 6*33; i != 9*33; ++i) colorData[i + 1] = 0xffff99_rgbf;