1#include <imgui_impl_glfw.h>
2#include <imgui_impl_vulkan.h>
4#include <glm/gtc/type_ptr.hpp>
13 ImGui_ImplVulkan_Shutdown();
14 ImGui_ImplGlfw_Shutdown();
15 ImGui::DestroyContext();
20 VkPhysicalDeviceProperties deviceProperties;
21 vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
22 ImGui_ImplVulkan_NewFrame();
23 ImGui_ImplGlfw_NewFrame();
25 renderFrameWindow(clockData);
27 rendererSection(renderer, ubo);
28 cameraSection(camera);
29 lightsSection(sceneManager);
30 objectsSection(sceneManager);
32 devicePropertiesSection(deviceProperties);
41 ImGui::SetNextWindowPos(ImVec2(0.0F, 0.0F), ImGuiCond_Always, ImVec2(0.0F, 0.0F));
42 ImGui::Begin(
"Application Info",
nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav);
43 ImGui::Text(
"FPS: %.1f", clockData.
fps);
44 ImGui::Text(
"Frame time: %.3fms", clockData.
deltaTimeMS);
50 ImGui::SetNextWindowPos(ImVec2(0.0F, 45.0F), ImGuiCond_Always, ImVec2(0.0F, 0.0F));
51 ImGui::Begin(
"Editor tools");
52 if (ImGui::CollapsingHeader(
"Renderer")) {
55 if (ImGui::BeginTable(
"ClearColorTable", 2)) {
56 ImGui::TableNextColumn();
59 if (ImGui::ColorEdit4(
"Clear Color", clearColor.data())) {
60 const VkClearColorValue clearColorValue = {{clearColor[0], clearColor[1], clearColor[2], clearColor[3]}};
64 ImGui::TableNextColumn();
65 static int item_current = 0;
67 if (ImGui::Combo(
"Color Presets##clearColor",
69 [](
void*,
const int idx,
const char** out_text) ->
bool {
79 ImGui::TableNextColumn();
81 ImGui::TableNextColumn();
82 if (ImGui::Combo(
"Color Presets##ambientColor",
84 [](
void*,
const int idx,
const char** out_text) ->
bool {
94 ImGui::TableNextColumn();
95 ImGui::SliderFloat((
"Intensity##" + std::to_string(0)).c_str(), &ubo.
ambientLightColor.a, 0.0F, 1.0F);
96 ImGui::TableNextColumn();
102 static bool fullscreen =
false;
103 if (ImGui::Checkbox(
"Fullscreen", &fullscreen)) {
111 if (ImGui::CollapsingHeader(
"Camera")) {
112 float fov = camera.
getFov();
113 float tnear = camera.
getNear();
114 float tfar = camera.
getFar();
115 if (ImGui::BeginTable(
"CameraTable", 2)) {
116 ImGui::TableNextColumn();
118 ImGui::TableNextColumn();
121 ImGui::TableNextColumn();
123 ImGui::TableNextColumn();
126 ImGui::TableNextColumn();
127 if (ImGui::SliderFloat(
"FOV", &fov, glm::radians(0.1F), glm::radians(180.0F))) { camera.
setFov(fov); }
128 ImGui::TableNextColumn();
131 ImGui::TableNextColumn();
132 if (ImGui::SliderFloat(
"Near", &tnear, 0.001F, 10.0F)) { camera.
setNear(tnear); }
133 ImGui::TableNextColumn();
136 ImGui::TableNextColumn();
137 if (ImGui::SliderFloat(
"Far", &tfar, 1.F, 1000.0F)) { camera.
setFar(tfar); }
138 ImGui::TableNextColumn();
141 ImGui::TableNextColumn();
143 if (ImGui::SliderFloat(
"Move speed", &moveSpeed, 0.1F, 10.0F)) { camera.
setMoveSpeed(moveSpeed); }
144 ImGui::TableNextColumn();
147 ImGui::TableNextColumn();
149 if (ImGui::SliderFloat(
"Look speed", &lookSpeed, 0.1F, 10.0F)) { camera.
setLookSpeed(lookSpeed); }
150 ImGui::TableNextColumn();
160 if (ImGui::CollapsingHeader(
"Objects")) {
164 open = ImGui::TreeNode(std::string(
object.getName() +
" [" + std::to_string(
object.getId()) +
"]").c_str());
165 ImGui::PopStyleColor(1);
167 if (ImGui::Button((
"Delete##" +
object.getName()).c_str())) {
168 m_objectsToRemove.push_back(
id);
172 if (ImGui::Button((
"Duplicate##" +
object.getName()).c_str())) {
175 ImGui::Text(
"Address: %p",
static_cast<void*
>(&
object));
176 ImGui::DragFloat3((
"Position##" +
object.getName()).c_str(), glm::value_ptr(
object.transform.translation), 0.1F);
177 ImGui::DragFloat3((
"Rotation##" +
object.getName()).c_str(), glm::value_ptr(
object.transform.rotation), 0.1F);
178 ImGui::DragFloat3((
"Scale##" +
object.getName()).c_str(), glm::value_ptr(
object.transform.scale), 0.1F);
188 if (ImGui::CollapsingHeader(
"Lights")) {
190 float tempIntensity = m_intensity;
191 float tempShininess = m_shininess;
194 if (ImGui::BeginTable(
"LightTable", 2)) {
195 ImGui::TableNextColumn();
196 if (ImGui::SliderFloat(
"Global Intensity", &tempIntensity, 0.0F, 5.F)) {
197 m_intensity = tempIntensity;
198 for (
auto&[fst, snd] : lights) {
199 snd.color.a = m_intensity;
202 ImGui::TableNextColumn();
203 if (ImGui::Button(
"Reset")) {
205 tempIntensity = m_intensity;
206 for (
auto&[fst, snd] : lights) {
207 snd.color.a = m_intensity;
211 ImGui::TableNextColumn();
212 if (ImGui::SliderFloat(
"Global Shininess", &tempShininess, 0.0F, 512.F)) {
213 m_shininess = tempShininess;
214 for (
auto&[fst, snd] : lights) {
215 snd.setShininess(m_shininess);
219 ImGui::TableNextColumn();
220 if (ImGui::Button(
"Reset")) {
222 tempShininess = m_shininess;
223 for (
auto&[fst, snd] : lights) {
224 snd.setShininess(m_shininess);
231 for (
auto& [
id, light] : lights) {
232 ImGui::PushStyleColor(ImGuiCol_Text, {light.color.r, light.color.g, light.color.b, 1.0F});
233 open = ImGui::TreeNode(std::string(light.getName() +
" [" + std::to_string(light.getId()) +
"]").c_str());
234 ImGui::PopStyleColor(1);
236 if (ImGui::Button((
"Delete##" + light.getName()).c_str())) {
237 m_lightsToRemove.push_back(
id);
241 if (ImGui::Button((
"Duplicate##" + light.getName()).c_str())) {
244 ImGui::Text(
"Address: %p",
static_cast<void*
>(&light));
245 ImGui::DragFloat3((
"Position##" + std::to_string(light.getId())).c_str(), glm::value_ptr(light.transform.translation), 0.1F);
246 ImGui::DragFloat3((
"Rotation##" + std::to_string(light.getId())).c_str(), glm::value_ptr(light.transform.rotation), 0.1F);
247 ImGui::DragFloat3((
"Scale##" + std::to_string(light.getId())).c_str(), glm::value_ptr(light.transform.scale), 0.1F);
248 if (ImGui::BeginTable(
"ColorTable", 2)) {
249 ImGui::TableNextColumn();
250 ImGui::ColorEdit4((
"Color##" + std::to_string(light.getId())).c_str(), glm::value_ptr(light.color));
251 ImGui::TableNextColumn();
252 static int item_current = 0;
253 if (ImGui::Combo(
"Color Presets",
255 [](
void*,
const int idx,
const char** out_text) ->
bool {
266 ImGui::SliderFloat((
"Intensity##" + std::to_string(light.getId())).c_str(), &light.color.a, 0.0F, 5.F);
268 if (ImGui::Button((
"Reset##" + std::to_string(light.getId())).c_str())) { light.color.a =
DEFAULT_LIGHT_INTENSITY; }
269 float shininess = light.getShininess();
270 if (ImGui::SliderFloat(
"Shininess", &shininess, 0.0F, 512.F)) {
271 light.setShininess(shininess);
274 if (ImGui::Button(
"Reset##shininess")) { light.setShininess(
DEFAULT_SHININESS); }
284 if (ImGui::CollapsingHeader(
"Input")) {
285 ImGui::IsMousePosValid() ? ImGui::Text(
"Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y) : ImGui::Text(
"Mouse pos: <INVALID>");
286 ImGui::Text(
"Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y);
287 ImGui::Text(
"Mouse down:");
288 for (
int i = 0; i < static_cast<int>(std::size(io.MouseDown)); i++) {
289 if (ImGui::IsMouseDown(i)) {
291 ImGui::Text(
"b%d (%.02f secs)", i, io.MouseDownDuration[i]);
294 ImGui::Text(
"Mouse wheel: %.1f", io.MouseWheel);
295 ImGui::Text(
"Keys down:");
296 for (
auto key =
static_cast<ImGuiKey
>(0); key < ImGuiKey_NamedKey_END; key = static_cast<ImGuiKey>(key + 1)) {
297 if (funcs::IsLegacyNativeDupe(key) || !ImGui::IsKeyDown(key)) {
continue; }
299 ImGui::Text((key < ImGuiKey_NamedKey_BEGIN) ?
"\"%s\"" :
"\"%s\" %d", ImGui::GetKeyName(key), key);
306 if (ImGui::CollapsingHeader(
"Device Properties")) {
307 if (ImGui::BeginTable(
"DevicePropertiesTable", 2)) {
309 ImGui::TableNextColumn(); ImGui::Text(
"Device Name: %s", deviceProperties.deviceName);
310 ImGui::TableNextColumn(); ImGui::Text(
"API Version: %d.%d.%d", VK_VERSION_MAJOR(deviceProperties.apiVersion), VK_VERSION_MINOR(deviceProperties.apiVersion), VK_VERSION_PATCH(deviceProperties.apiVersion));
311 ImGui::TableNextColumn(); ImGui::Text(
"Driver Version: %d.%d.%d", VK_VERSION_MAJOR(deviceProperties.driverVersion), VK_VERSION_MINOR(deviceProperties.driverVersion), VK_VERSION_PATCH(deviceProperties.driverVersion));
312 ImGui::TableNextColumn(); ImGui::Text(
"Vendor ID: %d", deviceProperties.vendorID);
313 ImGui::TableNextColumn(); ImGui::Text(
"Device ID: %d", deviceProperties.deviceID);
314 ImGui::TableNextColumn(); ImGui::Text(
"Device Type: %d", deviceProperties.deviceType);
315 ImGui::TableNextColumn(); ImGui::Text(
"Discrete Queue Priorities: %d", deviceProperties.limits.discreteQueuePriorities);
316 ImGui::TableNextColumn(); ImGui::Text(
"Max Push Constants Size: %d", deviceProperties.limits.maxPushConstantsSize);
317 ImGui::TableNextColumn(); ImGui::Text(
"Max Memory Allocation Count: %d", deviceProperties.limits.maxMemoryAllocationCount);
318 ImGui::TableNextColumn(); ImGui::Text(
"Max Image Dimension 1D: %d", deviceProperties.limits.maxImageDimension1D);
319 ImGui::TableNextColumn(); ImGui::Text(
"Max Image Dimension 2D: %d", deviceProperties.limits.maxImageDimension2D);
320 ImGui::TableNextColumn(); ImGui::Text(
"Max Image Dimension 3D: %d", deviceProperties.limits.maxImageDimension3D);
321 ImGui::TableNextColumn(); ImGui::Text(
"Max Image Dimension Cube: %d", deviceProperties.limits.maxImageDimensionCube);
322 ImGui::TableNextColumn(); ImGui::Text(
"Max Image Array Layers: %d", deviceProperties.limits.maxImageArrayLayers);
323 ImGui::TableNextColumn(); ImGui::Text(
"Max Texel Buffer Elements: %d", deviceProperties.limits.maxTexelBufferElements);
324 ImGui::TableNextColumn(); ImGui::Text(
"Max Uniform Buffer Range: %d", deviceProperties.limits.maxUniformBufferRange);
325 ImGui::TableNextColumn(); ImGui::Text(
"Max Storage Buffer Range: %d", deviceProperties.limits.maxStorageBufferRange);
This file contains the Light Factory class.
This file contains the Object Factory class.
This file contains the ImGuiWindowManager class.
void setMoveSpeed(const float moveSpeed)
float getMoveSpeed() const
float getLookSpeed() const
void setNear(const float near)
void setLookSpeed(const float lookSpeed)
void setFov(const float fov)
void setFar(const float far)
static constexpr std::array< std::pair< const char *, glm::vec4 >, 20 > COLOR_PRESETS_4
static constexpr glm::vec4 GRAY_4
static constexpr std::array< std::pair< const char *, glm::vec3 >, 20 > COLOR_PRESETS_3
static constexpr std::array< std::pair< const char *, VkClearColorValue >, 20 > COLOR_PRESETS_VK
static void renderFrameWindow(const ClockData &clockData)
static void cameraSection(Camera &camera)
void lightsSection(SceneManager &sceneManager)
static void rendererSection(Renderer *renderer, GlobalUbo &ubo)
static void inputsSection(const ImGuiIO &io)
static void devicePropertiesSection(VkPhysicalDeviceProperties deviceProperties)
void render(Renderer *renderer, SceneManager &sceneManager, Camera &camera, VkPhysicalDevice physicalDevice, GlobalUbo &ubo, const ClockData &clockData)
void objectsSection(SceneManager &sceneManager)
static std::unique_ptr< Light > duplicate(const Light &cpyLight)
std::unordered_map< unsigned int, Light > Map
static std::unique_ptr< Object > duplicate(const Object &objSrc)
std::unordered_map< unsigned int, Object > Map
Window & getWindow() const
std::array< float, 4 > getClearColor() const
float getAspectRatio() const
void setClearValue(const VkClearColorValue clearColorValue=DEFAULT_CLEAR_COLOR, const VkClearDepthStencilValue clearDepthValue=DEFAULT_CLEAR_DEPTH)
VkCommandBuffer getCurrentCommandBuffer() const
Class for object manager.
void setDestroyState(const bool state)
Object::Map & getObjects()
VkExtent2D getExtent() const
void setFullscreen(bool fullscreen, uint32_t width, uint32_t height)
static constexpr glm::vec3 DEFAULT_POSITION
static constexpr float DEFAULT_FOV
static constexpr float DEFAULT_LOOK_SPEED
static constexpr float DEFAULT_SHININESS
static constexpr float DEFAULT_AMBIENT_LIGHT_INTENSITY
static constexpr float DEFAULT_MOVE_SPEED
static constexpr float DEFAULT_NEAR
static constexpr float DEFAULT_LIGHT_INTENSITY
static constexpr glm::vec3 DEFAULT_ROTATION
static constexpr float DEFAULT_FAR
glm::vec4 ambientLightColor