mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
Cleanup video part of native OS X backend, phase 4
This commit is contained in:
parent
ebc0916bc6
commit
18c7709007
1 changed files with 69 additions and 77 deletions
|
@ -414,6 +414,8 @@ int OriginalMain(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
I_StartupJoysticks();
|
I_StartupJoysticks();
|
||||||
|
atterm(I_ShutdownJoysticks);
|
||||||
|
|
||||||
C_InitConsole(80 * 8, 25 * 8, false);
|
C_InitConsole(80 * 8, 25 * 8, false);
|
||||||
D_DoomMain();
|
D_DoomMain();
|
||||||
}
|
}
|
||||||
|
@ -1166,8 +1168,6 @@ namespace
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
|
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(NSNotification*)aNotification;
|
|
||||||
|
|
||||||
- (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)filename;
|
- (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)filename;
|
||||||
|
|
||||||
- (int)multisample;
|
- (int)multisample;
|
||||||
|
@ -1371,17 +1371,6 @@ static bool s_fullscreenNewAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(NSNotification*)aNotification
|
|
||||||
{
|
|
||||||
ZD_UNUSED(aNotification);
|
|
||||||
|
|
||||||
// Hide window as nothing will be rendered at this point
|
|
||||||
[m_window orderOut:nil];
|
|
||||||
|
|
||||||
I_ShutdownJoysticks();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (int)multisample
|
- (int)multisample
|
||||||
{
|
{
|
||||||
return m_multisample;
|
return m_multisample;
|
||||||
|
@ -1987,18 +1976,20 @@ public:
|
||||||
void SetFullscreen(bool fullscreen);
|
void SetFullscreen(bool fullscreen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PalEntry SourcePalette[256];
|
PalEntry m_palette[256];
|
||||||
BYTE GammaTable[3][256];
|
bool m_needPaletteUpdate;
|
||||||
PalEntry Flash;
|
|
||||||
int FlashAmount;
|
BYTE m_gammaTable[3][256];
|
||||||
float Gamma;
|
float m_gamma;
|
||||||
bool UpdatePending;
|
bool m_needGammaUpdate;
|
||||||
|
|
||||||
|
PalEntry m_flashColor;
|
||||||
|
int m_flashAmount;
|
||||||
|
|
||||||
|
bool m_isUpdatePending;
|
||||||
|
|
||||||
SDL_Window *Screen;
|
SDL_Window *Screen;
|
||||||
|
|
||||||
bool NeedPalUpdate;
|
|
||||||
bool NeedGammaUpdate;
|
|
||||||
|
|
||||||
void UpdateColors();
|
void UpdateColors();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2036,7 +2027,7 @@ CUSTOM_CVAR (Float, bgamma, 1.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static const struct MiniModeInfo
|
static const struct
|
||||||
{
|
{
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
|
@ -2125,6 +2116,8 @@ void CocoaVideo::StartModeIterator(int bits, bool fs)
|
||||||
|
|
||||||
bool CocoaVideo::NextMode(int* width, int* height, bool* letterbox)
|
bool CocoaVideo::NextMode(int* width, int* height, bool* letterbox)
|
||||||
{
|
{
|
||||||
|
assert(NULL != width);
|
||||||
|
assert(NULL != height);
|
||||||
ZD_UNUSED(letterbox);
|
ZD_UNUSED(letterbox);
|
||||||
|
|
||||||
if (m_modeIterator < sizeof(VideoModes) / sizeof(VideoModes[0]))
|
if (m_modeIterator < sizeof(VideoModes) / sizeof(VideoModes[0]))
|
||||||
|
@ -2226,11 +2219,11 @@ 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)
|
, m_needPaletteUpdate(false)
|
||||||
, Gamma(0.0f)
|
, m_gamma(0.0f)
|
||||||
, UpdatePending(false)
|
, m_needGammaUpdate(false)
|
||||||
, NeedPalUpdate(false)
|
, m_flashAmount(0)
|
||||||
, NeedGammaUpdate(false)
|
, m_isUpdatePending(false)
|
||||||
{
|
{
|
||||||
FString caption;
|
FString caption;
|
||||||
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
|
caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
|
||||||
|
@ -2245,10 +2238,10 @@ CocoaFrameBuffer::CocoaFrameBuffer (int width, int height, bool fullscreen)
|
||||||
|
|
||||||
for (size_t i = 0; i < 256; ++i)
|
for (size_t i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
GammaTable[0][i] = GammaTable[1][i] = GammaTable[2][i] = i;
|
m_gammaTable[0][i] = m_gammaTable[1][i] = m_gammaTable[2][i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(SourcePalette, GPalette.BaseColors, sizeof(PalEntry) * 256);
|
memcpy(m_palette, GPalette.BaseColors, sizeof(PalEntry) * 256);
|
||||||
UpdateColors();
|
UpdateColors();
|
||||||
|
|
||||||
SetVSync(vid_vsync);
|
SetVSync(vid_vsync);
|
||||||
|
@ -2280,7 +2273,7 @@ bool CocoaFrameBuffer::Lock (bool buffered)
|
||||||
|
|
||||||
void CocoaFrameBuffer::Unlock ()
|
void CocoaFrameBuffer::Unlock ()
|
||||||
{
|
{
|
||||||
if (UpdatePending && LockCount == 1)
|
if (m_isUpdatePending && LockCount == 1)
|
||||||
{
|
{
|
||||||
Update ();
|
Update ();
|
||||||
}
|
}
|
||||||
|
@ -2297,7 +2290,7 @@ void CocoaFrameBuffer::Update ()
|
||||||
{
|
{
|
||||||
if (LockCount > 0)
|
if (LockCount > 0)
|
||||||
{
|
{
|
||||||
UpdatePending = true;
|
m_isUpdatePending = true;
|
||||||
--LockCount;
|
--LockCount;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -2307,7 +2300,7 @@ void CocoaFrameBuffer::Update ()
|
||||||
|
|
||||||
Buffer = NULL;
|
Buffer = NULL;
|
||||||
LockCount = 0;
|
LockCount = 0;
|
||||||
UpdatePending = false;
|
m_isUpdatePending = false;
|
||||||
|
|
||||||
BlitCycles.Reset();
|
BlitCycles.Reset();
|
||||||
FlipCycles.Reset();
|
FlipCycles.Reset();
|
||||||
|
@ -2322,19 +2315,19 @@ void CocoaFrameBuffer::Update ()
|
||||||
|
|
||||||
BlitCycles.Unclock();
|
BlitCycles.Unclock();
|
||||||
|
|
||||||
if (NeedGammaUpdate)
|
if (m_needGammaUpdate)
|
||||||
{
|
{
|
||||||
bool Windowed = false;
|
bool Windowed = false;
|
||||||
NeedGammaUpdate = false;
|
m_needGammaUpdate = false;
|
||||||
CalcGamma((Windowed || rgamma == 0.f) ? Gamma : (Gamma * rgamma), GammaTable[0]);
|
CalcGamma((Windowed || rgamma == 0.f) ? m_gamma : (m_gamma * rgamma), m_gammaTable[0]);
|
||||||
CalcGamma((Windowed || ggamma == 0.f) ? Gamma : (Gamma * ggamma), GammaTable[1]);
|
CalcGamma((Windowed || ggamma == 0.f) ? m_gamma : (m_gamma * ggamma), m_gammaTable[1]);
|
||||||
CalcGamma((Windowed || bgamma == 0.f) ? Gamma : (Gamma * bgamma), GammaTable[2]);
|
CalcGamma((Windowed || bgamma == 0.f) ? m_gamma : (m_gamma * bgamma), m_gammaTable[2]);
|
||||||
NeedPalUpdate = true;
|
m_needPaletteUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NeedPalUpdate)
|
if (m_needPaletteUpdate)
|
||||||
{
|
{
|
||||||
NeedPalUpdate = false;
|
m_needPaletteUpdate = false;
|
||||||
UpdateColors();
|
UpdateColors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2345,16 +2338,16 @@ void CocoaFrameBuffer::UpdateColors()
|
||||||
|
|
||||||
for (size_t i = 0; i < 256; ++i)
|
for (size_t i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
palette[i].r = GammaTable[0][SourcePalette[i].r];
|
palette[i].r = m_gammaTable[0][m_palette[i].r];
|
||||||
palette[i].g = GammaTable[1][SourcePalette[i].g];
|
palette[i].g = m_gammaTable[1][m_palette[i].g];
|
||||||
palette[i].b = GammaTable[2][SourcePalette[i].b];
|
palette[i].b = m_gammaTable[2][m_palette[i].b];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FlashAmount)
|
if (m_flashAmount)
|
||||||
{
|
{
|
||||||
DoBlending(palette, palette, 256,
|
DoBlending(palette, palette, 256,
|
||||||
GammaTable[0][Flash.r], GammaTable[1][Flash.g], GammaTable[2][Flash.b],
|
m_gammaTable[0][m_flashColor.r], m_gammaTable[1][m_flashColor.g], m_gammaTable[2][m_flashColor.b],
|
||||||
FlashAmount);
|
m_flashAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
GPfx.SetPalette(palette);
|
GPfx.SetPalette(palette);
|
||||||
|
@ -2362,42 +2355,44 @@ void CocoaFrameBuffer::UpdateColors()
|
||||||
|
|
||||||
PalEntry *CocoaFrameBuffer::GetPalette ()
|
PalEntry *CocoaFrameBuffer::GetPalette ()
|
||||||
{
|
{
|
||||||
return SourcePalette;
|
return m_palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaFrameBuffer::UpdatePalette()
|
void CocoaFrameBuffer::UpdatePalette()
|
||||||
{
|
{
|
||||||
NeedPalUpdate = true;
|
m_needPaletteUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CocoaFrameBuffer::SetGamma(float gamma)
|
bool CocoaFrameBuffer::SetGamma(float gamma)
|
||||||
{
|
{
|
||||||
Gamma = gamma;
|
m_gamma = gamma;
|
||||||
NeedGammaUpdate = true;
|
m_needGammaUpdate = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CocoaFrameBuffer::SetFlash(PalEntry rgb, int amount)
|
bool CocoaFrameBuffer::SetFlash(PalEntry rgb, int amount)
|
||||||
{
|
{
|
||||||
Flash = rgb;
|
m_flashColor = rgb;
|
||||||
FlashAmount = amount;
|
m_flashAmount = amount;
|
||||||
NeedPalUpdate = true;
|
m_needPaletteUpdate = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaFrameBuffer::GetFlash(PalEntry &rgb, int &amount)
|
void CocoaFrameBuffer::GetFlash(PalEntry &rgb, int &amount)
|
||||||
{
|
{
|
||||||
rgb = Flash;
|
rgb = m_flashColor;
|
||||||
amount = FlashAmount;
|
amount = m_flashAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Q: Should I gamma adjust the returned palette?
|
|
||||||
void CocoaFrameBuffer::GetFlashedPalette(PalEntry pal[256])
|
void CocoaFrameBuffer::GetFlashedPalette(PalEntry pal[256])
|
||||||
{
|
{
|
||||||
memcpy (pal, SourcePalette, 256*sizeof(PalEntry));
|
memcpy(pal, m_palette, sizeof m_palette);
|
||||||
if (FlashAmount)
|
|
||||||
|
if (0 != m_flashAmount)
|
||||||
{
|
{
|
||||||
DoBlending (pal, pal, 256, Flash.r, Flash.g, Flash.b, FlashAmount);
|
DoBlending (pal, pal, 256, m_flashColor.r, m_flashColor.g, m_flashColor.b, m_flashAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2412,26 +2407,23 @@ bool CocoaFrameBuffer::IsFullscreen ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CocoaFrameBuffer::SetVSync (bool vsync)
|
void CocoaFrameBuffer::SetVSync (bool vsync)
|
||||||
{
|
|
||||||
if (CGLContextObj context = CGLGetCurrentContext())
|
|
||||||
{
|
{
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
|
||||||
// Inconsistency between 10.4 and 10.5 SDKs:
|
const long value = vsync ? 1 : 0;
|
||||||
// third argument of CGLSetParameter() is const long* on 10.4 and const GLint* on 10.5
|
#else // 10.5 or newer
|
||||||
// So, GLint typedef'ed to long instead of int to workaround this issue
|
const GLint value = vsync ? 1 : 0;
|
||||||
typedef long GLint;
|
|
||||||
#endif // prior to 10.5
|
#endif // prior to 10.5
|
||||||
|
|
||||||
const GLint value = vsync ? 1 : 0;
|
[[NSOpenGLContext currentContext] setValues:&value
|
||||||
CGLSetParameter(context, kCGLCPSwapInterval, &value);
|
forParameter:NSOpenGLCPSwapInterval];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ADD_STAT(blit)
|
ADD_STAT(blit)
|
||||||
{
|
{
|
||||||
FString out;
|
FString result;
|
||||||
out.Format("blit=%04.1f ms flip=%04.1f ms", BlitCycles.TimeMS(), FlipCycles.TimeMS());
|
result.Format("blit=%04.1f ms flip=%04.1f ms", BlitCycles.TimeMS(), FlipCycles.TimeMS());
|
||||||
return out;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue