plumageRender/src/render/render.h

186 lines
3.4 KiB
C
Raw Normal View History

#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
#include <assert.h>
#include <chrono>
#include <cstdio>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include "algorithm"
#include <codecvt>
#include <filesystem>
2024-03-26 18:04:18 +08:00
#include <iostream>
#include <locale>
2024-03-26 18:04:18 +08:00
#include <sys/stat.h>
#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 17:52:06 +08:00
#ifndef _VULKANFOUNDATION_H
#define _VULKANFOUNDATION_H
#include "vulkanFoundation.h"
#endif // !VULKANFOUNDATION_H
#ifndef _GLTFMODEL_H
#define _GLTFMODEL_H
2024-04-10 17:52:06 +08:00
#include "glTFModel.h"
#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
#ifndef _UI_HPP
#define _UI_HPP
2024-04-10 17:52:06 +08:00
#include "ui.hpp"
#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 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 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-10 15:32:33 +08:00
#ifndef _STB_IMAGE_WRITE_H
2024-04-10 17:52:06 +08:00
#define _STB_IMAGE_WRITE_H
#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;
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
{
public:
2023-06-06 11:40:59 +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;
struct stat
{
} info;
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;
//VkImage swapChainImage;
2024-04-08 15:45:52 +08:00
static uint32_t currentBuffer;
uint64_t savedFrameCounter = 1;
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;
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();
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);
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
};
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
}
}
2023-05-26 15:20:44 +08:00