- moved the palette stuff and some remaining scaling code from OpenGLFrameBuffer to DFrameBuffer and fixed GetFlashedPalette

This commit is contained in:
Christoph Oelckers 2018-05-16 22:10:24 +02:00
parent fc91827900
commit 44dd48c7fa
6 changed files with 74 additions and 101 deletions

View file

@ -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();

View file

@ -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<FGLDebug>();
@ -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

View file

@ -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<FGLDebug> 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;

View file

@ -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)
{

View file

@ -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)

View file

@ -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;