| 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::Software |
| 12 |
{ |
| 13 |
class SwTexture; |
| 14 |
|
| 15 |
/** |
| 16 |
@brief Renderbuffer stub of the software backend (aliased as `RHI::Renderbuffer`) |
| 17 |
|
| 18 |
The software 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 SwRenderbuffer |
| 22 |
{ |
| 23 |
public: |
| 24 |
SwRenderbuffer() = 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 software backend (aliased as `RHI::Framebuffer`) |
| 42 |
|
| 43 |
Provided only for the contract alias (the default-framebuffer rebinding some window backends use). |
| 44 |
The software backend routes off-screen rendering through @ref SwRenderTarget instead. |
| 45 |
*/ |
| 46 |
class SwFramebuffer |
| 47 |
{ |
| 48 |
public: |
| 49 |
SwFramebuffer() = 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 software 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 SwRenderTarget |
| 69 |
{ |
| 70 |
public: |
| 71 |
static constexpr std::uint32_t MaxColorAttachments = 8; |
| 72 |
|
| 73 |
SwRenderTarget(); |
| 74 |
~SwRenderTarget(); |
| 75 |
|
| 76 |
SwRenderTarget(const SwRenderTarget&) = delete; |
| 77 |
SwRenderTarget& operator=(const SwRenderTarget&) = delete; |
| 78 |
|
| 79 |
/** @brief Attaches a texture as the color attachment with the given index */ |
| 80 |
void AttachColorTexture(SwTexture& 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 software 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 SwTexture* GetColorTexture(std::uint32_t index) const { |
| 107 |
return (index < MaxColorAttachments ? _colorTextures[index] : nullptr); |
| 108 |
} |
| 109 |
|
| 110 |
private: |
| 111 |
SwTexture* _colorTextures[MaxColorAttachments]; |
| 112 |
std::uint32_t _numDrawBuffers; |
| 113 |
}; |
| 114 |
} |