vulkan图片加载

This commit is contained in:
2024-02-20 08:44:56 +08:00
committed by daiqingshuang
parent fbb01724a4
commit 45bd309e8d
28 changed files with 1076 additions and 843 deletions

View File

@@ -7,7 +7,7 @@
#include "imgui_internal.h"
#include "filesystem/stb_image.h"
#include "rhi/texture.h"
#include "rhi/vulkan/renderer_vk.h"
#include "rhi/renderer.h"
#include "spdlog/async.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
@@ -31,7 +31,7 @@ void application::init(const window_params& in_window_params, int argc, char** a
init_glfw();
init_imgui();
renderer_ = new renderer_vk();
renderer_ = new renderer();
renderer_->pre_init();
@@ -44,7 +44,6 @@ void application::init(const window_params& in_window_params, int argc, char** a
}
renderer_->init(window_);
renderer_->resize(in_window_params.width, in_window_params.height);
g_is_running = true;
}
@@ -67,7 +66,6 @@ int application::run() {
void application::shutdown() {
renderer_->shutdown();
destroy_imgui();
renderer_->post_shutdown();
delete renderer_;
renderer_ = nullptr;
@@ -77,31 +75,31 @@ void application::shutdown() {
g_is_running = false;
}
std::shared_ptr<texture> application::load_texture(const std::string& path) const {
std::shared_ptr<texture> application::load_texture(const std::string& path, vk::Format format) const {
int width = 0;
int height = 0;
unsigned char* image_data = stbi_load(path.c_str(), &width, &height, nullptr, 4);
uint8_t* image_data = stbi_load(path.c_str(), &width, &height, nullptr, 4);
if (!image_data) {
spdlog::error("Failed to load texture: {}", path.c_str());
return nullptr;
}
const auto texture = renderer_->create_texture(image_data, width, height);
const auto texture = renderer::create_texture(image_data, width, height, format);
stbi_image_free(image_data);
return texture;
}
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);
application::create_texture(const unsigned char* data, const int width, const int height, vk::Format format) const {
return renderer::create_texture(data, width, height, format);
}
std::shared_ptr<render_target> application::create_render_target(const int width, const int height,
texture_format format) const {
return renderer_->create_render_target(width, height, format);
vk::Format format) const {
return renderer::create_render_target(width, height, format);
}
std::shared_ptr<pixel_shader_drawer> application::create_pixel_shader_drawer() const {
return renderer_->create_pixel_shader_drawer();
return nullptr;
}
void application::init_glfw() {