Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
World3DRenderer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "World3DGPUScene.hpp"
4#include "World3DPipeline.hpp"
6
7#include <SDL3/SDL_gpu.h>
8
9#include <array>
10#include <cstddef>
11#include <cstdint>
12#include <expected>
13#include <filesystem>
14#include <memory>
15#include <optional>
16#include <string>
17
18namespace monopoly::engine
19{
35
37 {
39 std::string detail;
40 std::optional<World3DPipelineError> pipelineError;
41 std::optional<MeshGPUError> meshError;
42 };
43
45 {
46 std::size_t objects{};
47 std::size_t batches{};
48 std::size_t triangles{};
49 std::size_t shadowBatches{};
50 std::size_t shadowTriangles{};
51 std::uint32_t sampleCount{1U};
52 };
53
55 {
56 std::array<float, 3> color{};
57 std::array<float, 3> direction{};
58 bool enabled{};
59 };
60
62 {
63 std::array<float, 3> color{};
64 std::array<float, 3> position{};
65 std::array<float, 3> direction{0.0F, -1.0F, 0.0F};
66 std::array<float, 3> attenuation{1.0F, 0.0F, 0.0F};
67 float range{300.0F};
68 float falloff{1.0F};
69 float theta{0.0F};
70 float phi{0.0F};
71 bool enabled{};
72 };
73
81
83 {
84 public:
85 World3DRenderer() = default;
91
92 [[nodiscard]] static std::expected<World3DRenderer,
94 SDL_GPUDevice* device,
95 const std::filesystem::path& shaderDirectory,
97 const std::filesystem::path& studioEnvironmentPath = {});
98
99 [[nodiscard]] std::expected<World3DRenderStats,
103 std::uint32_t targetWidth,
104 std::uint32_t targetHeight,
105 const SDL_GPUViewport& viewport,
107
108 void reset() noexcept;
109 void setBilinearFiltering(bool enabled) noexcept { bilinearFiltering_ = enabled; }
110 void setModernPresentation(bool enabled) noexcept { modernPresentation_ = enabled; }
111 void setPresentationShadows(bool enabled) noexcept { presentationShadows_ = enabled; }
112 void setPresentationAntialiasing(bool enabled) noexcept { presentationAntialiasing_ = enabled; }
113 [[nodiscard]] bool presentationShadowsActive() const noexcept { return shadowsActive_; }
114 [[nodiscard]] bool presentationAntialiasingActive() const noexcept { return antialiasingActive_; }
115 [[nodiscard]] std::uint32_t presentationSampleCount() const noexcept { return antialiasingActive_ ? 4U : 1U; }
116 [[nodiscard]] bool bilinearFiltering() const noexcept { return bilinearFiltering_; }
118 { lighting_ = lighting; }
120 { return lighting_; }
122 { return meshCache_.get(); }
124 { return pipeline_; }
126 { return modernPipeline_ ? &*modernPipeline_ : nullptr; }
128 { return studioEnvironmentEnabled_; }
129
130 private:
131 [[nodiscard]] bool ensureDepthTarget(
132 std::uint32_t width, std::uint32_t height,
134 [[nodiscard]] bool ensurePresentationTargets(std::uint32_t width, std::uint32_t height);
135 [[nodiscard]] bool ensureShadowResources();
136 void releasePresentationResources() noexcept;
137 void releaseDepthTarget() noexcept;
138 void releaseSamplingResources() noexcept;
139
140 SDL_GPUDevice* device_{};
141 World3DPipeline pipeline_;
142 std::optional<World3DPipeline> modernPipeline_;
143 bool modernPipelineAttempted_{};
144 std::filesystem::path shaderDirectory_;
146 std::unique_ptr<MeshGPUCache> meshCache_;
147 StudioEnvironmentGPU studioEnvironment_;
148 bool studioEnvironmentEnabled_{};
149 SDL_GPUSampler* textureSampler_{};
150 SDL_GPUSampler* linearSampler_{};
151 bool bilinearFiltering_{};
152 SDL_GPUTexture* whiteTexture_{};
153 SDL_GPUTexture* depthTarget_{};
154 std::uint32_t depthWidth_{};
155 std::uint32_t depthHeight_{};
156 World3DLighting lighting_{};
157 bool modernPresentation_{};
158 bool presentationShadows_{};
159 bool presentationAntialiasing_{};
160 bool shadowsActive_{};
161 bool antialiasingActive_{};
163 SDL_GPUTexture* multisampleColor_{};
164 std::uint32_t multisampleWidth_{};
165 std::uint32_t multisampleHeight_{};
166 std::optional<World3DPipeline> multisampleLegacyPipeline_;
167 std::optional<World3DPipeline> multisampleModernPipeline_;
168 SDL_GPUTexture* shadowMap_{};
169 SDL_GPUTexture* shadowDepth_{};
170 SDL_GPUSampler* shadowSampler_{};
171 std::optional<World3DPipeline> shadowMapPipeline_;
172 };
173}
bool enabled
Definition Engine.cpp:170
PlayerNumber slot
std::uint32_t height
std::uint32_t width
unsigned index
CardTag other
void setBilinearFiltering(bool enabled) noexcept
void setLighting(const World3DLighting &lighting) noexcept
const World3DPipeline * modernPipeline() const noexcept
void setModernPresentation(bool enabled) noexcept
World3DRenderer & operator=(const World3DRenderer &)=delete
World3DRenderer(const World3DRenderer &)=delete
bool studioEnvironmentEnabled() const noexcept
const World3DLighting & lighting() const noexcept
std::uint32_t presentationSampleCount() const noexcept
bool presentationShadowsActive() const noexcept
static std::expected< World3DRenderer, World3DRendererError > load(SDL_GPUDevice *device, const std::filesystem::path &shaderDirectory, SDL_GPUTextureFormat colorFormat, const std::filesystem::path &studioEnvironmentPath={})
void setPresentationShadows(bool enabled) noexcept
const World3DPipeline & pipeline() const noexcept
bool bilinearFiltering() const noexcept
MeshGPUCache * meshCache() noexcept
void setPresentationAntialiasing(bool enabled) noexcept
bool presentationAntialiasingActive() const noexcept
std::expected< World3DRenderStats, World3DRendererError > render(SDL_GPUCommandBuffer *commandBuffer, SDL_GPUTexture *colorTarget, std::uint32_t targetWidth, std::uint32_t targetHeight, const SDL_GPUViewport &viewport, const SequenceWorld3DSlot &slot)
World3DDirectionalLight boardReflection
std::optional< MeshGPUError > meshError
std::optional< World3DPipelineError > pipelineError