Line data Source code
1 : /* Copyright (C) 2023 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
4 : * 0 A.D. is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 2 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * 0 A.D. is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #ifndef INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT
19 : #define INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT
20 :
21 : #include "renderer/backend/Format.h"
22 : #include "renderer/backend/IDeviceCommandContext.h"
23 : #include "renderer/backend/PipelineState.h"
24 :
25 : #include <memory>
26 :
27 : namespace Renderer
28 : {
29 :
30 : namespace Backend
31 : {
32 :
33 : namespace Dummy
34 : {
35 :
36 : class CDevice;
37 : class CBuffer;
38 : class CFramebuffer;
39 : class CShaderProgram;
40 : class CTexture;
41 :
42 18 : class CDeviceCommandContext : public IDeviceCommandContext
43 : {
44 : public:
45 : ~CDeviceCommandContext();
46 :
47 : IDevice* GetDevice() override;
48 :
49 : void SetGraphicsPipelineState(IGraphicsPipelineState* pipelineState) override;
50 :
51 : void BlitFramebuffer(IFramebuffer* destinationFramebuffer, IFramebuffer* sourceFramebuffer) override;
52 :
53 : void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override;
54 : void BeginFramebufferPass(IFramebuffer* framebuffer) override;
55 : void EndFramebufferPass() override;
56 : void ReadbackFramebufferSync(
57 : const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height,
58 : void* data) override;
59 :
60 : void UploadTexture(ITexture* texture, const Format dataFormat,
61 : const void* data, const size_t dataSize,
62 : const uint32_t level = 0, const uint32_t layer = 0) override;
63 : void UploadTextureRegion(ITexture* texture, const Format dataFormat,
64 : const void* data, const size_t dataSize,
65 : const uint32_t xOffset, const uint32_t yOffset,
66 : const uint32_t width, const uint32_t height,
67 : const uint32_t level = 0, const uint32_t layer = 0) override;
68 :
69 : using UploadBufferFunction = std::function<void(u8*)>;
70 : void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) override;
71 : void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) override;
72 : void UploadBufferRegion(
73 : IBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) override;
74 : void UploadBufferRegion(
75 : IBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize,
76 : const UploadBufferFunction& uploadFunction) override;
77 :
78 : void SetScissors(const uint32_t scissorCount, const Rect* scissors) override;
79 : void SetViewports(const uint32_t viewportCount, const Rect* viewports) override;
80 :
81 : void SetVertexInputLayout(
82 : IVertexInputLayout* vertexInputLayout) override;
83 :
84 : void SetVertexBuffer(
85 : const uint32_t bindingSlot, IBuffer* buffer, const uint32_t offset) override;
86 : void SetVertexBufferData(
87 : const uint32_t bindingSlot, const void* data, const uint32_t dataSize) override;
88 :
89 : void SetIndexBuffer(IBuffer* buffer) override;
90 : void SetIndexBufferData(const void* data, const uint32_t dataSize) override;
91 :
92 : void BeginPass() override;
93 : void EndPass() override;
94 :
95 : void Draw(const uint32_t firstVertex, const uint32_t vertexCount) override;
96 : void DrawIndexed(
97 : const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) override;
98 : void DrawInstanced(
99 : const uint32_t firstVertex, const uint32_t vertexCount,
100 : const uint32_t firstInstance, const uint32_t instanceCount) override;
101 : void DrawIndexedInstanced(
102 : const uint32_t firstIndex, const uint32_t indexCount,
103 : const uint32_t firstInstance, const uint32_t instanceCount,
104 : const int32_t vertexOffset) override;
105 : void DrawIndexedInRange(
106 : const uint32_t firstIndex, const uint32_t indexCount,
107 : const uint32_t start, const uint32_t end) override;
108 :
109 : void SetTexture(const int32_t bindingSlot, ITexture* texture) override;
110 :
111 : void SetUniform(
112 : const int32_t bindingSlot,
113 : const float value) override;
114 : void SetUniform(
115 : const int32_t bindingSlot,
116 : const float valueX, const float valueY) override;
117 : void SetUniform(
118 : const int32_t bindingSlot,
119 : const float valueX, const float valueY,
120 : const float valueZ) override;
121 : void SetUniform(
122 : const int32_t bindingSlot,
123 : const float valueX, const float valueY,
124 : const float valueZ, const float valueW) override;
125 : void SetUniform(
126 : const int32_t bindingSlot, PS::span<const float> values) override;
127 :
128 : void BeginScopedLabel(const char* name) override;
129 : void EndScopedLabel() override;
130 :
131 : void Flush() override;
132 :
133 : private:
134 : friend class CDevice;
135 :
136 : static std::unique_ptr<CDeviceCommandContext> Create(CDevice* device);
137 :
138 : CDeviceCommandContext();
139 :
140 : CDevice* m_Device = nullptr;
141 : };
142 :
143 : } // namespace Dummy
144 :
145 : } // namespace Backend
146 :
147 : } // namespace Renderer
148 :
149 : #endif // INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT
|