daily update on 20240104 by nitload youmu, double threading not work
This commit is contained in:
@@ -1,20 +1,37 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public unsafe class ElementBuffer : IDisposable, IBufferObject
|
||||
public partial class Form
|
||||
{
|
||||
uint[] _bufferID;
|
||||
private IglFunc GL;
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
internal ElementBuffer(int n, IglFunc glFunc)
|
||||
/// <summary>
|
||||
/// A collecion of handle to Element Buffer Object in OpenGL.
|
||||
/// Each <see cref="uint"/> value indexed from instance of this class this
|
||||
/// is the only handle to one Element Buffer Object.
|
||||
/// </summary>
|
||||
public unsafe class ElementBuffer : IBufferObject
|
||||
{
|
||||
internal ElementBuffer(uint n, IglFunc gl)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
GL = glFunc;
|
||||
GL = gl;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenBuffers(n, id);
|
||||
@@ -26,7 +43,7 @@ namespace StgSharp.Graphics
|
||||
get { return _bufferID[n]; }
|
||||
}
|
||||
|
||||
public void Bind(int index)
|
||||
public override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferID[index]);
|
||||
}
|
||||
@@ -38,14 +55,12 @@ namespace StgSharp.Graphics
|
||||
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferID.Length, id);
|
||||
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
internal class FormRenderBuffer
|
||||
{
|
||||
internal GLonRender GL;
|
||||
internal InternalFormBuffer data;
|
||||
}
|
||||
|
||||
internal class FormUpdateBuffer
|
||||
{
|
||||
internal GLonUpdate GL;
|
||||
internal InternalFormBuffer data;
|
||||
}
|
||||
|
||||
internal class InternalFormBuffer
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,38 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL buffer onjects
|
||||
/// </summary>
|
||||
public interface IBufferObject
|
||||
public abstract class IBufferObject : IDisposable
|
||||
{
|
||||
uint this[int index] { get; }
|
||||
void Bind(int index);
|
||||
protected uint[] _bufferID;
|
||||
protected IglFunc GL;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public uint this[int index]
|
||||
{
|
||||
get { return _bufferID[index]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind a buffer instance to OpenGL
|
||||
/// </summary>
|
||||
/// <param name="index">Index of handle of the object in this instance to be bind</param>
|
||||
public abstract void Bind(int index);
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
~IBufferObject()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,55 +5,59 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
|
||||
public unsafe struct VertexArray : IDisposable, IBufferObject
|
||||
public partial class Form
|
||||
{
|
||||
internal uint[] _bufferID;
|
||||
private IglFunc GL;
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
internal VertexArray(int n)
|
||||
public unsafe class VertexArray : IBufferObject
|
||||
{
|
||||
internal VertexArray(uint n, IglFunc gl)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
//GL = glFunc;
|
||||
GL = gl;
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.GenVertexArrays(n, id);
|
||||
}
|
||||
}
|
||||
|
||||
public uint this[int n]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bufferID[n];
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(int index)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindVertexArray(_bufferID[index]);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.DeleteVertexArrays(_bufferID.Length, id);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindNull()
|
||||
{
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(uint index, int vertexLength, Type dataType, bool isNomalized, int stride, int pointer)
|
||||
public void SetVertexAttribute(uint index, int vertexLength, Type dataType, bool isNomalized, uint stride, int pointer)
|
||||
{
|
||||
GL.SetVertexAttribute(
|
||||
index, vertexLength, dataType,
|
||||
isNomalized,
|
||||
stride, pointer);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteVertexArrays((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,29 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Security;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public unsafe struct VertexBuffer : IDisposable, IBufferObject
|
||||
public partial class Form
|
||||
{
|
||||
internal uint[] _bufferID;
|
||||
private IglFunc GL;
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
internal VertexBuffer(int n, IglFunc glFunc)
|
||||
public unsafe class VertexBuffer : IBufferObject
|
||||
{
|
||||
internal VertexBuffer(uint n, IglFunc glFunc)
|
||||
{
|
||||
_bufferID = new uint[n];
|
||||
GL = glFunc;
|
||||
@@ -23,29 +35,33 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public uint this[int n]
|
||||
{
|
||||
get { return _bufferID[n]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public void Bind(int index)
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferID[index]);
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, (uint)index);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
fixed (uint* id = _bufferID)
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferID.Length, id);
|
||||
fixed (uint* id = _bufferID)
|
||||
{
|
||||
GL.DeleteBuffers((uint)_bufferID.Length, _bufferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,139 +11,143 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
{
|
||||
protected Texture CreateTexture(int n)
|
||||
protected Texture CreateTexture(uint n)
|
||||
{
|
||||
return new Texture(n, GL);
|
||||
return new Texture(n, this.GL);
|
||||
}
|
||||
}
|
||||
public unsafe class Texture
|
||||
{
|
||||
internal uint[] textureId;
|
||||
internal Image[] sourceList;
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IglFunc GL;
|
||||
|
||||
internal void ChangeEnvironment(IglFunc gl)
|
||||
{
|
||||
GL = gl;
|
||||
}
|
||||
|
||||
protected unsafe class Texture
|
||||
internal Texture(uint n, IglFunc gl)
|
||||
{
|
||||
internal uint[] textureId;
|
||||
internal Image[] sourceList;
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IglFunc GL;
|
||||
|
||||
internal Texture(int n, IglFunc glFunc)
|
||||
textureId = new uint[n];
|
||||
sourceList = new Image[n];
|
||||
GL = gl;
|
||||
fixed (uint* id = textureId)
|
||||
{
|
||||
textureId = new uint[n];
|
||||
sourceList = new Image[n];
|
||||
GL = glFunc;
|
||||
fixed (uint* id = textureId)
|
||||
{
|
||||
GL.GenTextures(n, id);
|
||||
}
|
||||
GL.GenTextures(n, id);
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, textureId[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <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();
|
||||
fixed (Image.ImageInfo* textureInfo = &sourceList[index].info)
|
||||
{
|
||||
InternalIO.InternalLoadImage(name, textureInfo, loader);
|
||||
}
|
||||
|
||||
if (sourceList[index].info.pixelPtr != IntPtr.Zero)
|
||||
{
|
||||
uint channel;
|
||||
switch (sourceList[index].info.channel)
|
||||
{
|
||||
case 1:
|
||||
channel = GLconst.RED; break;
|
||||
case 2:
|
||||
channel = GLconst.RG; break;
|
||||
case 3:
|
||||
channel = GLconst.RGB; break;
|
||||
case 4:
|
||||
channel = GLconst.RGBA; break;
|
||||
default:
|
||||
channel = 0;
|
||||
break;
|
||||
}
|
||||
GL.TextureImage2d(
|
||||
GLconst.TEXTURE_2D, 0, channel,
|
||||
sourceList[index].Width, sourceList[index].Height,
|
||||
channel, GLconst.UNSIGNED_BYTE, (byte*)sourceList[index].info.pixelPtr
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog($"Failed to load image file of \"{name}\".", LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#region texture set
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Activate(TextureUnit unit)
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum TextureUnit
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
Unit3 = GLconst.TEXTURE3,
|
||||
Unit4 = GLconst.TEXTURE4,
|
||||
Unit5 = GLconst.TEXTURE5,
|
||||
Unit6 = GLconst.TEXTURE6,
|
||||
Unit7 = GLconst.TEXTURE7,
|
||||
Unit8 = GLconst.TEXTURE8,
|
||||
Unit9 = GLconst.TEXTURE9,
|
||||
Unit10 = GLconst.TEXTURE10,
|
||||
Unit11 = GLconst.TEXTURE11,
|
||||
Unit12 = GLconst.TEXTURE12,
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
GL.BindTexture(GLconst.TEXTURE_2D, textureId[index]);
|
||||
}
|
||||
|
||||
public enum Wrap
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="loader"></param>
|
||||
public unsafe void LoadTexture(int index, string name, ImageLoader loader)
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
sourceList[index] = new Image();
|
||||
fixed (Image.ImageInfo* textureInfo = &sourceList[index].info)
|
||||
{
|
||||
InternalIO.InternalLoadImage(name, textureInfo, loader);
|
||||
}
|
||||
|
||||
if (sourceList[index].info.pixelPtr != IntPtr.Zero)
|
||||
{
|
||||
uint channel;
|
||||
switch (sourceList[index].info.channel)
|
||||
{
|
||||
case 1:
|
||||
channel = GLconst.RED; break;
|
||||
case 2:
|
||||
channel = GLconst.RG; break;
|
||||
case 3:
|
||||
channel = GLconst.RGB; break;
|
||||
case 4:
|
||||
channel = GLconst.RGBA; break;
|
||||
default:
|
||||
channel = 0;
|
||||
break;
|
||||
}
|
||||
GL.TextureImage2d(
|
||||
GLconst.TEXTURE_2D, 0, channel,
|
||||
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
|
||||
channel, GLconst.UNSIGNED_BYTE, (byte*)sourceList[index].info.pixelPtr
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
InternalIO.InternalWriteLog($"Failed to load image file of \"{name}\".", LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Filter
|
||||
#region texture set
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
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,
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Activate(TextureUnit unit)
|
||||
{
|
||||
GL.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum TextureUnit
|
||||
{
|
||||
Unit0 = GLconst.TEXTURE0,
|
||||
Unit1 = GLconst.TEXTURE1,
|
||||
Unit2 = GLconst.TEXTURE2,
|
||||
Unit3 = GLconst.TEXTURE3,
|
||||
Unit4 = GLconst.TEXTURE4,
|
||||
Unit5 = GLconst.TEXTURE5,
|
||||
Unit6 = GLconst.TEXTURE6,
|
||||
Unit7 = GLconst.TEXTURE7,
|
||||
Unit8 = GLconst.TEXTURE8,
|
||||
Unit9 = GLconst.TEXTURE9,
|
||||
Unit10 = GLconst.TEXTURE10,
|
||||
Unit11 = GLconst.TEXTURE11,
|
||||
Unit12 = GLconst.TEXTURE12,
|
||||
Unit13 = GLconst.TEXTURE13,
|
||||
Unit14 = GLconst.TEXTURE14,
|
||||
Unit15 = GLconst.TEXTURE15,
|
||||
}
|
||||
|
||||
public enum Wrap
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
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