Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Device.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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_DEVICE
19#define INCLUDED_RENDERER_BACKEND_DUMMY_DEVICE
20
21#include "ps/CStr.h"
26
27#include <cstdint>
28#include <js/TypeDecls.h>
29#include <memory>
30#include <span>
31#include <string>
32#include <vector>
33
34namespace Renderer::Backend { class IFramebuffer; }
35
36namespace Renderer
37{
38
39namespace Backend
40{
41
42namespace Dummy
43{
44
45class CDevice : public IDevice
46{
47public:
48 CDevice();
49 ~CDevice() override;
50
51 Backend GetBackend() const override { return Backend::DUMMY; }
52
53 const std::string& GetName() const override { return m_Name; }
54 const std::string& GetVersion() const override { return m_Version; }
55 const std::string& GetDriverInformation() const override { return m_DriverInformation; }
56 const std::vector<std::string>& GetExtensions() const override { return m_Extensions; }
57
58 void Report(const Script::Request& rq, JS::HandleValue settings) override;
59
60 std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override;
61
62 std::unique_ptr<ISwapChain> CreateSwapChain(
63 const char* name, SDL_Window* window,
64 int surfaceDrawableWidth, int surfaceDrawableHeight,
65 const bool vsync, std::unique_ptr<ISwapChain> oldSwapChain) override;
66
67 void WaitUntilIdle() override;
68
69 std::unique_ptr<IGraphicsPipelineState> CreateGraphicsPipelineState(
70 const SGraphicsPipelineStateDesc& pipelineStateDesc) override;
71
72 std::unique_ptr<IComputePipelineState> CreateComputePipelineState(
73 const SComputePipelineStateDesc& pipelineStateDesc) override;
74
75 std::unique_ptr<IVertexInputLayout> CreateVertexInputLayout(
76 const std::span<const SVertexAttributeFormat> attributes) override;
77
78 std::unique_ptr<ITexture> CreateTexture(
79 const char* name, const ITexture::Type type, const uint32_t usage,
80 const Format format, const uint32_t width, const uint32_t height,
81 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override;
82
83 std::unique_ptr<ITexture> CreateTexture2D(
84 const char* name, const uint32_t usage,
85 const Format format, const uint32_t width, const uint32_t height,
86 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;
87
88 std::unique_ptr<IFramebuffer> CreateFramebuffer(
89 const char* name, SColorAttachment* colorAttachment,
90 SDepthStencilAttachment* depthStencilAttachment) override;
91
92 std::unique_ptr<IBuffer> CreateBuffer(
93 const char* name, const IBuffer::Type type, const uint32_t size, const uint32_t usage) override;
94
95 std::unique_ptr<IShaderProgram> CreateShaderProgram(
96 const CStr& name, const CShaderDefines& defines) override;
97
98 bool IsTextureFormatSupported(const Format format) const override;
99
100 bool IsFramebufferFormatSupported(const Format format) const override;
101
103 const uint32_t usage, const bool depth, const bool stencil) const override;
104
105 uint32_t AllocateQuery() override;
106
107 void FreeQuery(const uint32_t handle) override;
108
109 bool IsQueryResultAvailable(const uint32_t handle) const override;
110
111 uint64_t GetQueryResult(const uint32_t handle) override;
112
113 const Capabilities& GetCapabilities() const override { return m_Capabilities; }
114
115 void CollectStatistics(StatisticsVector&) const override {}
116
117protected:
118
119 std::string m_Name;
120 std::string m_Version;
122 std::vector<std::string> m_Extensions;
123
125};
126
127} // namespace Dummy
128
129} // namespace Backend
130
131} // namespace Renderer
132
133#endif // INCLUDED_RENDERER_BACKEND_DUMMY_DEVICE
struct SDL_Window SDL_Window
Definition: VideoMode.h:31
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:153
Definition: Device.h:46
void FreeQuery(const uint32_t handle) override
Definition: Device.cpp:164
std::unique_ptr< IDeviceCommandContext > CreateCommandContext() override
Definition: Device.cpp:72
Capabilities m_Capabilities
Definition: Device.h:124
std::unique_ptr< ITexture > CreateTexture2D(const char *name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc &defaultSamplerDesc, const uint32_t MIPLevelCount=1, const uint32_t sampleCount=1) override
Definition: Device.cpp:116
bool IsTextureFormatSupported(const Format format) const override
Definition: Device.cpp:143
const std::string & GetVersion() const override
Definition: Device.h:54
void WaitUntilIdle() override
Waits until all submitted work (via DeviceCommandContext::Flush) to backend is completed and it's saf...
Definition: Device.cpp:85
Format GetPreferredDepthStencilFormat(const uint32_t usage, const bool depth, const bool stencil) const override
Returns the most suitable format for the usage.
Definition: Device.cpp:153
std::unique_ptr< IVertexInputLayout > CreateVertexInputLayout(const std::span< const SVertexAttributeFormat > attributes) override
Creates a vertex input layout.
Definition: Device.cpp:101
std::vector< std::string > m_Extensions
Definition: Device.h:122
void Report(const Script::Request &rq, JS::HandleValue settings) override
Definition: Device.cpp:67
std::string m_Name
Definition: Device.h:119
uint32_t AllocateQuery() override
Definition: Device.cpp:159
const std::vector< std::string > & GetExtensions() const override
Definition: Device.h:56
std::unique_ptr< IShaderProgram > CreateShaderProgram(const CStr &name, const CShaderDefines &defines) override
Definition: Device.cpp:137
std::unique_ptr< ITexture > CreateTexture(const char *name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc &defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override
Definition: Device.cpp:107
bool IsFramebufferFormatSupported(const Format format) const override
Definition: Device.cpp:148
Backend GetBackend() const override
Definition: Device.h:51
uint64_t GetQueryResult(const uint32_t handle) override
After a call of the function the query result becomes invalid.
Definition: Device.cpp:173
std::string m_Version
Definition: Device.h:120
const std::string & GetDriverInformation() const override
Definition: Device.h:55
std::string m_DriverInformation
Definition: Device.h:121
std::unique_ptr< IBuffer > CreateBuffer(const char *name, const IBuffer::Type type, const uint32_t size, const uint32_t usage) override
Definition: Device.cpp:131
void CollectStatistics(StatisticsVector &) const override
Definition: Device.h:115
std::unique_ptr< IGraphicsPipelineState > CreateGraphicsPipelineState(const SGraphicsPipelineStateDesc &pipelineStateDesc) override
Creates a graphics pipeline state.
Definition: Device.cpp:89
std::unique_ptr< IComputePipelineState > CreateComputePipelineState(const SComputePipelineStateDesc &pipelineStateDesc) override
Creates a compute pipeline state.
Definition: Device.cpp:95
const std::string & GetName() const override
Definition: Device.h:53
bool IsQueryResultAvailable(const uint32_t handle) const override
Definition: Device.cpp:168
std::unique_ptr< ISwapChain > CreateSwapChain(const char *name, SDL_Window *window, int surfaceDrawableWidth, int surfaceDrawableHeight, const bool vsync, std::unique_ptr< ISwapChain > oldSwapChain) override
To be able to present something on a window it needs to create swapchain which provides framebuffer t...
Definition: Device.cpp:77
const Capabilities & GetCapabilities() const override
Definition: Device.h:113
CDevice()
Definition: Device.cpp:46
std::unique_ptr< IFramebuffer > CreateFramebuffer(const char *name, SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment) override
Definition: Device.cpp:125
Type
Definition: IBuffer.h:35
Definition: IDevice.h:64
std::vector< StatisticsItem > StatisticsVector
Definition: IDevice.h:228
Type
Definition: ITexture.h:36
Definition: Request.h:51
Definition: Canvas2D.h:30
Format
Definition: Format.h:28
Backend
Definition: Backend.h:28
Definition: Canvas2D.h:30
Definition: IFramebuffer.h:62
Definition: PipelineState.h:177
Definition: IFramebuffer.h:70
Definition: PipelineState.h:167
Definition: Sampler.h:54