Skip to content

Commit

Permalink
Framework now builds correctly on Raspberry Pi under Swift 3, althoug…
Browse files Browse the repository at this point in the history
…h the V4L camera is temporarily disabled.
  • Loading branch information
BradLarson committed Sep 14, 2016
1 parent b9e0ef5 commit 37d31e8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion framework/Source/Linux/OpenGLContext-RPi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class OpenGLContext: SerialDispatch {
lazy var extensionString:String = {
return self.runOperationSynchronously{
self.makeCurrentContext()
return String.fromCString(UnsafePointer<CChar>(glGetString(GLenum(GL_EXTENSIONS))))!
return String(cString:unsafeBitCast(glGetString(GLenum(GL_EXTENSIONS)), to:UnsafePointer<CChar>.self))
}
}()
}
8 changes: 4 additions & 4 deletions framework/Source/Linux/RPiRenderWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RPiRenderWindow: ImageConsumer {
let windowWidth:UInt32
let windowHeight:UInt32

public init(width:UInt32, height:UInt32) {
public init(width:UInt32? = nil, height:UInt32? = nil) {
sharedImageProcessingContext.makeCurrentContext()
display = eglGetDisplay(nil /* EGL_DEFAULT_DISPLAY */)
// guard (display != EGL_NO_DISPLAY) else {throw renderingError(errorString:"Could not obtain display")}
Expand All @@ -36,7 +36,7 @@ public class RPiRenderWindow: ImageConsumer {
EGL_NONE
]

var config:EGLConfig = nil
var config:EGLConfig? = nil
var num_config:EGLint = 0
// guard (eglChooseConfig(display, attributes, &config, 1, &num_config) != EGL_FALSE) else {throw renderingError(errorString:"Could not get a framebuffer configuration")}
eglChooseConfig(display, attributes, &config, 1, &num_config)
Expand Down Expand Up @@ -76,7 +76,7 @@ public class RPiRenderWindow: ImageConsumer {
glClear(GLenum(GL_COLOR_BUFFER_BIT))
}

public func newFramebufferAvailable(framebuffer:Framebuffer, fromSourceIndex:UInt) {
public func newFramebufferAvailable(_ framebuffer:Framebuffer, fromSourceIndex:UInt) {
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), 0)
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), 0)

Expand All @@ -85,7 +85,7 @@ public class RPiRenderWindow: ImageConsumer {
glClearColor(0.0, 0.0, 0.0, 0.0)
glClear(GLenum(GL_COLOR_BUFFER_BIT))

renderQuadWithShader(self.displayShader, vertices:verticallyInvertedImageVertices, inputTextures:[framebuffer.texturePropertiesForTargetOrientation(.Portrait)])
renderQuadWithShader(self.displayShader, vertices:verticallyInvertedImageVertices, inputTextures:[framebuffer.texturePropertiesForTargetOrientation(.portrait)])
framebuffer.unlock()
eglSwapBuffers(display, surface)
}
Expand Down
3 changes: 3 additions & 0 deletions framework/Source/Linux/V4LCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#else
import COpenGL
#endif

/*
import CVideo4Linux
import Glibc
import Foundation
Expand Down Expand Up @@ -120,3 +122,4 @@ public class V4LCamera:ImageSource {
// Not needed for camera inputs
}
}
*/
14 changes: 0 additions & 14 deletions framework/Source/OpenGLRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,11 @@ extension String {
}

func withGLChar(_ operation:(UnsafePointer<GLchar>) -> ()) {
#if os(Linux)
// cStringUsingEncoding isn't yet defined in the Linux Foundation.
// This approach is roughly 35X slower than the cStringUsingEncoding one.
let bufferCString = UnsafeMutablePointer<UInt8>.allocate(capacity:self.characters.count+1)
for (index, characterValue) in self.utf8.enumerate() {
bufferCString[index] = characterValue
}
bufferCString[self.characters.count] = 0 // Have to add a null termination

operation(UnsafePointer<GLchar>(bufferCString))

bufferCString.deallocate(capacity:self.characters.count)
#else
if let value = self.cString(using:String.Encoding.utf8) {
operation(UnsafePointer<GLchar>(value))
} else {
fatalError("Could not convert this string to UTF8: \(self)")
}
#endif
}
}

30 changes: 28 additions & 2 deletions framework/Source/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,43 @@ class WeakImageConsumer {
public class TargetContainer:Sequence {
var targets = [WeakImageConsumer]()
var count:Int { get {return targets.count}}
#if !os(Linux)
let dispatchQueue = DispatchQueue(label:"com.sunsetlakesoftware.GPUImage.targetContainerQueue", attributes: [])

#endif

public init() {
}

public func append(_ target:ImageConsumer, indexAtTarget:UInt) {
// TODO: Don't allow the addition of a target more than once
#if os(Linux)
self.targets.append(WeakImageConsumer(value:target, indexAtTarget:indexAtTarget))
#else
dispatchQueue.async{
self.targets.append(WeakImageConsumer(value:target, indexAtTarget:indexAtTarget))
}
#endif
}

public func makeIterator() -> AnyIterator<(ImageConsumer, UInt)> {
var index = 0

return AnyIterator { () -> (ImageConsumer, UInt)? in
#if os(Linux)
if (index >= self.targets.count) {
return nil
}

while (self.targets[index].value == nil) {
self.targets.remove(at:index)
if (index >= self.targets.count) {
return nil
}
}

index += 1
return (self.targets[index - 1].value!, self.targets[index - 1].indexAtTarget)
#else
return self.dispatchQueue.sync{
if (index >= self.targets.count) {
return nil
Expand All @@ -123,14 +144,19 @@ public class TargetContainer:Sequence {

index += 1
return (self.targets[index - 1].value!, self.targets[index - 1].indexAtTarget)
}
}
#endif
}
}

public func removeAll() {
#if os(Linux)
self.targets.removeAll()
#else
dispatchQueue.async{
self.targets.removeAll()
}
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion framework/Source/ShaderProgram.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,5 @@ public func shaderFromFile(_ file:URL) throws -> String {

let fragmentShaderString = try NSString(contentsOfFile:file.path, encoding:String.Encoding.ascii.rawValue)

return String(fragmentShaderString)
return String(describing:fragmentShaderString)
}

0 comments on commit 37d31e8

Please sign in to comment.