rokojori_action_library/Runtime/Rendering/RenderGraph/RDGraphTextureSlot.cs

147 lines
3.9 KiB
C#
Raw Normal View History

2025-04-24 13:39:00 +00:00
using Godot;
using System.Collections.Generic;
namespace Rokojori
{
2025-04-26 20:04:11 +00:00
public interface RDGraphTextureSlotInput
2025-04-24 13:39:00 +00:00
{
public RDTexture GetTexture();
2025-04-26 20:04:11 +00:00
public RGGraphProcessor GetProcessor();
2025-04-24 13:39:00 +00:00
public void SetConnected( CompositorEffectGraphTextureSlot slot );
public void ConnectTo( CompositorEffectGraphTextureSlot slot );
2026-01-15 14:00:42 +00:00
public void SetDisconnected( CompositorEffectGraphTextureSlot slot );
public void Disconnect( CompositorEffectGraphTextureSlot slot );
2025-04-24 13:39:00 +00:00
}
2025-04-26 20:04:11 +00:00
public class CompositorEffectGraphTextureSlot:RDGraphConnection, RDGraphTextureSlotInput
2025-04-24 13:39:00 +00:00
{
2025-04-26 20:04:11 +00:00
protected RDGraphTextureSlotInput _input;
public RDGraphTextureSlotInput input => _input;
2025-04-24 13:39:00 +00:00
public RDSampler sampler;
2025-04-30 20:18:22 +00:00
protected RDTexture _texture;
2025-04-24 13:39:00 +00:00
2026-01-10 18:35:50 +00:00
public void UseSampler( RenderingDevice.SamplerFilter filter = RenderingDevice.SamplerFilter.Linear, RenderingDevice.SamplerRepeatMode repeatMode = RenderingDevice.SamplerRepeatMode.Repeat )
{
sampler = graph.context.Sampler( filter, repeatMode );
}
2026-01-15 14:00:42 +00:00
public void UseLinearSampler( RenderingDevice.SamplerRepeatMode repeatMode = RenderingDevice.SamplerRepeatMode.Repeat )
{
sampler = graph.context.Sampler( RenderingDevice.SamplerFilter.Linear, repeatMode );
}
public void UseLinearSamplerEdgeClamped()
{
UseLinearSampler( RenderingDevice.SamplerRepeatMode.ClampToEdge );
}
public void UseLinearSamplerMirroredRepeat()
{
UseLinearSampler( RenderingDevice.SamplerRepeatMode.MirroredRepeat );
}
public void UseNearestSampler( RenderingDevice.SamplerRepeatMode repeatMode = RenderingDevice.SamplerRepeatMode.Repeat )
{
sampler = graph.context.Sampler( RenderingDevice.SamplerFilter.Nearest, repeatMode );
}
public void UseNearestSamplerEdgeClamped()
{
UseNearestSampler( RenderingDevice.SamplerRepeatMode.ClampToEdge );
}
public void UseNearestSamplerMirroredRepeat()
{
UseNearestSampler( RenderingDevice.SamplerRepeatMode.MirroredRepeat );
}
public void UseSamplerNoRepeat( RenderingDevice.SamplerFilter filter = RenderingDevice.SamplerFilter.Linear )
{
sampler = graph.context.Sampler( filter, RenderingDevice.SamplerRepeatMode.ClampToEdge );
}
2025-04-24 13:39:00 +00:00
public RDTexture GetTexture()
{
return _texture;
}
public RDTexture ResolveTexture()
{
return _texture = _input.GetTexture();
}
2025-04-26 20:04:11 +00:00
public RGGraphProcessor GetProcessor()
2025-04-24 13:39:00 +00:00
{
return _processor;
}
List<CompositorEffectGraphTextureSlot> _connectedSlots = new List<CompositorEffectGraphTextureSlot>();
public void SetConnected( CompositorEffectGraphTextureSlot slot )
{
_connectedSlots.Add( slot );
}
2026-01-15 14:00:42 +00:00
public void SetDisconnected( CompositorEffectGraphTextureSlot slot )
{
_connectedSlots.Remove( slot );
}
2025-04-26 20:04:11 +00:00
public CompositorEffectGraphTextureSlot( RGGraphProcessor processor ):base( processor )
2025-04-24 13:39:00 +00:00
{
}
2025-04-26 20:04:11 +00:00
public void SetInput( RDGraphTextureSlotInput input )
2025-04-24 13:39:00 +00:00
{
2026-01-15 14:00:42 +00:00
if ( input == _input )
{
return;
}
2025-04-24 13:39:00 +00:00
_input = input;
input.SetConnected( this );
}
2026-01-15 14:00:42 +00:00
public void ReplaceInput( RDGraphTextureSlotInput oldInput, RDGraphTextureSlotInput newInput )
{
RemoveInput( oldInput );
SetInput( newInput );
}
public void RemoveInput( RDGraphTextureSlotInput input )
{
if ( input != _input )
{
return;
}
_input.SetDisconnected( this );
_input = null;
}
2025-04-24 13:39:00 +00:00
public void ConnectTo( CompositorEffectGraphTextureSlot slot )
{
slot.SetInput( this );
}
2026-01-15 14:00:42 +00:00
public void Disconnect( CompositorEffectGraphTextureSlot slot )
{
slot.RemoveInput( this );
}
2025-04-24 13:39:00 +00:00
}
2025-04-30 20:18:22 +00:00
public class RG_TextureSlotEditable:CompositorEffectGraphTextureSlot
{
public RG_TextureSlotEditable( RGGraphProcessor processor ):base( processor ){}
public void SetTexture( RDTexture texture )
{
_texture = texture;
}
}
2025-04-24 13:39:00 +00:00
}