Remove buffer copies for gltf indices
Directly access the values from the buffer instead Fixes #894
This commit is contained in:
parent
d72ff3c8d5
commit
6f723ea1e0
3 changed files with 13 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Vulkan Example - glTF scene loading and rendering
|
||||
*
|
||||
* Copyright (C) 2020 by Sascha Willems - www.saschawillems.de
|
||||
* Copyright (C) 2020-2021 by Sascha Willems - www.saschawillems.de
|
||||
*
|
||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||
*/
|
||||
|
|
@ -163,7 +163,7 @@ public:
|
|||
// Load texture from image buffer
|
||||
images[i].texture.fromBuffer(buffer, bufferSize, VK_FORMAT_R8G8B8A8_UNORM, glTFImage.width, glTFImage.height, vulkanDevice, copyQueue);
|
||||
if (deleteBuffer) {
|
||||
delete buffer;
|
||||
delete[] buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -280,24 +280,21 @@ public:
|
|||
// glTF supports different component types of indices
|
||||
switch (accessor.componentType) {
|
||||
case TINYGLTF_PARAMETER_TYPE_UNSIGNED_INT: {
|
||||
uint32_t* buf = new uint32_t[accessor.count];
|
||||
memcpy(buf, &buffer.data[accessor.byteOffset + bufferView.byteOffset], accessor.count * sizeof(uint32_t));
|
||||
const uint32_t* buf = reinterpret_cast<const uint32_t*>(&buffer.data[accessor.byteOffset + bufferView.byteOffset]);
|
||||
for (size_t index = 0; index < accessor.count; index++) {
|
||||
indexBuffer.push_back(buf[index] + vertexStart);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TINYGLTF_PARAMETER_TYPE_UNSIGNED_SHORT: {
|
||||
uint16_t* buf = new uint16_t[accessor.count];
|
||||
memcpy(buf, &buffer.data[accessor.byteOffset + bufferView.byteOffset], accessor.count * sizeof(uint16_t));
|
||||
const uint16_t* buf = reinterpret_cast<const uint16_t*>(&buffer.data[accessor.byteOffset + bufferView.byteOffset]);
|
||||
for (size_t index = 0; index < accessor.count; index++) {
|
||||
indexBuffer.push_back(buf[index] + vertexStart);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TINYGLTF_PARAMETER_TYPE_UNSIGNED_BYTE: {
|
||||
uint8_t* buf = new uint8_t[accessor.count];
|
||||
memcpy(buf, &buffer.data[accessor.byteOffset + bufferView.byteOffset], accessor.count * sizeof(uint8_t));
|
||||
const uint8_t* buf = reinterpret_cast<const uint8_t*>(&buffer.data[accessor.byteOffset + bufferView.byteOffset]);
|
||||
for (size_t index = 0; index < accessor.count; index++) {
|
||||
indexBuffer.push_back(buf[index] + vertexStart);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue