refactor(渲染): 移除OnRenderPresent事件及相关处理
将缓冲区交换逻辑移至RHI模块处理,移除不再需要的OnRenderPresent事件及相关监听代码。同时统一日志消息中的中英文混用问题,将部分英文日志消息改为中文。
This commit is contained in:
parent
579aa2dd0d
commit
79e939ce5e
|
|
@ -259,11 +259,4 @@ DECLARE_EVENT_1(OnRenderSetCamera, Engine, extra2d::Mat4)
|
|||
*/
|
||||
DECLARE_EVENT_0(OnRenderEnd, Engine)
|
||||
|
||||
/**
|
||||
* @brief 渲染呈现事件
|
||||
*
|
||||
* 在渲染完成并准备好呈现时触发,窗口模块应调用 swapBuffers
|
||||
*/
|
||||
DECLARE_EVENT_0(OnRenderPresent, Engine)
|
||||
|
||||
} // namespace extra2d::events
|
||||
|
|
|
|||
|
|
@ -130,13 +130,6 @@ private:
|
|||
*/
|
||||
void onModuleConfig(const AppConfig &config);
|
||||
|
||||
/**
|
||||
* @brief 监听渲染呈现事件
|
||||
*
|
||||
* 当渲染完成时调用 swapBuffers 呈现渲染结果
|
||||
*/
|
||||
void onRenderPresent();
|
||||
|
||||
SDL_Window *window_ = nullptr;
|
||||
bool shouldClose_ = false;
|
||||
|
||||
|
|
@ -145,9 +138,6 @@ private:
|
|||
|
||||
// 模块配置事件监听器
|
||||
std::unique_ptr<events::OnModuleConfig<AppConfig>::Listener> configListener_;
|
||||
|
||||
// 渲染呈现事件监听器
|
||||
std::unique_ptr<events::OnRenderPresent::Listener> renderPresentListener_;
|
||||
};
|
||||
|
||||
} // namespace extra2d
|
||||
|
|
|
|||
|
|
@ -79,9 +79,6 @@ void Context::tick(float dt) {
|
|||
|
||||
// 3. 渲染结束并执行绘制
|
||||
events::OnRenderEnd::emit();
|
||||
|
||||
// 4. 呈现渲染结果(交换缓冲区)
|
||||
events::OnRenderPresent::emit();
|
||||
}
|
||||
|
||||
ModuleRegistry &Context::modules() { return ModuleRegistry::instance(); }
|
||||
|
|
|
|||
|
|
@ -22,18 +22,12 @@ bool WindowModule::init() {
|
|||
configListener_->bind(
|
||||
[this](const AppConfig &config) { this->onModuleConfig(config); });
|
||||
|
||||
// 监听渲染呈现事件
|
||||
renderPresentListener_ =
|
||||
std::make_unique<events::OnRenderPresent::Listener>();
|
||||
renderPresentListener_->bind([this]() { this->onRenderPresent(); });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowModule::shutdown() {
|
||||
// 清理事件监听器
|
||||
configListener_.reset();
|
||||
renderPresentListener_.reset();
|
||||
|
||||
if (window_) {
|
||||
SDL_DestroyWindow(window_);
|
||||
|
|
@ -206,9 +200,4 @@ bool WindowModule::isVisible() const {
|
|||
return (flags & SDL_WINDOW_SHOWN) != 0;
|
||||
}
|
||||
|
||||
void WindowModule::onRenderPresent() {
|
||||
// 交换缓冲区由 RHI 模块处理
|
||||
// 这里可以触发呈现事件
|
||||
}
|
||||
|
||||
} // namespace extra2d
|
||||
|
|
|
|||
|
|
@ -198,33 +198,33 @@ bool CommandQueue::initialize() {
|
|||
// 获取 RHI 模块
|
||||
auto *rhiModule = RHIModule::get();
|
||||
if (!rhiModule) {
|
||||
E2D_ERROR("RHIModule not available");
|
||||
E2D_ERROR("RHI模块 不可用");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto *device = rhiModule->getDevice();
|
||||
if (!device) {
|
||||
E2D_ERROR("RHIDevice not available");
|
||||
E2D_ERROR("RHI 设备不可用");
|
||||
return false;
|
||||
}
|
||||
|
||||
context_ = rhiModule->getContext();
|
||||
if (!context_) {
|
||||
E2D_ERROR("RHIContext not available");
|
||||
E2D_ERROR("RHI 上下文不可用");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建命令列表
|
||||
commandList_ = device->createCommandList();
|
||||
if (!commandList_) {
|
||||
E2D_ERROR("Failed to create command list");
|
||||
E2D_ERROR("创建命令列表失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 初始化 UBO 管理器
|
||||
uboManager_ = std::make_unique<UniformBufferManager>();
|
||||
if (!uboManager_->initialize()) {
|
||||
E2D_ERROR("Failed to initialize UniformBufferManager");
|
||||
E2D_ERROR("统一缓冲区管理器初始化失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ bool TextureAtlas::initialize(int width, int height) {
|
|||
shutdown();
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
E2D_ERROR("TextureAtlas::initialize: 无效的尺寸 {}x{}", width, height);
|
||||
E2D_ERROR("纹理图集::初始化: 无效的尺寸 {}x{}", width, height);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -79,17 +79,17 @@ void TextureAtlas::shutdown() {
|
|||
|
||||
bool TextureAtlas::addTexture(const std::string &name, Ptr<Texture> texture) {
|
||||
if (finalized_) {
|
||||
E2D_WARN("TextureAtlas::addTexture: 无法向已完成的图集添加纹理");
|
||||
E2D_WARN("纹理图集::添加纹理: 无法向已完成的图集添加纹理");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!texture) {
|
||||
E2D_WARN("TextureAtlas::addTexture: 纹理为空");
|
||||
E2D_WARN("纹理图集::添加纹理: 纹理为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (regions_.find(name) != regions_.end()) {
|
||||
E2D_WARN("TextureAtlas::addTexture: 纹理 '{}' 已存在", name);
|
||||
E2D_WARN("纹理图集::添加纹理: 纹理 '{}' 已存在", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -98,14 +98,13 @@ bool TextureAtlas::addTexture(const std::string &name, Ptr<Texture> texture) {
|
|||
int texHeight = static_cast<int>(texture->getHeight());
|
||||
|
||||
if (texWidth <= 0 || texHeight <= 0) {
|
||||
E2D_WARN("TextureAtlas::addTexture: 无效的纹理尺寸 {}x{}", texWidth,
|
||||
texHeight);
|
||||
E2D_WARN("纹理图集::添加纹理: 无效的纹理尺寸 {}x{}", texWidth, texHeight);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查纹理是否适合图集
|
||||
if (texWidth > width_ || texHeight > height_) {
|
||||
E2D_WARN("TextureAtlas::addTexture: 纹理 {}x{} 太大,无法放入图集 {}x{}",
|
||||
E2D_WARN("纹理图集::添加纹理: 纹理 {}x{} 太大,无法放入图集 {}x{}",
|
||||
texWidth, texHeight, width_, height_);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -134,24 +133,23 @@ bool TextureAtlas::addTexture(const std::string &name, Ptr<Texture> texture) {
|
|||
bool TextureAtlas::addTextureData(const std::string &name, const uint8_t *data,
|
||||
int width, int height, TextureFormat format) {
|
||||
if (finalized_) {
|
||||
E2D_WARN("TextureAtlas::addTextureData: 无法向已完成的图集添加纹理");
|
||||
E2D_WARN("纹理图集::添加纹理数据: 无法向已完成的图集添加纹理");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data || width <= 0 || height <= 0) {
|
||||
E2D_WARN("TextureAtlas::addTextureData: 无效参数");
|
||||
E2D_WARN("纹理图集::添加纹理数据: 无效参数");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (regions_.find(name) != regions_.end()) {
|
||||
E2D_WARN("TextureAtlas::addTextureData: 纹理 '{}' 已存在", name);
|
||||
E2D_WARN("纹理图集::添加纹理数据: 纹理 '{}' 已存在", name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (width > width_ || height > height_) {
|
||||
E2D_WARN(
|
||||
"TextureAtlas::addTextureData: 纹理 {}x{} 太大,无法放入图集 {}x{}",
|
||||
width, height, width_, height_);
|
||||
E2D_WARN("纹理图集::添加纹理数据: 纹理 {}x{} 太大,无法放入图集 {}x{}",
|
||||
width, height, width_, height_);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +177,7 @@ bool TextureAtlas::finalize() {
|
|||
}
|
||||
|
||||
if (pendingTextures_.empty()) {
|
||||
E2D_WARN("TextureAtlas::finalize: 没有要打包的纹理");
|
||||
E2D_WARN("纹理图集::清理: 没有要打包的纹理");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +201,7 @@ bool TextureAtlas::finalize() {
|
|||
static_cast<int>(rects.size()));
|
||||
|
||||
if (!result) {
|
||||
E2D_ERROR("TextureAtlas::finalize: 打包所有纹理失败");
|
||||
E2D_ERROR("纹理图集::清理: 打包所有纹理失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -213,7 +211,7 @@ bool TextureAtlas::finalize() {
|
|||
// 处理打包结果
|
||||
for (const auto &rect : rects) {
|
||||
if (!rect.was_packed) {
|
||||
E2D_WARN("TextureAtlas::finalize: 纹理 {} 未被打包", rect.id);
|
||||
E2D_WARN("纹理图集::清理: 纹理 {} 未被打包", rect.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -254,7 +252,7 @@ bool TextureAtlas::finalize() {
|
|||
atlasTexture_ = makePtr<Texture>();
|
||||
if (!atlasTexture_->loadFromMemory(atlasData.data(), width_, height_,
|
||||
TextureFormat::RGBA8)) {
|
||||
E2D_ERROR("TextureAtlas::finalize: 创建图集纹理失败");
|
||||
E2D_ERROR("纹理图集::清理: 创建图集纹理失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -308,7 +306,7 @@ float TextureAtlas::getUsageRatio() const {
|
|||
|
||||
Ptr<TextureAtlas> AtlasBuilder::build() {
|
||||
if (textures_.empty()) {
|
||||
E2D_WARN("AtlasBuilder::build: No textures to build");
|
||||
E2D_WARN("图集生成器::构建: 没有需要构建的纹理");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +328,7 @@ Ptr<TextureAtlas> AtlasBuilder::build() {
|
|||
|
||||
Ptr<TextureAtlas> AtlasBuilder::buildAuto() {
|
||||
if (textures_.empty()) {
|
||||
E2D_WARN("AtlasBuilder::buildAuto: No textures to build");
|
||||
E2D_WARN("图集生成器::自动构建: 没有需要构建的纹理");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -355,7 +353,7 @@ Ptr<TextureAtlas> AtlasBuilder::buildAuto() {
|
|||
atlasSize * atlasSize < totalArea * 1.5f) {
|
||||
atlasSize *= 2;
|
||||
if (atlasSize > 8192) {
|
||||
E2D_ERROR("AtlasBuilder::buildAuto: Textures too large for atlas");
|
||||
E2D_ERROR("图集生成器::自动构建: 纹理尺寸过大,无法放入图集");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ bool UniformBuffer::create(uint32_t size, uint32_t binding) {
|
|||
// 获取缓冲区句柄
|
||||
handle_ = BufferHandle(buffer.release());
|
||||
|
||||
E2D_DEBUG("UBO 已创建: 大小={}, 绑定槽={}", size, binding);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -123,9 +122,12 @@ bool UniformBufferManager::initialize() {
|
|||
globalUBOs_[i] = std::make_unique<UniformBuffer>();
|
||||
if (!globalUBOs_[i]->create(UniformBufferManager::GLOBAL_UBO_SIZE,
|
||||
UniformBufferManager::GLOBAL_UBO_BINDING)) {
|
||||
E2D_ERROR("创建全局 UBO {} 失败", i);
|
||||
E2D_ERROR("创建全局 UBO [{}] 失败", i);
|
||||
return false;
|
||||
}
|
||||
E2D_DEBUG("全局 UBO [{}] 已创建: 大小={}, 绑定槽={}", i,
|
||||
UniformBufferManager::GLOBAL_UBO_SIZE,
|
||||
UniformBufferManager::GLOBAL_UBO_BINDING);
|
||||
}
|
||||
|
||||
// 预分配材质 UBO 池
|
||||
|
|
@ -134,7 +136,7 @@ bool UniformBufferManager::initialize() {
|
|||
// 预分配材质 UBO CPU 缓冲区
|
||||
materialUBOBuffer_.resize(MATERIAL_UBO_BUFFER_SIZE);
|
||||
|
||||
E2D_INFO("UniformBufferManager 已初始化,使用双缓冲");
|
||||
E2D_INFO("统一缓冲区管理器已初始化,使用双缓冲");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +150,7 @@ void UniformBufferManager::shutdown() {
|
|||
materialUBOBufferOffset_ = 0;
|
||||
currentMaterialUBO_ = nullptr;
|
||||
|
||||
E2D_INFO("UniformBufferManager 已关闭");
|
||||
E2D_INFO("统一缓冲区管理器 已关闭");
|
||||
}
|
||||
|
||||
UniformBuffer *UniformBufferManager::getGlobalUBO(uint32_t frameIndex) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue