daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -58,22 +58,24 @@ namespace StgSharp
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
|
||||
|
||||
public unsafe partial class GlFunction
|
||||
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private static Dictionary<IntPtr, GlFunction> contextToGLMap = new Dictionary<IntPtr, GlFunction>();
|
||||
private static Dictionary<IntPtr, OpenGLFunction> contextToGLMap = new Dictionary<IntPtr, OpenGLFunction>();
|
||||
private OpenglContext* _context;
|
||||
|
||||
private GlFunction()
|
||||
private OpenGLFunction()
|
||||
{
|
||||
textureUnitCountGetter = new Lazy<int>(() => GetMaskInteger(GLconst.MAX_TEXTURE_IMAGE_UNITS));
|
||||
unusedTextureImageUintInitilizing = new Lazy<ConcurrentQueue<TextureUnit>>(InitializeUnusedTextureImageUint);
|
||||
}
|
||||
|
||||
internal static GlFunction CurrentGL { get; set; }
|
||||
|
||||
internal IntPtr ContextHandle => (IntPtr)_context;
|
||||
|
||||
internal static OpenGLFunction CurrentGL { get; set; }
|
||||
|
||||
protected ref OpenglContext Context
|
||||
{
|
||||
get
|
||||
@@ -89,11 +91,32 @@ namespace StgSharp.Graphics.OpenGL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ActiveTexture(uint type)
|
||||
public void ActiveTextureUnit(uint type)
|
||||
{
|
||||
Context.glActiveTexture(type);
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void Assert(bool shouldReportWhenNormal)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint code = Context.glGetError();
|
||||
if (code != GLconst.NO_ERROR)
|
||||
{
|
||||
throw new GlExecutionException(code);
|
||||
}
|
||||
if (shouldReportWhenNormal)
|
||||
{
|
||||
Console.WriteLine("OpenGL runs normally");
|
||||
}
|
||||
}
|
||||
catch (GlExecutionException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachShader(GlHandle program, GlHandle shader)
|
||||
{
|
||||
@@ -108,7 +131,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
|
||||
/// <summary>
|
||||
/// Bind a frame buffer to a frame buffer target
|
||||
/// Same function as <see href="https://docs.GL/gl3/glBindFramebuffer">glBindFramebuffer</see>.
|
||||
/// Same function as <see href="https://docs._gl/gl3/glBindFramebuffer">glBindFramebuffer</see>.
|
||||
/// </summary>
|
||||
/// <param name="target"> The frame buffer target of the binding operation.</param>
|
||||
/// <param name="handle"> The handle of the frame buffer object to bind.</param>
|
||||
@@ -160,33 +183,6 @@ namespace StgSharp.Graphics.OpenGL
|
||||
while (Context.glGetError() != 0) { }
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void Assert(bool shouldReportWhenNormal)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint code = Context.glGetError();
|
||||
if (code != GLconst.NO_ERROR)
|
||||
{
|
||||
throw new GlExecutionException(code);
|
||||
}
|
||||
if (shouldReportWhenNormal)
|
||||
{
|
||||
Console.WriteLine("OpenGL runs normally");
|
||||
}
|
||||
}
|
||||
catch (GlExecutionException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GenerateMipmap(Texture2DTarget target)
|
||||
{
|
||||
Context.glGenerateMipmap((uint)target);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void ClearGraphicError()
|
||||
{
|
||||
@@ -292,7 +288,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
TypeCode.UInt16 => GLconst.UNSIGNED_SHORT,
|
||||
TypeCode.Byte => GLconst.UNSIGNED_BYTE,
|
||||
_ => throw new ArgumentException(
|
||||
$"{($"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}")}{($"{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}")}")
|
||||
$"{$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}"}{$"{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}"}")
|
||||
};
|
||||
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
|
||||
}
|
||||
@@ -354,6 +350,12 @@ namespace StgSharp.Graphics.OpenGL
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GenerateMipmap(Texture2DTarget target)
|
||||
{
|
||||
Context.glGenerateMipmap((uint)target);
|
||||
}
|
||||
|
||||
public unsafe GlHandle[] GenFrameBuffers(int count)
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
@@ -498,6 +500,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, bptr);
|
||||
}
|
||||
i.PixelUpdateCount++;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -665,7 +668,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
#endif
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = ((pixels == null) || (pixels.Length == 0)) ? pixels : null)
|
||||
fixed (T* tptr = ((pixels == null) || (pixels.Length == 0)) ? null : pixels)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, tptr);
|
||||
@@ -697,7 +700,7 @@ namespace StgSharp.Graphics.OpenGL
|
||||
Context.glTexParameteri((uint)target, pname, param);
|
||||
}
|
||||
|
||||
public static bool TryGetFunctionPackage(IntPtr handle, out GlFunction functionPackage)
|
||||
public static bool TryGetFunctionPackage(IntPtr handle, out OpenGLFunction functionPackage)
|
||||
{
|
||||
return contextToGLMap.TryGetValue(handle, out functionPackage);
|
||||
}
|
||||
@@ -726,19 +729,19 @@ namespace StgSharp.Graphics.OpenGL
|
||||
Context.glFinish();
|
||||
}
|
||||
|
||||
internal static GlFunction BuildGlFunctionPackage(IntPtr handle)
|
||||
internal static OpenGLFunction BuildGlFunctionPackage(IntPtr handle)
|
||||
{
|
||||
GlFunction pack;
|
||||
OpenGLFunction pack;
|
||||
if (contextToGLMap.TryGetValue(handle, out pack))
|
||||
{
|
||||
return pack;
|
||||
}
|
||||
pack = new GlFunction { _context = (OpenglContext*)handle };
|
||||
pack = new OpenGLFunction { _context = (OpenglContext*)handle };
|
||||
contextToGLMap.Add(handle, pack);
|
||||
return pack;
|
||||
}
|
||||
|
||||
~GlFunction()
|
||||
~OpenGLFunction()
|
||||
{
|
||||
contextToGLMap.Remove(ContextHandle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user