-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: Add codectest to make it easy to test attribute encoder
This is useful when trying to compress binary vertex data blobs as well as to check the output data with a separate compressor using piping, so we use stdin and stdout instead of named files.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "../src/meshoptimizer.h" | ||
|
||
#include <vector> | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#ifdef _WIN32 | ||
#include <fcntl.h> | ||
#include <io.h> | ||
#endif | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
#ifdef _WIN32 | ||
_setmode(_fileno(stdin), _O_BINARY); | ||
_setmode(_fileno(stdout), _O_BINARY); | ||
#endif | ||
|
||
if (argc != 2 || atoi(argv[1]) <= 0) | ||
{ | ||
fprintf(stderr, "Usage: %s <stride>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
size_t stride = atoi(argv[1]); | ||
|
||
std::vector<unsigned char> input; | ||
unsigned char buffer[4096]; | ||
size_t bytes_read; | ||
|
||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), stdin)) > 0) | ||
input.insert(input.end(), buffer, buffer + bytes_read); | ||
|
||
size_t vertex_count = input.size() / stride; | ||
std::vector<unsigned char> output(meshopt_encodeVertexBufferBound(vertex_count, stride)); | ||
size_t output_size = meshopt_encodeVertexBuffer(output.data(), output.size(), input.data(), vertex_count, stride); | ||
|
||
fwrite(output.data(), 1, output_size, stdout); | ||
return 0; | ||
} |