Merge branch 'render' into main
This commit is contained in:
+6
-1
@@ -23,6 +23,8 @@ endif()
|
|||||||
if(BUILD_MODE STREQUAL "Engine")
|
if(BUILD_MODE STREQUAL "Engine")
|
||||||
add_subdirectory(FastRTTI)
|
add_subdirectory(FastRTTI)
|
||||||
add_subdirectory(glfw)
|
add_subdirectory(glfw)
|
||||||
|
add_subdirectory(RenderEngineSDK)
|
||||||
|
add_subdirectory(UwURenderEngine)
|
||||||
add_subdirectory(Core)
|
add_subdirectory(Core)
|
||||||
add_subdirectory(ProjectGenerator)
|
add_subdirectory(ProjectGenerator)
|
||||||
|
|
||||||
@@ -32,15 +34,18 @@ elseif(BUILD_MODE STREQUAL "Tests")
|
|||||||
elseif(BUILD_MODE STREQUAL "TestGame")
|
elseif(BUILD_MODE STREQUAL "TestGame")
|
||||||
add_subdirectory(FastRTTI)
|
add_subdirectory(FastRTTI)
|
||||||
add_subdirectory(glfw)
|
add_subdirectory(glfw)
|
||||||
|
add_subdirectory(RenderEngineSDK)
|
||||||
|
add_subdirectory(UwURenderEngine)
|
||||||
add_subdirectory(Core)
|
add_subdirectory(Core)
|
||||||
add_subdirectory(TestGame)
|
add_subdirectory(TestGame)
|
||||||
|
|
||||||
elseif(BUILD_MODE STREQUAL "All")
|
elseif(BUILD_MODE STREQUAL "All")
|
||||||
add_subdirectory(FastRTTI)
|
add_subdirectory(FastRTTI)
|
||||||
add_subdirectory(glfw)
|
add_subdirectory(glfw)
|
||||||
|
add_subdirectory(RenderEngineSDK)
|
||||||
|
add_subdirectory(UwURenderEngine)
|
||||||
add_subdirectory(Core)
|
add_subdirectory(Core)
|
||||||
add_subdirectory(ProjectGenerator)
|
add_subdirectory(ProjectGenerator)
|
||||||
add_subdirectory(TestGame)
|
add_subdirectory(TestGame)
|
||||||
add_subdirectory(Tests)
|
add_subdirectory(Tests)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
+5
-2
@@ -6,12 +6,15 @@ file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.h" "*.hpp")
|
|||||||
|
|
||||||
add_library(${CORE_NAME} STATIC ${SRC})
|
add_library(${CORE_NAME} STATIC ${SRC})
|
||||||
target_compile_features(${CORE_NAME} PRIVATE cxx_std_17)
|
target_compile_features(${CORE_NAME} PRIVATE cxx_std_17)
|
||||||
|
target_include_directories(${CORE_NAME} PUBLIC
|
||||||
|
${PROJECT_SOURCE_DIR}/FastRTTI
|
||||||
|
${PROJECT_SOURCE_DIR}/Delegate
|
||||||
|
)
|
||||||
target_include_directories(${CORE_NAME}
|
target_include_directories(${CORE_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${PROJECT_SOURCE_DIR}/FastRTTI
|
|
||||||
${PROJECT_SOURCE_DIR}/Delegate
|
|
||||||
${PROJECT_SOURCE_DIR}/glfw/Include
|
${PROJECT_SOURCE_DIR}/glfw/Include
|
||||||
|
${PROJECT_SOURCE_DIR}/RenderEngineSDK
|
||||||
${Vulkan_INCLUDE_DIRS}
|
${Vulkan_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+23
-17
@@ -3,16 +3,16 @@
|
|||||||
#include "SystemCalls.hpp"
|
#include "SystemCalls.hpp"
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <cstring>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "RenderEngine/RenderEngine.hpp"
|
#include "RenderEngineBase.hpp"
|
||||||
#include "Game/GameInstance.hpp"
|
#include "Game/GameInstance.hpp"
|
||||||
#include "Game/SaveMap/SaveMap.hpp"
|
#include "Game/SaveMap/SaveMap.hpp"
|
||||||
|
|
||||||
extern GameInstance* GameFactory(CoreInstance&);
|
extern GameInstance* GameFactory(CoreInstance&);
|
||||||
|
RenderEngineBase* RenderEngineFactory(CoreInstance& core);
|
||||||
|
|
||||||
std::shared_ptr<SaveMap> CoreInstance::MainConfig::save()
|
std::shared_ptr<SaveMap> CoreInstance::MainConfig::save()
|
||||||
{
|
{
|
||||||
@@ -50,22 +50,31 @@ CoreInstance::CoreInstance()
|
|||||||
|
|
||||||
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
||||||
|
|
||||||
if (glfwInit() == GLFW_FALSE)
|
// if (glfwInit() == GLFW_FALSE)
|
||||||
throw std::runtime_error("Fail init glfw");
|
// throw std::runtime_error("Fail init glfw");
|
||||||
|
//
|
||||||
|
// glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||||
|
// glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
// window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr);
|
||||||
|
// if (window_ == nullptr)
|
||||||
|
// {
|
||||||
|
// std::cout << "[!] Init render engine: Fail create window\n";
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// render_engine_ = new RenderEngine(*this, window_);
|
||||||
|
// } catch (const std::exception& e)
|
||||||
|
// {
|
||||||
|
// std::cout << "[!] Init render engine: " << e.what() << '\n';
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
try
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
|
||||||
window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr);
|
|
||||||
if (window_ == nullptr)
|
|
||||||
{
|
{
|
||||||
std::cout << "[!] Init render engine: Fail create window\n";
|
render_engine_ = RenderEngineFactory(*this);
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
render_engine_ = new RenderEngine(*this, window_);
|
|
||||||
} catch (const std::exception& e)
|
} catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
std::cout << "[!] Init render engine: " << e.what() << '\n';
|
std::cerr << "[!] Init render engine: " << e.what() << '\n';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +95,6 @@ CoreInstance::~CoreInstance()
|
|||||||
|
|
||||||
delete game_;
|
delete game_;
|
||||||
delete render_engine_;
|
delete render_engine_;
|
||||||
|
|
||||||
glfwDestroyWindow(window_);
|
|
||||||
glfwTerminate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreInstance::start()
|
void CoreInstance::start()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "Game/SaveMap/ISave.h"
|
#include "Game/SaveMap/ISave.h"
|
||||||
|
|
||||||
class SaveMap;
|
class SaveMap;
|
||||||
class RenderEngine;
|
class RenderEngineBase;
|
||||||
class GameInstance;
|
class GameInstance;
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ class CoreInstance {
|
|||||||
std::list<Module> modules_;
|
std::list<Module> modules_;
|
||||||
|
|
||||||
GLFWwindow* window_ = nullptr;
|
GLFWwindow* window_ = nullptr;
|
||||||
RenderEngine* render_engine_;
|
RenderEngineBase* render_engine_;
|
||||||
GameInstance* game_;
|
GameInstance* game_;
|
||||||
|
|
||||||
bool is_ready = false;
|
bool is_ready = false;
|
||||||
@@ -60,5 +60,5 @@ public:
|
|||||||
const std::string& getBaseWorldName() const { return main_config_.base_world; }
|
const std::string& getBaseWorldName() const { return main_config_.base_world; }
|
||||||
const std::string& getGameName() const { return main_config_.game_name; }
|
const std::string& getGameName() const { return main_config_.game_name; }
|
||||||
GameInstance* GetGameInstance() const { return game_; }
|
GameInstance* GetGameInstance() const { return game_; }
|
||||||
RenderEngine* GetRenderEngine() const { return render_engine_; }
|
RenderEngineBase* GetRenderEngine() const { return render_engine_; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#include "StaticMesh.hpp"
|
#include "StaticMesh.hpp"
|
||||||
|
|
||||||
#include "Core/CoreInstance.hpp"
|
#include "Core/CoreInstance.hpp"
|
||||||
#include "Core/RenderEngine/RenderEngine.hpp"
|
|
||||||
#include "Game/GameInstance.hpp"
|
#include "Game/GameInstance.hpp"
|
||||||
#include "Log/Log.hpp"
|
|
||||||
#include "Game/SaveMap/SaveMap.hpp"
|
#include "Game/SaveMap/SaveMap.hpp"
|
||||||
#include "Game/World/World.hpp"
|
#include "Game/World/World.hpp"
|
||||||
|
|
||||||
@@ -26,11 +24,11 @@ void StaticMesh::load_model(const std::string& model_name)
|
|||||||
{
|
{
|
||||||
model_name_ = model_name;
|
model_name_ = model_name;
|
||||||
SetModelName(model_name);
|
SetModelName(model_name);
|
||||||
model_ = GetWorld()->GetGameInstance().GetCore().GetRenderEngine()->GetActiveModelManager()->LoadModel(model_name);
|
model_ = GetWorld()->GetGameInstance().GetCurrentModelManager()->LoadModel(model_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticMesh::OnDestroy()
|
void StaticMesh::OnDestroy()
|
||||||
{
|
{
|
||||||
Mesh::OnDestroy();
|
Mesh::OnDestroy();
|
||||||
GetWorld()->GetGameInstance().GetCore().GetRenderEngine()->GetActiveModelManager()->FreeModel(model_name_);
|
GetWorld()->GetGameInstance().GetCurrentModelManager()->FreeModel(model_name_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Mesh.hpp"
|
#include "Mesh.hpp"
|
||||||
#include "Core/RenderEngine/ModelManager.hpp"
|
#include "Game/ModelManager.hpp"
|
||||||
|
|
||||||
GENERATE_META(StaticMesh)
|
GENERATE_META(StaticMesh)
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "ModelManager.hpp"
|
||||||
#include "Core/CoreInstance.hpp"
|
#include "Core/CoreInstance.hpp"
|
||||||
#include "Game/WorldFactory.hpp"
|
#include "Game/WorldFactory.hpp"
|
||||||
#include "SaveMap/SaveMap.hpp"
|
|
||||||
#include "Game/World/World.hpp"
|
#include "Game/World/World.hpp"
|
||||||
|
|
||||||
extern std::vector<WorldFactory> world_factories;
|
extern std::vector<WorldFactory> world_factories;
|
||||||
@@ -19,6 +19,8 @@ GameInstance::GameInstance(CoreInstance& core) : core(core)
|
|||||||
// Init directories
|
// Init directories
|
||||||
std::filesystem::create_directories(std::filesystem::path("./Resources"));
|
std::filesystem::create_directories(std::filesystem::path("./Resources"));
|
||||||
|
|
||||||
|
current_model_manager_ = new ModelManager();
|
||||||
|
|
||||||
for (auto& factories : world_factories)
|
for (auto& factories : world_factories)
|
||||||
{
|
{
|
||||||
if (factories.world_name == base_world)
|
if (factories.world_name == base_world)
|
||||||
@@ -36,6 +38,7 @@ GameInstance::GameInstance(CoreInstance& core) : core(core)
|
|||||||
GameInstance::~GameInstance()
|
GameInstance::~GameInstance()
|
||||||
{
|
{
|
||||||
delete world;
|
delete world;
|
||||||
|
delete current_model_manager_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameInstance::start()
|
void GameInstance::start()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
class CoreInstance;
|
class CoreInstance;
|
||||||
class World;
|
class World;
|
||||||
|
class ModelManager;
|
||||||
|
|
||||||
#define GENERATE_FACTORY_GAME_INSTANCE(Class) \
|
#define GENERATE_FACTORY_GAME_INSTANCE(Class) \
|
||||||
GameInstance* GameFactory(CoreInstance& core) { return new Class(core); }
|
GameInstance* GameFactory(CoreInstance& core) { return new Class(core); }
|
||||||
@@ -13,11 +14,12 @@ class GameInstance
|
|||||||
{
|
{
|
||||||
CoreInstance& core;
|
CoreInstance& core;
|
||||||
World* world = nullptr;
|
World* world = nullptr;
|
||||||
|
ModelManager* current_model_manager_ = nullptr;
|
||||||
|
|
||||||
std::atomic<bool> is_running = true;
|
std::atomic<bool> is_running = true;
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
// Stop call from core
|
// Stop call from the core
|
||||||
void stop();
|
void stop();
|
||||||
public:
|
public:
|
||||||
// Stop call from game
|
// Stop call from game
|
||||||
@@ -29,6 +31,7 @@ public:
|
|||||||
|
|
||||||
World* GetWorld() const { return world; }
|
World* GetWorld() const { return world; }
|
||||||
CoreInstance& GetCore() const { return core; }
|
CoreInstance& GetCore() const { return core; }
|
||||||
|
ModelManager* GetCurrentModelManager() const { return current_model_manager_; }
|
||||||
|
|
||||||
friend class CoreInstance;
|
friend class CoreInstance;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.hpp" "*.h")
|
||||||
|
|
||||||
|
add_library(RenderEngineSDK ${SRC})
|
||||||
|
|
||||||
|
target_include_directories(RenderEngineSDK PUBLIC
|
||||||
|
${PROJECT_SOURCE_DIR}/glfw/Include
|
||||||
|
${PROJECT_SOURCE_DIR}/Delegate
|
||||||
|
${PROJECT_SOURCE_DIR}/Core
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(RenderEngineSDK PUBLIC
|
||||||
|
FastRTTI
|
||||||
|
glfw
|
||||||
|
Vulkan::Vulkan
|
||||||
|
)
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#include "RenderEngineBase.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
RenderEngineBase::RenderEngineBase()
|
||||||
|
{
|
||||||
|
if (!glfwInit())
|
||||||
|
throw std::runtime_error("Fail init glfw");
|
||||||
|
|
||||||
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
|
||||||
|
window_ = glfwCreateWindow(800, 600, "UwU Engine", nullptr, nullptr);
|
||||||
|
if (window_ == nullptr)
|
||||||
|
throw std::runtime_error("Fail create window");
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderEngineBase::~RenderEngineBase()
|
||||||
|
{
|
||||||
|
if (window_ != nullptr)
|
||||||
|
glfwDestroyWindow(window_);
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
class CoreInstance;
|
||||||
|
|
||||||
|
class RenderEngineBase
|
||||||
|
{
|
||||||
|
GLFWwindow* window_ = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RenderEngineBase();
|
||||||
|
virtual ~RenderEngineBase();
|
||||||
|
|
||||||
|
virtual void start() = 0;
|
||||||
|
virtual void stop_render() const = 0;
|
||||||
|
|
||||||
|
GLFWwindow* get_window() const { return window_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RENDER_ENGINE_FACTORY_GENERATE(Class) \
|
||||||
|
RenderEngineBase* RenderEngineFactory(CoreInstance& core) {\
|
||||||
|
return new Class(core); \
|
||||||
|
}
|
||||||
@@ -5,11 +5,9 @@ set(CMAKE_CXX_STANDARD 20)
|
|||||||
file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.h" "*.hpp" "*.res" "*.world" "*.conf" "*.frag" "*.vert")
|
file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.h" "*.hpp" "*.res" "*.world" "*.conf" "*.frag" "*.vert")
|
||||||
|
|
||||||
add_executable(${GAME_NAME} ${SRC})
|
add_executable(${GAME_NAME} ${SRC})
|
||||||
target_link_libraries(${GAME_NAME} PRIVATE Core)
|
target_link_libraries(${GAME_NAME} PRIVATE Core UwURenderEngine)
|
||||||
target_include_directories(${GAME_NAME} PRIVATE
|
target_include_directories(${GAME_NAME} PRIVATE
|
||||||
${PROJECT_SOURCE_DIR}/Core
|
${PROJECT_SOURCE_DIR}/Core
|
||||||
${PROJECT_SOURCE_DIR}/FastRTTI
|
|
||||||
${PROJECT_SOURCE_DIR}/Delegate
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.hpp" "*.h")
|
||||||
|
|
||||||
|
add_library(UwURenderEngine ${SRC})
|
||||||
|
target_include_directories(UwURenderEngine PRIVATE ${PROJECT_SOURCE_DIR}/RenderEngineSDK)
|
||||||
|
target_link_libraries(UwURenderEngine PRIVATE RenderEngineSDK)
|
||||||
|
|
||||||
|
target_compile_features(UwURenderEngine PRIVATE cxx_std_17)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "RenderEngine.hpp"
|
#include "UwURenderEngine.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -15,7 +16,7 @@
|
|||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
const std::vector<const char*> RenderEngine::deviceExtensions = {
|
const std::vector<const char*> UwURenderEngine::deviceExtensions = {
|
||||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,14 +34,14 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
|||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult RenderEngine::enable_layer_validation(const VkDebugUtilsMessengerCreateInfoEXT* create_info)
|
VkResult UwURenderEngine::enable_layer_validation(const VkDebugUtilsMessengerCreateInfoEXT* create_info)
|
||||||
{
|
{
|
||||||
PFN_vkCreateDebugUtilsMessengerEXT debug_creator = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkCreateDebugUtilsMessengerEXT"));
|
PFN_vkCreateDebugUtilsMessengerEXT debug_creator = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkCreateDebugUtilsMessengerEXT"));
|
||||||
return debug_creator(instance_, create_info, nullptr, &debug_messenger_);
|
return debug_creator(instance_, create_info, nullptr, &debug_messenger_);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RenderEngine::SwapchainSupportDetails RenderEngine::query_swapchain_details() const
|
UwURenderEngine::SwapchainSupportDetails UwURenderEngine::query_swapchain_details() const
|
||||||
{
|
{
|
||||||
SwapchainSupportDetails details;
|
SwapchainSupportDetails details;
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ RenderEngine::SwapchainSupportDetails RenderEngine::query_swapchain_details() co
|
|||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const char*> RenderEngine::get_required_extensions()
|
std::vector<const char*> UwURenderEngine::get_required_extensions()
|
||||||
{
|
{
|
||||||
uint32_t extensions_count = 0;
|
uint32_t extensions_count = 0;
|
||||||
const char** glfw_extension = glfwGetRequiredInstanceExtensions(&extensions_count);
|
const char** glfw_extension = glfwGetRequiredInstanceExtensions(&extensions_count);
|
||||||
@@ -71,7 +72,7 @@ std::vector<const char*> RenderEngine::get_required_extensions()
|
|||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkVertexInputBindingDescription RenderEngine::Vertex::get_binding_description()
|
VkVertexInputBindingDescription UwURenderEngine::Vertex::get_binding_description()
|
||||||
{
|
{
|
||||||
VkVertexInputBindingDescription description;
|
VkVertexInputBindingDescription description;
|
||||||
description.binding = 0;
|
description.binding = 0;
|
||||||
@@ -80,7 +81,7 @@ VkVertexInputBindingDescription RenderEngine::Vertex::get_binding_description()
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<VkVertexInputAttributeDescription, 2> RenderEngine::Vertex::get_vertex_attribute_descriptions()
|
std::array<VkVertexInputAttributeDescription, 2> UwURenderEngine::Vertex::get_vertex_attribute_descriptions()
|
||||||
{
|
{
|
||||||
std::array<VkVertexInputAttributeDescription, 2> descriptions;
|
std::array<VkVertexInputAttributeDescription, 2> descriptions;
|
||||||
// Bind vertex loc
|
// Bind vertex loc
|
||||||
@@ -98,7 +99,7 @@ std::array<VkVertexInputAttributeDescription, 2> RenderEngine::Vertex::get_verte
|
|||||||
return descriptions;
|
return descriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderEngine::is_device_suitable(VkPhysicalDevice device, VkSurfaceKHR surface)
|
bool UwURenderEngine::is_device_suitable(VkPhysicalDevice device, VkSurfaceKHR surface)
|
||||||
{
|
{
|
||||||
VkPhysicalDeviceProperties device_properties;
|
VkPhysicalDeviceProperties device_properties;
|
||||||
VkPhysicalDeviceFeatures device_features;
|
VkPhysicalDeviceFeatures device_features;
|
||||||
@@ -115,7 +116,7 @@ bool RenderEngine::is_device_suitable(VkPhysicalDevice device, VkSurfaceKHR surf
|
|||||||
return check_device_extensions_support(device);
|
return check_device_extensions_support(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderEngine::check_device_extensions_support(VkPhysicalDevice device)
|
bool UwURenderEngine::check_device_extensions_support(VkPhysicalDevice device)
|
||||||
{
|
{
|
||||||
uint32_t extension_count;
|
uint32_t extension_count;
|
||||||
VK_CHECK(vkEnumerateDeviceExtensionProperties(device, nullptr, &extension_count, nullptr));
|
VK_CHECK(vkEnumerateDeviceExtensionProperties(device, nullptr, &extension_count, nullptr));
|
||||||
@@ -139,7 +140,7 @@ bool RenderEngine::check_device_extensions_support(VkPhysicalDevice device)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysicalDevice physical_device, VkSurfaceKHR surface)
|
UwURenderEngine::QueueFamilyIndices UwURenderEngine::find_queue_family_indices(VkPhysicalDevice physical_device, VkSurfaceKHR surface)
|
||||||
{
|
{
|
||||||
QueueFamilyIndices queue_family_indices;
|
QueueFamilyIndices queue_family_indices;
|
||||||
|
|
||||||
@@ -200,7 +201,7 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
|
|||||||
return queue_family_indices;
|
return queue_family_indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSurfaceFormatKHR RenderEngine::choose_surface_format(const std::vector<VkSurfaceFormatKHR>& surface_formats)
|
VkSurfaceFormatKHR UwURenderEngine::choose_surface_format(const std::vector<VkSurfaceFormatKHR>& surface_formats)
|
||||||
{
|
{
|
||||||
for (const auto& i : surface_formats)
|
for (const auto& i : surface_formats)
|
||||||
{
|
{
|
||||||
@@ -210,7 +211,7 @@ VkSurfaceFormatKHR RenderEngine::choose_surface_format(const std::vector<VkSurfa
|
|||||||
return surface_formats[0];
|
return surface_formats[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPresentModeKHR RenderEngine::choose_present_mode(const std::vector<VkPresentModeKHR>& present_modes, VkPresentModeKHR desired_present_mode)
|
VkPresentModeKHR UwURenderEngine::choose_present_mode(const std::vector<VkPresentModeKHR>& present_modes, VkPresentModeKHR desired_present_mode)
|
||||||
{
|
{
|
||||||
for (const auto& i : present_modes)
|
for (const auto& i : present_modes)
|
||||||
{
|
{
|
||||||
@@ -220,7 +221,7 @@ VkPresentModeKHR RenderEngine::choose_present_mode(const std::vector<VkPresentMo
|
|||||||
return VK_PRESENT_MODE_FIFO_KHR;
|
return VK_PRESENT_MODE_FIFO_KHR;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkExtent2D RenderEngine::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window)
|
VkExtent2D UwURenderEngine::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// Здесь вычисляется допустимое разрешение рендера
|
// Здесь вычисляется допустимое разрешение рендера
|
||||||
if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
|
if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
|
||||||
@@ -238,7 +239,7 @@ VkExtent2D RenderEngine::choose_extent(const VkSurfaceCapabilitiesKHR& capabilit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkShaderModule RenderEngine::create_shader_module(const std::string& code) const
|
VkShaderModule UwURenderEngine::create_shader_module(const std::string& code) const
|
||||||
{
|
{
|
||||||
VkShaderModuleCreateInfo shader_module_info{};
|
VkShaderModuleCreateInfo shader_module_info{};
|
||||||
shader_module_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
shader_module_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||||
@@ -250,7 +251,7 @@ VkShaderModule RenderEngine::create_shader_module(const std::string& code) const
|
|||||||
return shader_module;
|
return shader_module;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_buffer(VkDeviceSize size, VkBufferUsageFlags usage,
|
void UwURenderEngine::create_buffer(VkDeviceSize size, VkBufferUsageFlags usage,
|
||||||
VkBuffer* buffer, const std::vector<uint32_t>& queue_families)
|
VkBuffer* buffer, const std::vector<uint32_t>& queue_families)
|
||||||
{
|
{
|
||||||
VkBufferCreateInfo buffer_info{};
|
VkBufferCreateInfo buffer_info{};
|
||||||
@@ -274,7 +275,7 @@ void RenderEngine::create_buffer(VkDeviceSize size, VkBufferUsageFlags usage,
|
|||||||
VK_CHECK(vkCreateBuffer(device_, &buffer_info, nullptr, buffer));
|
VK_CHECK(vkCreateBuffer(device_, &buffer_info, nullptr, buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::allocate_memory(VkBuffer buffer, VkMemoryPropertyFlags property, VkDeviceMemory* device_memory)
|
void UwURenderEngine::allocate_memory(VkBuffer buffer, VkMemoryPropertyFlags property, VkDeviceMemory* device_memory)
|
||||||
{
|
{
|
||||||
VkMemoryRequirements requirements{};
|
VkMemoryRequirements requirements{};
|
||||||
vkGetBufferMemoryRequirements(device_, buffer, &requirements);
|
vkGetBufferMemoryRequirements(device_, buffer, &requirements);
|
||||||
@@ -287,7 +288,7 @@ void RenderEngine::allocate_memory(VkBuffer buffer, VkMemoryPropertyFlags proper
|
|||||||
VK_CHECK(vkAllocateMemory(device_, &allocate_info, nullptr, device_memory));
|
VK_CHECK(vkAllocateMemory(device_, &allocate_info, nullptr, device_memory));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_instance()
|
void UwURenderEngine::create_instance()
|
||||||
{
|
{
|
||||||
std::vector<const char*> extensions = get_required_extensions();
|
std::vector<const char*> extensions = get_required_extensions();
|
||||||
|
|
||||||
@@ -324,7 +325,7 @@ void RenderEngine::create_instance()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::pick_physical_device()
|
void UwURenderEngine::pick_physical_device()
|
||||||
{
|
{
|
||||||
uint32_t device_count = 0;
|
uint32_t device_count = 0;
|
||||||
std::vector<VkPhysicalDevice> devices;
|
std::vector<VkPhysicalDevice> devices;
|
||||||
@@ -348,7 +349,7 @@ void RenderEngine::pick_physical_device()
|
|||||||
throw std::runtime_error("No suitable device found");
|
throw std::runtime_error("No suitable device found");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_logical_device()
|
void UwURenderEngine::create_logical_device()
|
||||||
{
|
{
|
||||||
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
||||||
|
|
||||||
@@ -395,12 +396,12 @@ void RenderEngine::create_logical_device()
|
|||||||
vkGetDeviceQueue(device_, indices.transfer_family.value(), 0, &transfer_queue_);
|
vkGetDeviceQueue(device_, indices.transfer_family.value(), 0, &transfer_queue_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_swapchain(VkPresentModeKHR desired_present_mode)
|
void UwURenderEngine::create_swapchain()
|
||||||
{
|
{
|
||||||
SwapchainSupportDetails swapchain_support = query_swapchain_details();
|
SwapchainSupportDetails swapchain_support = query_swapchain_details();
|
||||||
VkSurfaceFormatKHR surface_format = choose_surface_format(swapchain_support.formats);
|
VkSurfaceFormatKHR surface_format = choose_surface_format(swapchain_support.formats);
|
||||||
VkPresentModeKHR present_mode = choose_present_mode(swapchain_support.present_modes, desired_present_mode);
|
VkPresentModeKHR present_mode = choose_present_mode(swapchain_support.present_modes, VK_PRESENT_MODE_MAILBOX_KHR);
|
||||||
VkExtent2D extent = choose_extent(swapchain_support.capabilities, window_);
|
VkExtent2D extent = choose_extent(swapchain_support.capabilities, get_window());
|
||||||
|
|
||||||
uint32_t image_count = swapchain_support.capabilities.minImageCount + 1;
|
uint32_t image_count = swapchain_support.capabilities.minImageCount + 1;
|
||||||
if (swapchain_support.capabilities.maxImageCount > 0 && image_count > swapchain_support.capabilities.maxImageCount)
|
if (swapchain_support.capabilities.maxImageCount > 0 && image_count > swapchain_support.capabilities.maxImageCount)
|
||||||
@@ -454,7 +455,7 @@ void RenderEngine::create_swapchain(VkPresentModeKHR desired_present_mode)
|
|||||||
swapchain_extent_ = extent;
|
swapchain_extent_ = extent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_image_views()
|
void UwURenderEngine::create_image_views()
|
||||||
{
|
{
|
||||||
VkImageViewCreateInfo image_view_info{};
|
VkImageViewCreateInfo image_view_info{};
|
||||||
image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
@@ -478,7 +479,7 @@ void RenderEngine::create_image_views()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_render_pass()
|
void UwURenderEngine::create_render_pass()
|
||||||
{
|
{
|
||||||
VkAttachmentDescription attachment_description{};
|
VkAttachmentDescription attachment_description{};
|
||||||
attachment_description.format = swapchain_image_format_;
|
attachment_description.format = swapchain_image_format_;
|
||||||
@@ -519,7 +520,7 @@ void RenderEngine::create_render_pass()
|
|||||||
VK_CHECK(vkCreateRenderPass(device_, &render_pass_info, nullptr, &render_pass_));
|
VK_CHECK(vkCreateRenderPass(device_, &render_pass_info, nullptr, &render_pass_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_description_set_layout()
|
void UwURenderEngine::create_description_set_layout()
|
||||||
{
|
{
|
||||||
VkDescriptorSetLayoutBinding ubo_layout_binding{};
|
VkDescriptorSetLayoutBinding ubo_layout_binding{};
|
||||||
ubo_layout_binding.binding = 0;
|
ubo_layout_binding.binding = 0;
|
||||||
@@ -536,7 +537,7 @@ void RenderEngine::create_description_set_layout()
|
|||||||
VK_CHECK(vkCreateDescriptorSetLayout(device_, &ubo_layout_info, nullptr, &ubo_layout_binding_));
|
VK_CHECK(vkCreateDescriptorSetLayout(device_, &ubo_layout_info, nullptr, &ubo_layout_binding_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_uniform_buffers()
|
void UwURenderEngine::create_uniform_buffers()
|
||||||
{
|
{
|
||||||
uniform_buffers_.resize(swapchain_images_.size());
|
uniform_buffers_.resize(swapchain_images_.size());
|
||||||
uniform_buffers_memory_.resize(swapchain_images_.size());
|
uniform_buffers_memory_.resize(swapchain_images_.size());
|
||||||
@@ -554,7 +555,7 @@ void RenderEngine::create_uniform_buffers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_descriptor_pool()
|
void UwURenderEngine::create_descriptor_pool()
|
||||||
{
|
{
|
||||||
VkDescriptorPoolSize pool_size{};
|
VkDescriptorPoolSize pool_size{};
|
||||||
pool_size.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
pool_size.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
@@ -569,7 +570,7 @@ void RenderEngine::create_descriptor_pool()
|
|||||||
VK_CHECK(vkCreateDescriptorPool(device_, &descriptor_pool_info, nullptr, &descriptor_pool_));
|
VK_CHECK(vkCreateDescriptorPool(device_, &descriptor_pool_info, nullptr, &descriptor_pool_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_descriptor_sets()
|
void UwURenderEngine::create_descriptor_sets()
|
||||||
{
|
{
|
||||||
std::vector<VkDescriptorSetLayout> layouts(swapchain_images_.size(), ubo_layout_binding_);
|
std::vector<VkDescriptorSetLayout> layouts(swapchain_images_.size(), ubo_layout_binding_);
|
||||||
VkDescriptorSetAllocateInfo descriptor_set_allocate_info{};
|
VkDescriptorSetAllocateInfo descriptor_set_allocate_info{};
|
||||||
@@ -603,7 +604,7 @@ void RenderEngine::create_descriptor_sets()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_graphics_pipeline()
|
void UwURenderEngine::create_graphics_pipeline()
|
||||||
{
|
{
|
||||||
std::ifstream vertex_shader_file("Shaders/vertex.spv", std::ios::binary);
|
std::ifstream vertex_shader_file("Shaders/vertex.spv", std::ios::binary);
|
||||||
if (!vertex_shader_file.is_open())
|
if (!vertex_shader_file.is_open())
|
||||||
@@ -745,7 +746,7 @@ void RenderEngine::create_graphics_pipeline()
|
|||||||
vkDestroyShaderModule(device_, fragment_shader, nullptr);
|
vkDestroyShaderModule(device_, fragment_shader, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_framebuffers()
|
void UwURenderEngine::create_framebuffers()
|
||||||
{
|
{
|
||||||
framebuffers_.resize(swapchain_images_.size());
|
framebuffers_.resize(swapchain_images_.size());
|
||||||
|
|
||||||
@@ -764,7 +765,7 @@ void RenderEngine::create_framebuffers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_command_pool()
|
void UwURenderEngine::create_command_pool()
|
||||||
{
|
{
|
||||||
QueueFamilyIndices queue_family_indices = find_queue_family_indices(physical_device_, surface_);
|
QueueFamilyIndices queue_family_indices = find_queue_family_indices(physical_device_, surface_);
|
||||||
|
|
||||||
@@ -776,7 +777,7 @@ void RenderEngine::create_command_pool()
|
|||||||
VK_CHECK(vkCreateCommandPool(device_, &command_pool_info, nullptr, &command_pool_));
|
VK_CHECK(vkCreateCommandPool(device_, &command_pool_info, nullptr, &command_pool_));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RenderEngine::find_memory_type(uint32_t typeFilter, VkMemoryPropertyFlags properties) const
|
uint32_t UwURenderEngine::find_memory_type(uint32_t typeFilter, VkMemoryPropertyFlags properties) const
|
||||||
{
|
{
|
||||||
VkPhysicalDeviceMemoryProperties memory_properties{};
|
VkPhysicalDeviceMemoryProperties memory_properties{};
|
||||||
vkGetPhysicalDeviceMemoryProperties(physical_device_, &memory_properties);
|
vkGetPhysicalDeviceMemoryProperties(physical_device_, &memory_properties);
|
||||||
@@ -790,7 +791,7 @@ uint32_t RenderEngine::find_memory_type(uint32_t typeFilter, VkMemoryPropertyFla
|
|||||||
throw std::runtime_error("failed to find suitable memory type!");
|
throw std::runtime_error("failed to find suitable memory type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint32_t> RenderEngine::get_unique_family_indices(const QueueFamilyIndices& indices)
|
std::vector<uint32_t> UwURenderEngine::get_unique_family_indices(const QueueFamilyIndices& indices)
|
||||||
{
|
{
|
||||||
std::set<uint32_t> set_indices = {indices.graphics_family.value(),
|
std::set<uint32_t> set_indices = {indices.graphics_family.value(),
|
||||||
indices.present_family.value(),
|
indices.present_family.value(),
|
||||||
@@ -803,7 +804,7 @@ std::vector<uint32_t> RenderEngine::get_unique_family_indices(const QueueFamilyI
|
|||||||
return arr_indices;
|
return arr_indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::allocate_vertex_buffer()
|
void UwURenderEngine::allocate_vertex_buffer()
|
||||||
{
|
{
|
||||||
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
||||||
|
|
||||||
@@ -835,7 +836,7 @@ void RenderEngine::allocate_vertex_buffer()
|
|||||||
vkDestroyBuffer(device_, staging_buffer, nullptr);
|
vkDestroyBuffer(device_, staging_buffer, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::allocate_index_buffer()
|
void UwURenderEngine::allocate_index_buffer()
|
||||||
{
|
{
|
||||||
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
||||||
std::set<uint32_t> set_indices = {indices.graphics_family.value(),
|
std::set<uint32_t> set_indices = {indices.graphics_family.value(),
|
||||||
@@ -867,7 +868,7 @@ void RenderEngine::allocate_index_buffer()
|
|||||||
vkFreeMemory(device_, staging_buffer_memory, nullptr);
|
vkFreeMemory(device_, staging_buffer_memory, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::copy_memory(VkBuffer src, VkBuffer dst, VkDeviceSize size)
|
void UwURenderEngine::copy_memory(VkBuffer src, VkBuffer dst, VkDeviceSize size)
|
||||||
{
|
{
|
||||||
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
QueueFamilyIndices indices = find_queue_family_indices(physical_device_, surface_);
|
||||||
VkCommandPool copy_pool;
|
VkCommandPool copy_pool;
|
||||||
@@ -912,7 +913,7 @@ void RenderEngine::copy_memory(VkBuffer src, VkBuffer dst, VkDeviceSize size)
|
|||||||
vkDestroyCommandPool(device_, copy_pool, nullptr);
|
vkDestroyCommandPool(device_, copy_pool, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::allocate_command_buffers()
|
void UwURenderEngine::allocate_command_buffers()
|
||||||
{
|
{
|
||||||
command_buffers_.resize(swapchain_images_.size());
|
command_buffers_.resize(swapchain_images_.size());
|
||||||
|
|
||||||
@@ -925,7 +926,7 @@ void RenderEngine::allocate_command_buffers()
|
|||||||
VK_CHECK(vkAllocateCommandBuffers(device_, &command_buffer_allocate_info, command_buffers_.data()));
|
VK_CHECK(vkAllocateCommandBuffers(device_, &command_buffer_allocate_info, command_buffers_.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_sync_objects()
|
void UwURenderEngine::create_sync_objects()
|
||||||
{
|
{
|
||||||
image_available_semaphores_.resize(swapchain_images_.size());
|
image_available_semaphores_.resize(swapchain_images_.size());
|
||||||
render_finished_semaphores_.resize(swapchain_images_.size());
|
render_finished_semaphores_.resize(swapchain_images_.size());
|
||||||
@@ -946,7 +947,7 @@ void RenderEngine::create_sync_objects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::record_command_buffer(VkCommandBuffer command_buffer, uint32_t image_index) const
|
void UwURenderEngine::record_command_buffer(VkCommandBuffer command_buffer, uint32_t image_index) const
|
||||||
{
|
{
|
||||||
VkCommandBufferBeginInfo command_buffer_begin_info{};
|
VkCommandBufferBeginInfo command_buffer_begin_info{};
|
||||||
command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
@@ -993,7 +994,7 @@ void RenderEngine::record_command_buffer(VkCommandBuffer command_buffer, uint32_
|
|||||||
VK_CHECK(vkEndCommandBuffer(command_buffer));
|
VK_CHECK(vkEndCommandBuffer(command_buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::update_uniform_buffer(uint32_t current_frame)
|
void UwURenderEngine::update_uniform_buffer(uint32_t current_frame)
|
||||||
{
|
{
|
||||||
static auto start_time = std::chrono::high_resolution_clock::now();
|
static auto start_time = std::chrono::high_resolution_clock::now();
|
||||||
auto current_time = std::chrono::high_resolution_clock::now();
|
auto current_time = std::chrono::high_resolution_clock::now();
|
||||||
@@ -1006,7 +1007,7 @@ void RenderEngine::update_uniform_buffer(uint32_t current_frame)
|
|||||||
memcpy(uniform_buffers_mapped_[current_frame], &ubo, sizeof(ubo));
|
memcpy(uniform_buffers_mapped_[current_frame], &ubo, sizeof(ubo));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::draw_frame()
|
void UwURenderEngine::draw_frame()
|
||||||
{
|
{
|
||||||
vkWaitForFences(device_, 1, &in_flight_fences_[current_frame_], VK_TRUE, UINT64_MAX);
|
vkWaitForFences(device_, 1, &in_flight_fences_[current_frame_], VK_TRUE, UINT64_MAX);
|
||||||
vkResetFences(device_, 1, &in_flight_fences_[current_frame_]);
|
vkResetFences(device_, 1, &in_flight_fences_[current_frame_]);
|
||||||
@@ -1046,14 +1047,13 @@ void RenderEngine::draw_frame()
|
|||||||
current_frame_ = (current_frame_ + 1) % static_cast<int>(swapchain_images_.size());
|
current_frame_ = (current_frame_ + 1) % static_cast<int>(swapchain_images_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::create_surface()
|
void UwURenderEngine::create_surface()
|
||||||
{
|
{
|
||||||
VK_CHECK(glfwCreateWindowSurface(instance_, window_, nullptr, &surface_));
|
VK_CHECK(glfwCreateWindowSurface(instance_, get_window(), nullptr, &surface_));
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine::RenderEngine(CoreInstance& core, GLFWwindow* window, VkPresentModeKHR desired_present_mode):
|
UwURenderEngine::UwURenderEngine(CoreInstance& core):
|
||||||
core_(core),
|
core_(core)
|
||||||
window_(window)
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
,debug_messenger_(nullptr)
|
,debug_messenger_(nullptr)
|
||||||
#endif
|
#endif
|
||||||
@@ -1062,7 +1062,7 @@ window_(window)
|
|||||||
create_surface();
|
create_surface();
|
||||||
pick_physical_device();
|
pick_physical_device();
|
||||||
create_logical_device();
|
create_logical_device();
|
||||||
create_swapchain(desired_present_mode);
|
create_swapchain();
|
||||||
create_image_views();
|
create_image_views();
|
||||||
create_render_pass();
|
create_render_pass();
|
||||||
create_description_set_layout();
|
create_description_set_layout();
|
||||||
@@ -1078,7 +1078,7 @@ window_(window)
|
|||||||
create_sync_objects();
|
create_sync_objects();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine::~RenderEngine()
|
UwURenderEngine::~UwURenderEngine()
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(device_);
|
vkDeviceWaitIdle(device_);
|
||||||
|
|
||||||
@@ -1160,22 +1160,22 @@ RenderEngine::~RenderEngine()
|
|||||||
vkDestroyInstance(instance_, nullptr);
|
vkDestroyInstance(instance_, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::start()
|
void UwURenderEngine::start()
|
||||||
{
|
{
|
||||||
World* world = core_.GetGameInstance()->GetWorld();
|
World* world = core_.GetGameInstance()->GetWorld();
|
||||||
std::vector<UType::object_ptr<Mesh>> meshes = world->GetActorsByClass<Mesh>();
|
std::vector<UType::object_ptr<Mesh>> meshes = world->GetActorsByClass<Mesh>();
|
||||||
for (auto& i : meshes)
|
for (auto& i : meshes)
|
||||||
i->load_model(i->GetModelName());
|
i->load_model(i->GetModelName());
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window_))
|
while (!glfwWindowShouldClose(get_window()))
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
draw_frame();
|
draw_frame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::stop_render() const
|
void UwURenderEngine::stop_render() const
|
||||||
{
|
{
|
||||||
if (window_ != nullptr && !glfwWindowShouldClose(window_))
|
if (!glfwWindowShouldClose(get_window()))
|
||||||
glfwSetWindowShouldClose(window_, true);
|
glfwSetWindowShouldClose(get_window(), true);
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include "RenderEngineBase.hpp"
|
||||||
#include <vector>
|
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#include <optional>
|
||||||
#include <GLFW/glfw3.h>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define GLM_FORCE_RADIANS
|
#define GLM_FORCE_RADIANS
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
#include "ModelManager.hpp"
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
||||||
@@ -21,9 +17,7 @@
|
|||||||
#define VK_CHECK(res) if ((res) != VK_SUCCESS) throw std::runtime_error("Vulkan error: " + std::to_string(res))
|
#define VK_CHECK(res) if ((res) != VK_SUCCESS) throw std::runtime_error("Vulkan error: " + std::to_string(res))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class CoreInstance;
|
class UwURenderEngine : public RenderEngineBase
|
||||||
|
|
||||||
class RenderEngine
|
|
||||||
{
|
{
|
||||||
struct QueueFamilyIndices
|
struct QueueFamilyIndices
|
||||||
{
|
{
|
||||||
@@ -69,16 +63,12 @@ class RenderEngine
|
|||||||
4, 5, 1, 1, 0, 4
|
4, 5, 1, 1, 0, 4
|
||||||
};
|
};
|
||||||
|
|
||||||
ModelManager model_manager_;
|
|
||||||
|
|
||||||
static const std::vector<const char*> deviceExtensions;
|
static const std::vector<const char*> deviceExtensions;
|
||||||
|
|
||||||
int current_frame_ = 0;
|
int current_frame_ = 0;
|
||||||
|
|
||||||
CoreInstance& core_;
|
CoreInstance& core_;
|
||||||
|
|
||||||
GLFWwindow* window_;
|
|
||||||
|
|
||||||
VkInstance instance_ = VK_NULL_HANDLE;
|
VkInstance instance_ = VK_NULL_HANDLE;
|
||||||
VkSurfaceKHR surface_ = VK_NULL_HANDLE;
|
VkSurfaceKHR surface_ = VK_NULL_HANDLE;
|
||||||
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
||||||
@@ -136,7 +126,7 @@ class RenderEngine
|
|||||||
void create_surface();
|
void create_surface();
|
||||||
void pick_physical_device();
|
void pick_physical_device();
|
||||||
void create_logical_device();
|
void create_logical_device();
|
||||||
void create_swapchain(VkPresentModeKHR desired_present_mode);
|
void create_swapchain();
|
||||||
void create_image_views();
|
void create_image_views();
|
||||||
void create_render_pass();
|
void create_render_pass();
|
||||||
void create_description_set_layout();
|
void create_description_set_layout();
|
||||||
@@ -157,14 +147,12 @@ class RenderEngine
|
|||||||
void draw_frame();
|
void draw_frame();
|
||||||
public:
|
public:
|
||||||
// Can throw the exception
|
// Can throw the exception
|
||||||
RenderEngine(CoreInstance& core, GLFWwindow* window, VkPresentModeKHR desired_present_mode = VK_PRESENT_MODE_MAILBOX_KHR);
|
UwURenderEngine(CoreInstance& core);
|
||||||
~RenderEngine();
|
~UwURenderEngine() override;
|
||||||
|
|
||||||
void start();
|
void start() override;
|
||||||
void stop_render() const;
|
void stop_render() const override;
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
GLFWwindow* get_window() const { return window_; }
|
|
||||||
|
|
||||||
ModelManager* GetActiveModelManager() { return &model_manager_; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RENDER_ENGINE_FACTORY_GENERATE(UwURenderEngine)
|
||||||
Reference in New Issue
Block a user