36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using Engine.Renderer.Pixel;
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
namespace Engine.Renderer.Texture;
|
|
|
|
public class DynamicTexture<T> : Texture<T> where T : struct, IPixel
|
|
{
|
|
private readonly PixelFormat _format;
|
|
private readonly PixelType _type;
|
|
private readonly PixelInternalFormat _internalFormat;
|
|
|
|
public DynamicTexture(int width, int height) : base(width, height)
|
|
{
|
|
var pixel = default(T);
|
|
_format = pixel.Format;
|
|
_type = pixel.Type;
|
|
_internalFormat = pixel.InternalFormat;
|
|
|
|
GL.BindTexture(TextureTarget.Texture2D, Handle);
|
|
GL.TexImage2D(TextureTarget.Texture2D, 0, _internalFormat, Width, Height, 0, _format, _type,
|
|
IntPtr.Zero);
|
|
}
|
|
|
|
public void Resize(int width, int height)
|
|
{
|
|
if (Width == width && Height == height)
|
|
return;
|
|
|
|
Width = width;
|
|
Height = height;
|
|
|
|
Bind();
|
|
GL.TexImage2D(TextureTarget.Texture2D, 0, _internalFormat, Width, Height, 0, _format, _type,
|
|
IntPtr.Zero);
|
|
}
|
|
} |