Refactor OpenGL SwapChain HDC management
- OpenGLSwapChain now gets HDC from OpenGLDevice instead of creating its own - Renamed OpenGLDevice::GetContext() to GetGLContext() for clarity - Renamed OpenGLDevice::GetDC() to GetPresentationDC() for clarity - OpenGLDevice now owns the HDC/HGLRC lifecycle - OpenGLSwapChain::Initialize() now takes OpenGLDevice* parameter - OpenGLSwapChain::Present() uses device's HDC for SwapBuffers - Updated minimal test to use new API and capture from frame 25-35 - RenderDoc SetDevice now uses GetGLContext() for proper OpenGL hook
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <Windows.h>
|
||||
|
||||
#include "../RHIDevice.h"
|
||||
#include "../RHICapabilities.h"
|
||||
|
||||
struct HWND__;
|
||||
struct HDC__;
|
||||
struct HGLRC__;
|
||||
|
||||
@@ -13,9 +13,10 @@ namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
using HWND = HWND__*;
|
||||
using HDC = HDC__*;
|
||||
using HGLRC = HGLRC__*;
|
||||
|
||||
class OpenGLSwapChain;
|
||||
|
||||
class OpenGLDevice : public RHIDevice {
|
||||
public:
|
||||
OpenGLDevice();
|
||||
@@ -24,12 +25,11 @@ public:
|
||||
bool Initialize(const RHIDeviceDesc& desc) override;
|
||||
void Shutdown() override;
|
||||
|
||||
bool CreateRenderWindow(int width, int height, const char* title, bool enableDebug = false);
|
||||
bool InitializeWithExistingWindow(HWND hwnd);
|
||||
|
||||
bool CreateRenderWindow(int width, int height, const char* title, bool enableDebug = false);
|
||||
HWND GetWindow() const { return m_hwnd; }
|
||||
HDC GetDC() const { return m_hdc; }
|
||||
HGLRC GetContext() const { return m_hglrc; }
|
||||
HDC GetPresentationDC() const { return m_hdc; }
|
||||
HGLRC GetGLContext() const { return m_hglrc; }
|
||||
const RHIDeviceInfo& GetDeviceInfoImpl() const { return m_deviceInfo; }
|
||||
|
||||
void SwapBuffers();
|
||||
@@ -54,14 +54,16 @@ public:
|
||||
void* GetNativeHandle() const;
|
||||
|
||||
private:
|
||||
HWND m_hwnd;
|
||||
HDC m_hdc;
|
||||
HGLRC m_hglrc;
|
||||
friend class OpenGLSwapChain;
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HDC m_hdc = nullptr;
|
||||
HGLRC m_hglrc = nullptr;
|
||||
RHIDeviceInfo m_deviceInfo;
|
||||
RHICapabilities m_capabilities;
|
||||
bool m_initialized;
|
||||
bool m_ownsWindow;
|
||||
bool m_shouldClose;
|
||||
bool m_initialized = false;
|
||||
bool m_ownsWindow = false;
|
||||
bool m_shouldClose = false;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "../RHISwapChain.h"
|
||||
#include "OpenGLTexture.h"
|
||||
#include "OpenGLDevice.h"
|
||||
|
||||
struct HWND__;
|
||||
struct HDC__;
|
||||
@@ -11,9 +12,6 @@ struct HDC__;
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
using HWND = HWND__*;
|
||||
using HDC = HDC__*;
|
||||
|
||||
enum class PresentMode {
|
||||
Immediate,
|
||||
VSync,
|
||||
@@ -33,8 +31,7 @@ public:
|
||||
OpenGLSwapChain();
|
||||
~OpenGLSwapChain() override;
|
||||
|
||||
bool Initialize(HWND window, bool vsync = true);
|
||||
bool Initialize(HWND window, int width, int height, PresentMode mode = PresentMode::VSync);
|
||||
bool Initialize(OpenGLDevice* device, HWND window, int width, int height);
|
||||
void Shutdown() override;
|
||||
|
||||
void Present(uint32_t syncInterval = 1, uint32_t flags = 0) override;
|
||||
@@ -52,7 +49,7 @@ public:
|
||||
int GetFramebufferHeight() const { return m_framebufferHeight; }
|
||||
|
||||
HWND GetWindow() const { return m_hwnd; }
|
||||
HDC GetDC() const { return m_hdc; }
|
||||
HDC GetDC() const { return m_device ? m_device->GetPresentationDC() : nullptr; }
|
||||
|
||||
bool ShouldClose() const override;
|
||||
void SetShouldClose(bool shouldClose) override;
|
||||
@@ -63,17 +60,17 @@ public:
|
||||
void* GetNativeHandle() override;
|
||||
|
||||
private:
|
||||
HWND m_hwnd;
|
||||
HDC m_hdc;
|
||||
int m_width;
|
||||
int m_height;
|
||||
int m_framebufferWidth;
|
||||
int m_framebufferHeight;
|
||||
bool m_vsync;
|
||||
bool m_shouldClose;
|
||||
bool m_fullscreen;
|
||||
PresentMode m_presentMode;
|
||||
OpenGLTexture* m_backBufferTexture;
|
||||
OpenGLDevice* m_device = nullptr;
|
||||
HWND m_hwnd = nullptr;
|
||||
int m_width = 0;
|
||||
int m_height = 0;
|
||||
int m_framebufferWidth = 0;
|
||||
int m_framebufferHeight = 0;
|
||||
bool m_vsync = true;
|
||||
bool m_shouldClose = false;
|
||||
bool m_fullscreen = false;
|
||||
PresentMode m_presentMode = PresentMode::VSync;
|
||||
OpenGLTexture* m_backBufferTexture = nullptr;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
Reference in New Issue
Block a user