From 3671c6c0eb329bf8d351d4ecab2d936565e10a20 Mon Sep 17 00:00:00 2001 From: Nick Girardo Date: Wed, 29 Jan 2025 19:22:17 -0500 Subject: [PATCH] Update vram and gram on palette swap --- src/gte.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/gte.cpp b/src/gte.cpp index f97c9e7..3e3263d 100644 --- a/src/gte.cpp +++ b/src/gte.cpp @@ -827,6 +827,23 @@ bool checkHotkey(SDL_Keycode key) { #define EM_BOOL int #endif +// Force a redraw of the sdl surfaces for vRAM and gRAM +// This is useful when the entire screen needs to be redrawn following a palette swap +void redrawVramGramSurfaces() { + int vramSize = vRAM_Surface->w * vRAM_Surface->h; + int gramSize = gRAM_Surface->w * gRAM_Surface->h; + Uint32 *vramPixels = (Uint32 *)vRAM_Surface->pixels; + Uint32 *gramPixels = (Uint32 *)gRAM_Surface->pixels; + + for (int i; i < vramSize; i++) { + vramPixels[i] = Palette::ConvertColor(vRAM_Surface, system_state.vram[i]); + } + + for (int i; i < gramSize; i++) { + gramPixels[i] = Palette::ConvertColor(gRAM_Surface, system_state.gram[i]); + } +} + void refreshScreen() { SDL_Rect src, dest; int scr_w, scr_h; @@ -869,11 +886,13 @@ void refreshScreen() { ImGui::SliderInt("Volume", &AudioCoprocessor::singleton_acp_state->volume, 0, 256); ImGui::Checkbox("Mute", &AudioCoprocessor::singleton_acp_state->isMuted); if(ImGui::BeginMenu("Pallete")) { - ImGui::RadioButton("Unscaled Capture", &palette_select, PALETTE_SELECT_CAPTURE); - ImGui::RadioButton("Full Contrast", &palette_select, PALETTE_SELECT_SCALED); - ImGui::RadioButton("Cheap HDMI converter", &palette_select, PALETTE_SELECT_HDMI); - ImGui::RadioButton("Flawed Theory (Legacy)", &palette_select, PALETTE_SELECT_OLD); - ImGui::EndMenu(); + if (ImGui::RadioButton("Unscaled Capture", &palette_select, PALETTE_SELECT_CAPTURE) || + ImGui::RadioButton("Full Contrast", &palette_select, PALETTE_SELECT_SCALED) || + ImGui::RadioButton("Cheap HDMI converter", &palette_select, PALETTE_SELECT_HDMI) || + ImGui::RadioButton("Flawed Theory (Legacy)", &palette_select, PALETTE_SELECT_OLD)) { + redrawVramGramSurfaces(); + } + ImGui::EndMenu(); } ImGui::EndMenu(); }