Pyrogenesis  trunk
DeviceCommandContext.h
Go to the documentation of this file.
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 
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 
43 {
44 public:
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;
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 
82  IVertexInputLayout* vertexInputLayout) override;
83 
84  void SetVertexBuffer(
85  const uint32_t bindingSlot, IBuffer* buffer, const uint32_t offset) override;
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;
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 
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
void DrawIndexedInRange(const uint32_t firstIndex, const uint32_t indexCount, const uint32_t start, const uint32_t end) override
Definition: DeviceCommandContext.cpp:178
void UploadTexture(ITexture *texture, const Format dataFormat, const void *data, const size_t dataSize, const uint32_t level=0, const uint32_t layer=0) override
Definition: DeviceCommandContext.cpp:59
void DrawInstanced(const uint32_t firstVertex, const uint32_t vertexCount, const uint32_t firstInstance, const uint32_t instanceCount) override
Definition: DeviceCommandContext.cpp:168
Definition: IBuffer.h:31
void SetScissors(const uint32_t scissorCount, const Rect *scissors) override
Definition: DeviceCommandContext.cpp:123
void DrawIndexed(const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) override
Definition: DeviceCommandContext.cpp:164
void SetIndexBufferData(const void *data, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:148
std::function< void(u8 *)> UploadBufferFunction
Definition: DeviceCommandContext.h:69
Definition: ITexture.h:33
void SetIndexBuffer(IBuffer *buffer) override
Definition: DeviceCommandContext.cpp:144
IVertexInputLayout stores precompiled list of vertex attributes.
Definition: IShaderProgram.h:73
static std::unique_ptr< CDeviceCommandContext > Create(CDevice *device)
Definition: DeviceCommandContext.cpp:38
void BeginFramebufferPass(IFramebuffer *framebuffer) override
Starts a framebuffer pass, performs attachment load operations.
Definition: DeviceCommandContext.cpp:110
void Flush() override
Definition: DeviceCommandContext.cpp:98
void SetVertexBuffer(const uint32_t bindingSlot, IBuffer *buffer, const uint32_t offset) override
Definition: DeviceCommandContext.cpp:135
void UploadBufferRegion(IBuffer *buffer, const void *data, const uint32_t dataOffset, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:80
void SetUniform(const int32_t bindingSlot, const float value) override
Definition: DeviceCommandContext.cpp:187
void DrawIndexedInstanced(const uint32_t firstIndex, const uint32_t indexCount, const uint32_t firstInstance, const uint32_t instanceCount, const int32_t vertexOffset) override
Definition: DeviceCommandContext.cpp:173
void BeginScopedLabel(const char *name) override
Definition: DeviceCommandContext.cpp:90
Format
Definition: Format.h:27
void Draw(const uint32_t firstVertex, const uint32_t vertexCount) override
Definition: DeviceCommandContext.cpp:160
void SetGraphicsPipelineState(IGraphicsPipelineState *pipelineState) override
Binds the graphics pipeline state.
Definition: DeviceCommandContext.cpp:54
IDevice * GetDevice() override
Definition: DeviceCommandContext.cpp:49
void EndPass() override
Definition: DeviceCommandContext.cpp:156
Definition: IDevice.h:47
Definition: Device.h:41
Represents a texture object.
Definition: TextureManager.h:256
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:190
Backend
Definition: Backend.h:27
void SetTexture(const int32_t bindingSlot, ITexture *texture) override
Definition: DeviceCommandContext.cpp:183
void EndFramebufferPass() override
Finishes a framebuffer pass, performs attachment store operations.
Definition: DeviceCommandContext.cpp:114
void UploadBuffer(IBuffer *buffer, const void *data, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:72
void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override
Clears all mentioned attachments.
Definition: DeviceCommandContext.cpp:106
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
Definition: IDeviceCommandContext.h:94
void BlitFramebuffer(IFramebuffer *destinationFramebuffer, IFramebuffer *sourceFramebuffer) override
Definition: DeviceCommandContext.cpp:102
CDevice * m_Device
Definition: DeviceCommandContext.h:140
A wrapper for backend shader program to handle high-level operations like file reloading and handling...
Definition: ShaderProgram.h:33
void SetVertexBufferData(const uint32_t bindingSlot, const void *data, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:139
void BeginPass() override
Definition: DeviceCommandContext.cpp:152
Definition: IDeviceCommandContext.h:40
IFramebuffer stores attachments which should be used by backend as rendering destinations.
Definition: IFramebuffer.h:84
void SetViewports(const uint32_t viewportCount, const Rect *viewports) override
Definition: DeviceCommandContext.cpp:127
void UploadTextureRegion(ITexture *texture, const Format dataFormat, const void *data, const size_t dataSize, const uint32_t xOffset, const uint32_t yOffset, const uint32_t width, const uint32_t height, const uint32_t level=0, const uint32_t layer=0) override
Definition: DeviceCommandContext.cpp:65
void EndScopedLabel() override
Definition: DeviceCommandContext.cpp:94
void SetVertexInputLayout(IVertexInputLayout *vertexInputLayout) override
Binds the vertex input layout.
Definition: DeviceCommandContext.cpp:131
void ReadbackFramebufferSync(const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height, void *data) override
Definition: DeviceCommandContext.cpp:118
Simplifed version of std::span (C++20) as we don&#39;t support the original one yet.
Definition: Span.h:36
Definition: DeviceCommandContext.h:42