mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-01 08:31:45 +00:00
- split base and OpenGL Cocoa framebuffers properly
This commit is contained in:
parent
ca1d8191aa
commit
c30b1a1f4a
2 changed files with 122 additions and 104 deletions
|
@ -51,15 +51,14 @@ public:
|
||||||
SystemBaseFrameBuffer(void *hMonitor, bool fullscreen);
|
SystemBaseFrameBuffer(void *hMonitor, bool fullscreen);
|
||||||
~SystemBaseFrameBuffer();
|
~SystemBaseFrameBuffer();
|
||||||
|
|
||||||
virtual bool IsFullscreen();
|
bool IsFullscreen() override;
|
||||||
virtual void SetVSync(bool vsync);
|
|
||||||
|
|
||||||
int GetClientWidth() override;
|
int GetClientWidth() override;
|
||||||
int GetClientHeight() override;
|
int GetClientHeight() override;
|
||||||
void ToggleFullscreen(bool yes) override;
|
void ToggleFullscreen(bool yes) override;
|
||||||
void SetWindowSize(int width, int height) override;
|
void SetWindowSize(int width, int height) override;
|
||||||
|
|
||||||
void SetMode(bool fullscreen, bool hiDPI);
|
virtual void SetMode(bool fullscreen, bool hiDPI);
|
||||||
|
|
||||||
static void UseHiDPI(bool hiDPI);
|
static void UseHiDPI(bool hiDPI);
|
||||||
static void SetCursor(NSCursor* cursor);
|
static void SetCursor(NSCursor* cursor);
|
||||||
|
@ -69,12 +68,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
SystemBaseFrameBuffer() {}
|
SystemBaseFrameBuffer() {}
|
||||||
|
|
||||||
void SwapBuffers();
|
|
||||||
|
|
||||||
void SetGammaTable(uint16_t* table);
|
|
||||||
void ResetGammaTable();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void SetFullscreenMode();
|
void SetFullscreenMode();
|
||||||
void SetWindowedMode();
|
void SetWindowedMode();
|
||||||
|
|
||||||
|
@ -83,12 +76,6 @@ private:
|
||||||
|
|
||||||
CocoaWindow* m_window;
|
CocoaWindow* m_window;
|
||||||
|
|
||||||
static const uint32_t GAMMA_CHANNEL_SIZE = 256;
|
|
||||||
static const uint32_t GAMMA_CHANNEL_COUNT = 3;
|
|
||||||
static const uint32_t GAMMA_TABLE_SIZE = GAMMA_CHANNEL_SIZE * GAMMA_CHANNEL_COUNT;
|
|
||||||
|
|
||||||
uint16_t m_originalGamma[GAMMA_TABLE_SIZE];
|
|
||||||
|
|
||||||
int GetTitleBarHeight() const;
|
int GetTitleBarHeight() const;
|
||||||
|
|
||||||
static const int MINIMUM_WIDTH = 320;
|
static const int MINIMUM_WIDTH = 320;
|
||||||
|
@ -100,11 +87,15 @@ class SystemGLFrameBuffer : public SystemBaseFrameBuffer
|
||||||
typedef SystemBaseFrameBuffer Super;
|
typedef SystemBaseFrameBuffer Super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SystemGLFrameBuffer(void *hMonitor, bool fullscreen)
|
SystemGLFrameBuffer(void *hMonitor, bool fullscreen);
|
||||||
: SystemBaseFrameBuffer(hMonitor, fullscreen)
|
|
||||||
{}
|
void SetVSync(bool vsync) override;
|
||||||
|
|
||||||
|
void SetMode(bool fullscreen, bool hiDPI) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void SwapBuffers();
|
||||||
|
|
||||||
SystemGLFrameBuffer() {}
|
SystemGLFrameBuffer() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -165,19 +165,17 @@ namespace
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@interface CocoaView : NSOpenGLView
|
@interface OpenGLCocoaView : NSOpenGLView
|
||||||
{
|
{
|
||||||
NSCursor* m_cursor;
|
NSCursor* m_cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetCursorRects;
|
|
||||||
|
|
||||||
- (void)setCursor:(NSCursor*)cursor;
|
- (void)setCursor:(NSCursor*)cursor;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation CocoaView
|
@implementation OpenGLCocoaView
|
||||||
|
|
||||||
- (void)resetCursorRects
|
- (void)resetCursorRects
|
||||||
{
|
{
|
||||||
|
@ -220,11 +218,6 @@ public:
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
EXTERN_CVAR(Float, Gamma)
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
extern id appCtrl;
|
extern id appCtrl;
|
||||||
|
|
||||||
|
|
||||||
|
@ -297,28 +290,9 @@ SystemBaseFrameBuffer::SystemBaseFrameBuffer(void*, const bool fullscreen)
|
||||||
{
|
{
|
||||||
SetFlash(0, 0);
|
SetFlash(0, 0);
|
||||||
|
|
||||||
NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat();
|
|
||||||
|
|
||||||
if (nil == pixelFormat)
|
|
||||||
{
|
|
||||||
I_FatalError("Cannot create OpenGL pixel format, graphics hardware is not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create OpenGL context and view
|
|
||||||
|
|
||||||
const NSRect contentRect = [m_window contentRectForFrameRect:[m_window frame]];
|
|
||||||
NSOpenGLView* glView = [[CocoaView alloc] initWithFrame:contentRect
|
|
||||||
pixelFormat:pixelFormat];
|
|
||||||
[[glView openGLContext] makeCurrentContext];
|
|
||||||
|
|
||||||
[m_window setContentView:glView];
|
|
||||||
|
|
||||||
assert(frameBuffer == nullptr);
|
assert(frameBuffer == nullptr);
|
||||||
frameBuffer = this;
|
frameBuffer = this;
|
||||||
|
|
||||||
// To be able to use OpenGL functions in SetMode()
|
|
||||||
ogl_LoadFunctions();
|
|
||||||
|
|
||||||
FConsoleWindow::GetInstance().Show(false);
|
FConsoleWindow::GetInstance().Show(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,6 +308,8 @@ SystemBaseFrameBuffer::~SystemBaseFrameBuffer()
|
||||||
[nc removeObserver:m_window
|
[nc removeObserver:m_window
|
||||||
name:NSWindowDidEndLiveResizeNotification
|
name:NSWindowDidEndLiveResizeNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
|
[m_window dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemBaseFrameBuffer::IsFullscreen()
|
bool SystemBaseFrameBuffer::IsFullscreen()
|
||||||
|
@ -378,20 +354,6 @@ int SystemBaseFrameBuffer::GetTitleBarHeight() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::SetVSync(bool vsync)
|
|
||||||
{
|
|
||||||
const GLint value = vsync ? 1 : 0;
|
|
||||||
|
|
||||||
[[NSOpenGLContext currentContext] setValues:&value
|
|
||||||
forParameter:NSOpenGLCPSwapInterval];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::SwapBuffers()
|
|
||||||
{
|
|
||||||
[[NSOpenGLContext currentContext] flushBuffer];
|
|
||||||
}
|
|
||||||
|
|
||||||
int SystemBaseFrameBuffer::GetClientWidth()
|
int SystemBaseFrameBuffer::GetClientWidth()
|
||||||
{
|
{
|
||||||
const int clientWidth = I_GetContentViewSize(m_window).width;
|
const int clientWidth = I_GetContentViewSize(m_window).width;
|
||||||
|
@ -453,6 +415,113 @@ void SystemBaseFrameBuffer::SetWindowedMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI)
|
void SystemBaseFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI)
|
||||||
|
{
|
||||||
|
if (fullscreen)
|
||||||
|
{
|
||||||
|
SetFullscreenMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowedMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
[m_window updateTitle];
|
||||||
|
|
||||||
|
if (![m_window isKeyWindow])
|
||||||
|
{
|
||||||
|
[m_window makeKeyAndOrderFront:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fullscreen = fullscreen;
|
||||||
|
m_hiDPI = hiDPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SystemBaseFrameBuffer::UseHiDPI(const bool hiDPI)
|
||||||
|
{
|
||||||
|
if (frameBuffer != nullptr)
|
||||||
|
{
|
||||||
|
frameBuffer->SetMode(frameBuffer->m_fullscreen, hiDPI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemBaseFrameBuffer::SetCursor(NSCursor* cursor)
|
||||||
|
{
|
||||||
|
if (frameBuffer != nullptr)
|
||||||
|
{
|
||||||
|
NSWindow* const window = frameBuffer->m_window;
|
||||||
|
id view = [window contentView];
|
||||||
|
|
||||||
|
[view setCursor:cursor];
|
||||||
|
[window invalidateCursorRectsForView:view];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemBaseFrameBuffer::SetWindowVisible(bool visible)
|
||||||
|
{
|
||||||
|
if (frameBuffer != nullptr)
|
||||||
|
{
|
||||||
|
if (visible)
|
||||||
|
{
|
||||||
|
[frameBuffer->m_window orderFront:nil];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[frameBuffer->m_window orderOut:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
I_SetNativeMouse(!visible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemBaseFrameBuffer::SetWindowTitle(const char* title)
|
||||||
|
{
|
||||||
|
if (frameBuffer != nullptr)
|
||||||
|
{
|
||||||
|
NSString* const nsTitle = nullptr == title ? nil :
|
||||||
|
[NSString stringWithCString:title encoding:NSISOLatin1StringEncoding];
|
||||||
|
[frameBuffer->m_window setTitle:nsTitle];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
SystemGLFrameBuffer::SystemGLFrameBuffer(void *hMonitor, bool fullscreen)
|
||||||
|
: SystemBaseFrameBuffer(hMonitor, fullscreen)
|
||||||
|
{
|
||||||
|
NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat();
|
||||||
|
|
||||||
|
if (nil == pixelFormat)
|
||||||
|
{
|
||||||
|
I_FatalError("Cannot create OpenGL pixel format, graphics hardware is not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create OpenGL context and view
|
||||||
|
|
||||||
|
const NSRect contentRect = [m_window contentRectForFrameRect:[m_window frame]];
|
||||||
|
OpenGLCocoaView* glView = [[OpenGLCocoaView alloc] initWithFrame:contentRect
|
||||||
|
pixelFormat:pixelFormat];
|
||||||
|
[[glView openGLContext] makeCurrentContext];
|
||||||
|
|
||||||
|
[m_window setContentView:glView];
|
||||||
|
|
||||||
|
// To be able to use OpenGL functions in SetMode()
|
||||||
|
ogl_LoadFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SystemGLFrameBuffer::SetVSync(bool vsync)
|
||||||
|
{
|
||||||
|
const GLint value = vsync ? 1 : 0;
|
||||||
|
|
||||||
|
[[NSOpenGLContext currentContext] setValues:&value
|
||||||
|
forParameter:NSOpenGLCPSwapInterval];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SystemGLFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI)
|
||||||
{
|
{
|
||||||
NSOpenGLView* const glView = [m_window contentView];
|
NSOpenGLView* const glView = [m_window contentView];
|
||||||
[glView setWantsBestResolutionOpenGLSurface:hiDPI];
|
[glView setWantsBestResolutionOpenGLSurface:hiDPI];
|
||||||
|
@ -486,51 +555,9 @@ void SystemBaseFrameBuffer::SetMode(const bool fullscreen, const bool hiDPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::UseHiDPI(const bool hiDPI)
|
void SystemGLFrameBuffer::SwapBuffers()
|
||||||
{
|
{
|
||||||
if (frameBuffer != nullptr)
|
[[NSOpenGLContext currentContext] flushBuffer];
|
||||||
{
|
|
||||||
frameBuffer->SetMode(frameBuffer->m_fullscreen, hiDPI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::SetCursor(NSCursor* cursor)
|
|
||||||
{
|
|
||||||
if (frameBuffer != nullptr)
|
|
||||||
{
|
|
||||||
NSWindow* const window = frameBuffer->m_window;
|
|
||||||
CocoaView* const view = [window contentView];
|
|
||||||
|
|
||||||
[view setCursor:cursor];
|
|
||||||
[window invalidateCursorRectsForView:view];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::SetWindowVisible(bool visible)
|
|
||||||
{
|
|
||||||
if (frameBuffer != nullptr)
|
|
||||||
{
|
|
||||||
if (visible)
|
|
||||||
{
|
|
||||||
[frameBuffer->m_window orderFront:nil];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[frameBuffer->m_window orderOut:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
I_SetNativeMouse(!visible);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SystemBaseFrameBuffer::SetWindowTitle(const char* title)
|
|
||||||
{
|
|
||||||
if (frameBuffer != nullptr)
|
|
||||||
{
|
|
||||||
NSString* const nsTitle = nullptr == title ? nil :
|
|
||||||
[NSString stringWithCString:title encoding:NSISOLatin1StringEncoding];
|
|
||||||
[frameBuffer->m_window setTitle:nsTitle];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue