
using Godot;
using Godot.Collections;

namespace Rokojori
{  
  public class RDUniformSet:RenderingObject
  {
    protected int _setIndex = -1;
    public int setIndex => _setIndex;

    public RDUniformSet( RokojoriCompositorEffect effect, int setIndex, Rid rid ):base( effect, rid )
    {
      _setIndex =setIndex;
    }
    
    public static RDUniformSet Image( RokojoriCompositorEffect effect, RDTexture texture, int setIndex )
    { 
      var uniform = new RDUniform();
      uniform.UniformType = RenderingDevice.UniformType.Image;
      uniform.Binding = 0;
      uniform.AddId( texture.rid );

      var rd = effect.rd;
      var rid = UniformSetCacheRD.GetCache( effect.context.shader.rid, (uint) setIndex, new Array<RDUniform>{ uniform } );
      // var rid = rd.UniformSetCreate( new Array<RDUniform>{ uniform }, effect.context.shader.rid, (uint) setIndex );

      return new RDUniformSet( effect, setIndex, rid );
    } 

    public static RDUniformSet Sampler( RokojoriCompositorEffect effect, RDSampler sampler, RDTexture texture, int setIndex )
    { 
      var uniform = new RDUniform();
      uniform.UniformType = RenderingDevice.UniformType.SamplerWithTexture;
      uniform.Binding = 0;
      uniform.AddId( sampler.rid );
      uniform.AddId( texture.rid ) ;

      var rd = effect.rd;
      
      var rid = UniformSetCacheRD.GetCache( effect.context.shader.rid, (uint) setIndex, new Array<RDUniform>{ uniform } );
      // var rid = rd.UniformSetCreate( new Array<RDUniform>{ uniform }, effect.context.shader.rid, (uint) setIndex );

      return new RDUniformSet( effect, setIndex, rid );
    } 
  }
}