Debian Codegraph @

Sources/nCine/Graphics/RHI/GL/GLRenderTarget.h

raw
1 #pragma once
2
3 #include "GLFramebuffer.h"
4 #include "../RhiTypes.h"
5
6 namespace nCine::RHI::GL
7 {
8 /**
9 @brief Off-screen render target of the OpenGL backend
10
11 Folds a framebuffer object and its owned depth/stencil renderbuffer behind a backend-neutral
12 surface (aliased as `RHI::RenderTarget`): color attachments are textures addressed by index,
13 the depth/stencil attachment is described by @ref DepthStencilFormat, and the backend translates
14 both to its own attachment points and storage formats.
15 */
16 class GLRenderTarget
17 {
18 public:
19 GLRenderTarget() = default;
20
21 GLRenderTarget(const GLRenderTarget&) = delete;
22 GLRenderTarget& operator=(const GLRenderTarget&) = delete;
23
24 /** @brief Attaches a texture as the color attachment with the given index */
25 void AttachColorTexture(GLTexture& texture, std::uint32_t index);
26 /** @brief Detaches any texture from the color attachment with the given index */
27 void DetachColorTexture(std::uint32_t index);
28
29 /** @brief Creates and attaches a depth/stencil buffer of the given format and size */
30 void AttachDepthStencil(DepthStencilFormat format, std::int32_t width, std::int32_t height);
31 /** @brief Detaches and destroys the depth/stencil buffer of the given format */
32 void DetachDepthStencil(DepthStencilFormat format);
33
34 /** @brief Binds the render target for drawing */
35 void BindDraw();
36 /** @brief Unbinds any render target from drawing, restoring the default one */
37 static void UnbindDraw();
38 /** @brief Sets the number of color attachments enabled for drawing */
39 bool SetDrawBuffers(std::uint32_t numColorAttachments);
40
41 /** @brief Returns `true` if the render target is complete and ready for rendering */
42 bool IsStatusComplete();
43
44 /** @brief Hints that the contents of the depth/stencil attachment are no longer needed */
45 void InvalidateDepthStencil(DepthStencilFormat format);
46
47 /** @brief Sets a backend object label for the render target, for debugging */
48 void SetObjectLabel(StringView label);
49
50 private:
51 GLFramebuffer _fbo;
52 };
53 }