Extra2D/include/renderer/rhi_module.h

114 lines
2.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <event/events.h>
#include <module/module.h>
#include <module/module_registry.h>
#include <renderer/rhi/rhi.h>
#include <memory>
namespace extra2d {
/**
* @brief RHI 模块
*
* 负责初始化和管理 RHI 后端,提供图形 API 抽象
* 优先级1在 WindowModule 之后初始化)
*/
class RHIModule : public Module {
E2D_REGISTER_MODULE(RHIModule, "RHI", 1)
public:
RHIModule();
~RHIModule() override;
/**
* @brief 初始化 RHI 模块
* @return 初始化是否成功
*/
bool init() override;
/**
* @brief 关闭 RHI 模块
*/
void shutdown() override;
/**
* @brief 获取 RHI 设备
* @return RHI 设备指针
*/
RHIDevice* getDevice() const { return device_.get(); }
/**
* @brief 获取 RHI 上下文
* @return RHI 上下文指针
*/
RHIContext* getContext() const { return context_; }
/**
* @brief 获取全局 RHIModule 实例
* @return RHIModule 指针
*/
static RHIModule* get();
/**
* @brief 检查 RHI 是否已初始化
* @return 是否已初始化
*/
bool isInitialized() const { return initialized_; }
/**
* @brief 创建缓冲区
* @param desc 缓冲区描述
* @return 缓冲区对象
*/
std::unique_ptr<RHIBuffer> createBuffer(const BufferDesc& desc);
/**
* @brief 创建纹理
* @param desc 纹理描述
* @return 纹理对象
*/
std::unique_ptr<RHITexture> createTexture(const TextureDesc& desc);
/**
* @brief 创建着色器
* @param desc 着色器描述
* @return 着色器对象
*/
std::unique_ptr<RHIShader> createShader(const ShaderDesc& desc);
/**
* @brief 创建图形管线
* @param desc 管线描述
* @return 管线对象
*/
std::unique_ptr<RHIPipeline> createPipeline(const PipelineDesc& desc);
/**
* @brief 创建帧缓冲
* @param desc 帧缓冲描述
* @return 帧缓冲对象
*/
std::unique_ptr<RHIFramebuffer> createFramebuffer(const RenderPassDesc& desc);
/**
* @brief 创建命令列表
* @return 命令列表对象
*/
std::unique_ptr<RHICommandList> createCommandList();
private:
/**
* @brief 窗口显示事件回调 - 在窗口显示时创建 OpenGL 上下文
*/
void onWindowShow();
private:
std::unique_ptr<RHIDevice> device_;
RHIContext* context_;
bool initialized_ = false;
std::unique_ptr<events::OnShow::Listener> onShowListener_;
};
} // namespace extra2d