//
//  PQGPUImageFilterGroup.swift
//  PQSpeed
//
//  Created by ak on 2021/5/16.
//  Copyright © 2021 BytesFlow. All rights reserved.
//

import Foundation
import BFCommonKit

open class PQGPUImageFilterGroup: PQBaseFilter{
    
    var mStickers:[PQEditVisionTrackMaterialsModel] = Array.init()
    init(stickers: [PQEditVisionTrackMaterialsModel]) {
        super.init(fragmentShader: PassthroughFragmentShader, numberOfInputs: 1)
        mStickers = stickers
    }
    
    func findShowStikcer(currTime:Float64) -> PQBaseFilter {
         
        var currentSticker:PQEditVisionTrackMaterialsModel?
        for sticker in mStickers {
            if(sticker.timelineIn >= currTime && sticker.timelineOut <= currTime){
                currentSticker = sticker
            }
        }
        //创建不同的filter
        if(currentSticker == nil){
            BFLog(message: "sticker data is error")
            return  PQBaseFilter.init(fragmentShader: PassthroughFragmentShader, numberOfInputs: 1)
        }
        
        var showFitler:PQBaseFilter?
        if currentSticker!.type == StickerType.VIDEO.rawValue {
            showFitler = PQMovieFilter(movieSticker: currentSticker!)
 

        } else if currentSticker!.type == StickerType.IMAGE.rawValue {
            showFitler = PQImageFilter(sticker: currentSticker!)
            
        }
        return showFitler ?? PQBaseFilter.init(fragmentShader: PassthroughFragmentShader, numberOfInputs: 1)
    }
    
    
    override public func newFramebufferAvailable(_ framebuffer: Framebuffer, fromSourceIndex: UInt) {
        super.newFramebufferAvailable(framebuffer, fromSourceIndex: fromSourceIndex)

//        let currTime = CMTimeGetSeconds(CMTime(value: framebuffer.timingStyle.timestamp!.value, timescale: framebuffer.timingStyle.timestamp!.timescale))
        
//        var showFilter = findShowStikcer(currTime: currTime)
//        if(showFilter){
//
//            self.targets.append(showFilter)
//
//        }
  
        
        
    }

    override open func renderFrame() {
        
    }
    
}
