Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
144 lines (120 loc) · 5.45 KB
/
Copy pathmain.cpp
File metadata and controls
144 lines (120 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (c) 2021-2025, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0
*/
#define VMA_IMPLEMENTATION
#include <nvapp/elem_camera.hpp>
#include <nvapp/elem_default_menu.hpp>
#include <nvapp/elem_default_title.hpp>
#include <nvapp/elem_logger.hpp>
#include <nvutils/file_operations.hpp>
#include "idbufferrasterization.hpp"
using namespace idraster;
int main(int argc, char** argv)
{
try
{
nvapp::ApplicationCreateInfo appInfo;
appInfo.name = TARGET_NAME;
appInfo.useMenu = true;
appInfo.vSync = false;
VkPhysicalDeviceShaderObjectFeaturesEXT shaderObjectFeature{};
shaderObjectFeature.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT;
shaderObjectFeature.shaderObject = VK_TRUE;
nvvk::ContextInitInfo vkSetup{
.instanceExtensions = {VK_EXT_DEBUG_UTILS_EXTENSION_NAME},
.deviceExtensions = {{VK_KHR_SWAPCHAIN_EXTENSION_NAME}, {VK_EXT_SHADER_OBJECT_EXTENSION_NAME, &shaderObjectFeature}},
};
nvutils::ProfilerManager profilerManager;
std::shared_ptr<nvutils::CameraManipulator> cameraManipulator = std::make_shared<nvutils::CameraManipulator>();
nvutils::ParameterRegistry parameterRegistry;
nvutils::ParameterParser parameterParser;
parameterRegistry.add({"validation"}, &vkSetup.enableValidationLayers);
parameterRegistry.add({"vsync"}, &appInfo.vSync);
parameterRegistry.add({"device", "force a vulkan device via index into the device list"}, &vkSetup.forceGPU);
std::shared_ptr<IdRasterElement> sampleElement = std::make_shared<IdRasterElement>();
sampleElement->setupConfigParameters(parameterRegistry);
parameterParser.add(parameterRegistry);
parameterParser.parse(argc, argv);
nvvk::addSurfaceExtensions(vkSetup.instanceExtensions);
nvvk::Context vkContext;
if(vkContext.init(vkSetup) != VK_SUCCESS)
{
LOGE("Error in Vulkan context creation\n");
return 1;
}
appInfo.instance = vkContext.getInstance();
appInfo.device = vkContext.getDevice();
appInfo.physicalDevice = vkContext.getPhysicalDevice();
appInfo.queues = vkContext.getQueueInfos();
// Setting up the layout of the application
appInfo.dockSetup = [](ImGuiID viewportID) {
#ifndef NDEBUG
// left side panel container
ImGuiID debugID = ImGui::DockBuilderSplitNode(viewportID, ImGuiDir_Left, 0.15F, nullptr, &viewportID);
ImGui::DockBuilderDockWindow("Debug", debugID);
#endif
// right side panel container
ImGuiID settingID = ImGui::DockBuilderSplitNode(viewportID, ImGuiDir_Right, 0.25F, nullptr, &viewportID);
ImGui::DockBuilderDockWindow("Settings", settingID);
ImGuiID loggerID = ImGui::DockBuilderSplitNode(settingID, ImGuiDir_Down, 0.35F, nullptr, &settingID);
ImGui::DockBuilderDockWindow("Log", loggerID);
ImGuiID profilerID = ImGui::DockBuilderSplitNode(loggerID, ImGuiDir_Down, 0.4F, nullptr, &loggerID);
ImGui::DockBuilderDockWindow("Profiler", profilerID);
};
// Create the application
nvapp::Application app;
app.init(appInfo);
auto logger = std::make_shared<nvapp::ElementLogger>();
nvapp::ElementLogger* loggerDeref = logger.get();
nvutils::Logger::getInstance().setLogCallback([&](nvutils::Logger::LogLevel logLevel, const std::string& text) {
loggerDeref->addLog(logLevel, "%s", text.c_str());
});
sampleElement->setContext(&vkContext);
sampleElement->setProfilerManager(&profilerManager);
sampleElement->setCameraManipulator(cameraManipulator);
// Set default model filename
if(sampleElement->m_modelFilename.empty())
{
std::vector<std::filesystem::path> directories;
directories.push_back(nvutils::getExecutablePath().parent_path());
directories.push_back(nvutils::getExecutablePath().parent_path() / "media");
directories.push_back(nvutils::getExecutablePath().parent_path() / TARGET_EXE_TO_DOWNLOAD_DIRECTORY);
sampleElement->m_modelFilename = nvutils::findFile(std::string("worldcar_parts.gltf"), directories);
}
app.addElement(std::make_shared<nvapp::ElementDefaultMenu>());
app.addElement(std::make_shared<nvapp::ElementDefaultWindowTitle>());
app.addElement(logger);
app.addElement(sampleElement);
app.addElement(std::make_shared<nvapp::ElementCamera>(cameraManipulator));
app.addElement(std::make_shared<nvapp::ElementProfiler>(&profilerManager));
app.run();
nvutils::Logger::getInstance().setLogCallback(nullptr);
// Cleanup in reverse order
app.deinit();
vkContext.deinit();
return 0;
}
catch(const std::exception& e)
{
LOGE("Uncaught exception: %s\n", e.what());
assert(!"We should never reach here under normal operation, but this "
"prints a nicer error message in the event we do.");
return EXIT_FAILURE;
}
}