mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 15:22:15 +00:00
- Enabled vid_vsync for SDL2 although just turning it on doesn't perform right.
- Improved fullscreen a bit.
This commit is contained in:
parent
d625caf03c
commit
4aef696007
1 changed files with 76 additions and 18 deletions
|
@ -43,6 +43,7 @@ public:
|
||||||
bool SetGamma (float gamma);
|
bool SetGamma (float gamma);
|
||||||
bool SetFlash (PalEntry rgb, int amount);
|
bool SetFlash (PalEntry rgb, int amount);
|
||||||
void GetFlash (PalEntry &rgb, int &amount);
|
void GetFlash (PalEntry &rgb, int &amount);
|
||||||
|
void SetFullscreen (bool fullscreen);
|
||||||
int GetPageCount ();
|
int GetPageCount ();
|
||||||
bool IsFullscreen ();
|
bool IsFullscreen ();
|
||||||
|
|
||||||
|
@ -61,12 +62,14 @@ private:
|
||||||
SDL_Window *Screen;
|
SDL_Window *Screen;
|
||||||
SDL_Renderer *Renderer;
|
SDL_Renderer *Renderer;
|
||||||
SDL_Texture *Texture;
|
SDL_Texture *Texture;
|
||||||
|
SDL_Rect UpdateRect;
|
||||||
|
|
||||||
bool NeedPalUpdate;
|
bool NeedPalUpdate;
|
||||||
bool NeedGammaUpdate;
|
bool NeedGammaUpdate;
|
||||||
bool NotPaletted;
|
bool NotPaletted;
|
||||||
|
|
||||||
void UpdateColors ();
|
void UpdateColors ();
|
||||||
|
void ResetSDLRenderer ();
|
||||||
|
|
||||||
SDLFB () {}
|
SDLFB () {}
|
||||||
};
|
};
|
||||||
|
@ -241,7 +244,7 @@ DFrameBuffer *SDLVideo::CreateFrameBuffer (int width, int height, bool fullscree
|
||||||
|
|
||||||
if (fsnow != fullscreen)
|
if (fsnow != fullscreen)
|
||||||
{
|
{
|
||||||
SDL_SetWindowFullscreen (fb->Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
fb->SetFullscreen (fullscreen);
|
||||||
}
|
}
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
@ -323,6 +326,7 @@ SDLFB::SDLFB (int width, int height, bool fullscreen)
|
||||||
|
|
||||||
FString caption;
|
FString caption;
|
||||||
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
|
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
|
||||||
|
|
||||||
Screen = SDL_CreateWindow (caption,
|
Screen = SDL_CreateWindow (caption,
|
||||||
SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter),
|
SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter),
|
||||||
width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
|
width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
|
||||||
|
@ -330,33 +334,24 @@ SDLFB::SDLFB (int width, int height, bool fullscreen)
|
||||||
if (Screen == NULL)
|
if (Screen == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Renderer = SDL_CreateRenderer (Screen, -1, SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE);
|
Renderer = NULL;
|
||||||
if (Renderer == NULL)
|
Texture = NULL;
|
||||||
return;
|
ResetSDLRenderer ();
|
||||||
|
|
||||||
Texture = SDL_CreateTexture (Renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
|
||||||
|
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
||||||
{
|
{
|
||||||
GammaTable[0][i] = GammaTable[1][i] = GammaTable[2][i] = i;
|
GammaTable[0][i] = GammaTable[1][i] = GammaTable[2][i] = i;
|
||||||
}
|
}
|
||||||
//if (Screen->format->palette == NULL)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256);
|
memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256);
|
||||||
UpdateColors ();
|
UpdateColors ();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
SetVSync (vid_vsync);
|
SetVSync (vid_vsync);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SDLFB::~SDLFB ()
|
SDLFB::~SDLFB ()
|
||||||
{
|
{
|
||||||
if(Screen)
|
if(Screen)
|
||||||
|
@ -464,7 +459,7 @@ void SDLFB::Update ()
|
||||||
SDL_UnlockTexture (Texture);
|
SDL_UnlockTexture (Texture);
|
||||||
|
|
||||||
SDLFlipCycles.Clock();
|
SDLFlipCycles.Clock();
|
||||||
SDL_RenderCopy(Renderer, Texture, NULL, NULL);
|
SDL_RenderCopy(Renderer, Texture, NULL, &UpdateRect);
|
||||||
SDL_RenderPresent(Renderer);
|
SDL_RenderPresent(Renderer);
|
||||||
SDLFlipCycles.Unclock();
|
SDLFlipCycles.Unclock();
|
||||||
|
|
||||||
|
@ -570,11 +565,72 @@ void SDLFB::GetFlashedPalette (PalEntry pal[256])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLFB::SetFullscreen (bool fullscreen)
|
||||||
|
{
|
||||||
|
SDL_SetWindowFullscreen (Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||||
|
if (!fullscreen)
|
||||||
|
{
|
||||||
|
// Restore proper window size
|
||||||
|
SDL_SetWindowSize (Screen, Width, Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResetSDLRenderer ();
|
||||||
|
}
|
||||||
|
|
||||||
bool SDLFB::IsFullscreen ()
|
bool SDLFB::IsFullscreen ()
|
||||||
{
|
{
|
||||||
return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
|
return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLFB::ResetSDLRenderer ()
|
||||||
|
{
|
||||||
|
if (Renderer)
|
||||||
|
{
|
||||||
|
if (Texture)
|
||||||
|
SDL_DestroyTexture (Texture);
|
||||||
|
SDL_DestroyRenderer (Renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer = SDL_CreateRenderer (Screen, -1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE|
|
||||||
|
(vid_vsync ? SDL_RENDERER_PRESENTVSYNC : 0));
|
||||||
|
if (!Renderer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Texture = SDL_CreateTexture (Renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Width, Height);
|
||||||
|
|
||||||
|
//if (Screen->format->palette == NULL)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate update rectangle
|
||||||
|
if (IsFullscreen ())
|
||||||
|
{
|
||||||
|
int w, h;
|
||||||
|
SDL_GetWindowSize (Screen, &w, &h);
|
||||||
|
UpdateRect.w = w;
|
||||||
|
UpdateRect.h = w*Height/Width;
|
||||||
|
UpdateRect.x = 0;
|
||||||
|
UpdateRect.y = (h - UpdateRect.h)/2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// In windowed mode we just update the whole window.
|
||||||
|
UpdateRect.x = 0;
|
||||||
|
UpdateRect.y = 0;
|
||||||
|
UpdateRect.w = Width;
|
||||||
|
UpdateRect.h = Height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SDLFB::SetVSync (bool vsync)
|
void SDLFB::SetVSync (bool vsync)
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
@ -592,6 +648,8 @@ void SDLFB::SetVSync (bool vsync)
|
||||||
const GLint value = vsync ? 1 : 0;
|
const GLint value = vsync ? 1 : 0;
|
||||||
CGLSetParameter(context, kCGLCPSwapInterval, &value);
|
CGLSetParameter(context, kCGLCPSwapInterval, &value);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
ResetSDLRenderer ();
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue