- removed SDLFB and cleaned things up a bit.

This commit is contained in:
Christoph Oelckers 2018-03-27 11:59:43 +02:00
parent 1a28644d83
commit e0f1abdf81
6 changed files with 8 additions and 542 deletions

View File

@ -36,7 +36,9 @@ extern int sys_ostype;
#include "version.h"
#include "v_video.h"
#ifdef _WIN32
EXTERN_CVAR(Bool, vid_glswfb)
#endif
extern int currentrenderer;
CVAR(Int, sys_statsenabled, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET)
CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET)
@ -254,9 +256,9 @@ static int GetRenderInfo()
{
if (currentrenderer == 0)
{
if (!screen->Accel2D) return 0;
#ifdef _WIN32
if (vid_glswfb) return 2;
if (screen->LegacyHardware()) return 6;
#endif
return 1;
}
else

View File

@ -103,11 +103,6 @@ DFrameBuffer *CreateGLSWFrameBuffer(int width, int height, bool bgra, bool fulls
int currentrenderer;
CUSTOM_CVAR(Bool, vid_glswfb, true, CVAR_NOINITCALL | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
EXTERN_CVAR(Bool, ticker )
EXTERN_CVAR(Bool, vid_vsync)
EXTERN_CVAR(Bool, vid_hidpi)
@ -497,11 +492,6 @@ CocoaVideo::CocoaVideo()
// There is no support for OpenGL 3.3 before Mavericks
defaultProfile = NSOpenGLProfileVersionLegacy;
}
else if (0 == vid_renderer && 0 == vid_glswfb)
{
// Software renderer uses OpenGL 2.1 for blitting
defaultProfile = NSOpenGLProfileVersionLegacy;
}
else if (const char* const glversion = Args->CheckValue("-glversion"))
{
// Check for explicit version specified in command line

View File

@ -93,19 +93,11 @@ CUSTOM_CVAR(Bool, gl_debug, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINI
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
#ifdef __arm__
CUSTOM_CVAR(Bool, vid_glswfb, false, CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
CUSTOM_CVAR(Bool, gl_es, false, CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
#else
CUSTOM_CVAR(Bool, vid_glswfb, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
CUSTOM_CVAR(Bool, gl_es, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
@ -248,18 +240,9 @@ DFrameBuffer *SDLGLVideo::CreateFrameBuffer (int width, int height, bool bgra, b
{
fb = new OpenGLFrameBuffer(0, width, height, 32, 60, fullscreen);
}
else if (vid_glswfb == 0)
{
fb = new SDLFB(width, height, bgra, fullscreen, nullptr);
}
else
{
fb = (SDLBaseFB*)CreateGLSWFrameBuffer(width, height, bgra, fullscreen);
if (!fb->IsValid())
{
delete fb;
fb = new SDLFB(width, height, bgra, fullscreen, nullptr);
}
}
retry = 0;
@ -271,13 +254,8 @@ DFrameBuffer *SDLGLVideo::CreateFrameBuffer (int width, int height, bool bgra, b
// 3. Try in the opposite screen mode with the closest size
// This is a somewhat confusing mass of recursion here.
while (fb == NULL || !fb->IsValid ())
while (fb == NULL)
{
if (fb != NULL)
{
delete fb;
}
switch (retry)
{
case 0:

View File

@ -112,437 +112,6 @@ static cycle_t SDLFlipCycles;
// CODE --------------------------------------------------------------------
// FrameBuffer implementation -----------------------------------------------
SDLFB::SDLFB (int width, int height, bool bgra, bool fullscreen, SDL_Window *oldwin)
: SDLBaseFB (width, height, bgra)
{
int i;
NeedPalUpdate = false;
NeedGammaUpdate = false;
UpdatePending = false;
NotPaletted = false;
FlashAmount = 0;
if (oldwin)
{
// In some cases (Mac OS X fullscreen) SDL2 doesn't like having multiple windows which
// appears to inevitably happen while compositor animations are running. So lets try
// to reuse the existing window.
Screen = oldwin;
SDL_SetWindowSize (Screen, width, height);
SetFullscreen (fullscreen);
}
else
{
FString caption;
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
Screen = SDL_CreateWindow (caption,
SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter),
width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)|SDL_WINDOW_RESIZABLE);
if (Screen == NULL)
return;
}
Renderer = NULL;
Texture = NULL;
ResetSDLRenderer ();
for (i = 0; i < 256; i++)
{
GammaTable[0][i] = GammaTable[1][i] = GammaTable[2][i] = i;
}
memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256);
UpdateColors ();
#ifdef __APPLE__
SetVSync (vid_vsync);
#endif
}
SDLFB::~SDLFB ()
{
if (Renderer)
{
if (Texture)
SDL_DestroyTexture (Texture);
SDL_DestroyRenderer (Renderer);
}
if(Screen)
{
SDL_DestroyWindow (Screen);
}
}
bool SDLFB::IsValid ()
{
return DFrameBuffer::IsValid() && Screen != NULL;
}
int SDLFB::GetPageCount ()
{
return 1;
}
bool SDLFB::Lock (bool buffered)
{
return DSimpleCanvas::Lock ();
}
bool SDLFB::Relock ()
{
return DSimpleCanvas::Lock ();
}
void SDLFB::Unlock ()
{
if (UpdatePending && LockCount == 1)
{
Update ();
}
else if (--LockCount <= 0)
{
Buffer = NULL;
LockCount = 0;
}
}
void SDLFB::Update ()
{
if (LockCount != 1)
{
if (LockCount > 0)
{
UpdatePending = true;
--LockCount;
}
return;
}
DrawRateStuff ();
#if !defined(__APPLE__) && !defined(__OpenBSD__)
if(vid_maxfps && !cl_capfps)
{
SEMAPHORE_WAIT(FPSLimitSemaphore)
}
#endif
Buffer = NULL;
LockCount = 0;
UpdatePending = false;
BlitCycles.Reset();
SDLFlipCycles.Reset();
BlitCycles.Clock();
void *pixels;
int pitch;
if (UsingRenderer)
{
if (SDL_LockTexture (Texture, NULL, &pixels, &pitch))
return;
}
else
{
if (SDL_LockSurface (Surface))
return;
pixels = Surface->pixels;
pitch = Surface->pitch;
}
if (Bgra)
{
CopyWithGammaBgra(pixels, pitch, GammaTable[0], GammaTable[1], GammaTable[2], Flash, FlashAmount);
}
else if (NotPaletted)
{
GPfx.Convert (MemBuffer, Pitch,
pixels, pitch, Width, Height,
FRACUNIT, FRACUNIT, 0, 0);
}
else
{
if (pitch == Pitch)
{
memcpy (pixels, MemBuffer, Width*Height);
}
else
{
for (int y = 0; y < Height; ++y)
{
memcpy ((uint8_t *)pixels+y*pitch, MemBuffer+y*Pitch, Width);
}
}
}
if (UsingRenderer)
{
SDL_UnlockTexture (Texture);
SDLFlipCycles.Clock();
SDL_RenderClear(Renderer);
SDL_RenderCopy(Renderer, Texture, NULL, NULL);
SDL_RenderPresent(Renderer);
SDLFlipCycles.Unclock();
}
else
{
SDL_UnlockSurface (Surface);
SDLFlipCycles.Clock();
SDL_UpdateWindowSurface (Screen);
SDLFlipCycles.Unclock();
}
BlitCycles.Unclock();
if (NeedGammaUpdate)
{
bool Windowed = false;
NeedGammaUpdate = false;
CalcGamma ((Windowed || rgamma == 0.f) ? Gamma : (Gamma * rgamma), GammaTable[0]);
CalcGamma ((Windowed || ggamma == 0.f) ? Gamma : (Gamma * ggamma), GammaTable[1]);
CalcGamma ((Windowed || bgamma == 0.f) ? Gamma : (Gamma * bgamma), GammaTable[2]);
NeedPalUpdate = true;
}
if (NeedPalUpdate)
{
NeedPalUpdate = false;
UpdateColors ();
}
}
void SDLFB::UpdateColors ()
{
if (NotPaletted)
{
PalEntry palette[256];
for (int i = 0; i < 256; ++i)
{
palette[i].r = GammaTable[0][SourcePalette[i].r];
palette[i].g = GammaTable[1][SourcePalette[i].g];
palette[i].b = GammaTable[2][SourcePalette[i].b];
}
if (FlashAmount)
{
DoBlending (palette, palette,
256, GammaTable[0][Flash.r], GammaTable[1][Flash.g], GammaTable[2][Flash.b],
FlashAmount);
}
GPfx.SetPalette (palette);
}
else
{
SDL_Color colors[256];
for (int i = 0; i < 256; ++i)
{
colors[i].r = GammaTable[0][SourcePalette[i].r];
colors[i].g = GammaTable[1][SourcePalette[i].g];
colors[i].b = GammaTable[2][SourcePalette[i].b];
}
if (FlashAmount)
{
DoBlending ((PalEntry *)colors, (PalEntry *)colors,
256, GammaTable[2][Flash.b], GammaTable[1][Flash.g], GammaTable[0][Flash.r],
FlashAmount);
}
SDL_SetPaletteColors (Surface->format->palette, colors, 0, 256);
}
}
PalEntry *SDLFB::GetPalette ()
{
return SourcePalette;
}
void SDLFB::UpdatePalette ()
{
NeedPalUpdate = true;
}
bool SDLFB::SetGamma (float gamma)
{
Gamma = gamma;
NeedGammaUpdate = true;
return true;
}
bool SDLFB::SetFlash (PalEntry rgb, int amount)
{
Flash = rgb;
FlashAmount = amount;
NeedPalUpdate = true;
return true;
}
void SDLFB::GetFlash (PalEntry &rgb, int &amount)
{
rgb = Flash;
amount = FlashAmount;
}
// Q: Should I gamma adjust the returned palette?
void SDLFB::GetFlashedPalette (PalEntry pal[256])
{
memcpy (pal, SourcePalette, 256*sizeof(PalEntry));
if (FlashAmount)
{
DoBlending (pal, pal, 256, Flash.r, Flash.g, Flash.b, FlashAmount);
}
}
void SDLFB::SetFullscreen (bool fullscreen)
{
if (IsFullscreen() == fullscreen)
return;
SDL_SetWindowFullscreen (Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
if (!fullscreen)
{
// Restore proper window size
SDL_SetWindowSize (Screen, Width, Height);
}
ResetSDLRenderer ();
}
bool SDLFB::IsFullscreen ()
{
return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
}
void SDLFB::ResetSDLRenderer ()
{
if (Renderer)
{
if (Texture)
SDL_DestroyTexture (Texture);
SDL_DestroyRenderer (Renderer);
}
UsingRenderer = !vid_forcesurface;
if (UsingRenderer)
{
Renderer = SDL_CreateRenderer (Screen, -1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE|
(vid_vsync ? SDL_RENDERER_PRESENTVSYNC : 0));
if (!Renderer)
return;
SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255);
Uint32 fmt;
if (Bgra)
{
fmt = SDL_PIXELFORMAT_ARGB8888;
}
else
{
switch (vid_displaybits)
{
default: fmt = SDL_PIXELFORMAT_ARGB8888; break;
case 30: fmt = SDL_PIXELFORMAT_ARGB2101010; break;
case 24: fmt = SDL_PIXELFORMAT_RGB888; break;
case 16: fmt = SDL_PIXELFORMAT_RGB565; break;
case 15: fmt = SDL_PIXELFORMAT_ARGB1555; break;
}
}
Texture = SDL_CreateTexture (Renderer, fmt, SDL_TEXTUREACCESS_STREAMING, Width, Height);
{
NotPaletted = true;
Uint32 format;
SDL_QueryTexture(Texture, &format, NULL, NULL, NULL);
Uint32 Rmask, Gmask, Bmask, Amask;
int bpp;
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
GPfx.SetFormat (bpp, Rmask, Gmask, Bmask);
}
}
else
{
Surface = SDL_GetWindowSurface (Screen);
if (Surface->format->palette == NULL)
{
NotPaletted = true;
GPfx.SetFormat (Surface->format->BitsPerPixel, Surface->format->Rmask, Surface->format->Gmask, Surface->format->Bmask);
}
else
NotPaletted = false;
}
// In fullscreen, set logical size according to animorphic ratio.
// Windowed modes are rendered to fill the window (usually 1:1)
if (IsFullscreen ())
{
int w, h;
SDL_GetWindowSize (Screen, &w, &h);
ScaleWithAspect (w, h, Width, Height);
SDL_RenderSetLogicalSize (Renderer, w, h);
}
}
void SDLFB::SetVSync (bool vsync)
{
#ifdef __APPLE__
if (CGLContextObj context = CGLGetCurrentContext())
{
// Apply vsync for native backend only (where OpenGL context is set)
const GLint value = vsync ? 1 : 0;
CGLSetParameter(context, kCGLCPSwapInterval, &value);
}
#else
ResetSDLRenderer ();
#endif // __APPLE__
}
void SDLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
{
int w, h;
SDL_GetWindowSize (Screen, &w, &h);
// Detect if we're doing scaling in the Window and adjust the mouse
// coordinates accordingly. This could be more efficent, but I
// don't think performance is an issue in the menus.
if(IsFullscreen())
{
int realw = w, realh = h;
ScaleWithAspect (realw, realh, SCREENWIDTH, SCREENHEIGHT);
if (realw != SCREENWIDTH || realh != SCREENHEIGHT)
{
double xratio = (double)SCREENWIDTH/realw;
double yratio = (double)SCREENHEIGHT/realh;
if (realw < w)
{
x = (x - (w - realw)/2)*xratio;
y *= yratio;
}
else
{
y = (y - (h - realh)/2)*yratio;
x *= xratio;
}
}
}
else
{
x = (int16_t)(x*Width/w);
y = (int16_t)(y*Height/h);
}
}
ADD_STAT (blit)
{
@ -555,6 +124,8 @@ ADD_STAT (blit)
// each platform has its own specific version of this function.
void I_SetWindowTitle(const char* caption)
{
#if 0
// This needs to be done differently. The static_cast here is fundamentally wrong because SDLFB is not the true ancestor of the screen's class.
auto Screen = static_cast<SDLFB *>(screen)->GetSDLWindow();
if (caption)
SDL_SetWindowTitle(static_cast<SDLFB *>(screen)->GetSDLWindow(), caption);
@ -564,5 +135,6 @@ void I_SetWindowTitle(const char* caption)
default_caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
SDL_SetWindowTitle(static_cast<SDLFB *>(screen)->GetSDLWindow(), default_caption);
}
#endif
}

View File

@ -2,59 +2,3 @@
#include "v_video.h"
#include "sdlglvideo.h"
class SDLFB : public SDLBaseFB
{
typedef SDLBaseFB Super;
public:
SDLFB(int width, int height, bool bgra, bool fullscreen, SDL_Window *oldwin);
~SDLFB();
bool Lock(bool buffer);
void Unlock();
bool Relock();
void ForceBuffering(bool force);
bool IsValid();
void Update();
PalEntry *GetPalette();
void GetFlashedPalette(PalEntry pal[256]);
void UpdatePalette();
bool SetGamma(float gamma);
bool SetFlash(PalEntry rgb, int amount);
void GetFlash(PalEntry &rgb, int &amount);
void SetFullscreen(bool fullscreen);
int GetPageCount();
bool IsFullscreen();
friend class SDLGLVideo;
virtual void SetVSync(bool vsync);
virtual void ScaleCoordsFromWindow(int16_t &x, int16_t &y);
SDL_Window *GetSDLWindow() override { return Screen; }
private:
PalEntry SourcePalette[256];
uint8_t GammaTable[3][256];
PalEntry Flash;
int FlashAmount;
float Gamma;
bool UpdatePending;
SDL_Window *Screen;
SDL_Renderer *Renderer;
union
{
SDL_Texture *Texture;
SDL_Surface *Surface;
};
bool UsingRenderer;
bool NeedPalUpdate;
bool NeedGammaUpdate;
bool NotPaletted;
void UpdateColors();
void ResetSDLRenderer();
SDLFB() {}
};

View File

@ -1862,18 +1862,6 @@ OptionValue "GLD3D"
1, "$OPTVAL_GL"
}
OptionValue "GLSDL"
{
0, "$OPTVAL_SDL"
1, "$OPTVAL_GL"
}
OptionValue "GLCOCOA"
{
0, "$OPTVAL_COCOA"
1, "$OPTVAL_GL"
}
OptionMenu RendererMenu protected
{
Title "$RNDMNU_TITLE"
@ -1884,14 +1872,6 @@ OptionMenu RendererMenu protected
{
Option "$RNDMNU_CANVAS", "vid_glswfb", "GLD3D"
}
IfOption(unix)
{
Option "$RNDMNU_CANVAS", "vid_glswfb", "GLSDL"
}
IfOption(Mac)
{
Option "$RNDMNU_CANVAS", "vid_glswfb", "GLCOCOA"
}
}
/*=======================================