save state
This commit is contained in:
@@ -1,89 +1,122 @@
|
||||
// Desktop platform implementation (simplified - uses RmlUi backend for graphics)
|
||||
// D:\Dev\Mosis\MosisService\designer\src\desktop_platform.cpp
|
||||
// Include glad BEFORE GLFW
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "desktop_platform.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
// Note: Graphics context and rendering is handled by RmlUi's backend.
|
||||
// This platform implementation provides additional utilities and state management.
|
||||
namespace mosis {
|
||||
|
||||
namespace mosis::desktop {
|
||||
// DesktopPlatform implementation
|
||||
|
||||
DesktopPlatform::DesktopPlatform()
|
||||
: m_file_interface(std::make_unique<DesktopFileInterface>())
|
||||
DesktopPlatform::DesktopPlatform(GLFWwindow* window, uint32_t width, uint32_t height)
|
||||
: m_window(window)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
{
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
m_start_time = std::chrono::duration<double>(now.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
DesktopPlatform::~DesktopPlatform() = default;
|
||||
|
||||
bool DesktopPlatform::Initialize(uint32_t width, uint32_t height, const char* title) {
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
// Graphics initialization is done by RmlUi Backend
|
||||
return true;
|
||||
}
|
||||
|
||||
void DesktopPlatform::Shutdown() {
|
||||
// Graphics shutdown is done by RmlUi Backend
|
||||
}
|
||||
|
||||
std::unique_ptr<IGraphicsContext> DesktopPlatform::CreateGraphicsContext() {
|
||||
// Graphics context is managed by RmlUi Backend
|
||||
// On desktop, GLFW manages the context, so we don't need a separate wrapper
|
||||
// Return nullptr to indicate context is already managed
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<IRenderTarget> DesktopPlatform::CreateRenderTarget(uint32_t width, uint32_t height) {
|
||||
// Render targets are managed by RmlUi Backend
|
||||
auto target = std::make_unique<DesktopRenderTarget>();
|
||||
if (target->Create(width, height)) {
|
||||
return target;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IFileInterface& DesktopPlatform::GetFileInterface() {
|
||||
return *m_file_interface;
|
||||
Rml::FileInterface& DesktopPlatform::GetFileInterface() {
|
||||
return m_file_interface;
|
||||
}
|
||||
|
||||
void DesktopPlatform::Log(const std::string& message) {
|
||||
std::cout << "[INFO] " << message << std::endl;
|
||||
}
|
||||
|
||||
void DesktopPlatform::LogError(const std::string& message) {
|
||||
std::cerr << "[ERROR] " << message << std::endl;
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
|
||||
bool DesktopPlatform::PollEvents() {
|
||||
// Events are handled by RmlUi Backend
|
||||
return true;
|
||||
glfwPollEvents();
|
||||
return !glfwWindowShouldClose(m_window);
|
||||
}
|
||||
|
||||
void DesktopPlatform::SwapBuffers() {
|
||||
// Swap is handled by RmlUi Backend
|
||||
}
|
||||
|
||||
bool DesktopPlatform::ShouldClose() const {
|
||||
return false; // Determined by RmlUi Backend
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
|
||||
void DesktopPlatform::SetResolution(uint32_t width, uint32_t height) {
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
glfwSetWindowSize(m_window, width, height);
|
||||
}
|
||||
|
||||
float DesktopPlatform::GetDpiScale() const {
|
||||
return 1.0f;
|
||||
void DesktopPlatform::SetAssetsPath(const std::string& path) {
|
||||
m_file_interface.SetAssetsPath(path);
|
||||
}
|
||||
|
||||
double DesktopPlatform::GetElapsedTime() const {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
double current = std::chrono::duration<double>(now.time_since_epoch()).count();
|
||||
return current - m_start_time;
|
||||
// DesktopRenderTarget implementation
|
||||
|
||||
DesktopRenderTarget::~DesktopRenderTarget() {
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool DesktopPlatform::IsMouseButtonDown() const {
|
||||
return false; // Input is handled through RmlUi
|
||||
bool DesktopRenderTarget::Create(uint32_t width, uint32_t height) {
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
// Create framebuffer
|
||||
glGenFramebuffers(1, &m_framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
|
||||
|
||||
// Create color texture
|
||||
glGenTextures(1, &m_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0);
|
||||
|
||||
// Create depth/stencil renderbuffer
|
||||
glGenRenderbuffers(1, &m_depth_buffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_depth_buffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depth_buffer);
|
||||
|
||||
// Check completeness
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
Destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DesktopPlatform::GetMousePosition(double& x, double& y) const {
|
||||
x = y = 0; // Input is handled through RmlUi
|
||||
void DesktopRenderTarget::Bind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
}
|
||||
|
||||
} // namespace mosis::desktop
|
||||
void DesktopRenderTarget::Unbind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void DesktopRenderTarget::Destroy() {
|
||||
if (m_depth_buffer) {
|
||||
glDeleteRenderbuffers(1, &m_depth_buffer);
|
||||
m_depth_buffer = 0;
|
||||
}
|
||||
if (m_texture) {
|
||||
glDeleteTextures(1, &m_texture);
|
||||
m_texture = 0;
|
||||
}
|
||||
if (m_framebuffer) {
|
||||
glDeleteFramebuffers(1, &m_framebuffer);
|
||||
m_framebuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mosis
|
||||
|
||||
Reference in New Issue
Block a user