Debian Codegraph @

Sources/nCine/Graphics/RHI/PVR/PvrRenderTarget.h

raw
1 #pragma once
2
3 #include "../RhiTypes.h"
4
5 #include <cstdint>
6
7 #include <Containers/StringView.h>
8
9 using namespace Death::Containers;
10
11 namespace nCine::RHI::PVR
12 {
13 class PvrTexture;
14
15 /**
16 @brief Renderbuffer stub of the PVR backend (aliased as `RHI::Renderbuffer`)
17
18 The PVR backend renders 2D only, so depth/stencil renderbuffers carry no storage; the class
19 just records the format and size to satisfy the contract alias.
20 */
21 class PvrRenderbuffer
22 {
23 public:
24 PvrRenderbuffer() = default;
25 void Create(DepthStencilFormat format, std::int32_t width, std::int32_t height) {
26 _format = format;
27 _width = width;
28 _height = height;
29 }
30 inline std::uint32_t GetGLHandle() const {
31 return 0;
32 }
33
34 private:
35 DepthStencilFormat _format = DepthStencilFormat::None;
36 std::int32_t _width = 0;
37 std::int32_t _height = 0;
38 };
39
40 /**
41 @brief Framebuffer stub of the PVR backend (aliased as `RHI::Framebuffer`)
42
43 Provided only for the contract alias (the default-framebuffer rebinding some window backends use).
44 The PVR backend routes off-screen rendering through @ref PvrRenderTarget instead.
45 */
46 class PvrFramebuffer
47 {
48 public:
49 PvrFramebuffer() = default;
50 inline std::uint32_t GetGLHandle() const {
51 return 0;
52 }
53 bool Bind() const {
54 return true;
55 }
56 static bool Unbind() {
57 return true;
58 }
59 };
60
61 /**
62 @brief Off-screen render target of the PVR backend (aliased as `RHI::RenderTarget`)
63
64 Holds the color textures the rasterizer writes into (addressed by attachment index) and an
65 optional depth/stencil (ignored for 2D). @ref BindDraw() records the target on the device so the
66 following clears and draws land in its color attachment 0.
67 */
68 class PvrRenderTarget
69 {
70 public:
71 static constexpr std::uint32_t MaxColorAttachments = 8;
72
73 PvrRenderTarget();
74 ~PvrRenderTarget();
75
76 PvrRenderTarget(const PvrRenderTarget&) = delete;
77 PvrRenderTarget& operator=(const PvrRenderTarget&) = delete;
78
79 /** @brief Attaches a texture as the color attachment with the given index */
80 void AttachColorTexture(PvrTexture& texture, std::uint32_t index);
81 /** @brief Detaches any texture from the color attachment with the given index */
82 void DetachColorTexture(std::uint32_t index);
83
84 /** @brief Records a depth/stencil buffer (no storage — the PVR backend is 2D) */
85 void AttachDepthStencil(DepthStencilFormat format, std::int32_t width, std::int32_t height);
86 /** @brief Clears the recorded depth/stencil buffer */
87 void DetachDepthStencil(DepthStencilFormat format);
88
89 /** @brief Binds the render target as the current draw target on the device */
90 void BindDraw();
91 /** @brief Unbinds any render target from the device */
92 static void UnbindDraw();
93 /** @brief Sets the number of color attachments enabled for drawing */
94 bool SetDrawBuffers(std::uint32_t numColorAttachments);
95
96 /** @brief Returns `true` if the target has a usable color attachment 0 */
97 bool IsStatusComplete();
98
99 /** @brief Hints that the depth/stencil contents are no longer needed (no-op) */
100 void InvalidateDepthStencil(DepthStencilFormat format);
101
102 /** @brief Sets a debug label for the render target (ignored) */
103 void SetObjectLabel(StringView label);
104
105 /** @brief Returns the texture attached at the given color attachment index, or `nullptr` */
106 inline PvrTexture* GetColorTexture(std::uint32_t index) const {
107 return (index < MaxColorAttachments ? _colorTextures[index] : nullptr);
108 }
109
110 private:
111 PvrTexture* _colorTextures[MaxColorAttachments];
112 std::uint32_t _numDrawBuffers;
113 };
114 }