Browse Source

MeshTools: handle the ObjectId attribute in compile().

And that's the last warning fixed.
pull/432/head
Vladimír Vondruš 6 years ago
parent
commit
ea3bcb6d93
  1. 20
      src/Magnum/MeshTools/Compile.cpp
  2. 342
      src/Magnum/MeshTools/Test/CompileGLTest.cpp

20
src/Magnum/MeshTools/Compile.cpp

@ -108,14 +108,24 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices,
case Trade::MeshAttribute::Normal: case Trade::MeshAttribute::Normal:
attribute.emplace(Shaders::Generic3D::Normal{}, format); attribute.emplace(Shaders::Generic3D::Normal{}, format);
break; break;
#ifndef MAGNUM_TARGET_GLES2
/* So it doesn't yell that we didn't handle a known attribute */ case Trade::MeshAttribute::ObjectId:
case Trade::MeshAttribute::Custom: break; /* LCOV_EXCL_LINE */ attribute.emplace(Shaders::Generic3D::ObjectId{}, format);
break;
#endif
/* To avoid the compiler warning that we didn't handle an enum
value. For these a runtime warning is printed below. */
#ifdef MAGNUM_TARGET_GLES2
case Trade::MeshAttribute::ObjectId:
#endif
case Trade::MeshAttribute::Custom:
break; /* LCOV_EXCL_LINE */
} }
if(!attribute) { if(!attribute) {
if(!(flags & CompileFlag::NoWarnOnCustomAttributes)) if(!Trade::isMeshAttributeCustom(meshData.attributeName(i)) || !(flags & CompileFlag::NoWarnOnCustomAttributes))
Warning{} << "MeshTools::compile(): ignoring unknown attribute" << meshData.attributeName(i); Warning{} << "MeshTools::compile(): ignoring unknown/unsupported attribute" << meshData.attributeName(i);
continue; continue;
} }

342
src/Magnum/MeshTools/Test/CompileGLTest.cpp

@ -75,7 +75,8 @@ enum class Flag {
GeneratedFlatNormals = 1 << 5, GeneratedFlatNormals = 1 << 5,
GeneratedSmoothNormals = 1 << 6, GeneratedSmoothNormals = 1 << 6,
TextureCoordinates2D = 1 << 7, TextureCoordinates2D = 1 << 7,
Colors = 1 << 8 Colors = 1 << 8,
ObjectId = 1 << 9
}; };
typedef Containers::EnumSet<Flag> Flags; typedef Containers::EnumSet<Flag> Flags;
@ -93,6 +94,9 @@ struct CompileGLTest: GL::OpenGLTester {
public: public:
explicit CompileGLTest(); explicit CompileGLTest();
void renderSetup();
void renderTeardown();
/** @todo remove the template once MeshDataXD is gone */ /** @todo remove the template once MeshDataXD is gone */
template<class T> void twoDimensions(); template<class T> void twoDimensions();
template<class T> void threeDimensions(); template<class T> void threeDimensions();
@ -100,7 +104,9 @@ struct CompileGLTest: GL::OpenGLTester {
void packedAttributes(); void packedAttributes();
void customAttribute(); void customAttribute();
void unsupportedAttribute();
void implementationSpecificAttributeFormat(); void implementationSpecificAttributeFormat();
void generateNormalsNoPosition(); void generateNormalsNoPosition();
void generateNormals2DPosition(); void generateNormals2DPosition();
void generateNormalsNoFloats(); void generateNormalsNoFloats();
@ -113,8 +119,14 @@ struct CompileGLTest: GL::OpenGLTester {
Shaders::Flat2D _flat2D; Shaders::Flat2D _flat2D;
Shaders::Flat2D _flatTextured2D{Shaders::Flat2D::Flag::Textured}; Shaders::Flat2D _flatTextured2D{Shaders::Flat2D::Flag::Textured};
#ifndef MAGNUM_TARGET_GLES2
Shaders::Flat2D _flatObjectId2D{Shaders::Flat2D::Flag::InstancedObjectId};
#endif
Shaders::Flat3D _flat3D; Shaders::Flat3D _flat3D;
Shaders::Flat3D _flatTextured3D{Shaders::Flat3D::Flag::Textured}; Shaders::Flat3D _flatTextured3D{Shaders::Flat3D::Flag::Textured};
#ifndef MAGNUM_TARGET_GLES2
Shaders::Flat3D _flatObjectId3D{Shaders::Flat3D::Flag::InstancedObjectId};
#endif
Shaders::VertexColor2D _color2D; Shaders::VertexColor2D _color2D;
Shaders::VertexColor3D _color3D; Shaders::VertexColor3D _color3D;
Shaders::Phong _phong; Shaders::Phong _phong;
@ -124,6 +136,9 @@ struct CompileGLTest: GL::OpenGLTester {
#endif #endif
GL::Renderbuffer _color; GL::Renderbuffer _color;
#ifndef MAGNUM_TARGET_GLES2
GL::Renderbuffer _objectId;
#endif
GL::Framebuffer _framebuffer{{{}, {32, 32}}}; GL::Framebuffer _framebuffer{{{}, {32, 32}}};
GL::Texture2D _texture; GL::Texture2D _texture;
}; };
@ -136,7 +151,8 @@ constexpr struct {
{"positions, nonindexed", Flag::NonIndexed}, {"positions, nonindexed", Flag::NonIndexed},
{"positions + colors", Flag::Colors}, {"positions + colors", Flag::Colors},
{"positions + texture coordinates", Flag::TextureCoordinates2D}, {"positions + texture coordinates", Flag::TextureCoordinates2D},
{"positions + texture coordinates + colors", Flag::TextureCoordinates2D|Flag::Colors} {"positions + texture coordinates + colors", Flag::TextureCoordinates2D|Flag::Colors},
{"positions, object id, nonindexed", Flag::ObjectId|Flag::NonIndexed}
}; };
constexpr struct { constexpr struct {
@ -168,7 +184,8 @@ constexpr struct {
{"positions, gen smooth normals + texcoords + colors", Flag::GeneratedSmoothNormals|Flag::TextureCoordinates2D|Flag::Colors}, {"positions, gen smooth normals + texcoords + colors", Flag::GeneratedSmoothNormals|Flag::TextureCoordinates2D|Flag::Colors},
{"positions, nonindexed + gen smooth normals", Flag::NonIndexed|Flag::GeneratedSmoothNormals}, {"positions, nonindexed + gen smooth normals", Flag::NonIndexed|Flag::GeneratedSmoothNormals},
{"positions, tangents, bitangents, normals", Flag::Tangents|Flag::Bitangents|Flag::Normals}, {"positions, tangents, bitangents, normals", Flag::Tangents|Flag::Bitangents|Flag::Normals},
{"positions, tangents, bitangents from tangents, normals", Flag::Tangents|Flag::BitangentsFromTangents|Flag::Normals} {"positions, tangents, bitangents from tangents, normals", Flag::Tangents|Flag::BitangentsFromTangents|Flag::Normals},
{"positions, object id, nonindexed", Flag::ObjectId|Flag::NonIndexed}
}; };
constexpr struct { constexpr struct {
@ -201,31 +218,43 @@ constexpr Color4ub ImageData[] {
CompileGLTest::CompileGLTest() { CompileGLTest::CompileGLTest() {
addInstancedTests<CompileGLTest>({ addInstancedTests<CompileGLTest>({
&CompileGLTest::twoDimensions<Trade::MeshData>}, Containers::arraySize(Data2D)); &CompileGLTest::twoDimensions<Trade::MeshData>},
Containers::arraySize(Data2D),
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
addInstancedTests<CompileGLTest>({ addInstancedTests<CompileGLTest>({
&CompileGLTest::twoDimensions<Trade::MeshData2D>}, &CompileGLTest::twoDimensions<Trade::MeshData2D>},
Containers::arraySize(Data2D)); Containers::arraySize(Data2D),
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
addInstancedTests<CompileGLTest>({ addInstancedTests<CompileGLTest>({
&CompileGLTest::threeDimensions<Trade::MeshData>}, &CompileGLTest::threeDimensions<Trade::MeshData>},
Containers::arraySize(Data3D)); Containers::arraySize(Data3D),
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
addInstancedTests<CompileGLTest>({ addInstancedTests<CompileGLTest>({
&CompileGLTest::threeDimensions<Trade::MeshData3D>}, &CompileGLTest::threeDimensions<Trade::MeshData3D>},
Containers::arraySize(Data3D)); Containers::arraySize(Data3D),
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
addTests({&CompileGLTest::packedAttributes}); addTests({&CompileGLTest::packedAttributes},
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
addInstancedTests({&CompileGLTest::customAttribute, addInstancedTests({&CompileGLTest::customAttribute,
&CompileGLTest::unsupportedAttribute,
&CompileGLTest::implementationSpecificAttributeFormat}, &CompileGLTest::implementationSpecificAttributeFormat},
Containers::arraySize(CustomAttributeWarningData)); Containers::arraySize(CustomAttributeWarningData));
@ -234,7 +263,9 @@ CompileGLTest::CompileGLTest() {
&CompileGLTest::generateNormalsNoFloats}); &CompileGLTest::generateNormalsNoFloats});
addInstancedTests({&CompileGLTest::externalBuffers}, addInstancedTests({&CompileGLTest::externalBuffers},
Containers::arraySize(DataExternal)); Containers::arraySize(DataExternal),
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
addTests({&CompileGLTest::externalBuffersInvalid}); addTests({&CompileGLTest::externalBuffersInvalid});
@ -255,7 +286,18 @@ CompileGLTest::CompileGLTest() {
GL::RenderbufferFormat::RGBA4, GL::RenderbufferFormat::RGBA4,
#endif #endif
{32, 32}); {32, 32});
_framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, _color) #ifndef MAGNUM_TARGET_GLES2
_objectId.setStorage(GL::RenderbufferFormat::R32UI, {32, 32});
#endif
_framebuffer
.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, _color)
#ifndef MAGNUM_TARGET_GLES2
.attachRenderbuffer(GL::Framebuffer::ColorAttachment{1}, _objectId)
.mapForDraw({
{Shaders::Generic3D::ColorOutput, GL::Framebuffer::ColorAttachment{0}},
{Shaders::Generic3D::ObjectIdOutput, GL::Framebuffer::ColorAttachment{1}}
})
#endif
.bind(); .bind();
_texture _texture
.setMinificationFilter(SamplerFilter::Linear) .setMinificationFilter(SamplerFilter::Linear)
@ -305,12 +347,33 @@ template<> struct MeshTypeName<Trade::MeshData3D> {
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
void CompileGLTest::renderSetup() {
#ifndef MAGNUM_TARGET_GLES2
/* To avoid reading from the integer object ID attachment */
/** @todo ugh this needs to be a global thing and managed through
scoped RendererState */
_framebuffer.mapForRead(GL::Framebuffer::ColorAttachment{0});
#endif
}
void CompileGLTest::renderTeardown() {}
template<class T> void CompileGLTest::twoDimensions() { template<class T> void CompileGLTest::twoDimensions() {
setTestCaseTemplateName(MeshTypeName<T>::name()); setTestCaseTemplateName(MeshTypeName<T>::name());
auto&& data = Data2D[testCaseInstanceId()]; auto&& data = Data2D[testCaseInstanceId()];
setTestCaseDescription(data.name); setTestCaseDescription(data.name);
#ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH /** @todo remove once MeshDataXD is gone */
if(std::is_same<T, Trade::MeshData2D>::value && data.flags & Flag::ObjectId)
CORRADE_SKIP("Not possible with MeshData2D.");
CORRADE_IGNORE_DEPRECATED_POP
#endif
/* /*
Object ID initially set to the same value, bottom half changed to 13562
after the mesh gets deindexed.
6-----7-----8 6-----7-----8
| /| /| | /| /|
| / | / | | / | / |
@ -325,18 +388,19 @@ template<class T> void CompileGLTest::twoDimensions() {
Vector2 position; Vector2 position;
Vector2 textureCoordinates; Vector2 textureCoordinates;
Color3 color; Color3 color;
UnsignedInt objectId;
} vertexData[]{ } vertexData[]{
{{-0.75f, -0.75f}, {0.0f, 0.0f}, 0x00ff00_rgbf}, {{-0.75f, -0.75f}, {0.0f, 0.0f}, 0x00ff00_rgbf, 26234},
{{ 0.00f, -0.75f}, {0.5f, 0.0f}, 0x808000_rgbf}, {{ 0.00f, -0.75f}, {0.5f, 0.0f}, 0x808000_rgbf, 26234},
{{ 0.75f, -0.75f}, {1.0f, 0.0f}, 0xff0000_rgbf}, {{ 0.75f, -0.75f}, {1.0f, 0.0f}, 0xff0000_rgbf, 26234},
{{-0.75f, 0.00f}, {0.0f, 0.5f}, 0x00ff80_rgbf}, {{-0.75f, 0.00f}, {0.0f, 0.5f}, 0x00ff80_rgbf, 26234},
{{ 0.00f, 0.00f}, {0.5f, 0.5f}, 0x808080_rgbf}, {{ 0.00f, 0.00f}, {0.5f, 0.5f}, 0x808080_rgbf, 26234},
{{ 0.75f, 0.00f}, {1.0f, 0.5f}, 0xff0080_rgbf}, {{ 0.75f, 0.00f}, {1.0f, 0.5f}, 0xff0080_rgbf, 26234},
{{-0.75f, 0.75f}, {0.0f, 1.0f}, 0x00ffff_rgbf}, {{-0.75f, 0.75f}, {0.0f, 1.0f}, 0x00ffff_rgbf, 26234},
{{ 0.0f, 0.75f}, {0.5f, 1.0f}, 0x8080ff_rgbf}, {{ 0.0f, 0.75f}, {0.5f, 1.0f}, 0x8080ff_rgbf, 26234},
{{ 0.75f, 0.75f}, {1.0f, 1.0f}, 0xff00ff_rgbf} {{ 0.75f, 0.75f}, {1.0f, 1.0f}, 0xff00ff_rgbf, 26234}
}; };
Containers::Array<Trade::MeshAttributeData> attributeData; Containers::Array<Trade::MeshAttributeData> attributeData;
@ -354,6 +418,11 @@ template<class T> void CompileGLTest::twoDimensions() {
Trade::MeshAttribute::Color, Trade::MeshAttribute::Color,
Containers::stridedArrayView(vertexData, &vertexData[0].color, Containers::stridedArrayView(vertexData, &vertexData[0].color,
Containers::arraySize(vertexData), sizeof(Vertex))}); Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::ObjectId)
arrayAppend(attributeData, Trade::MeshAttributeData{
Trade::MeshAttribute::ObjectId,
Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(Vertex))});
const UnsignedInt indexData[]{ const UnsignedInt indexData[]{
0, 1, 4, 0, 4, 3, 0, 1, 4, 0, 4, 3,
@ -367,7 +436,16 @@ template<class T> void CompileGLTest::twoDimensions() {
{}, vertexData, std::move(attributeData)}; {}, vertexData, std::move(attributeData)};
/* Duplicate everything if data is non-indexed */ /* Duplicate everything if data is non-indexed */
if(data.flags & Flag::NonIndexed) meshData = duplicate(meshData); if(data.flags & Flag::NonIndexed) {
meshData = duplicate(meshData);
/* Update object IDs in the bottom half */
if(data.flags & Flag::ObjectId) {
auto objectIds = meshData.mutableAttribute<UnsignedInt>(Trade::MeshAttribute::ObjectId);
for(std::size_t i = 0; i != meshData.vertexCount()/2; ++i)
objectIds[i] = 13562;
}
}
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -425,6 +503,31 @@ template<class T> void CompileGLTest::twoDimensions() {
/* SwiftShader has some minor off-by-one precision differences */ /* SwiftShader has some minor off-by-one precision differences */
(DebugTools::CompareImageToFile{_manager, 0.75f, 0.0906f})); (DebugTools::CompareImageToFile{_manager, 0.75f, 0.0906f}));
} }
#ifndef MAGNUM_TARGET_GLES2
/* Check object ID rendering, if we have per-vertex object ID */
if(data.flags & Flag::ObjectId) {
_framebuffer.clearColor(1, Vector4ui{27});
_flatObjectId2D.draw(mesh);
MAGNUM_VERIFY_NO_GL_ERROR();
/* Object ID -- no need to verify the whole image, just check that
pixels on known places have expected values. SwiftShader insists
that the read format has to be 32bit, so the renderbuffer format is
that too to make it the same (ES3 Mesa complains if these don't
match). */
_framebuffer.mapForRead(GL::Framebuffer::ColorAttachment{1});
CORRADE_COMPARE(_framebuffer.checkStatus(GL::FramebufferTarget::Read), GL::Framebuffer::Status::Complete);
Image2D image = _framebuffer.read(_framebuffer.viewport(), {PixelFormat::R32UI});
MAGNUM_VERIFY_NO_GL_ERROR();
/* Outside of the object, cleared to 27 */
CORRADE_COMPARE(image.pixels<UnsignedInt>()[2][2], 27);
/* Inside of the object, bottom and top half should be different */
CORRADE_COMPARE(image.pixels<UnsignedInt>()[11][18], 13562);
CORRADE_COMPARE(image.pixels<UnsignedInt>()[19][15], 26234);
}
#endif
} }
template<class T> void CompileGLTest::threeDimensions() { template<class T> void CompileGLTest::threeDimensions() {
@ -434,12 +537,15 @@ template<class T> void CompileGLTest::threeDimensions() {
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH /** @todo remove once MeshDataXD is gone */ CORRADE_IGNORE_DEPRECATED_PUSH /** @todo remove once MeshDataXD is gone */
if(std::is_same<T, Trade::MeshData3D>::value && data.flags & (Flag::Tangents|Flag::Bitangents|Flag::BitangentsFromTangents)) if(std::is_same<T, Trade::MeshData3D>::value && data.flags & (Flag::Tangents|Flag::Bitangents|Flag::BitangentsFromTangents|Flag::ObjectId))
CORRADE_SKIP("Not possible with MeshData3D."); CORRADE_SKIP("Not possible with MeshData3D.");
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
/* /*
Object ID initially set to the same value, bottom half changed to 13562
after the mesh gets deindexed.
6-----7-----8 6-----7-----8
| /| /| | /| /|
| / | / | | / | / |
@ -457,45 +563,46 @@ template<class T> void CompileGLTest::threeDimensions() {
Vector3 normal; Vector3 normal;
Vector2 textureCoordinates; Vector2 textureCoordinates;
Color4 color; Color4 color;
UnsignedInt objectId;
} vertexData[]{ } vertexData[]{
{{-0.75f, -0.75f, -0.35f}, {{-0.75f, -0.75f, -0.35f},
Vector4{Vector3{1.0f, 0.5f, 0.5f}.normalized(), -1.0f}, {}, Vector4{Vector3{1.0f, 0.5f, 0.5f}.normalized(), -1.0f}, {},
Vector3{-0.5f, -0.5f, 1.0f}.normalized(), Vector3{-0.5f, -0.5f, 1.0f}.normalized(),
{0.0f, 0.0f}, 0x00ff00_rgbf}, {0.0f, 0.0f}, 0x00ff00_rgbf, 26234},
{{ 0.00f, -0.75f, -0.25f}, {{ 0.00f, -0.75f, -0.25f},
Vector4{Vector3{1.0f, 0.0f, 0.5f}.normalized(), 1.0f}, {}, Vector4{Vector3{1.0f, 0.0f, 0.5f}.normalized(), 1.0f}, {},
Vector3{ 0.0f, -0.5f, 1.0f}.normalized(), Vector3{ 0.0f, -0.5f, 1.0f}.normalized(),
{0.5f, 0.0f}, 0x808000_rgbf}, {0.5f, 0.0f}, 0x808000_rgbf, 26234},
{{ 0.75f, -0.75f, -0.35f}, {{ 0.75f, -0.75f, -0.35f},
Vector4{Vector3{1.0f, -0.5f, 0.5f}.normalized(), 1.0f}, {}, Vector4{Vector3{1.0f, -0.5f, 0.5f}.normalized(), 1.0f}, {},
Vector3{ 0.5f, -0.5f, 1.0f}.normalized(), Vector3{ 0.5f, -0.5f, 1.0f}.normalized(),
{1.0f, 0.0f}, 0xff0000_rgbf}, {1.0f, 0.0f}, 0xff0000_rgbf, 26234},
{{-0.75f, 0.00f, -0.25f}, {{-0.75f, 0.00f, -0.25f},
Vector4{Vector3{1.0f, 0.5f, 0.0f}.normalized(), -1.0f}, {}, Vector4{Vector3{1.0f, 0.5f, 0.0f}.normalized(), -1.0f}, {},
Vector3{-0.5f, 0.0f, 1.0f}.normalized(), Vector3{-0.5f, 0.0f, 1.0f}.normalized(),
{0.0f, 0.5f}, 0x00ff80_rgbf}, {0.0f, 0.5f}, 0x00ff80_rgbf, 26234},
{{ 0.00f, 0.00f, 0.00f}, {{ 0.00f, 0.00f, 0.00f},
Vector4{Vector3{1.0f, 0.0f, 0.0f}.normalized(), 1.0f}, {}, Vector4{Vector3{1.0f, 0.0f, 0.0f}.normalized(), 1.0f}, {},
Vector3{ 0.0f, 0.0f, 1.0f}.normalized(), Vector3{ 0.0f, 0.0f, 1.0f}.normalized(),
{0.5f, 0.5f}, 0x808080_rgbf}, {0.5f, 0.5f}, 0x808080_rgbf, 26234},
{{ 0.75f, 0.00f, -0.25f}, {{ 0.75f, 0.00f, -0.25f},
Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), 1.0f}, {}, Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), 1.0f}, {},
Vector3{ 0.5f, 0.0f, 1.0f}.normalized(), Vector3{ 0.5f, 0.0f, 1.0f}.normalized(),
{1.0f, 0.5f}, 0xff0080_rgbf}, {1.0f, 0.5f}, 0xff0080_rgbf, 26234},
{{-0.75f, 0.75f, -0.35f}, {{-0.75f, 0.75f, -0.35f},
Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), -1.0f}, {}, Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), -1.0f}, {},
Vector3{-0.5f, 0.5f, 1.0f}.normalized(), Vector3{-0.5f, 0.5f, 1.0f}.normalized(),
{0.0f, 1.0f}, 0x00ffff_rgbf}, {0.0f, 1.0f}, 0x00ffff_rgbf, 26234},
{{ 0.0f, 0.75f, -0.25f}, {{ 0.0f, 0.75f, -0.25f},
Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), -1.0f}, {}, Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), -1.0f}, {},
Vector3{ 0.0f, 0.5f, 1.0f}.normalized(), Vector3{ 0.0f, 0.5f, 1.0f}.normalized(),
{0.5f, 1.0f}, 0x8080ff_rgbf}, {0.5f, 1.0f}, 0x8080ff_rgbf, 26234},
{{ 0.75f, 0.75f, -0.35f}, {{ 0.75f, 0.75f, -0.35f},
Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), -1.0f}, {}, Vector4{Vector3{1.0f, -0.5f, 0.0f}.normalized(), -1.0f}, {},
Vector3{ 0.5f, 0.5f, 1.0f}.normalized(), Vector3{ 0.5f, 0.5f, 1.0f}.normalized(),
{1.0f, 1.0f}, 0xff00ff_rgbf} {1.0f, 1.0f}, 0xff00ff_rgbf, 26234}
}; };
/* Calculate bitangents from normal+tangent */ /* Calculate bitangents from normal+tangent */
@ -532,6 +639,11 @@ template<class T> void CompileGLTest::threeDimensions() {
Trade::MeshAttribute::Color, Trade::MeshAttribute::Color,
Containers::stridedArrayView(vertexData, &vertexData[0].color, Containers::stridedArrayView(vertexData, &vertexData[0].color,
Containers::arraySize(vertexData), sizeof(Vertex))}); Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::ObjectId)
arrayAppend(attributeData, Trade::MeshAttributeData{
Trade::MeshAttribute::ObjectId,
Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(Vertex))});
const UnsignedByte indexData[]{ const UnsignedByte indexData[]{
0, 1, 4, 0, 4, 3, 0, 1, 4, 0, 4, 3,
@ -545,7 +657,16 @@ template<class T> void CompileGLTest::threeDimensions() {
{}, vertexData, std::move(attributeData)}; {}, vertexData, std::move(attributeData)};
/* Duplicate everything if data is non-indexed */ /* Duplicate everything if data is non-indexed */
if(data.flags & Flag::NonIndexed) meshData = duplicate(meshData); if(data.flags & Flag::NonIndexed) {
meshData = duplicate(meshData);
/* Update object IDs in the bottom half */
if(data.flags & Flag::ObjectId) {
auto objectIds = meshData.mutableAttribute<UnsignedInt>(Trade::MeshAttribute::ObjectId);
for(std::size_t i = 0; i != meshData.vertexCount()/2; ++i)
objectIds[i] = 13562;
}
}
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -670,6 +791,33 @@ template<class T> void CompileGLTest::threeDimensions() {
(DebugTools::CompareImageToFile{_manager, 1.0f, 0.0948f})); (DebugTools::CompareImageToFile{_manager, 1.0f, 0.0948f}));
} }
#ifndef MAGNUM_TARGET_GLES2
/* Check object ID rendering, if we have per-vertex object ID */
if(data.flags & Flag::ObjectId) {
_framebuffer.clearColor(1, Vector4ui{27});
_flatObjectId3D
.setTransformationProjectionMatrix(projection*transformation)
.draw(mesh);
MAGNUM_VERIFY_NO_GL_ERROR();
/* Object ID -- no need to verify the whole image, just check that
pixels on known places have expected values. SwiftShader insists
that the read format has to be 32bit, so the renderbuffer format is
that too to make it the same (ES3 Mesa complains if these don't
match). */
_framebuffer.mapForRead(GL::Framebuffer::ColorAttachment{1});
CORRADE_COMPARE(_framebuffer.checkStatus(GL::FramebufferTarget::Read), GL::Framebuffer::Status::Complete);
Image2D image = _framebuffer.read(_framebuffer.viewport(), {PixelFormat::R32UI});
MAGNUM_VERIFY_NO_GL_ERROR();
/* Outside of the object, cleared to 27 */
CORRADE_COMPARE(image.pixels<UnsignedInt>()[2][2], 27);
/* Inside of the object, bottom and top half should be different */
CORRADE_COMPARE(image.pixels<UnsignedInt>()[11][18], 13562);
CORRADE_COMPARE(image.pixels<UnsignedInt>()[19][15], 26234);
}
#endif
/* Check with the mesh visualizer shader for TBN direction. This has to be /* Check with the mesh visualizer shader for TBN direction. This has to be
last, as it gets skipped on WebGL / ES2. */ last, as it gets skipped on WebGL / ES2. */
if(data.flags >= (Flag::Tangents|Flag::Bitangents|Flag::Normals) || if(data.flags >= (Flag::Tangents|Flag::Bitangents|Flag::Normals) ||
@ -713,52 +861,85 @@ template<class T> void CompileGLTest::threeDimensions() {
} }
} }
/* Can't be inline because MSVC 2015 doesn't like anonymous bitfields in local
structs */
struct PackedVertex {
Vector3s position;
Vector3s normal;
Vector2us textureCoordinates;
Color4ub color;
UnsignedShort objectId;
UnsignedShort:16;
};
void CompileGLTest::packedAttributes() { void CompileGLTest::packedAttributes() {
/* Same as above, just packed */
const struct Vertex { /*
Vector3s position; Same as above, except that the middle row of indices is duplicated to
Vector3s normal; make it possible to have different object IDs for the bottom and top
Vector2us textureCoordinates; row while still be able to test non-default index type as well.
Color4ub color;
} vertexData[]{ 9----10----11
| /| /|
| / | / |
|/ |/ |
6-----7-----8
3-----4-----5
| /| /|
| / | / |
|/ |/ |
0-----1-----2
*/
const PackedVertex vertexData[]{
{Math::pack<Vector3s>(Vector3{-0.75f, -0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{-0.75f, -0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{-0.5f, -0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, -0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 0.0f}), 0x00ff00_rgb}, Math::pack<Vector2us>(Vector2{0.0f, 0.0f}), 0x00ff00_rgb, 13562},
{Math::pack<Vector3s>(Vector3{ 0.00f, -0.75f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.00f, -0.75f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.0f, -0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, -0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 0.0f}), 0x808000_rgb}, Math::pack<Vector2us>(Vector2{0.5f, 0.0f}), 0x808000_rgb, 13562},
{Math::pack<Vector3s>(Vector3{ 0.75f, -0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{ 0.75f, -0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{ 0.5f, -0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, -0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 0.0f}), 0xff0000_rgb}, Math::pack<Vector2us>(Vector2{1.0f, 0.0f}), 0xff0000_rgb, 13562},
{Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}), {Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb}, Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb, 13562},
{Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}), {Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}),
Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb}, Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb, 13562},
{Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb}, Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb, 13562},
{Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb, 26234},
{Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}),
Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb, 26234},
{Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb, 26234},
{Math::pack<Vector3s>(Vector3{-0.75f, 0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{-0.75f, 0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{-0.5f, 0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, 0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 1.0f}), 0x00ffff_rgb}, Math::pack<Vector2us>(Vector2{0.0f, 1.0f}), 0x00ffff_rgb, 26234},
{Math::pack<Vector3s>(Vector3{ 0.0f, 0.75f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.0f, 0.75f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.0f, 0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, 0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 1.0f}), 0x8080ff_rgb}, Math::pack<Vector2us>(Vector2{0.5f, 1.0f}), 0x8080ff_rgb, 26234},
{Math::pack<Vector3s>(Vector3{ 0.75f, 0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{ 0.75f, 0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{ 0.5f, 0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, 0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 1.0f}), 0xff00ff_rgb} Math::pack<Vector2us>(Vector2{1.0f, 1.0f}), 0xff00ff_rgb, 26234}
}; };
static_assert(sizeof(Vertex) % 4 == 0, static_assert(sizeof(PackedVertex) % 4 == 0,
"the vertex is not 4-byte aligned and that's bad"); "the vertex is not 4-byte aligned and that's bad");
const UnsignedByte indexData[]{ const UnsignedByte indexData[]{
0, 1, 4, 0, 4, 3, 0, 1, 4, 0, 4, 3,
1, 2, 5, 1, 5, 4, 1, 2, 5, 1, 5, 4,
3, 4, 7, 3, 7, 6, 6, 7, 10, 6, 10, 9,
4, 5, 8, 4, 8, 7 7, 8, 11, 7, 11, 10
}; };
Trade::MeshData meshData{MeshPrimitive::Triangles, {}, indexData, Trade::MeshData meshData{MeshPrimitive::Triangles, {}, indexData,
@ -767,22 +948,28 @@ void CompileGLTest::packedAttributes() {
Trade::MeshAttribute::Position, Trade::MeshAttribute::Position,
VertexFormat::Vector3sNormalized, VertexFormat::Vector3sNormalized,
Containers::stridedArrayView(vertexData, &vertexData[0].position, Containers::stridedArrayView(vertexData, &vertexData[0].position,
Containers::arraySize(vertexData), sizeof(Vertex))}, Containers::arraySize(vertexData), sizeof(PackedVertex))},
Trade::MeshAttributeData{ Trade::MeshAttributeData{
Trade::MeshAttribute::Normal, Trade::MeshAttribute::Normal,
VertexFormat::Vector3sNormalized, VertexFormat::Vector3sNormalized,
Containers::stridedArrayView(vertexData, &vertexData[0].normal, Containers::stridedArrayView(vertexData, &vertexData[0].normal,
Containers::arraySize(vertexData), sizeof(Vertex))}, Containers::arraySize(vertexData), sizeof(PackedVertex))},
Trade::MeshAttributeData{ Trade::MeshAttributeData{
Trade::MeshAttribute::TextureCoordinates, Trade::MeshAttribute::TextureCoordinates,
VertexFormat::Vector2usNormalized, VertexFormat::Vector2usNormalized,
Containers::stridedArrayView(vertexData, &vertexData[0].textureCoordinates, Containers::stridedArrayView(vertexData, &vertexData[0].textureCoordinates,
Containers::arraySize(vertexData), sizeof(Vertex))}, Containers::arraySize(vertexData), sizeof(PackedVertex))},
Trade::MeshAttributeData{ Trade::MeshAttributeData{
Trade::MeshAttribute::Color, Trade::MeshAttribute::Color,
/* It should figure out the type itself here */ /* It should figure out the type itself here */
Containers::stridedArrayView(vertexData, &vertexData[0].color, Containers::stridedArrayView(vertexData, &vertexData[0].color,
Containers::arraySize(vertexData), sizeof(Vertex))} Containers::arraySize(vertexData), sizeof(PackedVertex))},
#ifndef MAGNUM_TARGET_GLES2
Trade::MeshAttributeData{
Trade::MeshAttribute::ObjectId,
Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(PackedVertex))}
#endif
}}; }};
GL::Mesh mesh = compile(meshData); GL::Mesh mesh = compile(meshData);
@ -838,6 +1025,29 @@ void CompileGLTest::packedAttributes() {
Utility::Directory::join(COMPILEGLTEST_TEST_DIR, "textured3D.tga"), Utility::Directory::join(COMPILEGLTEST_TEST_DIR, "textured3D.tga"),
/* SwiftShader has some minor off-by-one precision differences */ /* SwiftShader has some minor off-by-one precision differences */
(DebugTools::CompareImageToFile{_manager, 1.0f, 0.0948f})); (DebugTools::CompareImageToFile{_manager, 1.0f, 0.0948f}));
#ifndef MAGNUM_TARGET_GLES2
_framebuffer.clearColor(1, Vector4ui{27});
_flatObjectId3D
.setTransformationProjectionMatrix(projection*transformation)
.draw(mesh);
MAGNUM_VERIFY_NO_GL_ERROR();
/* Object ID -- no need to verify the whole image, just check that pixels
on known places have expected values. SwiftShader insists that the read
format has to be 32bit, so the renderbuffer format is that too to make
it the same (ES3 Mesa complains if these don't match). */
_framebuffer.mapForRead(GL::Framebuffer::ColorAttachment{1});
CORRADE_COMPARE(_framebuffer.checkStatus(GL::FramebufferTarget::Read), GL::Framebuffer::Status::Complete);
Image2D image = _framebuffer.read(_framebuffer.viewport(), {PixelFormat::R32UI});
MAGNUM_VERIFY_NO_GL_ERROR();
/* Outside of the object, cleared to 27 */
CORRADE_COMPARE(image.pixels<UnsignedInt>()[2][2], 27);
/* Inside of the object, bottom and top half should be different */
CORRADE_COMPARE(image.pixels<UnsignedInt>()[11][18], 13562);
CORRADE_COMPARE(image.pixels<UnsignedInt>()[19][15], 26234);
#endif
} }
void CompileGLTest::customAttribute() { void CompileGLTest::customAttribute() {
@ -855,7 +1065,29 @@ void CompileGLTest::customAttribute() {
else else
MeshTools::compile(data); MeshTools::compile(data);
CORRADE_COMPARE(out.str(), instanceData.flags ? "" : CORRADE_COMPARE(out.str(), instanceData.flags ? "" :
"MeshTools::compile(): ignoring unknown attribute Trade::MeshAttribute::Custom(115)\n"); "MeshTools::compile(): ignoring unknown/unsupported attribute Trade::MeshAttribute::Custom(115)\n");
}
void CompileGLTest::unsupportedAttribute() {
auto&& instanceData = CustomAttributeWarningData[testCaseInstanceId()];
setTestCaseDescription(instanceData.name);
#ifndef MAGNUM_TARGET_GLES2
CORRADE_SKIP("All attributes are supported on ES3+.");
#else
Trade::MeshData data{MeshPrimitive::Triangles,
nullptr, {Trade::MeshAttributeData{Trade::MeshAttribute::ObjectId,
VertexFormat::UnsignedByte, nullptr}}};
std::ostringstream out;
Warning redirectError{&out};
if(instanceData.flags)
MeshTools::compile(data, instanceData.flags);
else
MeshTools::compile(data);
/* Warns always, regardless of the flag */
CORRADE_COMPARE(out.str(), "MeshTools::compile(): ignoring unknown/unsupported attribute Trade::MeshAttribute::ObjectId\n");
#endif
} }
void CompileGLTest::implementationSpecificAttributeFormat() { void CompileGLTest::implementationSpecificAttributeFormat() {

Loading…
Cancel
Save