|
|
|
|
/*
|
|
|
|
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
|
|
|
|
|
|
|
|
|
|
This file is part of Magnum.
|
|
|
|
|
|
|
|
|
|
Magnum is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
|
only, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
|
|
Magnum is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License version 3 for more details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <TestSuite/Tester.h>
|
|
|
|
|
#include <Utility/Endianness.h>
|
|
|
|
|
|
|
|
|
|
#include "MeshTools/CompressIndices.h"
|
|
|
|
|
|
|
|
|
|
using Corrade::Utility::Endianness;
|
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace MeshTools { namespace Test {
|
|
|
|
|
|
|
|
|
|
class CompressIndicesTest: public Corrade::TestSuite::Tester {
|
|
|
|
|
public:
|
|
|
|
|
CompressIndicesTest();
|
|
|
|
|
|
|
|
|
|
void compressChar();
|
|
|
|
|
void compressShort();
|
|
|
|
|
void compressInt();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CompressIndicesTest::CompressIndicesTest() {
|
|
|
|
|
addTests(&CompressIndicesTest::compressChar,
|
|
|
|
|
&CompressIndicesTest::compressShort,
|
|
|
|
|
&CompressIndicesTest::compressInt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompressIndicesTest::compressChar() {
|
|
|
|
|
std::size_t indexCount;
|
|
|
|
|
Mesh::IndexType indexType;
|
|
|
|
|
char* data;
|
|
|
|
|
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
|
|
|
|
|
std::vector<UnsignedInt>{1, 2, 3, 0, 4});
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(indexCount, 5);
|
|
|
|
|
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte);
|
|
|
|
|
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
|
|
|
|
|
(std::vector<char>{ 0x01, 0x02, 0x03, 0x00, 0x04 }));
|
|
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompressIndicesTest::compressShort() {
|
|
|
|
|
std::size_t indexCount;
|
|
|
|
|
Mesh::IndexType indexType;
|
|
|
|
|
char* data;
|
|
|
|
|
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
|
|
|
|
|
std::vector<UnsignedInt>{1, 256, 0, 5});
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(indexCount, 4);
|
|
|
|
|
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort);
|
|
|
|
|
if(!Endianness::isBigEndian()) {
|
|
|
|
|
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
|
|
|
|
|
(std::vector<char>{ 0x01, 0x00,
|
|
|
|
|
0x00, 0x01,
|
|
|
|
|
0x00, 0x00,
|
|
|
|
|
0x05, 0x00 }));
|
|
|
|
|
} else {
|
|
|
|
|
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
|
|
|
|
|
(std::vector<char>{ 0x00, 0x01,
|
|
|
|
|
0x01, 0x00,
|
|
|
|
|
0x00, 0x00,
|
|
|
|
|
0x00, 0x05 }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompressIndicesTest::compressInt() {
|
|
|
|
|
std::size_t indexCount;
|
|
|
|
|
Mesh::IndexType indexType;
|
|
|
|
|
char* data;
|
|
|
|
|
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
|
|
|
|
|
std::vector<UnsignedInt>{65536, 3, 2});
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(indexCount, 3);
|
|
|
|
|
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt);
|
|
|
|
|
|
|
|
|
|
if(!Endianness::isBigEndian()) {
|
|
|
|
|
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
|
|
|
|
|
(std::vector<char>{ 0x00, 0x00, 0x01, 0x00,
|
|
|
|
|
0x03, 0x00, 0x00, 0x00,
|
|
|
|
|
0x02, 0x00, 0x00, 0x00 }));
|
|
|
|
|
} else {
|
|
|
|
|
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
|
|
|
|
|
(std::vector<char>{ 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x03,
|
|
|
|
|
0x00, 0x00, 0x00, 0x02 }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}}
|
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CompressIndicesTest)
|