2017-02-14 18:35:37 +01:00
|
|
|
#define CITRO3D_NO_DEPRECATION
|
2017-02-09 04:30:25 +01:00
|
|
|
#include "internal.h"
|
|
|
|
#include <c3d/base.h>
|
2017-02-14 18:24:57 +01:00
|
|
|
#include <c3d/renderbuffer.h>
|
2015-03-07 23:41:32 +01:00
|
|
|
|
|
|
|
static const u8 colorFmtSizes[] = {2,1,0,0,0};
|
|
|
|
static const u8 depthFmtSizes[] = {0,0,1,2};
|
|
|
|
|
2015-11-28 15:53:06 +01:00
|
|
|
static inline u16 getColorBufFillFlag(int fmt)
|
2015-03-07 23:41:32 +01:00
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
if (fmt < 0) return 0;
|
|
|
|
return BIT(0) | ((u32)colorFmtSizes[fmt] << 8);
|
2015-03-07 23:41:32 +01:00
|
|
|
}
|
|
|
|
|
2015-11-28 15:53:06 +01:00
|
|
|
static inline u16 getDepthBufFillFlag(int fmt)
|
2015-03-07 23:41:32 +01:00
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
if (fmt < 0) return 0;
|
|
|
|
return BIT(0) | ((u32)depthFmtSizes[fmt] << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline GPU_TEXCOLOR colorFmtFromDepthFmt(int fmt)
|
|
|
|
{
|
|
|
|
switch (fmt)
|
|
|
|
{
|
|
|
|
case GPU_RB_DEPTH16:
|
|
|
|
return GPU_RGB565;
|
|
|
|
case GPU_RB_DEPTH24:
|
|
|
|
return GPU_RGB8;
|
|
|
|
case GPU_RB_DEPTH24_STENCIL8:
|
|
|
|
return GPU_RGBA8;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2015-03-07 23:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool C3D_RenderBufInit(C3D_RenderBuf* rb, int width, int height, int colorFmt, int depthFmt)
|
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
memset(rb, 0, sizeof(*rb));
|
2015-03-07 23:41:32 +01:00
|
|
|
|
|
|
|
rb->depthFmt = depthFmt;
|
|
|
|
rb->clearColor = rb->clearDepth = 0;
|
|
|
|
|
2015-11-28 15:53:06 +01:00
|
|
|
if (colorFmt < 0)
|
|
|
|
return false;
|
|
|
|
if (!C3D_TexInitVRAM(&rb->colorBuf, width, height, colorFmt))
|
|
|
|
return false;
|
2015-03-07 23:41:32 +01:00
|
|
|
|
2015-09-20 14:04:50 +02:00
|
|
|
if (depthFmt >= 0)
|
2015-03-07 23:41:32 +01:00
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
if (!C3D_TexInitVRAM(&rb->depthBuf, width, height, colorFmtFromDepthFmt(depthFmt)))
|
2015-09-20 14:04:50 +02:00
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
C3D_TexDelete(&rb->colorBuf);
|
2015-09-20 14:04:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-28 15:53:06 +01:00
|
|
|
}
|
2015-03-07 23:41:32 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C3D_RenderBufClearAsync(C3D_RenderBuf* rb)
|
|
|
|
{
|
2015-09-07 14:47:20 +02:00
|
|
|
GX_MemoryFill(
|
2015-11-28 15:53:06 +01:00
|
|
|
(u32*)rb->colorBuf.data, rb->clearColor, (u32*)((u8*)rb->colorBuf.data+rb->colorBuf.size), getColorBufFillFlag(rb->colorBuf.fmt),
|
|
|
|
(u32*)rb->depthBuf.data, rb->clearDepth, (u32*)((u8*)rb->depthBuf.data+rb->depthBuf.size), getDepthBufFillFlag(rb->depthFmt));
|
2015-03-07 23:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void C3D_RenderBufTransferAsync(C3D_RenderBuf* rb, u32* frameBuf, u32 flags)
|
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
u32 dim = GX_BUFFER_DIM((u32)rb->colorBuf.width, (u32)rb->colorBuf.height);
|
|
|
|
GX_DisplayTransfer((u32*)rb->colorBuf.data, dim, frameBuf, dim, flags);
|
2015-03-07 23:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void C3D_RenderBufBind(C3D_RenderBuf* rb)
|
|
|
|
{
|
|
|
|
C3D_Context* ctx = C3Di_GetContext();
|
2017-02-14 18:24:57 +01:00
|
|
|
C3D_FrameBuf* fb = &ctx->fb;
|
|
|
|
ctx->flags |= C3DiF_FrameBuf;
|
|
|
|
fb->colorBuf = rb->colorBuf.data;
|
|
|
|
fb->depthBuf = rb->depthBuf.data;
|
|
|
|
fb->width = rb->colorBuf.width;
|
|
|
|
fb->height = rb->colorBuf.height;
|
|
|
|
fb->colorFmt = (GPU_COLORBUF)rb->colorBuf.fmt;
|
|
|
|
fb->depthFmt = rb->depthFmt >= 0 ? (GPU_DEPTHBUF)rb->depthFmt : GPU_RB_DEPTH16;
|
|
|
|
fb->block32 = false;
|
|
|
|
fb->colorMask = 0xF;
|
|
|
|
fb->depthMask = 0x2;
|
2015-11-28 15:53:06 +01:00
|
|
|
C3D_SetViewport(0, 0, rb->colorBuf.width, rb->colorBuf.height);
|
2015-03-07 23:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void C3D_RenderBufDelete(C3D_RenderBuf* rb)
|
|
|
|
{
|
2015-11-28 15:53:06 +01:00
|
|
|
C3D_TexDelete(&rb->colorBuf);
|
|
|
|
C3D_TexDelete(&rb->depthBuf);
|
2015-03-07 23:41:32 +01:00
|
|
|
}
|