OK, let’s try this with some code. The following works in OF 0.9.8 on OSX 10.9, but does not work on any later Max OS’s, though no errors show up in the traps I have here.
When it works correctly, we get a lovely gauss blur extending out around the circle.
Forcing OpenGL 2.0 as per the above does not fix the situation.
Revelant items in header
// GL
GLint width;
GLint height;
ofFbo sourceFbo;
// Core Image
CGLContextObj CGLContext;
NSOpenGLPixelFormatAttribute* attr;
NSOpenGLPixelFormat* pf;
CGColorSpaceRef genericRGB;
CIContext* glCIcontext;
CIImage* inputCIImage;
CIFilter* clampFilter;
CIFilter* blurFilter;
CIFilter* colorShiftFilter;
CGSize texSize;
GLint tex;
CGRect outRect;
CGRect inRect;
Setup
// just in case -- haven't confirmed this is necessary
ofDisableArbTex();
width = ofGetViewportWidth();
height = ofGetViewportHeight();
ofBackground(0);
ofClear(0);
glEnable(GL_POINT_SMOOTH);
sourceFbo.allocate(width, height, GL_RGBA32F_ARB); //32-bit framebuffer for smoothness
sourceFbo.begin();
ofClear(0,0,0);
sourceFbo.end();
// Groundwork for Core Image
genericRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
NSOpenGLPixelFormatAttribute attr[] = {
NSOpenGLPFAAccelerated,
NSOpenGLPFANoRecovery,
NSOpenGLPFAColorSize, 32,
0
};
pf=[[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
if (!pf) {
NSLog(@"ofBDW could not create NS Open GL Pixel Format");
}
glCIcontext = [CIContext contextWithCGLContext: CGLGetCurrentContext()
pixelFormat: CGLPixelFormatObj(pf)
colorSpace: genericRGB
options: nil];
if (!glCIcontext)
{
NSLog(@"ofBDW could not create the CI context");
}
texSize = CGSizeMake(width,height);
clampFilter = [CIFilter filterWithName:@"CIAffineClamp"] ; // for ensuring blur goes fully to edge
blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"] ;
colorShiftFilter = [CIFilter filterWithName:@"CIColorControls"] ;
if (!blurFilter) {
NSLog(@"ofBDW could not create CI Blur Filter");
}
if (!clampFilter) {
NSLog(@"ofBDW could not create CI Clamp Filter");
}
if (!colorShiftFilter) {
NSLog(@"ofBDW could not create CI Color Shift Filter");
}
inRect = CGRectMake(0,0,width,height);
outRect = CGRectMake(0,0,width,height);
Update
sourceFbo.begin();
ofColor(255,255,255);
ofDrawCircle(width/2.0, height/2.0, 40);
// do we have to re-initialise the inputCIImage each time? I am assuming yes...
GLint tex = sourceFbo.getTexture().texData.textureID;
CGSize texSize = CGSizeMake(width, height);
//NSLog(@"FBO Texture ID = %d", tex);
inputCIImage = [CIImage imageWithTexture:tex
size:texSize
flipped:NO
colorSpace:genericRGB];
if (!inputCIImage)
{
NSLog(@"ofBDW could not create CIImage from texture");
}
// Draw something
ofColor(255,255,255);
ofDrawCircle(width/2.0, height/2.0, 40);
// Filter it
float blurRadius = 20.0;
float saturation = 1.0;
float brightness = 1.0;
float contrast = 1.0;
CGAffineTransform xform = CGAffineTransformIdentity;
[clampFilter setValue:[NSValue valueWithBytes:&xform objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"];
[clampFilter setValue:inputCIImage forKey:kCIInputImageKey];
// blur filter
[blurFilter setValue:clampFilter.outputImage forKey:kCIInputImageKey];
[blurFilter setValue:[NSNumber numberWithFloat: blurRadius] forKey:@"inputRadius"];
// color shift filter
[colorShiftFilter setValue:[NSNumber numberWithFloat: saturation] forKey:@"inputSaturation"];
[colorShiftFilter setValue:[NSNumber numberWithFloat: brightness] forKey:@"inputBrightness"];
[colorShiftFilter setValue:[NSNumber numberWithFloat: contrast] forKey:@"inputContrast"];
[colorShiftFilter setValue:inputCIImage forKey:kCIInputImageKey];
ofSetColor(255,255,255,255);
[glCIcontext drawImage:blurFilter.outputImage
inRect:outRect
fromRect:inRect]; // this also serves to crop the affine clamped blur image
// alpha blend the color shifted copy onto the blurred copy
ofSetColor(255,255,255,127); //127
sourceFbo.end();
Draw
ofSetColor(255,255,255,255);
sourceFbo.draw(0,0);