mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-14 00:20:51 +00:00
- moved the palette stuff and some remaining scaling code from OpenGLFrameBuffer to DFrameBuffer and fixed GetFlashedPalette
This commit is contained in:
parent
fc91827900
commit
44dd48c7fa
6 changed files with 74 additions and 101 deletions
|
@ -2700,7 +2700,7 @@ void D_DoomMain (void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// let the renderer reinitialize some stuff if needed
|
// let the renderer reinitialize some stuff if needed
|
||||||
screen->GameRestart();
|
screen->InitPalette();
|
||||||
// These calls from inside V_Init2 are still necessary
|
// These calls from inside V_Init2 are still necessary
|
||||||
C_NewModeAdjust();
|
C_NewModeAdjust();
|
||||||
M_InitVideoModesMenu();
|
M_InitVideoModesMenu();
|
||||||
|
|
|
@ -75,9 +75,7 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int
|
||||||
gl_RenderState.Reset();
|
gl_RenderState.Reset();
|
||||||
|
|
||||||
GLRenderer = new FGLRenderer(this);
|
GLRenderer = new FGLRenderer(this);
|
||||||
memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256);
|
InitPalette();
|
||||||
UpdatePalette ();
|
|
||||||
ScreenshotBuffer = NULL;
|
|
||||||
|
|
||||||
InitializeState();
|
InitializeState();
|
||||||
mDebug = std::make_shared<FGLDebug>();
|
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()
|
void OpenGLFrameBuffer::InitForLevel()
|
||||||
{
|
{
|
||||||
if (GLRenderer != NULL)
|
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 w = SCREENWIDTH;
|
||||||
int h = SCREENHEIGHT;
|
int h = SCREENHEIGHT;
|
||||||
|
|
||||||
ReleaseScreenshotBuffer();
|
auto ScreenshotBuffer = new uint8_t[w * h * 3];
|
||||||
ScreenshotBuffer = new uint8_t[w * h * 3];
|
|
||||||
|
|
||||||
float rcpWidth = 1.0f / w;
|
float rcpWidth = 1.0f / w;
|
||||||
float rcpHeight = 1.0f / h;
|
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;
|
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
|
// 2D drawing
|
||||||
|
|
|
@ -27,11 +27,6 @@ public:
|
||||||
|
|
||||||
void CleanForRestart() override;
|
void CleanForRestart() override;
|
||||||
void UpdatePalette() 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 InitForLevel() override;
|
||||||
void SetClearColor(int color) override;
|
void SetClearColor(int color) override;
|
||||||
uint32_t GetCaps() 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.
|
// 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;
|
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);
|
bool WipeStartScreen(int type);
|
||||||
void WipeEndScreen();
|
void WipeEndScreen();
|
||||||
bool WipeDo(int ticks);
|
bool WipeDo(int ticks);
|
||||||
|
@ -66,14 +58,11 @@ public:
|
||||||
|
|
||||||
void SetVSync(bool vsync);
|
void SetVSync(bool vsync);
|
||||||
|
|
||||||
void ScaleCoordsFromWindow(int16_t &x, int16_t &y) override;
|
|
||||||
void Draw2D() override;
|
void Draw2D() override;
|
||||||
|
|
||||||
bool HWGammaActive = false; // Are we using hardware or software gamma?
|
bool HWGammaActive = false; // Are we using hardware or software gamma?
|
||||||
std::shared_ptr<FGLDebug> mDebug; // Debug API
|
std::shared_ptr<FGLDebug> mDebug; // Debug API
|
||||||
private:
|
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.
|
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;
|
int camtexcount = 0;
|
||||||
|
|
||||||
|
|
|
@ -627,7 +627,7 @@ void M_ScreenShot (const char *filename)
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
Printf ("Could not open %s\n", autoname.GetChars());
|
Printf ("Could not open %s\n", autoname.GetChars());
|
||||||
screen->ReleaseScreenshotBuffer();
|
delete[] buffer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (writepcx)
|
if (writepcx)
|
||||||
|
@ -641,7 +641,7 @@ void M_ScreenShot (const char *filename)
|
||||||
screen->GetWidth(), screen->GetHeight(), pitch, gamma);
|
screen->GetWidth(), screen->GetHeight(), pitch, gamma);
|
||||||
}
|
}
|
||||||
delete file;
|
delete file;
|
||||||
screen->ReleaseScreenshotBuffer();
|
delete[] buffer;
|
||||||
|
|
||||||
if (!screenshot_quiet)
|
if (!screenshot_quiet)
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,11 +130,6 @@ public:
|
||||||
}
|
}
|
||||||
// These methods should never be called.
|
// These methods should never be called.
|
||||||
void Update() { DBGBREAK; }
|
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; }
|
bool IsFullscreen() { DBGBREAK; return 0; }
|
||||||
int GetClientWidth() { DBGBREAK; return 0; }
|
int GetClientWidth() { DBGBREAK; return 0; }
|
||||||
int GetClientHeight() { DBGBREAK; return 0; }
|
int GetClientHeight() { DBGBREAK; return 0; }
|
||||||
|
@ -818,6 +813,37 @@ void FPaletteTester::MakeTexture()
|
||||||
CurTranslation = t;
|
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
|
// 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());
|
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)
|
CCMD(clean)
|
||||||
|
|
|
@ -343,6 +343,9 @@ protected:
|
||||||
bool Bgra = 0;
|
bool Bgra = 0;
|
||||||
int clipleft = 0, cliptop = 0, clipwidth = -1, clipheight = -1;
|
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:
|
public:
|
||||||
int hwcaps = 0;
|
int hwcaps = 0;
|
||||||
int instack[2] = { 0,0 }; // this is globally maintained state for portal recursion avoidance.
|
int instack[2] = { 0,0 }; // this is globally maintained state for portal recursion avoidance.
|
||||||
|
@ -362,13 +365,13 @@ public:
|
||||||
virtual void Update () = 0;
|
virtual void Update () = 0;
|
||||||
|
|
||||||
// Return a pointer to 256 palette entries that can be written to.
|
// 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
|
// 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().
|
// 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
|
// Sets the gamma level. Returns false if the hardware does not support
|
||||||
// gamma changing. (Always true for now, since palettes can always be
|
// 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
|
// 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
|
// does not support this. (Always true for now, since palettes can always
|
||||||
// be flashed.)
|
// be flashed.)
|
||||||
virtual bool SetFlash (PalEntry rgb, int amount) = 0;
|
bool SetFlash (PalEntry rgb, int amount);
|
||||||
|
|
||||||
// Converse of SetFlash
|
// Converse of SetFlash
|
||||||
virtual void GetFlash (PalEntry &rgb, int &amount) = 0;
|
void GetFlash (PalEntry &rgb, int &amount);
|
||||||
|
|
||||||
// Returns true if running fullscreen.
|
// Returns true if running fullscreen.
|
||||||
virtual bool IsFullscreen () = 0;
|
virtual bool IsFullscreen () = 0;
|
||||||
|
@ -419,7 +422,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// Report a game restart
|
// Report a game restart
|
||||||
virtual void GameRestart();
|
void InitPalette();
|
||||||
virtual void InitForLevel() {}
|
virtual void InitForLevel() {}
|
||||||
virtual void SetClearColor(int color) {}
|
virtual void SetClearColor(int color) {}
|
||||||
virtual uint32_t GetCaps();
|
virtual uint32_t GetCaps();
|
||||||
|
@ -433,7 +436,8 @@ public:
|
||||||
virtual bool WipeDo(int ticks);
|
virtual bool WipeDo(int ticks);
|
||||||
virtual void WipeCleanup();
|
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; }
|
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.
|
// 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) {}
|
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.
|
// The original size of the framebuffer as selected in the video menu.
|
||||||
int VideoWidth = 0;
|
int VideoWidth = 0;
|
||||||
int VideoHeight = 0;
|
int VideoHeight = 0;
|
||||||
|
|
Loading…
Reference in a new issue