rj-action-library/Runtime/Procedural/Textures/TextureCombiner/TextureCombinerBuffer.cs

57 lines
989 B
C#
Raw Normal View History

2025-02-14 07:44:20 +00:00
using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
public class TextureBuffer<T>
{
int _width;
public int width => _width;
int _height;
public int height => _height;
T[] _pixels;
public static TextureBuffer<T> Create( int w, int h )
{
var tb = new TextureBuffer<T>();
tb._height = h;
tb._width = w;
tb._pixels = new T[ w * h ];
return tb;
}
public int ComputeIndexFromPosition( int x, int y )
{
return x + y * _width;
}
public void SetAt( int x, int y, T value )
{
SetIndexed( ComputeIndexFromPosition( x, y ), value );
}
public void SetIndexed( int index, T value )
{
_pixels[ index ] = value;
}
public T GetAt( int x, int y )
{
return GetIndexed( ComputeIndexFromPosition( x, y ) );
}
public T GetIndexed( int index )
{
return _pixels[ index ];
}
}
}