.
This commit is contained in:
36
Engine/Renderer/Texture/DynamicTexture.cs
Normal file
36
Engine/Renderer/Texture/DynamicTexture.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user