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