From 05220a713320b0b14525baad647f8ace577e19ee Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 31 May 2016 09:36:18 +0200 Subject: [PATCH] Added IsBgra() to DCanvas Changed SWRender output format to be decided by IsBgra() --- src/f_wipe.cpp | 10 ++++----- src/posix/cocoa/i_video.mm | 10 +++++---- src/posix/hardware.h | 2 +- src/posix/sdl/hardware.cpp | 5 ++++- src/posix/sdl/sdlvideo.cpp | 6 +++--- src/posix/sdl/sdlvideo.h | 2 +- src/r_draw.cpp | 39 +++++++++++++++++++++++++++++++++- src/r_drawt.cpp | 2 -- src/r_main.cpp | 28 ++++++++++++++---------- src/r_main.h | 2 ++ src/r_segs.cpp | 2 -- src/r_swrenderer.cpp | 12 ++++++----- src/r_things.cpp | 1 - src/textures/canvastexture.cpp | 2 +- src/v_draw.cpp | 16 ++++++-------- src/v_video.cpp | 26 +++++++++++------------ src/v_video.h | 8 ++++--- src/win32/fb_d3d9.cpp | 17 +++++++-------- src/win32/fb_ddraw.cpp | 7 +----- src/win32/hardware.cpp | 5 ++++- src/win32/hardware.h | 2 +- src/win32/win32iface.h | 8 +++---- src/win32/win32video.cpp | 21 ++++++++++-------- wadsrc/static/menudef.txt | 2 +- 24 files changed, 139 insertions(+), 96 deletions(-) diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp index 7e1ec678e..84b6036e4 100644 --- a/src/f_wipe.cpp +++ b/src/f_wipe.cpp @@ -33,8 +33,6 @@ // SCREEN WIPE PACKAGE // -EXTERN_CVAR(Bool, r_swtruecolor) - static int CurrentWipeType; static short *wipe_scr_start; @@ -385,7 +383,7 @@ static bool (*wipes[])(int) = // Returns true if the wipe should be performed. bool wipe_StartScreen (int type) { - if (r_swtruecolor) + if (screen->IsBgra()) return false; CurrentWipeType = clamp(type, 0, wipe_NUMWIPES - 1); @@ -401,7 +399,7 @@ bool wipe_StartScreen (int type) void wipe_EndScreen (void) { - if (r_swtruecolor) + if (screen->IsBgra()) return; if (CurrentWipeType) @@ -420,7 +418,7 @@ bool wipe_ScreenWipe (int ticks) { bool rc; - if (r_swtruecolor) + if (screen->IsBgra()) return true; if (CurrentWipeType == wipe_None) @@ -436,7 +434,7 @@ bool wipe_ScreenWipe (int ticks) // Final things for the wipe void wipe_Cleanup() { - if (r_swtruecolor) + if (screen->IsBgra()) return; if (wipe_scr_start != NULL) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 5e073daf3..c97460a02 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -96,6 +96,8 @@ EXTERN_CVAR(Bool, ticker ) EXTERN_CVAR(Bool, vid_vsync) EXTERN_CVAR(Bool, vid_hidpi) +CVAR(Bool, swtruecolor, false, CVAR_ARCHIVE) + CUSTOM_CVAR(Bool, fullscreen, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { extern int NewWidth, NewHeight, NewBits, DisplayBits; @@ -199,7 +201,7 @@ public: virtual EDisplayType GetDisplayType() { return DISPLAY_Both; } virtual void SetWindowedScale(float scale); - virtual DFrameBuffer* CreateFrameBuffer(int width, int height, bool fs, DFrameBuffer* old); + virtual DFrameBuffer* CreateFrameBuffer(int width, int height, bool bgra, bool fs, DFrameBuffer* old); virtual void StartModeIterator(int bits, bool fullscreen); virtual bool NextMode(int* width, int* height, bool* letterbox); @@ -518,7 +520,7 @@ bool CocoaVideo::NextMode(int* const width, int* const height, bool* const lette return false; } -DFrameBuffer* CocoaVideo::CreateFrameBuffer(const int width, const int height, const bool fullscreen, DFrameBuffer* const old) +DFrameBuffer* CocoaVideo::CreateFrameBuffer(const int width, const int height, const bool bgra, const bool fullscreen, DFrameBuffer* const old) { PalEntry flashColor = 0; int flashAmount = 0; @@ -762,7 +764,7 @@ CocoaVideo* CocoaVideo::GetInstance() CocoaFrameBuffer::CocoaFrameBuffer(int width, int height, bool fullscreen) -: DFrameBuffer(width, height) +: DFrameBuffer(width, height, false) , m_needPaletteUpdate(false) , m_gamma(0.0f) , m_needGammaUpdate(false) @@ -1064,7 +1066,7 @@ void I_CreateRenderer() DFrameBuffer* I_SetMode(int &width, int &height, DFrameBuffer* old) { - return Video->CreateFrameBuffer(width, height, fullscreen, old); + return Video->CreateFrameBuffer(width, height, swtruecolor, fullscreen, old); } bool I_CheckResolution(const int width, const int height, const int bits) diff --git a/src/posix/hardware.h b/src/posix/hardware.h index 618941fe5..3c06cb6c6 100644 --- a/src/posix/hardware.h +++ b/src/posix/hardware.h @@ -74,7 +74,7 @@ class IVideo virtual EDisplayType GetDisplayType () = 0; virtual void SetWindowedScale (float scale) = 0; - virtual DFrameBuffer *CreateFrameBuffer (int width, int height, bool fs, DFrameBuffer *old) = 0; + virtual DFrameBuffer *CreateFrameBuffer (int width, int height, bool bgra, bool fs, DFrameBuffer *old) = 0; virtual void StartModeIterator (int bits, bool fs) = 0; virtual bool NextMode (int *width, int *height, bool *letterbox) = 0; diff --git a/src/posix/sdl/hardware.cpp b/src/posix/sdl/hardware.cpp index 6142eb1d8..52bca35e7 100644 --- a/src/posix/sdl/hardware.cpp +++ b/src/posix/sdl/hardware.cpp @@ -51,6 +51,7 @@ EXTERN_CVAR (Bool, ticker) EXTERN_CVAR (Bool, fullscreen) +EXTERN_CVAR (Bool, swtruecolor) EXTERN_CVAR (Float, vid_winscale) IVideo *Video; @@ -128,7 +129,7 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old) fs = fullscreen; break; } - DFrameBuffer *res = Video->CreateFrameBuffer (width, height, fs, old); + DFrameBuffer *res = Video->CreateFrameBuffer (width, height, swtruecolor, fs, old); /* Right now, CreateFrameBuffer cannot return NULL if (res == NULL) @@ -280,6 +281,8 @@ CUSTOM_CVAR (Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) } } +CVAR (Bool, swtruecolor, false, CVAR_ARCHIVE) + extern int NewWidth, NewHeight, NewBits, DisplayBits; CUSTOM_CVAR (Bool, fullscreen, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) diff --git a/src/posix/sdl/sdlvideo.cpp b/src/posix/sdl/sdlvideo.cpp index 04c3a3f2e..b050097be 100644 --- a/src/posix/sdl/sdlvideo.cpp +++ b/src/posix/sdl/sdlvideo.cpp @@ -257,7 +257,7 @@ bool SDLVideo::NextMode (int *width, int *height, bool *letterbox) return false; } -DFrameBuffer *SDLVideo::CreateFrameBuffer (int width, int height, bool fullscreen, DFrameBuffer *old) +DFrameBuffer *SDLVideo::CreateFrameBuffer (int width, int height, bool bgra, bool fullscreen, DFrameBuffer *old) { static int retry = 0; static int owidth, oheight; @@ -335,7 +335,7 @@ DFrameBuffer *SDLVideo::CreateFrameBuffer (int width, int height, bool fullscree } ++retry; - fb = static_cast(CreateFrameBuffer (width, height, fullscreen, NULL)); + fb = static_cast(CreateFrameBuffer (width, height, bgra, fullscreen, NULL)); } retry = 0; @@ -351,7 +351,7 @@ void SDLVideo::SetWindowedScale (float scale) // FrameBuffer implementation ----------------------------------------------- SDLFB::SDLFB (int width, int height, bool fullscreen, SDL_Window *oldwin) - : DFrameBuffer (width, height) + : DFrameBuffer (width, height, false) { int i; diff --git a/src/posix/sdl/sdlvideo.h b/src/posix/sdl/sdlvideo.h index 072167b5a..385733bc1 100644 --- a/src/posix/sdl/sdlvideo.h +++ b/src/posix/sdl/sdlvideo.h @@ -10,7 +10,7 @@ class SDLVideo : public IVideo EDisplayType GetDisplayType () { return DISPLAY_Both; } void SetWindowedScale (float scale); - DFrameBuffer *CreateFrameBuffer (int width, int height, bool fs, DFrameBuffer *old); + DFrameBuffer *CreateFrameBuffer (int width, int height, bool bgra, bool fs, DFrameBuffer *old); void StartModeIterator (int bits, bool fs); bool NextMode (int *width, int *height, bool *letterbox); diff --git a/src/r_draw.cpp b/src/r_draw.cpp index f939406bb..82169ec6f 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -179,7 +179,6 @@ FDynamicColormap ShadeFakeColormap[16]; BYTE identitymap[256]; EXTERN_CVAR (Int, r_columnmethod) -EXTERN_CVAR (Bool, r_swtruecolor) void R_InitShadeMaps() { @@ -4129,6 +4128,14 @@ const BYTE *R_GetColumn (FTexture *tex, int col) // [RH] Initialize the column drawer pointers void R_InitColumnDrawers () { + // Save a copy when switching to true color mode as the assembly palette drawers might change them + static bool pointers_saved = false; + static DWORD(*dovline1_saved)(); + static DWORD(*doprevline1_saved)(); + static DWORD(*domvline1_saved)(); + static void(*dovline4_saved)(); + static void(*domvline4_saved)(); + if (r_swtruecolor) { R_DrawColumnHoriz = R_DrawColumnHorizP_RGBA_C; @@ -4201,6 +4208,16 @@ void R_InitColumnDrawers () rt_tlaterevsubclamp4cols = rt_tlaterevsubclamp4cols_RGBA_c; rt_initcols = rt_initcols_rgba; + if (!pointers_saved) + { + pointers_saved = true; + dovline1_saved = dovline1; + doprevline1_saved = doprevline1; + domvline1_saved = domvline1; + dovline4_saved = dovline4; + domvline4_saved = domvline4; + } + dovline1 = vlinec1_RGBA; doprevline1 = vlinec1_RGBA; dovline4 = vlinec4_RGBA; @@ -4304,7 +4321,27 @@ void R_InitColumnDrawers () rt_tlatesubclamp4cols = rt_tlatesubclamp4cols_c; rt_tlaterevsubclamp4cols = rt_tlaterevsubclamp4cols_c; rt_initcols = rt_initcols_pal; + + if (pointers_saved) + { + pointers_saved = false; + dovline1 = dovline1_saved; + doprevline1 = doprevline1_saved; + domvline1 = domvline1_saved; + dovline4 = dovline4_saved; + domvline4 = domvline4_saved; + } } + + colfunc = basecolfunc = R_DrawColumn; + fuzzcolfunc = R_DrawFuzzColumn; + transcolfunc = R_DrawTranslatedColumn; + spanfunc = R_DrawSpan; + + // [RH] Horizontal column drawers + hcolfunc_pre = R_DrawColumnHoriz; + hcolfunc_post1 = rt_map1col; + hcolfunc_post4 = rt_map4cols; } // [RH] Choose column drawers in a single place diff --git a/src/r_drawt.cpp b/src/r_drawt.cpp index 485ed7ab3..e47590c72 100644 --- a/src/r_drawt.cpp +++ b/src/r_drawt.cpp @@ -47,8 +47,6 @@ #include "r_things.h" #include "v_video.h" -EXTERN_CVAR(Bool, r_swtruecolor) - // I should have commented this stuff better. // // dc_temp is the buffer R_DrawColumnHoriz writes into. diff --git a/src/r_main.cpp b/src/r_main.cpp index 9dc61eea3..aec8310d5 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -103,7 +103,8 @@ bool r_dontmaplines; CVAR (String, r_viewsize, "", CVAR_NOSET) CVAR (Bool, r_shadercolormaps, true, CVAR_ARCHIVE) -CVAR (Bool, r_swtruecolor, false, CVAR_ARCHIVE) + +bool r_swtruecolor; double r_BaseVisibility; double r_WallVisibility; @@ -398,16 +399,6 @@ void R_InitRenderer() R_InitPlanes (); R_InitShadeMaps(); R_InitColumnDrawers (); - - colfunc = basecolfunc = R_DrawColumn; - fuzzcolfunc = R_DrawFuzzColumn; - transcolfunc = R_DrawTranslatedColumn; - spanfunc = R_DrawSpan; - - // [RH] Horizontal column drawers - hcolfunc_pre = R_DrawColumnHoriz; - hcolfunc_post1 = rt_map1col; - hcolfunc_post4 = rt_map4cols; } //========================================================================== @@ -962,6 +953,13 @@ void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines) { const bool savedviewactive = viewactive; + const bool savedoutputformat = r_swtruecolor; + + if (r_swtruecolor != canvas->IsBgra()) + { + r_swtruecolor = canvas->IsBgra(); + R_InitColumnDrawers(); + } viewwidth = width; RenderTarget = canvas; @@ -980,7 +978,15 @@ void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas, screen->Lock (true); R_SetupBuffer (); screen->Unlock (); + viewactive = savedviewactive; + r_swtruecolor = savedoutputformat; + + if (r_swtruecolor != canvas->IsBgra()) + { + r_swtruecolor = canvas->IsBgra(); + R_InitColumnDrawers(); + } } //========================================================================== diff --git a/src/r_main.h b/src/r_main.h index c1034ea3e..765635e5d 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -106,6 +106,8 @@ inline uint32_t shade_pal_index(uint32_t index, uint32_t light) return 0xff000000 | (red << 16) | (green << 8) | blue; } +extern bool r_swtruecolor; + extern double GlobVis; void R_SetVisibility(double visibility); diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 8c71f0fb7..cab97adfc 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -61,8 +61,6 @@ CVAR(Bool, r_np2, true, 0) //CVAR (Int, ty, 8, 0) //CVAR (Int, tx, 8, 0) -EXTERN_CVAR(Bool, r_swtruecolor) - #define HEIGHTBITS 12 #define HEIGHTSHIFT (FRACBITS-HEIGHTBITS) diff --git a/src/r_swrenderer.cpp b/src/r_swrenderer.cpp index 433007acb..15e2fda8f 100644 --- a/src/r_swrenderer.cpp +++ b/src/r_swrenderer.cpp @@ -155,6 +155,12 @@ void FSoftwareRenderer::Precache(BYTE *texhitlist, TMap &act void FSoftwareRenderer::RenderView(player_t *player) { + if (r_swtruecolor != screen->IsBgra()) + { + r_swtruecolor = screen->IsBgra(); + R_InitColumnDrawers(); + } + R_RenderActorView (player->mo); // [RH] Let cameras draw onto textures that were visible this frame. FCanvasTextureInfo::UpdateAll (); @@ -182,8 +188,7 @@ void FSoftwareRenderer::RemapVoxels() void FSoftwareRenderer::WriteSavePic (player_t *player, FILE *file, int width, int height) { -#ifdef PALETTEOUTPUT - DCanvas *pic = new DSimpleCanvas (width, height); + DCanvas *pic = new DSimpleCanvas (width, height, false); PalEntry palette[256]; // Take a snapshot of the player's view @@ -196,7 +201,6 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FILE *file, int width, i pic->Destroy(); pic->ObjectFlags |= OF_YesReallyDelete; delete pic; -#endif } //=========================================================================== @@ -313,7 +317,6 @@ void FSoftwareRenderer::CopyStackedViewParameters() void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) { -#ifdef PALETTEOUTPUT BYTE *Pixels = const_cast(tex->GetPixels()); DSimpleCanvas *Canvas = tex->GetCanvas(); @@ -337,7 +340,6 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin tex->SetUpdated(); fixedcolormap = savecolormap; realfixedcolormap = savecm; -#endif } //========================================================================== diff --git a/src/r_things.cpp b/src/r_things.cpp index 2abcc0e12..f52c80376 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -98,7 +98,6 @@ EXTERN_CVAR (Bool, st_scale) EXTERN_CVAR(Bool, r_shadercolormaps) EXTERN_CVAR(Int, r_drawfuzz) EXTERN_CVAR(Bool, r_deathcamera); -EXTERN_CVAR(Bool, r_swtruecolor) // // Sprite rotation 0 is facing the viewer, diff --git a/src/textures/canvastexture.cpp b/src/textures/canvastexture.cpp index d1f70439f..7242149a4 100644 --- a/src/textures/canvastexture.cpp +++ b/src/textures/canvastexture.cpp @@ -103,7 +103,7 @@ const BYTE *FCanvasTexture::GetPixels () void FCanvasTexture::MakeTexture () { - Canvas = new DSimpleCanvas (Width, Height); + Canvas = new DSimpleCanvas (Width, Height, false); Canvas->Lock (); GC::AddSoftRoot(Canvas); diff --git a/src/v_draw.cpp b/src/v_draw.cpp index ed6571ad3..b4f1ad4b5 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -77,8 +77,6 @@ extern "C" short spanend[MAXHEIGHT]; CVAR (Bool, hud_scale, false, CVAR_ARCHIVE); -EXTERN_CVAR(Bool, r_swtruecolor) - // For routines that take RGB colors, cache the previous lookup in case there // are several repetitions with the same color. static int LastPal = -1; @@ -1019,7 +1017,7 @@ void DCanvas::PUTTRANSDOT (int xx, int yy, int basecolor, int level) oldyyshifted = yy * GetPitch(); } - if (r_swtruecolor) + if (IsBgra()) { uint32_t *spot = (uint32_t*)GetBuffer() + oldyyshifted + xx; @@ -1091,7 +1089,7 @@ void DCanvas::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32 real { swapvalues (x0, x1); } - if (r_swtruecolor) + if (IsBgra()) { uint32_t *spot = (uint32_t*)GetBuffer() + y0*GetPitch() + x0; for (int i = 0; i <= deltaX; i++) @@ -1104,7 +1102,7 @@ void DCanvas::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32 real } else if (deltaX == 0) { // vertical line - if (r_swtruecolor) + if (IsBgra()) { uint32_t *spot = (uint32_t*)GetBuffer() + y0*GetPitch() + x0; int pitch = GetPitch(); @@ -1127,7 +1125,7 @@ void DCanvas::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32 real } else if (deltaX == deltaY) { // diagonal line. - if (r_swtruecolor) + if (IsBgra()) { uint32_t *spot = (uint32_t*)GetBuffer() + y0*GetPitch() + x0; int advance = GetPitch() + xDir; @@ -1295,7 +1293,7 @@ void DCanvas::Clear (int left, int top, int right, int bottom, int palcolor, uin palcolor = PalFromRGB(color); } - if (r_swtruecolor) + if (IsBgra()) { uint32_t *dest = (uint32_t*)Buffer + top * Pitch + left; x = right - left; @@ -1502,7 +1500,7 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, // void DCanvas::DrawBlock (int x, int y, int _width, int _height, const BYTE *src) const { - if (r_swtruecolor) + if (IsBgra()) return; int srcpitch = _width; @@ -1531,7 +1529,7 @@ void DCanvas::DrawBlock (int x, int y, int _width, int _height, const BYTE *src) // void DCanvas::GetBlock (int x, int y, int _width, int _height, BYTE *dest) const { - if (r_swtruecolor) + if (IsBgra()) return; const BYTE *src; diff --git a/src/v_video.cpp b/src/v_video.cpp index 01043b8bc..bc99edbf1 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -65,8 +65,6 @@ #include "menu/menu.h" #include "r_data/voxels.h" -EXTERN_CVAR(Bool, r_swtruecolor) - FRenderer *Renderer; IMPLEMENT_ABSTRACT_CLASS (DCanvas) @@ -83,7 +81,7 @@ class DDummyFrameBuffer : public DFrameBuffer DECLARE_CLASS (DDummyFrameBuffer, DFrameBuffer); public: DDummyFrameBuffer (int width, int height) - : DFrameBuffer (0, 0) + : DFrameBuffer (0, 0, false) { Width = width; Height = height; @@ -208,13 +206,14 @@ DCanvas *DCanvas::CanvasChain = NULL; // //========================================================================== -DCanvas::DCanvas (int _width, int _height) +DCanvas::DCanvas (int _width, int _height, bool _bgra) { // Init member vars Buffer = NULL; LockCount = 0; Width = _width; Height = _height; + Bgra = _bgra; // Add to list of active canvases Next = CanvasChain; @@ -366,7 +365,7 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h) gap = Pitch - w; - if (r_swtruecolor) + if (IsBgra()) { uint32_t *spot = (uint32_t*)Buffer + x1 + y1*Pitch; @@ -448,7 +447,7 @@ void DCanvas::GetScreenshotBuffer(const BYTE *&buffer, int &pitch, ESSType &colo Lock(true); buffer = GetBuffer(); pitch = GetPitch(); - color_type = r_swtruecolor ? SS_BGRA : SS_PAL; + color_type = IsBgra() ? SS_BGRA : SS_PAL; } //========================================================================== @@ -761,8 +760,8 @@ void DCanvas::CalcGamma (float gamma, BYTE gammalookup[256]) // //========================================================================== -DSimpleCanvas::DSimpleCanvas (int width, int height) - : DCanvas (width, height) +DSimpleCanvas::DSimpleCanvas (int width, int height, bool bgra) + : DCanvas (width, height, bgra) { // Making the pitch a power of 2 is very bad for performance // Try to maximize the number of cache lines that can be filled @@ -799,8 +798,9 @@ DSimpleCanvas::DSimpleCanvas (int width, int height) Pitch = width + MAX(0, CPU.DataL1LineSize - 8); } } - MemBuffer = new BYTE[Pitch * height * 4]; - memset (MemBuffer, 0, Pitch * height * 4); + int bytes_per_pixel = bgra ? 4 : 1; + MemBuffer = new BYTE[Pitch * height * bytes_per_pixel]; + memset (MemBuffer, 0, Pitch * height * bytes_per_pixel); } //========================================================================== @@ -869,8 +869,8 @@ void DSimpleCanvas::Unlock () // //========================================================================== -DFrameBuffer::DFrameBuffer (int width, int height) - : DSimpleCanvas (width, height) +DFrameBuffer::DFrameBuffer (int width, int height, bool bgra) + : DSimpleCanvas (width, height, bgra) { LastMS = LastSec = FrameCount = LastCount = LastTic = 0; Accel2D = false; @@ -927,7 +927,7 @@ void DFrameBuffer::DrawRateStuff () // Buffer can be NULL if we're doing hardware accelerated 2D if (buffer != NULL) { - if (r_swtruecolor) + if (IsBgra()) { uint32_t *buffer32 = (uint32_t*)buffer; buffer32 += (GetHeight() - 1) * GetPitch(); diff --git a/src/v_video.h b/src/v_video.h index fa1ce83df..120beff9a 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -185,7 +185,7 @@ class DCanvas : public DObject { DECLARE_ABSTRACT_CLASS (DCanvas, DObject) public: - DCanvas (int width, int height); + DCanvas (int width, int height, bool bgra); virtual ~DCanvas (); // Member variable access @@ -193,6 +193,7 @@ public: inline int GetWidth () const { return Width; } inline int GetHeight () const { return Height; } inline int GetPitch () const { return Pitch; } + inline bool IsBgra() const { return Bgra; } virtual bool IsValid (); @@ -267,6 +268,7 @@ protected: int Height; int Pitch; int LockCount; + bool Bgra; bool ClipBox (int &left, int &top, int &width, int &height, const BYTE *&src, const int srcpitch) const; void DrawTextureV(FTexture *img, double x, double y, uint32 tag, va_list tags) = delete; @@ -289,7 +291,7 @@ class DSimpleCanvas : public DCanvas { DECLARE_CLASS (DSimpleCanvas, DCanvas) public: - DSimpleCanvas (int width, int height); + DSimpleCanvas (int width, int height, bool bgra); ~DSimpleCanvas (); bool IsValid (); @@ -327,7 +329,7 @@ class DFrameBuffer : public DSimpleCanvas { DECLARE_ABSTRACT_CLASS (DFrameBuffer, DSimpleCanvas) public: - DFrameBuffer (int width, int height); + DFrameBuffer (int width, int height, bool bgra); // Force the surface to use buffered output if true is passed. virtual bool Lock (bool buffered) = 0; diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 0cd847b97..fd84e3bbb 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -187,7 +187,6 @@ EXTERN_CVAR (Float, Gamma) EXTERN_CVAR (Bool, vid_vsync) EXTERN_CVAR (Float, transsouls) EXTERN_CVAR (Int, vid_refreshrate) -EXTERN_CVAR (Bool, r_swtruecolor) extern IDirect3D9 *D3D; @@ -243,8 +242,8 @@ CVAR(Bool, vid_hwaalines, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // //========================================================================== -D3DFB::D3DFB (UINT adapter, int width, int height, bool fullscreen) - : BaseWinFB (width, height) +D3DFB::D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen) + : BaseWinFB (width, height, bgra) { D3DPRESENT_PARAMETERS d3dpp; @@ -766,7 +765,7 @@ void D3DFB::KillNativeTexs() bool D3DFB::CreateFBTexture () { - FBFormat = r_swtruecolor ? D3DFMT_A8R8G8B8 : D3DFMT_L8; + FBFormat = IsBgra() ? D3DFMT_A8R8G8B8 : D3DFMT_L8; if (FAILED(D3DDevice->CreateTexture(Width, Height, 1, D3DUSAGE_DYNAMIC, FBFormat, D3DPOOL_DEFAULT, &FBTexture, NULL))) { @@ -1307,7 +1306,7 @@ void D3DFB::Draw3DPart(bool copy3d) SUCCEEDED(FBTexture->LockRect (0, &lockrect, NULL, D3DLOCK_DISCARD))) || SUCCEEDED(FBTexture->LockRect (0, &lockrect, &texrect, 0))) { - if (r_swtruecolor && FBFormat == D3DFMT_A8R8G8B8) + if (IsBgra() && FBFormat == D3DFMT_A8R8G8B8) { if (lockrect.Pitch == Pitch * sizeof(uint32_t) && Pitch == Width) { @@ -1325,7 +1324,7 @@ void D3DFB::Draw3DPart(bool copy3d) } } } - else if (!r_swtruecolor && FBFormat == D3DFMT_L8) + else if (!IsBgra() && FBFormat == D3DFMT_L8) { if (lockrect.Pitch == Pitch && Pitch == Width) { @@ -1377,7 +1376,7 @@ void D3DFB::Draw3DPart(bool copy3d) memset(Constant, 0, sizeof(Constant)); SetAlphaBlend(D3DBLENDOP(0)); EnableAlphaTest(FALSE); - if (r_swtruecolor) + if (IsBgra()) SetPixelShader(Shaders[SHADER_NormalColor]); else SetPixelShader(Shaders[SHADER_NormalColorPal]); @@ -1398,7 +1397,7 @@ void D3DFB::Draw3DPart(bool copy3d) realfixedcolormap->ColorizeStart[1]/2, realfixedcolormap->ColorizeStart[2]/2, 0); color1 = D3DCOLOR_COLORVALUE(realfixedcolormap->ColorizeEnd[0]/2, realfixedcolormap->ColorizeEnd[1]/2, realfixedcolormap->ColorizeEnd[2]/2, 1); - if (r_swtruecolor) + if (IsBgra()) SetPixelShader(Shaders[SHADER_SpecialColormap]); else SetPixelShader(Shaders[SHADER_SpecialColormapPal]); @@ -1412,7 +1411,7 @@ void D3DFB::Draw3DPart(bool copy3d) CalcFullscreenCoords(verts, Accel2D, false, color0, color1); D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, verts, sizeof(FBVERTEX)); } - if (r_swtruecolor) + if (IsBgra()) SetPixelShader(Shaders[SHADER_NormalColor]); else SetPixelShader(Shaders[SHADER_NormalColorPal]); diff --git a/src/win32/fb_ddraw.cpp b/src/win32/fb_ddraw.cpp index fbdf035a3..5637e9695 100644 --- a/src/win32/fb_ddraw.cpp +++ b/src/win32/fb_ddraw.cpp @@ -60,9 +60,7 @@ // TYPES ------------------------------------------------------------------- -#ifdef USE_OBSOLETE_DDRAW IMPLEMENT_CLASS(DDrawFB) -#endif // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -120,10 +118,8 @@ cycle_t BlitCycles; // CODE -------------------------------------------------------------------- -#ifdef USE_OBSOLETE_DDRAW - DDrawFB::DDrawFB (int width, int height, bool fullscreen) - : BaseWinFB (width, height) + : BaseWinFB (width, height, false) { int i; @@ -1330,7 +1326,6 @@ void DDrawFB::Blank () PrimarySurf->Blt (NULL, NULL, NULL, DDBLT_COLORFILL, &blitFX); } } -#endif ADD_STAT (blit) { diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 8cc770556..8856924c0 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -51,6 +51,7 @@ EXTERN_CVAR (Bool, ticker) EXTERN_CVAR (Bool, fullscreen) +EXTERN_CVAR (Bool, swtruecolor) EXTERN_CVAR (Float, vid_winscale) CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -146,7 +147,7 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old) } break; } - DFrameBuffer *res = Video->CreateFrameBuffer (width, height, fs, old); + DFrameBuffer *res = Video->CreateFrameBuffer (width, height, swtruecolor, fs, old); /* Right now, CreateFrameBuffer cannot return NULL if (res == NULL) @@ -310,6 +311,8 @@ void I_RestoreWindowedPos () MoveWindow (Window, winx, winy, winw, winh, TRUE); } +CVAR (Bool, swtruecolor, false, CVAR_ARCHIVE) + extern int NewWidth, NewHeight, NewBits, DisplayBits; CUSTOM_CVAR (Bool, fullscreen, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) diff --git a/src/win32/hardware.h b/src/win32/hardware.h index b2bafef32..184eeccf5 100644 --- a/src/win32/hardware.h +++ b/src/win32/hardware.h @@ -45,7 +45,7 @@ class IVideo virtual EDisplayType GetDisplayType () = 0; virtual void SetWindowedScale (float scale) = 0; - virtual DFrameBuffer *CreateFrameBuffer (int width, int height, bool fs, DFrameBuffer *old) = 0; + virtual DFrameBuffer *CreateFrameBuffer (int width, int height, bool bgra, bool fs, DFrameBuffer *old) = 0; virtual void StartModeIterator (int bits, bool fs) = 0; virtual bool NextMode (int *width, int *height, bool *letterbox) = 0; diff --git a/src/win32/win32iface.h b/src/win32/win32iface.h index 0b3333d63..d30475eb3 100644 --- a/src/win32/win32iface.h +++ b/src/win32/win32iface.h @@ -70,7 +70,7 @@ class Win32Video : public IVideo EDisplayType GetDisplayType () { return DISPLAY_Both; } void SetWindowedScale (float scale); - DFrameBuffer *CreateFrameBuffer (int width, int height, bool fs, DFrameBuffer *old); + DFrameBuffer *CreateFrameBuffer (int width, int height, bool bgra, bool fs, DFrameBuffer *old); void StartModeIterator (int bits, bool fs); bool NextMode (int *width, int *height, bool *letterbox); @@ -121,7 +121,7 @@ class BaseWinFB : public DFrameBuffer { DECLARE_ABSTRACT_CLASS(BaseWinFB, DFrameBuffer) public: - BaseWinFB (int width, int height) : DFrameBuffer (width, height), Windowed (true) {} + BaseWinFB (int width, int height, bool bgra) : DFrameBuffer (width, height, bgra), Windowed (true) {} bool IsFullscreen () { return !Windowed; } virtual void Blank () = 0; @@ -142,7 +142,6 @@ protected: BaseWinFB() {} }; -#ifdef USE_OBSOLETE_DDRAW class DDrawFB : public BaseWinFB { DECLARE_CLASS(DDrawFB, BaseWinFB) @@ -224,13 +223,12 @@ private: DDrawFB() {} }; -#endif class D3DFB : public BaseWinFB { DECLARE_CLASS(D3DFB, BaseWinFB) public: - D3DFB (UINT adapter, int width, int height, bool fullscreen); + D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen); ~D3DFB (); bool IsValid (); diff --git a/src/win32/win32video.cpp b/src/win32/win32video.cpp index 3f3645d0b..5b2d5ef20 100644 --- a/src/win32/win32video.cpp +++ b/src/win32/win32video.cpp @@ -222,6 +222,13 @@ bool Win32Video::InitD3D9 () // Enumerate available display modes. FreeModes (); #ifndef PALETTEOUTPUT // To do: remove this again (AddD3DModes fails when there are too many modes available for videomenu to display) + + AddMode(320, 200, 8, 200, 0); + AddMode(320, 240, 8, 240, 0); + AddMode(640, 480, 8, 480, 0); + AddMode(800, 600, 8, 600, 0); + AddMode(1024, 768, 8, 768, 0); + AddMode(1920, 1080, 8, 1440, 0); // 1080p AddMode(1920*2, 1080*2, 8, 1440, 0); // 4k AddMode(2560, 1440, 8, 1440, 0); // 27" classic @@ -636,7 +643,7 @@ bool Win32Video::NextMode (int *width, int *height, bool *letterbox) return false; } -DFrameBuffer *Win32Video::CreateFrameBuffer (int width, int height, bool fullscreen, DFrameBuffer *old) +DFrameBuffer *Win32Video::CreateFrameBuffer (int width, int height, bool bgra, bool fullscreen, DFrameBuffer *old) { static int retry = 0; static int owidth, oheight; @@ -652,7 +659,8 @@ DFrameBuffer *Win32Video::CreateFrameBuffer (int width, int height, bool fullscr BaseWinFB *fb = static_cast (old); if (fb->Width == width && fb->Height == height && - fb->Windowed == !fullscreen) + fb->Windowed == !fullscreen && + fb->Bgra == bgra) { return old; } @@ -667,13 +675,9 @@ DFrameBuffer *Win32Video::CreateFrameBuffer (int width, int height, bool fullscr flashAmount = 0; } -#ifndef USE_OBSOLETE_DDRAW - fb = new D3DFB(m_Adapter, width, height, fullscreen); - LOG1("New fb created @ %p\n", fb); -#else if (D3D != NULL) { - fb = new D3DFB (m_Adapter, width, height, fullscreen); + fb = new D3DFB (m_Adapter, width, height, bgra, fullscreen); } else { @@ -738,10 +742,9 @@ DFrameBuffer *Win32Video::CreateFrameBuffer (int width, int height, bool fullscr } ++retry; - fb = static_cast(CreateFrameBuffer (width, height, fullscreen, NULL)); + fb = static_cast(CreateFrameBuffer (width, height, bgra, fullscreen, NULL)); } retry = 0; -#endif fb->SetFlash (flashColor, flashAmount); return fb; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 93e33ce79..3c712de96 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -661,7 +661,7 @@ OptionMenu "VideoOptions" Option "$DSPLYMNU_VSYNC", "vid_vsync", "OnOff" Option "$DSPLYMNU_CAPFPS", "cl_capfps", "OffOn" Option "$DSPLYMNU_COLUMNMETHOD", "r_columnmethod", "ColumnMethods" - Option "$DSPLYMNU_TRUECOLOR", "r_swtruecolor", "OnOff" + Option "$DSPLYMNU_TRUECOLOR", "swtruecolor", "OnOff" StaticText " " Option "$DSPLYMNU_WIPETYPE", "wipetype", "Wipes"