3
votes

I have an NSView. It has a layer. Inside of the layer, there are several sublayers. One of those sublayers needs to blend with the layers beneath it. I've set the top layer's compositingFilter property, but no blending happens. :-(

Here's a visual representation:

Root Layer      <-- myView.layer
|- Bottom Layer <-- myView.layer.sublayers[0]
|- Middle Layer <-- myView.layer.sublayers[1]
|- Top Layer    <-- myView.layer.sublayers[2]

Root Layer
|- Bottom Layer
|- Middle Layer
|- Top Layer    <-- Added filter to this layer.

I set the property like so:

self.topLayer.compositingFilter = [CIFilter filterWithName:@"CIMultiplyBlendMode"];

I assumed that the input image and background image would be supplied automatically with the contents of each of the layers, but maybe I'm wrong. Am I?

TL;DR: How does a n00b composite a stack of layers together using blending modes?

P.S. I'm drawing the contents of each layer using the delegate method, -drawLayer:inContext:.

1
You're not wrong. input image is set automatically. shouldn't When do you set the filter? Do you call setNeedsDisplay after that? Did you try setting an image as contents? What I found helping is to send setDefaults to the filter before adding it to the layer.mahal tertin

1 Answers

1
votes

There is a flag you have to enable on NSView for it use filters on the layer:

[self.view setWantsLayer:YES];
[self.view setLayerUsesCoreImageFilters:YES];

I think this is specific to OS X and NSView and isn't necessary with UIView on iOS. Everything else looks correct to me.