make new opengl source generator

This commit is contained in:
Youmu Liu
2026-08-26 18:12:08 +08:00
parent 65041ff8bc
commit 75bf7fc139
126 changed files with 8934 additions and 26139 deletions
@@ -5,13 +5,8 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Mathematics.Numeric;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics.OpenGL
{
@@ -28,136 +23,51 @@ namespace StgSharp.Graphics.OpenGL
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void DeleteBuffer(
GlHandle handle
public void DeleteBuffer(
GlHandle handle
)
{
_context->glDeleteBuffers(1, (uint*)&handle);
_context->glDeleteBuffers(1, &handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void DeleteBuffers(
GlHandle[] handle
public void DeleteBuffers(
ReadOnlySpan<GlHandle> handles
)
{
if ((handle == null) || (handle.Length == 0)) {
throw new ArgumentNullException(nameof(handle));
}
fixed (GlHandle* hptr = handle)
{
uint* iptr = (uint*)hptr;
for (int i = 0; i < handle.Length; i++) {
_context->glDeleteBuffers(1, iptr + i);
}
fixed (GlHandle* handlesPtr = handles) {
_context->glDeleteBuffers(handles.Length, (uint*)handlesPtr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe GlHandle[] GenBuffers(
int count
public GlHandle[] GenBuffers(
int count
)
{
GlHandle[] h = new GlHandle[count];
fixed (GlHandle* hptr = h)
{
for (int i = 0; i < count; i++) {
_context->glGenBuffers(count, ((uint*)hptr) + i);
}
ArgumentOutOfRangeException.ThrowIfNegative(count);
GlHandle[] handles = new GlHandle[count];
if (handles.Length == 0) {
return handles;
}
return h;
fixed (GlHandle* handlesPtr = handles) {
_context->glGenBuffers(count, (uint*)handlesPtr);
}
return handles;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetBufferData<T>(
BufferType bufferType,
T bufferData,
BufferUsage usage
) where T : unmanaged, INumber<T>
public void SetBufferData<T>(
BufferType bufferType,
ReadOnlySpan<T> bufferData,
BufferUsage usage
) where T : unmanaged
{
int size = Marshal.SizeOf<T>();
T* p = &bufferData;
_context->glBufferData((uint)bufferType, size, (nint*)p, (uint)usage);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetBufferData<T>(
BufferType bufferType,
[NotNull] T[] bufferArray,
BufferUsage usage
) where T : unmanaged, INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf<T>();
if (bufferArray == null) {
return;
}
fixed (void* bufferPtr = bufferArray) {
_context->glBufferData((uint)bufferType, size, (nint*)bufferPtr, (uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetBufferData<T>(
BufferType bufferType,
ReadOnlySpan<T> bufferSpan,
BufferUsage usage
) where T : unmanaged, INumber<T>
{
int size = bufferSpan.Length * Marshal.SizeOf<T>();
if (bufferSpan.IsEmpty) {
return;
}
fixed (void* bufferPtr = bufferSpan) {
_context->glBufferData((uint)bufferType, size, (IntPtr*)bufferPtr, (uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetBufferData<T>(
BufferType bufferType,
Span<T> bufferArray,
BufferUsage usage
) where T : unmanaged, INumber<T>
{
int size = bufferArray.Length * Marshal.SizeOf<T>();
if (bufferArray.IsEmpty) {
return;
}
fixed (void* bufferPtr = bufferArray) {
_context->glBufferData((uint)bufferType, size, (IntPtr*)bufferPtr, (uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetBufferVectorData<T>(
BufferType bufferType,
ReadOnlySpan<T> bufferSpan,
BufferUsage usage
) where T : unmanaged, IUnmanagedVector<T>
{
int size = bufferSpan.Length * Marshal.SizeOf<T>();
fixed (void* bufferPtr = bufferSpan) {
_context->glBufferData((uint)bufferType, size, (IntPtr*)bufferPtr, (uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetBufferVectorData<T>(
BufferType bufferType,
T[] bufferArray,
BufferUsage usage
) where T : unmanaged, IUnmanagedVector<T>
{
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
if (bufferArray == null) {
return;
}
fixed (void* bufferPtr = bufferArray) {
_context->glBufferData((uint)bufferType, (nuint)size, (IntPtr*)bufferPtr,
(uint)usage);
nint sizeInBytes = checked((nint)bufferData.Length * sizeof(T));
fixed (T* bufferPtr = bufferData) {
_context->glBufferData((uint)bufferType, sizeInBytes, bufferPtr, (uint)usage);
}
}
@@ -19,11 +19,26 @@ namespace StgSharp.Graphics.OpenGL
Span<GlHandle> framebuffers
)
{
if (framebuffers.IsEmpty) {
return;
}
fixed (GlHandle* framebuffersPtr = framebuffers) {
Context.glGenFramebuffers(framebuffers.Length, (uint*)framebuffersPtr);
}
}
/// <summary>Delete framebuffer object handles.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DeleteFramebuffers(
ReadOnlySpan<GlHandle> framebuffers
)
{
fixed (GlHandle* framebuffersPtr = framebuffers) {
Context.glDeleteFramebuffers(framebuffers.Length, (uint*)framebuffersPtr);
}
}
/// <summary>
/// Bind a framebuffer object to a framebuffer target.
/// </summary>
@@ -73,6 +88,17 @@ namespace StgSharp.Graphics.OpenGL
_context->glDeleteRenderbuffers(1, &bufferHandle.Value);
}
/// <summary>Delete renderbuffer object handles.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DeleteRenderbuffers(
ReadOnlySpan<GlHandle> renderbuffers
)
{
fixed (GlHandle* renderbuffersPtr = renderbuffers) {
Context.glDeleteRenderbuffers(renderbuffers.Length, (uint*)renderbuffersPtr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void FrameBufferTexture2d(
FrameBufferTarget target,
@@ -91,7 +117,13 @@ namespace StgSharp.Graphics.OpenGL
int count
)
{
ArgumentOutOfRangeException.ThrowIfNegative(count);
GlHandle[] h = new GlHandle[count];
if (h.Length == 0) {
return h;
}
fixed (GlHandle* hptr = h) {
_context->glGenRenderbuffers(count, (uint*)hptr);
}
@@ -5,11 +5,8 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
@@ -18,114 +15,179 @@ namespace StgSharp.Graphics.OpenGL
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe GlHandle CreateGraphicProgram()
public GlHandle CreateGraphicProgram()
{
return GlHandle.Create(_context->glCreateProgram());
return CreateProgram();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe GlHandle[] CreateProgram(
int count
public GlHandle[] CreateProgram(
int count
)
{
GlHandle[] h = new GlHandle[count];
for (int i = 0; i < count; i++) {
h.SetValue(i, _context->glCreateProgram());
ArgumentOutOfRangeException.ThrowIfNegative(count);
GlHandle[] handles = new GlHandle[count];
for (int i = 0; i < handles.Length; i++) {
handles[i] = CreateProgram();
}
return h;
return handles;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GlHandle CreateShader(
ShaderType type
)
{
GlHandle handle = CreateShader((uint)type);
if (handle.Value == 0)
{
uint error = _context->glGetError();
throw new InvalidOperationException($"Failed in creating shader: {error}");
}
return handle;
}
public GlHandle[] CreateShaderSet(
int count,
ShaderType type
)
{
GlHandle[] ret = new GlHandle[count];
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = _context->glCreateShader(t);
if (id == 0)
{
uint error = _context->glGetError();
throw new InvalidOperationException($"Failed in creating shader: {error}");
}
ret[i] = GlHandle.Create(id);
ArgumentOutOfRangeException.ThrowIfNegative(count);
GlHandle[] handles = new GlHandle[count];
for (int i = 0; i < handles.Length; i++) {
handles[i] = CreateShader(type);
}
return ret;
return handles;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string GetShaderStatus(
GlHandle shader,
ShaderStatus status
)
{
return GetShaderStatus(shader, (uint)status);
}
public string GetShaderStatus(
Shader s,
int index,
int key
GlHandle shader,
uint statusName
)
{
IntPtr sptr = IntPtr.Zero;
if (GraphicFramework.glCheckShaderStatus(ref Context, s.handle[index].Value, key,
ref sptr) == 0) {
return Marshal.PtrToStringAnsi(sptr) ?? string.Empty;
int status;
_context->glGetShaderiv(shader.Value, statusName, &status);
if (status != 0) {
return string.Empty;
}
return string.Empty;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe GlHandle GetUniformLocation(
GlHandle program,
string name
)
{
byte[] code = Encoding.UTF8.GetBytes(name);
fixed (byte* ptr = code)
int logLength;
_context->glGetShaderiv(shader.Value, glConst.INFO_LOG_LENGTH, &logLength);
if (logLength <= 1) {
return string.Empty;
}
byte[] log = new byte[logLength];
fixed (byte* logPtr = log)
{
int ret = _context->glGetUniformLocation(program.Value, ptr);
#if DEBUG
if (ret is glConst.INVALID_OPERATION or glConst.INVALID_VALUE)
{
throw new InvalidOperationException();
}
if (ret == -1) {
throw new UniformEmptyReferenceException(nameof(program), name);
}
#endif
return GlHandle.CreateSigned(ret);
int written;
_context->glGetShaderInfoLog(shader.Value, log.Length, &written, logPtr);
return Encoding.UTF8.GetString(log, 0, Math.Clamp(written, 0, log.Length));
}
}
public GlHandle GetUniformLocation(
GlHandle program,
string name
)
{
ArgumentNullException.ThrowIfNull(name);
int byteCount = Encoding.UTF8.GetByteCount(name);
Span<byte> utf8Name = byteCount < 256
? stackalloc byte[byteCount + 1]
: new byte[byteCount + 1];
int written = Encoding.UTF8.GetBytes(name.AsSpan(), utf8Name);
utf8Name[written] = 0;
int location;
fixed (byte* namePtr = utf8Name) {
location = _context->glGetUniformLocation(program.Value, namePtr);
}
#if DEBUG
if (location == -1) {
throw new UniformEmptyReferenceException(nameof(program), name);
}
#endif
return GlHandle.CreateSigned(location);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void LoadShaderSource(
GlHandle shaderHandle,
byte[] codeStream
)
public Uniform<T> GetUniform<T>(
GlHandle program,
string name
) where T : unmanaged
{
fixed (byte* streamPtr = codeStream) {
_context->glShaderSource(shaderHandle.Value, 1, &streamPtr, (int*)0);
}
return new Uniform<T>(GetUniformLocation(program, name));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void LoadShaderSource(
GlHandle shaderHandle,
ReadOnlySpan<char> codeStream
)
public Uniform<T, U> GetUniform<T, U>(
GlHandle program,
string name
) where T : unmanaged where U : struct
{
fixed (char* streamPtr = codeStream) {
_context->glShaderSource(shaderHandle.Value, 1, (byte**)&streamPtr, (int*)0);
}
return new Uniform<T, U>(GetUniformLocation(program, name));
}
public unsafe void LoadShaderSource(
GlHandle shaderHandle,
ReadOnlySpan<byte> codeStream
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Uniform<T, U, V> GetUniform<T, U, V>(
GlHandle program,
string name
) where T : unmanaged where U : struct where V : struct
{
return new Uniform<T, U, V>(GetUniformLocation(program, name));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Uniform<T, U, V, W> GetUniform<T, U, V, W>(
GlHandle program,
string name
) where T : unmanaged where U : struct where V : struct where W : struct
{
return new Uniform<T, U, V, W>(GetUniformLocation(program, name));
}
public void ShaderSource(
GlHandle shader,
ReadOnlySpan<byte> source
)
{
fixed (byte* streamPtr = codeStream)
int length = source.Length;
fixed (byte* sourcePtr = source)
{
byte* bptr = streamPtr;
_context->glShaderSource(shaderHandle.Value, 1, &bptr, (int*)0);
byte emptySource = 0;
byte* sourceAddress = sourcePtr == null ? &emptySource : sourcePtr;
_context->glShaderSource(shader.Value, 1, &sourceAddress, &length);
}
}
public void ShaderSource(
GlHandle shader,
string source
)
{
ArgumentNullException.ThrowIfNull(source);
int byteCount = Encoding.UTF8.GetByteCount(source);
Span<byte> utf8Source = byteCount < 1024
? stackalloc byte[byteCount]
: new byte[byteCount];
int written = Encoding.UTF8.GetBytes(source.AsSpan(), utf8Source);
ShaderSource(shader, utf8Source[..written]);
}
}
}
@@ -5,10 +5,7 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace StgSharp.Graphics.OpenGL
@@ -29,25 +26,42 @@ namespace StgSharp.Graphics.OpenGL
int count
)
{
ArgumentOutOfRangeException.ThrowIfNegative(count);
GlHandle[] h = new GlHandle[count];
if (h.Length == 0) {
return h;
}
fixed (GlHandle* hptr = h) {
_context->glGenTextures(count, (uint*)hptr);
}
return h;
}
/// <summary>Delete texture object handles.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DeleteTextures(
ReadOnlySpan<GlHandle> textures
)
{
fixed (GlHandle* texturesPtr = textures) {
Context.glDeleteTextures(textures.Length, (uint*)texturesPtr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void GetTextureImage<T>(
Texture2DTarget target,
int level,
ImageChannel channel,
FrameBufferChannel channel,
PixelChannelLayout channelLayout,
T[] dataStream
) where T : unmanaged, INumber<T>
Span<T> destination
) where T : unmanaged
{
fixed (T* tptr = dataStream) {
fixed (T* tptr = destination) {
_context->glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout,
(nint*)tptr);
tptr);
}
}
@@ -65,73 +79,50 @@ namespace StgSharp.Graphics.OpenGL
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReadPixels(
public void ReadPixels<T>(
(int X, int Y) beginPosition,
(int width, int height) size,
FrameBufferChannel format,
PixelChannelLayout dataType,
ref byte[] stream
)
Span<T> destination
) where T : unmanaged
{
fixed (byte* bptr = stream) {
fixed (T* destinationPtr = destination) {
_context->glReadPixels(beginPosition.X, beginPosition.Y, size.width, size.height,
(uint)format, (uint)dataType, (nint*)bptr);
(uint)format, (uint)dataType, destinationPtr);
}
}
public void RereadImage(
in Image i,
(int X, int Y) beginPosition,
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TextureImage2d(
Texture2DTarget target,
int level,
int internalFormat,
int width,
int height,
FrameBufferChannel format,
PixelChannelLayout dataType
PixelChannelLayout type
)
{
byte[] pixels = i.PixelBuffer;
if (!pixels.CheckArrayFormat(dataType)) {
throw new GlArrayFormatException(dataType, "i.PixelArray");
}
fixed (byte* bptr = pixels) {
_context->glReadPixels(beginPosition.X, beginPosition.Y, i.Width, i.Height,
(uint)format, (uint)dataType, (nint*)bptr);
}
i.PixelUpdateCount++;
_context->glTexImage2D((uint)target, level, internalFormat, width, height, 0,
(uint)format, (uint)type, (void*)0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TextureImage2d<T>(
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
int internalFormat,
int width,
int height,
ImageChannel targetChannel,
FrameBufferChannel format,
PixelChannelLayout type,
T[] pixels
) where T : unmanaged, INumber<T>
ReadOnlySpan<T> pixels
) where T : unmanaged
{
fixed (T* tptr = pixels)
{
T* ptr = ((pixels == null) || (pixels.Length == 0)) ? (T*)IntPtr.Zero : tptr;
_context->glTexImage2D((uint)target, level, (int)sourceChannel, width, height, 0,
(uint)targetChannel, (uint)type, (nint*)tptr);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TextureImage2d<T>(
Texture2DTarget target,
int level,
ImageChannel sourceChannel,
int width,
int height,
ImageChannel targetChannel,
PixelChannelLayout type,
Span<T> pixelSpan
) where T : unmanaged, INumber<T>
{
fixed (T* tPtr = pixelSpan) {
_context->glTexImage2D((uint)target, level, (int)sourceChannel, width, height, 0,
(uint)targetChannel, (uint)type, (nint*)tPtr);
fixed (T* pixelPtr = pixels) {
_context->glTexImage2D((uint)target, level, internalFormat, width, height, 0,
(uint)format, (uint)type, pixelPtr);
}
}
@@ -25,15 +25,11 @@ namespace StgSharp.Graphics.OpenGL
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void DeleteVertexArrays(
GlHandle[] arrays
ReadOnlySpan<GlHandle> arrays
)
{
fixed (GlHandle* hptr = arrays)
{
uint* iptr = (uint*)hptr;
for (int i = 0; i < arrays.Length; i++) {
_context->glDeleteVertexArrays(1, iptr + i);
}
fixed (GlHandle* arraysPtr = arrays) {
_context->glDeleteVertexArrays(arrays.Length, (uint*)arraysPtr);
}
}
@@ -41,7 +37,13 @@ namespace StgSharp.Graphics.OpenGL
int count
)
{
ArgumentOutOfRangeException.ThrowIfNegative(count);
GlHandle[] h = new GlHandle[count];
if (h.Length == 0) {
return h;
}
fixed (GlHandle* hptr = h) {
_context->glGenVertexArrays(count, (uint*)hptr);
}
@@ -58,7 +60,18 @@ namespace StgSharp.Graphics.OpenGL
int pointer
)
{
uint type = GraphicFramework.GLtype[(int)t];
uint type = t switch
{
TypeCode.Single => glConst.FLOAT,
TypeCode.Int32 => glConst.INT,
TypeCode.UInt32 => glConst.UNSIGNED_INT,
TypeCode.Int16 => glConst.SHORT,
TypeCode.UInt16 => glConst.UNSIGNED_SHORT,
TypeCode.SByte => glConst.BYTE,
TypeCode.Byte => glConst.UNSIGNED_BYTE,
_ => throw new ArgumentOutOfRangeException(nameof(t), t,
"The type cannot be used as an OpenGL vertex attribute."),
};
_context->glVertexAttribPointer(index, size, type, (byte)(normalized ? 1 : 0), stride,
(nint*)pointer);
_context->glEnableVertexAttribArray(index);
@@ -1,149 +0,0 @@
// -----------------------------------------------------------------------------
// file="AutoTexture"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Collections;
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
/// the texture with minimum costs to upgrade pixels to BufferHandle. Usually <see ///
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint, ///
/// Texture2DTarget, GlHandle, int)" />.
/// </summary>
public sealed class AutoTextureGL
{
private TextureProperty[] propertyCache;
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>(
);
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>();
private int _size, _currentIndex;
private LinkedList<int> usedTextureIndex;
private Queue<int> unusedTextureUnitIndex;
private TextureGL texturePackage;
private TextureProperty _textureProperty;
private AutoTextureGL(
TextureGL texture
)
{
texturePackage = texture;
_size = texture.Count;
imageIndexMap = new BidirectionalDictionary<Image, int>();
unusedTextureUnitIndex = new Queue<int>(Enumerable.Range(0, _size));
usedTextureIndex = new LinkedList<int>();
propertyCache = new TextureProperty[_size];
}
public AutoTextureGL(
int textureObjectSize,
[NotNull]glRender binding
)
{
this._size = textureObjectSize;
imageIndexMap = new BidirectionalDictionary<Image, int>();
texturePackage = new TextureGL(textureObjectSize, binding);
unusedTextureUnitIndex = new Queue<int>(Enumerable.Range(0, _size));
usedTextureIndex = new LinkedList<int>();
propertyCache = new TextureProperty[_size];
}
public TextureProperty DefaultTextureProperty
{
get => _textureProperty;
set => _textureProperty = value;
}
private OpenGLFunction GL => texturePackage.GL;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SelectTextureAndBind(
Image i
)
{
TextureProperty property = _textureProperty;
SelectTextureAndBind(i, property);
}
public void SelectTextureAndBind(
[NotNull]Image i,
TextureProperty property
)
{
// usable texture with image match
if (imageIndexMap.TryGetValue(i, out int index))
{
// prop setting match
if (propertyCache[index] == property)
{
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D(index); //GL.Assert(true);
if (i.PixelUpdateCount != imageUpdateIndex[i])
{
texturePackage.LoadTexture(index, i); //GL.Assert(true);
}
} else
{
_currentIndex = index; //GL.Assert(true);
texturePackage.Bind2D(index); //GL.Assert(true);
texturePackage.Set2dProperty(index, property); //GL.Assert(true);
if (i.PixelUpdateCount != imageUpdateIndex[i])
{
texturePackage.LoadTexture(index, i); //GL.Assert(true);
}
}
} else
{
if (unusedTextureUnitIndex.TryDequeue(out int newIndex))
{
// has extra unused texture object
imageIndexMap.Add(i, index);
texturePackage.Bind2D(index);
texturePackage.Set2dProperty(index, property);
texturePackage.LoadTexture(index, i);
usedTextureIndex.AddLast(newIndex);
propertyCache[newIndex] = property;
imageUpdateIndex[i] = i.PixelUpdateCount;
} else
{
// recycle from current
int reusedIndex = usedTextureIndex.First!.Value;
usedTextureIndex.RemoveFirst();
usedTextureIndex.AddLast(reusedIndex);
imageIndexMap[i] = reusedIndex;
propertyCache[newIndex] = property;
imageUpdateIndex[i] = i.PixelUpdateCount;
}
}
}
public static AutoTextureGL ToAuto(
[NotNull]TextureGL texture
)
{
if (texture.IndexOfCurrentTexture != -1) {
throw new InvalidOperationException("Texture to be converted has been editted.");
}
return new AutoTextureGL(texture);
}
}
}
+7 -62
View File
@@ -5,72 +5,17 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL;
using StgSharp.Mathematics;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
/// <summary>
/// A collection of handle to Element BufferHandle Object in OpenglFunc. Each <see ///
/// langword="uint" /> value indexed from instance of this class this is the only handle to
/// one Element BufferHandle Object.
/// </summary>
public sealed unsafe class ElementBuffer : GlBufferObjectBase
/// <summary>A set of OpenGL element-buffer handles.</summary>
public sealed record class ElementBuffer(
GlHandle[] Handles
)
{
internal ElementBuffer(
int n,
glRender binding
)
: base(binding)
{
_bufferHandle = GL.GenBuffers(n);
}
public int Count => Handles.Length;
public sealed override void Bind(
int index
)
{
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
}
public void SetValue<T>(
int index,
T[] bufferArray,
BufferUsage usage
) where T : unmanaged, INumber<T>
{
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferArray, usage);
}
public void SetValue<T>(
int index,
ReadOnlySpan<T> bufferSpan,
BufferUsage usage
) where T : unmanaged, INumber<T>
{
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferSpan, usage);
}
protected sealed override void Dispose(
bool disposing
)
{
if (disposing) {
GL.DeleteBuffers(_bufferHandle);
}
}
public GlHandle this[int index] => Handles[index];
}
}
}
+10 -71
View File
@@ -5,22 +5,13 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
#pragma warning disable CA1008
#pragma warning disable CA1028
#pragma warning disable CA1008
#pragma warning disable CA1028
public enum FrameBufferTarget : uint
#pragma warning restore CA1028
#pragma warning restore CA1008
#pragma warning restore CA1028
#pragma warning restore CA1008
{
Read = glConst.READ_FRAMEBUFFER,
@@ -29,67 +20,15 @@ namespace StgSharp.Graphics.OpenGL
}
public sealed class FrameBuffer : GlBufferObjectBase
/// <summary>A set of OpenGL framebuffer handles.</summary>
public sealed record class FrameBuffer(
GlHandle[] Handles
)
{
internal unsafe FrameBuffer(
int count,
glRender binding
)
: base(binding)
{
_bufferHandle = new GlHandle[count];
GL.GenFrameBuffers(_bufferHandle);
}
public int Count => Handles.Length;
/// <summary>
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
/// BufferHandle target specified by target. <see langword="FrameBufferTarget.All" /> will
/// be set as default target.
/// </summary>
/// <param _label="index">
/// Index of object to be binded in handle set
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override unsafe void Bind(
int index
)
{
GL.BindFrameBuffer(FrameBufferTarget.All, _bufferHandle[index]);
}
/// <summary>
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
/// BufferHandle target specified by target. Target of this frame BufferHandle should be
/// set manually.
/// </summary>
/// <param _label="target">
/// The frame BufferHandle target of the binding operation.
/// </param>
/// <param _label="index">
/// Index of object to be binded in handle set
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Bind(
FrameBufferTarget target,
int index
)
{
GL.BindFrameBuffer(target, _bufferHandle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindNull()
{
OpenGLFunction.CurrentGL.BindFrameBuffer(FrameBufferTarget.All, GlHandle.Zero);
}
protected override void Dispose(
bool disposing
)
{
throw new NotImplementedException();
}
public GlHandle this[int index] => Handles[index];
}
}
@@ -1,32 +0,0 @@
// -----------------------------------------------------------------------------
// file="GLBufferObjectBase"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics.OpenGL;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public abstract class GlBufferObjectBase : BufferObjectBase
{
private readonly glRender _contextBinding;
protected GlBufferObjectBase(
glRender contextBinding
)
{
binding = contextBinding;
_contextBinding = contextBinding;
}
protected OpenGLFunction GL => _contextBinding.GL;
}
}
+6 -42
View File
@@ -5,53 +5,17 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed class RenderBuffer : GlBufferObjectBase
/// <summary>A set of OpenGL renderbuffer handles.</summary>
public sealed record class RenderBuffer(
GlHandle[] Handles
)
{
public RenderBuffer(
int count,
glRender binding
)
: base(binding)
{
_bufferHandle = GL.GenRenderBuffer(count);
}
public int Count => Handles.Length;
public override void Bind(
int index
)
{
GL.BindRenderBuffer(this[index]);
}
public void Store(
RenderBufferInternalFormat format,
(int width, int height) size
)
{
if ((size.width > binding.Width) || (size.height > binding.Height)) {
World.LogWarning("FrameBuffer is larger than current canvas binding");
}
}
protected override void Dispose(
bool disposing
)
{
foreach (GlHandle item in _bufferHandle)
{
Console.WriteLine("removing a render buffer");
GL.DeleteRenderBuffer(item);
}
}
public GlHandle this[int index] => Handles[index];
}
}
+15 -223
View File
@@ -5,235 +5,27 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.HighPerformance.ProcessorAbstraction;
using StgSharp.Mathematics;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class TextureGL
/// <summary>A set of OpenGL texture handles.</summary>
public sealed record class TextureGL(
GlHandle[] Handles
)
{
private int currentEditingTextureIndex;
public int Count => Handles.Length;
private OpenGLFunction _gl;
internal GlHandle[] _textureHandle;
internal TextureGL(
int count,
glRender binding
)
{
// sourceList = new Image[count];
this._gl = binding.GL;
_textureHandle = _gl.GenTextures(count);
}
public GlHandle this[
int index
]
{
get => _textureHandle[index];
}
public int Count => _textureHandle.Length;
// internal Image[] sourceList;
public int IndexOfCurrentTexture => currentEditingTextureIndex;
internal OpenGLFunction GL => _gl;
public void ActivateAs(
TextureUnit unit
)
{
_gl.ActiveTextureUnit((uint)unit);
}
public void Bind2D(
int index
)
{
currentEditingTextureIndex = index;
_gl.BindTexture(glConst.TEXTURE_2D, _textureHandle[index]);
}
/// <summary>
/// Load an <see cref="Image" /> to certain texture.
/// </summary>
/// <param _label="index">
///
/// </param>
/// <param _label="i">
///
/// </param>
public unsafe void LoadTexture(
int index,
Image i
)
{
byte[] handle = i.PixelBuffer;
_gl.TextureImage2d(Texture2DTarget.Texture2D, 0, i.Channel, i.Width, i.Height,
i.Channel, i.PixelLayout, pixels:handle);
_gl.GenerateMipmap(Texture2DTarget.Texture2D);
}
#region texture setting
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dFilterProperty(
int index,
TextureFilter onMinify,
TextureFilter onMagnify
)
{
#if DEBUG
if (index != currentEditingTextureIndex)
{
throw new InvalidOperationException(
"Texture to be editted is not the one being activated.");
}
#endif
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MIN_FILTER, (int)onMinify);
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_MAG_FILTER,
(int)onMagnify);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dWrapProperty(
int index,
TextureWrap onHorizontial,
TextureWrap onVertical
)
{
#if DEBUG
if (index != currentEditingTextureIndex)
{
throw new InvalidOperationException(
"Texture to be editted is not the one being activated.");
}
#endif
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_S,
(int)onHorizontial);
_gl.TextureParameter(glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_T, (int)onVertical);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set2dProperty(
int index,
TextureProperty property
)
{
Set2dFilterProperty(index, property.FilterOnMinify, property.FilterOnMagnify);
Set2dWrapProperty(index, property.WrapOnHorizontial, property.WrapOnVertical);
}
#endregion texture setting
}
[StructLayout(LayoutKind.Explicit)]
public struct TextureProperty
{
[FieldOffset(0)] private M128 mask;
[FieldOffset(0)] private TextureFilter mag;
[FieldOffset(4)] private TextureFilter min;
[FieldOffset(8)] private TextureWrap hori;
[FieldOffset(12)] private TextureWrap vert;
public TextureProperty(
TextureFilter onMagnify,
TextureFilter onMinify,
TextureWrap onHorizontal,
TextureWrap onVertical
)
{
FilterOnMagnify = onMagnify;
FilterOnMinify = onMinify;
WrapOnHorizontial = onHorizontal;
WrapOnVertical = onVertical;
}
public TextureFilter FilterOnMagnify
{
get => mag;
set => mag = value;
}
public TextureFilter FilterOnMinify
{
get => min;
set => min = value;
}
public TextureWrap WrapOnHorizontial
{
get => hori;
set => hori = value;
}
public TextureWrap WrapOnVertical
{
get => vert;
set => vert = value;
}
public override bool Equals(
[NotNullWhen(true)] object obj
)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return HashCode.Combine(FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial,
WrapOnVertical);
}
public override string ToString()
{
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
}
public static bool operator !=(
TextureProperty left,
TextureProperty right
)
{
return left.mask != right.mask;
}
public static bool operator ==(
TextureProperty left,
TextureProperty right
)
{
return left.mask == right.mask;
}
public static implicit operator TextureProperty(
(
TextureFilter onMagnify, TextureFilter onMinify,
TextureWrap onHorizontial, TextureWrap onVertical
) propertyValueTuple
)
{
return new TextureProperty(propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
propertyValueTuple.onHorizontial,
propertyValueTuple.onVertical);
}
public GlHandle this[int index] => Handles[index];
}
public readonly record struct TextureProperty(
TextureFilter FilterOnMagnify,
TextureFilter FilterOnMinify,
TextureWrap WrapOnHorizontal,
TextureWrap WrapOnVertical
);
#pragma warning disable CA1008
public enum TextureFilter
#pragma warning restore CA1008
@@ -272,9 +64,9 @@ namespace StgSharp.Graphics.OpenGL
}
#pragma warning disable CA1008
#pragma warning disable CA1008
public enum TextureWrap
#pragma warning restore CA1008
#pragma warning restore CA1008
{
Repeat = glConst.REPEAT,
+7 -52
View File
@@ -5,62 +5,17 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class VertexArray : GlBufferObjectBase
/// <summary>A set of OpenGL vertex-array handles.</summary>
public sealed record class VertexArray(
GlHandle[] Handles
)
{
internal VertexArray(
int n,
glRender binding
)
: base(binding)
{
_bufferHandle = GL.GenVertexArrays(n);
}
public int Count => Handles.Length;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public sealed override void Bind(
int index
)
{
GL.BindVertexArray(_bufferHandle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindNull()
{
OpenGLFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetVertexAttribute(
uint attributeIndex,
int vertexLength,
TypeCode dataType,
bool isNomalized,
int stride,
int pointer
)
{
GL.SetVertexAttribute(attributeIndex, vertexLength, dataType, isNomalized, stride,
pointer);
}
protected sealed override void Dispose(
bool disposing
)
{
if (disposing) {
GL.DeleteVertexArrays(_bufferHandle);
}
}
public GlHandle this[int index] => Handles[index];
}
}
}
+7 -147
View File
@@ -5,157 +5,17 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Mathematics;
using StgSharp.Mathematics.Numeric;
using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public sealed unsafe class VertexBuffer : GlBufferObjectBase
/// <summary>A set of OpenGL vertex-buffer handles.</summary>
public sealed record class VertexBuffer(
GlHandle[] Handles
)
{
internal VertexBuffer(
int n,
glRender binding
)
: base(binding)
{
_bufferHandle = GL.GenBuffers(n);
}
public int Count => Handles.Length;
public sealed override void Bind(
int index
)
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
}
/// <summary>
///
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unbind()
{
GL.BindBuffer(BufferType.ArrayBuffer, GlHandle.Zero);
}
/// <summary>
/// Set _data to current vertex BufferHandle object
/// </summary>
/// <typeparam _label="TItem">
/// Type of bufferData
/// </typeparam>
/// <param _label="index">
/// Index to find certain VBO in this instance
/// </param>
/// <param _label="bufferArray">
/// Data to write in
/// </param>
/// <param _label="usage">
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
/// </param>
public void WriteScalerData<T>(
int index,
T[] bufferArray,
BufferUsage usage
) where T : unmanaged, INumber<T>
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
}
/// <summary>
/// Set _data to current vertex BufferHandle object
/// </summary>
/// <typeparam _label="TItem">
/// Type of bufferData
/// </typeparam>
/// <param _label="index">
/// Index to find certain VBO in this instance
/// </param>
/// <param _label="scalerSpan">
/// A <see cref="Span{T}" /> of _data to write in
/// </param>
/// <param _label="usage">
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
/// </param>
public void WriteScalerData<T>(
int index,
ReadOnlySpan<T> scalerSpan,
BufferUsage usage
) where T : unmanaged,INumber<T>
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
}
/// <summary>
/// Set data to current vertex BufferHandle object
/// </summary>
/// <typeparam _label="TItem">
/// Type of bufferData
/// </typeparam>
/// <param _label="index">
/// Index to find certain VBO in this instance
/// </param>
/// <param _label="vectorSpan">
/// A <see cref="Span{T}" /> of data to write in
/// </param>
/// <param _label="usage">
/// How OpenGL use these data, defined by <see cref="BufferUsage" />
/// </param>
public void WriteVectorData<T>(
int index,
ReadOnlySpan<T> vectorSpan,
BufferUsage usage
) where T : unmanaged, IUnmanagedVector<T>
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
}
/// <summary>
/// Set _data to current vertex BufferHandle object
/// </summary>
/// <typeparam _label="TItem">
/// Type of bufferData
/// </typeparam>
/// <param _label="index">
/// Index to find certain VBO in this instance
/// </param>
/// <param _label="vectorArray">
/// A array of _data to write in
/// </param>
/// <param _label="usage">
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
/// </param>
public void WriteVectorData<T>(
int index,
T[] vectorArray,
BufferUsage usage
) where T : unmanaged, IUnmanagedVector<T>
{
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
}
protected sealed override void Dispose(
bool disposing
)
{
if (disposing) {
GL.DeleteBuffers(_bufferHandle);
}
}
public GlHandle this[int index] => Handles[index];
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,48 +0,0 @@
// -----------------------------------------------------------------------------
// file="IglConvertable"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp.Graphics.OpenGL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public interface IglConvertable
{
/// <summary>
///
/// </summary>
public void DisplayGLtypeDefinition();
/// <summary>
///
/// </summary>
public void GainAllUniforms(
ShaderProgram source,
params string[] uniformName
);
/// <summary>
///
/// </summary>
/// <returns>
///
/// </returns>
public ShaderStruct GetConvertedGLtype();
/// <summary>
///
/// </summary>
public void SetAllUniforms();
}
}
+19 -266
View File
@@ -5,163 +5,33 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using StgSharp;
using StgSharp.Graphics;
using StgSharp.Internal;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
namespace StgSharp.Graphics.OpenGL
{
public abstract partial class glRender : RenderStream
/// <summary>
/// A set of OpenGL shader handles with their common stage type.
/// </summary>
public sealed record Shader
{
/// <summary>
/// Create an instance of <see cref="Shader" /> program
/// </summary>
/// <returns>
/// New instance of <see cref="Shader" /> instance.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override ShaderProgram CreateShaderProgram()
{
return new ShaderProgram(this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override Shader CreateShaderSegment(
ShaderType type,
int count
public Shader(
GlHandle[] handles,
ShaderType type
)
{
return new Shader(GL.CreateShaderSet(count, type), type, this);
ArgumentNullException.ThrowIfNull(handles);
Handles = handles;
Type = type;
}
}
public int Count => Handles.Length;
public class Shader
{
public GlHandle[] Handles { get; }
private readonly OpenGLFunction GL;
internal readonly GlHandle[] handle;
public readonly ShaderType type;
public ShaderType Type { get; }
internal unsafe Shader(
GlHandle[] handle,
ShaderType usage,
glRender stream
)
{
this.handle = handle;
GL = stream.GL;
type = usage;
}
/// <summary>
/// Attach one shader code to a shader program.
/// </summary>
/// <param _label="target">
/// Shader program to attach
/// </param>
/// <param _label="index">
/// Index of shader code in current shader code set.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AttachTo(
int index,
[NotNull]ShaderProgram target
)
{
GL.AttachShader(target.handle, handle[index]);
}
public void CheckStatus(
int index,
ShaderStatus status
)
{
string log = GL.GetShaderStatus(this, index, (int)status);
if (!string.IsNullOrEmpty(log)) {
throw new InvalidOperationException($"{$"Shader Error \t{status}\n"}{log}");
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(
int index,
ReadOnlySpan<byte> codeU8Stream
)
{
GL.LoadShaderSource(handle[index], codeU8Stream);
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(
int index,
byte[] codeStream
)
{
ArgumentNullException.ThrowIfNull(codeStream);
GL.LoadShaderSource(handle[index], codeStream);
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(
int index,
string codeStream
)
{
ArgumentNullException.ThrowIfNull(codeStream);
GL.LoadShaderSource(handle[index], codeStream.AsSpan());
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
}
public void FromBytes(
byte[] stream
)
{
throw new NotImplementedException();
}
public static byte[] FromCodeFile(
string fileRoute
)
{
string str = File.ReadAllText(fileRoute);
if (string.IsNullOrEmpty(str)) {
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
}
return Encoding.UTF8.GetBytes(str);
}
public byte[] GetBytes()
{
return Array.Empty<byte>();
}
public byte[] GetBytes(
out int length
)
{
throw new NotImplementedException();
}
public override string ToString()
{
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
}
public GlHandle this[int index] => Handles[index];
}
@@ -172,125 +42,8 @@ namespace StgSharp.Graphics.OpenGL
}
public class ShaderProgram
{
private readonly OpenGLFunction GL;
internal readonly GlHandle handle;
/// <summary>
/// CustomizeInit a program with no shader attached.
/// </summary>
internal unsafe ShaderProgram(
glRender binding
)
{
GL = binding.GL;
handle = GL.CreateProgram();
}
/// <summary>
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param _label="name">
/// ContextName of the Uniform in shader code
/// </param>
/// <returns>
///
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe Uniform<T> GetUniform<T>(
string name
) where T : unmanaged
{
return new Uniform<T>(GL.GetUniformLocation(this.handle, name));
}
/// <summary>
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param _label="name">
/// ContextName of the Uniform in shader code
/// </param>
/// <returns>
///
/// </returns>
public unsafe Uniform<T, U> GetUniform<T, U>(
string name
) where T : unmanaged where U : struct
{
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
}
/// <summary>
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param _label="name">
/// ContextName of the Uniform in shader code
/// </param>
/// <returns>
///
/// </returns>
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(
string name
) where T : unmanaged where U : struct where V : struct
{
return new Uniform<T, U, V>(GL.GetUniformLocation(this.handle, name));
}
/// <summary>
/// Get a uniform form current shader, the value type of the uniform should be provided.
/// </summary>
/// <param _label="name">
/// ContextName of the Uniform in shader code
/// </param>
/// <returns>
///
/// </returns>
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(
string name
) where T : unmanaged where U : struct where V : struct where W : struct
{
return new Uniform<T, U, V, W>(GL.GetUniformLocation(this.handle, name));
}
/// <summary>
/// Link the shader to current viewPortDisplay.
/// </summary>
public unsafe void Link()
{
if (GraphicFramework.InternalLinkShaderProgram(
(OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
{
IntPtr logPtr = GraphicFramework.InternalReadSSCLog();
try
{
byte[] logByte = new byte[512];
Marshal.Copy(logPtr, logByte, 0, 512);
string log = Encoding.UTF8.GetString(logByte);
log = log.Replace("\0", string.Empty);
DefaultLog.InternalWriteLog(log, LogType.Error);
}
catch (Exception ex)
{
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
}
}
}
/// <summary>
/// Let the current viewPortDisplay use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
{
GL.UseProgram(handle);
}
~ShaderProgram()
{
// handle.Dispose();
}
}
}
/// <summary>
/// An OpenGL shader-program handle.
/// </summary>
public readonly record struct ShaderProgram(GlHandle Handle);
}
@@ -7,10 +7,17 @@
namespace StgSharp.Graphics.OpenGL
{
public class Uniform
public abstract class Uniform
{
internal GlHandle id;
internal readonly GlHandle id;
protected Uniform(
GlHandle handle
)
{
id = handle;
}
public GlHandle Handle => id;
@@ -19,48 +26,20 @@ namespace StgSharp.Graphics.OpenGL
public sealed class Uniform<T> : Uniform where T : unmanaged
{
internal Uniform() { }
internal unsafe Uniform(
GlHandle id
public Uniform(
GlHandle handle
)
{
this.id = id;
}
internal static Uniform<T> FromHandle(
GlHandle handle
)
{
return new Uniform<T>
{
id = handle
};
}
: base(handle) { }
}
public sealed class Uniform<T, U> : Uniform where T : unmanaged where U : struct
{
internal Uniform() { }
internal unsafe Uniform(
GlHandle id
public Uniform(
GlHandle handle
)
{
this.id = id;
}
internal static Uniform<T, U> FromHandle(
GlHandle handle
)
{
return new Uniform<T, U>
{
id = handle
};
}
: base(handle) { }
}
@@ -68,24 +47,10 @@ namespace StgSharp.Graphics.OpenGL
where V : struct
{
internal Uniform() { }
internal unsafe Uniform(
GlHandle id
public Uniform(
GlHandle handle
)
{
this.id = id;
}
internal static Uniform<T, U, V> FromHandle(
GlHandle handle
)
{
return new Uniform<T, U, V>
{
id = handle
};
}
: base(handle) { }
}
@@ -94,25 +59,10 @@ namespace StgSharp.Graphics.OpenGL
where W : struct
{
internal Uniform() { }
internal unsafe Uniform(
GlHandle id
public Uniform(
GlHandle handle
)
{
this.id = id;
}
internal static Uniform<T, U, V, W> FromHandle(
GlHandle handle
)
{
return new Uniform<T, U, V, W>
{
id = handle
};
}
: base(handle) { }
}
}
@@ -1,665 +0,0 @@
// -----------------------------------------------------------------------------
// file="glApiManager.Const"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
public static partial class glManager
{
#region coreVersion
private static bool core10 = false;
private static bool core11 = false;
private static bool core12 = false;
private static bool core13 = false;
private static bool core14 = false;
private static bool core15 = false;
private static bool core20 = false;
private static bool core21 = false;
private static bool core30 = false;
private static bool core31 = false;
private static bool core32 = false;
private static bool core33 = false;
private static bool core40 = false;
private static bool core41 = false;
private static bool core42 = false;
private static bool core43 = false;
private static bool core44 = false;
private static bool core45 = false;
private static bool core46 = false;
#endregion
#region extension
private static bool _3DFX_tbuffer;
private static bool _3DFX_texture_compression_FXT1;
private static bool _4DFX_multisample;
private static bool AMD_blend_minmax_factor;
private static bool AMD_conservative_depth;
private static bool AMD_debug_output;
private static bool AMD_depth_clamp_separate;
private static bool AMD_draw_buffers_blend;
private static bool AMD_framebuffer_multisample_advanced;
private static bool AMD_framebuffer_sample_positions;
private static bool AMD_gcn_shader;
private static bool AMD_gpu_shader_half_float;
private static bool AMD_gpu_shader_int16;
private static bool AMD_gpu_shader_int64;
private static bool AMD_interleaved_elements;
private static bool AMD_multi_draw_indirect;
private static bool AMD_name_gen_delete;
private static bool AMD_occlusion_query_event;
private static bool AMD_performance_monitor;
private static bool AMD_pinned_memory;
private static bool AMD_query_buffer_object;
private static bool AMD_sample_positions;
private static bool AMD_seamless_cubemap_per_texture;
private static bool AMD_shader_atomic_counter_ops;
private static bool AMD_shader_ballot;
private static bool AMD_shader_explicit_vertex_parameter;
private static bool AMD_shader_gpu_shader_half_float_fetch;
private static bool AMD_shader_image_load_store_lod;
private static bool AMD_shader_stencil_export;
private static bool AMD_shader_trinary_minmax;
private static bool AMD_sparse_texture;
private static bool AMD_stencil_operation_extended;
private static bool AMD_texture_gather_bias_lod;
private static bool AMD_texture_texture4;
private static bool AMD_transform_feedback3_lines_triangles;
private static bool AMD_transform_feedback4;
private static bool AMD_vertex_shader_layer;
private static bool AMD_vertex_shader_tessellator;
private static bool AMD_vertex_shader_viewport_index;
private static bool APPLE_aux_depth_stencil;
private static bool APPLE_client_storage;
private static bool APPLE_element_array;
private static bool APPLE_fence;
private static bool APPLE_float_pixels;
private static bool APPLE_flush_buffer_range;
private static bool APPLE_object_purgeable;
private static bool APPLE_rgb_422;
private static bool APPLE_row_bytes;
private static bool APPLE_specular_vector;
private static bool APPLE_texture_range;
private static bool APPLE_transform_hint;
private static bool APPLE_vertex_array_object;
private static bool APPLE_vertex_array_range;
private static bool APPLE_vertex_program_evaluators;
private static bool APPLE_ycbcr_422;
private static bool ARB_arrays_of_arrays;
private static bool ARB_base_instance;
private static bool ARB_bindless_texture;
private static bool ARB_blend_func_extended;
private static bool ARB_buffer_storage;
private static bool ARB_cl_event;
private static bool ARB_clear_buffer_object;
private static bool ARB_clear_texture;
private static bool ARB_clip_control;
private static bool ARB_color_buffer_float;
private static bool ARB_compatibility;
private static bool ARB_compressed_texture_pixel_storage;
private static bool ARB_compute_shader;
private static bool ARB_compute_variable_group_size;
private static bool ARB_conditional_render_inverted;
private static bool ARB_conservative_depth;
private static bool ARB_copy_buffer;
private static bool ARB_copy_image;
private static bool ARB_cull_distance;
private static bool ARB_debug_output;
private static bool ARB_depth_buffer_float;
private static bool ARB_depth_clamp;
private static bool ARB_depth_texture;
private static bool ARB_derivative_control;
private static bool ARB_direct_state_access;
private static bool ARB_draw_buffers;
private static bool ARB_draw_buffers_blend;
private static bool ARB_draw_elements_base_vertex;
private static bool ARB_draw_indirect;
private static bool ARB_draw_instanced;
private static bool ARB_enhanced_layouts;
private static bool ARB_ES2_compatibility;
private static bool ARB_ES3_1_compatibility;
private static bool ARB_ES3_2_compatibility;
private static bool ARB_ES3_compatibility;
private static bool ARB_explicit_attrib_location;
private static bool ARB_explicit_uniform_location;
private static bool ARB_fragment_coord_conventions;
private static bool ARB_fragment_layer_viewport;
private static bool ARB_fragment_program;
private static bool ARB_fragment_program_shadow;
private static bool ARB_fragment_shader;
private static bool ARB_fragment_shader_interlock;
private static bool ARB_framebuffer_no_attachments;
private static bool ARB_framebuffer_object;
private static bool ARB_framebuffer_sRGB;
private static bool ARB_geometry_shader4;
private static bool ARB_get_program_binary;
private static bool ARB_get_texture_sub_image;
private static bool ARB_gl_spirv;
private static bool ARB_gpu_shader_fp64;
private static bool ARB_gpu_shader_int64;
private static bool ARB_gpu_shader5;
private static bool ARB_half_float_pixel;
private static bool ARB_half_float_vertex;
private static bool ARB_imaging;
private static bool ARB_indirect_parameters;
private static bool ARB_instanced_arrays;
private static bool ARB_internalformat_query;
private static bool ARB_internalformat_query2;
private static bool ARB_invalidate_subdata;
private static bool ARB_map_buffer_alignment;
private static bool ARB_map_buffer_range;
private static bool ARB_matrix_palette;
private static bool ARB_multi_bind;
private static bool ARB_multi_draw_indirect;
private static bool ARB_multisample;
private static bool ARB_multitexture;
private static bool ARB_occlusion_query;
private static bool ARB_occlusion_query2;
private static bool ARB_parallel_shader_compile;
private static bool ARB_pipeline_statistics_query;
private static bool ARB_pixel_buffer_object;
private static bool ARB_point_parameters;
private static bool ARB_point_sprite;
private static bool ARB_polygon_offset_clamp;
private static bool ARB_post_depth_coverage;
private static bool ARB_program_interface_query;
private static bool ARB_provoking_vertex;
private static bool ARB_query_buffer_object;
private static bool ARB_robust_buffer_access_behavior;
private static bool ARB_robustness;
private static bool ARB_robustness_isolation;
private static bool ARB_sample_locations;
private static bool ARB_sample_shading;
private static bool ARB_sampler_objects;
private static bool ARB_seamless_cube_map;
private static bool ARB_seamless_cubemap_per_texture;
private static bool ARB_separate_shader_objects;
private static bool ARB_shader_atomic_counter_ops;
private static bool ARB_shader_atomic_counters;
private static bool ARB_shader_ballot;
private static bool ARB_shader_bit_encoding;
private static bool ARB_shader_clock;
private static bool ARB_shader_draw_parameters;
private static bool ARB_shader_group_vote;
private static bool ARB_shader_image_load_store;
private static bool ARB_shader_image_size;
private static bool ARB_shader_objects;
private static bool ARB_shader_precision;
private static bool ARB_shader_stencil_export;
private static bool ARB_shader_storage_buffer_object;
private static bool ARB_shader_subroutine;
private static bool ARB_shader_texture_image_samples;
private static bool ARB_shader_texture_lod;
private static bool ARB_shader_viewport_layer_array;
private static bool ARB_shading_language_100;
private static bool ARB_shading_language_420pack;
private static bool ARB_shading_language_include;
private static bool ARB_shading_language_packing;
private static bool ARB_shadow;
private static bool ARB_shadow_ambient;
private static bool ARB_sparse_buffer;
private static bool ARB_sparse_texture;
private static bool ARB_sparse_texture_clamp;
private static bool ARB_sparse_texture2;
private static bool ARB_spirv_extensions;
private static bool ARB_stencil_texturing;
private static bool ARB_sync;
private static bool ARB_tessellation_shader;
private static bool ARB_texture_barrier;
private static bool ARB_texture_border_clamp;
private static bool ARB_texture_buffer_object;
private static bool ARB_texture_buffer_object_rgb32;
private static bool ARB_texture_buffer_range;
private static bool ARB_texture_compression;
private static bool ARB_texture_compression_bptc;
private static bool ARB_texture_compression_rgtc;
private static bool ARB_texture_cube_map;
private static bool ARB_texture_cube_map_array;
private static bool ARB_texture_env_add;
private static bool ARB_texture_env_combine;
private static bool ARB_texture_env_crossbar;
private static bool ARB_texture_env_dot3;
private static bool ARB_texture_filter_anisotropic;
private static bool ARB_texture_filter_minmax;
private static bool ARB_texture_float;
private static bool ARB_texture_gather;
private static bool ARB_texture_mirror_clamp_to_edge;
private static bool ARB_texture_mirrored_repeat;
private static bool ARB_texture_multisample;
private static bool ARB_texture_non_power_of_two;
private static bool ARB_texture_query_levels;
private static bool ARB_texture_query_lod;
private static bool ARB_texture_rectangle;
private static bool ARB_texture_rg;
private static bool ARB_texture_rgb10_a2ui;
private static bool ARB_texture_stencil8;
private static bool ARB_texture_storage;
private static bool ARB_texture_storage_multisample;
private static bool ARB_texture_swizzle;
private static bool ARB_texture_view;
private static bool ARB_timer_query;
private static bool ARB_transform_feedback_instanced;
private static bool ARB_transform_feedback_overflow_query;
private static bool ARB_transform_feedback2;
private static bool ARB_transform_feedback3;
private static bool ARB_transpose_matrix;
private static bool ARB_uniform_buffer_object;
private static bool ARB_vertex_array_bgra;
private static bool ARB_vertex_array_object;
private static bool ARB_vertex_attrib_64bit;
private static bool ARB_vertex_attrib_binding;
private static bool ARB_vertex_blend;
private static bool ARB_vertex_buffer_object;
private static bool ARB_vertex_program;
private static bool ARB_vertex_shader;
private static bool ARB_vertex_type_10f_11f_11f_rev;
private static bool ARB_vertex_type_2_10_10_10_rev;
private static bool ARB_viewport_array;
private static bool ARB_window_pos;
private static bool ATI_draw_buffers;
private static bool ATI_element_array;
private static bool ATI_envmap_bumpmap;
private static bool ATI_fragment_shader;
private static bool ATI_map_object_buffer;
private static bool ATI_meminfo;
private static bool ATI_pixel_format_float;
private static bool ATI_pn_triangles;
private static bool ATI_separate_stencil;
private static bool ATI_text_fragment_shader;
private static bool ATI_texture_env_combine3;
private static bool ATI_texture_float;
private static bool ATI_texture_mirror_once;
private static bool ATI_vertex_array_object;
private static bool ATI_vertex_attrib_array_object;
private static bool ATI_vertex_streams;
private static bool EXT_422_pixels;
private static bool EXT_abgr;
private static bool EXT_bgra;
private static bool EXT_bindable_uniform;
private static bool EXT_blend_color;
private static bool EXT_blend_equation_separate;
private static bool EXT_blend_func_separate;
private static bool EXT_blend_logic_op;
private static bool EXT_blend_minmax;
private static bool EXT_blend_subtract;
private static bool EXT_clip_volume_hint;
private static bool EXT_cmyka;
private static bool EXT_color_subtable;
private static bool EXT_compiled_vertex_array;
private static bool EXT_convolution;
private static bool EXT_coordinate_frame;
private static bool EXT_copy_texture;
private static bool EXT_cull_vertex;
private static bool EXT_debug_label;
private static bool EXT_debug_marker;
private static bool EXT_depth_bounds_test;
private static bool EXT_direct_state_access;
private static bool EXT_draw_buffers2;
private static bool EXT_draw_instanced;
private static bool EXT_draw_range_elements;
private static bool EXT_EGL_image_storage;
private static bool EXT_EGL_sync;
private static bool EXT_external_buffer;
private static bool EXT_fog_coord;
private static bool EXT_framebuffer_blit;
private static bool EXT_framebuffer_blit_layers;
private static bool EXT_framebuffer_multisample;
private static bool EXT_framebuffer_multisample_blit_scaled;
private static bool EXT_framebuffer_object;
private static bool EXT_framebuffer_sRGB;
private static bool EXT_geometry_shader4;
private static bool EXT_gpu_program_parameters;
private static bool EXT_gpu_shader4;
private static bool EXT_histogram;
private static bool EXT_index_array_formats;
private static bool EXT_index_func;
private static bool EXT_index_material;
private static bool EXT_index_texture;
private static bool EXT_light_texture;
private static bool EXT_memory_object;
private static bool EXT_memory_object_fd;
private static bool EXT_memory_object_win32;
private static bool EXT_misc_attribute;
private static bool EXT_multi_draw_arrays;
private static bool EXT_multisample;
private static bool EXT_multiview_tessellation_geometry_shader;
private static bool EXT_multiview_texture_multisample;
private static bool EXT_multiview_timer_query;
private static bool EXT_packed_depth_stencil;
private static bool EXT_packed_float;
private static bool EXT_packed_pixels;
private static bool EXT_paletted_texture;
private static bool EXT_pixel_buffer_object;
private static bool EXT_pixel_transform;
private static bool EXT_pixel_transform_color_table;
private static bool EXT_point_parameters;
private static bool EXT_polygon_offset;
private static bool EXT_polygon_offset_clamp;
private static bool EXT_post_depth_coverage;
private static bool EXT_provoking_vertex;
private static bool EXT_raster_multisample;
private static bool EXT_rescale_normal;
private static bool EXT_secondary_color;
private static bool EXT_semaphore;
private static bool EXT_semaphore_fd;
private static bool EXT_semaphore_win32;
private static bool EXT_separate_shader_objects;
private static bool EXT_separate_specular_color;
private static bool EXT_shader_framebuffer_fetch;
private static bool EXT_shader_framebuffer_fetch_non_coherent;
private static bool EXT_shader_image_load_formatted;
private static bool EXT_shader_image_load_store;
private static bool EXT_shader_integer_mix;
private static bool EXT_shader_samples_identical;
private static bool EXT_shadow_funcs;
private static bool EXT_shared_texture_palette;
private static bool EXT_sparse_texture2;
private static bool EXT_stencil_clear_tag;
private static bool EXT_stencil_two_side;
private static bool EXT_stencil_wrap;
private static bool EXT_subtexture;
private static bool EXT_texture;
private static bool EXT_texture_array;
private static bool EXT_texture_buffer_object;
private static bool EXT_texture_compression_latc;
private static bool EXT_texture_compression_rgtc;
private static bool EXT_texture_compression_s3tc;
private static bool EXT_texture_cube_map;
private static bool EXT_texture_env_add;
private static bool EXT_texture_env_combine;
private static bool EXT_texture_env_dot3;
private static bool EXT_texture_filter_anisotropic;
private static bool EXT_texture_filter_minmax;
private static bool EXT_texture_integer;
private static bool EXT_texture_lod_bias;
private static bool EXT_texture_mirror_clamp;
private static bool EXT_texture_object;
private static bool EXT_texture_perturb_normal;
private static bool EXT_texture_shadow_lod;
private static bool EXT_texture_shared_exponent;
private static bool EXT_texture_snorm;
private static bool EXT_texture_sRGB;
private static bool EXT_texture_sRGB_decode;
private static bool EXT_texture_sRGB_R8;
private static bool EXT_texture_sRGB_RG8;
private static bool EXT_texture_storage;
private static bool EXT_texture_swizzle;
private static bool EXT_texture3D;
private static bool EXT_timer_query;
private static bool EXT_transform_feedback;
private static bool EXT_vertex_array;
private static bool EXT_vertex_array_bgra;
private static bool EXT_vertex_attrib_64bit;
private static bool EXT_vertex_shader;
private static bool EXT_vertex_weighting;
private static bool EXT_win32_keyed_mutex;
private static bool EXT_window_rectangles;
private static bool EXT_x11_sync_object;
private static bool GREMEDY_frame_terminator;
private static bool GREMEDY_string_marker;
private static bool HP_convolution_border_modes;
private static bool HP_image_transform;
private static bool HP_occlusion_test;
private static bool HP_texture_lighting;
private static bool IBM_cull_vertex;
private static bool IBM_multimode_draw_arrays;
private static bool IBM_rasterpos_clip;
private static bool IBM_static_data;
private static bool IBM_texture_mirrored_repeat;
private static bool IBM_vertex_array_lists;
private static bool INGR_blend_func_separate;
private static bool INGR_color_clamp;
private static bool INGR_interlace_read;
private static bool INTEL_blackhole_render;
private static bool INTEL_conservative_rasterization;
private static bool INTEL_fragment_shader_ordering;
private static bool INTEL_framebuffer_CMAA;
private static bool INTEL_map_texture;
private static bool INTEL_parallel_arrays;
private static bool INTEL_performance_query;
private static bool KHR_blend_equation_advanced;
private static bool KHR_blend_equation_advanced_coherent;
private static bool KHR_context_flush_control;
private static bool KHR_debug;
private static bool KHR_no_error;
private static bool KHR_parallel_shader_compile;
private static bool KHR_robust_buffer_access_behavior;
private static bool KHR_robustness;
private static bool KHR_shader_subgroup;
private static bool KHR_texture_compression_astc_hdr;
private static bool KHR_texture_compression_astc_ldr;
private static bool KHR_texture_compression_astc_sliced_3d;
private static bool MESA_framebuffer_flip_x;
private static bool MESA_framebuffer_flip_y;
private static bool MESA_framebuffer_swap_xy;
private static bool MESA_pack_invert;
private static bool MESA_program_binary_formats;
private static bool MESA_resize_buffers;
private static bool MESA_shader_integer_functions;
private static bool MESA_tile_raster_order;
private static bool MESA_window_pos;
private static bool MESA_ycbcr_texture;
private static bool MESAX_texture_stack;
private static bool NV_alpha_to_coverage_dither_control;
private static bool NV_bindless_multi_draw_indirect;
private static bool NV_bindless_multi_draw_indirect_count;
private static bool NV_bindless_texture;
private static bool NV_blend_equation_advanced;
private static bool NV_blend_equation_advanced_coherent;
private static bool NV_blend_minmax_factor;
private static bool NV_blend_square;
private static bool NV_clip_space_w_scaling;
private static bool NV_command_list;
private static bool NV_compute_program5;
private static bool NV_compute_shader_derivatives;
private static bool NV_conditional_render;
private static bool NV_conservative_raster;
private static bool NV_conservative_raster_dilate;
private static bool NV_conservative_raster_pre_snap;
private static bool NV_conservative_raster_pre_snap_triangles;
private static bool NV_conservative_raster_underestimation;
private static bool NV_copy_depth_to_color;
private static bool NV_copy_image;
private static bool NV_deep_texture3D;
private static bool NV_depth_buffer_float;
private static bool NV_depth_clamp;
private static bool NV_draw_texture;
private static bool NV_draw_vulkan_image;
private static bool NV_evaluators;
private static bool NV_explicit_multisample;
private static bool NV_fence;
private static bool NV_fill_rectangle;
private static bool NV_float_buffer;
private static bool NV_fog_distance;
private static bool NV_fragment_coverage_to_color;
private static bool NV_fragment_program;
private static bool NV_fragment_program_option;
private static bool NV_fragment_program2;
private static bool NV_fragment_program4;
private static bool NV_fragment_shader_barycentric;
private static bool NV_fragment_shader_interlock;
private static bool NV_framebuffer_mixed_samples;
private static bool NV_framebuffer_multisample_coverage;
private static bool NV_geometry_program4;
private static bool NV_geometry_shader_passthrough;
private static bool NV_geometry_shader4;
private static bool NV_gpu_multicast;
private static bool NV_gpu_program4;
private static bool NV_gpu_program5;
private static bool NV_gpu_program5_mem_extended;
private static bool NV_gpu_shader5;
private static bool NV_half_float;
private static bool NV_internalformat_sample_query;
private static bool NV_light_max_exponent;
private static bool NV_memory_attachment;
private static bool NV_memory_object_sparse;
private static bool NV_mesh_shader;
private static bool NV_multisample_coverage;
private static bool NV_multisample_filter_hint;
private static bool NV_occlusion_query;
private static bool NV_packed_depth_stencil;
private static bool NV_parameter_buffer_object;
private static bool NV_parameter_buffer_object2;
private static bool NV_path_rendering;
private static bool NV_path_rendering_shared_edge;
private static bool NV_pixel_data_range;
private static bool NV_point_sprite;
private static bool NV_present_video;
private static bool NV_primitive_restart;
private static bool NV_primitive_shading_rate;
private static bool NV_query_resource;
private static bool NV_query_resource_tag;
private static bool NV_register_combiners;
private static bool NV_register_combiners2;
private static bool NV_representative_fragment_test;
private static bool NV_robustness_video_memory_purge;
private static bool NV_sample_locations;
private static bool NV_sample_mask_override_coverage;
private static bool NV_scissor_exclusive;
private static bool NV_shader_atomic_counters;
private static bool NV_shader_atomic_float;
private static bool NV_shader_atomic_float64;
private static bool NV_shader_atomic_fp16_vector;
private static bool NV_shader_atomic_int64;
private static bool NV_shader_buffer_load;
private static bool NV_shader_buffer_store;
private static bool NV_shader_storage_buffer_object;
private static bool NV_shader_subgroup_partitioned;
private static bool NV_shader_texture_footprint;
private static bool NV_shader_thread_group;
private static bool NV_shader_thread_shuffle;
private static bool NV_shading_rate_image;
private static bool NV_stereo_view_rendering;
private static bool NV_tessellation_program5;
private static bool NV_texgen_emboss;
private static bool NV_texgen_reflection;
private static bool NV_texture_barrier;
private static bool NV_texture_compression_vtc;
private static bool NV_texture_env_combine4;
private static bool NV_texture_expand_normal;
private static bool NV_texture_multisample;
private static bool NV_texture_rectangle;
private static bool NV_texture_rectangle_compressed;
private static bool NV_texture_shader;
private static bool NV_texture_shader2;
private static bool NV_texture_shader3;
private static bool NV_timeline_semaphore;
private static bool NV_transform_feedback;
private static bool NV_transform_feedback2;
private static bool NV_uniform_buffer_std430_layout;
private static bool NV_uniform_buffer_unified_memory;
private static bool NV_vdpau_interop;
private static bool NV_vdpau_interop2;
private static bool NV_vertex_array_range;
private static bool NV_vertex_array_range2;
private static bool NV_vertex_attrib_integer_64bit;
private static bool NV_vertex_buffer_unified_memory;
private static bool NV_vertex_program;
private static bool NV_vertex_program1_1;
private static bool NV_vertex_program2;
private static bool NV_vertex_program2_option;
private static bool NV_vertex_program3;
private static bool NV_vertex_program4;
private static bool NV_video_capture;
private static bool NV_viewport_array2;
private static bool NV_viewport_swizzle;
private static bool NVX_blend_equation_advanced_multi_draw_buffers;
private static bool NVX_conditional_render;
private static bool NVX_gpu_memory_info;
private static bool NVX_gpu_multicast2;
private static bool NVX_linked_gpu_multicast;
private static bool NVX_progress_fence;
private static bool OES_byte_coordinates;
private static bool OES_compressed_paletted_texture;
private static bool OES_fixed_point;
private static bool OES_query_matrix;
private static bool OES_read_format;
private static bool OES_single_precision;
private static bool OML_interlace;
private static bool OML_resample;
private static bool OML_subsample;
private static bool OVR_multiview;
private static bool OVR_multiview2;
private static bool PGI_misc_hints;
private static bool PGI_vertex_hints;
private static bool REND_screen_coordinates;
private static bool S3_s3tc;
private static bool SGI_color_matrix;
private static bool SGI_color_table;
private static bool SGI_texture_color_table;
private static bool SGIS_detail_texture;
private static bool SGIS_fog_function;
private static bool SGIS_generate_mipmap;
private static bool SGIS_multisample;
private static bool SGIS_pixel_texture;
private static bool SGIS_point_line_texgen;
private static bool SGIS_point_parameters;
private static bool SGIS_sharpen_texture;
private static bool SGIS_texture_border_clamp;
private static bool SGIS_texture_color_mask;
private static bool SGIS_texture_edge_clamp;
private static bool SGIS_texture_filter4;
private static bool SGIS_texture_lod;
private static bool SGIS_texture_select;
private static bool SGIS_texture4D;
private static bool SGIX_async;
private static bool SGIX_async_histogram;
private static bool SGIX_async_pixel;
private static bool SGIX_blend_alpha_minmax;
private static bool SGIX_calligraphic_fragment;
private static bool SGIX_clipmap;
private static bool SGIX_convolution_accuracy;
private static bool SGIX_depth_pass_instrument;
private static bool SGIX_depth_texture;
private static bool SGIX_flush_raster;
private static bool SGIX_fog_offset;
private static bool SGIX_fragment_lighting;
private static bool SGIX_framezoom;
private static bool SGIX_igloo_interface;
private static bool SGIX_instruments;
private static bool SGIX_interlace;
private static bool SGIX_ir_instrument1;
private static bool SGIX_list_priority;
private static bool SGIX_pixel_texture;
private static bool SGIX_pixel_tiles;
private static bool SGIX_polynomial_ffd;
private static bool SGIX_reference_plane;
private static bool SGIX_resample;
private static bool SGIX_scalebias_hint;
private static bool SGIX_shadow;
private static bool SGIX_shadow_ambient;
private static bool SGIX_sprite;
private static bool SGIX_subsample;
private static bool SGIX_tag_sample_buffer;
private static bool SGIX_texture_add_env;
private static bool SGIX_texture_coordinate_clamp;
private static bool SGIX_texture_lod_bias;
private static bool SGIX_texture_multi_buffer;
private static bool SGIX_texture_scale_bias;
private static bool SGIX_vertex_preclip;
private static bool SGIX_ycrcb;
private static bool SGIX_ycrcb_subsample;
private static bool SGIX_ycrcba;
private static bool SUN_convolution_border_modes;
private static bool SUN_global_alpha;
private static bool SUN_mesh_array;
private static bool SUN_slice_accum;
private static bool SUN_triangle_list;
private static bool SUN_vertex;
private static bool SUNX_constant_data;
private static bool WIN_phong_shading;
private static bool WIN_specular_fog;
#endregion
}
}
File diff suppressed because it is too large Load Diff
+1 -6
View File
@@ -4532,12 +4532,7 @@ namespace StgSharp.Graphics.OpenGL
int i
)
{
#if DEBUG
if ((i > OpenGLFunction.CurrentGL.AttachmentColorRange) || (i < 0))
{
throw new ArgumentOutOfRangeException();
}
#endif
ArgumentOutOfRangeException.ThrowIfNegative(i);
return (uint)(glConst.COLOR_ATTACHMENT0 + i);
}
@@ -6,12 +6,6 @@
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
@@ -37,65 +31,4 @@ namespace StgSharp.Graphics.OpenGL
}
public sealed class GlArrayFormatException : Exception
{
internal GlArrayFormatException(
string message
)
: base(message) { }
internal GlArrayFormatException(
SerializationInfo info,
StreamingContext context
)
: base(info, context) { }
internal GlArrayFormatException(
string message,
Exception innerException
)
: base(message, innerException) { }
public GlArrayFormatException(
PixelChannelLayout layout,
string arrayname
)
: base($"{arrayname} cannot be used as layout of {layout}") { }
}
public static partial class GlHelper
{
public static bool CheckArrayFormat(
this Array array,
PixelChannelLayout layout
)
{
return layout switch
{
PixelChannelLayout.Byte or PixelChannelLayout.UByte332 or PixelChannelLayout.UByte233Rev => (array is byte[]) ||
(array is sbyte[]),
PixelChannelLayout.Short => array is short[],
PixelChannelLayout.UShort => array is ushort[],
PixelChannelLayout.Int => array is int[],
PixelChannelLayout.Float => array is float[],
PixelChannelLayout.UShort4444 => (array is ushort[]) || (array is byte[]),
PixelChannelLayout.UByte => (array is byte[]) || (array is sbyte[]),
PixelChannelLayout.UInt => array is uint[],
PixelChannelLayout.UShort565 or
PixelChannelLayout.UShort565Rev or
PixelChannelLayout.UShort4444Rev or
PixelChannelLayout.UShort5551 or
PixelChannelLayout.UShort1555Rev => array is ushort[],
PixelChannelLayout.UInt8888Rev or
PixelChannelLayout.UInt1010102 or
PixelChannelLayout.UInt2101010Rev => array is int[],
PixelChannelLayout.UInt8888 => array is uint[] or byte[],
_ => false,
};
}
}
}
@@ -1,114 +0,0 @@
// -----------------------------------------------------------------------------
// file="glRenderObjectGenrator"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
public partial class glRender
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected AutoTextureGL CreateAutoTexture(
int count
)
{
return new AutoTextureGL(count, this);
}
/// <summary>
/// Create a set of <see cref="ElementBuffer" />.
/// </summary>
/// <param _label="count">
/// Amount of EBO to be created.
/// </param>
/// <returns>
///
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected ElementBuffer CreateElementBuffer(
int count
)
{
return new ElementBuffer(count, this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected FrameBuffer CreateFrameBuffer(
int count
)
{
return new FrameBuffer(count, this);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected RenderBuffer CreateRenderBuffer(
int count
)
{
return new RenderBuffer(count, this);
}
/// <summary>
/// Create a sets of <see cref="TextureGL" />
/// </summary>
/// <param _label="count">
/// Amount of textures to be created.
/// </param>
/// <returns>
///
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected TextureGL CreateTexture(
int count
)
{
return new TextureGL(count, this);
}
/// <summary>
/// Create a set of <see cref="VertexArray" />.
/// </summary>
/// <param _label="count">
/// Amount of VAO to be created.
/// </param>
/// <returns>
///
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(
int count
)
{
return new VertexArray(count, this);
}
/// <summary>
/// Create a set of <see cref="VertexBuffer" />.
/// </summary>
/// <param _label="count">
/// Amount of Object to be created.
/// </param>
/// <returns>
///
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexBuffer CreateVertexBuffer(
int count
)
{
return new VertexBuffer(count, this);
}
}
}
@@ -1,26 +0,0 @@
// -----------------------------------------------------------------------------
// file="glRenderStream.ThreadSecurity"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics.OpenGL
{
public partial class glRender
{
private static ConcurrentDictionary<Thread, glRender> threadLocalIndex
= new();
private readonly SynchronizationContext mainThreadContext = SynchronizationContext.Current;
}
}
@@ -117,15 +117,6 @@ namespace StgSharp.Graphics.OpenGL
CustomizeDeinit();
}
protected sealed override Uniform<GraphicsMatrix> NativeCameraUniform(
ShaderProgram source,
string name
)
{
NativeCamera.GainAllUniforms(source, name);
return NativeCamera.convertedUniform;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected sealed override void NativeCameraViewRange(
Radius fieldOfRange,
+20
View File
@@ -0,0 +1,20 @@
// -----------------------------------------------------------------------------
// file="glSync"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics.OpenGL
{
[StructLayout(LayoutKind.Sequential)]
public struct glSync
{
public IntPtr Handle;
}
}
-91
View File
@@ -1,91 +0,0 @@
// -----------------------------------------------------------------------------
// file="glType"
// Project: StgSharp
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphics.OpenGL
{
internal delegate void GLVULKANPROCNV();
public unsafe struct glHandleARB(
IntPtr value
) { }
/// <summary>
/// OpenGL numeric type. An IEEE-754 floating-point value, clamped to the range [0,1].
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct GlClampF
{
public float value;
public GlClampF(
float a
)
{
value = a;
}
}
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct glHalfNv(
Half bin
)
{
[FieldOffset(0)] public Half binary = bin;
public float ToSingle()
{
return (float)binary;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct glSync
{
public IntPtr Handle;
}
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct GlFixed
{
[FieldOffset(0)] public int All;
[FieldOffset(0)] public short Decimals;
[FieldOffset(4)] public short Integer;
}
/// <summary>
/// OpenGL numeric type. An IEEE-754 double precision floating-point value, clamped to the
/// range [0,1].
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct GlClampD
{
public double value;
public GlClampD(
double a
)
{
value = a;
}
}
}