feat(RHI): 实现 RHISwapChain 抽象基类
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <wrl/client.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../RHISwapChain.h"
|
||||
#include "D3D12Enum.h"
|
||||
#include "D3D12Texture.h"
|
||||
|
||||
@@ -13,22 +14,27 @@ using Microsoft::WRL::ComPtr;
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class D3D12SwapChain {
|
||||
class D3D12SwapChain : public RHISwapChain {
|
||||
public:
|
||||
D3D12SwapChain();
|
||||
~D3D12SwapChain();
|
||||
~D3D12SwapChain() override;
|
||||
|
||||
bool Initialize(IDXGIFactory4* factory, ID3D12CommandQueue* commandQueue, HWND windowHandle, uint32_t width, uint32_t height, uint32_t bufferCount = 2);
|
||||
bool Initialize(IDXGISwapChain* swapChain, uint32_t width, uint32_t height);
|
||||
void Shutdown();
|
||||
void Shutdown() override;
|
||||
|
||||
uint32_t GetCurrentBackBufferIndex() const;
|
||||
uint32_t GetCurrentBackBufferIndex() const override;
|
||||
RHITexture* GetCurrentBackBuffer() override;
|
||||
D3D12Texture* GetBackBuffer(uint32_t index) const;
|
||||
void Present(uint32_t syncInterval, uint32_t flags);
|
||||
void Resize(uint32_t width, uint32_t height);
|
||||
void SetFullscreen(bool fullscreen);
|
||||
bool IsFullscreen() const;
|
||||
void* GetNativeHandle() const;
|
||||
void Present(uint32_t syncInterval = 1, uint32_t flags = 0) override;
|
||||
void Resize(uint32_t width, uint32_t height) override;
|
||||
void SetFullscreen(bool fullscreen) override;
|
||||
bool IsFullscreen() const override;
|
||||
void* GetNativeHandle() override;
|
||||
|
||||
bool ShouldClose() const override;
|
||||
void SetShouldClose(bool shouldClose) override;
|
||||
void PollEvents() override;
|
||||
|
||||
IDXGISwapChain3* GetSwapChain() const { return m_swapChain.Get(); }
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../RHISwapChain.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
@@ -20,20 +22,22 @@ enum class SurfaceFormat {
|
||||
BGRA8
|
||||
};
|
||||
|
||||
class OpenGLSwapChain {
|
||||
class OpenGLSwapChain : public RHISwapChain {
|
||||
public:
|
||||
OpenGLSwapChain();
|
||||
~OpenGLSwapChain();
|
||||
~OpenGLSwapChain() override;
|
||||
|
||||
bool Initialize(GLFWwindow* window, bool vsync = true);
|
||||
bool Initialize(GLFWwindow* window, int width, int height, PresentMode mode = PresentMode::VSync);
|
||||
void Shutdown();
|
||||
void Shutdown() override;
|
||||
|
||||
void Present();
|
||||
void Present(uint32_t syncInterval = 1, uint32_t flags = 0) override;
|
||||
void SwapBuffers();
|
||||
void Resize(int width, int height);
|
||||
void Resize(uint32_t width, uint32_t height) override;
|
||||
void SetVSync(bool enabled);
|
||||
bool IsVSync() const { return m_vsync; }
|
||||
void SetFullscreen(bool fullscreen) override;
|
||||
bool IsFullscreen() const override;
|
||||
|
||||
void SetFramebufferSize(int width, int height);
|
||||
int GetWidth() const { return m_width; }
|
||||
@@ -43,9 +47,13 @@ public:
|
||||
|
||||
GLFWwindow* GetWindow() const { return m_window; }
|
||||
|
||||
bool ShouldClose() const;
|
||||
void SetShouldClose(bool shouldClose);
|
||||
void PollEvents();
|
||||
bool ShouldClose() const override;
|
||||
void SetShouldClose(bool shouldClose) override;
|
||||
void PollEvents() override;
|
||||
|
||||
uint32_t GetCurrentBackBufferIndex() const override;
|
||||
RHITexture* GetCurrentBackBuffer() override;
|
||||
void* GetNativeHandle() override;
|
||||
|
||||
private:
|
||||
GLFWwindow* m_window;
|
||||
|
||||
31
engine/include/XCEngine/RHI/RHISwapChain.h
Normal file
31
engine/include/XCEngine/RHI/RHISwapChain.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "RHITypes.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class RHITexture;
|
||||
|
||||
class RHISwapChain {
|
||||
public:
|
||||
virtual ~RHISwapChain() = default;
|
||||
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual uint32_t GetCurrentBackBufferIndex() const = 0;
|
||||
virtual RHITexture* GetCurrentBackBuffer() = 0;
|
||||
virtual void Present(uint32_t syncInterval = 1, uint32_t flags = 0) = 0;
|
||||
virtual void Resize(uint32_t width, uint32_t height) = 0;
|
||||
virtual void SetFullscreen(bool fullscreen) = 0;
|
||||
virtual bool IsFullscreen() const = 0;
|
||||
|
||||
virtual bool ShouldClose() const = 0;
|
||||
virtual void SetShouldClose(bool shouldClose) = 0;
|
||||
virtual void PollEvents() = 0;
|
||||
|
||||
virtual void* GetNativeHandle() = 0;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user