2023-06-12 11:05:10 +08:00
|
|
|
|
#pragma once
|
2023-05-26 15:20:44 +08:00
|
|
|
|
|
2024-04-10 17:52:06 +08:00
|
|
|
|
|
|
|
|
|
#ifndef TINYGLTF_IMPLEMENTATION
|
|
|
|
|
#define TINYGLTF_IMPLEMENTATION
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef STB_IMAGE_IMPLEMENTATION
|
|
|
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
|
|
|
|
#define TINYGLTF_NO_STB_IMAGE_WRITE
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2024-04-10 11:50:50 +08:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <map>
|
2023-06-05 21:31:21 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <vector>
|
2024-03-27 17:29:32 +08:00
|
|
|
|
|
2023-06-05 21:31:21 +08:00
|
|
|
|
#include "algorithm"
|
2024-04-10 11:50:50 +08:00
|
|
|
|
#include <codecvt>
|
|
|
|
|
#include <filesystem>
|
2024-03-26 18:04:18 +08:00
|
|
|
|
#include <iostream>
|
2024-04-10 11:50:50 +08:00
|
|
|
|
#include <locale>
|
2024-03-26 18:04:18 +08:00
|
|
|
|
#include <sys/stat.h>
|
2023-06-05 21:31:21 +08:00
|
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
2024-04-09 13:31:15 +08:00
|
|
|
|
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#ifndef _GLFW3_H
|
|
|
|
|
#define _GLFW3_H
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "GLFW/glfw3.h"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_GLFW3_H
|
2024-04-10 11:50:50 +08:00
|
|
|
|
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#ifndef _VULKANFOUNDATION_H
|
|
|
|
|
#define _VULKANFOUNDATION_H
|
|
|
|
|
#include "vulkanFoundation.h"
|
|
|
|
|
#endif // !VULKANFOUNDATION_H
|
2024-04-10 11:50:50 +08:00
|
|
|
|
|
|
|
|
|
#ifndef _GLTFMODEL_H
|
|
|
|
|
#define _GLTFMODEL_H
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "glTFModel.h"
|
2024-04-10 11:50:50 +08:00
|
|
|
|
#endif // !GLTFMODEL_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#ifndef _RENDERGUI_H
|
|
|
|
|
#define _RENDERGUI_H
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "renderUI.h"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_RENDERGUI_H
|
|
|
|
|
|
2024-04-10 11:50:50 +08:00
|
|
|
|
#ifndef _UI_HPP
|
|
|
|
|
#define _UI_HPP
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "ui.hpp"
|
2024-04-10 11:50:50 +08:00
|
|
|
|
#endif // !UI_HPP
|
|
|
|
|
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#ifndef _RENDERIO_H
|
|
|
|
|
#define _RENDERIO_H
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "renderIO.h"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !RENDERIO_H
|
2024-04-10 11:50:50 +08:00
|
|
|
|
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#ifndef _VULKANDEVICE_HPP
|
|
|
|
|
#define _VULKANDEVICE_HPP
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "VulkanDevice.hpp"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_VULKANDEVICE_HPP
|
|
|
|
|
|
|
|
|
|
#ifndef _CAMERA_HPP
|
|
|
|
|
#define _CAMERA_HPP
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "camera.hpp"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_CAMERA_HPP
|
|
|
|
|
|
|
|
|
|
#ifndef _VULKANTEXTURE_HPP
|
|
|
|
|
#define _VULKANTEXTURE_HPP
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "VulkanTexture.hpp"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_VULKANTEXTURE_HPP
|
2024-04-10 11:50:50 +08:00
|
|
|
|
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#ifndef _VULKANUTILS_HPP
|
|
|
|
|
#define _VULKANUTILS_HPP
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#include "VulkanUtils.hpp"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_VULKANUTILS_HPP
|
2024-04-02 12:08:46 +08:00
|
|
|
|
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#ifndef _STB_IMAGE_WRITE_H
|
2024-04-10 17:52:06 +08:00
|
|
|
|
#define _STB_IMAGE_WRITE_H
|
2024-03-29 11:04:47 +08:00
|
|
|
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
|
|
|
#include "stb_image_write.h"
|
2024-04-10 15:32:33 +08:00
|
|
|
|
#endif // !_STB_IMAGE_WRITE_H
|
|
|
|
|
|
|
|
|
|
|
2023-05-26 15:20:44 +08:00
|
|
|
|
#define ENABLE_VALIDATION false
|
|
|
|
|
|
2024-04-10 17:52:06 +08:00
|
|
|
|
PluamgeVulkanBackend::VulkanFoundation vkFoundation;
|
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
namespace PlumageRender
|
2023-05-26 15:20:44 +08:00
|
|
|
|
{
|
2024-04-10 17:52:06 +08:00
|
|
|
|
|
|
|
|
|
|
2024-04-08 15:45:52 +08:00
|
|
|
|
class renderMain
|
2023-06-06 11:40:59 +08:00
|
|
|
|
{
|
2024-04-07 17:29:35 +08:00
|
|
|
|
public:
|
2023-06-06 11:40:59 +08:00
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
GLFWwindow* window;
|
2023-06-05 16:40:39 +08:00
|
|
|
|
|
2024-04-08 15:45:52 +08:00
|
|
|
|
|
2024-04-09 13:31:15 +08:00
|
|
|
|
|
2024-04-08 11:10:30 +08:00
|
|
|
|
struct Models
|
|
|
|
|
{
|
|
|
|
|
glTFModel::Model scene;
|
|
|
|
|
glTFModel::Model skybox;
|
2024-04-10 17:52:06 +08:00
|
|
|
|
}models;
|
|
|
|
|
|
2023-06-05 21:31:21 +08:00
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
struct stat
|
|
|
|
|
{
|
2023-06-05 21:31:21 +08:00
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
} info;
|
2023-06-05 21:31:21 +08:00
|
|
|
|
|
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
glm::vec3 modelrot = glm::vec3(0.0f);
|
|
|
|
|
glm::vec3 modelPos = glm::vec3(0.0f);
|
|
|
|
|
|
|
|
|
|
uint32_t frameIndex = 0;
|
2024-04-09 13:31:15 +08:00
|
|
|
|
uint32_t frameCounter = 0;
|
2024-04-07 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
//VkImage swapChainImage;
|
|
|
|
|
|
2024-04-08 15:45:52 +08:00
|
|
|
|
static uint32_t currentBuffer;
|
2024-04-07 17:29:35 +08:00
|
|
|
|
|
|
|
|
|
|
2024-04-10 11:50:50 +08:00
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
|
2024-04-10 11:50:50 +08:00
|
|
|
|
uint64_t savedFrameCounter = 1;
|
2024-04-07 17:29:35 +08:00
|
|
|
|
|
2024-04-08 18:10:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t lastFPS = 0;
|
2024-04-09 13:31:15 +08:00
|
|
|
|
float frameTimer = 1.0f;
|
|
|
|
|
float fpsTimer = 0.0f;
|
2024-04-08 18:10:00 +08:00
|
|
|
|
static int32_t animationIndex;
|
|
|
|
|
float animationTimer = 0.0f;
|
2024-04-07 17:29:35 +08:00
|
|
|
|
|
2024-04-09 23:48:07 +08:00
|
|
|
|
Camera camera;
|
2024-04-09 13:31:15 +08:00
|
|
|
|
|
2024-04-08 15:45:52 +08:00
|
|
|
|
|
2024-04-09 13:31:15 +08:00
|
|
|
|
renderMain();
|
|
|
|
|
~renderMain();
|
2023-06-05 21:31:21 +08:00
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
void initWindow(int width, int height);
|
|
|
|
|
static void framebufferResizeCallback(GLFWwindow* window, int width, int height);
|
|
|
|
|
void windowResized();
|
2024-04-10 17:52:06 +08:00
|
|
|
|
void prepare(Setter setter, PlumageGUI renderGUI, RenderInput renderInput, RenderOutput renderOutput, PBR::Material pbrMaterial, PluamgeVulkanBackend::VulkanFoundation vkFoundation, renderMain mainRender, UI* ui);
|
|
|
|
|
void setupCamera(Camera camera, Setter setter);
|
2024-04-07 17:29:35 +08:00
|
|
|
|
void submitWork(VkCommandBuffer cmdBuffer, VkQueue queue);
|
2024-04-08 18:10:00 +08:00
|
|
|
|
void submitToPresentQueue();
|
|
|
|
|
|
2024-04-10 17:52:06 +08:00
|
|
|
|
virtual void render(Setter setter, PlumageGUI plumageGUI, UI* gui, renderMain mainRender, PluamgeVulkanBackend::VulkanFoundation vkFoundation, RenderInput renderInput, RenderOutput renderOutput);
|
2024-04-10 15:32:33 +08:00
|
|
|
|
void renderLoop(GLFWwindow* window, Setter setter);
|
2024-04-09 13:31:15 +08:00
|
|
|
|
void drawFrame();
|
2024-04-08 15:45:52 +08:00
|
|
|
|
private:
|
2024-04-08 18:10:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool framebufferResized = false;
|
|
|
|
|
|
|
|
|
|
bool prepared = false;
|
|
|
|
|
|
2023-05-26 15:20:44 +08:00
|
|
|
|
};
|
2023-06-05 21:31:21 +08:00
|
|
|
|
|
2024-04-09 13:31:15 +08:00
|
|
|
|
renderMain::renderMain()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderMain::~renderMain()
|
|
|
|
|
{
|
2024-04-10 17:52:06 +08:00
|
|
|
|
models.scene.destroy(PluamgeVulkanBackend::VulkanFoundation::device);
|
|
|
|
|
models.skybox.destroy(PluamgeVulkanBackend::VulkanFoundation::device);
|
2024-04-09 13:31:15 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-04-07 17:29:35 +08:00
|
|
|
|
}
|
2023-05-26 15:20:44 +08:00
|
|
|
|
|