mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
Change Gfx_Clear to allow separately clearing colour and depth buffer
This commit is contained in:
parent
b7bde85cd4
commit
551dfa716f
@ -625,7 +625,7 @@ static void Game_RenderFrame(double delta) {
|
|||||||
|
|
||||||
/* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */
|
/* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */
|
||||||
if (Window_Main.Inactive) return;
|
if (Window_Main.Inactive) return;
|
||||||
Gfx_Clear();
|
Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH);
|
||||||
|
|
||||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
|
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
|
||||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View);
|
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View);
|
||||||
|
@ -70,6 +70,11 @@ extern const cc_string Gfx_LowPerfMessage;
|
|||||||
#define GFX_MAX_INDICES (65536 / 4 * 6)
|
#define GFX_MAX_INDICES (65536 / 4 * 6)
|
||||||
#define GFX_MAX_VERTICES 65536
|
#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) */
|
/* Texture should persist across gfx context loss (if backend supports ManagedTextures) */
|
||||||
#define TEXTURE_FLAG_MANAGED 0x01
|
#define TEXTURE_FLAG_MANAGED 0x01
|
||||||
/* Texture should allow updating via Gfx_UpdateTexture */
|
/* 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 */
|
/* Sets whether blending between the alpha components of texture and vertex colour is performed */
|
||||||
CC_API void Gfx_SetAlphaArgBlend(cc_bool enabled);
|
CC_API void Gfx_SetAlphaArgBlend(cc_bool enabled);
|
||||||
|
|
||||||
/* Clears the colour and depth buffer to default */
|
/* Clears the given rendering buffer(s) to default. */
|
||||||
CC_API void Gfx_Clear(void);
|
/* 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 */
|
/* Sets the colour that the colour buffer is cleared to */
|
||||||
CC_API void Gfx_ClearColor(PackedCol color);
|
CC_API void Gfx_ClearColor(PackedCol color);
|
||||||
/* Sets whether pixels may be discard based on z/depth */
|
/* Sets whether pixels may be discard based on z/depth */
|
||||||
|
@ -426,9 +426,13 @@ void Gfx_BeginFrame(void) {
|
|||||||
C3D_FrameDrawOn(topTarget);
|
C3D_FrameDrawOn(topTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
C3D_RenderTargetClear(topTarget, C3D_CLEAR_ALL, clear_color, 0);
|
int targets = 0;
|
||||||
C3D_RenderTargetClear(bottomTarget, C3D_CLEAR_ALL, 0, 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) {
|
void Gfx_EndFrame(void) {
|
||||||
|
@ -899,9 +899,13 @@ static float gfx_clearColor[4];
|
|||||||
static cc_bool gfx_alphaBlending, gfx_colorEnabled = true;
|
static cc_bool gfx_alphaBlending, gfx_colorEnabled = true;
|
||||||
static cc_bool gfx_depthTest, gfx_depthWrite;
|
static cc_bool gfx_depthTest, gfx_depthWrite;
|
||||||
|
|
||||||
static void OM_Clear(void) {
|
static void OM_Clear(GfxBuffers buffers) {
|
||||||
|
if (buffers & GFX_BUFFER_COLOR) {
|
||||||
ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer, gfx_clearColor);
|
ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer, gfx_clearColor);
|
||||||
|
}
|
||||||
|
if (buffers & GFX_BUFFER_DEPTH) {
|
||||||
ID3D11DeviceContext_ClearDepthStencilView(context, depthbufferView, D3D11_CLEAR_DEPTH, 0.0f, 0);
|
ID3D11DeviceContext_ClearDepthStencilView(context, depthbufferView, D3D11_CLEAR_DEPTH, 0.0f, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OM_UpdateTarget(void) {
|
static void OM_UpdateTarget(void) {
|
||||||
@ -1108,7 +1112,10 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
gfx_vsync = vsync;
|
gfx_vsync = vsync;
|
||||||
}
|
}
|
||||||
void Gfx_BeginFrame(void) { OM_UpdateTarget(); }
|
void Gfx_BeginFrame(void) { OM_UpdateTarget(); }
|
||||||
void Gfx_Clear(void) { OM_Clear(); }
|
|
||||||
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
|
OM_Clear(buffers);
|
||||||
|
}
|
||||||
|
|
||||||
void Gfx_EndFrame(void) {
|
void Gfx_EndFrame(void) {
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present
|
// https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present
|
||||||
|
@ -844,9 +844,12 @@ void Gfx_BeginFrame(void) {
|
|||||||
IDirect3DDevice9_BeginScene(device);
|
IDirect3DDevice9_BeginScene(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
DWORD flags = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER;
|
DWORD targets = 0;
|
||||||
cc_result res = IDirect3DDevice9_Clear(device, 0, NULL, flags, gfx_clearColor, 0.0f, 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");
|
if (res) Logger_Abort2(res, "D3D9_Clear");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,7 +531,9 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_BeginFrame(void) { }
|
void Gfx_BeginFrame(void) { }
|
||||||
void Gfx_Clear(void) {
|
|
||||||
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
|
// TODO clear only some buffers
|
||||||
// no need to use glClear
|
// no need to use glClear
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
void Gfx_BeginFrame(void) {
|
void Gfx_BeginFrame(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
|
// TODO clear only some buffers
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_EndFrame(void) {
|
void Gfx_EndFrame(void) {
|
||||||
|
@ -90,9 +90,13 @@ void Gfx_BeginFrame(void) {
|
|||||||
|
|
||||||
extern void __rdpq_autosync_change(int mode);
|
extern void __rdpq_autosync_change(int mode);
|
||||||
static color_t gfx_clearColor;
|
static color_t gfx_clearColor;
|
||||||
void Gfx_Clear(void) {
|
|
||||||
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
__rdpq_autosync_change(AUTOSYNC_PIPE);
|
__rdpq_autosync_change(AUTOSYNC_PIPE);
|
||||||
|
|
||||||
|
if (buffers & GFX_BUFFER_COLOR)
|
||||||
rdpq_clear(gfx_clearColor);
|
rdpq_clear(gfx_clearColor);
|
||||||
|
if (buffers & GFX_BUFFER_DEPTH)
|
||||||
rdpq_clear_z(0xFFFC);
|
rdpq_clear_z(0xFFFC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ void Gfx_BeginFrame(void) {
|
|||||||
Platform_LogConst("FRAME");
|
Platform_LogConst("FRAME");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_ClearColor(PackedCol color) {
|
void Gfx_ClearColor(PackedCol color) {
|
||||||
|
@ -298,7 +298,8 @@ void Gfx_SetAlphaBlending(cc_bool enabled) {
|
|||||||
|
|
||||||
void Gfx_SetAlphaArgBlend(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_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,
|
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);
|
fb_color.width, fb_color.height, clearR, clearG, clearB);
|
||||||
|
@ -432,9 +432,12 @@ void Gfx_BeginFrame(void) {
|
|||||||
gcmResetFlipStatus();
|
gcmResetFlipStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
rsxClearSurface(context, GCM_CLEAR_R | GCM_CLEAR_G | GCM_CLEAR_B | GCM_CLEAR_A
|
int targets = 0;
|
||||||
| GCM_CLEAR_S | GCM_CLEAR_Z);
|
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) {
|
void Gfx_EndFrame(void) {
|
||||||
|
@ -250,7 +250,14 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
void Gfx_BeginFrame(void) {
|
void Gfx_BeginFrame(void) {
|
||||||
sceGuStart(GU_DIRECT, list);
|
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) {
|
void Gfx_EndFrame(void) {
|
||||||
sceGuFinish();
|
sceGuFinish();
|
||||||
|
@ -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;
|
static struct GPUBuffer* clearVB;
|
||||||
if (!clearVB) {
|
if (!clearVB) {
|
||||||
clearVB = GPUBuffer_Alloc(4 * sizeof(struct VertexColoured));
|
clearVB = GPUBuffer_Alloc(4 * sizeof(struct VertexColoured));
|
||||||
|
@ -131,11 +131,15 @@ void Gfx_SetAlphaBlending(cc_bool enabled) {
|
|||||||
|
|
||||||
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
|
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
int i, size = width * height;
|
int i, size = width * height;
|
||||||
|
|
||||||
|
if (buffers & GFX_BUFFER_COLOR) {
|
||||||
for (i = 0; i < size; i++) colorBuffer[i] = clearColor;
|
for (i = 0; i < size; i++) colorBuffer[i] = clearColor;
|
||||||
|
}
|
||||||
|
if (buffers & GFX_BUFFER_DEPTH) {
|
||||||
for (i = 0; i < size; i++) depthBuffer[i] = 1.0f;
|
for (i = 0; i < size; i++) depthBuffer[i] = 1.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_ClearColor(PackedCol color) {
|
void Gfx_ClearColor(PackedCol color) {
|
||||||
|
@ -267,7 +267,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
void Gfx_BeginFrame(void) {
|
void Gfx_BeginFrame(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_EndFrame(void) {
|
void Gfx_EndFrame(void) {
|
||||||
|
@ -368,15 +368,17 @@ void Gfx_BeginFrame(void) {
|
|||||||
pb_target_back_buffer();
|
pb_target_back_buffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
int width = pb_back_buffer_width();
|
int width = pb_back_buffer_width();
|
||||||
int height = pb_back_buffer_height();
|
int height = pb_back_buffer_height();
|
||||||
|
|
||||||
// TODO do ourselves
|
// TODO do ourselves
|
||||||
|
if (buffers & GFX_BUFFER_DEPTH)
|
||||||
pb_erase_depth_stencil_buffer(0, 0, width, height);
|
pb_erase_depth_stencil_buffer(0, 0, width, height);
|
||||||
|
if (buffers & GFX_BUFFER_COLOR)
|
||||||
pb_fill(0, 0, width, height, clearColor);
|
pb_fill(0, 0, width, height, clearColor);
|
||||||
//pb_erase_text_screen();
|
|
||||||
|
|
||||||
|
//pb_erase_text_screen();
|
||||||
while (pb_busy()) { } // Wait for completion TODO: necessary??
|
while (pb_busy()) { } // Wait for completion TODO: necessary??
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +345,8 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
void Gfx_BeginFrame(void) {
|
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
|
// Xe_Clear is just a Resolve anyways
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
|||||||
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
||||||
// TODO test
|
// TODO test
|
||||||
Gfx_BeginFrame();
|
Gfx_BeginFrame();
|
||||||
Gfx_Clear();
|
Gfx_ClearBuffers(GFX_BUFFER_COLOR | GFX_BUFFER_DEPTH);
|
||||||
// TODO: Only transfer dirty region instead of the entire bitmap
|
// TODO: Only transfer dirty region instead of the entire bitmap
|
||||||
Gfx_TransferImage(fb_offset, bmp->width, bmp->height);
|
Gfx_TransferImage(fb_offset, bmp->width, bmp->height);
|
||||||
Gfx_EndFrame();
|
Gfx_EndFrame();
|
||||||
|
@ -297,8 +297,12 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_BeginFrame(void) { }
|
void Gfx_BeginFrame(void) { }
|
||||||
void Gfx_Clear(void) {
|
void Gfx_ClearBuffers(GfxBuffers buffers) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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) {
|
void Gfx_EndFrame(void) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user