Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Device.h
Go to the documentation of this file.
1/* Copyright (C) 2024 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
23
24#include <memory>
25#include <string>
26#include <vector>
27
28class CShaderDefines;
29
30namespace Renderer
31{
32
33namespace Backend
34{
35
36namespace Dummy
37{
38
39class CDeviceCommandContext;
40
41class CDevice : public IDevice
42{
43public:
44 CDevice();
45 ~CDevice() override;
46
47 Backend GetBackend() const override { return Backend::DUMMY; }
48
49 const std::string& GetName() const override { return m_Name; }
50 const std::string& GetVersion() const override { return m_Version; }
51 const std::string& GetDriverInformation() const override { return m_DriverInformation; }
52 const std::vector<std::string>& GetExtensions() const override { return m_Extensions; }
53
54 void Report(const ScriptRequest& rq, JS::HandleValue settings) override;
55
56 std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override;
57
58 std::unique_ptr<IGraphicsPipelineState> CreateGraphicsPipelineState(
59 const SGraphicsPipelineStateDesc& pipelineStateDesc) override;
60
61 std::unique_ptr<IComputePipelineState> CreateComputePipelineState(
62 const SComputePipelineStateDesc& pipelineStateDesc) override;
63
64 std::unique_ptr<IVertexInputLayout> CreateVertexInputLayout(
65 const PS::span<const SVertexAttributeFormat> attributes) override;
66
67 std::unique_ptr<ITexture> CreateTexture(
68 const char* name, const ITexture::Type type, const uint32_t usage,
69 const Format format, const uint32_t width, const uint32_t height,
70 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override;
71
72 std::unique_ptr<ITexture> CreateTexture2D(
73 const char* name, const uint32_t usage,
74 const Format format, const uint32_t width, const uint32_t height,
75 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override;
76
77 std::unique_ptr<IFramebuffer> CreateFramebuffer(
78 const char* name, SColorAttachment* colorAttachment,
79 SDepthStencilAttachment* depthStencilAttachment) override;
80
81 std::unique_ptr<IBuffer> CreateBuffer(
82 const char* name, const IBuffer::Type type, const uint32_t size, const uint32_t usage) override;
83
84 std::unique_ptr<IShaderProgram> CreateShaderProgram(
85 const CStr& name, const CShaderDefines& defines) override;
86
87 bool AcquireNextBackbuffer() override;
88
91 const AttachmentLoadOp, const AttachmentStoreOp) override;
92
93 void Present() override;
94
95 void OnWindowResize(const uint32_t width, const uint32_t height) override;
96
97 bool IsTextureFormatSupported(const Format format) const override;
98
99 bool IsFramebufferFormatSupported(const Format format) const override;
100
102 const uint32_t usage, const bool depth, const bool stencil) const override;
103
104 const Capabilities& GetCapabilities() const override { return m_Capabilities; }
105
106protected:
107
108 std::string m_Name;
109 std::string m_Version;
111 std::vector<std::string> m_Extensions;
112
113 std::unique_ptr<IFramebuffer> m_Backbuffer;
114
116};
117
118} // namespace Dummy
119
120} // namespace Backend
121
122} // namespace Renderer
123
124#endif // INCLUDED_RENDERER_BACKEND_DUMMY_DEVICE
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:147
Simplifed version of std::span (C++20) as we don't support the original one yet.
Definition: Span.h:37
Definition: Device.h:42
std::unique_ptr< IDeviceCommandContext > CreateCommandContext() override
Definition: Device.cpp:72
Capabilities m_Capabilities
Definition: Device.h:115
void OnWindowResize(const uint32_t width, const uint32_t height) override
Should be called on window surface resize.
Definition: Device.cpp:148
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:103
bool IsTextureFormatSupported(const Format format) const override
Definition: Device.cpp:152
const std::string & GetVersion() const override
Definition: Device.h:50
IFramebuffer * GetCurrentBackbuffer(const AttachmentLoadOp, const AttachmentStoreOp, const AttachmentLoadOp, const AttachmentStoreOp) override
Returns a framebuffer for the current backbuffer with the required attachment operations.
Definition: Device.cpp:136
std::unique_ptr< IFramebuffer > m_Backbuffer
Definition: Device.h:113
std::unique_ptr< IVertexInputLayout > CreateVertexInputLayout(const PS::span< const SVertexAttributeFormat > attributes) override
Creates a vertex input layout.
Definition: Device.cpp:89
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:162
std::vector< std::string > m_Extensions
Definition: Device.h:111
void Present() override
Presents the backbuffer to the swapchain queue to be flipped on a screen.
Definition: Device.cpp:143
std::string m_Name
Definition: Device.h:108
const std::vector< std::string > & GetExtensions() const override
Definition: Device.h:52
std::unique_ptr< IShaderProgram > CreateShaderProgram(const CStr &name, const CShaderDefines &defines) override
Definition: Device.cpp:124
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:95
bool IsFramebufferFormatSupported(const Format format) const override
Definition: Device.cpp:157
Backend GetBackend() const override
Definition: Device.h:47
std::string m_Version
Definition: Device.h:109
const std::string & GetDriverInformation() const override
Definition: Device.h:51
std::string m_DriverInformation
Definition: Device.h:110
std::unique_ptr< IBuffer > CreateBuffer(const char *name, const IBuffer::Type type, const uint32_t size, const uint32_t usage) override
Definition: Device.cpp:118
std::unique_ptr< IGraphicsPipelineState > CreateGraphicsPipelineState(const SGraphicsPipelineStateDesc &pipelineStateDesc) override
Creates a graphics pipeline state.
Definition: Device.cpp:77
std::unique_ptr< IComputePipelineState > CreateComputePipelineState(const SComputePipelineStateDesc &pipelineStateDesc) override
Creates a compute pipeline state.
Definition: Device.cpp:83
const std::string & GetName() const override
Definition: Device.h:49
const Capabilities & GetCapabilities() const override
Definition: Device.h:104
bool AcquireNextBackbuffer() override
Acquires a backbuffer for rendering a frame.
Definition: Device.cpp:130
CDevice()
Definition: Device.cpp:42
void Report(const ScriptRequest &rq, JS::HandleValue settings) override
Definition: Device.cpp:67
std::unique_ptr< IFramebuffer > CreateFramebuffer(const char *name, SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment) override
Definition: Device.cpp:112
Type
Definition: IBuffer.h:35
Definition: IDevice.h:48
IFramebuffer stores attachments which should be used by backend as rendering destinations.
Definition: IFramebuffer.h:85
Type
Definition: ITexture.h:37
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:60
Format
Definition: Format.h:28
AttachmentStoreOp
Store operation is set for each attachment, what should be done with its content on EndFramebufferPas...
Definition: IFramebuffer.h:52
Backend
Definition: Backend.h:28
AttachmentLoadOp
Load operation is set for each attachment, what should be done with its content on BeginFramebufferPa...
Definition: IFramebuffer.h:37
Definition: VideoMode.h:29
Definition: IFramebuffer.h:60
Definition: PipelineState.h:175
Definition: IFramebuffer.h:68
Definition: PipelineState.h:165
Definition: Sampler.h:57
unsigned int uint32_t
Definition: wposix_types.h:53