- cleaned out unused stuff from DCanvas.

- removed CocoaFrameBuffer because it is a software fallback which is no longer supported.
This commit is contained in:
Christoph Oelckers 2018-03-27 11:25:06 +02:00
parent ba799aebbd
commit 1a28644d83
8 changed files with 2 additions and 410 deletions

View file

@ -1111,17 +1111,6 @@ int OpenGLSWFrameBuffer::GetPageCount()
return 2;
}
//==========================================================================
//
// OpenGLSWFrameBuffer :: IsValid
//
//==========================================================================
bool OpenGLSWFrameBuffer::IsValid()
{
return Valid;
}
//==========================================================================
//
// OpenGLSWFrameBuffer :: Lock

View file

@ -31,7 +31,6 @@ public:
OpenGLSWFrameBuffer(void *hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen, bool bgra);
~OpenGLSWFrameBuffer();
bool IsValid() override;
bool Lock(bool buffered) override;
void Unlock() override;
void Update() override;

View file

@ -315,57 +315,6 @@ private:
// ---------------------------------------------------------------------------
class CocoaFrameBuffer : public DFrameBuffer
{
public:
CocoaFrameBuffer(int width, int height, bool bgra, bool fullscreen);
~CocoaFrameBuffer();
virtual bool Lock(bool buffer);
virtual void Unlock();
virtual void Update();
virtual PalEntry* GetPalette();
virtual void GetFlashedPalette(PalEntry pal[256]);
virtual void UpdatePalette();
virtual bool SetGamma(float gamma);
virtual bool SetFlash(PalEntry rgb, int amount);
virtual void GetFlash(PalEntry &rgb, int &amount);
virtual int GetPageCount();
virtual bool IsFullscreen();
virtual void SetVSync(bool vsync);
private:
static const size_t BYTES_PER_PIXEL = 4;
PalEntry m_palette[256];
bool m_needPaletteUpdate;
uint8_t m_gammaTable[3][256];
float m_gamma;
bool m_needGammaUpdate;
PalEntry m_flashColor;
int m_flashAmount;
bool UpdatePending;
uint8_t* m_pixelBuffer;
GLuint m_texture;
void Flip();
void UpdateColors();
};
// ---------------------------------------------------------------------------
EXTERN_CVAR(Float, Gamma)
CUSTOM_CVAR(Float, rgamma, 1.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
@ -659,20 +608,9 @@ DFrameBuffer* CocoaVideo::CreateFrameBuffer(const int width, const int height, c
{
fb = new OpenGLFrameBuffer(NULL, width, height, 32, 60, fullscreen);
}
else if (vid_glswfb)
{
fb = CreateGLSWFrameBuffer(width, height, bgra, fullscreen);
if (!fb->IsValid())
{
delete fb;
fb = new CocoaFrameBuffer(width, height, bgra, fullscreen);
}
}
else
{
fb = new CocoaFrameBuffer(width, height, bgra, fullscreen);
fb = CreateGLSWFrameBuffer(width, height, bgra, fullscreen);
}
fb->SetFlash(flashColor, flashAmount);
@ -861,265 +799,6 @@ CocoaVideo* CocoaVideo::GetInstance()
// ---------------------------------------------------------------------------
CocoaFrameBuffer::CocoaFrameBuffer(int width, int height, bool bgra, bool fullscreen)
: DFrameBuffer(width, height, bgra)
, m_needPaletteUpdate(false)
, m_gamma(0.0f)
, m_needGammaUpdate(false)
, m_flashAmount(0)
, UpdatePending(false)
, m_pixelBuffer(new uint8_t[width * height * BYTES_PER_PIXEL])
, m_texture(0)
{
static bool isOpenGLInitialized;
if (!isOpenGLInitialized)
{
if (ogl_LoadFunctions() == ogl_LOAD_FAILED)
{
I_FatalError("Failed to load OpenGL functions.");
}
isOpenGLInitialized = true;
}
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texture);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
GPfx.SetFormat(32, 0x000000FF, 0x0000FF00, 0x00FF0000);
for (size_t i = 0; i < 256; ++i)
{
m_gammaTable[0][i] = m_gammaTable[1][i] = m_gammaTable[2][i] = i;
}
memcpy(m_palette, GPalette.BaseColors, sizeof(PalEntry) * 256);
UpdateColors();
SetVSync(vid_vsync);
}
CocoaFrameBuffer::~CocoaFrameBuffer()
{
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(1, &m_texture);
delete[] m_pixelBuffer;
}
int CocoaFrameBuffer::GetPageCount()
{
return 1;
}
bool CocoaFrameBuffer::Lock(bool buffered)
{
return DSimpleCanvas::Lock(buffered);
}
void CocoaFrameBuffer::Unlock()
{
if (UpdatePending && LockCount == 1)
{
Update();
}
else if (--LockCount <= 0)
{
Buffer = NULL;
LockCount = 0;
}
}
void CocoaFrameBuffer::Update()
{
if (LockCount != 1)
{
if (LockCount > 0)
{
UpdatePending = true;
--LockCount;
}
return;
}
DrawRateStuff();
Buffer = NULL;
LockCount = 0;
UpdatePending = false;
BlitCycles.Reset();
FlipCycles.Reset();
BlitCycles.Clock();
if (IsBgra())
{
CopyWithGammaBgra(m_pixelBuffer, Width * BYTES_PER_PIXEL, m_gammaTable[0], m_gammaTable[1], m_gammaTable[2], m_flashColor, m_flashAmount);
}
else
{
GPfx.Convert(MemBuffer, Pitch, m_pixelBuffer, Width * BYTES_PER_PIXEL,
Width, Height, FRACUNIT, FRACUNIT, 0, 0);
}
FlipCycles.Clock();
Flip();
FlipCycles.Unclock();
BlitCycles.Unclock();
if (m_needGammaUpdate)
{
CalcGamma(rgamma == 0.0f ? m_gamma : m_gamma * rgamma, m_gammaTable[0]);
CalcGamma(ggamma == 0.0f ? m_gamma : m_gamma * ggamma, m_gammaTable[1]);
CalcGamma(bgamma == 0.0f ? m_gamma : m_gamma * bgamma, m_gammaTable[2]);
m_needGammaUpdate = false;
m_needPaletteUpdate = true;
}
if (m_needPaletteUpdate)
{
m_needPaletteUpdate = false;
UpdateColors();
}
}
void CocoaFrameBuffer::UpdateColors()
{
PalEntry palette[256];
for (size_t i = 0; i < 256; ++i)
{
palette[i].r = m_gammaTable[0][m_palette[i].r];
palette[i].g = m_gammaTable[1][m_palette[i].g];
palette[i].b = m_gammaTable[2][m_palette[i].b];
}
if (0 != m_flashAmount)
{
DoBlending(palette, palette, 256,
m_gammaTable[0][m_flashColor.r],
m_gammaTable[1][m_flashColor.g],
m_gammaTable[2][m_flashColor.b],
m_flashAmount);
}
GPfx.SetPalette(palette);
}
PalEntry* CocoaFrameBuffer::GetPalette()
{
return m_palette;
}
void CocoaFrameBuffer::UpdatePalette()
{
m_needPaletteUpdate = true;
}
bool CocoaFrameBuffer::SetGamma(float gamma)
{
m_gamma = gamma;
m_needGammaUpdate = true;
return true;
}
bool CocoaFrameBuffer::SetFlash(PalEntry rgb, int amount)
{
m_flashColor = rgb;
m_flashAmount = amount;
m_needPaletteUpdate = true;
return true;
}
void CocoaFrameBuffer::GetFlash(PalEntry &rgb, int &amount)
{
rgb = m_flashColor;
amount = m_flashAmount;
}
void CocoaFrameBuffer::GetFlashedPalette(PalEntry pal[256])
{
memcpy(pal, m_palette, sizeof m_palette);
if (0 != m_flashAmount)
{
DoBlending(pal, pal, 256,
m_flashColor.r, m_flashColor.g, m_flashColor.b,
m_flashAmount);
}
}
bool CocoaFrameBuffer::IsFullscreen()
{
return CocoaVideo::IsFullscreen();
}
void CocoaFrameBuffer::SetVSync(bool vsync)
{
const GLint value = vsync ? 1 : 0;
[[NSOpenGLContext currentContext] setValues:&value
forParameter:NSOpenGLCPSwapInterval];
}
void CocoaFrameBuffer::Flip()
{
assert(NULL != screen);
if (rbOpts.dirty)
{
glViewport(rbOpts.shiftX, rbOpts.shiftY, rbOpts.width, rbOpts.height);
// TODO: Figure out why the following glClear() call is needed
// to avoid drawing of garbage in fullscreen mode when
// in-game's aspect ratio is different from display one
glClear(GL_COLOR_BUFFER_BIT);
rbOpts.dirty = false;
}
const GLenum format = IsBgra() ? GL_BGRA : GL_RGBA;
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, Width, Height, 0, format, GL_UNSIGNED_BYTE, m_pixelBuffer);
glBegin(GL_QUADS);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(Width, 0.0f);
glVertex2f(Width, 0.0f);
glTexCoord2f(Width, Height);
glVertex2f(Width, Height);
glTexCoord2f(0.0f, Height);
glVertex2f(0.0f, Height);
glEnd();
glFlush();
[[NSOpenGLContext currentContext] flushBuffer];
}
// ---------------------------------------------------------------------------
SDLGLFB::SDLGLFB(void*, const int width, const int height, int, int, const bool fullscreen, bool bgra)
: DFrameBuffer(width, height, bgra)
, m_Lock(0)

View file

@ -113,7 +113,6 @@ const uint32_t *FCanvasTexture::GetPixelsBgra()
void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style because making it work as alpha texture is impractical.
{
Canvas = new DSimpleCanvas (Width, Height, false);
Canvas->Lock ();
if (Width != Height || Width != Canvas->GetPitch())
{
@ -134,7 +133,6 @@ void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style
void FCanvasTexture::MakeTextureBgra()
{
CanvasBgra = new DSimpleCanvas(Width, Height, true);
CanvasBgra->Lock();
if (Width != Height || Width != CanvasBgra->GetPitch())
{

View file

@ -216,18 +216,6 @@ DCanvas::~DCanvas ()
{
}
//==========================================================================
//
// DCanvas :: IsValid
//
//==========================================================================
bool DCanvas::IsValid ()
{
// A nun-subclassed DCanvas is never valid
return false;
}
//==========================================================================
//
// V_GetColorFromString
@ -609,48 +597,6 @@ DSimpleCanvas::~DSimpleCanvas ()
}
}
//==========================================================================
//
// DSimpleCanvas :: IsValid
//
//==========================================================================
bool DSimpleCanvas::IsValid ()
{
return (MemBuffer != NULL);
}
//==========================================================================
//
// DSimpleCanvas :: Lock
//
//==========================================================================
bool DSimpleCanvas::Lock (bool)
{
if (LockCount == 0)
{
Buffer = MemBuffer;
}
LockCount++;
return false; // System surfaces are never lost
}
//==========================================================================
//
// DSimpleCanvas :: Unlock
//
//==========================================================================
void DSimpleCanvas::Unlock ()
{
if (--LockCount <= 0)
{
LockCount = 0;
Buffer = NULL; // Enforce buffer access only between Lock/Unlock
}
}
//==========================================================================
//
// DFrameBuffer Constructor

View file

@ -212,7 +212,6 @@ public:
inline int GetPitch () const { return Pitch; }
inline bool IsBgra() const { return Bgra; }
virtual bool IsValid ();
protected:
uint8_t *Buffer;
@ -227,9 +226,6 @@ protected:
DCanvas() {}
private:
// Keep track of canvases, for automatic destruction at exit
DCanvas *Next;
static DCanvas *CanvasChain;
};
// A canvas in system memory.
@ -241,10 +237,6 @@ public:
DSimpleCanvas (int width, int height, bool bgra);
~DSimpleCanvas ();
bool IsValid ();
bool Lock (bool buffered=true);
void Unlock ();
protected:
void Resize(int width, int height);
@ -294,6 +286,7 @@ public:
DFrameBuffer (int width, int height, bool bgra);
// Access control
virtual bool IsValid() = delete;
virtual bool Lock(bool buffered = true) = 0; // Returns true if the surface was lost since last time
virtual void Unlock() = 0;

View file

@ -894,17 +894,6 @@ int D3DFB::GetPageCount ()
return 1;
}
//==========================================================================
//
// D3DFB :: IsValid
//
//==========================================================================
bool D3DFB::IsValid ()
{
return D3DDevice != NULL;
}
//==========================================================================
//
// D3DFB :: GetHR

View file

@ -24,7 +24,6 @@ public:
D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen);
~D3DFB ();
bool IsValid ();
bool Lock (bool buffered);
void Unlock ();
void Update ();