MetaCore/Source/MetaCoreRender/Private/MetaCoreRenderDevice.cpp

108 lines
2.7 KiB
C++

#include "MetaCoreRender/MetaCoreRenderDevice.h"
#include "MetaCorePlatform/MetaCoreWindow.h"
#include "camera.h"
#include "displayRegion.h"
#include "graphicsEngine.h"
#include "graphicsWindow.h"
#include "pandaFramework.h"
#include "pandaNode.h"
#include "perspectiveLens.h"
#include "windowFramework.h"
#include <glm/mat4x4.hpp>
#include <algorithm>
#include <memory>
namespace MetaCore {
namespace {
glm::mat4 MetaCoreConvertPandaMatrixToGlm(const LMatrix4f& matrix) {
glm::mat4 result(1.0F);
for (int col = 0; col < 4; ++col) {
for (int row = 0; row < 4; ++row) {
// Transpose mathematical matrix: result[col][row] is GLM(row, col).
// We want GLM(row, col) = Panda(col, row) to switch v*M to M*v.
result[col][row] = matrix.get_cell(col, row);
}
}
return result;
}
} // namespace
class MetaCoreRenderDevice::MetaCoreRenderDeviceImpl {
public:
MetaCoreWindow* Window = nullptr;
PandaFramework* Framework = nullptr;
WindowFramework* WindowFrameworkHandle = nullptr;
GraphicsWindow* GraphicsWindowHandle = nullptr;
GraphicsEngine* GraphicsEngineHandle = nullptr;
DisplayRegion* SceneDisplayRegion = nullptr;
NodePath SceneRoot{};
NodePath EditorCamera{};
bool Initialized = false;
};
MetaCoreRenderDevice::MetaCoreRenderDevice()
: Impl_(std::make_unique<MetaCoreRenderDeviceImpl>()) {
}
MetaCoreRenderDevice::~MetaCoreRenderDevice() {
Shutdown();
}
bool MetaCoreRenderDevice::Initialize(MetaCoreWindow& window) {
if (Impl_->Initialized) {
return true;
}
Impl_->Window = &window;
Impl_->Initialized = true;
return true;
}
void MetaCoreRenderDevice::Shutdown() {
if (!Impl_->Initialized) {
return;
}
if (!Impl_->EditorCamera.is_empty()) {
Impl_->EditorCamera.remove_node();
Impl_->EditorCamera = NodePath();
}
if (!Impl_->SceneRoot.is_empty()) {
Impl_->SceneRoot.remove_node();
Impl_->SceneRoot = NodePath();
}
Impl_->SceneDisplayRegion = nullptr;
Impl_->GraphicsEngineHandle = nullptr;
Impl_->GraphicsWindowHandle = nullptr;
Impl_->WindowFrameworkHandle = nullptr;
Impl_->Framework = nullptr;
Impl_->Window = nullptr;
Impl_->Initialized = false;
}
void MetaCoreRenderDevice::RenderFrame() const {
if (Impl_->GraphicsEngineHandle != nullptr) {
Impl_->GraphicsEngineHandle->render_frame();
}
}
void MetaCoreRenderDevice::PresentFrame() const {
if (Impl_->GraphicsEngineHandle != nullptr) {
Impl_->GraphicsEngineHandle->flip_frame();
}
}
void MetaCoreRenderDevice::SetSceneViewportRect(const MetaCoreViewportRect& viewportRect) {
// 已废弃 Panda3D 实现,视口管理已移至 Filament 链
}
} // namespace MetaCore