From 6c4836397be9792b0f16641a055b5f8798fe2608 Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 20 Sep 2015 14:04:50 +0200 Subject: [PATCH] Some tweaks in renderbuffer handling --- source/base.c | 21 ++++++++++----------- source/context.h | 2 +- source/drawArrays.c | 2 +- source/drawElements.c | 2 +- source/renderbuffer.c | 35 +++++++++++++++++++++++------------ 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/source/base.c b/source/base.c index 88edb98..7090b60 100644 --- a/source/base.c +++ b/source/base.c @@ -126,12 +126,6 @@ void C3Di_UpdateContext(void) int i; C3D_Context* ctx = C3Di_GetContext(); - if (ctx->flags & C3DiF_NeedFinishDrawing) - { - ctx->flags &= ~C3DiF_NeedFinishDrawing; - //GPU_FinishDrawing(); - } - if (ctx->flags & C3DiF_Program) { ctx->flags &= ~C3DiF_Program; @@ -141,6 +135,11 @@ void C3Di_UpdateContext(void) if (ctx->flags & C3DiF_RenderBuf) { ctx->flags &= ~C3DiF_RenderBuf; + if (ctx->flags & C3DiF_DrawUsed) + { + ctx->flags &= ~C3DiF_DrawUsed; + GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_FLUSH, 1); + } C3Di_RenderBufBind(ctx->rb); } @@ -238,12 +237,12 @@ void C3D_FlushAsync(void) if (!(ctx->flags & C3DiF_Active)) return; - if (ctx->flags & C3DiF_NeedFinishDrawing) + if (ctx->flags & C3DiF_DrawUsed) { - ctx->flags &= ~C3DiF_NeedFinishDrawing; - GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_FLUSH, 0x00000001); - GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_INVALIDATE, 0x00000001); - GPUCMD_AddWrite(GPUREG_0063, 0x00000001); + ctx->flags &= ~C3DiF_DrawUsed; + GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_FLUSH, 1); + GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_INVALIDATE, 1); + GPUCMD_AddWrite(GPUREG_0063, 1); // Does this even do anything at all? } GPUCMD_Finalize(); diff --git a/source/context.h b/source/context.h index 70de827..34c9a37 100644 --- a/source/context.h +++ b/source/context.h @@ -49,7 +49,7 @@ typedef struct enum { C3DiF_Active = BIT(0), - C3DiF_NeedFinishDrawing = BIT(1), + C3DiF_DrawUsed = BIT(1), C3DiF_AttrInfo = BIT(2), C3DiF_BufInfo = BIT(3), C3DiF_Effect = BIT(4), diff --git a/source/drawArrays.c b/source/drawArrays.c index 81ec32e..cb10cb8 100644 --- a/source/drawArrays.c +++ b/source/drawArrays.c @@ -22,5 +22,5 @@ void C3D_DrawArrays(GPU_Primitive_t primitive, int first, int size) GPUCMD_AddMaskedWrite(GPUREG_0245, 1, 0x00000001); GPUCMD_AddWrite(GPUREG_0231, 0x00000001); - C3Di_GetContext()->flags |= C3DiF_NeedFinishDrawing; + C3Di_GetContext()->flags |= C3DiF_DrawUsed; } diff --git a/source/drawElements.c b/source/drawElements.c index 793ffc2..c33bc0d 100644 --- a/source/drawElements.c +++ b/source/drawElements.c @@ -28,5 +28,5 @@ void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void GPUCMD_AddMaskedWrite(GPUREG_0245, 1, 0x00000001); GPUCMD_AddWrite(GPUREG_0231, 0x00000001); - C3Di_GetContext()->flags |= C3DiF_NeedFinishDrawing; + C3Di_GetContext()->flags |= C3DiF_DrawUsed; } diff --git a/source/renderbuffer.c b/source/renderbuffer.c index f04cd8a..8648027 100644 --- a/source/renderbuffer.c +++ b/source/renderbuffer.c @@ -23,16 +23,25 @@ bool C3D_RenderBufInit(C3D_RenderBuf* rb, int width, int height, int colorFmt, i rb->height = height; rb->clearColor = rb->clearDepth = 0; - rb->colorBuf = vramAlloc(calcColorBufSize(width, height, colorFmt)); - if (!rb->colorBuf) return false; - - rb->depthBuf = vramAlloc(calcDepthBufSize(width, height, depthFmt)); - if (!rb->depthBuf) + if (colorFmt >= 0) { - vramFree(rb->colorBuf); - rb->colorBuf = NULL; - return false; - } + rb->colorBuf = vramAlloc(calcColorBufSize(width, height, colorFmt)); + if (!rb->colorBuf) return false; + } else + rb->colorFmt = GPU_RB_RGBA8; + + if (depthFmt >= 0) + { + rb->depthBuf = vramAlloc(calcDepthBufSize(width, height, depthFmt)); + if (!rb->depthBuf) + { + if (rb->colorBuf) + vramFree(rb->colorBuf); + rb->colorBuf = NULL; + return false; + } + } else + rb->depthFmt = GPU_RB_DEPTH16; return true; } @@ -62,7 +71,7 @@ void C3D_RenderBufBind(C3D_RenderBuf* rb) void C3Di_RenderBufBind(C3D_RenderBuf* rb) { - u32 param[4]; + u32 param[4] = { 0, 0, 0, 0 }; GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_INVALIDATE, 1); @@ -77,8 +86,10 @@ void C3Di_RenderBufBind(C3D_RenderBuf* rb) GPUCMD_AddWrite(GPUREG_FRAMEBUFFER_BLOCK32, 0x00000000); //? // "Enable depth buffer" (?) - param[0] = param[1] = 0xF; - param[2] = param[3] = 0x2; + if (rb->colorBuf) + param[0] = param[1] = 0xF; + if (rb->depthBuf) + param[2] = param[3] = 0x2; GPUCMD_AddIncrementalWrites(GPUREG_COLORBUFFER_READ, param, 4); }