GPUImage2 unable to cycle through filters real-time

428 Views Asked by At

I have the following block of code that utilizes the GPUImage2 library to filter video in real time. The idea is to be able to cycle these filters based on button clicks. But only one filter will be applied and whenever I try and cycle to the next filter it does not change. Here is my function:

func filterToggle() {
    switch(filterSelected) {
    case 0:
        let sketch = SketchFilter()
        camera! --> sketch --> renderView
        break;
    case 1:
        let toon = ToonFilter()
        camera! --> toon --> renderView
        break;
    default:
        break;
    }
    camera?.startCapture()
}

Thank you for any help!

1

There are 1 best solutions below

0
On

You have to disconnect the previous filters from the renderView and the camera before switching to another.

Before adding new filters to the chain, call removeAllTargets() on the camera and the previous filter (you may want to have an instance variable that stores the previous filter in order to do this). The Mac version of FilterShowcase demonstrates this in action.