From 43c552aa0192933a28bf0b93ec1e8365f6aeb856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 31 Jul 2025 18:28:07 +0200 Subject: [PATCH] Shaders: properly test uniform struct trivial copyability. Somehow this wasn't done for any of the types and then the lack of tests got copied to the Ui library as well. Sigh. --- .../Shaders/Test/DistanceFieldVectorTest.cpp | 34 ++++++++ src/Magnum/Shaders/Test/FlatTest.cpp | 38 +++++++++ src/Magnum/Shaders/Test/GenericTest.cpp | 79 +++++++++++++++++++ src/Magnum/Shaders/Test/LineTest.cpp | 36 +++++++++ .../Shaders/Test/MeshVisualizerTest.cpp | 60 ++++++++++++++ src/Magnum/Shaders/Test/PhongTest.cpp | 60 ++++++++++++++ src/Magnum/Shaders/Test/VectorTest.cpp | 34 ++++++++ 7 files changed, 341 insertions(+) diff --git a/src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp b/src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp index 81401a1a9..bdfff2392 100644 --- a/src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp +++ b/src/Magnum/Shaders/Test/DistanceFieldVectorTest.cpp @@ -38,11 +38,13 @@ struct DistanceFieldVectorTest: TestSuite::Tester { void drawUniformConstructDefault(); void drawUniformConstructNoInit(); + void drawUniformConstructCopy(); void drawUniformSetters(); void drawUniformMaterialIdPacking(); void materialUniformConstructDefault(); void materialUniformConstructNoInit(); + void materialUniformConstructCopy(); void materialUniformSetters(); }; @@ -52,11 +54,13 @@ DistanceFieldVectorTest::DistanceFieldVectorTest() { &DistanceFieldVectorTest::drawUniformConstructDefault, &DistanceFieldVectorTest::drawUniformConstructNoInit, + &DistanceFieldVectorTest::drawUniformConstructCopy, &DistanceFieldVectorTest::drawUniformSetters, &DistanceFieldVectorTest::drawUniformMaterialIdPacking, &DistanceFieldVectorTest::materialUniformConstructDefault, &DistanceFieldVectorTest::materialUniformConstructNoInit, + &DistanceFieldVectorTest::materialUniformConstructCopy, &DistanceFieldVectorTest::materialUniformSetters}); } @@ -124,6 +128,20 @@ void DistanceFieldVectorTest::drawUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void DistanceFieldVectorTest::drawUniformConstructCopy() { + /* Testing only some fields, should be enough */ + DistanceFieldVectorDrawUniform a; + a.materialId = 76; + + DistanceFieldVectorDrawUniform b = a; + CORRADE_COMPARE(b.materialId, 76); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void DistanceFieldVectorTest::drawUniformSetters() { DistanceFieldVectorDrawUniform a; a.setMaterialId(76); @@ -196,6 +214,22 @@ void DistanceFieldVectorTest::materialUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void DistanceFieldVectorTest::materialUniformConstructCopy() { + /* Testing only some fields, should be enough */ + DistanceFieldVectorMaterialUniform a; + a.color = 0x354565fc_rgbaf; + a.outlineEnd = 0.37f; + + DistanceFieldVectorMaterialUniform b = a; + CORRADE_COMPARE(b.color, 0x354565fc_rgbaf); + CORRADE_COMPARE(b.outlineEnd, 0.37f); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void DistanceFieldVectorTest::materialUniformSetters() { DistanceFieldVectorMaterialUniform a; a.setColor(0x354565fc_rgbaf) diff --git a/src/Magnum/Shaders/Test/FlatTest.cpp b/src/Magnum/Shaders/Test/FlatTest.cpp index 4bf7f2dfa..7b1bc68f4 100644 --- a/src/Magnum/Shaders/Test/FlatTest.cpp +++ b/src/Magnum/Shaders/Test/FlatTest.cpp @@ -38,11 +38,13 @@ struct FlatTest: TestSuite::Tester { void drawUniformConstructDefault(); void drawUniformConstructNoInit(); + void drawUniformConstructCopy(); void drawUniformSetters(); void drawUniformMaterialIdPacking(); void materialUniformConstructDefault(); void materialUniformConstructNoInit(); + void materialUniformConstructCopy(); void materialUniformSetters(); }; @@ -52,11 +54,13 @@ FlatTest::FlatTest() { &FlatTest::drawUniformConstructDefault, &FlatTest::drawUniformConstructNoInit, + &FlatTest::drawUniformConstructCopy, &FlatTest::drawUniformSetters, &FlatTest::drawUniformMaterialIdPacking, &FlatTest::materialUniformConstructDefault, &FlatTest::materialUniformConstructNoInit, + &FlatTest::materialUniformConstructCopy, &FlatTest::materialUniformSetters}); } @@ -140,6 +144,24 @@ void FlatTest::drawUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void FlatTest::drawUniformConstructCopy() { + /* Testing only some fields, should be enough */ + FlatDrawUniform a; + a.materialId = 5; + a.objectId = 7; + a.perInstanceJointCount = 9; + + FlatDrawUniform b = a; + CORRADE_COMPARE(b.materialId, 5); + CORRADE_COMPARE(b.objectId, 7); + CORRADE_COMPARE(b.perInstanceJointCount, 9); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void FlatTest::drawUniformSetters() { FlatDrawUniform a; a.setMaterialId(5) @@ -214,6 +236,22 @@ void FlatTest::materialUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void FlatTest::materialUniformConstructCopy() { + /* Testing only some fields, should be enough */ + FlatMaterialUniform a; + a.color = 0x354565fc_rgbaf; + a.alphaMask = 0.7f; + + FlatMaterialUniform b = a; + CORRADE_COMPARE(b.color, 0x354565fc_rgbaf); + CORRADE_COMPARE(b.alphaMask, 0.7f); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void FlatTest::materialUniformSetters() { FlatMaterialUniform a; a.setColor(0x354565fc_rgbaf) diff --git a/src/Magnum/Shaders/Test/GenericTest.cpp b/src/Magnum/Shaders/Test/GenericTest.cpp index 59c102bed..26aef684a 100644 --- a/src/Magnum/Shaders/Test/GenericTest.cpp +++ b/src/Magnum/Shaders/Test/GenericTest.cpp @@ -38,22 +38,27 @@ struct GenericTest: TestSuite::Tester { void projectionUniform2DConstructDefault(); void projectionUniform2DConstructNoInit(); + void projectionUniform2DConstructCopy(); void projectionUniform2DSetters(); void projectionUniform3DConstructDefault(); void projectionUniform3DConstructNoInit(); + void projectionUniform3DConstructCopy(); void projectionUniform3DSetters(); void transformationUniform2DConstructDefault(); void transformationUniform2DConstructNoInit(); + void transformationUniform2DConstructCopy(); void transformationUniform2DSetters(); void transformationUniform3DConstructDefault(); void transformationUniform3DConstructNoInit(); + void transformationUniform3DConstructCopy(); void transformationUniform3DSetters(); void textureTransformationUniformConstructDefault(); void textureTransformationUniformConstructNoInit(); + void textureTransformationUniformConstructCopy(); void textureTransformationUniformSetters(); }; @@ -66,22 +71,27 @@ GenericTest::GenericTest() { &GenericTest::projectionUniform2DConstructDefault, &GenericTest::projectionUniform2DConstructNoInit, + &GenericTest::projectionUniform2DConstructCopy, &GenericTest::projectionUniform2DSetters, &GenericTest::projectionUniform3DConstructDefault, &GenericTest::projectionUniform3DConstructNoInit, + &GenericTest::projectionUniform3DConstructCopy, &GenericTest::projectionUniform3DSetters, &GenericTest::transformationUniform2DConstructDefault, &GenericTest::transformationUniform2DConstructNoInit, + &GenericTest::transformationUniform2DConstructCopy, &GenericTest::transformationUniform2DSetters, &GenericTest::transformationUniform3DConstructDefault, &GenericTest::transformationUniform3DConstructNoInit, + &GenericTest::transformationUniform3DConstructCopy, &GenericTest::transformationUniform3DSetters, &GenericTest::textureTransformationUniformConstructDefault, &GenericTest::textureTransformationUniformConstructNoInit, + &GenericTest::textureTransformationUniformConstructCopy, &GenericTest::textureTransformationUniformSetters}); } @@ -173,6 +183,19 @@ void GenericTest::projectionUniform2DConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void GenericTest::projectionUniform2DConstructCopy() { + ProjectionUniform2D a; + a.projectionMatrix[2] = {1.5f, 0.3f, 3.1f, 0.5f}; + + ProjectionUniform2D b = a; + CORRADE_COMPARE(b.projectionMatrix[2], (Vector4{1.5f, 0.3f, 3.1f, 0.5f})); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void GenericTest::projectionUniform2DSetters() { ProjectionUniform2D a; a.setProjectionMatrix(Matrix3::projection({2.5f, 3.0f})); @@ -242,6 +265,19 @@ void GenericTest::projectionUniform3DConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void GenericTest::projectionUniform3DConstructCopy() { + ProjectionUniform3D a; + a.projectionMatrix[2] = {1.5f, 0.3f, 3.1f, 0.5f}; + + ProjectionUniform3D b = a; + CORRADE_COMPARE(b.projectionMatrix[2], (Vector4{1.5f, 0.3f, 3.1f, 0.5f})); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void GenericTest::projectionUniform3DSetters() { ProjectionUniform3D a; a.setProjectionMatrix(Matrix4::perspectiveProjection(35.0_degf, 1.5f, 0.1f, 100.0f)); @@ -303,6 +339,19 @@ void GenericTest::transformationUniform2DConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void GenericTest::transformationUniform2DConstructCopy() { + TransformationUniform2D a; + a.transformationMatrix[2] = {1.5f, 0.3f, 3.1f, 0.5f}; + + TransformationUniform2D b = a; + CORRADE_COMPARE(b.transformationMatrix[2], (Vector4{1.5f, 0.3f, 3.1f, 0.5f})); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void GenericTest::transformationUniform2DSetters() { TransformationUniform2D a; a.setTransformationMatrix(Matrix3::translation({2.5f, 3.0f})); @@ -372,6 +421,19 @@ void GenericTest::transformationUniform3DConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void GenericTest::transformationUniform3DConstructCopy() { + TransformationUniform3D a; + a.transformationMatrix[2] = {1.5f, 0.3f, 3.1f, 0.5f}; + + TransformationUniform3D b = a; + CORRADE_COMPARE(b.transformationMatrix[2], (Vector4{1.5f, 0.3f, 3.1f, 0.5f})); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void GenericTest::transformationUniform3DSetters() { TransformationUniform3D a; a.setTransformationMatrix(Matrix4::translation({3.5f, 2.0f, -1.0f})); @@ -441,6 +503,23 @@ void GenericTest::textureTransformationUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void GenericTest::textureTransformationUniformConstructCopy() { + TextureTransformationUniform a; + a.rotationScaling[1] = {2.5f, -3.0f}; + a.offset = {2.7f, 0.3f}; + a.layer = 37; + + TextureTransformationUniform b = a; + CORRADE_COMPARE(b.rotationScaling[1], (Vector2{2.5f, -3.0f})); + CORRADE_COMPARE(b.offset, (Vector2{2.7f, 0.3f})); + CORRADE_COMPARE(b.layer, 37); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void GenericTest::textureTransformationUniformSetters() { TextureTransformationUniform a; a.setTextureMatrix(Matrix3::translation({2.6f, 0.3f})* diff --git a/src/Magnum/Shaders/Test/LineTest.cpp b/src/Magnum/Shaders/Test/LineTest.cpp index 58995c75f..452b4abb6 100644 --- a/src/Magnum/Shaders/Test/LineTest.cpp +++ b/src/Magnum/Shaders/Test/LineTest.cpp @@ -42,11 +42,13 @@ struct LineTest: TestSuite::Tester { void drawUniformConstructDefault(); void drawUniformConstructNoInit(); + void drawUniformConstructCopy(); void drawUniformSetters(); void drawUniformMaterialIdPacking(); void materialUniformConstructDefault(); void materialUniformConstructNoInit(); + void materialUniformConstructCopy(); void materialUniformSetters(); /* Miter limit tests are copied verbatim between the Shaders and Ui @@ -93,11 +95,13 @@ LineTest::LineTest() { &LineTest::drawUniformConstructDefault, &LineTest::drawUniformConstructNoInit, + &LineTest::drawUniformConstructCopy, &LineTest::drawUniformSetters, &LineTest::drawUniformMaterialIdPacking, &LineTest::materialUniformConstructDefault, &LineTest::materialUniformConstructNoInit, + &LineTest::materialUniformConstructCopy, &LineTest::materialUniformSetters, &LineTest::materialUniformMiterLimit}); @@ -184,6 +188,22 @@ void LineTest::drawUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void LineTest::drawUniformConstructCopy() { + /* Testing only some fields, should be enough */ + LineDrawUniform a; + a.materialId = 5; + a.objectId = 7; + + LineDrawUniform b = a; + CORRADE_COMPARE(b.materialId, 5); + CORRADE_COMPARE(b.objectId, 7); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void LineTest::drawUniformSetters() { LineDrawUniform a; a.setMaterialId(5) @@ -258,6 +278,22 @@ void LineTest::materialUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void LineTest::materialUniformConstructCopy() { + /* Testing only some fields, should be enough */ + LineMaterialUniform a; + a.color = 0x354565fc_rgbaf; + a.smoothness = 7.0f; + + LineMaterialUniform b = a; + CORRADE_COMPARE(b.color, 0x354565fc_rgbaf); + CORRADE_COMPARE(b.smoothness, 7.0f); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void LineTest::materialUniformSetters() { LineMaterialUniform a; a.setBackgroundColor(0x01020304_rgbaf) diff --git a/src/Magnum/Shaders/Test/MeshVisualizerTest.cpp b/src/Magnum/Shaders/Test/MeshVisualizerTest.cpp index b362cddb0..767e0dea4 100644 --- a/src/Magnum/Shaders/Test/MeshVisualizerTest.cpp +++ b/src/Magnum/Shaders/Test/MeshVisualizerTest.cpp @@ -39,16 +39,19 @@ struct MeshVisualizerTest: TestSuite::Tester { void drawUniform2DConstructDefault(); void drawUniform2DConstructNoInit(); + void drawUniform2DConstructCopy(); void drawUniform2DSetters(); void drawUniform2DMaterialIdPacking(); void drawUniform3DConstructDefault(); void drawUniform3DConstructNoInit(); + void drawUniform3DConstructCopy(); void drawUniform3DSetters(); void drawUniform3DMaterialIdPacking(); void materialUniformConstructDefault(); void materialUniformConstructNoInit(); + void materialUniformConstructCopy(); void materialUniformSetters(); }; @@ -59,16 +62,19 @@ MeshVisualizerTest::MeshVisualizerTest() { &MeshVisualizerTest::drawUniform2DConstructDefault, &MeshVisualizerTest::drawUniform2DConstructNoInit, + &MeshVisualizerTest::drawUniform2DConstructCopy, &MeshVisualizerTest::drawUniform2DSetters, &MeshVisualizerTest::drawUniform2DMaterialIdPacking, &MeshVisualizerTest::drawUniform3DConstructDefault, &MeshVisualizerTest::drawUniform3DConstructNoInit, + &MeshVisualizerTest::drawUniform3DConstructCopy, &MeshVisualizerTest::drawUniform3DSetters, &MeshVisualizerTest::drawUniform3DMaterialIdPacking, &MeshVisualizerTest::materialUniformConstructDefault, &MeshVisualizerTest::materialUniformConstructNoInit, + &MeshVisualizerTest::materialUniformConstructCopy, &MeshVisualizerTest::materialUniformSetters}); } @@ -155,6 +161,24 @@ void MeshVisualizerTest::drawUniform2DConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void MeshVisualizerTest::drawUniform2DConstructCopy() { + /* Testing only some fields, should be enough */ + MeshVisualizerDrawUniform2D a; + a.materialId = 73; + a.objectId = 7; + a.perInstanceJointCount = 9; + + MeshVisualizerDrawUniform2D b = a; + CORRADE_COMPARE(b.materialId, 73); + CORRADE_COMPARE(b.objectId, 7); + CORRADE_COMPARE(b.perInstanceJointCount, 9); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void MeshVisualizerTest::drawUniform2DSetters() { MeshVisualizerDrawUniform2D a; a.setMaterialId(73) @@ -261,6 +285,26 @@ void MeshVisualizerTest::drawUniform3DConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void MeshVisualizerTest::drawUniform3DConstructCopy() { + /* Testing only some fields, should be enough */ + MeshVisualizerDrawUniform3D a; + a.normalMatrix[2] = {1.5f, 0.3f, 3.1f, 0.5f}; + a.materialId = 5; + a.objectId = 7; + a.perInstanceJointCount = 9; + + MeshVisualizerDrawUniform3D b = a; + CORRADE_COMPARE(b.normalMatrix[2], (Vector4{1.5f, 0.3f, 3.1f, 0.5f})); + CORRADE_COMPARE(b.materialId, 5); + CORRADE_COMPARE(b.objectId, 7); + CORRADE_COMPARE(b.perInstanceJointCount, 9); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void MeshVisualizerTest::drawUniform3DSetters() { MeshVisualizerDrawUniform3D a; a.setNormalMatrix(Matrix4::rotationX(90.0_degf).normalMatrix()) @@ -365,6 +409,22 @@ void MeshVisualizerTest::materialUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void MeshVisualizerTest::materialUniformConstructCopy() { + /* Testing only some fields, should be enough */ + MeshVisualizerMaterialUniform a; + a.color = 0x354565fc_rgbaf; + a.lineWidth = 0.765f; + + MeshVisualizerMaterialUniform b = a; + CORRADE_COMPARE(b.color, 0x354565fc_rgbaf); + CORRADE_COMPARE(b.lineWidth, 0.765f); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void MeshVisualizerTest::materialUniformSetters() { MeshVisualizerMaterialUniform a; a.setColor(0x354565fc_rgbaf) diff --git a/src/Magnum/Shaders/Test/PhongTest.cpp b/src/Magnum/Shaders/Test/PhongTest.cpp index 4fd6fc1e2..d92912ce7 100644 --- a/src/Magnum/Shaders/Test/PhongTest.cpp +++ b/src/Magnum/Shaders/Test/PhongTest.cpp @@ -39,15 +39,18 @@ struct PhongTest: TestSuite::Tester { void drawUniformConstructDefault(); void drawUniformConstructNoInit(); + void drawUniformConstructCopy(); void drawUniformSetters(); void drawUniformPacking(); void materialUniformConstructDefault(); void materialUniformConstructNoInit(); + void materialUniformConstructCopy(); void materialUniformSetters(); void lightUniformConstructDefault(); void lightUniformConstructNoInit(); + void lightUniformConstructCopy(); void lightUniformSetters(); }; @@ -58,15 +61,18 @@ PhongTest::PhongTest() { &PhongTest::drawUniformConstructDefault, &PhongTest::drawUniformConstructNoInit, + &PhongTest::drawUniformConstructCopy, &PhongTest::drawUniformSetters, &PhongTest::drawUniformPacking, &PhongTest::materialUniformConstructDefault, &PhongTest::materialUniformConstructNoInit, + &PhongTest::materialUniformConstructCopy, &PhongTest::materialUniformSetters, &PhongTest::lightUniformConstructDefault, &PhongTest::lightUniformConstructNoInit, + &PhongTest::lightUniformConstructCopy, &PhongTest::lightUniformSetters}); } @@ -183,6 +189,26 @@ void PhongTest::drawUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void PhongTest::drawUniformConstructCopy() { + /* Testing only some fields, should be enough */ + PhongDrawUniform a; + a.normalMatrix[2] = {1.5f, 0.3f, 3.1f, 0.5f}; + a.materialId = 5; + a.lightCount = 7; + a.perInstanceJointCount = 9; + + PhongDrawUniform b = a; + CORRADE_COMPARE(b.normalMatrix[2], (Vector4{1.5f, 0.3f, 3.1f, 0.5f})); + CORRADE_COMPARE(b.materialId, 5); + CORRADE_COMPARE(b.lightCount, 7); + CORRADE_COMPARE(b.perInstanceJointCount, 9); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void PhongTest::drawUniformSetters() { PhongDrawUniform a; a.setNormalMatrix(Matrix4::rotationX(90.0_degf).normalMatrix()) @@ -290,6 +316,24 @@ void PhongTest::materialUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void PhongTest::materialUniformConstructCopy() { + /* Testing only some fields, should be enough */ + PhongMaterialUniform a; + a.diffuseColor = 0x354565fc_rgbaf; + a.normalTextureScale = 0.4f; + a.alphaMask = 7.0f; + + PhongMaterialUniform b = a; + CORRADE_COMPARE(b.diffuseColor, 0x354565fc_rgbaf); + CORRADE_COMPARE(b.normalTextureScale, 0.4f); + CORRADE_COMPARE(b.alphaMask, 7.0f); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void PhongTest::materialUniformSetters() { PhongMaterialUniform a; a.setAmbientColor(0xff3366cc_rgbaf) @@ -360,6 +404,22 @@ void PhongTest::lightUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void PhongTest::lightUniformConstructCopy() { + /* Testing only some fields, should be enough */ + PhongLightUniform a; + a.color = 0x354565_rgbf; + a.range = 7.0f; + + PhongLightUniform b = a; + CORRADE_COMPARE(b.color, 0x354565_rgbf); + CORRADE_COMPARE(b.range, 7.0f); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void PhongTest::lightUniformSetters() { PhongLightUniform a; a.setPosition({2.5f, 3.6f, 0.7f, 1.1f}) diff --git a/src/Magnum/Shaders/Test/VectorTest.cpp b/src/Magnum/Shaders/Test/VectorTest.cpp index 2635c4418..f5b2064c6 100644 --- a/src/Magnum/Shaders/Test/VectorTest.cpp +++ b/src/Magnum/Shaders/Test/VectorTest.cpp @@ -38,11 +38,13 @@ struct VectorTest: TestSuite::Tester { void drawUniformConstructDefault(); void drawUniformConstructNoInit(); + void drawUniformConstructCopy(); void drawUniformSetters(); void drawUniformMaterialIdPacking(); void materialUniformConstructDefault(); void materialUniformConstructNoInit(); + void materialUniformConstructCopy(); void materialUniformSetters(); }; @@ -52,11 +54,13 @@ VectorTest::VectorTest() { &VectorTest::drawUniformConstructDefault, &VectorTest::drawUniformConstructNoInit, + &VectorTest::drawUniformConstructCopy, &VectorTest::drawUniformSetters, &VectorTest::drawUniformMaterialIdPacking, &VectorTest::materialUniformConstructDefault, &VectorTest::materialUniformConstructNoInit, + &VectorTest::materialUniformConstructCopy, &VectorTest::materialUniformSetters}); } @@ -124,6 +128,20 @@ void VectorTest::drawUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void VectorTest::drawUniformConstructCopy() { + /* Testing only some fields, should be enough */ + VectorDrawUniform a; + a.materialId = 5; + + VectorDrawUniform b = a; + CORRADE_COMPARE(b.materialId, 5); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void VectorTest::drawUniformSetters() { VectorDrawUniform a; a.setMaterialId(5); @@ -184,6 +202,22 @@ void VectorTest::materialUniformConstructNoInit() { CORRADE_VERIFY(!std::is_convertible::value); } +void VectorTest::materialUniformConstructCopy() { + /* Testing only some fields, should be enough */ + VectorMaterialUniform a; + a.color = 0x354565fc_rgbaf; + a.backgroundColor = 0x98769fac_rgbaf; + + VectorMaterialUniform b = a; + CORRADE_COMPARE(b.color, 0x354565fc_rgbaf); + CORRADE_COMPARE(b.backgroundColor, 0x98769fac_rgbaf); + + #ifndef CORRADE_NO_STD_IS_TRIVIALLY_TRAITS + CORRADE_VERIFY(std::is_trivially_copy_constructible::value); + CORRADE_VERIFY(std::is_trivially_copy_assignable::value); + #endif +} + void VectorTest::materialUniformSetters() { VectorMaterialUniform a; a.setColor(0x354565fc_rgbaf)