diff --git a/framework/Source/iOS/OpenGLContext.swift b/framework/Source/iOS/OpenGLContext.swift index a740d7ac..39409db2 100755 --- a/framework/Source/iOS/OpenGLContext.swift +++ b/framework/Source/iOS/OpenGLContext.swift @@ -9,9 +9,9 @@ public class OpenGLContext: SerialDispatch { return FramebufferCache(context:self) }() var shaderCache:[String:ShaderProgram] = [:] - + let context:EAGLContext - + lazy var passthroughShader:ShaderProgram = { return crashOnShaderCompileFailure("OpenGLContext"){return try self.programForVertexShader(OneInputVertexShader, fragmentShader:PassthroughFragmentShader)} }() @@ -21,8 +21,8 @@ public class OpenGLContext: SerialDispatch { let err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, nil, self.context, nil, &newTextureCache) return newTextureCache! }() - - + + public let serialDispatchQueue:dispatch_queue_t = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.processingQueue", nil) var dispatchKey:Int = 1 public let dispatchQueueKey:UnsafePointer @@ -34,36 +34,36 @@ public class OpenGLContext: SerialDispatch { let context = UnsafeMutablePointer(Unmanaged.passUnretained(self.serialDispatchQueue).toOpaque()) dispatchQueueKey = UnsafePointer(bitPattern:dispatchKey) dispatch_queue_set_specific(serialDispatchQueue, dispatchQueueKey, context, nil) - + guard let generatedContext = EAGLContext(API:.OpenGLES2, sharegroup:imageProcessingShareGroup) else { fatalError("Unable to create an OpenGL ES 2.0 context. The GPUImage framework requires OpenGL ES 2.0 support to work.") } - + self.context = generatedContext self.makeCurrentContext() - + glDisable(GLenum(GL_DEPTH_TEST)) glEnable(GLenum(GL_TEXTURE_2D)) } - + // MARK: - // MARK: Rendering - + public func makeCurrentContext() { if (EAGLContext.currentContext() != self.context) { EAGLContext.setCurrentContext(self.context) } } - + func presentBufferForDisplay() { self.context.presentRenderbuffer(Int(GL_RENDERBUFFER)) } - - + + // MARK: - // MARK: Device capabilities - + func supportsTextureCaches() -> Bool { #if (arch(i386) || arch(x86_64)) && os(iOS) return false // Simulator glitches out on use of texture caches @@ -71,7 +71,7 @@ public class OpenGLContext: SerialDispatch { return true // Every iOS version and device that can run Swift can handle texture caches #endif } - + public var maximumTextureSizeForThisDevice:GLint {get { return _maximumTextureSizeForThisDevice } } private lazy var _maximumTextureSizeForThisDevice:GLint = { return self.openGLDeviceSettingForOption(GL_MAX_TEXTURE_SIZE) @@ -87,10 +87,13 @@ public class OpenGLContext: SerialDispatch { return self.openGLDeviceSettingForOption(GL_MAX_VARYING_VECTORS) }() - lazy var extensionString:String = { - return self.runOperationSynchronously{ + lazy var extensionString:String = self.createExtensionString() + + private func createExtensionString() -> String { + return self.runOperationSynchronously{ () -> String in self.makeCurrentContext() return String.fromCString(UnsafePointer(glGetString(GLenum(GL_EXTENSIONS))))! } - }() -} \ No newline at end of file + } + +}