This commit is contained in:
2024-02-01 12:42:58 +08:00
parent 2cc7cf4f32
commit bbd2b83e7a
141 changed files with 14229 additions and 43622 deletions

View File

@@ -8,6 +8,7 @@
#include "imgui_internal.h"
#include "filesystem/stb_image.h"
#include "rhi/texture.h"
#include "rhi/opengl/renderer_opengl.h"
#include "spdlog/async.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
@@ -18,6 +19,7 @@
bool g_is_running = true;
bool g_exit_requested = false;
slang::IGlobalSession* g_slang_global_session = nullptr;
application::~application()
{
@@ -26,6 +28,8 @@ application::~application()
void application::init(window_params in_window_params, int argc, char** argv)
{
slang::createGlobalSession(&g_slang_global_session);
try
{
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/log.txt");
@@ -53,20 +57,24 @@ void application::init(window_params in_window_params, int argc, char** argv)
bool use_dx11 = false;
bool use_dx12 = false;
bool use_vulkan = false;
bool use_opengl = false;
#else
bool use_vulkan = true;
bool use_opengl = false;
#endif
#if WIN32
command_line::instance().get_arg("dx11", use_dx11);
command_line::instance().get_arg("dx12", use_dx12);
command_line::instance().get_arg("vulkan", use_vulkan);
command_line::instance().get_arg("opengl", use_opengl);
// only one renderer can be used at a time
const int renderer_count = use_dx11 + use_dx12 + use_vulkan;
const int renderer_count = use_dx11 + use_dx12 + use_vulkan + use_opengl;
assert(renderer_count <= 1);
// if no renderer is specified, use dx11
if (!(use_dx11 || use_dx12 || use_vulkan))
if (!(use_dx11 || use_dx12 || use_vulkan || use_opengl))
{
use_dx11 = true;
}
@@ -75,6 +83,11 @@ void application::init(window_params in_window_params, int argc, char** argv)
{
renderer_ = new renderer_dx11();
}
else if (use_opengl)
{
renderer_ = new renderer_opengl();
window_flags |= SDL_WINDOW_OPENGL;
}
// if (use_dx12)
// {
// renderer_ = new renderer_dx12();
@@ -90,11 +103,17 @@ void application::init(window_params in_window_params, int argc, char** argv)
renderer_ = new renderer_vulkan();
window_flags |= SDL_WINDOW_VULKAN;
}
else if (use_opengl)
{
renderer_ = new renderer_opengl();
window_flags |= SDL_WINDOW_OPENGL;
}
#endif
// if (!renderer_)
// renderer_ = new renderer_null();
renderer_->pre_init();
if (in_window_params.fullscreen)
window_flags |= SDL_WINDOW_FULLSCREEN;
if (in_window_params.borderless)
@@ -121,6 +140,7 @@ void application::init(window_params in_window_params, int argc, char** argv)
SDL_ShowWindow(window_);
renderer_->init(window_);
renderer_->init_slang(R"(E:\Projects\AronaStudio\Arona\shaders\)");
renderer_->resize(in_window_params.width, in_window_params.height);
g_is_running = true;
}
@@ -147,9 +167,9 @@ int application::run()
if (g_exit_requested)
break;
renderer_->new_frame();
renderer_->new_frame(window_);
draw_gui();
renderer_->end_frame();
renderer_->end_frame(window_);
}
return 0;
}
@@ -162,7 +182,7 @@ void application::shutdown()
delete renderer_;
}
texture* application::load_texture(const std::string& path) const
std::shared_ptr<texture> application::load_texture(const std::string& path) const
{
int width = 0;
int height = 0;
@@ -177,7 +197,7 @@ texture* application::load_texture(const std::string& path) const
return texture;
}
texture* application::create_texture(const unsigned char* data, const int width, const int height) const
std::shared_ptr<texture> application::create_texture(const unsigned char* data, const int width, const int height) const
{
return renderer_->create_texture(data, width, height);
}