diff --git a/framework/GPUImageMac.xcodeproj/project.pbxproj b/framework/GPUImageMac.xcodeproj/project.pbxproj index 426d80aa8..3a6362ef9 100644 --- a/framework/GPUImageMac.xcodeproj/project.pbxproj +++ b/framework/GPUImageMac.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + A87E5E12177648F3007FD5B1 /* GPUImageRawDataOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A87E5E13177648F3007FD5B1 /* GPUImageRawDataOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = A87E5E11177648F3007FD5B1 /* GPUImageRawDataOutput.m */; }; + A87E5E1617764B16007FD5B1 /* GPUImageRawDataInput.h in Headers */ = {isa = PBXBuildFile; fileRef = A87E5E1417764B16007FD5B1 /* GPUImageRawDataInput.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A87E5E1717764B16007FD5B1 /* GPUImageRawDataInput.m in Sources */ = {isa = PBXBuildFile; fileRef = A87E5E1517764B16007FD5B1 /* GPUImageRawDataInput.m */; }; BC56957A174683620081491B /* GPUImageCrosshairGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = BC569576174683620081491B /* GPUImageCrosshairGenerator.h */; settings = {ATTRIBUTES = (Public, ); }; }; BC56957B174683620081491B /* GPUImageCrosshairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = BC569577174683620081491B /* GPUImageCrosshairGenerator.m */; }; BC56957C174683620081491B /* GPUImageLineGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = BC569578174683620081491B /* GPUImageLineGenerator.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -312,6 +316,10 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageRawDataOutput.h; path = Source/GPUImageRawDataOutput.h; sourceTree = SOURCE_ROOT; }; + A87E5E11177648F3007FD5B1 /* GPUImageRawDataOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageRawDataOutput.m; path = Source/GPUImageRawDataOutput.m; sourceTree = SOURCE_ROOT; }; + A87E5E1417764B16007FD5B1 /* GPUImageRawDataInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageRawDataInput.h; path = Source/GPUImageRawDataInput.h; sourceTree = SOURCE_ROOT; }; + A87E5E1517764B16007FD5B1 /* GPUImageRawDataInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageRawDataInput.m; path = Source/GPUImageRawDataInput.m; sourceTree = SOURCE_ROOT; }; BC569576174683620081491B /* GPUImageCrosshairGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageCrosshairGenerator.h; path = Source/GPUImageCrosshairGenerator.h; sourceTree = SOURCE_ROOT; }; BC569577174683620081491B /* GPUImageCrosshairGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageCrosshairGenerator.m; path = Source/GPUImageCrosshairGenerator.m; sourceTree = SOURCE_ROOT; }; BC569578174683620081491B /* GPUImageLineGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLineGenerator.h; path = Source/GPUImageLineGenerator.h; sourceTree = SOURCE_ROOT; }; @@ -706,6 +714,8 @@ BCF40F1817248286005AE36A /* Sources */ = { isa = PBXGroup; children = ( + A87E5E1417764B16007FD5B1 /* GPUImageRawDataInput.h */, + A87E5E1517764B16007FD5B1 /* GPUImageRawDataInput.m */, BCF40F191724829B005AE36A /* GPUImageOutput.h */, BCF40F1A1724829B005AE36A /* GPUImageOutput.m */, BCF8679B1727585D00912E34 /* GPUImageAVCamera.h */, @@ -746,6 +756,8 @@ BCF40F2217248811005AE36A /* Outputs */ = { isa = PBXGroup; children = ( + A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */, + A87E5E11177648F3007FD5B1 /* GPUImageRawDataOutput.m */, BCF40F2317248836005AE36A /* GPUImageView.h */, BCF40F2417248836005AE36A /* GPUImageView.m */, BCF867521725AF9300912E34 /* GPUImageMovieWriter.h */, @@ -1056,6 +1068,8 @@ buildActionMask = 2147483647; files = ( BCA3F3651723A96600E28AEC /* GPUImage.h in Headers */, + A87E5E1617764B16007FD5B1 /* GPUImageRawDataInput.h in Headers */, + A87E5E12177648F3007FD5B1 /* GPUImageRawDataOutput.h in Headers */, BCF40F1217247D68005AE36A /* GPUImageContext.h in Headers */, BCF40F1617247FD8005AE36A /* GLProgram.h in Headers */, BCF40F1B1724829B005AE36A /* GPUImageOutput.h in Headers */, @@ -1417,6 +1431,8 @@ BCA20BC817471C4B0097C84A /* GPUImagePerlinNoiseFilter.m in Sources */, BCA20BCA17471C4B0097C84A /* GPUImageVoronoiConsumerFilter.m in Sources */, BC96A4F2176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m in Sources */, + A87E5E13177648F3007FD5B1 /* GPUImageRawDataOutput.m in Sources */, + A87E5E1717764B16007FD5B1 /* GPUImageRawDataInput.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/framework/Source/GPUImageRawDataOutput.h b/framework/Source/GPUImageRawDataOutput.h index 5fd0e436e..b1dcc8ba3 100755 --- a/framework/Source/GPUImageRawDataOutput.h +++ b/framework/Source/GPUImageRawDataOutput.h @@ -11,6 +11,7 @@ typedef struct GPUByteColorVector GPUByteColorVector; @protocol GPUImageRawDataProcessor; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE @interface GPUImageRawDataOutput : NSObject { CGSize imageSize; CVOpenGLESTextureCacheRef rawDataTextureCache; @@ -21,6 +22,18 @@ typedef struct GPUByteColorVector GPUByteColorVector; __unsafe_unretained id textureDelegate; } +#else +@interface GPUImageRawDataOutput : NSObject { + CGSize imageSize; + CVOpenGLTextureCacheRef rawDataTextureCache; + CVPixelBufferRef renderTarget; + GPUImageRotationMode inputRotation; + BOOL outputBGRA; + CVOpenGLTextureRef renderTexture; + + __unsafe_unretained id textureDelegate; +} +#endif @property(readonly) GLubyte *rawBytesForImage; @property(nonatomic, copy) void(^newFrameAvailableBlock)(void); diff --git a/framework/Source/GPUImageRawDataOutput.m b/framework/Source/GPUImageRawDataOutput.m index 51373acb8..4d5564a33 100755 --- a/framework/Source/GPUImageRawDataOutput.m +++ b/framework/Source/GPUImageRawDataOutput.m @@ -116,14 +116,25 @@ - (void)createDataFBO; if ([GPUImageContext supportsFastTextureUpload]) { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE #if defined(__IPHONE_6_0) CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, [[GPUImageContext sharedImageProcessingContext] context], NULL, &rawDataTextureCache); #else CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)[[GPUImageContext sharedImageProcessingContext] context], NULL, &rawDataTextureCache); #endif - if (err) +#else + CGLContextObj context = (__bridge void *)[[GPUImageContext sharedImageProcessingContext] context]; + CVReturn err = CVOpenGLTextureCacheCreate(kCFAllocatorDefault, + NULL, + context, + CGLGetPixelFormat(context), + NULL, + &rawDataTextureCache); +#endif + + if (err) { - NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate %d", err); + NSAssert(NO, @"Error at CVOpenGL(ES)TextureCacheCreate %d", err); } // Code originally sourced from http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/ @@ -154,6 +165,7 @@ - (void)createDataFBO; attrs, &renderTarget); +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault, rawDataTextureCache, renderTarget, NULL, // texture attributes @@ -165,13 +177,30 @@ - (void)createDataFBO; GL_UNSIGNED_BYTE, 0, &renderTexture); +#else + CVOpenGLTextureCacheCreateTextureFromImage (kCFAllocatorDefault, + rawDataTextureCache, renderTarget, + NULL, + &renderTexture); +#endif + CFRelease(attrs); CFRelease(empty); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE glBindTexture(CVOpenGLESTextureGetTarget(renderTexture), CVOpenGLESTextureGetName(renderTexture)); +#else + glBindTexture(CVOpenGLTextureGetTarget(renderTexture), CVOpenGLTextureGetName(renderTexture)); +#endif + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0); +#else + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLTextureGetName(renderTexture), 0); +#endif } else { @@ -179,8 +208,13 @@ - (void)createDataFBO; glGenRenderbuffers(1, &dataRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, dataRenderbuffer); +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, (int)imageSize.width, (int)imageSize.height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, dataRenderbuffer); +#else + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, (int)imageSize.width, (int)imageSize.height); +#endif + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, dataRenderbuffer); } GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); diff --git a/framework/Source/Mac/GPUImage.h b/framework/Source/Mac/GPUImage.h index 3da667ccd..dcd836806 100755 --- a/framework/Source/Mac/GPUImage.h +++ b/framework/Source/Mac/GPUImage.h @@ -8,6 +8,8 @@ #import #import #import +#import +#import // Filters #import diff --git a/framework/Source/Mac/GPUImageMovieWriter.m b/framework/Source/Mac/GPUImageMovieWriter.m index 889fcda2f..e27e32e21 100755 --- a/framework/Source/Mac/GPUImageMovieWriter.m +++ b/framework/Source/Mac/GPUImageMovieWriter.m @@ -4,6 +4,7 @@ #import "GLProgram.h" #import "GPUImageFilter.h" +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE NSString *const kGPUImageColorSwizzlingFragmentShaderString = SHADER_STRING ( varying highp vec2 textureCoordinate; @@ -14,7 +15,20 @@ void main() { gl_FragColor = texture2D(inputImageTexture, textureCoordinate).bgra; } -); + ); +#else +NSString *const kGPUImageColorSwizzlingFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate).bgra; + } + ); +#endif @interface GPUImageMovieWriter ()