Skip to content
Snippets Groups Projects
Commit 249608f0 authored by Trevor Hollmann's avatar Trevor Hollmann
Browse files

[#26] Some improvements to first mesh test project.

This commit fixes an issue where the indices of a vertex group would
always be handled as uint16_t regardless of what the IndexType was.

Additionally, the vertex attributes are now printed as well.
parent e9cafd07
No related branches found
No related tags found
1 merge request!19Resolve "Asset Loading"
Pipeline #25155 passed
......@@ -21,23 +21,41 @@ int main(int argc, const char** argv) {
"points", "lines", "line loop", "line strip", "triangles",
"triangle strip", "triangle fan"
};
const char *primitive_types[] = {
"unknown", "position", "normal", "texcoord0"
};
printf("Mesh %s (%s) has %lu vertex group(s) and %lu material(s):\n",
mesh.name.c_str(), path, mesh.vertexGroups.size(),
mesh.materials.size());
for (size_t i = 0; i < mesh.vertexGroups.size(); i++) {
char *buf;
printf("--- vertex group %lu ---\n", i);
const auto &vg = mesh.vertexGroups[i];
printf("primitive mode: %d (%s)\n", vg.mode,
primitive_modes[vg.mode]);
printf("index buffer: %lu bytes for %lu indices (%p)\n",
vg.indexBuffer.data.size(), vg.numIndices,
vg.indexBuffer.data.data());
buf = (char*)vg.indexBuffer.data.data();
uint16_t *indices = (uint16_t*)buf;
printf("index buffer: %lu bytes for %lu indices ",
vg.indexBuffer.data.size(), vg.numIndices);
const auto itype = vg.indexBuffer.type;
printf("(%s @ %p)\n",
itype == vkcv::asset::UINT32 ? "UINT32" :
itype == vkcv::asset::UINT16 ? "UINT16" :
"UINT8", vg.indexBuffer.data.data());
printf("\tindices: ");
for (size_t j = 0; j < vg.numIndices; j++) {
printf("%u ", indices[j]);
const size_t n = vg.numIndices;
if (vg.indexBuffer.type == vkcv::asset::UINT32) {
uint32_t *idx = (uint32_t*)vg.indexBuffer.data.data();
for (size_t j = 0; j < n; j++) printf("%u ", idx[j]);
} else
if (vg.indexBuffer.type == vkcv::asset::UINT16) {
uint16_t *idx = (uint16_t*)vg.indexBuffer.data.data();
for (size_t j = 0; j < n; j++) printf("%u ", idx[j]);
} else
if (vg.indexBuffer.type == vkcv::asset::UINT8) {
uint8_t *idx = (uint8_t*)vg.indexBuffer.data.data();
for (size_t j = 0; j < n; j++) printf("%u ", idx[j]);
} else {
fprintf(stderr, "ERROR Invalid IndexType: %d\n",
vg.indexBuffer.type);
return 0;
}
printf("\n");
printf("vertex buffer: %lu bytes for %lu vertices with %lu "
......@@ -45,6 +63,13 @@ int main(int argc, const char** argv) {
vg.vertexBuffer.data.size(), vg.numVertices,
vg.vertexBuffer.attributes.size(),
vg.vertexBuffer.data.data());
printf("attributes:\toffset\tlength\tstride\tcomponents\n");
for (const auto att : vg.vertexBuffer.attributes) {
printf("%11s\t%u\t%u\t%u\t%hhux%hu\n",
primitive_types[att.type],
att.offset, att.length, att.stride,
att.componentCount, att.componentType);
}
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment