Merge 'remotes/trunk'
[0ad.git] / source / renderer / backend / dummy / Device.cpp
blobefc589ebe00a29945571546886af89f936b3278d
1 /* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #include "precompiled.h"
20 #include "Device.h"
22 #include "renderer/backend/dummy/Buffer.h"
23 #include "renderer/backend/dummy/DeviceCommandContext.h"
24 #include "renderer/backend/dummy/Framebuffer.h"
25 #include "renderer/backend/dummy/PipelineState.h"
26 #include "renderer/backend/dummy/ShaderProgram.h"
27 #include "renderer/backend/dummy/Texture.h"
28 #include "scriptinterface/JSON.h"
29 #include "scriptinterface/Object.h"
30 #include "scriptinterface/ScriptInterface.h"
31 #include "scriptinterface/ScriptRequest.h"
33 namespace Renderer
36 namespace Backend
39 namespace Dummy
42 CDevice::CDevice()
44 m_Name = "Dummy";
45 m_Version = "Unknown";
46 m_DriverInformation = "Unknown";
47 m_Extensions = {};
49 m_Backbuffer = CFramebuffer::Create(this);
51 m_Capabilities.S3TC = true;
52 m_Capabilities.ARBShaders = false;
53 m_Capabilities.ARBShadersShadow = false;
54 m_Capabilities.computeShaders = true;
55 m_Capabilities.debugLabels = true;
56 m_Capabilities.debugScopedLabels = true;
57 m_Capabilities.multisampling = true;
58 m_Capabilities.anisotropicFiltering = true;
59 m_Capabilities.maxSampleCount = 4u;
60 m_Capabilities.maxAnisotropy = 16.0f;
61 m_Capabilities.maxTextureSize = 8192u;
62 m_Capabilities.instancing = true;
65 CDevice::~CDevice() = default;
67 void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings)
69 Script::SetProperty(rq, settings, "name", "dummy");
72 std::unique_ptr<IDeviceCommandContext> CDevice::CreateCommandContext()
74 return CDeviceCommandContext::Create(this);
77 std::unique_ptr<IGraphicsPipelineState> CDevice::CreateGraphicsPipelineState(
78 const SGraphicsPipelineStateDesc& pipelineStateDesc)
80 return CGraphicsPipelineState::Create(this, pipelineStateDesc);
83 std::unique_ptr<IVertexInputLayout> CDevice::CreateVertexInputLayout(
84 const PS::span<const SVertexAttributeFormat> UNUSED(attributes))
86 return nullptr;
89 std::unique_ptr<ITexture> CDevice::CreateTexture(
90 const char* UNUSED(name), const CTexture::Type type, const uint32_t usage,
91 const Format format, const uint32_t width, const uint32_t height,
92 const Sampler::Desc& UNUSED(defaultSamplerDesc), const uint32_t MIPLevelCount, const uint32_t UNUSED(sampleCount))
94 return CTexture::Create(this, type, usage, format, width, height, MIPLevelCount);
97 std::unique_ptr<ITexture> CDevice::CreateTexture2D(
98 const char* name, const uint32_t usage,
99 const Format format, const uint32_t width, const uint32_t height,
100 const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
102 return CreateTexture(name, ITexture::Type::TEXTURE_2D, usage,
103 format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount);
106 std::unique_ptr<IFramebuffer> CDevice::CreateFramebuffer(
107 const char*, SColorAttachment*, SDepthStencilAttachment*)
109 return CFramebuffer::Create(this);
112 std::unique_ptr<IBuffer> CDevice::CreateBuffer(
113 const char*, const CBuffer::Type type, const uint32_t size, const bool dynamic)
115 return CBuffer::Create(this, type, size, dynamic);
118 std::unique_ptr<IShaderProgram> CDevice::CreateShaderProgram(
119 const CStr&, const CShaderDefines&)
121 return CShaderProgram::Create(this);
124 bool CDevice::AcquireNextBackbuffer()
126 // We have nothing to acquire.
127 return true;
130 IFramebuffer* CDevice::GetCurrentBackbuffer(
131 const AttachmentLoadOp, const AttachmentStoreOp,
132 const AttachmentLoadOp, const AttachmentStoreOp)
134 return m_Backbuffer.get();
137 void CDevice::Present()
139 // We have nothing to present.
142 void CDevice::OnWindowResize(const uint32_t UNUSED(width), const uint32_t UNUSED(height))
146 bool CDevice::IsTextureFormatSupported(const Format UNUSED(format)) const
148 return true;
151 bool CDevice::IsFramebufferFormatSupported(const Format UNUSED(format)) const
153 return true;
156 Format CDevice::GetPreferredDepthStencilFormat(
157 const uint32_t, const bool, const bool) const
159 return Format::D24_UNORM_S8_UINT;
162 std::unique_ptr<IDevice> CreateDevice(SDL_Window* UNUSED(window))
164 return std::make_unique<Dummy::CDevice>();
167 } // namespace Dummy
169 } // namespace Backend
171 } // namespace Renderer