Skip to content

Commit 4f0daf9

Browse files
authored
Merge pull request #998 from zeux/vtx1-zigzag16-tests
Expand testing coverage for 16-bit deltas in v1 codec
2 parents 5710056 + 5cf7dda commit 4f0daf9

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

demo/tests.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,27 @@ static void decodeVertexV1Custom()
477477
assert(memcmp(decoded, kVertexBuffer, sizeof(kVertexBuffer)) == 0);
478478
}
479479

480+
static void decodeVertexV1Deltas()
481+
{
482+
const unsigned short expected[] = {
483+
248, 248, 240, 240, 249, 250, 243, 244, 250, 252, 246, 248, 251, 254, 249, 252,
484+
252, 256, 252, 256, 253, 258, 255, 260, 254, 260, 258, 264, 255, 262, 261, 268,
485+
256, 264, 264, 272, 257, 262, 267, 268, 258, 260, 270, 264, 259, 258, 273, 260,
486+
260, 256, 276, 256, 261, 254, 279, 252, 262, 252, 282, 248, 263, 250, 285, 244, // clang-format :-/
487+
};
488+
489+
const unsigned char input[] = {
490+
0xa1, 0x99, 0x99, 0x01, 0x2a, 0xaa, 0xaa, 0xaa, 0x02, 0x04, 0x44, 0x44, 0x44, 0x43, 0x33, 0x33,
491+
0x33, 0x02, 0x06, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x02, 0x08, 0x88, 0x88, 0x88, 0x87,
492+
0x77, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
493+
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0x01, 0x01, // clang-format :-/
494+
};
495+
496+
unsigned short decoded[sizeof(expected) / sizeof(expected[0])];
497+
assert(meshopt_decodeVertexBuffer(decoded, 16, 8, input, sizeof(input)) == 0);
498+
assert(memcmp(decoded, expected, sizeof(expected)) == 0);
499+
}
500+
480501
static void encodeVertexMemorySafe()
481502
{
482503
const size_t vertex_count = sizeof(kVertexBuffer) / sizeof(kVertexBuffer[0]);
@@ -610,9 +631,9 @@ static void decodeVertexDeltas()
610631
for (size_t i = 0; i < 16; ++i)
611632
{
612633
data[i * 4 + 0] = (unsigned short)(0xf8 + i * 1);
613-
data[i * 4 + 1] = (unsigned short)(0xf8 + i * 2);
634+
data[i * 4 + 1] = (unsigned short)(0xf8 + (i < 8 ? i : 16 - i) * 2);
614635
data[i * 4 + 2] = (unsigned short)(0xf0 + i * 3);
615-
data[i * 4 + 3] = (unsigned short)(0xf0 + i * 4);
636+
data[i * 4 + 3] = (unsigned short)(0xf0 + (i < 8 ? i : 16 - i) * 4);
616637
}
617638

618639
std::vector<unsigned char> buffer(meshopt_encodeVertexBufferBound(16, 8));
@@ -2733,6 +2754,7 @@ void runTests()
27332754
decodeVertexV0Mode2();
27342755
decodeVertexV1();
27352756
decodeVertexV1Custom();
2757+
decodeVertexV1Deltas();
27362758

27372759
for (int version = 0; version <= 1; ++version)
27382760
{

js/meshopt_decoder.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ var tests = {
9999
assert.deepStrictEqual(result, expected);
100100
},
101101

102+
decodeVertexBufferV1_Deltas: function () {
103+
var encoded = new Uint8Array([
104+
0xa1, 0x99, 0x99, 0x01, 0x2a, 0xaa, 0xaa, 0xaa, 0x02, 0x04, 0x44, 0x44, 0x44, 0x43, 0x33, 0x33, 0x33, 0x02, 0x06, 0x66, 0x66, 0x66, 0x66,
105+
0x66, 0x66, 0x66, 0x02, 0x08, 0x88, 0x88, 0x88, 0x87, 0x77, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106+
0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0x01, 0x01,
107+
]);
108+
109+
var expected = new Uint16Array([
110+
248, 248, 240, 240, 249, 250, 243, 244, 250, 252, 246, 248, 251, 254, 249, 252, 252, 256, 252, 256, 253, 258, 255, 260, 254, 260, 258,
111+
264, 255, 262, 261, 268, 256, 264, 264, 272, 257, 262, 267, 268, 258, 260, 270, 264, 259, 258, 273, 260, 260, 256, 276, 256, 261, 254,
112+
279, 252, 262, 252, 282, 248, 263, 250, 285, 244,
113+
]);
114+
115+
var result = new Uint16Array(expected.length);
116+
decoder.decodeVertexBuffer(new Uint8Array(result.buffer), 16, 8, encoded);
117+
118+
assert.deepStrictEqual(result, expected);
119+
},
120+
102121
decodeIndexBuffer16: function () {
103122
var encoded = new Uint8Array([
104123
0xe0, 0xf0, 0x10, 0xfe, 0xff, 0xf0, 0x0c, 0xff, 0x02, 0x02, 0x02, 0x00, 0x76, 0x87, 0x56, 0x67, 0x78, 0xa9, 0x86, 0x65, 0x89, 0x68, 0x98,

0 commit comments

Comments
 (0)