mirror of
https://github.com/perfect-dark-pc-port/perfect_dark.git
synced 2026-10-24 00:02:43 +02:00
port: more gfx_pc cleanup
This commit is contained in:
1 parent
dca1e1752b
commit
536c766793
2 files changed
+12
-187
No files matched your search
+12
-179
@@ -55,8 +55,7 @@ using namespace std;
|
||||
#define RATIO_Y (gfx_current_dimensions.height / (float)SCREEN_HEIGHT)
|
||||
|
||||
#define MAX_BUFFERED 256
|
||||
// #define MAX_LIGHTS 2
|
||||
#define MAX_LIGHTS 32
|
||||
#define MAX_LIGHTS 4
|
||||
#define MAX_VERTICES 128
|
||||
#define MAX_VERTEX_COLORS 64
|
||||
|
||||
@@ -235,7 +234,6 @@ static size_t buf_vbo_num_tris;
|
||||
static struct GfxWindowManagerAPI* gfx_wapi;
|
||||
static struct GfxRenderingAPI* gfx_rapi;
|
||||
|
||||
static int markerOn;
|
||||
static uintptr_t segmentPointers[16];
|
||||
|
||||
struct FBInfo {
|
||||
@@ -1195,8 +1193,6 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
||||
struct LoadedVertex* v3 = &rsp.loaded_vertices[vtx3_idx];
|
||||
struct LoadedVertex* v_arr[3] = { v1, v2, v3 };
|
||||
|
||||
// if (rand()%2) return;
|
||||
|
||||
if ((rsp.extra_geometry_mode & G_NO_CLIPPING_EXT) == 0) {
|
||||
if (v1->clip_rej & v2->clip_rej & v3->clip_rej) {
|
||||
// The whole triangle lies outside the visible area
|
||||
@@ -1274,20 +1270,18 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
||||
rdp.viewport_or_scissor_changed = false;
|
||||
}
|
||||
|
||||
uint64_t cc_id = rdp.combine_mode;
|
||||
uint64_t cc_options = 0;
|
||||
bool use_alpha =
|
||||
(rdp.other_mode_l & (3 << 20)) == (G_BL_CLR_MEM << 20) && (rdp.other_mode_l & (3 << 16)) == (G_BL_1MA << 16);
|
||||
bool use_fog = ((rdp.other_mode_l >> 30) == G_BL_CLR_FOG) || ((rdp.other_mode_l >> 26) == G_BL_A_FOG);
|
||||
bool texture_edge = (rdp.other_mode_l & CVG_X_ALPHA) == CVG_X_ALPHA;
|
||||
bool use_noise = (rdp.other_mode_l & (3U << G_MDSFT_ALPHACOMPARE)) == G_AC_DITHER;
|
||||
bool use_2cyc = (rdp.other_mode_h & (3U << G_MDSFT_CYCLETYPE)) == G_CYC_2CYCLE;
|
||||
bool alpha_threshold = (rdp.other_mode_l & (3U << G_MDSFT_ALPHACOMPARE)) == G_AC_THRESHOLD;
|
||||
bool invisible =
|
||||
(rdp.other_mode_l & (3 << 24)) == (G_BL_0 << 24) && (rdp.other_mode_l & (3 << 20)) == (G_BL_CLR_MEM << 20);
|
||||
bool use_grayscale = rdp.grayscale;
|
||||
bool use_modulate = use_alpha && (rsp.extra_geometry_mode & G_MODULATE_EXT) != 0;
|
||||
bool use_blur = (rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) == G_TF_BLUR_EXT;
|
||||
const bool use_fog = ((rdp.other_mode_l >> 30) == G_BL_CLR_FOG) || ((rdp.other_mode_l >> 26) == G_BL_A_FOG);
|
||||
const bool texture_edge = (rdp.other_mode_l & CVG_X_ALPHA) == CVG_X_ALPHA;
|
||||
const bool use_noise = (rdp.other_mode_l & (3U << G_MDSFT_ALPHACOMPARE)) == G_AC_DITHER;
|
||||
const bool use_2cyc = (rdp.other_mode_h & (3U << G_MDSFT_CYCLETYPE)) == G_CYC_2CYCLE;
|
||||
const bool alpha_threshold = (rdp.other_mode_l & (3U << G_MDSFT_ALPHACOMPARE)) == G_AC_THRESHOLD;
|
||||
const bool invisible = (rdp.other_mode_l & (3 << 24)) == (G_BL_0 << 24) && (rdp.other_mode_l & (3 << 20)) == (G_BL_CLR_MEM << 20);
|
||||
const bool use_grayscale = rdp.grayscale;
|
||||
const bool use_modulate = use_alpha && (rsp.extra_geometry_mode & G_MODULATE_EXT) != 0;
|
||||
const bool use_blur = (rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) == G_TF_BLUR_EXT;
|
||||
|
||||
if (texture_edge) {
|
||||
use_alpha = true;
|
||||
@@ -1489,19 +1483,9 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
||||
if (clampS) {
|
||||
buf_vbo[buf_vbo_len++] = (tex_width2[t] - 0.5f) / tex_width[t];
|
||||
}
|
||||
#ifdef __WIIU__
|
||||
else {
|
||||
buf_vbo[buf_vbo_len++] = 0.0f;
|
||||
}
|
||||
#endif
|
||||
if (clampT) {
|
||||
buf_vbo[buf_vbo_len++] = (tex_height2[t] - 0.5f) / tex_height[t];
|
||||
}
|
||||
#ifdef __WIIU__
|
||||
else {
|
||||
buf_vbo[buf_vbo_len++] = 0.0f;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (use_fog) {
|
||||
@@ -1583,27 +1567,14 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
||||
buf_vbo[buf_vbo_len++] = color->r / 255.0f;
|
||||
buf_vbo[buf_vbo_len++] = color->g / 255.0f;
|
||||
buf_vbo[buf_vbo_len++] = color->b / 255.0f;
|
||||
#ifdef __WIIU__
|
||||
// padding
|
||||
if (!use_alpha) {
|
||||
buf_vbo[buf_vbo_len++] = 1.0f;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
buf_vbo[buf_vbo_len++] = color->a / 255.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// struct RGBA *color = &v_arr[i]->color;
|
||||
// buf_vbo[buf_vbo_len++] = color->r / 255.0f;
|
||||
// buf_vbo[buf_vbo_len++] = color->g / 255.0f;
|
||||
// buf_vbo[buf_vbo_len++] = color->b / 255.0f;
|
||||
// buf_vbo[buf_vbo_len++] = color->a / 255.0f;
|
||||
}
|
||||
|
||||
if (++buf_vbo_num_tris == MAX_BUFFERED) {
|
||||
// if (++buf_vbo_num_tris == 1) {
|
||||
gfx_flush();
|
||||
}
|
||||
}
|
||||
@@ -1738,38 +1709,21 @@ static void gfx_sp_movemem(uint8_t index, uint8_t offset, const void* data) {
|
||||
rsp.lookat_enabled = (index == 0) || (rsp.lookat[1].dir[0] || rsp.lookat[1].dir[1]);
|
||||
rsp.lights_changed = true;
|
||||
break;
|
||||
#ifdef F3DEX_GBI_2
|
||||
case G_MV_LIGHT: {
|
||||
int lightidx = offset / 24 - 2;
|
||||
if (lightidx >= 0 && lightidx <= MAX_LIGHTS) { // skip lookat
|
||||
// NOTE: reads out of bounds if it is an ambient light
|
||||
memcpy(rsp.current_lights + lightidx, data, sizeof(Light_t));
|
||||
} else if (lightidx < 0) {
|
||||
memcpy(rsp.lookat + offset / 24, data, sizeof(Light_t));
|
||||
}
|
||||
break;
|
||||
}
|
||||
#else
|
||||
case G_MV_L0:
|
||||
case G_MV_L1:
|
||||
case G_MV_L2:
|
||||
// NOTE: reads out of bounds if it is an ambient light
|
||||
memcpy(rsp.current_lights + (index - G_MV_L0) / 2, data, sizeof(Light_t));
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_sp_moveword(uint8_t index, uint16_t offset, uintptr_t data) {
|
||||
switch (index) {
|
||||
case G_MW_NUMLIGHT:
|
||||
#ifdef F3DEX_GBI_2
|
||||
rsp.current_num_lights = data / 24 + 1; // add ambient light
|
||||
#else
|
||||
// Ambient light is included
|
||||
// The 31th bit is a flag that lights should be recalculated
|
||||
rsp.current_num_lights = (data - 0x80000000U) / 32;
|
||||
#endif
|
||||
rsp.lights_changed = 1;
|
||||
break;
|
||||
case G_MW_FOG:
|
||||
@@ -1986,38 +1940,6 @@ static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t
|
||||
rdp.textures_changed[0] = rdp.textures_changed[1] = true;
|
||||
}
|
||||
|
||||
/*static uint8_t color_comb_component(uint32_t v) {
|
||||
switch (v) {
|
||||
case G_CCMUX_TEXEL0:
|
||||
return CC_TEXEL0;
|
||||
case G_CCMUX_TEXEL1:
|
||||
return CC_TEXEL1;
|
||||
case G_CCMUX_PRIMITIVE:
|
||||
return CC_PRIM;
|
||||
case G_CCMUX_SHADE:
|
||||
return CC_SHADE;
|
||||
case G_CCMUX_ENVIRONMENT:
|
||||
return CC_ENV;
|
||||
case G_CCMUX_TEXEL0_ALPHA:
|
||||
return CC_TEXEL0A;
|
||||
case G_CCMUX_LOD_FRACTION:
|
||||
return CC_LOD;
|
||||
default:
|
||||
return CC_0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t color_comb(uint32_t a, uint32_t b, uint32_t c, uint32_t d) {
|
||||
return color_comb_component(a) |
|
||||
(color_comb_component(b) << 3) |
|
||||
(color_comb_component(c) << 6) |
|
||||
(color_comb_component(d) << 9);
|
||||
}
|
||||
|
||||
static void gfx_dp_set_combine_mode(uint32_t rgb, uint32_t alpha) {
|
||||
rdp.combine_mode = rgb | (alpha << 12);
|
||||
}*/
|
||||
|
||||
static void gfx_dp_set_combine_mode(uint32_t rgb, uint32_t alpha, uint32_t rgb_cyc2, uint32_t alpha_cyc2) {
|
||||
rdp.combine_mode = rgb | (alpha << 16) | ((uint64_t)rgb_cyc2 << 28) | ((uint64_t)alpha_cyc2 << 44);
|
||||
}
|
||||
@@ -2147,7 +2069,6 @@ static void gfx_draw_rectangle(int32_t ulx, int32_t uly, int32_t lrx, int32_t lr
|
||||
|
||||
static void gfx_dp_texture_rectangle(int32_t ulx, int32_t uly, int32_t lrx, int32_t lry, uint8_t tile, int16_t uls,
|
||||
int16_t ult, int16_t dsdx, int16_t dtdy, bool flip) {
|
||||
// printf("render %d at %d\n", tile, lrx);
|
||||
uint64_t saved_combine_mode = rdp.combine_mode;
|
||||
if ((rdp.other_mode_h & (3U << G_MDSFT_CYCLETYPE)) == G_CYC_COPY) {
|
||||
// Per RDP Command Summary Set Tile's shift s and this dsdx should be set to 4 texels
|
||||
@@ -2357,49 +2278,23 @@ static void gfx_run_dl(Gfx* cmd) {
|
||||
case G_NOOP:
|
||||
break;
|
||||
case G_MTX: {
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_matrix(C0(0, 8) ^ G_MTX_PUSH, (const int32_t*)seg_addr(cmd->words.w1));
|
||||
#else
|
||||
gfx_sp_matrix(C0(16, 8), (const int32_t*)seg_addr(cmd->words.w1));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case (uint8_t)G_POPMTX:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_pop_matrix(cmd->words.w1 / 64);
|
||||
#else
|
||||
gfx_sp_pop_matrix(1);
|
||||
#endif
|
||||
break;
|
||||
case G_MOVEMEM:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_movemem(C0(0, 8), C0(8, 8) * 8, seg_addr(cmd->words.w1));
|
||||
#else
|
||||
gfx_sp_movemem(C0(16, 8), 0, seg_addr(cmd->words.w1));
|
||||
#endif
|
||||
break;
|
||||
case (uint8_t)G_MOVEWORD:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_moveword(C0(16, 8), C0(0, 16), cmd->words.w1);
|
||||
#else
|
||||
gfx_sp_moveword(C0(0, 8), C0(8, 16), cmd->words.w1);
|
||||
#endif
|
||||
break;
|
||||
case (uint8_t)G_TEXTURE:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_texture(C1(16, 16), C1(0, 16), C0(11, 3), C0(8, 3), C0(1, 7));
|
||||
#else
|
||||
gfx_sp_texture(C1(16, 16), C1(0, 16), C0(11, 3), C0(8, 3), C0(0, 8));
|
||||
#endif
|
||||
break;
|
||||
case G_VTX:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_vertex(C0(12, 8), C0(1, 7) - C0(12, 8), (const Vtx*)seg_addr(cmd->words.w1));
|
||||
#elif defined(F3DEX_GBI) || defined(F3DLP_GBI)
|
||||
gfx_sp_vertex(C0(10, 6), C0(16, 8) / 2, (const Vtx*)seg_addr(cmd->words.w1));
|
||||
#else
|
||||
gfx_sp_vertex(C0(0, 16) / sizeof(Vtx), C0(16, 4), (const Vtx*)seg_addr(cmd->words.w1));
|
||||
#endif
|
||||
break;
|
||||
case G_DL:
|
||||
if (C0(16, 1) == 0) {
|
||||
@@ -2415,17 +2310,7 @@ static void gfx_run_dl(Gfx* cmd) {
|
||||
}
|
||||
break;
|
||||
case (uint8_t)G_ENDDL:
|
||||
|
||||
// if (markerOn)
|
||||
// printf("END DL ON MARKER\n");
|
||||
|
||||
markerOn = false;
|
||||
return;
|
||||
#ifdef F3DEX_GBI_2
|
||||
case G_GEOMETRYMODE:
|
||||
gfx_sp_geometry_mode(~C0(0, 24), cmd->words.w1);
|
||||
break;
|
||||
#else
|
||||
case (uint8_t)G_SETGEOMETRYMODE:
|
||||
gfx_sp_geometry_mode(0, cmd->words.w1);
|
||||
break;
|
||||
@@ -2435,43 +2320,17 @@ static void gfx_run_dl(Gfx* cmd) {
|
||||
case G_EXTRAGEOMETRYMODE_EXT:
|
||||
gfx_sp_extra_geometry_mode(~C0(0, 24), cmd->words.w1);
|
||||
break;
|
||||
#endif
|
||||
case (uint8_t)G_TRI1:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_tri1(C0(16, 8) / 2, C0(8, 8) / 2, C0(0, 8) / 2, false);
|
||||
#elif defined(F3DEX_GBI) || defined(F3DLP_GBI)
|
||||
gfx_sp_tri1(C1(16, 8) / 2, C1(8, 8) / 2, C1(0, 8) / 2, false);
|
||||
#else
|
||||
gfx_sp_tri1(C1(16, 8) / 10, C1(8, 8) / 10, C1(0, 8) / 10, false);
|
||||
#endif
|
||||
break;
|
||||
#ifdef F3DEX_GBI_2
|
||||
case G_QUAD: {
|
||||
[[fallthrough]];
|
||||
}
|
||||
#endif
|
||||
#if defined(F3DEX_GBI) || defined(F3DLP_GBI)
|
||||
case (uint8_t)G_TRI2:
|
||||
gfx_sp_tri1(C0(16, 8) / 2, C0(8, 8) / 2, C0(0, 8) / 2, false);
|
||||
gfx_sp_tri1(C1(16, 8) / 2, C1(8, 8) / 2, C1(0, 8) / 2, false);
|
||||
break;
|
||||
#endif
|
||||
case (uint8_t)G_TRI4:
|
||||
gfx_sp_tri4(cmd);
|
||||
break;
|
||||
case (uint8_t)G_SETOTHERMODE_L:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_set_other_mode(31 - C0(8, 8) - C0(0, 8), C0(0, 8) + 1, cmd->words.w1);
|
||||
#else
|
||||
gfx_sp_set_other_mode(C0(8, 8), C0(0, 8), cmd->words.w1);
|
||||
#endif
|
||||
break;
|
||||
case (uint8_t)G_SETOTHERMODE_H:
|
||||
#ifdef F3DEX_GBI_2
|
||||
gfx_sp_set_other_mode(63 - C0(8, 8) - C0(0, 8), C0(0, 8) + 1, (uint64_t)cmd->words.w1 << 32);
|
||||
#else
|
||||
gfx_sp_set_other_mode(C0(8, 8) + 32, C0(0, 8), (uint64_t)cmd->words.w1 << 32);
|
||||
#endif
|
||||
break;
|
||||
case G_COL:
|
||||
gfx_sp_set_vertex_colors(C0(0, 16) / 4, (NormalColor *)seg_addr(cmd->words.w1));
|
||||
@@ -2534,19 +2393,6 @@ static void gfx_run_dl(Gfx* cmd) {
|
||||
case G_TEXRECTFLIP: {
|
||||
int32_t lrx, lry, tile, ulx, uly;
|
||||
uint32_t uls, ult, dsdx, dtdy;
|
||||
#ifdef F3DEX_GBI_2E
|
||||
lrx = (int32_t)(C0(0, 24) << 8) >> 8;
|
||||
lry = (int32_t)(C1(0, 24) << 8) >> 8;
|
||||
tile = C1(24, 3);
|
||||
++cmd;
|
||||
ulx = (int32_t)(C0(0, 24) << 8) >> 8;
|
||||
uly = (int32_t)(C1(0, 24) << 8) >> 8;
|
||||
++cmd;
|
||||
uls = C0(16, 16);
|
||||
ult = C0(0, 16);
|
||||
dsdx = C1(16, 16);
|
||||
dtdy = C1(0, 16);
|
||||
#else
|
||||
lrx = C0(12, 12);
|
||||
lry = C0(0, 12);
|
||||
tile = C1(24, 3);
|
||||
@@ -2558,26 +2404,12 @@ static void gfx_run_dl(Gfx* cmd) {
|
||||
++cmd;
|
||||
dsdx = C1(16, 16);
|
||||
dtdy = C1(0, 16);
|
||||
#endif
|
||||
gfx_dp_texture_rectangle(ulx, uly, lrx, lry, tile, uls, ult, dsdx, dtdy, opcode == G_TEXRECTFLIP);
|
||||
break;
|
||||
}
|
||||
case G_FILLRECT:
|
||||
#ifdef F3DEX_GBI_2E
|
||||
{
|
||||
int32_t lrx, lry, ulx, uly;
|
||||
lrx = (int32_t)(C0(0, 24) << 8) >> 8;
|
||||
lry = (int32_t)(C1(0, 24) << 8) >> 8;
|
||||
++cmd;
|
||||
ulx = (int32_t)(C0(0, 24) << 8) >> 8;
|
||||
uly = (int32_t)(C1(0, 24) << 8) >> 8;
|
||||
gfx_dp_fill_rectangle(ulx, uly, lrx, lry);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
gfx_dp_fill_rectangle(C1(12, 12), C1(0, 12), C0(12, 12), C0(0, 12));
|
||||
break;
|
||||
#endif
|
||||
case G_FILLRECT_WIDE_EXT: {
|
||||
int32_t lrx, lry, ulx, uly;
|
||||
lrx = (int32_t)(C0(0, 24) << 8) >> 8;
|
||||
@@ -2663,8 +2495,9 @@ static void gfx_run_dl(Gfx* cmd) {
|
||||
case (uint8_t)G_RDPHALF_1:
|
||||
case (uint8_t)G_RDPHALF_2:
|
||||
case (uint8_t)G_RDPHALF_CONT:
|
||||
// TODO: skyRender uses these to render some types of skies and skybox water
|
||||
// on N64 skyRender uses these to render some types of skies and skybox water
|
||||
// by issuing low-level ucode commands G_TRI_FILL and G_TRI_SHADE_TXTR
|
||||
// the port renders the sky in a different manner
|
||||
break;
|
||||
case G_RDPFLUSH_EXT:
|
||||
gfx_flush();
|
||||
|
||||
@@ -4594,20 +4594,12 @@ Gfx *playerRenderHud(Gfx *gdl)
|
||||
&& ((g_Vars.currentplayer->devicesactive & ~g_Vars.currentplayer->devicesinhibit) & DEVICE_NIGHTVISION)) {
|
||||
gdl = bviewDrawNvLens(gdl);
|
||||
gdl = bviewDrawNvBinoculars(gdl);
|
||||
#ifndef PLATFORM_N64
|
||||
// turn off "greenscale"
|
||||
gDPGrayscaleEXT(gdl++, G_OFF);
|
||||
#endif
|
||||
} else if (g_Vars.currentplayer->isdead == false
|
||||
&& g_InCutscene == 0
|
||||
&& (!g_Vars.currentplayer->eyespy || (g_Vars.currentplayer->eyespy && !g_Vars.currentplayer->eyespy->active))
|
||||
&& ((g_Vars.currentplayer->devicesactive & ~g_Vars.currentplayer->devicesinhibit) & DEVICE_IRSCANNER)) {
|
||||
gdl = bviewDrawIrLens(gdl);
|
||||
gdl = bviewDrawIrBinoculars(gdl);
|
||||
#ifndef PLATFORM_N64
|
||||
// turn off "redscale"
|
||||
gDPGrayscaleEXT(gdl++, G_OFF);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (g_Vars.currentplayer->eyesshutfrac > 0) {
|
||||
|
||||
Reference in new issue
Block a user