
using Godot;
using System.Collections.Generic;

namespace Rokojori
{  
  public class RG_ImageTexture:RGGraphProcessor, RDGraphTextureSlotInput
  {
    RDTexture _texture;

    public RDTexture GetTexture()
    {
      return _texture;
    }

    public RGGraphProcessor GetProcessor()
    {
      return this;
    } 

    List<CompositorEffectGraphTextureSlot> _connectedSlots = new List<CompositorEffectGraphTextureSlot>();

    public void SetConnected( CompositorEffectGraphTextureSlot slot )
    {
      _connectedSlots.Add( slot );
    }

    public void SetDisconnected( CompositorEffectGraphTextureSlot slot )
    {
      _connectedSlots.Remove( slot );
    }

    public RG_ImageTexture( RDGraph graph):base( graph )
    {

    } 

    public void SetImageTexture( RDTexture texture )
    {
      _texture = texture;
    }

    public void SetImageTexture( Texture2D texture2D, bool sRGB = true )
    {
      if ( texture2D == null )
      {
        // RJLog.Log( "Set Texture: no texture" );
        _texture = null;
        return;
      }

      var rdTextureRID = RenderingServer.Singleton.TextureGetRdTexture( texture2D.GetRid(), sRGB );

      // RJLog.Log( "Set Texture:", texture2D.GetRid(), ">>", rdTextureRID );
      SetImageTexture( new RDTexture( graph.context, rdTextureRID ) );
    }

    public override void Process()
    {

    }

    public void ConnectTo( CompositorEffectGraphTextureSlot slot )
    {
      slot.SetInput( this );
    }
    
    public void Disconnect( CompositorEffectGraphTextureSlot slot )
    {
      slot.RemoveInput( this );
    }
  }
}