Change Gfx_Clear to allow separately clearing colour and depth buffer

This commit is contained in:
UnknownShadow200 2024-03-22 07:51:51 +11:00
parent b7bde85cd4
commit 551dfa716f
19 changed files with 89 additions and 37 deletions

View File

@ -625,7 +625,7 @@ static void Game_RenderFrame(double delta) {
/* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */
if (Window_Main.Inactive) return;
Gfx_Clear();
Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH);
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View);

View File

@ -70,6 +70,11 @@ extern const cc_string Gfx_LowPerfMessage;
#define GFX_MAX_INDICES (65536 / 4 * 6)
#define GFX_MAX_VERTICES 65536
typedef enum GfxBuffers_ {
GFX_BUFFER_COLOR = 1,
GFX_BUFFER_DEPTH = 2
} GfxBuffers;
/* Texture should persist across gfx context loss (if backend supports ManagedTextures) */
#define TEXTURE_FLAG_MANAGED 0x01
/* Texture should allow updating via Gfx_UpdateTexture */
@ -132,8 +137,9 @@ CC_API void Gfx_SetAlphaBlending(cc_bool enabled);
/* Sets whether blending between the alpha components of texture and vertex colour is performed */
CC_API void Gfx_SetAlphaArgBlend(cc_bool enabled);
/* Clears the colour and depth buffer to default */
CC_API void Gfx_Clear(void);
/* Clears the given rendering buffer(s) to default. */
/* buffers can be either GFX_BUFFER_COLOR or GFX_BUFFER_DEPTH, or both */
CC_API void Gfx_ClearBuffers(GfxBuffers buffers);
/* Sets the colour that the colour buffer is cleared to */
CC_API void Gfx_ClearColor(PackedCol color);
/* Sets whether pixels may be discard based on z/depth */

View File

@ -426,9 +426,13 @@ void Gfx_BeginFrame(void) {
C3D_FrameDrawOn(topTarget);
}
void Gfx_Clear(void) {
C3D_RenderTargetClear(topTarget, C3D_CLEAR_ALL, clear_color, 0);
C3D_RenderTargetClear(bottomTarget, C3D_CLEAR_ALL, 0, 0);
void Gfx_ClearBuffers(GfxBuffers buffers) {
int targets = 0;
if (buffers & GFX_BUFFER_COLOR) targets |= C3D_CLEAR_COLOR;
if (buffers & GFX_BUFFER_DEPTH) targets |= C3D_CLEAR_DEPTH;
C3D_RenderTargetClear(topTarget, targets, clear_color, 0);
C3D_RenderTargetClear(bottomTarget, targets, 0, 0);
}
void Gfx_EndFrame(void) {

View File

@ -899,9 +899,13 @@ static float gfx_clearColor[4];
static cc_bool gfx_alphaBlending, gfx_colorEnabled = true;
static cc_bool gfx_depthTest, gfx_depthWrite;
static void OM_Clear(void) {
ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer, gfx_clearColor);
ID3D11DeviceContext_ClearDepthStencilView(context, depthbufferView, D3D11_CLEAR_DEPTH, 0.0f, 0);
static void OM_Clear(GfxBuffers buffers) {
if (buffers & GFX_BUFFER_COLOR) {
ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer, gfx_clearColor);
}
if (buffers & GFX_BUFFER_DEPTH) {
ID3D11DeviceContext_ClearDepthStencilView(context, depthbufferView, D3D11_CLEAR_DEPTH, 0.0f, 0);
}
}
static void OM_UpdateTarget(void) {
@ -1108,7 +1112,10 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
gfx_vsync = vsync;
}
void Gfx_BeginFrame(void) { OM_UpdateTarget(); }
void Gfx_Clear(void) { OM_Clear(); }
void Gfx_ClearBuffers(GfxBuffers buffers) {
OM_Clear(buffers);
}
void Gfx_EndFrame(void) {
// https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present

View File

@ -844,9 +844,12 @@ void Gfx_BeginFrame(void) {
IDirect3DDevice9_BeginScene(device);
}
void Gfx_Clear(void) {
DWORD flags = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER;
cc_result res = IDirect3DDevice9_Clear(device, 0, NULL, flags, gfx_clearColor, 0.0f, 0);
void Gfx_ClearBuffers(GfxBuffers buffers) {
DWORD targets = 0;
if (buffers & GFX_BUFFER_COLOR) targets |= D3DCLEAR_TARGET;
if (buffers & GFX_BUFFER_DEPTH) targets |= D3DCLEAR_ZBUFFER;
cc_result res = IDirect3DDevice9_Clear(device, 0, NULL, targets, gfx_clearColor, 0.0f, 0);
if (res) Logger_Abort2(res, "D3D9_Clear");
}

View File

@ -531,7 +531,9 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
}
void Gfx_BeginFrame(void) { }
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO clear only some buffers
// no need to use glClear
}

View File

@ -253,7 +253,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_BeginFrame(void) {
}
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO clear only some buffers
}
void Gfx_EndFrame(void) {

View File

@ -90,10 +90,14 @@ void Gfx_BeginFrame(void) {
extern void __rdpq_autosync_change(int mode);
static color_t gfx_clearColor;
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
__rdpq_autosync_change(AUTOSYNC_PIPE);
rdpq_clear(gfx_clearColor);
rdpq_clear_z(0xFFFC);
if (buffers & GFX_BUFFER_COLOR)
rdpq_clear(gfx_clearColor);
if (buffers & GFX_BUFFER_DEPTH)
rdpq_clear_z(0xFFFC);
}
void Gfx_ClearColor(PackedCol color) {

View File

@ -61,7 +61,8 @@ void Gfx_BeginFrame(void) {
Platform_LogConst("FRAME");
}
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO
}
void Gfx_ClearColor(PackedCol color) {

View File

@ -298,7 +298,8 @@ void Gfx_SetAlphaBlending(cc_bool enabled) {
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO clear only some buffers
q = draw_disable_tests(q, 0, &fb_depth);
q = draw_clear(q, 0, 2048.0f - fb_color.width / 2.0f, 2048.0f - fb_color.height / 2.0f,
fb_color.width, fb_color.height, clearR, clearG, clearB);

View File

@ -432,9 +432,12 @@ void Gfx_BeginFrame(void) {
gcmResetFlipStatus();
}
void Gfx_Clear(void) {
rsxClearSurface(context, GCM_CLEAR_R | GCM_CLEAR_G | GCM_CLEAR_B | GCM_CLEAR_A
| GCM_CLEAR_S | GCM_CLEAR_Z);
void Gfx_ClearBuffers(GfxBuffers buffers) {
int targets = 0;
if (buffers & GFX_BUFFER_COLOR) targets |= (GCM_CLEAR_R | GCM_CLEAR_G | GCM_CLEAR_B | GCM_CLEAR_A);
if (buffers & GFX_BUFFER_DEPTH) targets |= (GCM_CLEAR_S | GCM_CLEAR_Z);
rsxClearSurface(context, targets);
}
void Gfx_EndFrame(void) {

View File

@ -250,7 +250,14 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_BeginFrame(void) {
sceGuStart(GU_DIRECT, list);
}
void Gfx_Clear(void) { sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); }
void Gfx_ClearBuffers(GfxBuffers buffers) {
int targets = 0;
if (buffers & GFX_BUFFER_COLOR) targets |= GU_COLOR_BUFFER_BIT;
if (buffers & GFX_BUFFER_DEPTH) targets |= GU_DEPTH_BUFFER_BIT;
sceGuClear(targets);
}
void Gfx_EndFrame(void) {
sceGuFinish();

View File

@ -1117,7 +1117,8 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
}
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO clear only some buffers
static struct GPUBuffer* clearVB;
if (!clearVB) {
clearVB = GPUBuffer_Alloc(4 * sizeof(struct VertexColoured));

View File

@ -131,11 +131,15 @@ void Gfx_SetAlphaBlending(cc_bool enabled) {
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
int i, size = width * height;
for (i = 0; i < size; i++) colorBuffer[i] = clearColor;
for (i = 0; i < size; i++) depthBuffer[i] = 1.0f;
if (buffers & GFX_BUFFER_COLOR) {
for (i = 0; i < size; i++) colorBuffer[i] = clearColor;
}
if (buffers & GFX_BUFFER_DEPTH) {
for (i = 0; i < size; i++) depthBuffer[i] = 1.0f;
}
}
void Gfx_ClearColor(PackedCol color) {

View File

@ -267,7 +267,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_BeginFrame(void) {
}
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO
}
void Gfx_EndFrame(void) {

View File

@ -368,15 +368,17 @@ void Gfx_BeginFrame(void) {
pb_target_back_buffer();
}
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
int width = pb_back_buffer_width();
int height = pb_back_buffer_height();
// TODO do ourselves
pb_erase_depth_stencil_buffer(0, 0, width, height);
pb_fill(0, 0, width, height, clearColor);
//pb_erase_text_screen();
if (buffers & GFX_BUFFER_DEPTH)
pb_erase_depth_stencil_buffer(0, 0, width, height);
if (buffers & GFX_BUFFER_COLOR)
pb_fill(0, 0, width, height, clearColor);
//pb_erase_text_screen();
while (pb_busy()) { } // Wait for completion TODO: necessary??
}

View File

@ -345,7 +345,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
void Gfx_BeginFrame(void) {
}
void Gfx_Clear(void) {
void Gfx_ClearBuffers(GfxBuffers buffers) {
// TODO clear only some buffers
// Xe_Clear is just a Resolve anyways
}

View File

@ -333,7 +333,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) {
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
// TODO test
Gfx_BeginFrame();
Gfx_Clear();
Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH);
// TODO: Only transfer dirty region instead of the entire bitmap
Gfx_TransferImage(fb_offset, bmp->width, bmp->height);
Gfx_EndFrame();

View File

@ -297,8 +297,12 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
}
void Gfx_BeginFrame(void) { }
void Gfx_Clear(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
void Gfx_ClearBuffers(GfxBuffers buffers) {
int targets = 0;
if (buffers & GFX_BUFFER_COLOR) targets |= GL_COLOR_BUFFER_BIT;
if (buffers & GFX_BUFFER_DEPTH) targets |= GL_DEPTH_BUFFER_BIT;
glClear(targets);
}
void Gfx_EndFrame(void) {