fix(RHI): 修复 OpenGL/D3D12 后端编译问题

- 修复 OpenGLCommandList 方法签名匹配 RHI 抽象接口
- 修复 OpenGLSwapChain Present/Resize 方法签名
- 添加 OpenGL 特有方法重载支持后端测试(底层逃逸)
- 暂时禁用不兼容的 Resources 模块
- 更新 OpenGL 测试 CMakeLists
This commit is contained in:
2026-03-17 19:35:51 +08:00
parent a257ff2d8b
commit e138fb2075
15 changed files with 188 additions and 308 deletions

View File

@@ -150,6 +150,20 @@ add_library(XCEngine STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLSampler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLSampler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLRenderTargetView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLRenderTargetView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLDepthStencilView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLDepthStencilView.cpp
# Resources - TEMPORARILY DISABLED
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/Resources.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/ResourceTypes.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/IResource.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/ResourceHandle.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/IResourceLoader.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/ResourceManager.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/ResourceCache.h
# ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/Resources/AsyncLoader.h
# ${CMAKE_CURRENT_SOURCE_DIR}/src/Resources/ResourceManager.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/Resources/ResourceCache.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/Resources/AsyncLoader.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/Resources/ResourceTypes.cpp
) )
target_include_directories(XCEngine PUBLIC target_include_directories(XCEngine PUBLIC

View File

@@ -31,9 +31,12 @@ public:
void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override; void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
void TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES); void TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
void UAVBarrier(void* resource = nullptr); void UAVBarrier(void* resource = nullptr);
void UAVBarrierInternal(ID3D12Resource* resource);
void AliasBarrier(void* beforeResource = nullptr, void* afterResource = nullptr); void AliasBarrier(void* beforeResource = nullptr, void* afterResource = nullptr);
void AliasBarrierInternal(ID3D12Resource* beforeResource, ID3D12Resource* afterResource);
void SetPipelineState(void* pso) override; void SetPipelineState(void* pso) override;
void SetPipelineStateInternal(ID3D12PipelineState* pso);
void SetRootSignature(ID3D12RootSignature* signature); void SetRootSignature(ID3D12RootSignature* signature);
void SetViewport(const Viewport& viewport) override; void SetViewport(const Viewport& viewport) override;
void SetViewports(uint32_t count, const Viewport* viewports) override; void SetViewports(uint32_t count, const Viewport* viewports) override;
@@ -68,7 +71,9 @@ public:
void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t startVertex = 0, uint32_t startInstance = 0) override; void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t startVertex = 0, uint32_t startInstance = 0) override;
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t startIndex = 0, int32_t baseVertex = 0, uint32_t startInstance = 0) override; void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t startIndex = 0, int32_t baseVertex = 0, uint32_t startInstance = 0) override;
void DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset); void DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset);
void DrawInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
void DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset); void DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset);
void DrawIndexedInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
void Clear(float r, float g, float b, float a, uint32_t buffers) override; void Clear(float r, float g, float b, float a, uint32_t buffers) override;
void ClearRenderTarget(void* renderTarget, const float color[4]) override; void ClearRenderTarget(void* renderTarget, const float color[4]) override;
@@ -90,6 +95,7 @@ public:
void Dispatch(uint32_t x, uint32_t y, uint32_t z) override; void Dispatch(uint32_t x, uint32_t y, uint32_t z) override;
void DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset); void DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset);
void DispatchIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
void ExecuteBundle(ID3D12GraphicsCommandList* bundle); void ExecuteBundle(ID3D12GraphicsCommandList* bundle);

View File

@@ -80,7 +80,7 @@ public:
const RHIDeviceInfo& GetDeviceInfo() const override; const RHIDeviceInfo& GetDeviceInfo() const override;
void* GetNativeDevice() override; void* GetNativeDevice() override;
void* GetNativeHandle() const override; void* GetNativeHandle() const;
bool PollEvents() override; bool PollEvents() override;
void SwapBuffers() override; void SwapBuffers() override;

View File

@@ -57,6 +57,12 @@ public:
void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) override; void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) override;
void SetIndexBuffer(void* buffer, uint64_t offset, Format format) override; void SetIndexBuffer(void* buffer, uint64_t offset, Format format) override;
// OpenGL 特有版本(底层逃逸)
void SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride);
void SetVertexBuffers(unsigned int startSlot, unsigned int count, const unsigned int* buffers, const size_t* offsets, const size_t* strides);
void SetIndexBuffer(unsigned int buffer, unsigned int type);
void SetIndexBuffer(unsigned int buffer, unsigned int type, size_t offset);
void BindVertexArray(unsigned int vao); void BindVertexArray(unsigned int vao);
void BindVertexArray(unsigned int vao, unsigned int indexBuffer, unsigned int indexType); void BindVertexArray(unsigned int vao, unsigned int indexBuffer, unsigned int indexType);
void UseShader(unsigned int program); void UseShader(unsigned int program);

View File

@@ -21,7 +21,7 @@ public:
bool InitializeWithExistingWindow(GLFWwindow* window); bool InitializeWithExistingWindow(GLFWwindow* window);
GLFWwindow* GetWindow() const { return m_window; } GLFWwindow* GetWindow() const { return m_window; }
const OpenGLDeviceInfo& GetDeviceInfoImpl() const { return m_deviceInfo; } const RHIDeviceInfo& GetDeviceInfoImpl() const { return m_deviceInfo; }
void SwapBuffers() override; void SwapBuffers() override;
bool PollEvents() override; bool PollEvents() override;
@@ -42,13 +42,12 @@ public:
const RHIDeviceInfo& GetDeviceInfo() const override; const RHIDeviceInfo& GetDeviceInfo() const override;
void* GetNativeDevice() override; void* GetNativeDevice() override;
void* GetNativeHandle() const override; void* GetNativeHandle() const;
private: private:
GLFWwindow* m_window; GLFWwindow* m_window;
OpenGLDeviceInfo m_deviceInfo; RHIDeviceInfo m_deviceInfo;
RHICapabilities m_capabilities; RHICapabilities m_capabilities;
RHIDeviceInfo m_deviceInfoBase;
bool m_initialized; bool m_initialized;
bool m_ownsWindow; bool m_ownsWindow;
}; };

View File

@@ -5,43 +5,20 @@
#include <string> #include <string>
#include "../RHIPipelineState.h" #include "../RHIPipelineState.h"
#include "../RHIEnums.h"
namespace XCEngine { namespace XCEngine {
namespace RHI { namespace RHI {
enum class ComparisonFunc { enum class OpenGLPrimitiveTopology {
Never, Points,
Less, Lines,
Equal, LineStrip,
LessEqual, Triangles,
Greater, TriangleStrip
NotEqual,
GreaterEqual,
Always
}; };
enum class BlendFactor { enum class OpenGLBlendOp {
Zero,
One,
SrcColor,
OneMinusSrcColor,
DstColor,
OneMinusDstColor,
SrcAlpha,
OneMinusSrcAlpha,
DstAlpha,
OneMinusDstAlpha,
ConstantColor,
OneMinusConstantColor,
ConstantAlpha,
OneMinusConstantAlpha,
Src1Color,
InvSrc1Color,
Src1Alpha,
InvSrc1Alpha
};
enum class BlendOp {
Add, Add,
Subtract, Subtract,
ReverseSubtract, ReverseSubtract,
@@ -66,17 +43,6 @@ enum class PolygonMode {
Fill Fill
}; };
enum class StencilOp {
Keep,
Zero,
Replace,
Incr,
IncrWrap,
Decr,
DecrWrap,
Invert
};
struct DepthStencilState { struct DepthStencilState {
bool depthTestEnable = true; bool depthTestEnable = true;
bool depthWriteEnable = true; bool depthWriteEnable = true;
@@ -94,7 +60,7 @@ struct DepthStencilState {
struct BlendState { struct BlendState {
bool blendEnable = false; bool blendEnable = false;
BlendFactor srcBlend = BlendFactor::SrcAlpha; BlendFactor srcBlend = BlendFactor::SrcAlpha;
BlendFactor dstBlend = BlendFactor::OneMinusSrcAlpha; BlendFactor dstBlend = BlendFactor::InvSrcAlpha;
BlendFactor srcBlendAlpha = BlendFactor::One; BlendFactor srcBlendAlpha = BlendFactor::One;
BlendFactor dstBlendAlpha = BlendFactor::Zero; BlendFactor dstBlendAlpha = BlendFactor::Zero;
BlendOp blendOp = BlendOp::Add; BlendOp blendOp = BlendOp::Add;

View File

@@ -41,9 +41,7 @@ void D3D12CommandList::Shutdown() {
m_trackedResources.clear(); m_trackedResources.clear();
} }
void D3D12CommandList::Reset(ID3D12CommandAllocator* allocator) { void D3D12CommandList::Reset() {
m_commandList->Reset(allocator, nullptr);
m_currentTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; m_currentTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
m_currentPipelineState = nullptr; m_currentPipelineState = nullptr;
m_currentRootSignature = nullptr; m_currentRootSignature = nullptr;
@@ -54,7 +52,23 @@ void D3D12CommandList::Close() {
m_commandList->Close(); m_commandList->Close();
} }
void D3D12CommandList::TransitionBarrier(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource) { void D3D12CommandList::TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
TransitionBarrierInternal(static_cast<ID3D12Resource*>(resource), stateBefore, stateAfter);
}
void D3D12CommandList::UAVBarrier(void* resource) {
UAVBarrierInternal(static_cast<ID3D12Resource*>(resource));
}
void D3D12CommandList::AliasBarrier(void* beforeResource, void* afterResource) {
AliasBarrierInternal(static_cast<ID3D12Resource*>(beforeResource), static_cast<ID3D12Resource*>(afterResource));
}
void D3D12CommandList::SetPipelineState(void* pso) {
SetPipelineStateInternal(static_cast<ID3D12PipelineState*>(pso));
}
void D3D12CommandList::TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource) {
D3D12_RESOURCE_BARRIER barrier = {}; D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
@@ -68,7 +82,7 @@ void D3D12CommandList::TransitionBarrier(ID3D12Resource* resource, ResourceState
m_resourceStateMap[resource] = stateAfter; m_resourceStateMap[resource] = stateAfter;
} }
void D3D12CommandList::UAVBarrier(ID3D12Resource* resource) { void D3D12CommandList::UAVBarrierInternal(ID3D12Resource* resource) {
D3D12_RESOURCE_BARRIER barrier = {}; D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
@@ -77,7 +91,7 @@ void D3D12CommandList::UAVBarrier(ID3D12Resource* resource) {
m_commandList->ResourceBarrier(1, &barrier); m_commandList->ResourceBarrier(1, &barrier);
} }
void D3D12CommandList::AliasBarrier(ID3D12Resource* beforeResource, ID3D12Resource* afterResource) { void D3D12CommandList::AliasBarrierInternal(ID3D12Resource* beforeResource, ID3D12Resource* afterResource) {
D3D12_RESOURCE_BARRIER barrier = {}; D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
@@ -87,16 +101,11 @@ void D3D12CommandList::AliasBarrier(ID3D12Resource* beforeResource, ID3D12Resour
m_commandList->ResourceBarrier(1, &barrier); m_commandList->ResourceBarrier(1, &barrier);
} }
void D3D12CommandList::SetPipelineState(ID3D12PipelineState* pso) { void D3D12CommandList::SetPipelineStateInternal(ID3D12PipelineState* pso) {
m_commandList->SetPipelineState(pso); m_commandList->SetPipelineState(pso);
m_currentPipelineState = pso; m_currentPipelineState = pso;
} }
void D3D12CommandList::SetRootSignature(ID3D12RootSignature* signature) {
m_commandList->SetGraphicsRootSignature(signature);
m_currentRootSignature = signature;
}
void D3D12CommandList::SetViewport(const Viewport& viewport) { void D3D12CommandList::SetViewport(const Viewport& viewport) {
D3D12_VIEWPORT d3d12Viewport = {}; D3D12_VIEWPORT d3d12Viewport = {};
d3d12Viewport.TopLeftX = viewport.topLeftX; d3d12Viewport.TopLeftX = viewport.topLeftX;
@@ -150,7 +159,15 @@ void D3D12CommandList::SetPrimitiveTopology(PrimitiveTopology topology) {
m_currentTopology = ToD3D12Topology(topology); m_currentTopology = ToD3D12Topology(topology);
} }
void D3D12CommandList::SetRenderTargets(uint32_t count, ID3D12Resource** renderTargets, ID3D12Resource* depthStencil) { void D3D12CommandList::SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil) {
std::vector<ID3D12Resource*> resources(count);
for (uint32_t i = 0; i < count; ++i) {
resources[i] = static_cast<ID3D12Resource*>(renderTargets[i]);
}
SetRenderTargetsInternal(count, resources.data(), static_cast<ID3D12Resource*>(depthStencil));
}
void D3D12CommandList::SetRenderTargetsInternal(uint32_t count, ID3D12Resource** renderTargets, ID3D12Resource* depthStencil) {
std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> rtvHandles(count); std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> rtvHandles(count);
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
rtvHandles[i].ptr = 0; rtvHandles[i].ptr = 0;
@@ -162,11 +179,11 @@ void D3D12CommandList::SetRenderTargets(uint32_t count, ID3D12Resource** renderT
m_commandList->OMSetRenderTargets(count, count > 0 ? rtvHandles.data() : nullptr, FALSE, depthStencil ? &dsvHandle : nullptr); m_commandList->OMSetRenderTargets(count, count > 0 ? rtvHandles.data() : nullptr, FALSE, depthStencil ? &dsvHandle : nullptr);
} }
void D3D12CommandList::SetRenderTargets(uint32_t count, const D3D12_CPU_DESCRIPTOR_HANDLE* renderTargetHandles, const D3D12_CPU_DESCRIPTOR_HANDLE* depthStencilHandle) { void D3D12CommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) {
m_commandList->OMSetRenderTargets(count, renderTargetHandles, FALSE, depthStencilHandle); SetVertexBufferInternal(slot, static_cast<ID3D12Resource*>(buffer), offset, stride);
} }
void D3D12CommandList::SetVertexBuffer(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride) { void D3D12CommandList::SetVertexBufferInternal(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride) {
D3D12_VERTEX_BUFFER_VIEW view = {}; D3D12_VERTEX_BUFFER_VIEW view = {};
view.BufferLocation = buffer->GetGPUVirtualAddress() + offset; view.BufferLocation = buffer->GetGPUVirtualAddress() + offset;
view.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width) - static_cast<UINT>(offset); view.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width) - static_cast<UINT>(offset);
@@ -175,11 +192,25 @@ void D3D12CommandList::SetVertexBuffer(uint32_t slot, ID3D12Resource* buffer, ui
m_commandList->IASetVertexBuffers(slot, 1, &view); m_commandList->IASetVertexBuffers(slot, 1, &view);
} }
void D3D12CommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const D3D12_VERTEX_BUFFER_VIEW* views) { void D3D12CommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) {
std::vector<D3D12_VERTEX_BUFFER_VIEW> views(count);
for (uint32_t i = 0; i < count; ++i) {
views[i].BufferLocation = buffers[i];
views[i].StrideInBytes = strides[i];
views[i].SizeInBytes = 0;
}
SetVertexBuffersInternal(startSlot, count, views.data());
}
void D3D12CommandList::SetVertexBuffersInternal(uint32_t startSlot, uint32_t count, const D3D12_VERTEX_BUFFER_VIEW* views) {
m_commandList->IASetVertexBuffers(startSlot, count, views); m_commandList->IASetVertexBuffers(startSlot, count, views);
} }
void D3D12CommandList::SetIndexBuffer(ID3D12Resource* buffer, uint64_t offset, Format indexFormat) { void D3D12CommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format format) {
SetIndexBufferInternal(static_cast<ID3D12Resource*>(buffer), offset, format);
}
void D3D12CommandList::SetIndexBufferInternal(ID3D12Resource* buffer, uint64_t offset, Format indexFormat) {
D3D12_INDEX_BUFFER_VIEW view = {}; D3D12_INDEX_BUFFER_VIEW view = {};
view.BufferLocation = buffer->GetGPUVirtualAddress() + offset; view.BufferLocation = buffer->GetGPUVirtualAddress() + offset;
view.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width) - static_cast<UINT>(offset); view.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width) - static_cast<UINT>(offset);
@@ -240,11 +271,19 @@ void D3D12CommandList::DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
m_commandList->DrawIndexedInstanced(indexCount, instanceCount, startIndex, baseVertex, startInstance); m_commandList->DrawIndexedInstanced(indexCount, instanceCount, startIndex, baseVertex, startInstance);
} }
void D3D12CommandList::DrawInstancedIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) { void D3D12CommandList::DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset) {
DrawInstancedIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
}
void D3D12CommandList::DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset) {
DrawIndexedInstancedIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
}
void D3D12CommandList::DrawInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0); m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0);
} }
void D3D12CommandList::DrawIndexedInstancedIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) { void D3D12CommandList::DrawIndexedInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0); m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0);
} }
@@ -270,7 +309,11 @@ void D3D12CommandList::ClearUnorderedAccessView(D3D12_GPU_DESCRIPTOR_HANDLE view
m_commandList->ClearUnorderedAccessViewFloat(viewHandle, resourceHandle, unorderedAccess, values, rectCount, rects); m_commandList->ClearUnorderedAccessViewFloat(viewHandle, resourceHandle, unorderedAccess, values, rectCount, rects);
} }
void D3D12CommandList::CopyResource(ID3D12Resource* dst, ID3D12Resource* src) { void D3D12CommandList::CopyResource(void* dst, void* src) {
CopyResourceInternal(static_cast<ID3D12Resource*>(dst), static_cast<ID3D12Resource*>(src));
}
void D3D12CommandList::CopyResourceInternal(ID3D12Resource* dst, ID3D12Resource* src) {
m_commandList->CopyResource(dst, src); m_commandList->CopyResource(dst, src);
} }
@@ -318,7 +361,11 @@ void D3D12CommandList::Dispatch(uint32_t threadGroupCountX, uint32_t threadGroup
m_commandList->Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ); m_commandList->Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
} }
void D3D12CommandList::DispatchIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) { void D3D12CommandList::DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset) {
DispatchIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
}
void D3D12CommandList::DispatchIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0); m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0);
} }
@@ -343,191 +390,5 @@ void D3D12CommandList::TrackResource(ID3D12Resource* resource) {
} }
} }
void D3D12CommandList::Reset() {
m_currentTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
m_currentPipelineState = nullptr;
m_currentRootSignature = nullptr;
m_currentDescriptorHeap = nullptr;
}
void D3D12CommandList::TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
TransitionBarrierInternal(static_cast<ID3D12Resource*>(resource), stateBefore, stateAfter);
}
void D3D12CommandList::UAVBarrier(void* resource) {
UAVBarrierInternal(static_cast<ID3D12Resource*>(resource));
}
void D3D12CommandList::AliasBarrier(void* beforeResource, void* afterResource) {
AliasBarrierInternal(static_cast<ID3D12Resource*>(beforeResource), static_cast<ID3D12Resource*>(afterResource));
}
void D3D12CommandList::SetPipelineState(void* pso) {
SetPipelineStateInternal(static_cast<ID3D12PipelineState*>(pso));
}
void D3D12CommandList::SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil) {
std::vector<ID3D12Resource*> resources(count);
for (uint32_t i = 0; i < count; ++i) {
resources[i] = static_cast<ID3D12Resource*>(renderTargets[i]);
}
SetRenderTargetsInternal(count, resources.data(), static_cast<ID3D12Resource*>(depthStencil));
}
void D3D12CommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) {
SetVertexBufferInternal(slot, static_cast<ID3D12Resource*>(buffer), offset, stride);
}
void D3D12CommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) {
std::vector<D3D12_VERTEX_BUFFER_VIEW> views(count);
for (uint32_t i = 0; i < count; ++i) {
views[i].BufferLocation = buffers[i];
views[i].StrideInBytes = strides[i];
views[i].SizeInBytes = 0;
}
SetVertexBuffersInternal(startSlot, count, views.data());
}
void D3D12CommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format format) {
SetIndexBufferInternal(static_cast<ID3D12Resource*>(buffer), offset, format);
}
void D3D12CommandList::Clear(float r, float g, float b, float a, uint32_t buffers) {
float color[4] = { r, g, b, a };
ClearRenderTarget(nullptr, color);
}
void D3D12CommandList::ClearRenderTarget(void* renderTarget, const float color[4]) {
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = {};
if (renderTarget) {
}
m_commandList->ClearRenderTargetView(rtvHandle, color, 0, nullptr);
}
void D3D12CommandList::ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) {
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {};
if (depthStencil) {
}
m_commandList->ClearDepthStencilView(dsvHandle, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, depth, stencil, 0, nullptr);
}
void D3D12CommandList::CopyResource(void* dst, void* src) {
CopyResourceInternal(static_cast<ID3D12Resource*>(dst), static_cast<ID3D12Resource*>(src));
}
void D3D12CommandList::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
m_commandList->Dispatch(x, y, z);
}
void D3D12CommandList::DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset) {
DispatchIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
}
void D3D12CommandList::DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset) {
DrawInstancedIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
}
void D3D12CommandList::DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset) {
DrawIndexedInstancedIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
}
void D3D12CommandList::TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource) {
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.Transition.pResource = resource;
barrier.Transition.StateBefore = ToD3D12(stateBefore);
barrier.Transition.StateAfter = ToD3D12(stateAfter);
barrier.Transition.Subresource = subresource;
m_commandList->ResourceBarrier(1, &barrier);
m_resourceStateMap[resource] = stateAfter;
}
void D3D12CommandList::UAVBarrierInternal(ID3D12Resource* resource) {
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.UAV.pResource = resource;
m_commandList->ResourceBarrier(1, &barrier);
}
void D3D12CommandList::AliasBarrierInternal(ID3D12Resource* beforeResource, ID3D12Resource* afterResource) {
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.Aliasing.pResourceBefore = beforeResource;
barrier.Aliasing.pResourceAfter = afterResource;
m_commandList->ResourceBarrier(1, &barrier);
}
void D3D12CommandList::SetPipelineStateInternal(ID3D12PipelineState* pso) {
m_commandList->SetPipelineState(pso);
m_currentPipelineState = pso;
}
void D3D12CommandList::SetRenderTargetsInternal(uint32_t count, ID3D12Resource** renderTargets, ID3D12Resource* depthStencil) {
std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> rtvHandles(count);
for (uint32_t i = 0; i < count; ++i) {
rtvHandles[i].ptr = 0;
}
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {};
dsvHandle.ptr = 0;
m_commandList->OMSetRenderTargets(count, count > 0 ? rtvHandles.data() : nullptr, FALSE, depthStencil ? &dsvHandle : nullptr);
}
void D3D12CommandList::SetVertexBufferInternal(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride) {
D3D12_VERTEX_BUFFER_VIEW view = {};
view.BufferLocation = buffer->GetGPUVirtualAddress() + offset;
view.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width) - static_cast<UINT>(offset);
view.StrideInBytes = stride;
m_commandList->IASetVertexBuffers(slot, 1, &view);
}
void D3D12CommandList::SetVertexBuffersInternal(uint32_t startSlot, uint32_t count, const D3D12_VERTEX_BUFFER_VIEW* views) {
m_commandList->IASetVertexBuffers(startSlot, count, views);
}
void D3D12CommandList::SetIndexBufferInternal(ID3D12Resource* buffer, uint64_t offset, Format indexFormat) {
D3D12_INDEX_BUFFER_VIEW view = {};
view.BufferLocation = buffer->GetGPUVirtualAddress() + offset;
view.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width) - static_cast<UINT>(offset);
view.Format = ToD3D12(indexFormat);
m_commandList->IASetIndexBuffer(&view);
}
void D3D12CommandList::ClearRenderTargetView(ID3D12Resource* renderTarget, const float color[4], uint32_t rectCount, const D3D12_RECT* rects) {
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = {};
m_commandList->ClearRenderTargetView(rtvHandle, color, rectCount, rects);
}
void D3D12CommandList::ClearDepthStencilView(ID3D12Resource* depthStencil, uint32_t clearFlags, float depth, uint8_t stencil, uint32_t rectCount, const D3D12_RECT* rects) {
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {};
m_commandList->ClearDepthStencilView(dsvHandle, static_cast<D3D12_CLEAR_FLAGS>(clearFlags), depth, stencil, rectCount, rects);
}
void D3D12CommandList::CopyResourceInternal(ID3D12Resource* dst, ID3D12Resource* src) {
m_commandList->CopyResource(dst, src);
}
void D3D12CommandList::DispatchIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0);
}
void D3D12CommandList::DrawInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0);
}
void D3D12CommandList::DrawIndexedInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
m_commandList->ExecuteIndirect(nullptr, 1, argBuffer, alignedByteOffset, nullptr, 0);
}
} // namespace RHI } // namespace RHI
} // namespace XCEngine } // namespace XCEngine

View File

@@ -199,7 +199,15 @@ const RHIDeviceInfo& D3D12Device::GetDeviceInfo() const {
RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& desc) { RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& desc) {
auto* buffer = new D3D12Buffer(); auto* buffer = new D3D12Buffer();
if (buffer->Initialize(m_device.Get(), desc.size, desc.stride, desc.bufferType)) { D3D12_HEAP_TYPE heapType = D3D12_HEAP_TYPE_DEFAULT;
if (desc.bufferType == static_cast<uint32_t>(BufferType::ReadBack)) {
heapType = D3D12_HEAP_TYPE_READBACK;
} else if (desc.bufferType == static_cast<uint32_t>(BufferType::Constant)) {
heapType = D3D12_HEAP_TYPE_UPLOAD;
}
if (buffer->Initialize(m_device.Get(), desc.size, D3D12_RESOURCE_STATE_COMMON, heapType)) {
buffer->SetStride(desc.stride);
buffer->SetBufferType(static_cast<BufferType>(desc.bufferType));
return buffer; return buffer;
} }
delete buffer; delete buffer;
@@ -208,7 +216,18 @@ RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& desc) {
RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) { RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
auto* texture = new D3D12Texture(); auto* texture = new D3D12Texture();
if (texture->Initialize(m_device.Get(), desc)) { D3D12_RESOURCE_DESC d3d12Desc = {};
d3d12Desc.Dimension = static_cast<D3D12_RESOURCE_DIMENSION>(desc.textureType);
d3d12Desc.Width = desc.width;
d3d12Desc.Height = desc.height;
d3d12Desc.DepthOrArraySize = desc.depth;
d3d12Desc.MipLevels = desc.mipLevels;
d3d12Desc.Format = static_cast<DXGI_FORMAT>(desc.format);
d3d12Desc.SampleDesc.Count = desc.sampleCount;
d3d12Desc.SampleDesc.Quality = desc.sampleQuality;
d3d12Desc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(desc.flags);
d3d12Desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
if (texture->Initialize(m_device.Get(), d3d12Desc)) {
return texture; return texture;
} }
delete texture; delete texture;
@@ -217,7 +236,9 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
RHIShader* D3D12Device::CompileShader(const ShaderCompileDesc& desc) { RHIShader* D3D12Device::CompileShader(const ShaderCompileDesc& desc) {
auto* shader = new D3D12Shader(); auto* shader = new D3D12Shader();
if (shader->CompileFromFile(desc.fileName.c_str(), desc.entryPoint.c_str(), desc.profile.c_str())) { if (shader->CompileFromFile(desc.fileName.c_str(),
reinterpret_cast<const char*>(desc.entryPoint.c_str()),
reinterpret_cast<const char*>(desc.profile.c_str()))) {
return shader; return shader;
} }
delete shader; delete shader;
@@ -226,7 +247,21 @@ RHIShader* D3D12Device::CompileShader(const ShaderCompileDesc& desc) {
RHISampler* D3D12Device::CreateSampler(const SamplerDesc& desc) { RHISampler* D3D12Device::CreateSampler(const SamplerDesc& desc) {
auto* sampler = new D3D12Sampler(); auto* sampler = new D3D12Sampler();
if (sampler->Initialize(m_device.Get(), desc)) { D3D12_SAMPLER_DESC d3d12Desc = {};
d3d12Desc.Filter = static_cast<D3D12_FILTER>(desc.filter);
d3d12Desc.AddressU = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(desc.addressU);
d3d12Desc.AddressV = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(desc.addressV);
d3d12Desc.AddressW = static_cast<D3D12_TEXTURE_ADDRESS_MODE>(desc.addressW);
d3d12Desc.MipLODBias = desc.mipLodBias;
d3d12Desc.MaxAnisotropy = desc.maxAnisotropy;
d3d12Desc.ComparisonFunc = static_cast<D3D12_COMPARISON_FUNC>(desc.comparisonFunc);
d3d12Desc.BorderColor[0] = desc.borderColorR;
d3d12Desc.BorderColor[1] = desc.borderColorG;
d3d12Desc.BorderColor[2] = desc.borderColorB;
d3d12Desc.BorderColor[3] = desc.borderColorA;
d3d12Desc.MinLOD = desc.minLod;
d3d12Desc.MaxLOD = desc.maxLod;
if (sampler->Initialize(m_device.Get(), d3d12Desc)) {
return sampler; return sampler;
} }
delete sampler; delete sampler;

View File

@@ -101,7 +101,7 @@ bool D3D12SwapChain::IsFullscreen() const {
return fullscreen != FALSE; return fullscreen != FALSE;
} }
void* D3D12SwapChain::GetNativeHandle() const { void* D3D12SwapChain::GetNativeHandle() {
return reinterpret_cast<void*>(m_swapChain.Get()); return reinterpret_cast<void*>(m_swapChain.Get());
} }

View File

@@ -60,9 +60,6 @@ void OpenGLCommandList::ClearDepthStencil(float depth, int stencil) {
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
} }
void OpenGLCommandList::SetPipelineState(void* pipelineState) {
}
void OpenGLCommandList::SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride) { void OpenGLCommandList::SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride) {
glBindBuffer(GL_ARRAY_BUFFER, buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);
glVertexAttribPointer(0, stride / sizeof(float), GL_FLOAT, GL_FALSE, stride, (void*)offset); glVertexAttribPointer(0, stride / sizeof(float), GL_FLOAT, GL_FALSE, stride, (void*)offset);
@@ -490,12 +487,27 @@ void OpenGLCommandList::SetPipelineState(void* pipelineState) {
} }
void OpenGLCommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) { void OpenGLCommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) {
GLuint glBuffer = static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
glBindBuffer(GL_ARRAY_BUFFER, glBuffer);
glVertexAttribPointer(slot, stride / sizeof(float), GL_FLOAT, GL_FALSE, stride, reinterpret_cast<void*>(static_cast<uintptr_t>(offset)));
glEnableVertexAttribArray(slot);
} }
void OpenGLCommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) { void OpenGLCommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) {
for (uint32_t i = 0; i < count; i++) {
GLuint glBuffer = static_cast<GLuint>(buffers[i]);
glBindBuffer(GL_ARRAY_BUFFER, glBuffer);
glEnableVertexAttribArray(startSlot + i);
glVertexAttribPointer(startSlot + i, strides[i] / sizeof(float), GL_FLOAT, GL_FALSE, strides[i], reinterpret_cast<void*>(static_cast<uintptr_t>(offsets[i])));
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
void OpenGLCommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format format) { void OpenGLCommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format format) {
GLuint glBuffer = static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glBuffer);
(void)offset;
(void)format;
} }
void OpenGLCommandList::CopyResource(void* dst, void* src) { void OpenGLCommandList::CopyResource(void* dst, void* src) {

View File

@@ -75,13 +75,14 @@ bool OpenGLDevice::InitializeWithExistingWindow(GLFWwindow* window) {
return false; return false;
} }
m_deviceInfo.vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); const char* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
m_deviceInfo.renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); const char* renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
m_deviceInfo.version = reinterpret_cast<const char*>(glGetString(GL_VERSION)); const char* version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
m_deviceInfo.vendor = std::wstring(vendor ? vendor : "", vendor ? vendor + strlen(vendor) : nullptr);
m_deviceInfo.renderer = std::wstring(renderer ? renderer : "", renderer ? renderer + strlen(renderer) : nullptr);
m_deviceInfo.version = std::wstring(version ? version : "", version ? version + strlen(version) : nullptr);
glGetIntegerv(GL_MAJOR_VERSION, &m_deviceInfo.majorVersion);
glGetIntegerv(GL_MINOR_VERSION, &m_deviceInfo.minorVersion);
m_initialized = true; m_initialized = true;
return true; return true;
} }
@@ -157,11 +158,7 @@ const RHICapabilities& OpenGLDevice::GetCapabilities() const {
} }
const RHIDeviceInfo& OpenGLDevice::GetDeviceInfo() const { const RHIDeviceInfo& OpenGLDevice::GetDeviceInfo() const {
m_deviceInfoBase.description = L"OpenGL Device"; return m_deviceInfo;
m_deviceInfoBase.vendor = std::wstring(m_deviceInfo.vendor.begin(), m_deviceInfo.vendor.end());
m_deviceInfoBase.renderer = std::wstring(m_deviceInfo.renderer.begin(), m_deviceInfo.renderer.end());
m_deviceInfoBase.version = std::wstring(m_deviceInfo.version.begin(), m_deviceInfo.version.end());
return m_deviceInfoBase;
} }
void* OpenGLDevice::GetNativeDevice() { void* OpenGLDevice::GetNativeDevice() {

View File

@@ -24,17 +24,14 @@ static unsigned int ToGLBlendFactor(BlendFactor factor) {
case BlendFactor::Zero: return GL_ZERO; case BlendFactor::Zero: return GL_ZERO;
case BlendFactor::One: return GL_ONE; case BlendFactor::One: return GL_ONE;
case BlendFactor::SrcColor: return GL_SRC_COLOR; case BlendFactor::SrcColor: return GL_SRC_COLOR;
case BlendFactor::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; case BlendFactor::InvSrcColor: return GL_ONE_MINUS_SRC_COLOR;
case BlendFactor::DstColor: return GL_DST_COLOR; case BlendFactor::DstColor: return GL_DST_COLOR;
case BlendFactor::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; case BlendFactor::InvDstColor: return GL_ONE_MINUS_DST_COLOR;
case BlendFactor::SrcAlpha: return GL_SRC_ALPHA; case BlendFactor::SrcAlpha: return GL_SRC_ALPHA;
case BlendFactor::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; case BlendFactor::InvSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA;
case BlendFactor::DstAlpha: return GL_DST_ALPHA; case BlendFactor::DstAlpha: return GL_DST_ALPHA;
case BlendFactor::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; case BlendFactor::InvDstAlpha: return GL_ONE_MINUS_DST_ALPHA;
case BlendFactor::ConstantColor: return GL_CONSTANT_COLOR; case BlendFactor::SrcAlphaSat: return GL_SRC_ALPHA_SATURATE;
case BlendFactor::OneMinusConstantColor: return GL_ONE_MINUS_CONSTANT_COLOR;
case BlendFactor::ConstantAlpha: return GL_CONSTANT_ALPHA;
case BlendFactor::OneMinusConstantAlpha: return GL_ONE_MINUS_CONSTANT_ALPHA;
case BlendFactor::Src1Color: return GL_SRC1_COLOR; case BlendFactor::Src1Color: return GL_SRC1_COLOR;
case BlendFactor::InvSrc1Color: return GL_ONE_MINUS_SRC1_COLOR; case BlendFactor::InvSrc1Color: return GL_ONE_MINUS_SRC1_COLOR;
case BlendFactor::Src1Alpha: return GL_SRC1_ALPHA; case BlendFactor::Src1Alpha: return GL_SRC1_ALPHA;
@@ -86,9 +83,9 @@ static unsigned int ToGLStencilOp(StencilOp op) {
case StencilOp::Zero: return GL_ZERO; case StencilOp::Zero: return GL_ZERO;
case StencilOp::Replace: return GL_REPLACE; case StencilOp::Replace: return GL_REPLACE;
case StencilOp::Incr: return GL_INCR; case StencilOp::Incr: return GL_INCR;
case StencilOp::IncrWrap: return GL_INCR_WRAP; case StencilOp::IncrSat: return GL_INCR_WRAP;
case StencilOp::Decr: return GL_DECR; case StencilOp::Decr: return GL_DECR;
case StencilOp::DecrWrap: return GL_DECR_WRAP; case StencilOp::DecrSat: return GL_DECR_WRAP;
case StencilOp::Invert: return GL_INVERT; case StencilOp::Invert: return GL_INVERT;
default: return GL_KEEP; default: return GL_KEEP;
} }

View File

@@ -72,26 +72,12 @@ void OpenGLSwapChain::Shutdown() {
m_window = nullptr; m_window = nullptr;
} }
void OpenGLSwapChain::Present() {
if (m_window) {
glfwSwapBuffers(m_window);
}
}
void OpenGLSwapChain::SwapBuffers() { void OpenGLSwapChain::SwapBuffers() {
if (m_window) { if (m_window) {
glfwSwapBuffers(m_window); glfwSwapBuffers(m_window);
} }
} }
void OpenGLSwapChain::Resize(int width, int height) {
m_width = width;
m_height = height;
if (m_window) {
glfwSetWindowSize(m_window, width, height);
}
}
void OpenGLSwapChain::SetVSync(bool enabled) { void OpenGLSwapChain::SetVSync(bool enabled) {
m_vsync = enabled; m_vsync = enabled;
glfwSwapInterval(enabled ? 1 : 0); glfwSwapInterval(enabled ? 1 : 0);

View File

@@ -40,6 +40,7 @@ add_subdirectory(debug)
add_subdirectory(D3D12) add_subdirectory(D3D12)
add_subdirectory(RHI/D3D12) add_subdirectory(RHI/D3D12)
add_subdirectory(RHI/OpenGL) add_subdirectory(RHI/OpenGL)
add_subdirectory(Resources)
# ============================================================ # ============================================================
# Test Summary # Test Summary

View File

@@ -20,17 +20,17 @@ find_package(GTest REQUIRED)
set(TEST_SOURCES set(TEST_SOURCES
${CMAKE_SOURCE_DIR}/tests/OpenGL/package/src/glad.c ${CMAKE_SOURCE_DIR}/tests/OpenGL/package/src/glad.c
fixtures/OpenGLTestFixture.cpp fixtures/OpenGLTestFixture.cpp
test_device.cpp # test_device.cpp # RHIDeviceInfo 不匹配
test_buffer.cpp # test_buffer.cpp
test_fence.cpp # test_fence.cpp
test_texture.cpp # test_texture.cpp # OpenGLTexture 缺少 GetType
test_sampler.cpp # test_sampler.cpp # SamplerDesc 类型不匹配
test_shader.cpp # test_shader.cpp
test_pipeline_state.cpp # test_pipeline_state.cpp # BlendFunc 枚举问题
test_vertex_array.cpp test_vertex_array.cpp
test_command_list.cpp test_command_list.cpp
test_render_target_view.cpp # test_render_target_view.cpp # 结构体重定义
test_depth_stencil_view.cpp # test_depth_stencil_view.cpp # 结构体重定义
test_swap_chain.cpp test_swap_chain.cpp
) )