Skip to content

Commit 6134352

Browse files
authored
Merge branch 'SaschaWillems:master' into master
2 parents 829c240 + f735a89 commit 6134352

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ git submodule update
5454

5555
## Building
5656

57-
The repository contains everything required to compile and build the examples on <img src="./images/windowslogo.png" alt="" height="22px" valign="bottom"> Windows, <img src="./images/linuxlogo.png" alt="" height="24px" valign="bottom"> Linux, <img src="./images/androidlogo.png" alt="" height="24px" valign="bottom"> Android, <img src="./images/applelogo.png" alt="" valign="bottom" height="24px"> iOS and macOS (using MoltenVK) using a C++ compiler that supports C++20.
57+
The repository contains everything required to compile and build the examples on Windows, Android, iOS and macOS (using MoltenVK) using a C++ compiler that supports C++20.
5858

5959
See [BUILD.md](BUILD.md) for details on how to build for the different platforms.
6060

base/VulkanglTFModel.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan glTF model and texture loading class based on tinyglTF (https://github.com/syoyo/tinygltf)
33
*
4-
* Copyright (C) 2018-2024 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2018-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -108,6 +108,7 @@ void vkglTF::Texture::fromglTfImage(tinygltf::Image &gltfimage, std::string path
108108
buffer = &gltfimage.image[0];
109109
bufferSize = gltfimage.image.size();
110110
}
111+
assert(buffer);
111112

112113
format = VK_FORMAT_R8G8B8A8_UNORM;
113114

@@ -140,7 +141,7 @@ void vkglTF::Texture::fromglTfImage(tinygltf::Image &gltfimage, std::string path
140141
VK_CHECK_RESULT(vkAllocateMemory(device->logicalDevice, &memAllocInfo, nullptr, &stagingMemory));
141142
VK_CHECK_RESULT(vkBindBufferMemory(device->logicalDevice, stagingBuffer, stagingMemory, 0));
142143

143-
uint8_t* data;
144+
uint8_t* data{nullptr};
144145
VK_CHECK_RESULT(vkMapMemory(device->logicalDevice, stagingMemory, 0, memReqs.size, 0, (void**)&data));
145146
memcpy(data, buffer, bufferSize);
146147
vkUnmapMemory(device->logicalDevice, stagingMemory);
@@ -337,7 +338,7 @@ void vkglTF::Texture::fromglTfImage(tinygltf::Image &gltfimage, std::string path
337338
VK_CHECK_RESULT(vkAllocateMemory(device->logicalDevice, &memAllocInfo, nullptr, &stagingMemory));
338339
VK_CHECK_RESULT(vkBindBufferMemory(device->logicalDevice, stagingBuffer, stagingMemory, 0));
339340

340-
uint8_t* data;
341+
uint8_t* data{ nullptr };
341342
VK_CHECK_RESULT(vkMapMemory(device->logicalDevice, stagingMemory, 0, memReqs.size, 0, (void**)&data));
342343
memcpy(data, ktxTextureData, ktxTextureSize);
343344
vkUnmapMemory(device->logicalDevice, stagingMemory);
@@ -408,8 +409,6 @@ void vkglTF::Texture::fromglTfImage(tinygltf::Image &gltfimage, std::string path
408409
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
409410
samplerInfo.compareOp = VK_COMPARE_OP_NEVER;
410411
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
411-
samplerInfo.maxAnisotropy = 1.0;
412-
samplerInfo.anisotropyEnable = VK_FALSE;
413412
samplerInfo.maxLod = (float)mipLevels;
414413
samplerInfo.maxAnisotropy = 8.0f;
415414
samplerInfo.anisotropyEnable = VK_TRUE;
@@ -651,7 +650,7 @@ void vkglTF::Model::createEmptyTexture(VkQueue transferQueue)
651650
VK_CHECK_RESULT(vkBindBufferMemory(device->logicalDevice, stagingBuffer, stagingMemory, 0));
652651

653652
// Copy texture data into staging buffer
654-
uint8_t* data;
653+
uint8_t* data{ nullptr };
655654
VK_CHECK_RESULT(vkMapMemory(device->logicalDevice, stagingMemory, 0, memReqs.size, 0, (void**)&data));
656655
memcpy(data, buffer, bufferSize);
657656
vkUnmapMemory(device->logicalDevice, stagingMemory);
@@ -733,13 +732,13 @@ vkglTF::Model::~Model()
733732
vkFreeMemory(device->logicalDevice, vertices.memory, nullptr);
734733
vkDestroyBuffer(device->logicalDevice, indices.buffer, nullptr);
735734
vkFreeMemory(device->logicalDevice, indices.memory, nullptr);
736-
for (auto texture : textures) {
735+
for (auto& texture : textures) {
737736
texture.destroy();
738737
}
739-
for (auto node : nodes) {
738+
for (auto& node : nodes) {
740739
delete node;
741740
}
742-
for (auto skin : skins) {
741+
for (auto& skin : skins) {
743742
delete skin;
744743
}
745744
if (descriptorSetLayoutUbo != VK_NULL_HANDLE) {
@@ -885,8 +884,10 @@ void vkglTF::Model::loadNode(vkglTF::Node *parent, const tinygltf::Node &node, u
885884
switch (numColorComponents) {
886885
case 3:
887886
vert.color = glm::vec4(glm::make_vec3(&bufferColors[v * 3]), 1.0f);
887+
break;
888888
case 4:
889889
vert.color = glm::make_vec4(&bufferColors[v * 4]);
890+
break;
890891
}
891892
}
892893
else {
@@ -1256,7 +1257,7 @@ void vkglTF::Model::loadFromFile(std::string filename, vks::VulkanDevice *device
12561257
}
12571258
}
12581259

1259-
for (auto extension : gltfModel.extensionsUsed) {
1260+
for (auto& extension : gltfModel.extensionsUsed) {
12601261
if (extension == "KHR_materials_pbrSpecularGlossiness") {
12611262
std::cout << "Required extension: " << extension;
12621263
metallicRoughnessWorkflow = false;
@@ -1273,7 +1274,7 @@ void vkglTF::Model::loadFromFile(std::string filename, vks::VulkanDevice *device
12731274
struct StagingBuffer {
12741275
VkBuffer buffer;
12751276
VkDeviceMemory memory;
1276-
} vertexStaging, indexStaging;
1277+
} vertexStaging{}, indexStaging{};
12771278

12781279
// Create staging buffers
12791280
// Vertex data
@@ -1332,12 +1333,12 @@ void vkglTF::Model::loadFromFile(std::string filename, vks::VulkanDevice *device
13321333
// Setup descriptors
13331334
uint32_t uboCount{ 0 };
13341335
uint32_t imageCount{ 0 };
1335-
for (auto node : linearNodes) {
1336+
for (auto& node : linearNodes) {
13361337
if (node->mesh) {
13371338
uboCount++;
13381339
}
13391340
}
1340-
for (auto material : materials) {
1341+
for (auto& material : materials) {
13411342
if (material.baseColorTexture != nullptr) {
13421343
imageCount++;
13431344
}

base/vulkanexamplebase.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ void VulkanExampleBase::renderLoop()
334334
if (wl_display_dispatch_pending(display) == -1)
335335
return;
336336
#endif
337-
338-
benchmark.run([=] { render(); }, vulkanDevice->properties);
337+
benchmark.run([=, this] { render(); }, vulkanDevice->properties);
339338
vkDeviceWaitIdle(device);
340339
if (!benchmark.filename.empty()) {
341340
benchmark.saveResults();

examples/multithreading/multithreading.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan Example - Multi threaded command buffer generation and rendering
33
*
4-
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -329,7 +329,7 @@ class VulkanExample : public VulkanExampleBase
329329

330330
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
331331

332-
VkClearValue clearValues[2];
332+
VkClearValue clearValues[2]{};
333333
clearValues[0].color = defaultClearColor;
334334
clearValues[1].depthStencil = { 1.0f, 0 };
335335

@@ -369,7 +369,7 @@ class VulkanExample : public VulkanExampleBase
369369
{
370370
for (uint32_t i = 0; i < numObjectsPerThread; i++)
371371
{
372-
threadPool.threads[t]->addJob([=] { threadRenderCode(t, i, inheritanceInfo); });
372+
threadPool.threads[t]->addJob([=, this] { threadRenderCode(t, i, inheritanceInfo); });
373373
}
374374
}
375375

@@ -428,7 +428,7 @@ class VulkanExample : public VulkanExampleBase
428428
VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0);
429429
std::vector<VkDynamicState> dynamicStateEnables = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR};
430430
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
431-
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
431+
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages{};
432432

433433
VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass, 0);
434434
pipelineCI.pInputAssemblyState = &inputAssemblyState;

0 commit comments

Comments
 (0)