diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index a13d5c658..39fd7a9fb 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -36,7 +36,7 @@ INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc. // Returns a pointer to the palette which should be used for caching textures. -static RGBA_t *HWR_GetTexturePalette(void) +RGBA_t *HWR_GetTexturePalette(void) { return HWR_ShouldUsePaletteRendering() ? mapPalette : pLocalPalette; } @@ -926,6 +926,7 @@ void HWR_SetPalette(RGBA_t *palette) { // set the palette for palette postprocessing + if (cv_grpalettedepth.value == 16) { // crush to 16-bit rgb565, like software currently does in the standard configuration // Note: Software's screenshots have the 24-bit palette, but the screen gets @@ -945,9 +946,13 @@ void HWR_SetPalette(RGBA_t *palette) } HWD.pfnSetScreenPalette(crushed_palette); } + else + { + HWD.pfnSetScreenPalette(palette); + } // this part is responsible for keeping track of the palette OUTSIDE of a level. - if (!(gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN))) + if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN)) HWR_SetMapPalette(); } else @@ -999,11 +1004,11 @@ void HWR_SetMapPalette(void) RGBA_t *palette; int i; - if (!(gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN))) //we dont have a master palette + if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN)) //we dont have a master palette { // outside of a level, pMasterPalette should have PLAYPAL ready for us //palette = pMasterPalette; // we dont have this in kart so just use plocalpalette as before - + palette = pLocalPalette; } else diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 99c90243e..5c43b0206 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -567,12 +567,13 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) } else // Do TRANSMAP** fade. { - if (HWR_ShouldUsePaletteRendering()) - Surf.PolyColor.rgba = pLocalPalette[color&0xFF].rgba; - else - Surf.PolyColor.rgba = pLocalPalette[color].rgba; + RGBA_t *palette = HWR_GetTexturePalette(); + Surf.PolyColor.rgba = palette[color&0xFF].rgba; - Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f); + if (HWR_ShouldUsePaletteRendering()) + Surf.PolyColor.s.alpha = softwaretranstogl[strength]; + else + Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f); } HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); @@ -748,9 +749,10 @@ void HWR_drawAMline(const fline_t *fl, INT32 color) { F2DCoord v1, v2; RGBA_t color_rgba; - - color_rgba = V_GetColor(color); - + RGBA_t *palette = HWR_GetTexturePalette(); + + color_rgba = palette[color&0xFF]; + v1.x = ((float)fl->a.x-(vid.width/2.0f))*(2.0f/vid.width); v1.y = ((float)fl->a.y-(vid.height/2.0f))*(2.0f/vid.height); @@ -768,6 +770,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh, fwait = 0; + RGBA_t *palette = HWR_GetTexturePalette(); if (wh < 0) return; // consistency w/ software @@ -848,7 +851,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) v[0].t = v[1].t = 0.0f; v[2].t = v[3].t = 1.0f; - Surf.PolyColor = V_GetColor(color); + Surf.PolyColor = palette[color&0xFF]; HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); @@ -862,6 +865,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh; + RGBA_t *palette = HWR_GetTexturePalette(); if (w < 0 || h < 0) return; // consistency w/ software @@ -882,7 +886,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { - RGBA_t rgbaColour = V_GetColor(color); + RGBA_t rgbaColour = palette[color&0xFF]; FRGBAFloat clearColour; clearColour.red = (float)rgbaColour.s.red / 255; clearColour.green = (float)rgbaColour.s.green / 255; @@ -972,6 +976,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) FSurfaceInfo Surf; float fx, fy, fw, fh; UINT8 alphalevel = ((color & V_ALPHAMASK) >> V_ALPHASHIFT); + RGBA_t *palette = HWR_GetTexturePalette(); if (w < 0 || h < 0) return; // consistency w/ software @@ -992,7 +997,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { - RGBA_t rgbaColour = V_GetColor(color); + RGBA_t rgbaColour = palette[color&0xFF]; FRGBAFloat clearColour; clearColour.red = (float)rgbaColour.s.red / 255; clearColour.green = (float)rgbaColour.s.green / 255; @@ -1066,7 +1071,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) v[0].t = v[1].t = 0.0f; v[2].t = v[3].t = 1.0f; - Surf.PolyColor = V_GetColor(color); + Surf.PolyColor = palette[color&0xFF]; if (alphalevel) { diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index befe25b26..e6e4688cc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -73,6 +73,7 @@ static void CV_screentextures_ONChange(void); static void CV_useCustomShaders_ONChange(void); static void CV_grshaders_OnChange(void); static void CV_grpaletterendering_OnChange(void); +static void CV_grpalettedepth_OnChange(void); static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}}; @@ -147,6 +148,9 @@ consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t glpalettedepth_cons_t[] = {{16, "16 bits"}, {24, "24 bits"}, {0, NULL}}; +consvar_t cv_grpalettedepth = {"gr_palettedepth", "16 bits", CV_SAVE|CV_CALL, glpalettedepth_cons_t, CV_grpalettedepth_OnChange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -178,10 +182,7 @@ static void CV_screentextures_ONChange(void) static void CV_grshaders_OnChange(void) { - if (rendermode == render_opengl) - V_SetPalette(0); - - if (cv_grpaletterendering.value) + if ((rendermode == render_opengl) && (cv_grpaletterendering.value)) { // can't do palette rendering without shaders, so update the state if needed HWR_TogglePaletteRendering(); @@ -197,15 +198,20 @@ static void CV_useCustomShaders_ONChange(void) } } - static void CV_grpaletterendering_OnChange(void) { - if (gr_shadersavailable) + if ((rendermode == render_opengl) && (gr_shadersavailable)) { HWR_TogglePaletteRendering(); } } +static void CV_grpalettedepth_OnChange(void) +{ + if (HWR_ShouldUsePaletteRendering()) + HWR_SetPalette(pLocalPalette); +} + // ========================================================================== // Globals // ========================================================================== @@ -6400,6 +6406,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_secbright); CV_RegisterVar(&cv_grpaletterendering); + CV_RegisterVar(&cv_grpalettedepth); CV_RegisterVar(&cv_grflashpal); CV_RegisterVar(&cv_grvhseffect); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 2e88f9336..2939a4e59 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -92,6 +92,7 @@ void HWR_ClearClipper(void); boolean HWR_UseShader(void); boolean HWR_ShouldUsePaletteRendering(void); boolean HWR_PalRenderFlashpal(void); +void HWR_TogglePaletteRendering(void); // My original intention was to split hw_main.c // into files like hw_bsp.c, hw_sprites.c... @@ -162,6 +163,7 @@ extern boolean gr_maphasportals; // hw_cache.c void HWR_PrepLevelCache(size_t pnumtextures); +RGBA_t *HWR_GetTexturePalette(void); // hw_trick.c void HWR_CorrectSWTricks(void); @@ -190,8 +192,9 @@ extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletterendering; -extern consvar_t cv_grscreentextures; +extern consvar_t cv_grpalettedepth; extern consvar_t cv_grflashpal; +extern consvar_t cv_grscreentextures; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright;