Skip to content

Commit

Permalink
Add opengl renderer fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Kirch committed Jan 4, 2015
1 parent 4ef0f9f commit 100f658
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Handmade Hero OSX/Handmade Hero OSX/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import CoreVideo
// textureId that we'll use to store reference to our opengl texture
var textureId: GLuint = GLuint()
// pixel format attributes
let pixelFormatAttrs: [NSOpenGLPixelFormatAttribute] = [
// UInt32(NSOpenGLPFADoubleBuffer),
// UInt32(NSOpenGLPFAAccelerated),
// UInt32(NSOpenGLPFADepthSize), UInt32(24),
let pixelFormatAttrsBestCase: [NSOpenGLPixelFormatAttribute] = [
UInt32(NSOpenGLPFADoubleBuffer),
UInt32(NSOpenGLPFAAccelerated),
UInt32(NSOpenGLPFADepthSize), UInt32(24),
UInt32(0)
]
let pixelFormatAttrsFallbackCase: [NSOpenGLPixelFormatAttribute] = [
UInt32(NSOpenGLPFADepthSize), UInt32(24),
UInt32(0)
]
// list of vertices we'll use for defining our triangles
Expand Down Expand Up @@ -52,7 +56,15 @@ import CoreVideo
}

override func awakeFromNib() {
let pf = NSOpenGLPixelFormat(attributes: pixelFormatAttrs)
var pf = NSOpenGLPixelFormat(attributes: pixelFormatAttrsBestCase)
if (pf == nil) {
NSLog("Couldn't init opengl the way we wanted, using fallback")
pf = NSOpenGLPixelFormat(attributes: pixelFormatAttrsFallbackCase)
}
if (pf == nil) {
NSLog("Couldn't init opengl at all, sorry :(")
abort()
}
let glContext = NSOpenGLContext(format: pf, shareContext: nil)
self.pixelFormat = pf
self.openGLContext = glContext
Expand Down

0 comments on commit 100f658

Please sign in to comment.