daily update on 20240203 by nitloadd youmu. New glhandle setup.
This commit is contained in:
@@ -7,19 +7,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="ElementBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of EBO to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected ElementBuffer CreateElementBuffer(uint count)
|
||||
{
|
||||
return new ElementBuffer(count, this.gl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A collecion of handle to Element Buffer Object in OpenGL.
|
||||
@@ -30,28 +18,25 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal ElementBuffer(uint n, IglFunc gl)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
_bufferHandle = new glHandle((int)n);
|
||||
GL = gl;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenBuffers(n, id);
|
||||
}
|
||||
GL.GenBuffers(n, _bufferHandle);
|
||||
}
|
||||
|
||||
public uint this[int n]
|
||||
{
|
||||
get { return _bufferID[n]; }
|
||||
get { return _bufferHandle[n]; }
|
||||
}
|
||||
|
||||
public override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
||||
}
|
||||
|
||||
@@ -59,7 +44,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public abstract class IBufferObject : IDisposable
|
||||
{
|
||||
protected uint[] _bufferID;
|
||||
protected glHandle _bufferHandle;
|
||||
protected IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
@@ -21,7 +21,7 @@ namespace StgSharp.Graphics
|
||||
/// <returns></returns>
|
||||
public uint this[int index]
|
||||
{
|
||||
get { return _bufferID[index]; }
|
||||
get { return _bufferHandle[index]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,36 +5,20 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexArray"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of VAO to be crated.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected VertexArray CreateVertexArray(uint count)
|
||||
{
|
||||
return new VertexArray(count, gl);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class VertexArray : IBufferObject
|
||||
{
|
||||
internal VertexArray(uint n, IglFunc gl)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
_bufferHandle = new glHandle((int)n);
|
||||
GL = gl;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenVertexArrays(n, id);
|
||||
}
|
||||
GL.GenVertexArrays(n, _bufferHandle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindVertexArray(_bufferID[index]);
|
||||
GL.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -56,7 +40,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteVertexArrays((uint)_bufferID.Length, _bufferID);
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,39 +9,14 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Create aset of <see cref="VertexBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of Object to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected VertexBuffer CreateVertexBuffer(uint count)
|
||||
{
|
||||
return new VertexBuffer(count, gl);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class VertexBuffer : IBufferObject
|
||||
{
|
||||
internal VertexBuffer(uint n, IglFunc glFunc)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
_bufferHandle = new glHandle((int)n);
|
||||
GL = glFunc;
|
||||
fixed (uint* ptr = _bufferID)
|
||||
{
|
||||
GL.GenBuffers(n, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
|
||||
GL.GenBuffers(n, _bufferHandle);
|
||||
}
|
||||
|
||||
public sealed override void Bind(int index)
|
||||
@@ -49,22 +24,6 @@ namespace StgSharp.Graphics
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, (uint)index);
|
||||
}
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
@@ -74,7 +33,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void SetValue<T>(int index, T bufferData, BufferUsage usage) where T : IMat
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
||||
|
||||
}
|
||||
@@ -88,9 +47,30 @@ namespace StgSharp.Graphics
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void SetValueArray<T>(int index, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
|
||||
}
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,47 +9,37 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
protected Texture CreateTexture(uint n)
|
||||
{
|
||||
return new Texture(n, this.GL);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class Texture
|
||||
{
|
||||
internal uint[] textureId;
|
||||
internal Image[] sourceList;
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
internal glHandle _textureHandle;
|
||||
internal Image[] sourceList;
|
||||
private IglFunc GL;
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
internal Texture(uint n, IglFunc gl)
|
||||
{
|
||||
textureId = new uint[n];
|
||||
_textureHandle = new glHandle((int)n);
|
||||
sourceList = new Image[n];
|
||||
GL = gl;
|
||||
fixed (uint* id = textureId)
|
||||
{
|
||||
GL.GenTextures(n, id);
|
||||
}
|
||||
GL.GenTextures(n, _textureHandle);
|
||||
}
|
||||
|
||||
public void Activate(TextureUnit unit)
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, textureId[index]);
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="loader"></param>
|
||||
/// <param name="name"> </param>
|
||||
/// <param name="index"> </param>
|
||||
/// <param name="loader"> </param>
|
||||
public unsafe void LoadTexture(int index, string name, ImageLoader loader)
|
||||
{
|
||||
sourceList[index] = new Image();
|
||||
@@ -87,6 +77,11 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
#region texture set
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
@@ -103,13 +98,17 @@ namespace StgSharp.Graphics
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Activate(TextureUnit unit)
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
}
|
||||
#endregion texture set
|
||||
}
|
||||
|
||||
public enum Filter
|
||||
{
|
||||
Nearest = GLconst.NEAREST,
|
||||
Linear = GLconst.LINEAR,
|
||||
Nearest_LinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
|
||||
Linear_LinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
|
||||
Nearest_NearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
|
||||
Linear_NearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
|
||||
}
|
||||
|
||||
public enum TextureUnit
|
||||
@@ -139,15 +138,4 @@ namespace StgSharp.Graphics
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
}
|
||||
|
||||
public enum Filter
|
||||
{
|
||||
Nearest = GLconst.NEAREST,
|
||||
Linear = GLconst.LINEAR,
|
||||
Nearest_LinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
|
||||
Linear_LinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
|
||||
Nearest_NearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
|
||||
Linear_NearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user