2025-04-23 12:00:43 +00:00
|
|
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
public class RDTexture: RenderingObject
|
|
|
|
{
|
2025-04-26 20:04:11 +00:00
|
|
|
public RDTexture( RDContext context, Rid rid ):base( context, rid ){}
|
2025-04-23 12:00:43 +00:00
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture Create( RDContext effect, RDTextureFormat format, RDTextureView view )
|
2025-04-23 12:00:43 +00:00
|
|
|
{
|
2025-04-26 20:04:11 +00:00
|
|
|
return new RDTexture( effect, effect.renderingDevice.TextureCreate( format, view ) );
|
2025-04-23 12:00:43 +00:00
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture Color( RDContext context )
|
2025-04-23 12:00:43 +00:00
|
|
|
{
|
|
|
|
var rid = context.sceneBuffers.GetColorLayer( (uint) context.view );
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
return new RDTexture( context, rid );
|
2025-04-23 12:00:43 +00:00
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture Depth( RDContext context )
|
2025-04-23 12:00:43 +00:00
|
|
|
{
|
|
|
|
var rid = context.sceneBuffers.GetDepthLayer( (uint) context.view );
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
return new RDTexture( context, rid );
|
2025-04-23 12:00:43 +00:00
|
|
|
}
|
2025-04-24 13:39:00 +00:00
|
|
|
|
|
|
|
public RDTextureFormat format
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2025-04-26 20:04:11 +00:00
|
|
|
return context.renderingDevice.TextureGetFormat( rid );
|
2025-04-24 13:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Vector2I size
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var textureFormat = format;
|
|
|
|
return new Vector2I( (int) textureFormat.Width, (int) textureFormat.Height );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture EnsureScreenSizeTexture( RDTexture texture, RDContext context, bool cleanUp = true )
|
2025-04-25 08:13:22 +00:00
|
|
|
{
|
2025-04-26 20:04:11 +00:00
|
|
|
var size = context.internalSize;
|
2025-04-25 08:13:22 +00:00
|
|
|
|
|
|
|
if ( texture == null || texture.size != size )
|
|
|
|
{
|
|
|
|
if ( cleanUp && texture != null )
|
|
|
|
{
|
2025-04-26 20:04:11 +00:00
|
|
|
context.Free( texture, "Old Screen Size Texture" );
|
2025-04-25 08:13:22 +00:00
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
texture = Create( context, size );
|
2025-04-25 08:13:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture Create( RDContext context, RDTextureFormat format )
|
2025-04-24 13:39:00 +00:00
|
|
|
{
|
|
|
|
var view = new RDTextureView();
|
2025-04-26 20:04:11 +00:00
|
|
|
var rid = context.renderingDevice.TextureCreate( format, view );
|
|
|
|
return new RDTexture( context, rid );
|
2025-04-24 13:39:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static RDTextureFormat DefaultFormat( int w, int h, RenderingDevice.DataFormat dataFormat = RenderingDevice.DataFormat.R16G16B16A16Unorm )
|
|
|
|
{
|
|
|
|
var format = new RDTextureFormat();
|
|
|
|
|
|
|
|
format.Width = (uint) w;
|
|
|
|
format.Height = (uint) h;
|
|
|
|
format.Format = dataFormat;
|
2025-04-25 08:13:22 +00:00
|
|
|
format.UsageBits = RenderingDevice.TextureUsageBits.StorageBit |
|
|
|
|
RenderingDevice.TextureUsageBits.SamplingBit |
|
|
|
|
RenderingDevice.TextureUsageBits.CanCopyFromBit |
|
|
|
|
RenderingDevice.TextureUsageBits.CpuReadBit
|
|
|
|
;
|
2025-04-24 13:39:00 +00:00
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static RDTextureFormat FormatChangeSize( RDTextureFormat tf, Vector2I size )
|
|
|
|
{
|
|
|
|
return FormatChangeSize( tf, size.X, size.Y );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static RDTextureFormat FormatChangeSize( RDTextureFormat tf, int w, int h )
|
|
|
|
{
|
|
|
|
var clone = FormatCopy( tf );
|
|
|
|
clone.Width = (uint) w;
|
|
|
|
clone.Height = (uint) h;
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static RDTextureFormat FormatCopy( RDTextureFormat tf )
|
|
|
|
{
|
|
|
|
var format = new RDTextureFormat();
|
|
|
|
|
|
|
|
format.Format = tf.Format;
|
|
|
|
|
|
|
|
format.Width = tf.Width;
|
|
|
|
format.Height = tf.Height;
|
|
|
|
format.Depth = tf.Depth;
|
|
|
|
|
|
|
|
format.ArrayLayers = tf.ArrayLayers;
|
|
|
|
format.Mipmaps = tf.Mipmaps;
|
|
|
|
format.TextureType = tf.TextureType;
|
|
|
|
format.Samples = tf.Samples;
|
|
|
|
format.UsageBits = tf.UsageBits;
|
|
|
|
format.IsResolveBuffer = tf.IsResolveBuffer;
|
|
|
|
format.IsDiscardable = tf.IsDiscardable;
|
|
|
|
|
|
|
|
return tf;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture Create( RDContext context, Vector2I size, RenderingDevice.DataFormat dataFormat = RenderingDevice.DataFormat.R16G16B16A16Unorm )
|
2025-04-24 13:39:00 +00:00
|
|
|
{
|
2025-04-26 20:04:11 +00:00
|
|
|
return Create( context, size.X, size.Y, dataFormat );
|
2025-04-24 13:39:00 +00:00
|
|
|
}
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
public static RDTexture Create( RDContext context, int width, int height,
|
2025-04-24 13:39:00 +00:00
|
|
|
RenderingDevice.DataFormat dataFormat = RenderingDevice.DataFormat.R16G16B16A16Unorm )
|
|
|
|
{
|
|
|
|
var view = new RDTextureView();
|
|
|
|
var format = DefaultFormat( width, height, dataFormat );
|
|
|
|
|
2025-04-26 20:04:11 +00:00
|
|
|
var rid = context.renderingDevice.TextureCreate( format, view );
|
|
|
|
return new RDTexture( context, rid );
|
2025-04-24 13:39:00 +00:00
|
|
|
}
|
2025-04-23 12:00:43 +00:00
|
|
|
}
|
|
|
|
}
|