From a1d5833c8aa2f85817ad3c3cd64e0e618e8c695e Mon Sep 17 00:00:00 2001
From: "alexey.lysiuk" <alexey.lysiuk@gmail.com>
Date: Sat, 30 Jun 2018 11:06:41 +0300
Subject: [PATCH 1/3] - reset framebuffer pointer on destruction in Cocoa
 backend

Added debug validation of framebuffer pointer as well
---
 src/posix/cocoa/i_video.mm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm
index f4f03f2df..b3e422a26 100644
--- a/src/posix/cocoa/i_video.mm
+++ b/src/posix/cocoa/i_video.mm
@@ -386,6 +386,7 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen)
 		}
 	}
 
+	assert(frameBuffer == nullptr);
 	frameBuffer = this;
 
 	FConsoleWindow::GetInstance().Show(false);
@@ -393,6 +394,9 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen)
 
 SystemGLFrameBuffer::~SystemGLFrameBuffer()
 {
+	assert(frameBuffer == this);
+	frameBuffer = nullptr;
+
 	NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
 	[nc removeObserver:m_window
 				  name:NSWindowDidMoveNotification

From 49f2e75ee490907123aaea55ea6233282df34d8b Mon Sep 17 00:00:00 2001
From: "alexey.lysiuk" <alexey.lysiuk@gmail.com>
Date: Sat, 30 Jun 2018 11:13:12 +0300
Subject: [PATCH 2/3] - removed support of legacy OpenGL profile in Cocoa
 backend

Minimum OpenGL version is now 3.3 and so, the given legacy fallback doesn't make any sense
This increases required macOS version to 10.9 as on previous versions nothing but a black screen was rendered
---
 src/posix/cocoa/i_video.mm | 29 +++--------------------------
 1 file changed, 3 insertions(+), 26 deletions(-)

diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm
index b3e422a26..1e6e9cc19 100644
--- a/src/posix/cocoa/i_video.mm
+++ b/src/posix/cocoa/i_video.mm
@@ -288,7 +288,7 @@ CocoaWindow* CreateWindow(const NSUInteger styleMask)
 	return window;
 }
 
-NSOpenGLPixelFormat* CreatePixelFormat(const NSOpenGLPixelFormatAttribute profile)
+NSOpenGLPixelFormat* CreatePixelFormat()
 {
 	NSOpenGLPixelFormatAttribute attributes[16];
 	size_t i = 0;
@@ -301,7 +301,7 @@ NSOpenGLPixelFormat* CreatePixelFormat(const NSOpenGLPixelFormatAttribute profil
 	attributes[i++] = NSOpenGLPFAStencilSize;
 	attributes[i++] = NSOpenGLPixelFormatAttribute(8);
 	attributes[i++] = NSOpenGLPFAOpenGLProfile;
-	attributes[i++] = profile;
+	attributes[i++] = NSOpenGLProfileVersion3_2Core;
 	
 	if (!vid_autoswitch)
 	{
@@ -330,30 +330,7 @@ SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen)
 {
 	SetFlash(0, 0);
 
-	// Create OpenGL pixel format
-	NSOpenGLPixelFormatAttribute defaultProfile = NSOpenGLProfileVersion3_2Core;
-
-	if (NSAppKitVersionNumber < AppKit10_9)
-	{
-		// There is no support for OpenGL 3.3 before Mavericks
-		defaultProfile = NSOpenGLProfileVersionLegacy;
-	}
-	else if (const char* const glversion = Args->CheckValue("-glversion"))
-	{
-		// Check for explicit version specified in command line
-		const double version = strtod(glversion, nullptr) + 0.01;
-		if (version < 3.3)
-		{
-			defaultProfile = NSOpenGLProfileVersionLegacy;
-		}
-	}
-
-	NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat(defaultProfile);
-
-	if (nil == pixelFormat && NSOpenGLProfileVersion3_2Core == defaultProfile)
-	{
-		pixelFormat = CreatePixelFormat(NSOpenGLProfileVersionLegacy);
-	}
+	NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat();
 
 	if (nil == pixelFormat)
 	{

From c0c7573788945d3fcd9538ad370c9dfc2234091a Mon Sep 17 00:00:00 2001
From: Magnus Norddahl <dpjudas@users.noreply.github.com>
Date: Sat, 30 Jun 2018 16:46:33 +0200
Subject: [PATCH 3/3] - fix black ssao bug

---
 src/gl/scene/gl_scene.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp
index 942e646ae..4b087a0c3 100644
--- a/src/gl/scene/gl_scene.cpp
+++ b/src/gl/scene/gl_scene.cpp
@@ -75,7 +75,7 @@ EXTERN_CVAR (Bool, r_drawvoxels)
 void FDrawInfo::ApplyVPUniforms()
 {
 	VPUniforms.CalcDependencies();
-	GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms, NORMAL_PASS);
+	GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms, gl_RenderState.GetPassType());
 
 	if (!(gl.flags & RFL_NO_CLIP_PLANES))
 	{