Skip to content

Commit 58aa93f

Browse files
authored
Merge pull request #50 from jherico/update_2022_04
Clean up warnings, update dependencies
2 parents 0126195 + 315c0ce commit 58aa93f

File tree

32 files changed

+92
-81
lines changed

32 files changed

+92
-81
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(NAME VulkanCppExamples)
66
include(${CMAKE_SOURCE_DIR}/cmake/ezvcpkg/ezvcpkg.cmake)
77

88
ezvcpkg_fetch(
9+
COMMIT af2287382b1991dbdcb7e5112d236f3323b9dd7a
910
PACKAGES assimp basisu imgui glad glfw3 gli glm vulkan
1011
UPDATE_TOOLCHAIN
1112
)

base/common.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
// Vulkan!
5555
#include <vulkan/vulkan.hpp>
5656

57+
#include "keycodes.hpp"
58+
#if defined(__ANDROID__)
59+
#include "android.hpp"
60+
#else
61+
#include "gl.hpp"
62+
// Cross platform window management (except android)
63+
#include "glfw/glfw.hpp"
64+
#endif
65+
5766
using glm::ivec2;
5867
using glm::mat3;
5968
using glm::mat4;
@@ -96,15 +105,6 @@ class Vectors {
96105
static const vec3 ZERO4;
97106
};
98107

99-
#include "keycodes.hpp"
100-
#if defined(__ANDROID__)
101-
#include "android.hpp"
102-
103-
#else
104-
#include "gl.hpp"
105-
// Cross platform window management (except android)
106-
#include "glfw/glfw.hpp"
107-
#endif
108108

109109
// Boilerplate for running an example
110110
#if defined(__ANDROID__)

base/ui.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
using namespace vkx;
2020
using namespace vkx::ui;
2121

22-
void UIOverlay::create(const UIOverlayCreateInfo& createInfo) {
23-
this->createInfo = createInfo;
22+
void UIOverlay::create(const UIOverlayCreateInfo& createInfo_) {
23+
createInfo = createInfo_;
2424
#if defined(__ANDROID__)
2525
// Screen density
2626
if (vkx::android::screenDensity >= ACONFIGURATION_DENSITY_XXXHIGH) {
@@ -62,6 +62,7 @@ void UIOverlay::create(const UIOverlayCreateInfo& createInfo) {
6262

6363
/** Free up all Vulkan resources acquired by the UI overlay */
6464
UIOverlay::~UIOverlay() {
65+
destroy();
6566
}
6667

6768
void UIOverlay::destroy() {
@@ -79,6 +80,7 @@ void UIOverlay::destroy() {
7980
context.device.freeCommandBuffers(commandPool, cmdBuffers);
8081
context.device.destroyCommandPool(commandPool);
8182
context.device.destroyFence(fence);
83+
commandPool = nullptr;
8284
}
8385
}
8486

@@ -217,7 +219,7 @@ void UIOverlay::preparePipeline() {
217219

218220
/** Prepare a separate render pass for rendering the UI as an overlay */
219221
void UIOverlay::prepareRenderPass() {
220-
vk::AttachmentDescription attachments[2] = {};
222+
std::array<vk::AttachmentDescription, 2> attachments;
221223

222224
// Color attachment
223225
attachments[0].format = createInfo.colorformat;
@@ -236,7 +238,7 @@ void UIOverlay::prepareRenderPass() {
236238

237239
vk::AttachmentReference colorReference{ 0, vk::ImageLayout::eColorAttachmentOptimal };
238240
vk::AttachmentReference depthReference{ 1, vk::ImageLayout::eDepthStencilAttachmentOptimal };
239-
vk::SubpassDependency subpassDependencies[2];
241+
std::array<vk::SubpassDependency, 2> subpassDependencies;
240242

241243
// Transition from final to initial (VK_SUBPASS_EXTERNAL refers to all commmands executed outside of the actual renderpass)
242244
subpassDependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
@@ -263,11 +265,11 @@ void UIOverlay::prepareRenderPass() {
263265

264266
vk::RenderPassCreateInfo renderPassInfo;
265267
renderPassInfo.attachmentCount = 2;
266-
renderPassInfo.pAttachments = attachments;
268+
renderPassInfo.pAttachments = attachments.data();
267269
renderPassInfo.subpassCount = 1;
268270
renderPassInfo.pSubpasses = &subpassDescription;
269271
renderPassInfo.dependencyCount = 2;
270-
renderPassInfo.pDependencies = subpassDependencies;
272+
renderPassInfo.pDependencies = subpassDependencies.data();
271273

272274
renderPass = context.device.createRenderPass(renderPassInfo);
273275
}
@@ -292,7 +294,7 @@ void UIOverlay::updateCommandBuffers() {
292294

293295
if (cmdBuffers.size()) {
294296
context.trashAll<vk::CommandBuffer>(cmdBuffers,
295-
[&](const std::vector<vk::CommandBuffer>& buffers) { context.device.freeCommandBuffers(commandPool, buffers); });
297+
[this](const std::vector<vk::CommandBuffer>& buffers) { context.device.freeCommandBuffers(commandPool, buffers); });
296298
cmdBuffers.clear();
297299
}
298300

@@ -404,8 +406,8 @@ void UIOverlay::update() {
404406
}
405407

406408
// Upload data
407-
ImDrawVert* vtxDst = (ImDrawVert*)vertexBuffer.mapped;
408-
ImDrawIdx* idxDst = (ImDrawIdx*)indexBuffer.mapped;
409+
auto vtxDst = (ImDrawVert*)vertexBuffer.mapped;
410+
auto idxDst = (ImDrawIdx*)indexBuffer.mapped;
409411

410412
for (int n = 0; n < imDrawData->CmdListsCount; n++) {
411413
const ImDrawList* cmd_list = imDrawData->CmdLists[n];
@@ -465,8 +467,8 @@ bool UIOverlay::checkBox(const char* caption, int32_t* value) const {
465467
return res;
466468
}
467469

468-
bool UIOverlay::inputFloat(const char* caption, float* value, float step, uint32_t precision) const {
469-
return ImGui::InputFloat(caption, value, step, step * 10.0f, precision);
470+
bool UIOverlay::inputFloat(const char* caption, float* value, float step, const char* format) const {
471+
return ImGui::InputFloat(caption, value, step, step * 10.0f, format);
470472
}
471473

472474
bool UIOverlay::sliderFloat(const char* caption, float* value, float min, float max) const {
@@ -486,7 +488,7 @@ bool UIOverlay::comboBox(const char* caption, int32_t* itemindex, const std::vec
486488
for (size_t i = 0; i < items.size(); i++) {
487489
charitems.push_back(items[i].c_str());
488490
}
489-
uint32_t itemCount = static_cast<uint32_t>(charitems.size());
491+
auto itemCount = static_cast<uint32_t>(charitems.size());
490492
return ImGui::Combo(caption, itemindex, &charitems[0], itemCount, itemCount);
491493
}
492494

base/ui.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class UIOverlay {
5353
struct PushConstBlock {
5454
glm::vec2 scale;
5555
glm::vec2 translate;
56-
} pushConstBlock;
56+
};
57+
PushConstBlock pushConstBlock;
5758

5859
void prepareResources();
5960
void preparePipeline();
@@ -66,7 +67,7 @@ class UIOverlay {
6667

6768
std::vector<vk::CommandBuffer> cmdBuffers;
6869

69-
UIOverlay(const vks::Context& context)
70+
explicit UIOverlay(const vks::Context& context)
7071
: context(context) {}
7172
~UIOverlay();
7273

@@ -81,7 +82,7 @@ class UIOverlay {
8182
bool header(const char* caption) const;
8283
bool checkBox(const char* caption, bool* value) const;
8384
bool checkBox(const char* caption, int32_t* value) const;
84-
bool inputFloat(const char* caption, float* value, float step, uint32_t precision) const;
85+
bool inputFloat(const char* caption, float* value, float step, const char* precision = "%.3f") const;
8586
bool sliderFloat(const char* caption, float* value, float min, float max) const;
8687
bool sliderInt(const char* caption, int32_t* value, int32_t min, int32_t max) const;
8788
bool comboBox(const char* caption, int32_t* itemindex, const std::vector<std::string>& items) const;

base/vks/filesystem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
namespace vks { namespace file {
1212

13-
void withBinaryFileContents(const std::string& filename, std::function<void(size_t size, const void* data)> handler) {
14-
withBinaryFileContents(filename, [&](const char* filename, size_t size, const void* data) { handler(size, data); });
13+
void withBinaryFileContents(const std::string& filename, const SimpleHandler& handler) {
14+
withBinaryFileContents(filename, [&handler](const char*, size_t size, const void* data_) { handler(size, data_); });
1515
}
1616

17-
void withBinaryFileContents(const std::string& filename, std::function<void(const char* filename, size_t size, const void* data)> handler) {
17+
void withBinaryFileContents(const std::string& filename, const NamedHandler& handler) {
1818
auto storage = storage::Storage::readFile(filename);
1919
handler(filename.c_str(), storage->size(), storage->data());
2020
}
2121

2222
std::vector<uint8_t> readBinaryFile(const std::string& filename) {
2323
std::vector<uint8_t> result;
24-
withBinaryFileContents(filename, [&](size_t size, const void* data) {
24+
withBinaryFileContents(filename, [&result](size_t size, const void* data) {
2525
result.resize(size);
2626
memcpy(result.data(), data, size);
2727
});
@@ -33,7 +33,7 @@ std::string readTextFile(const std::string& fileName) {
3333
std::ifstream fileStream(fileName, std::ios::in);
3434

3535
if (!fileStream.is_open()) {
36-
throw std::runtime_error("File " + fileName + " not found");
36+
throw std::invalid_argument("File " + fileName + " not found");
3737
}
3838
std::string line = "";
3939
while (!fileStream.eof()) {

base/vks/filesystem.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
namespace vks { namespace file {
99

10-
void withBinaryFileContents(const std::string& filename, std::function<void(const char* filename, size_t size, const void* data)> handler);
10+
using SimpleHandler = std::function<void(size_t, const void*)>;
11+
using NamedHandler = std::function<void(const char*, size_t, const void*)>;
1112

12-
void withBinaryFileContents(const std::string& filename, std::function<void(size_t size, const void* data)> handler);
13+
void withBinaryFileContents(const std::string& filename, const SimpleHandler& handler);
14+
15+
void withBinaryFileContents(const std::string& filename, const NamedHandler& handler);
1316

1417
std::string readTextFile(const std::string& fileName);
1518

base/vks/model.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ using namespace vks::model;
2121
const int Model::defaultFlags =
2222
aiProcess_FlipWindingOrder | aiProcess_Triangulate | aiProcess_PreTransformVertices | aiProcess_CalcTangentSpace | aiProcess_GenSmoothNormals;
2323

24-
void Model::loadFromFile(const Context& context, const std::string& filename, const VertexLayout& layout, const ModelCreateInfo& createInfo, const int flags) {
25-
this->layout = layout;
24+
void Model::loadFromFile(const Context& context, const std::string& filename, const VertexLayout& layout_, const ModelCreateInfo& createInfo, const int flags) {
25+
layout = layout_;
2626
scale = createInfo.scale;
2727
uvscale = createInfo.uvscale;
2828
center = createInfo.center;
@@ -32,15 +32,14 @@ void Model::loadFromFile(const Context& context, const std::string& filename, co
3232
Assimp::Importer importer;
3333
const aiScene* pScene;
3434

35-
3635
// Load file
37-
vks::file::withBinaryFileContents(filename, [&](const char* filename, size_t size, const void* data) {
38-
pScene = importer.ReadFileFromMemory(data, size, flags, filename);
36+
vks::file::withBinaryFileContents(filename, [flags, &pScene, &importer](const char* filename_, size_t size, const void* data) {
37+
pScene = importer.ReadFileFromMemory(data, size, flags, filename_);
3938
});
4039

4140
if (!pScene) {
4241
std::string error = importer.GetErrorString();
43-
throw std::runtime_error(
42+
throw std::invalid_argument(
4443
error +
4544
"\n\nThe file may be part of the additional asset pack.\n\nRun \"download_assets.py\" in the repository root to download the latest version.");
4645
}
@@ -158,6 +157,9 @@ void Model::appendVertex(std::vector<uint8_t>& outputBuffer, const aiScene* pSce
158157
vertexBuffer.push_back(0.0f);
159158
vertexBuffer.push_back(0.0f);
160159
break;
160+
default:
161+
throw new std::invalid_argument("Bad case");
162+
161163
};
162164
}
163165
appendOutput(outputBuffer, vertexBuffer);

base/vks/pipelines.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "context.hpp"
44
#include "model.hpp"
55
#include "shaders.hpp"
6+
#include <exception>
67

78
namespace vks { namespace pipelines {
89
struct PipelineRasterizationStateCreateInfo : public vk::PipelineRasterizationStateCreateInfo {
@@ -72,7 +73,7 @@ struct PipelineVertexInputStateCreateInfo : public vk::PipelineVertexInputStateC
7273
auto attributeIndexOffset = (uint32_t)attributeDescriptions.size();
7374
for (uint32_t i = 0; i < componentsSize; ++i) {
7475
const auto& component = vertexLayout.components[i];
75-
const auto format = vertexLayout.componentFormat(component);
76+
const auto format = vks::model::VertexLayout::componentFormat(component);
7677
const auto offset = vertexLayout.offset(i);
7778
attributeDescriptions.emplace_back(attributeIndexOffset + i, binding, format, offset);
7879
}
@@ -188,7 +189,7 @@ struct GraphicsPipelineBuilder {
188189

189190
vk::Pipeline create(const vk::PipelineCache& cache) {
190191
update();
191-
return device.createGraphicsPipeline(cache, pipelineCreateInfo);
192+
return device.createGraphicsPipeline(cache, pipelineCreateInfo).value;
192193
}
193194

194195
vk::Pipeline create() { return create(pipelineCache); }

base/vulkanExampleBase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ void ExampleBase::renderLoop() {
242242
}
243243

244244
std::string ExampleBase::getWindowTitle() {
245-
std::string device(context.deviceProperties.deviceName);
245+
std::string deviceName = context.deviceProperties.deviceName;
246246
std::string windowTitle;
247-
windowTitle = title + " - " + device + " - " + std::to_string(frameCounter) + " fps";
247+
windowTitle = title + " - " + deviceName + " - " + std::to_string(frameCounter) + " fps";
248248
return windowTitle;
249249
}
250250

@@ -665,7 +665,7 @@ void ExampleBase::updateOverlay() {
665665

666666
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0);
667667
ImGui::SetNextWindowPos(ImVec2(10, 10));
668-
ImGui::SetNextWindowSize(ImVec2(0, 0), ImGuiSetCond_FirstUseEver);
668+
ImGui::SetNextWindowSize(ImVec2(0, 0), ImGuiCond_FirstUseEver);
669669
ImGui::Begin("Vulkan Example", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
670670
ImGui::TextUnformatted(title.c_str());
671671
ImGui::TextUnformatted(context.deviceProperties.deviceName);

cmake/ezvcpkg/ezvcpkg.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ macro(EZVCPKG_BOOTSTRAP)
107107
# present and the user will have the default checkout, rather than their requested commit
108108
message(STATUS "EZVCPKG Checking out commit ${EZVCPKG_COMMIT}")
109109
execute_process(
110-
COMMAND ${GIT_EXECUTABLE} "checkout" ${EZVCPKG_COMMIT}
110+
COMMAND ${GIT_EXECUTABLE} "-c" "advice.detachedHead=false" "checkout" ${EZVCPKG_COMMIT}
111111
WORKING_DIRECTORY ${EZVCPKG_DIR}
112112
OUTPUT_QUIET)
113113
endif()

0 commit comments

Comments
 (0)