Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
IDevice.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_IDEVICE
19#define INCLUDED_RENDERER_BACKEND_IDEVICE
20
21#include "graphics/Color.h"
22#include "ps/containers/Span.h"
33
34#include <memory>
35#include <string>
36#include <vector>
37
38class CShaderDefines;
39class CStr;
40
41namespace Renderer
42{
43
44namespace Backend
45{
46
48{
49public:
51 {
52 bool S3TC;
64 };
65
66 virtual ~IDevice() {}
67
68 virtual Backend GetBackend() const = 0;
69
70 virtual const std::string& GetName() const = 0;
71 virtual const std::string& GetVersion() const = 0;
72 virtual const std::string& GetDriverInformation() const = 0;
73 virtual const std::vector<std::string>& GetExtensions() const = 0;
74
75 virtual void Report(const ScriptRequest& rq, JS::HandleValue settings) = 0;
76
77 virtual std::unique_ptr<IDeviceCommandContext> CreateCommandContext() = 0;
78
79 /**
80 * Creates a graphics pipeline state. It's a caller responsibility to
81 * guarantee a lifespan of IShaderProgram stored in the description.
82 */
83 virtual std::unique_ptr<IGraphicsPipelineState> CreateGraphicsPipelineState(
84 const SGraphicsPipelineStateDesc& pipelineStateDesc) = 0;
85
86 /**
87 * Creates a compute pipeline state. It's a caller responsibility to
88 * guarantee a lifespan of IShaderProgram stored in the description.
89 */
90 virtual std::unique_ptr<IComputePipelineState> CreateComputePipelineState(
91 const SComputePipelineStateDesc& pipelineStateDesc) = 0;
92
93 /**
94 * Creates a vertex input layout. It's recommended to use as few different
95 * layouts as posible.
96 */
97 virtual std::unique_ptr<IVertexInputLayout> CreateVertexInputLayout(
98 const PS::span<const SVertexAttributeFormat> attributes) = 0;
99
100 virtual std::unique_ptr<ITexture> CreateTexture(
101 const char* name, const ITexture::Type type, const uint32_t usage,
102 const Format format, const uint32_t width, const uint32_t height,
103 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) = 0;
104
105 virtual std::unique_ptr<ITexture> CreateTexture2D(
106 const char* name, const uint32_t usage,
107 const Format format, const uint32_t width, const uint32_t height,
108 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) = 0;
109
110 /**
111 * @see IFramebuffer
112 *
113 * The color attachment and the depth-stencil attachment should not be
114 * nullptr at the same time. There should not be many different clear
115 * colors along all color attachments for all framebuffers created for
116 * the device.
117 *
118 * @return A valid framebuffer if it was created successfully else nullptr.
119 */
120 virtual std::unique_ptr<IFramebuffer> CreateFramebuffer(
121 const char* name, SColorAttachment* colorAttachment,
122 SDepthStencilAttachment* depthStencilAttachment) = 0;
123
124 virtual std::unique_ptr<IBuffer> CreateBuffer(
125 const char* name, const IBuffer::Type type, const uint32_t size, const uint32_t usage) = 0;
126
127 virtual std::unique_ptr<IShaderProgram> CreateShaderProgram(
128 const CStr& name, const CShaderDefines& defines) = 0;
129
130 /**
131 * Acquires a backbuffer for rendering a frame.
132 *
133 * @return True if it was successfully acquired and we can render to it.
134 */
135 virtual bool AcquireNextBackbuffer() = 0;
136
137 /**
138 * Returns a framebuffer for the current backbuffer with the required
139 * attachment operations. It should not be called if the last
140 * AcquireNextBackbuffer call returned false.
141 *
142 * It's guaranteed that for the same acquired backbuffer this function returns
143 * a framebuffer with the same attachments and properties except load and
144 * store operations.
145 *
146 * @return The last successfully acquired framebuffer that wasn't
147 * presented.
148 */
150 const AttachmentLoadOp colorAttachmentLoadOp,
151 const AttachmentStoreOp colorAttachmentStoreOp,
152 const AttachmentLoadOp depthStencilAttachmentLoadOp,
153 const AttachmentStoreOp depthStencilAttachmentStoreOp) = 0;
154
155 /**
156 * Presents the backbuffer to the swapchain queue to be flipped on a
157 * screen. Should be called only if the last AcquireNextBackbuffer call
158 * returned true.
159 */
160 virtual void Present() = 0;
161
162 /**
163 * Should be called on window surface resize. It's the device owner
164 * responsibility to call that function. Shouldn't be called during
165 * rendering to an acquired backbuffer.
166 */
167 virtual void OnWindowResize(const uint32_t width, const uint32_t height) = 0;
168
169 virtual bool IsTextureFormatSupported(const Format format) const = 0;
170
171 virtual bool IsFramebufferFormatSupported(const Format format) const = 0;
172
173 /**
174 * Returns the most suitable format for the usage. Returns
175 * Format::UNDEFINED if there is no such format.
176 */
178 const uint32_t usage, const bool depth, const bool stencil) const = 0;
179
180 virtual const Capabilities& GetCapabilities() const = 0;
181};
182
183} // namespace Backend
184
185} // namespace Renderer
186
187#endif // INCLUDED_RENDERER_BACKEND_IDEVICE
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
Type
Definition: IBuffer.h:35
Definition: IDevice.h:48
virtual Backend GetBackend() const =0
virtual const std::string & GetName() const =0
virtual const std::vector< std::string > & GetExtensions() const =0
virtual std::unique_ptr< IComputePipelineState > CreateComputePipelineState(const SComputePipelineStateDesc &pipelineStateDesc)=0
Creates a compute pipeline state.
virtual void OnWindowResize(const uint32_t width, const uint32_t height)=0
Should be called on window surface resize.
virtual Format GetPreferredDepthStencilFormat(const uint32_t usage, const bool depth, const bool stencil) const =0
Returns the most suitable format for the usage.
virtual std::unique_ptr< IDeviceCommandContext > CreateCommandContext()=0
virtual const Capabilities & GetCapabilities() const =0
virtual ~IDevice()
Definition: IDevice.h:66
virtual bool AcquireNextBackbuffer()=0
Acquires a backbuffer for rendering a frame.
virtual bool IsFramebufferFormatSupported(const Format format) const =0
virtual const std::string & GetVersion() const =0
virtual std::unique_ptr< IFramebuffer > CreateFramebuffer(const char *name, SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment)=0
virtual const std::string & GetDriverInformation() const =0
virtual bool IsTextureFormatSupported(const Format format) const =0
virtual 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)=0
virtual 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)=0
virtual std::unique_ptr< IGraphicsPipelineState > CreateGraphicsPipelineState(const SGraphicsPipelineStateDesc &pipelineStateDesc)=0
Creates a graphics pipeline state.
virtual std::unique_ptr< IVertexInputLayout > CreateVertexInputLayout(const PS::span< const SVertexAttributeFormat > attributes)=0
Creates a vertex input layout.
virtual void Report(const ScriptRequest &rq, JS::HandleValue settings)=0
virtual IFramebuffer * GetCurrentBackbuffer(const AttachmentLoadOp colorAttachmentLoadOp, const AttachmentStoreOp colorAttachmentStoreOp, const AttachmentLoadOp depthStencilAttachmentLoadOp, const AttachmentStoreOp depthStencilAttachmentStoreOp)=0
Returns a framebuffer for the current backbuffer with the required attachment operations.
virtual std::unique_ptr< IShaderProgram > CreateShaderProgram(const CStr &name, const CShaderDefines &defines)=0
virtual std::unique_ptr< IBuffer > CreateBuffer(const char *name, const IBuffer::Type type, const uint32_t size, const uint32_t usage)=0
virtual void Present()=0
Presents the backbuffer to the swapchain queue to be flipped on a screen.
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
bool ARBShaders
Definition: IDevice.h:53
bool anisotropicFiltering
Definition: IDevice.h:59
bool ARBShadersShadow
Definition: IDevice.h:54
float maxAnisotropy
Definition: IDevice.h:61
bool multisampling
Definition: IDevice.h:58
uint32_t maxSampleCount
Definition: IDevice.h:60
bool instancing
Definition: IDevice.h:63
bool S3TC
Definition: IDevice.h:52
bool computeShaders
Definition: IDevice.h:55
bool debugLabels
Definition: IDevice.h:56
bool debugScopedLabels
Definition: IDevice.h:57
uint32_t maxTextureSize
Definition: IDevice.h:62
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