| 1 |
#include "GsRenderTarget.h" |
| 2 |
#include "GsDevice.h" |
| 3 |
#include "GsTexture.h" |
| 4 |
|
| 5 |
namespace nCine::RHI::GS |
| 6 |
{ |
| 7 |
GsRenderTarget::GsRenderTarget() |
| 8 |
: _numDrawBuffers(1) |
| 9 |
{ |
| 10 |
for (std::uint32_t i = 0; i < MaxColorAttachments; i++) { |
| 11 |
_colorTextures[i] = nullptr; |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
GsRenderTarget::~GsRenderTarget() |
| 16 |
{ |
| 17 |
// Clear from the device so a destroyed target can't dangle as the current one |
| 18 |
GsDevice::UnbindRenderTarget(this); |
| 19 |
} |
| 20 |
|
| 21 |
void GsRenderTarget::AttachColorTexture(GsTexture& texture, std::uint32_t index) |
| 22 |
{ |
| 23 |
if (index < MaxColorAttachments) { |
| 24 |
_colorTextures[index] = &texture; |
| 25 |
// Becoming a render target allocates the texture's surface out of the reserve and marks it |
| 26 |
// non-evictable; it also tags the store as bottom-up (the GL framebuffer convention) both for |
| 27 |
// drawing into it and for later sampling it as a source |
| 28 |
texture.SetRenderTarget(true); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
void GsRenderTarget::DetachColorTexture(std::uint32_t index) |
| 33 |
{ |
| 34 |
if (index < MaxColorAttachments) { |
| 35 |
_colorTextures[index] = nullptr; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
void GsRenderTarget::AttachDepthStencil(DepthStencilFormat format, std::int32_t width, std::int32_t height) |
| 40 |
{ |
| 41 |
static_cast<void>(format); |
| 42 |
static_cast<void>(width); |
| 43 |
static_cast<void>(height); |
| 44 |
} |
| 45 |
|
| 46 |
void GsRenderTarget::DetachDepthStencil(DepthStencilFormat format) |
| 47 |
{ |
| 48 |
static_cast<void>(format); |
| 49 |
} |
| 50 |
|
| 51 |
void GsRenderTarget::BindDraw() |
| 52 |
{ |
| 53 |
GsDevice::SetRenderTarget(this); |
| 54 |
} |
| 55 |
|
| 56 |
void GsRenderTarget::UnbindDraw() |
| 57 |
{ |
| 58 |
GsDevice::SetRenderTarget(nullptr); |
| 59 |
} |
| 60 |
|
| 61 |
bool GsRenderTarget::SetDrawBuffers(std::uint32_t numColorAttachments) |
| 62 |
{ |
| 63 |
_numDrawBuffers = numColorAttachments; |
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
bool GsRenderTarget::IsStatusComplete() |
| 68 |
{ |
| 69 |
return (_colorTextures[0] != nullptr); |
| 70 |
} |
| 71 |
|
| 72 |
void GsRenderTarget::InvalidateDepthStencil(DepthStencilFormat format) |
| 73 |
{ |
| 74 |
static_cast<void>(format); |
| 75 |
} |
| 76 |
|
| 77 |
void GsRenderTarget::SetObjectLabel(StringView label) |
| 78 |
{ |
| 79 |
static_cast<void>(label); |
| 80 |
} |
| 81 |
} |