Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions framework/Source/iOS/OpenGLContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}()
Expand All @@ -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<Void>
Expand All @@ -34,44 +34,44 @@ public class OpenGLContext: SerialDispatch {
let context = UnsafeMutablePointer<Void>(Unmanaged<dispatch_queue_t>.passUnretained(self.serialDispatchQueue).toOpaque())
dispatchQueueKey = UnsafePointer<Void>(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
#else
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)
Expand All @@ -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<CChar>(glGetString(GLenum(GL_EXTENSIONS))))!
}
}()
}
}

}