
using Godot;
using Godot.Collections;
using System.Collections.Generic;

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class CrossChannelCurvesEffect:ColorEffect
  {
    public CrossChannelCurvesEffect():base()
    {
      Initialize();
    } 

    public enum CrossChannelDriver
    {
      Red,
      Green,
      Blue,
      Hue,
      Saturation,
      Lightness
    }

    public enum CrossChannelTarget
    {
      Red,
      Green,
      Blue,
      Hue,
      Saturation,
      Lightness,
      Temparature
    }

    [Export( PropertyHint.Range, "0,1") ]
    public float amount = 0.5f;
    
    [Export]
    public CrossChannelDriver driver = CrossChannelDriver.Lightness;

    [Export]
    public CrossChannelTarget target = CrossChannelTarget.Saturation;

    [Export]
    public CurveTexture curve = new CurveTexture();

    RG_ScreenColorTexure screenColorTexture;
    RG_ImageTexture _curvesTexture;
    RG_CrossChannelCurves _curves;    

    void Initialize()
    { 
      screenColorTexture = new RG_ScreenColorTexure( graph );
      _curvesTexture = new RG_ImageTexture( graph );
      _curves = new RG_CrossChannelCurves( graph );


      graph.InitializeNodes();      

      
      _curves.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); 
      _curves.SetCurvesTextureSlotInputs( _curvesTexture );

      _curvesTexture.SetImageTexture( curve );

      _curves.curves.sampler = context.Sampler( RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode.ClampToEdge );

      graph.SetProcessOrder( 
        screenColorTexture, 
        _curves 
      );
    }
   

    protected override void ForAllViews()
    {
      _curvesTexture.SetImageTexture( curve );

      _curves.constants.Set(        
        amount,
        (float)(int)driver,
        (float)(int)target,
        0f,
        0f,
        0f,
        0f,
        0f
      );
    }

   
  }
}