From 44dd48c7fad92fad33e69057d802a01f078feb80 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 16 May 2018 22:10:24 +0200 Subject: [PATCH] - moved the palette stuff and some remaining scaling code from OpenGLFrameBuffer to DFrameBuffer and fixed GetFlashedPalette --- src/d_main.cpp | 2 +- src/gl/system/gl_framebuffer.cpp | 79 ++++---------------------------- src/gl/system/gl_framebuffer.h | 11 ----- src/m_misc.cpp | 4 +- src/v_video.cpp | 58 ++++++++++++++++++++--- src/v_video.h | 21 +++++---- 6 files changed, 74 insertions(+), 101 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 7c71d490c..861318c66 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2700,7 +2700,7 @@ void D_DoomMain (void) else { // let the renderer reinitialize some stuff if needed - screen->GameRestart(); + screen->InitPalette(); // These calls from inside V_Init2 are still necessary C_NewModeAdjust(); M_InitVideoModesMenu(); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 6241d32a8..ed2b3fdc6 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -75,9 +75,7 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int gl_RenderState.Reset(); GLRenderer = new FGLRenderer(this); - memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256); - UpdatePalette (); - ScreenshotBuffer = NULL; + InitPalette(); InitializeState(); mDebug = std::make_shared(); @@ -396,35 +394,6 @@ void OpenGLFrameBuffer::SetOutputViewport(IntRect *bounds) } -void OpenGLFrameBuffer::UpdatePalette() -{ - if (GLRenderer) - GLRenderer->ClearTonemapPalette(); -} - -void OpenGLFrameBuffer::GetFlashedPalette (PalEntry pal[256]) -{ - memcpy(pal, SourcePalette, 256*sizeof(PalEntry)); -} - -PalEntry *OpenGLFrameBuffer::GetPalette () -{ - return SourcePalette; -} - -bool OpenGLFrameBuffer::SetFlash(PalEntry rgb, int amount) -{ - Flash = PalEntry(amount, rgb.r, rgb.g, rgb.b); - return true; -} - -void OpenGLFrameBuffer::GetFlash(PalEntry &rgb, int &amount) -{ - rgb = Flash; - rgb.a = 0; - amount = Flash.a; -} - void OpenGLFrameBuffer::InitForLevel() { if (GLRenderer != NULL) @@ -433,6 +402,13 @@ void OpenGLFrameBuffer::InitForLevel() } } +void OpenGLFrameBuffer::UpdatePalette() +{ + if (GLRenderer) + GLRenderer->ClearTonemapPalette(); +} + + //=========================================================================== // // @@ -476,8 +452,7 @@ void OpenGLFrameBuffer::GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, int w = SCREENWIDTH; int h = SCREENHEIGHT; - ReleaseScreenshotBuffer(); - ScreenshotBuffer = new uint8_t[w * h * 3]; + auto ScreenshotBuffer = new uint8_t[w * h * 3]; float rcpWidth = 1.0f / w; float rcpHeight = 1.0f / h; @@ -506,42 +481,6 @@ void OpenGLFrameBuffer::GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, gamma = 1 == vid_hwgamma || (2 == vid_hwgamma && !fullscreen) ? 1.0f : Gamma; } -//=========================================================================== -// -// Releases the screenshot buffer. -// -//=========================================================================== - -void OpenGLFrameBuffer::ReleaseScreenshotBuffer() -{ - if (ScreenshotBuffer != NULL) delete [] ScreenshotBuffer; - ScreenshotBuffer = NULL; -} - - -void OpenGLFrameBuffer::GameRestart() -{ - memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256); - UpdatePalette (); - ScreenshotBuffer = NULL; -} - - -void OpenGLFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y) -{ - int letterboxX = mOutputLetterbox.left; - int letterboxY = mOutputLetterbox.top; - int letterboxWidth = mOutputLetterbox.width; - int letterboxHeight = mOutputLetterbox.height; - - // Subtract the LB video mode letterboxing - if (IsFullscreen()) - y -= (GetTrueHeight() - VideoHeight) / 2; - - x = int16_t((x - letterboxX) * Width / letterboxWidth); - y = int16_t((y - letterboxY) * Height / letterboxHeight); -} - //=========================================================================== // // 2D drawing diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 1541b3676..7bf378e05 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -27,11 +27,6 @@ public: void CleanForRestart() override; void UpdatePalette() override; - void GetFlashedPalette (PalEntry pal[256]) override; - PalEntry *GetPalette () override; - bool SetFlash(PalEntry rgb, int amount) override; - void GetFlash(PalEntry &rgb, int &amount) override; - void GameRestart() override; void InitForLevel() override; void SetClearColor(int color) override; uint32_t GetCaps() override; @@ -54,9 +49,6 @@ public: // points to the last row in the buffer, which will be the first row output. virtual void GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, ESSType &color_type, float &gamma) override; - // Releases the screenshot buffer. - virtual void ReleaseScreenshotBuffer(); - bool WipeStartScreen(int type); void WipeEndScreen(); bool WipeDo(int ticks); @@ -66,14 +58,11 @@ public: void SetVSync(bool vsync); - void ScaleCoordsFromWindow(int16_t &x, int16_t &y) override; void Draw2D() override; bool HWGammaActive = false; // Are we using hardware or software gamma? std::shared_ptr mDebug; // Debug API private: - PalEntry Flash; // Only needed to support some cruft in the interface that only makes sense for the software renderer - PalEntry SourcePalette[256]; // This is where unpaletted textures get their palette from uint8_t *ScreenshotBuffer; // What the name says. This must be maintained because the software renderer can return a locked canvas surface which the caller cannot release. int camtexcount = 0; diff --git a/src/m_misc.cpp b/src/m_misc.cpp index e0eb5d165..3aa2df4d4 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -627,7 +627,7 @@ void M_ScreenShot (const char *filename) if (file == NULL) { Printf ("Could not open %s\n", autoname.GetChars()); - screen->ReleaseScreenshotBuffer(); + delete[] buffer; return; } if (writepcx) @@ -641,7 +641,7 @@ void M_ScreenShot (const char *filename) screen->GetWidth(), screen->GetHeight(), pitch, gamma); } delete file; - screen->ReleaseScreenshotBuffer(); + delete[] buffer; if (!screenshot_quiet) { diff --git a/src/v_video.cpp b/src/v_video.cpp index b269518cc..1441a1966 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -130,11 +130,6 @@ public: } // These methods should never be called. void Update() { DBGBREAK; } - PalEntry *GetPalette() { DBGBREAK; return NULL; } - void GetFlashedPalette(PalEntry palette[256]) { DBGBREAK; } - void UpdatePalette() { DBGBREAK; } - bool SetFlash(PalEntry rgb, int amount) { DBGBREAK; return false; } - void GetFlash(PalEntry &rgb, int &amount) { DBGBREAK; } bool IsFullscreen() { DBGBREAK; return 0; } int GetClientWidth() { DBGBREAK; return 0; } int GetClientHeight() { DBGBREAK; return 0; } @@ -818,6 +813,37 @@ void FPaletteTester::MakeTexture() CurTranslation = t; } + +//========================================================================== +// +// Palette stuff. +// +//========================================================================== + +void DFrameBuffer::GetFlashedPalette(PalEntry pal[256]) +{ + DoBlending(SourcePalette, pal, 256, Flash.r, Flash.g, Flash.b, Flash.a); +} + +PalEntry *DFrameBuffer::GetPalette() +{ + return SourcePalette; +} + +bool DFrameBuffer::SetFlash(PalEntry rgb, int amount) +{ + Flash = PalEntry(amount, rgb.r, rgb.g, rgb.b); + return true; +} + +void DFrameBuffer::GetFlash(PalEntry &rgb, int &amount) +{ + rgb = Flash; + rgb.a = 0; + amount = Flash.a; +} + + //========================================================================== // // DFrameBuffer :: SetVSync @@ -898,12 +924,14 @@ void DFrameBuffer::WipeCleanup() //========================================================================== // -// DFrameBuffer :: GameRestart +// DFrameBuffer :: InitPalette // //========================================================================== -void DFrameBuffer::GameRestart() +void DFrameBuffer::InitPalette() { + memcpy(SourcePalette, GPalette.BaseColors, sizeof(PalEntry) * 256); + UpdatePalette(); } //========================================================================== @@ -1080,6 +1108,22 @@ int DFrameBuffer::ScreenToWindowY(int y) return mScreenViewport.top + mScreenViewport.height - (int)round(y * mScreenViewport.height / (float)GetHeight()); } +void DFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y) +{ + int letterboxX = mOutputLetterbox.left; + int letterboxY = mOutputLetterbox.top; + int letterboxWidth = mOutputLetterbox.width; + int letterboxHeight = mOutputLetterbox.height; + + // Subtract the LB video mode letterboxing + if (IsFullscreen()) + y -= (GetTrueHeight() - VideoHeight) / 2; + + x = int16_t((x - letterboxX) * Width / letterboxWidth); + y = int16_t((y - letterboxY) * Height / letterboxHeight); +} + + CCMD(clean) diff --git a/src/v_video.h b/src/v_video.h index ca60cc7d0..57fc28945 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -343,6 +343,9 @@ protected: bool Bgra = 0; int clipleft = 0, cliptop = 0, clipwidth = -1, clipheight = -1; + PalEntry Flash; // Only needed to support some cruft in the interface that only makes sense for the software renderer + PalEntry SourcePalette[256]; // This is where unpaletted textures get their palette from + public: int hwcaps = 0; int instack[2] = { 0,0 }; // this is globally maintained state for portal recursion avoidance. @@ -362,13 +365,13 @@ public: virtual void Update () = 0; // Return a pointer to 256 palette entries that can be written to. - virtual PalEntry *GetPalette () = 0; + PalEntry *GetPalette (); // Stores the palette with flash blended in into 256 dwords - virtual void GetFlashedPalette (PalEntry palette[256]) = 0; + void GetFlashedPalette (PalEntry palette[256]); // Mark the palette as changed. It will be updated on the next Update(). - virtual void UpdatePalette () = 0; + virtual void UpdatePalette() {} // Sets the gamma level. Returns false if the hardware does not support // gamma changing. (Always true for now, since palettes can always be @@ -379,10 +382,10 @@ public: // being all flash and 0 being no flash. Returns false if the hardware // does not support this. (Always true for now, since palettes can always // be flashed.) - virtual bool SetFlash (PalEntry rgb, int amount) = 0; + bool SetFlash (PalEntry rgb, int amount); // Converse of SetFlash - virtual void GetFlash (PalEntry &rgb, int &amount) = 0; + void GetFlash (PalEntry &rgb, int &amount); // Returns true if running fullscreen. virtual bool IsFullscreen () = 0; @@ -419,7 +422,7 @@ public: // Report a game restart - virtual void GameRestart(); + void InitPalette(); virtual void InitForLevel() {} virtual void SetClearColor(int color) {} virtual uint32_t GetCaps(); @@ -433,7 +436,8 @@ public: virtual bool WipeDo(int ticks); virtual void WipeCleanup(); - virtual void ScaleCoordsFromWindow(int16_t &x, int16_t &y) {} + virtual int GetTrueHeight() { return GetHeight(); } + void ScaleCoordsFromWindow(int16_t &x, int16_t &y); uint64_t GetLastFPS() const { return LastCount; } @@ -506,9 +510,6 @@ public: // points to the last row in the buffer, which will be the first row output. virtual void GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, ESSType &color_type, float &gamma) {} - // Releases the screenshot buffer. - virtual void ReleaseScreenshotBuffer() {} - // The original size of the framebuffer as selected in the video menu. int VideoWidth = 0; int VideoHeight = 0;