Skip to content

Commit

Permalink
depth mask affects gl clear
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanr13 committed Dec 14, 2024
1 parent 9f255ba commit 3468a85
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include <sys/stat.h>
#include <unistd.h>

#ifdef USE_TFD
#include "tinyfiledialogs/tinyfiledialogs.h"
#endif

#include "3ds.h"
#include "emulator.h"
#include "services/hid.h"
Expand Down
35 changes: 22 additions & 13 deletions src/pica/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ void gpu_update_cur_fb(GPU* gpu) {
gpu->cur_fb->color_fmt = gpu->io.fb.colorbuf_fmt.fmt & 7;
gpu->cur_fb->color_Bpp = gpu->io.fb.colorbuf_fmt.size + 2;

linfo("drawing on fb %d at %x", gpu->cur_fb - gpu->fbs.d,
gpu->cur_fb->color_paddr);
linfo("drawing on fb %d at %x with depth buffer at %x",
gpu->cur_fb - gpu->fbs.d, gpu->cur_fb->color_paddr,
gpu->cur_fb->depth_paddr);

glBindFramebuffer(GL_FRAMEBUFFER, gpu->cur_fb->fbo);

Expand Down Expand Up @@ -387,12 +388,19 @@ void gpu_display_transfer(GPU* gpu, u32 paddr, int yoff, bool scalex,
}

void gpu_clear_fb(GPU* gpu, u32 paddr, u32 color) {
// some of the current gl state can affect gl clear
// so we need to reset it
glDisable(GL_SCISSOR_TEST);
glColorMask(true, true, true, true);
glDepthMask(true);
// right now we assume clear color is rgba8888 and d24s8 format, this should
// be changed
for (int i = 0; i < FB_MAX; i++) {
if (gpu->fbs.d[i].color_paddr == paddr) {
LRU_use(gpu->fbs, &gpu->fbs.d[i]);
glBindFramebuffer(GL_FRAMEBUFFER, gpu->fbs.d[i].fbo);
glClearColor((color >> 24) / 256.f, ((color >> 16) & 0xff) / 256.f,
((color >> 8) & 0xff) / 256.f, (color & 0xff) / 256.f);
glClearColor((color >> 24) / 255.f, ((color >> 16) & 0xff) / 255.f,
((color >> 8) & 0xff) / 255.f, (color & 0xff) / 255.f);
glClear(GL_COLOR_BUFFER_BIT);
linfo("cleared color buffer at %x of fb %d with value %x", paddr, i,
color);
Expand All @@ -401,11 +409,11 @@ void gpu_clear_fb(GPU* gpu, u32 paddr, u32 color) {
if (gpu->fbs.d[i].depth_paddr == paddr) {
LRU_use(gpu->fbs, &gpu->fbs.d[i]);
glBindFramebuffer(GL_FRAMEBUFFER, gpu->fbs.d[i].fbo);
glClearDepthf((color & MASK(24)) / (float) (1 << 24));
glClearDepthf((color & MASK(24)) / (float) BIT(24));
glClearStencil(color >> 24);
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
linfo("cleared depth buffer at %x of fb %d with value %x", paddr, i,
color);
return;
}
}
}
Expand Down Expand Up @@ -1015,13 +1023,14 @@ void gpu_update_gl_state(GPU* gpu) {
2 * cvtf24(gpu->io.raster.view_h) * ctremu.videoscale);
if (gpu->io.raster.scisssortest.enable) {
glEnable(GL_SCISSOR_TEST);
glScissor(
gpu->io.raster.scisssortest.x1 * ctremu.videoscale,
gpu->io.raster.scisssortest.y1 * ctremu.videoscale,
(gpu->io.raster.scisssortest.x2 - gpu->io.raster.scisssortest.x1) *
ctremu.videoscale,
(gpu->io.raster.scisssortest.y2 - gpu->io.raster.scisssortest.y1) *
ctremu.videoscale);
glScissor(gpu->io.raster.scisssortest.x1 * ctremu.videoscale,
gpu->io.raster.scisssortest.y1 * ctremu.videoscale,
(gpu->io.raster.scisssortest.x2 + 1 -
gpu->io.raster.scisssortest.x1) *
ctremu.videoscale,
(gpu->io.raster.scisssortest.y2 + 1 -
gpu->io.raster.scisssortest.y1) *
ctremu.videoscale);
} else {
glDisable(GL_SCISSOR_TEST);
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/gsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ void gsp_handle_command(E3DS* s) {
addrin, pitchin, gapin, addrout, pitchout, gapout, copysize,
flags);

// texture copy can be used to copy between framebuffers and this wont work right now

u8* src = PTR(addrin);
u8* dst = PTR(addrout);

Expand Down

0 comments on commit 3468a85

Please sign in to comment.