Permalink
Browse files

Fixed pixellation and other filters by making sure they get uniforms …

…and aspect ratios set properly before running the first filter operation.
  • Loading branch information...
1 parent f51b807 commit 99ef54a351f2f51693cb57a95a315403bc287178 @BradLarson committed Oct 3, 2012
@@ -603,31 +603,31 @@ - (void)setFloatArray:(GLfloat *)array length:(GLsizei)count forUniform:(NSStrin
- (void)setMatrix3f:(GPUMatrix3x3)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniformMatrix3fv(uniform, 1, GL_FALSE, (GLfloat *)&matrix);
});
}
- (void)setMatrix4f:(GPUMatrix4x4)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniformMatrix4fv(uniform, 1, GL_FALSE, (GLfloat *)&matrix);
});
}
- (void)setFloat:(GLfloat)floatValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniform1f(uniform, floatValue);
});
}
- (void)setPoint:(CGPoint)pointValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
GLfloat positionArray[2];
@@ -640,7 +640,7 @@ - (void)setPoint:(CGPoint)pointValue forUniform:(GLint)uniform program:(GLProgra
- (void)setSize:(CGSize)sizeValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
GLfloat sizeArray[2];
@@ -653,7 +653,7 @@ - (void)setSize:(CGSize)sizeValue forUniform:(GLint)uniform program:(GLProgram *
- (void)setVec3:(GPUVector3)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniform3fv(uniform, 1, (GLfloat *)&vectorValue);
@@ -662,7 +662,7 @@ - (void)setVec3:(GPUVector3)vectorValue forUniform:(GLint)uniform program:(GLPro
- (void)setVec4:(GPUVector4)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniform4fv(uniform, 1, (GLfloat *)&vectorValue);
@@ -671,7 +671,7 @@ - (void)setVec4:(GPUVector4)vectorValue forUniform:(GLint)uniform program:(GLPro
- (void)setFloatArray:(GLfloat *)arrayValue length:(GLsizei)arrayLength forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniform1fv(uniform, arrayLength, arrayValue);
@@ -680,7 +680,7 @@ - (void)setFloatArray:(GLfloat *)arrayValue length:(GLsizei)arrayLength forUnifo
- (void)setInteger:(GLint)intValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
{
- dispatch_async([GPUImageOpenGLESContext sharedOpenGLESQueue], ^{
+ runAsynchronouslyOnVideoProcessingQueue(^{
[GPUImageOpenGLESContext setActiveShaderProgram:shaderProgram];
glUniform1i(uniform, intValue);
});
@@ -4,6 +4,7 @@
void runOnMainQueueWithoutDeadlocking(void (^block)(void));
void runSynchronouslyOnVideoProcessingQueue(void (^block)(void));
+void runAsynchronouslyOnVideoProcessingQueue(void (^block)(void));
void reportAvailableMemoryForGPUImage(NSString *tag);
@class GPUImageMovieWriter;
@@ -29,6 +29,20 @@ void runSynchronouslyOnVideoProcessingQueue(void (^block)(void))
}
}
+void runAsynchronouslyOnVideoProcessingQueue(void (^block)(void))
+{
+ dispatch_queue_t videoProcessingQueue = [GPUImageOpenGLESContext sharedOpenGLESQueue];
+
+ if (dispatch_get_current_queue() == videoProcessingQueue)
@mabene

mabene Oct 8, 2012

How do you plan to do this once dispatch_get_current_queue (currently deprecated) is removed?

@BradLarson

BradLarson Oct 9, 2012

Owner

Hadn't even noticed that dispatch_get_current_queue() was deprecated with iOS 6.0. Oddly, it's only deprecated starting with that, and is not marked as deprecated in Mountain Lion. Thanks for pointing that out. I'm examining alternatives, and my main thread synchronous dispatch function uses a different identity check, so it won't be affected.

+ {
+ block();
+ }
+ else
+ {
+ dispatch_async(videoProcessingQueue, block);
+ }
+}
+
void reportAvailableMemoryForGPUImage(NSString *tag)
{
if (!tag)
@@ -63,9 +63,15 @@ - (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex;
[super setInputSize:newSize atIndex:textureIndex];
if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!CGSizeEqualToSize(newSize, CGSizeZero)) )
-
{
- [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)];
+ if (GPUImageRotationSwapsWidthAndHeight(inputRotation))
+ {
+ [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)];
+ }
+ else
+ {
+ [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)];
+ }
}
}
@@ -83,7 +83,14 @@ - (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex;
if (!CGSizeEqualToSize(oldInputSize, inputTextureSize) && (!CGSizeEqualToSize(newSize, CGSizeZero)) )
{
- [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)];
+ if (GPUImageRotationSwapsWidthAndHeight(inputRotation))
+ {
+ [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)];
+ }
+ else
+ {
+ [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)];
+ }
}
}
@@ -96,7 +96,11 @@ - (void)capturePhotoAsSampleBufferWithCompletionHandler:(void (^)(CMSampleBuffer
[photoOutput captureStillImageAsynchronouslyFromConnection:[[photoOutput connections] objectAtIndex:0] completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
block(imageSampleBuffer, error);
- }];*/
+ }];
+
+ dispatch_semaphore_signal(frameRenderingSemaphore);
+
+ */
return;
}

0 comments on commit 99ef54a

Please sign in to comment.