mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 15:22:15 +00:00
Cleanup video part of native OS X backend, phase 1
This commit is contained in:
parent
195ed09c5e
commit
41c949f8ac
1 changed files with 67 additions and 224 deletions
|
@ -247,22 +247,6 @@ CUSTOM_CVAR(Bool, fullscreen, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
setmodeneeded = true;
|
setmodeneeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_CVAR(Float, vid_winscale, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
||||||
{
|
|
||||||
if (self < 1.f)
|
|
||||||
{
|
|
||||||
self = 1.f;
|
|
||||||
}
|
|
||||||
else if (Video)
|
|
||||||
{
|
|
||||||
Video->SetWindowedScale (self);
|
|
||||||
NewWidth = screen->GetWidth();
|
|
||||||
NewHeight = screen->GetHeight();
|
|
||||||
NewBits = DisplayBits;
|
|
||||||
setmodeneeded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -2117,21 +2101,6 @@ int SDL_QueryTexture(SDL_Texture *texture, Uint32* format, int* access, int* w,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SDL_LockTexture(SDL_Texture* texture, const SDL_Rect *rect, void** pixels, int *pitch)
|
|
||||||
{
|
|
||||||
assert(NULL == rect);
|
|
||||||
|
|
||||||
*pixels = texture->window->pixels;
|
|
||||||
*pitch = texture->window->pitch;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDL_UnlockTexture(SDL_Texture *texture)
|
|
||||||
{
|
|
||||||
ZD_UNUSED(texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
int SDL_UpdateWindowSurface(SDL_Window *screen)
|
int SDL_UpdateWindowSurface(SDL_Window *screen)
|
||||||
{
|
{
|
||||||
assert(NULL != screen);
|
assert(NULL != screen);
|
||||||
|
@ -2179,31 +2148,11 @@ int SDL_UpdateWindowSurface(SDL_Window *screen)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
|
|
||||||
{
|
|
||||||
ZD_UNUSED(renderer);
|
|
||||||
ZD_UNUSED(texture);
|
|
||||||
ZD_UNUSED(srcrect);
|
|
||||||
ZD_UNUSED(dstrect);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDL_RenderPresent(SDL_Renderer *renderer)
|
void SDL_RenderPresent(SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
SDL_UpdateWindowSurface(renderer->window);
|
SDL_UpdateWindowSurface(renderer->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDL_SetPaletteColors(SDL_Palette* palette, const SDL_Color* colors, int firstcolor, int ncolors)
|
|
||||||
{
|
|
||||||
ZD_UNUSED(palette);
|
|
||||||
ZD_UNUSED(colors);
|
|
||||||
ZD_UNUSED(firstcolor);
|
|
||||||
ZD_UNUSED(ncolors);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
|
|
||||||
|
@ -2213,27 +2162,25 @@ int SDL_SetPaletteColors(SDL_Palette* palette, const SDL_Color* colors, int firs
|
||||||
class CocoaVideo : public IVideo
|
class CocoaVideo : public IVideo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CocoaVideo(int parm);
|
explicit CocoaVideo(int dummy);
|
||||||
~CocoaVideo();
|
|
||||||
|
|
||||||
EDisplayType GetDisplayType () { return DISPLAY_Both; }
|
virtual EDisplayType GetDisplayType() { return DISPLAY_Both; }
|
||||||
void SetWindowedScale (float scale);
|
virtual void SetWindowedScale(float scale);
|
||||||
|
|
||||||
DFrameBuffer *CreateFrameBuffer (int width, int height, bool fs, DFrameBuffer *old);
|
virtual DFrameBuffer* CreateFrameBuffer(int width, int height, bool fs, DFrameBuffer* old);
|
||||||
|
|
||||||
void StartModeIterator (int bits, bool fs);
|
virtual void StartModeIterator(int bits, bool fs);
|
||||||
bool NextMode (int *width, int *height, bool *letterbox);
|
virtual bool NextMode(int* width, int* height, bool* letterbox);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int IteratorMode;
|
size_t m_modeIterator;
|
||||||
int IteratorBits;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CocoaFrameBuffer : public DFrameBuffer
|
class CocoaFrameBuffer : public DFrameBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CocoaFrameBuffer (int width, int height, bool fullscreen);
|
CocoaFrameBuffer(int width, int height, bool fullscreen);
|
||||||
~CocoaFrameBuffer ();
|
~CocoaFrameBuffer();
|
||||||
|
|
||||||
bool Lock (bool buffer);
|
bool Lock (bool buffer);
|
||||||
void Unlock ();
|
void Unlock ();
|
||||||
|
@ -2270,11 +2217,9 @@ private:
|
||||||
SDL_Texture *Texture;
|
SDL_Texture *Texture;
|
||||||
SDL_Surface *Surface;
|
SDL_Surface *Surface;
|
||||||
};
|
};
|
||||||
SDL_Rect UpdateRect;
|
|
||||||
|
|
||||||
bool NeedPalUpdate;
|
bool NeedPalUpdate;
|
||||||
bool NeedGammaUpdate;
|
bool NeedGammaUpdate;
|
||||||
bool NotPaletted;
|
|
||||||
|
|
||||||
void UpdateColors ();
|
void UpdateColors ();
|
||||||
void ResetSDLRenderer ();
|
void ResetSDLRenderer ();
|
||||||
|
@ -2379,66 +2324,40 @@ static MiniModeInfo WinModes[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
static cycle_t BlitCycles;
|
static cycle_t BlitCycles;
|
||||||
static cycle_t SDLFlipCycles;
|
static cycle_t FlipCycles;
|
||||||
|
|
||||||
// CODE --------------------------------------------------------------------
|
|
||||||
|
|
||||||
void ScaleWithAspect (Uint16 &w, Uint16 &h, Uint16 Width, Uint16 Height)
|
CocoaVideo::CocoaVideo(int dummy)
|
||||||
|
: m_modeIterator(0)
|
||||||
{
|
{
|
||||||
int resRatio = CheckRatio (Width, Height);
|
ZD_UNUSED(dummy);
|
||||||
int screenRatio;
|
}
|
||||||
CheckRatio (w, h, &screenRatio);
|
|
||||||
if (resRatio == screenRatio)
|
|
||||||
return;
|
|
||||||
|
|
||||||
double yratio;
|
void CocoaVideo::StartModeIterator(int bits, bool fs)
|
||||||
switch(resRatio)
|
{
|
||||||
|
ZD_UNUSED(bits);
|
||||||
|
ZD_UNUSED(fs);
|
||||||
|
|
||||||
|
m_modeIterator = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CocoaVideo::NextMode(int* width, int* height, bool* letterbox)
|
||||||
|
{
|
||||||
|
ZD_UNUSED(letterbox);
|
||||||
|
|
||||||
|
if (m_modeIterator < sizeof(WinModes) / sizeof(WinModes[0]))
|
||||||
{
|
{
|
||||||
case 0: yratio = 4./3.; break;
|
*width = WinModes[m_modeIterator].Width;
|
||||||
case 1: yratio = 16./9.; break;
|
*height = WinModes[m_modeIterator].Height;
|
||||||
case 2: yratio = 16./10.; break;
|
|
||||||
case 3: yratio = 17./10.; break;
|
|
||||||
case 4: yratio = 5./4.; break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
double y = w/yratio;
|
|
||||||
if (y > h)
|
|
||||||
w = h*yratio;
|
|
||||||
else
|
|
||||||
h = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
CocoaVideo::CocoaVideo (int parm)
|
++m_modeIterator;
|
||||||
{
|
|
||||||
IteratorBits = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CocoaVideo::~CocoaVideo ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CocoaVideo::StartModeIterator (int bits, bool fs)
|
|
||||||
{
|
|
||||||
IteratorMode = 0;
|
|
||||||
IteratorBits = bits;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CocoaVideo::NextMode (int *width, int *height, bool *letterbox)
|
|
||||||
{
|
|
||||||
if (IteratorBits != 8)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ((unsigned)IteratorMode < sizeof(WinModes)/sizeof(WinModes[0]))
|
|
||||||
{
|
|
||||||
*width = WinModes[IteratorMode].Width;
|
|
||||||
*height = WinModes[IteratorMode].Height;
|
|
||||||
++IteratorMode;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DFrameBuffer *CocoaVideo::CreateFrameBuffer (int width, int height, bool fullscreen, DFrameBuffer *old)
|
DFrameBuffer *CocoaVideo::CreateFrameBuffer(int width, int height, bool fullscreen, DFrameBuffer* old)
|
||||||
{
|
{
|
||||||
static int retry = 0;
|
static int retry = 0;
|
||||||
static int owidth, oheight;
|
static int owidth, oheight;
|
||||||
|
@ -2525,16 +2444,13 @@ void CocoaVideo::SetWindowedScale (float scale)
|
||||||
|
|
||||||
|
|
||||||
CocoaFrameBuffer::CocoaFrameBuffer (int width, int height, bool fullscreen)
|
CocoaFrameBuffer::CocoaFrameBuffer (int width, int height, bool fullscreen)
|
||||||
: DFrameBuffer (width, height)
|
: DFrameBuffer(width, height)
|
||||||
|
, FlashAmount(0)
|
||||||
|
, Gamma(0.0f)
|
||||||
|
, UpdatePending(false)
|
||||||
|
, NeedPalUpdate(false)
|
||||||
|
, NeedGammaUpdate(false)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
NeedPalUpdate = false;
|
|
||||||
NeedGammaUpdate = false;
|
|
||||||
UpdatePending = false;
|
|
||||||
NotPaletted = false;
|
|
||||||
FlashAmount = 0;
|
|
||||||
|
|
||||||
FString caption;
|
FString caption;
|
||||||
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
|
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
|
||||||
|
|
||||||
|
@ -2548,7 +2464,7 @@ CocoaFrameBuffer::CocoaFrameBuffer (int width, int height, bool fullscreen)
|
||||||
Texture = NULL;
|
Texture = NULL;
|
||||||
ResetSDLRenderer ();
|
ResetSDLRenderer ();
|
||||||
|
|
||||||
for (i = 0; i < 256; i++)
|
for (size_t 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;
|
||||||
}
|
}
|
||||||
|
@ -2627,42 +2543,15 @@ void CocoaFrameBuffer::Update ()
|
||||||
UpdatePending = false;
|
UpdatePending = false;
|
||||||
|
|
||||||
BlitCycles.Reset();
|
BlitCycles.Reset();
|
||||||
SDLFlipCycles.Reset();
|
FlipCycles.Reset();
|
||||||
BlitCycles.Clock();
|
BlitCycles.Clock();
|
||||||
|
|
||||||
void *pixels;
|
GPfx.Convert(MemBuffer, Pitch, Texture->window->pixels, Texture->window->pitch,
|
||||||
int pitch;
|
Width, Height, FRACUNIT, FRACUNIT, 0, 0);
|
||||||
|
|
||||||
if (SDL_LockTexture (Texture, NULL, &pixels, &pitch))
|
FlipCycles.Clock();
|
||||||
return;
|
|
||||||
|
|
||||||
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 ((BYTE *)pixels+y*pitch, MemBuffer+y*Pitch, Width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_UnlockTexture (Texture);
|
|
||||||
|
|
||||||
SDLFlipCycles.Clock();
|
|
||||||
SDL_RenderCopy(Renderer, Texture, NULL, &UpdateRect);
|
|
||||||
SDL_RenderPresent(Renderer);
|
SDL_RenderPresent(Renderer);
|
||||||
SDLFlipCycles.Unclock();
|
FlipCycles.Unclock();
|
||||||
|
|
||||||
BlitCycles.Unclock();
|
BlitCycles.Unclock();
|
||||||
|
|
||||||
|
@ -2685,42 +2574,23 @@ void CocoaFrameBuffer::Update ()
|
||||||
|
|
||||||
void CocoaFrameBuffer::UpdateColors ()
|
void CocoaFrameBuffer::UpdateColors ()
|
||||||
{
|
{
|
||||||
if (NotPaletted)
|
|
||||||
{
|
|
||||||
PalEntry palette[256];
|
PalEntry palette[256];
|
||||||
|
|
||||||
for (int i = 0; i < 256; ++i)
|
for (size_t i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
palette[i].r = GammaTable[0][SourcePalette[i].r];
|
palette[i].r = GammaTable[0][SourcePalette[i].r];
|
||||||
palette[i].g = GammaTable[1][SourcePalette[i].g];
|
palette[i].g = GammaTable[1][SourcePalette[i].g];
|
||||||
palette[i].b = GammaTable[2][SourcePalette[i].b];
|
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)
|
if (FlashAmount)
|
||||||
{
|
{
|
||||||
DoBlending ((PalEntry *)colors, (PalEntry *)colors,
|
DoBlending(palette, palette, 256,
|
||||||
256, GammaTable[2][Flash.b], GammaTable[1][Flash.g], GammaTable[0][Flash.r],
|
GammaTable[0][Flash.r], GammaTable[1][Flash.g], GammaTable[2][Flash.b],
|
||||||
FlashAmount);
|
FlashAmount);
|
||||||
}
|
}
|
||||||
SDL_SetPaletteColors (Surface->format->palette, colors, 0, 256);
|
|
||||||
}
|
GPfx.SetPalette (palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
PalEntry *CocoaFrameBuffer::GetPalette ()
|
PalEntry *CocoaFrameBuffer::GetPalette ()
|
||||||
|
@ -2728,7 +2598,7 @@ PalEntry *CocoaFrameBuffer::GetPalette ()
|
||||||
return SourcePalette;
|
return SourcePalette;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaFrameBuffer::UpdatePalette ()
|
void CocoaFrameBuffer::UpdatePalette()
|
||||||
{
|
{
|
||||||
NeedPalUpdate = true;
|
NeedPalUpdate = true;
|
||||||
}
|
}
|
||||||
|
@ -2806,9 +2676,6 @@ void CocoaFrameBuffer::ResetSDLRenderer ()
|
||||||
// }
|
// }
|
||||||
Texture = SDL_CreateTexture (Renderer, fmt, SDL_TEXTUREACCESS_STREAMING, Width, Height);
|
Texture = SDL_CreateTexture (Renderer, fmt, SDL_TEXTUREACCESS_STREAMING, Width, Height);
|
||||||
|
|
||||||
{
|
|
||||||
NotPaletted = true;
|
|
||||||
|
|
||||||
Uint32 format;
|
Uint32 format;
|
||||||
SDL_QueryTexture(Texture, &format, NULL, NULL, NULL);
|
SDL_QueryTexture(Texture, &format, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
@ -2816,27 +2683,6 @@ void CocoaFrameBuffer::ResetSDLRenderer ()
|
||||||
int bpp;
|
int bpp;
|
||||||
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
|
SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
|
||||||
GPfx.SetFormat (bpp, Rmask, Gmask, Bmask);
|
GPfx.SetFormat (bpp, Rmask, Gmask, Bmask);
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate update rectangle
|
|
||||||
if (IsFullscreen ())
|
|
||||||
{
|
|
||||||
int w, h;
|
|
||||||
SDL_GetWindowSize (Screen, &w, &h);
|
|
||||||
UpdateRect.w = w;
|
|
||||||
UpdateRect.h = h;
|
|
||||||
ScaleWithAspect (UpdateRect.w, UpdateRect.h, Width, Height);
|
|
||||||
UpdateRect.x = (w - UpdateRect.w)/2;
|
|
||||||
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 CocoaFrameBuffer::SetVSync (bool vsync)
|
void CocoaFrameBuffer::SetVSync (bool vsync)
|
||||||
|
@ -2855,11 +2701,10 @@ void CocoaFrameBuffer::SetVSync (bool vsync)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ADD_STAT (blit)
|
ADD_STAT(blit)
|
||||||
{
|
{
|
||||||
FString out;
|
FString out;
|
||||||
out.Format ("blit=%04.1f ms flip=%04.1f ms",
|
out.Format("blit=%04.1f ms flip=%04.1f ms", BlitCycles.TimeMS(), FlipCycles.TimeMS());
|
||||||
BlitCycles.TimeMS(), SDLFlipCycles.TimeMS());
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2892,8 +2737,6 @@ void I_InitGraphics ()
|
||||||
I_FatalError ("Failed to initialize display");
|
I_FatalError ("Failed to initialize display");
|
||||||
|
|
||||||
atterm (I_ShutdownGraphics);
|
atterm (I_ShutdownGraphics);
|
||||||
|
|
||||||
Video->SetWindowedScale (vid_winscale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void I_DeleteRenderer()
|
static void I_DeleteRenderer()
|
||||||
|
|
Loading…
Reference in a new issue