Line data Source code
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 : #include "precompiled.h"
19 :
20 : #include "Device.h"
21 :
22 : #include "renderer/backend/Format.h"
23 : #include "renderer/backend/IFramebuffer.h"
24 : #include "renderer/backend/dummy/Buffer.h"
25 : #include "renderer/backend/dummy/DeviceCommandContext.h"
26 : #include "renderer/backend/dummy/Framebuffer.h"
27 : #include "renderer/backend/dummy/PipelineState.h"
28 : #include "renderer/backend/dummy/ShaderProgram.h"
29 : #include "renderer/backend/dummy/SwapChain.h"
30 : #include "renderer/backend/dummy/Texture.h"
31 : #include "scriptinterface/Object.h"
32 :
33 : #include <SDL_video.h>
34 : #include <initializer_list>
35 : #include <js/RootingAPI.h>
36 :
37 : namespace Renderer
38 : {
39 :
40 : namespace Backend
41 : {
42 :
43 : namespace Dummy
44 : {
45 :
46 12 : CDevice::CDevice()
47 : {
48 12 : m_Name = "Dummy";
49 12 : m_Version = "Unknown";
50 12 : m_DriverInformation = "Unknown";
51 12 : m_Extensions = {};
52 :
53 12 : m_Capabilities.S3TC = true;
54 12 : m_Capabilities.computeShaders = true;
55 12 : m_Capabilities.debugLabels = true;
56 12 : m_Capabilities.debugScopedLabels = true;
57 12 : m_Capabilities.multisampling = true;
58 12 : m_Capabilities.anisotropicFiltering = true;
59 12 : m_Capabilities.maxSampleCount = 4u;
60 12 : m_Capabilities.maxAnisotropy = 16.0f;
61 12 : m_Capabilities.maxTextureSize = 8192u;
62 12 : m_Capabilities.instancing = true;
63 12 : }
64 :
65 24 : CDevice::~CDevice() = default;
66 :
67 0 : void CDevice::Report(const Script::Request& rq, JS::HandleValue settings)
68 : {
69 0 : Script::SetProperty(rq, settings, "name", "dummy");
70 0 : }
71 :
72 10 : std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
73 : {
74 10 : return CDeviceCommandContext::Create(this);
75 : }
76 :
77 10 : std::unique_ptr<ISwapChain> CDevice::CreateSwapChain(
78 : const char*, SDL_Window*, int, int,
79 : const bool, std::unique_ptr<ISwapChain> oldSwapChain)
80 : {
81 10 : oldSwapChain.reset();
82 10 : return CSwapChain::Create(this);
83 : }
84 :
85 10 : void CDevice::WaitUntilIdle()
86 : {
87 10 : }
88 :
89 0 : std::unique_ptr<IGraphicsPipelineState> CDevice::CreateGraphicsPipelineState(
90 : const SGraphicsPipelineStateDesc& pipelineStateDesc)
91 : {
92 0 : return CGraphicsPipelineState::Create(this, pipelineStateDesc);
93 : }
94 :
95 0 : std::unique_ptr<IComputePipelineState> CDevice::CreateComputePipelineState(
96 : const SComputePipelineStateDesc& pipelineStateDesc)
97 : {
98 0 : return CComputePipelineState::Create(this, pipelineStateDesc);
99 : }
100 :
101 130 : std::unique_ptr<IVertexInputLayout> CDevice::CreateVertexInputLayout(
102 : const std::span<const SVertexAttributeFormat>)
103 : {
104 130 : return nullptr;
105 : }
106 :
107 99 : std::unique_ptr<ITexture> CDevice::CreateTexture(
108 : const char* /*name*/, const CTexture::Type type, const uint32_t usage,
109 : const Format format, const uint32_t width, const uint32_t height,
110 : const Sampler::Desc& /*defaultSamplerDesc*/, const uint32_t MIPLevelCount,
111 : const uint32_t /*sampleCount*/)
112 : {
113 99 : return CTexture::Create(this, type, usage, format, width, height, MIPLevelCount);
114 : }
115 :
116 86 : std::unique_ptr<ITexture> CDevice::CreateTexture2D(
117 : const char* name, const uint32_t usage,
118 : const Format format, const uint32_t width, const uint32_t height,
119 : const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
120 : {
121 86 : return CreateTexture(name, ITexture::Type::TEXTURE_2D, usage,
122 86 : format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
123 : }
124 :
125 20 : std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer(
126 : const char*, SColorAttachment*, SDepthStencilAttachment*)
127 : {
128 20 : return CFramebuffer::Create(this);
129 : }
130 :
131 10 : std::unique_ptr<IBuffer> CDevice::CreateBuffer(
132 : const char*, const CBuffer::Type type, const uint32_t size, const uint32_t usage)
133 : {
134 10 : return CBuffer::Create(this, type, size, usage);
135 : }
136 :
137 0 : std::unique_ptr<IShaderProgram> CDevice::CreateShaderProgram(
138 : const CStr&, const CShaderDefines&)
139 : {
140 0 : return CShaderProgram::Create(this);
141 : }
142 :
143 52 : bool CDevice::IsTextureFormatSupported(const Format) const
144 : {
145 52 : return true;
146 : }
147 :
148 0 : bool CDevice::IsFramebufferFormatSupported(const Format) const
149 : {
150 0 : return true;
151 : }
152 :
153 50 : Format CDevice::GetPreferredDepthStencilFormat(
154 : const uint32_t, const bool, const bool) const
155 : {
156 50 : return Format::D24_UNORM_S8_UINT;
157 : }
158 :
159 0 : uint32_t CDevice::AllocateQuery()
160 : {
161 0 : return 0;
162 : }
163 :
164 0 : void CDevice::FreeQuery(const uint32_t /*handle*/)
165 : {
166 0 : }
167 :
168 0 : bool CDevice::IsQueryResultAvailable(const uint32_t /*handle*/) const
169 : {
170 0 : return false;
171 : }
172 :
173 0 : uint64_t CDevice::GetQueryResult(const uint32_t /*handle*/)
174 : {
175 0 : return 0;
176 : }
177 :
178 10 : std::unique_ptr<IDevice> CreateDevice(SDL_Window*)
179 : {
180 10 : return std::make_unique<Dummy::CDevice>();
181 : }
182 :
183 : } // namespace Dummy
184 :
185 : } // namespace Backend
186 :
187 : } // namespace Renderer
|