From 5d9ca779ac6ab428b2162a2a81fc775ffca7cc31 Mon Sep 17 00:00:00 2001 From: zilmar Date: Fri, 19 May 2017 16:23:43 +1000 Subject: [PATCH] [Video] Make RDP in to a class instead of struct --- Source/Project64-video/Combine.cpp | 6 +- Source/Project64-video/Config.cpp | 14 +- Source/Project64-video/Gfx_1.3.h | 2 +- Source/Project64-video/Main.cpp | 23 +- Source/Project64-video/TexCache.cpp | 2 +- Source/Project64-video/TexMod.h | 4 +- Source/Project64-video/Util.cpp | 18 +- Source/Project64-video/rdp.cpp | 369 ++++++++++++++++++++++++---- Source/Project64-video/rdp.h | 63 +++-- 9 files changed, 377 insertions(+), 124 deletions(-) diff --git a/Source/Project64-video/Combine.cpp b/Source/Project64-video/Combine.cpp index d53e1f084..e034c5cf2 100644 --- a/Source/Project64-video/Combine.cpp +++ b/Source/Project64-video/Combine.cpp @@ -5269,7 +5269,7 @@ static void cc_t0_inter_noise_using_prim() MOD_0(TMOD_TEX_INTER_NOISE_USING_COL); MOD_0_COL(rdp.prim_color); - rdp.noise = RDP::noise_texture; + rdp.noise = CRDP::noise_texture; } static void cc_t0_inter_noise_using_env() @@ -5282,7 +5282,7 @@ static void cc_t0_inter_noise_using_env() MOD_0(TMOD_TEX_INTER_NOISE_USING_COL); MOD_0_COL(rdp.env_color); - rdp.noise = RDP::noise_texture; + rdp.noise = CRDP::noise_texture; } static void cc_t0_sub_env_mul_enva_add_env() @@ -15489,7 +15489,7 @@ void Combine() lod_frac = 10; } - rdp.noise = RDP::noise_none; + rdp.noise = CRDP::noise_none; uint32_t found = TRUE; diff --git a/Source/Project64-video/Config.cpp b/Source/Project64-video/Config.cpp index 4e18b0051..1a0b81b47 100644 --- a/Source/Project64-video/Config.cpp +++ b/Source/Project64-video/Config.cpp @@ -884,11 +884,9 @@ void CALL DllConfig(void * hParent) if (g_romopen) { - if (evoodoo)// && fullscreen && !ev_fullscreen) - { - ReleaseGfx(); - rdp_reset(); - } + ReleaseGfx(); + rdp.free(); + rdp.init(); if (g_ghq_use) { ext_ghq_shutdown(); @@ -915,11 +913,7 @@ void CloseConfig() { ZLUT_init(); } - // re-init evoodoo graphics to resize window - if (evoodoo)// && !ev_fullscreen) - InitGfx(); - else - rdp_reset(); + InitGfx(); } } diff --git a/Source/Project64-video/Gfx_1.3.h b/Source/Project64-video/Gfx_1.3.h index 8233435a4..d46627433 100644 --- a/Source/Project64-video/Gfx_1.3.h +++ b/Source/Project64-video/Gfx_1.3.h @@ -111,7 +111,7 @@ extern "C" { int NormalMemory; /* a normal uint8_t array */ int MemoryBswaped; /* a normal uint8_t array where the memory has been pre bswap on a dword (32 bits) boundry */ -} PLUGIN_INFO; + } PLUGIN_INFO; typedef struct { diff --git a/Source/Project64-video/Main.cpp b/Source/Project64-video/Main.cpp index 62d4ad948..d917ebdd3 100644 --- a/Source/Project64-video/Main.cpp +++ b/Source/Project64-video/Main.cpp @@ -68,7 +68,7 @@ uint32_t region = 0; unsigned int BMASK = 0x7FFFFF; // Reality display processor structure -RDP rdp; +CRDP rdp; CSettings * g_settings = NULL; @@ -461,8 +461,6 @@ int InitGfx() WriteTrace(TraceGlide64, TraceDebug, "-"); - rdp_reset(); - // Initialize Glide grGlideInit(); @@ -524,6 +522,8 @@ int InitGfx() grGlideShutdown(); return FALSE; } + rdp.init(); + util_init(); GfxInitDone = TRUE; to_fullscreen = FALSE; @@ -707,6 +707,8 @@ void ReleaseGfx() { WriteTrace(TraceGlide64, TraceDebug, "-"); + rdp.free(); + // Restore gamma settings if (voodoo.gamma_correction) { @@ -987,7 +989,10 @@ int CALL InitiateGFX(GFX_INFO Gfx_Info) gfx = Gfx_Info; - util_init(); + if (!rdp.init()) + { + return false; + } math_init(); TexCacheInit(); CRC_BuildTable(); @@ -1062,10 +1067,7 @@ void CALL RomClosed(void) #endif rdp.window_changed = TRUE; g_romopen = FALSE; - if (evoodoo) - { - ReleaseGfx(); - } + ReleaseGfx(); } static void CheckDRAMSize() @@ -1102,7 +1104,6 @@ void CALL RomOpen(void) no_dlist = true; g_romopen = TRUE; g_ucode_error_report = TRUE; // allowed to report ucode errors - rdp_reset(); // Get the country code & translate to NTSC(0) or PAL(1) uint16_t code = ((uint16_t*)gfx.HEADER)[0x1F ^ 1]; @@ -1147,7 +1148,6 @@ void CALL RomOpen(void) ClearCache(); CheckDRAMSize(); - // ** EVOODOO EXTENSIONS ** if (!GfxInitDone) { @@ -1161,8 +1161,7 @@ void CALL RomOpen(void) else evoodoo = 0; - if (evoodoo) - InitGfx(); + InitGfx(); } /****************************************************************** diff --git a/Source/Project64-video/TexCache.cpp b/Source/Project64-video/TexCache.cpp index 0dc2e55d1..5b14ff40e 100644 --- a/Source/Project64-video/TexCache.cpp +++ b/Source/Project64-video/TexCache.cpp @@ -409,7 +409,7 @@ void GetTexInfo(int id, int tile) CACHE_LUT *cache; - if (rdp.noise == RDP::noise_texture) + if (rdp.noise == CRDP::noise_texture) return; uint32_t mod, modcolor, modcolor1, modcolor2, modfactor; diff --git a/Source/Project64-video/TexMod.h b/Source/Project64-video/TexMod.h index c822a58dc..7cfc6a806 100644 --- a/Source/Project64-video/TexMod.h +++ b/Source/Project64-video/TexMod.h @@ -281,7 +281,7 @@ static void mod_tex_sub_col_mul_fac_add_tex(uint16_t *dst, int size, uint32_t co cg = (color >> 8) & 0xF; cb = (color >> 4) & 0xF; - for (int i = 0; i> 8) & 0xF; cb = (color >> 4) & 0xF; - for (int i = 0; i> 12) & 0xF); diff --git a/Source/Project64-video/Util.cpp b/Source/Project64-video/Util.cpp index 3435fce69..9235397be 100644 --- a/Source/Project64-video/Util.cpp +++ b/Source/Project64-video/Util.cpp @@ -1505,14 +1505,14 @@ static void render_tri(uint16_t linew, int old_interpolate) } ConvertCoordsConvert(rdp.vtxbuf, n); - if (rdp.fog_mode == RDP::fog_enabled) + if (rdp.fog_mode == CRDP::fog_enabled) { for (i = 0; i < n; i++) { rdp.vtxbuf[i].f = 1.0f / maxval(4.0f, rdp.vtxbuf[i].f); } } - else if (rdp.fog_mode == RDP::fog_blend) + else if (rdp.fog_mode == CRDP::fog_blend) { float fog = 1.0f / maxval(1, rdp.fog_color & 0xFF); for (i = 0; i < n; i++) @@ -1520,7 +1520,7 @@ static void render_tri(uint16_t linew, int old_interpolate) rdp.vtxbuf[i].f = fog; } } - else if (rdp.fog_mode == RDP::fog_blend_inverse) + else if (rdp.fog_mode == CRDP::fog_blend_inverse) { float fog = 1.0f / maxval(1, (~rdp.fog_color) & 0xFF); for (i = 0; i < n; i++) @@ -1735,7 +1735,7 @@ void update() rdp.tex_ctr = 0; TexCache(); - if (rdp.noise == RDP::noise_none) + if (rdp.noise == CRDP::noise_none) rdp.update ^= UPDATE_TEXTURE; } @@ -1888,13 +1888,13 @@ void update() { grFogColorValue(rdp.fog_color); grFogMode(GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT); - rdp.fog_mode = RDP::fog_enabled; + rdp.fog_mode = CRDP::fog_enabled; WriteTrace(TraceRDP, TraceDebug, "fog enabled "); } else { WriteTrace(TraceRDP, TraceDebug, "fog disabled in blender"); - rdp.fog_mode = RDP::fog_disabled; + rdp.fog_mode = CRDP::fog_disabled; grFogMode(GR_FOG_DISABLE); } } @@ -1902,20 +1902,20 @@ void update() { grFogColorValue(rdp.fog_color); grFogMode(GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT); - rdp.fog_mode = RDP::fog_blend; + rdp.fog_mode = CRDP::fog_blend; WriteTrace(TraceRDP, TraceDebug, "fog blend "); } else if (blender == 0x04d1) { grFogColorValue(rdp.fog_color); grFogMode(GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT); - rdp.fog_mode = RDP::fog_blend_inverse; + rdp.fog_mode = CRDP::fog_blend_inverse; WriteTrace(TraceRDP, TraceDebug, "fog blend "); } else { WriteTrace(TraceRDP, TraceDebug, "fog disabled"); - rdp.fog_mode = RDP::fog_disabled; + rdp.fog_mode = CRDP::fog_disabled; grFogMode(GR_FOG_DISABLE); } } diff --git a/Source/Project64-video/rdp.cpp b/Source/Project64-video/rdp.cpp index f58322ff5..17e2f528c 100644 --- a/Source/Project64-video/rdp.cpp +++ b/Source/Project64-video/rdp.cpp @@ -148,19 +148,313 @@ void microcheck(); static int reset = 0; static CSettings::ucode_t g_old_ucode = CSettings::uCode_Unsupported; -void RDP::Reset() +CRDP::CRDP() : + vtx1(NULL), + vtx2(NULL) { - memset(this, 0, sizeof(RDP_Base)); + free(); +} + +CRDP::~CRDP() +{ + free(); +} + +bool CRDP::init() +{ + if (vtx1 != NULL) + { + return true; + } + + vtx1 = new VERTEX[256]; + if (vtx1 == NULL) + { + free(); + return false; + } + memset(vtx1, 0, sizeof(VERTEX) * 256); + vtx2 = new VERTEX[256]; + if (vtx2 == NULL) + { + free(); + return false; + } + memset(vtx2, 0, sizeof(VERTEX) * 256); + + for (int i = 0; i < MAX_TMU; i++) + { + cache[i] = new CACHE_LUT[MAX_CACHE]; + if (cache[i] == NULL) + { + free(); + return false; + } + }; + vtx = new VERTEX[MAX_VTX]; + if (vtx == NULL) + { + free(); + return false; + } + memset(vtx, 0, sizeof(VERTEX)*MAX_VTX); // set all vertex numbers for (int i = 0; i < MAX_VTX; i++) + { vtx[i].number = i; + } - scissor_o.ul_x = 0; - scissor_o.ul_y = 0; - scissor_o.lr_x = 320; - scissor_o.lr_y = 240; + frame_buffers = new COLOR_IMAGE[NUMTEXBUF + 2]; + if (frame_buffers == NULL) + { + free(); + return false; + } + return true; +} - vi_org_reg = *gfx.VI_ORIGIN_REG; +void CRDP::free() +{ + if (vtx1) + { + delete vtx1; + vtx1 = NULL; + } + if (vtx2) + { + delete vtx2; + vtx2 = NULL; + } + clip = 0; + vtxbuf = NULL; + vtxbuf2 = NULL; + + for (int i = 0; i < MAX_TMU; i++) + { + if (cache[i] != NULL) + { + delete cache[i]; + cache[i] = NULL; + } + cur_cache[i] = 0; + cur_cache_n[i] = 0; + } + if (vtx != NULL) + { + delete[] vtx; + vtx = NULL; + } + + if (frame_buffers != NULL) + { + delete[] frame_buffers; + frame_buffers = NULL; + } + + n_global = 0; + vtx_buffer = 0; + v0 = 0; + vn = 0; + memset(RomName, 0, sizeof(RomName)); + vi_width = 0; + vi_height = 0; + + window_changed = 0; + + offset_x = 0; + offset_y = 0; + offset_x_bak = 0; + offset_y_bak = 0; + + scale_x = 0; + scale_x_bak = 0; + + scale_y = 0; + scale_y_bak = 0; + + memset(view_scale, 0, sizeof(view_scale)); + memset(view_trans, 0, sizeof(view_trans)); + clip_min_x = 0; + clip_max_x = 0; + clip_min_y = 0; + clip_max_y = 0; + clip_ratio = 0; + + updatescreen = 0; + + tri_n = 0; + debug_n = 0; + + memset(pc, 0, sizeof(pc)); + pc_i = 0; + dl_count = 0; + LLE = 0; + + memset(segment, 0, sizeof(segment)); + halt = 0; + + cmd0 = 0; + cmd1 = 0; + cmd2 = 0; + cmd3 = 0; + + memset(&scissor_o, 0, sizeof(scissor_o)); + memset(&scissor, 0, sizeof(scissor)); + fog_color = 0; + fill_color = 0; + prim_color = 0; + blend_color = 0; + env_color = 0; + SCALE = 0; + CENTER = 0; + prim_lodmin = 0; + prim_lodfrac = 0; + prim_depth = 0; + prim_dz = 0; + K4 = 0; + K5 = 0; + noise = noise_none; + + memset(col, 0, sizeof(col)); + memset(col_2, 0, sizeof(col_2)); + memset(coladd, 0, sizeof(coladd)); + shade_factor = 0; + cmb_flags = 0; + cmb_flags_2 = 0; + + memset(model, 0, sizeof(model)); + memset(proj, 0, sizeof(proj)); + memset(combined, 0, sizeof(combined)); + memset(dkrproj, 0, sizeof(dkrproj)); + memset(model_stack, 0, sizeof(model_stack)); + + model_i = 0; + model_stack_size = 0; + cur_tile = 0; + mipmap_level = 0; + last_tile = 0; + last_tile_size = 0; + + t0 = GR_TMU0; + t1 = GR_TMU0; + best_tex = 0; + tex = 0; + filter_mode = 0; + + memset(pal_8, 0, sizeof(pal_8)); + memset(pal_8_crc, 0, sizeof(pal_8_crc)); + pal_256_crc = 0; + tlut_mode = 0; + LOD_en = 0; + Persp_en = 0; + persp_supported = 0; + force_wrap = 0; + memset(pal_8_rice, 0, sizeof(pal_8_rice)); + num_lights = 0; + memset(light, 0, sizeof(light)); + memset(light_vector, 0, sizeof(light_vector)); + memset(lookat, 0, sizeof(lookat)); + use_lookat = 0; + + cycle1 = 0; + cycle2 = 0; + cycle_mode = 0; + c_a0 = 0; + c_b0 = 0; + c_c0 = 0; + c_d0 = 0; + c_Aa0 = 0; + c_Ab0 = 0; + c_Ac0 = 0; + c_Ad0 = 0; + c_a1 = 0; + c_b1 = 0; + c_c1 = 0; + c_d1 = 0; + c_Aa1 = 0; + c_Ab1 = 0; + c_Ac1 = 0; + c_Ad1 = 0; + + fbl_a0 = 0; + fbl_b0 = 0; + fbl_c0 = 0; + fbl_d0 = 0; + fbl_a1 = 0; + fbl_b1 = 0; + fbl_c1 = 0; + fbl_d1 = 0; + + uncombined = 0; + update = 0; + flags = 0; + + first = 0; + + tex_ctr = 0; + + allow_combine = 0; + + s2dex_tex_loaded = 0; + bg_image_height = 0; + + rm = 0; + render_mode_changed = 0; + geom_mode = 0; + + othermode_h = 0; + othermode_l = 0; + + texrecting = 0; + + cimg = 0; + ocimg = 0; + zimg = 0; + tmpzimg = 0; + vi_org_reg = 0; + memset(maincimg, 0, sizeof(maincimg)); + last_drawn_ci_addr = 0; + main_ci = 0; + main_ci_end = 0; + main_ci_bg = 0; + main_ci_last_tex_addr = 0; + zimg_end = 0; + last_bg = 0; + ci_width = 0; + ci_height = 0; + ci_size = 0; + ci_end = 0; + zi_width = 0; + zi_lrx = 0; + zi_lry = 0; + ci_count = 0; + num_of_ci = 0; + main_ci_index = 0; + copy_ci_index = 0; + copy_zi_index = 0; + swap_ci_index = 0; + black_ci_index = 0; + motionblur = 0; + fb_drawn = 0; + fb_drawn_front = 0; + read_previous_ci = 0; + read_whole_frame = 0; + ci_status = ci_main; + cur_image = NULL; + tbuff_tex = NULL; + memset(aTBuffTex, 0, sizeof(aTBuffTex)); + cur_tex_buf = 0; + acc_tex_buf = 0; + skip_drawing = 0; + fog_multiplier = 0; + fog_offset = 0; + fog_mode = fog_disabled; + + reset = 1; + + v0 = vn = 0; + + //vi_org_reg = *gfx.VI_ORIGIN_REG; view_scale[2] = 32.0f * 511.0f; view_trans[2] = 32.0f * 511.0f; clip_ratio = 1.0f; @@ -170,48 +464,14 @@ void RDP::Reset() cycle_mode = 2; allow_combine = 1; rdp.update = UPDATE_SCISSOR | UPDATE_COMBINE | UPDATE_ZBUF_ENABLED | UPDATE_CULL_MODE; - fog_mode = RDP::fog_enabled; + fog_mode = CRDP::fog_enabled; maincimg[0].addr = maincimg[1].addr = last_drawn_ci_addr = 0x7FFFFFFF; -} -RDP::RDP() -{ - vtx1 = new VERTEX[256]; - memset(vtx1, 0, sizeof(VERTEX) * 256); - vtx2 = new VERTEX[256]; - memset(vtx2, 0, sizeof(VERTEX) * 256); - vtxbuf = vtxbuf2 = 0; - vtx_buffer = n_global = 0; - - for (int i = 0; i < MAX_TMU; i++) - { - cache[i] = new CACHE_LUT[MAX_CACHE]; - cur_cache[i] = 0; - cur_cache_n[i] = 0; - }; - - vtx = new VERTEX[MAX_VTX]; - memset(vtx, 0, sizeof(VERTEX)*MAX_VTX); - v0 = vn = 0; - - frame_buffers = new COLOR_IMAGE[NUMTEXBUF + 2]; -} - -RDP::~RDP() -{ - delete[] vtx1; - delete[] vtx2; - for (int i = 0; i < MAX_TMU; i++) - delete[] cache[i]; - - delete[] vtx; - delete[] frame_buffers; -} - -void rdp_reset() -{ - reset = 1; - rdp.Reset(); + memset(&timg, 0, sizeof(timg)); + memset(tiles, 0, sizeof(tiles)); + memset(tmem, 0, sizeof(tmem)); + memset(addr, 0, sizeof(addr)); + memset(load_info, 0, sizeof(load_info)); } void microcheck() @@ -604,7 +864,7 @@ EXPORT void CALL ProcessDList(void) if (g_settings->ucode() == CSettings::ucode_Turbo3d) { Turbo3D(); - } + } else { // MAIN PROCESSING LOOP @@ -686,7 +946,7 @@ EXPORT void CALL ProcessDList(void) CI_SET = FALSE; } WriteTrace(TraceRDP, TraceDebug, "ProcessDList end"); -} + } // undef - undefined instruction, always ignore void undef() @@ -719,7 +979,9 @@ void ys_memrect() uint32_t ul_y = (uint16_t)((rdp.cmd1 & 0x00000FFF) >> 2); if (lr_y > rdp.scissor_o.lr_y) + { lr_y = rdp.scissor_o.lr_y; + } uint32_t off_x = ((rdp.cmd2 & 0xFFFF0000) >> 16) >> 5; uint32_t off_y = (rdp.cmd2 & 0x0000FFFF) >> 5; @@ -955,15 +1217,14 @@ void rdp_texrect() rdp.tri_n += 2; return; } - //* + //hack for Banjo2. it removes black texrects under Banjo if (!g_settings->fb_hwfbe_enabled() && ((rdp.cycle1 << 16) | (rdp.cycle2 & 0xFFFF)) == 0xFFFFFFFF && (rdp.othermode_l & 0xFFFF0000) == 0x00500000) { rdp.tri_n += 2; return; } - //*/ - //* + //remove motion blur in night vision if (g_settings->ucode() == CSettings::ucode_PerfectDark && (rdp.maincimg[1].addr != rdp.maincimg[0].addr) && (rdp.timg.addr >= rdp.maincimg[1].addr) && (rdp.timg.addr < (rdp.maincimg[1].addr + rdp.ci_width*rdp.ci_height*rdp.ci_size))) { @@ -1298,10 +1559,10 @@ void rdp_texrect() apply_shade_mods(&vptr[i]); } - if (rdp.fog_mode >= RDP::fog_blend) + if (rdp.fog_mode >= CRDP::fog_blend) { float fog; - if (rdp.fog_mode == RDP::fog_blend) + if (rdp.fog_mode == CRDP::fog_blend) fog = 1.0f / maxval(1, rdp.fog_color & 0xFF); else fog = 1.0f / maxval(1, (~rdp.fog_color) & 0xFF); diff --git a/Source/Project64-video/rdp.h b/Source/Project64-video/rdp.h index 2395c6f51..cc3487e43 100644 --- a/Source/Project64-video/rdp.h +++ b/Source/Project64-video/rdp.h @@ -350,7 +350,36 @@ typedef struct #define NUMTEXBUF 92 -struct RDP_Base { +class CRDP +{ +public: + CRDP(); + ~CRDP(); + + bool init(); + void free(); + + // Clipping + int clip; // clipping flags + VERTEX *vtx1; //[256] copy vertex buffer #1 (used for clipping) + VERTEX *vtx2; //[256] copy vertex buffer #2 + VERTEX *vtxbuf; // current vertex buffer (reset to vtx, used to determine current vertex buffer) + VERTEX *vtxbuf2; + int n_global; // Used to pass the number of vertices from clip_z to clip_tri + int vtx_buffer; + + CACHE_LUT *cache[MAX_TMU]; //[MAX_CACHE] + CACHE_LUT *cur_cache[MAX_TMU]; + uint32_t cur_cache_n[MAX_TMU]; + int n_cached[MAX_TMU]; + + // Vertices + VERTEX *vtx; //[MAX_VTX] + int v0, vn; + + COLOR_IMAGE *frame_buffers; //[NUMTEXBUF+2] + TEXTURE_BUFFER texbufs[2]; + char RomName[21]; float vi_width; float vi_height; @@ -541,41 +570,11 @@ struct RDP_Base { fog_mode; }; -struct RDP : public RDP_Base -{ - // Clipping - int clip; // clipping flags - VERTEX *vtx1; //[256] copy vertex buffer #1 (used for clipping) - VERTEX *vtx2; //[256] copy vertex buffer #2 - VERTEX *vtxbuf; // current vertex buffer (reset to vtx, used to determine current vertex buffer) - VERTEX *vtxbuf2; - int n_global; // Used to pass the number of vertices from clip_z to clip_tri - int vtx_buffer; - - CACHE_LUT *cache[MAX_TMU]; //[MAX_CACHE] - CACHE_LUT *cur_cache[MAX_TMU]; - uint32_t cur_cache_n[MAX_TMU]; - int n_cached[MAX_TMU]; - - // Vertices - VERTEX *vtx; //[MAX_VTX] - int v0, vn; - - COLOR_IMAGE *frame_buffers; //[NUMTEXBUF+2] - TEXTURE_BUFFER texbufs[2]; - - char RomName[21]; - - RDP(); - ~RDP(); - void Reset(); -}; - void SetWireframeCol(); void ChangeSize(); void GoToFullScreen(); -extern RDP rdp; +extern CRDP rdp; extern VOODOO voodoo; extern GrTexInfo fontTex;