- 在RHICommandList.h中添加7个RHIResourceView*方法重载: - TransitionBarrier(RHIResourceView*, ...) - SetRenderTargets(count, RHIResourceView**, RHIResourceView*) - SetVertexBuffer(slot, RHIResourceView*, ...) - SetIndexBuffer(RHIResourceView*, ...) - ClearRenderTarget(RHIResourceView*, ...) - ClearDepthStencil(RHIResourceView*, ...) - CopyResource(RHIResourceView*, RHIResourceView*) - D3D12CommandList完整实现: - 通过D3D12ResourceView::GetResource()获取底层资源 - 通过D3D12ResourceView::GetCPUHandle()获取RTV/DSV句柄 - OpenGLCommandList添加stub实现保持接口一致 - 验证: 144个单元测试全部通过, 4个D3D12集成测试全部通过
190 lines
9.5 KiB
C++
190 lines
9.5 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
#include "../RHICommandList.h"
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
class OpenGLBuffer;
|
|
class OpenGLVertexArray;
|
|
class OpenGLShader;
|
|
class OpenGLTexture;
|
|
|
|
enum class PrimitiveType {
|
|
Points,
|
|
Lines,
|
|
LineStrip,
|
|
Triangles,
|
|
TriangleStrip,
|
|
TriangleFan,
|
|
LineListAdj,
|
|
TriangleListAdj,
|
|
Patch
|
|
};
|
|
|
|
enum class ClearFlag {
|
|
Color = 1,
|
|
Depth = 2,
|
|
Stencil = 4
|
|
};
|
|
|
|
inline ClearFlag operator|(ClearFlag a, ClearFlag b) {
|
|
return static_cast<ClearFlag>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b));
|
|
}
|
|
|
|
class OpenGLCommandList : public RHICommandList {
|
|
public:
|
|
OpenGLCommandList();
|
|
~OpenGLCommandList() override;
|
|
|
|
void Shutdown() override;
|
|
|
|
void Reset() override;
|
|
void Close() override;
|
|
|
|
void Clear(float r, float g, float b, float a, unsigned int buffers) override;
|
|
void ClearColor(float r, float g, float b, float a);
|
|
void ClearDepth(float depth);
|
|
void ClearStencil(int stencil);
|
|
void ClearDepthStencil(float depth, int stencil);
|
|
|
|
void SetPipelineState(void* pipelineState) override;
|
|
void SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) override;
|
|
void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) 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(RHIResourceView* 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, unsigned int indexBuffer, unsigned int indexType);
|
|
void UseShader(unsigned int program);
|
|
|
|
void SetViewport(int x, int y, int width, int height);
|
|
void SetViewport(float x, float y, float width, float height, float minDepth, float maxDepth);
|
|
void SetViewports(unsigned int count, const float* viewports);
|
|
void SetScissor(int x, int y, int width, int height);
|
|
void SetScissorRects(unsigned int count, const int* rects);
|
|
void EnableScissorTest(bool enable);
|
|
|
|
void EnableDepthTest(bool enable);
|
|
void EnableDepthWrite(bool enable);
|
|
void SetDepthFunc(unsigned int func);
|
|
void EnableStencilTest(bool enable);
|
|
void SetStencilFunc(unsigned int func, int ref, unsigned int mask);
|
|
void SetStencilOp(unsigned int fail, unsigned int zfail, unsigned int zpass);
|
|
void EnableBlending(bool enable);
|
|
void SetBlendFunc(unsigned int src, unsigned int dst);
|
|
void SetBlendFuncSeparate(unsigned int srcRGB, unsigned int dstRGB, unsigned int srcAlpha, unsigned int dstAlpha);
|
|
void SetBlendEquation(unsigned int mode);
|
|
void SetBlendColor(float r, float g, float b, float a);
|
|
|
|
void EnableCulling(bool enable);
|
|
void SetCullFace(unsigned int face);
|
|
void SetFrontFace(unsigned int face);
|
|
void SetPolygonMode(unsigned int mode);
|
|
void SetPolygonOffset(float factor, float units);
|
|
|
|
void SetPrimitiveType(PrimitiveType type);
|
|
|
|
void Draw(PrimitiveType type, unsigned int vertexCount, unsigned int startVertex);
|
|
void DrawInstanced(PrimitiveType type, unsigned int vertexCount, unsigned int instanceCount, unsigned int startVertex, unsigned int startInstance);
|
|
void DrawIndexed(PrimitiveType type, unsigned int indexCount, unsigned int startIndex, int baseVertex);
|
|
void DrawIndexedInstanced(PrimitiveType type, unsigned int indexCount, unsigned int instanceCount, unsigned int startIndex, int baseVertex, unsigned int startInstance);
|
|
void DrawIndirect(PrimitiveType type, unsigned int buffer, size_t offset, unsigned int drawCount, unsigned int stride);
|
|
void DrawIndexedIndirect(PrimitiveType type, unsigned int buffer, size_t offset, unsigned int drawCount, unsigned int stride);
|
|
|
|
void MultiDrawArrays(PrimitiveType type, const int* first, const int* count, unsigned int drawCount);
|
|
void MultiDrawElements(PrimitiveType type, const int* count, unsigned int type_, const void* const* indices, unsigned int drawCount);
|
|
|
|
void Dispatch(uint32_t x, uint32_t y, uint32_t z) override;
|
|
void DispatchIndirect(unsigned int buffer, size_t offset);
|
|
void DispatchCompute(unsigned int x, unsigned int y, unsigned int z, unsigned int groupX, unsigned int groupY, unsigned int groupZ);
|
|
|
|
void MemoryBarrier(unsigned int barriers);
|
|
void TextureBarrier();
|
|
|
|
void BindTexture(unsigned int target, unsigned int unit, unsigned int texture);
|
|
void BindTextures(unsigned int first, unsigned int count, const unsigned int* textures);
|
|
void BindSampler(unsigned int unit, unsigned int sampler);
|
|
void BindSamplers(unsigned int first, unsigned int count, const unsigned int* samplers);
|
|
void BindImageTexture(unsigned int unit, unsigned int texture, int level, bool layered, int layer, unsigned int access, unsigned int format);
|
|
|
|
void BindBufferBase(unsigned int target, unsigned int index, unsigned int buffer);
|
|
void BindBufferRange(unsigned int target, unsigned int index, unsigned int buffer, size_t offset, size_t size);
|
|
|
|
void Enable(unsigned int cap);
|
|
void Disable(unsigned int cap);
|
|
void Enablei(unsigned int cap, unsigned int index);
|
|
void Disablei(unsigned int cap, unsigned int index);
|
|
|
|
void SetUniform1i(int location, int v);
|
|
void SetUniform1f(int location, float v);
|
|
void SetUniform2f(int location, float x, float y);
|
|
void SetUniform3f(int location, float x, float y, float z);
|
|
void SetUniform4f(int location, float x, float y, float z, float w);
|
|
void SetUniform1fv(int location, int count, const float* v);
|
|
void SetUniform2fv(int location, int count, const float* v);
|
|
void SetUniform3fv(int location, int count, const float* v);
|
|
void SetUniform4fv(int location, int count, const float* v);
|
|
void SetUniformMatrix4fv(int location, int count, bool transpose, const float* v);
|
|
|
|
void UseProgram(unsigned int program);
|
|
void BindFragDataLocation(unsigned int program, unsigned int colorNumber, const char* name);
|
|
void BindFragDataLocationIndexed(unsigned int program, unsigned int colorNumber, unsigned int index, const char* name);
|
|
|
|
void BeginQuery(unsigned int target, unsigned int id);
|
|
void EndQuery(unsigned int target);
|
|
void GetQueryObjectiv(unsigned int id, unsigned int pname, int* params);
|
|
void GetQueryObjectuiv(unsigned int id, unsigned int pname, unsigned int* params);
|
|
|
|
void ReadPixels(int x, int y, int width, int height, unsigned int format, unsigned int type, void* data);
|
|
void BlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, unsigned int mask, unsigned int filter);
|
|
|
|
void CopyImageSubData(unsigned int srcName, unsigned int srcTarget, int srcLevel, int srcX, int srcY, int srcZ, unsigned int dstName, unsigned int dstTarget, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth);
|
|
void CopyResource(void* dst, void* src) override;
|
|
void CopyResource(RHIResourceView* dst, RHIResourceView* src) override;
|
|
|
|
void InvalidateFramebuffer(unsigned int target, unsigned int count, const unsigned int* attachments);
|
|
void InvalidateSubFramebuffer(unsigned int target, unsigned int count, const unsigned int* attachments, int x, int y, int width, int height);
|
|
|
|
void PushDebugGroup(unsigned int source, unsigned int id, int length, const char* message);
|
|
void PopDebugGroup();
|
|
|
|
void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
|
void TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
|
void SetPrimitiveTopology(PrimitiveTopology topology) override;
|
|
void SetViewport(const Viewport& viewport) override;
|
|
void SetViewports(uint32_t count, const Viewport* viewports) override;
|
|
void SetScissorRect(const Rect& rect) override;
|
|
void SetScissorRects(uint32_t count, const Rect* rects) override;
|
|
void SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil = nullptr) override;
|
|
void SetRenderTargets(uint32_t count, RHIResourceView** renderTargets, RHIResourceView* depthStencil = nullptr) override;
|
|
void SetDepthStencilState(const DepthStencilState& state) override;
|
|
void SetStencilRef(uint8_t ref) override;
|
|
void SetBlendState(const BlendState& state) override;
|
|
void SetBlendFactor(const float factor[4]) override;
|
|
void ClearRenderTarget(void* renderTarget, const float color[4]) override;
|
|
void ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) override;
|
|
void ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) override;
|
|
void ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) override;
|
|
void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t startVertex, uint32_t startInstance) override;
|
|
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t startIndex, int32_t baseVertex, uint32_t startInstance) override;
|
|
|
|
private:
|
|
unsigned int m_primitiveType;
|
|
unsigned int m_currentVAO;
|
|
unsigned int m_currentProgram;
|
|
};
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|