Add OpenGL backend: OpenGLDevice class

- Created OpenGLDevice class for window and OpenGL context management
- Added CreateWindow() and InitializeWithExistingWindow() methods
- Integrated with GLFW and GLAD
- Added to tests/OpenGL as test target

This is the first step in building the OpenGL RHI backend parallel to D3D12.
This commit is contained in:
2026-03-16 16:07:12 +08:00
parent 9c29cfa0a6
commit 6aaf89e603
3 changed files with 151 additions and 13 deletions

View File

@@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <GLFW/glfw3.h>
namespace XCEngine {
namespace RHI {
struct OpenGLDeviceInfo {
std::string vendor;
std::string renderer;
std::string version;
int majorVersion;
int minorVersion;
};
class OpenGLDevice {
public:
OpenGLDevice();
~OpenGLDevice();
bool CreateWindow(int width, int height, const char* title, bool enableDebug = false);
bool InitializeWithExistingWindow(GLFWwindow* window);
void Shutdown();
GLFWwindow* GetWindow() const { return m_window; }
const OpenGLDeviceInfo& GetDeviceInfo() const { return m_deviceInfo; }
void SwapBuffers();
bool PollEvents();
void SetShouldClose(bool shouldClose);
bool ShouldClose() const;
private:
GLFWwindow* m_window;
OpenGLDeviceInfo m_deviceInfo;
bool m_initialized;
bool m_ownsWindow;
};
} // namespace RHI
} // namespace XCEngine