-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
170 lines (137 loc) · 5.36 KB
/
main.cpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright (c) 2019-2021, 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) 2019-2021 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0
*/
//--------------------------------------------------------------------------------------------------
// This example is creating a scene with many similar objects and a plane. There are a few materials
// and a light direction.
// More details in simple.cpp
//
#include <array>
#include <chrono>
#include <iostream>
#include <vulkan/vulkan.hpp>
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
#define IMGUI_DEFINE_MATH_OPERATORS
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_vulkan.h"
#include "example.hpp"
#include "GLFW/glfw3.h"
#include "nvh/fileoperations.hpp"
#include "nvh/inputparser.h"
#include "nvpsystem.hpp"
#include "nvvk/context_vk.hpp"
#include "nvvk/extensions_vk.hpp"
int const SAMPLE_SIZE_WIDTH = 1600;
int const SAMPLE_SIZE_HEIGHT = 1000;
// Default search path for shaders
std::vector<std::string> defaultSearchPaths;
//--------------------------------------------------------------------------------------------------
//
//
int main(int argc, char** argv)
{
// setup some basic things for the sample, logging file for example
NVPSystem system(PROJECT_NAME);
// Default search path for shaders
defaultSearchPaths = {
NVPSystem::exePath() + PROJECT_NAME,
NVPSystem::exePath() + R"(media)",
NVPSystem::exePath() + PROJECT_RELDIRECTORY,
NVPSystem::exePath() + PROJECT_DOWNLOAD_RELDIRECTORY,
};
// Parsing the command line: mandatory '-f' for the filename of the scene
InputParser parser(argc, argv);
std::string filename = parser.getString("-f");
if(parser.exist("-f"))
{
filename = parser.getString("-f");
}
else if(argc == 2 && nvh::endsWith(argv[1], ".gltf")) // Drag&Drop on .exe
{
filename = argv[1];
}
else
{
filename = nvh::findFile("robot/robot.gltf", defaultSearchPaths, true);
}
// Setup GLFW window
if(!glfwInit())
{
return 1;
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(SAMPLE_SIZE_WIDTH, SAMPLE_SIZE_HEIGHT, PROJECT_NAME, nullptr, nullptr);
// Enabling the extension
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT feature;
// Vulkan required extensions
assert(glfwVulkanSupported() == 1);
uint32_t count{0};
auto reqExtensions = glfwGetRequiredInstanceExtensions(&count);
// Requesting Vulkan extensions and layers
nvvk::ContextCreateInfo contextInfo;
contextInfo.setVersion(1, 2); // Using Vulkan 1.2
for(uint32_t ext_id = 0; ext_id < count; ext_id++) // Adding required extensions (surface, win32, linux, ..)
contextInfo.addInstanceExtension(reqExtensions[ext_id]);
contextInfo.addInstanceLayer("VK_LAYER_LUNARG_monitor", true); // FPS in titlebar
contextInfo.addInstanceExtension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, true); // Allow debug names
contextInfo.addDeviceExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME); // Enabling ability to present rendering
// #VKRay: Activate the ray tracing extension
contextInfo.addDeviceExtension(VK_NV_RAY_TRACING_EXTENSION_NAME, true /*optional*/);
// Creating the Vulkan instance and device
nvvk::Context vkctx;
vkctx.initInstance(contextInfo);
// Find all compatible devices
auto compatibleDevices = vkctx.getCompatibleDevices(contextInfo);
assert(!compatibleDevices.empty());
// Use first compatible device
vkctx.initDevice(compatibleDevices[0], contextInfo);
VkToonExample example;
// Window need to be opened to get the surface on which to draw
vk::SurfaceKHR surface = example.getVkSurface(vkctx.m_instance, window);
vkctx.setGCTQueueWithPresent(surface);
example.setup(vkctx.m_instance, vkctx.m_device, vkctx.m_physicalDevice, vkctx.m_queueGCT.familyIndex);
LOGI("Using %s \n", example.getPhysicalDevice().getProperties().deviceName.data());
example.createSwapchain(surface, SAMPLE_SIZE_WIDTH, SAMPLE_SIZE_HEIGHT);
example.createDepthBuffer();
example.createRenderPass();
example.createFrameBuffers();
//example.createTonemapper();
example.createAxis();
example.createDescriptorFinal();
example.createFinalPipeline(); // How the quad will be rendered
example.loadScene(filename); // Now build the example
example.createPostProcess(); // Adding all post-effects, line extractions, ..
example.initGUI(0); // Using sub-pass 0
// GLFW Callback
example.setupGlfwCallbacks(window);
ImGui_ImplGlfw_InitForVulkan(window, true);
// Main loop
while(!glfwWindowShouldClose(window))
{
glfwPollEvents();
if(example.isMinimized())
continue;
CameraManip.updateAnim();
example.display(); // infinitely drawing
}
glfwDestroyWindow(window);
glfwTerminate();
example.destroy();
vkctx.deinit();
return 0;
}