daily update on 20240528 by nitload youmu
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="AnimationBuilder.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public sealed class AnimationBuilder: IImageProvider
|
||||
{
|
||||
|
||||
private Image cache;
|
||||
|
||||
private TimeFunction time;
|
||||
|
||||
public AnimationBuilder(
|
||||
Func<float, Image> builderFunc,
|
||||
TimeFunction timeline
|
||||
)
|
||||
{
|
||||
time = timeline;
|
||||
BuilderFunc = builderFunc;
|
||||
}
|
||||
|
||||
public Func<float, Image> BuilderFunc { get; set; }
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get => time.IsComplete;
|
||||
}
|
||||
|
||||
public Image GetAnimationFrame()
|
||||
{
|
||||
if (!time.IsComplete)
|
||||
{
|
||||
cache = BuilderFunc(time.Calculate());
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
time.Reset();
|
||||
}
|
||||
|
||||
Image IImageProvider.ProvideImage()
|
||||
{
|
||||
return GetAnimationFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IImageProvider
|
||||
{
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
+4813
-4794
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,32 @@
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public enum ImageChannelLayout
|
||||
{
|
||||
UByte = GLconst.UNSIGNED_BYTE,
|
||||
Byte = GLconst.BYTE,
|
||||
UShort = GLconst.UNSIGNED_SHORT,
|
||||
Short = GLconst.SHORT,
|
||||
UInt = GLconst.UNSIGNED_INT,
|
||||
Int = GLconst.INT,
|
||||
Float = GLconst.FLOAT,
|
||||
UByte332 = 0x8032, // GL_UNSIGNED_BYTE_3_3_2
|
||||
UByte233Rev = 0x8362, // GL_UNSIGNED_BYTE_2_3_3_REV
|
||||
UShort565 = 0x8363, // GL_UNSIGNED_SHORT_5_6_5
|
||||
UShort565Rev = 0x8364, // GL_UNSIGNED_SHORT_5_6_5_REV
|
||||
UShort4444 = 0x8033, // GL_UNSIGNED_SHORT_4_4_4_4
|
||||
UShort4444Rev = 0x8034, // GL_UNSIGNED_SHORT_4_4_4_4_REV
|
||||
UShort5551 = 0x8035, // GL_UNSIGNED_SHORT_5_5_5_1
|
||||
UShort1555Rev = 0x8366, // GL_UNSIGNED_SHORT_1_5_5_5_REV
|
||||
UInt8888 = 0x8035, // GL_UNSIGNED_INT_8_8_8_8
|
||||
UInt8888Rev = 0x8367, // GL_UNSIGNED_INT_8_8_8_8_REV
|
||||
UInt1010102 = 0x8036, // GL_UNSIGNED_INT_10_10_10_2
|
||||
UInt2101010Rev = 0x8368 // GL_UNSIGNED_INT_2_10_10_10_REV
|
||||
}
|
||||
|
||||
|
||||
internal enum VkStructureType : uint
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
|
||||
@@ -43,6 +67,44 @@ namespace StgSharp.Graphics
|
||||
VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
||||
}
|
||||
|
||||
public enum FrameBufferChannel
|
||||
{
|
||||
STENCIL_INDEX = GLconst.STENCIL_INDEX,
|
||||
DEPTH_COMPONENT = GLconst.DEPTH_COMPONENT,
|
||||
DEPTH_STENCIL = GLconst.DEPTH_STENCIL,
|
||||
RED = GLconst.RED,
|
||||
GREEN = GLconst.GREEN,
|
||||
BLUE = GLconst.BLUE,
|
||||
RGB = GLconst.RGB,
|
||||
BGR = GLconst.BGR,
|
||||
RGBA = GLconst.RGBA,
|
||||
BGRA = GLconst.BGRA
|
||||
}
|
||||
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
Texture2D = GLconst.TEXTURE_2D,
|
||||
ProxyTexture2D = GLconst.PROXY_TEXTURE_2D,
|
||||
Texture1DArray = GLconst.TEXTURE_1D_ARRAY,
|
||||
ProxyTexture1DArray = GLconst.PROXY_TEXTURE_1D_ARRAY,
|
||||
TextureRectangle = GLconst.TEXTURE_RECTANGLE,
|
||||
ProxyTextureRectangle = GLconst.PROXY_TEXTURE_RECTANGLE,
|
||||
TextureCubeMapPositiveX = GLconst.TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
TextureCubeMapNegativeX = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
TextureCubeMapPositiveY = GLconst.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
TextureCubeMapNegativeY = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
TextureCubeMapPositiveZ = GLconst.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
TextureCubeMapNegativeZ = GLconst.TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||
ProxyTextureCubeMap = GLconst.PROXY_TEXTURE_CUBE_MAP
|
||||
}
|
||||
|
||||
public enum RenderBufferInternalFormat : uint
|
||||
{
|
||||
RGBA8 = GLconst.RGBA8,
|
||||
Depth24_Stencil8 = GLconst.DEPTH24_STENCIL8,
|
||||
}
|
||||
|
||||
public enum GLOperation : uint
|
||||
{
|
||||
StencilTest = GLconst.STENCIL_TEST,
|
||||
@@ -76,17 +138,23 @@ namespace StgSharp.Graphics
|
||||
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum ShaderType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Fragment = 0x8B30,
|
||||
Vertex = 0x8B31,
|
||||
Fragment = GLconst.FRAGMENT_SHADER,
|
||||
Vertex = GLconst.VERTEX_SHADER,
|
||||
Compute = GLconst.COMPUTE_SHADER,
|
||||
Geometry = GLconst.GEOMETRY_SHADER,
|
||||
}
|
||||
|
||||
public enum BufferType : uint
|
||||
#pragma warning disable CA1008 // 枚举应具有零值
|
||||
public enum BufferType : int
|
||||
#pragma warning restore CA1008 // 枚举应具有零值
|
||||
{
|
||||
ARRAY_BUFFER = 0x8892,
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893,
|
||||
ATOMIC_COUNTER_BUFFER = GLconst.ATOMIC_COUNTER_BUFFER,
|
||||
ArrayBuffer = GLconst.ARRAY_BUFFER,
|
||||
ElementArrayBuffer = GLconst.ELEMENT_ARRAY_BUFFER,
|
||||
AtomicCounterBuffer = GLconst.ATOMIC_COUNTER_BUFFER,
|
||||
COPY_READ_BUFFER = GLconst.COPY_READ_BUFFER,
|
||||
COPY_WRITE_BUFFER = GLconst.COPY_WRITE_BUFFER,
|
||||
DISPATCH_INDIRECT_BUFFER = GLconst.DISPATCH_INDIRECT_BUFFER,
|
||||
@@ -100,19 +168,22 @@ namespace StgSharp.Graphics
|
||||
UNIFORM_BUFFER = GLconst.UNIFORM_BUFFER,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008 // 枚举应具有零值
|
||||
public enum BufferUsage : int
|
||||
#pragma warning restore CA1008 // 枚举应具有零值
|
||||
{
|
||||
STREAM_DRAW = 0x88E0,
|
||||
STREAM_READ = 0x88E1,
|
||||
STREAM_COPY = 0x88E2,
|
||||
STATIC_DRAW = 0x88E4,
|
||||
STATIC_READ = 0x88E5,
|
||||
STATIC_COPY = 0x88E6,
|
||||
DYNAMIC_DRAW = 0x88E8,
|
||||
DYNAMIC_READ = 0x88E9,
|
||||
DYNAMIC_COPY = 0x88EA
|
||||
StreamDraw = 0x88E0,
|
||||
StreamRead = 0x88E1,
|
||||
StreamCopy = 0x88E2,
|
||||
StaticDraw = 0x88E4,
|
||||
StaticRead = 0x88E5,
|
||||
StaticCopy = 0x88E6,
|
||||
DynamicDraw = 0x88E8,
|
||||
DynamicRead = 0x88E9,
|
||||
DynamicCopy = 0x88EA
|
||||
}
|
||||
|
||||
|
||||
public enum MaskBufferBit
|
||||
{
|
||||
COLOR = GLconst.COLOR_BUFFER_BIT,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Form.cs"
|
||||
// file="ViewModel.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -46,7 +46,7 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public abstract unsafe partial class Form
|
||||
public abstract unsafe partial class ViewModel
|
||||
{
|
||||
|
||||
private int _frameCount;
|
||||
@@ -54,20 +54,18 @@ namespace StgSharp.Graphics
|
||||
|
||||
private IntPtr windowID;
|
||||
|
||||
private short fpsCount;
|
||||
internal Form sharedForm;
|
||||
internal ViewModel sharedForm;
|
||||
|
||||
internal int height;
|
||||
internal int width;
|
||||
internal IntPtr monitor;
|
||||
|
||||
internal LinkedList<Control> allControl;
|
||||
internal string name;
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
internal Vector4 backgroundColor;
|
||||
|
||||
protected Form((int width, int height) size, string name)
|
||||
protected ViewModel((int width, int height) size, string name)
|
||||
{
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
@@ -92,7 +90,7 @@ namespace StgSharp.Graphics
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Form()
|
||||
protected ViewModel()
|
||||
{
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
@@ -102,8 +100,6 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
Console.Clear();
|
||||
Console.WriteLine(_frameSpeed);
|
||||
};
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
(1000L * 1000L) / 60, TimeSpanProvider.DefaultProvider
|
||||
@@ -218,7 +214,7 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Set all necessary metadata to current form instance
|
||||
/// </summary>
|
||||
public void SetMetadata(int width, int height, string name, IntPtr monitor, Form sharedForm)
|
||||
public void SetMetadata(int width, int height, string name, IntPtr monitor, ViewModel sharedForm)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
@@ -41,7 +41,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract partial class Form
|
||||
public abstract partial class ViewModel
|
||||
{
|
||||
private Blueprint renderLogic;
|
||||
|
||||
@@ -64,6 +64,40 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public T BuildMainRenderStream<T>((int x, int y, int z) unitCubeSize) where T : RenderStream
|
||||
{
|
||||
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
|
||||
args.UnitCubeSize = unitCubeSize;
|
||||
args.Name = this.name;
|
||||
args.Height = this.Height;
|
||||
args.Width = this.Width;
|
||||
T? ret = Activator.CreateInstance(typeof(T), args) as T;
|
||||
if (ret == null)
|
||||
{
|
||||
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
|
||||
}
|
||||
ret!.InternalInit();
|
||||
this.WindowID = ret.CanvasHandle;
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T BuildNewRenderStream<T>(RenderStreamConstructArgs arg, (int x, int y, int z) unitCubeSize) where T : RenderStream
|
||||
{
|
||||
T? ret = Activator.CreateInstance(typeof(T), arg) as T;
|
||||
if (ret == null)
|
||||
{
|
||||
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
|
||||
}
|
||||
ret!.InternalInit();
|
||||
this.WindowID = ret.CanvasHandle;
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
|
||||
{
|
||||
|
||||
@@ -11,16 +11,16 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
public abstract unsafe partial class Form
|
||||
public abstract unsafe partial class ViewModel
|
||||
{
|
||||
|
||||
static internal Dictionary<IntPtr, Form> activatedForms ;
|
||||
static internal Dictionary<IntPtr, ViewModel> activatedForms ;
|
||||
|
||||
public static void ShowForm<T>(FormFormatter f) where T : Form
|
||||
public static void ShowForm<T>(FormFormatter f) where T : ViewModel
|
||||
{
|
||||
if (activatedForms == null)
|
||||
{
|
||||
activatedForms = new Dictionary<IntPtr, Form>();
|
||||
activatedForms = new Dictionary<IntPtr, ViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,14 +34,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL buffer objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
protected IntPtr binding;
|
||||
protected RenderStream binding;
|
||||
protected glHandleSet _bufferHandle;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of handle to Element Buffer Object in OpenGL.
|
||||
@@ -48,27 +48,34 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal ElementBuffer(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
GL.BindBuffer(BufferType.ELEMENT_ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ELEMENT_ARRAY_BUFFER, bufferArray, usage);
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget:uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Read = GLconst.READ_FRAMEBUFFER,
|
||||
All = GLconst.FRAMEBUFFER,
|
||||
@@ -17,9 +21,9 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal unsafe FrameBuffer(int count, glRenderStream contextBinding)
|
||||
{
|
||||
binding = contextBinding.ContextHandle;
|
||||
binding = contextBinding;
|
||||
_bufferHandle = new glHandleSet(count);
|
||||
((GLcontext*)binding)->glGenFramebuffers((uint)count,_bufferHandle.handle);
|
||||
((GLcontext*)binding.ContextHandle)->glGenFramebuffers((uint)count,_bufferHandle.handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,7 +33,12 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
public unsafe override void Bind(int index)
|
||||
{
|
||||
((GLcontext*)binding)->glBindFramebuffer(GLconst.FRAMEBUFFER, _bufferHandle[index].Value);
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,_bufferHandle[index]);
|
||||
}
|
||||
|
||||
public static void BindNull()
|
||||
{
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,glHandle.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,7 +49,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
public unsafe void Bind(FrameBufferTarget target, int index)
|
||||
{
|
||||
((GLcontext*)binding)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
|
||||
((GLcontext*)binding.ContextHandle)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class RenderBuffer : BufferObjectBase
|
||||
{
|
||||
public RenderBuffer(int count, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenRenderBuffer(count);
|
||||
}
|
||||
|
||||
public override void Bind(int index)
|
||||
{
|
||||
glFunc.BindRenderBuffer(this[index]);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Store(RenderBufferInternalFormat format, (int width,int height) size)
|
||||
{
|
||||
if (size.width > binding.Width || size.height>binding.Height)
|
||||
{
|
||||
StgSharp.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="texture.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class TextureGL
|
||||
{
|
||||
|
||||
internal static bool[] unitActivated = new bool[16];
|
||||
private IntPtr binding;
|
||||
internal glHandleSet _textureHandle;
|
||||
internal Image[] sourceList;
|
||||
|
||||
public glHandle this[int index]
|
||||
{
|
||||
get => _textureHandle[index];
|
||||
}
|
||||
|
||||
internal TextureGL(int n, glRenderStream binding)
|
||||
{
|
||||
sourceList = new Image[n];
|
||||
this.binding = binding.ContextHandle;
|
||||
_textureHandle = glFunc.GenTextures(n);
|
||||
}
|
||||
|
||||
public static void Activate(TextureUnit unit)
|
||||
{
|
||||
glFunc.ActiveTexture((uint)unit);
|
||||
}
|
||||
|
||||
public void Bind2D(int index)
|
||||
{
|
||||
glFunc.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="index"> </param>
|
||||
/// <param name="i"> </param>
|
||||
public unsafe void LoadTexture(int index, Image i)
|
||||
{
|
||||
sourceList[index] = i;
|
||||
glArrayHandle handle = sourceList[index].GetArrayHandle();
|
||||
glFunc.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, (uint)i.Channel,
|
||||
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
|
||||
(uint)i.Channel, ImageChannelLayout.Byte,
|
||||
pixelArrayHandle: handle
|
||||
);
|
||||
handle.Release();
|
||||
}
|
||||
|
||||
|
||||
#region texture setting
|
||||
|
||||
public void Set2dFilterProperty(
|
||||
Filter onMinify, Filter onMagnify)
|
||||
{
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
|
||||
}
|
||||
|
||||
public void Set2dWrapProperty(
|
||||
Wrap onHorizontial, Wrap onVertical)
|
||||
{
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
|
||||
glFunc.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
|
||||
}
|
||||
|
||||
#endregion texture setting
|
||||
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Filter
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Nearest = GLconst.NEAREST,
|
||||
Linear = GLconst.LINEAR,
|
||||
NearestLinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
|
||||
LinearLinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
|
||||
NearestNearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
|
||||
LinearNearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
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,
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum Wrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
}
|
||||
}
|
||||
@@ -28,38 +28,40 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class VertexArray : BufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
_bufferHandle = GL.GenVertexArrays(n);
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenVertexArrays(n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
GL.BindVertexArray(_bufferHandle[index]);
|
||||
glFunc.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindNull()
|
||||
public static void BindNull()
|
||||
{
|
||||
GL.BindVertexArray(glHandle.Zero);
|
||||
glFunc.BindVertexArray(glHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
public static void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
{
|
||||
GL.SetVertexAttribute(
|
||||
glFunc.SetVertexAttribute(
|
||||
index, vertexLength, dataType,
|
||||
isNomalized,
|
||||
stride, pointer);
|
||||
@@ -69,7 +71,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
glFunc.DeleteVertexArrays(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -38,20 +39,20 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public unsafe class VertexBuffer : BufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(int n, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,8 +65,8 @@ namespace StgSharp.Graphics
|
||||
public void WriteMatrixData<T>(int index, T bufferData, BufferUsage usage)
|
||||
where T : struct, IMat
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferData, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, bufferData, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,8 +84,8 @@ namespace StgSharp.Graphics
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, bufferArray, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +95,7 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="scalerSpan">A <see cref="Span{T}"/> of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteScalerData<T>(int index, Span<T> scalerSpan, BufferUsage usage)
|
||||
public void WriteScalerData<T>(int index, ReadOnlySpan<T> scalerSpan, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
@@ -102,8 +103,8 @@ namespace StgSharp.Graphics
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ARRAY_BUFFER, scalerSpan, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -113,10 +114,10 @@ namespace StgSharp.Graphics
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="vectorSpan">A <see cref="Span{T}"/> of data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteVectorData<T>(int index, Span<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
public void WriteVectorData<T>(int index, ReadOnlySpan<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ARRAY_BUFFER, vectorSpan, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -128,8 +129,8 @@ namespace StgSharp.Graphics
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteVectorData<T>(int index, T[] vectorArray, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ARRAY_BUFFER, vectorArray, usage);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -138,14 +139,14 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, glHandle.Zero);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace StgSharp.Graphics
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
/// Direct call will cause <see langword="InvalidOperationException"/>
|
||||
/// </summary>
|
||||
public unsafe class glHandle
|
||||
public unsafe class glHandle: IDisposable
|
||||
{
|
||||
private static uint* zeroHandle = (uint*)Marshal.AllocHGlobal(Marshal.SizeOf<uint>());
|
||||
|
||||
@@ -93,6 +94,8 @@ namespace StgSharp.Graphics
|
||||
set => *valuePtr = value;
|
||||
}
|
||||
|
||||
public static glHandle ZeroHandle => FromPtr(IntPtr.Zero);
|
||||
|
||||
public static glHandle Zero => Alloc(0);
|
||||
|
||||
public static glHandle Alloc(uint value)
|
||||
@@ -113,6 +116,30 @@ namespace StgSharp.Graphics
|
||||
Marshal.FreeHGlobal((IntPtr)valuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (IsIsolated)
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)valuePtr).Free();
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ~glHandle()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe class glSHandle
|
||||
@@ -188,9 +215,9 @@ namespace StgSharp.Graphics
|
||||
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
|
||||
internal readonly Array a;
|
||||
internal GCHandle handle;
|
||||
private bool disposedValue;
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
@@ -230,7 +257,6 @@ namespace StgSharp.Graphics
|
||||
handle.Free();
|
||||
handle = default;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -43,14 +43,19 @@ namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle,int key, ref IntPtr logPtr);
|
||||
#pragma warning disable CA5392
|
||||
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle, int key, ref IntPtr logPtr);
|
||||
#pragma warning restore CA5392
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
internal static unsafe partial class GL
|
||||
internal static unsafe partial class glFunc
|
||||
{
|
||||
|
||||
private static GLcontext* context;
|
||||
@@ -58,15 +63,12 @@ namespace StgSharp.Graphics
|
||||
public static IntPtr CurrentContextHandle
|
||||
{
|
||||
get { return (IntPtr)context; }
|
||||
set
|
||||
{
|
||||
context = (GLcontext*)value;
|
||||
}
|
||||
set { context = (GLcontext*)value; }
|
||||
}
|
||||
|
||||
private static ref GLcontext Context
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if ((IntPtr)context==IntPtr.Zero)
|
||||
@@ -74,7 +76,7 @@ namespace StgSharp.Graphics
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
#endif
|
||||
return ref *context;
|
||||
return ref (*context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,14 +98,21 @@ namespace StgSharp.Graphics
|
||||
Context.glBindBuffer((uint)bufferType, handle.Value);
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void GetTextureImage<T>(Texture2DTarget target, int level, ImageChannel channel, ImageChannelLayout channelLayout, ref T[] dataStream)where T: struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key,ref sptr) == 0)
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = dataStream)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(sptr);
|
||||
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
|
||||
}
|
||||
return "";
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,12 +127,30 @@ namespace StgSharp.Graphics
|
||||
Context.glBindFramebuffer((uint)target, handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindRenderBuffer(glHandle handle)
|
||||
{
|
||||
Context.glBindRenderbuffer(GLconst.RENDERBUFFER, handle.Value);
|
||||
}
|
||||
|
||||
|
||||
public static void WaitAccomplishment()
|
||||
{
|
||||
Context.glFinish();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindTexture(uint type, glHandle texture)
|
||||
{
|
||||
Context.glBindTexture(type, texture.Value);
|
||||
}
|
||||
|
||||
public static unsafe int GetMaskInteger(uint statusCode)
|
||||
{
|
||||
int ret = 0;
|
||||
Context.glGetIntegerv(statusCode,&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindVertexArray(glHandle handle)
|
||||
@@ -131,10 +158,35 @@ namespace StgSharp.Graphics
|
||||
Context.glBindVertexArray(handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
public static void RereadImage(
|
||||
this Image i, (int X, int Y) beginPosition, FrameBufferChannel format, ImageChannelLayout dataType)
|
||||
{
|
||||
Context.glVertexAttribDivisor(layoutIndex, divisor);
|
||||
glArrayHandle handle = i.GetArrayHandle();
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, (byte*)handle.AddressOfArray()
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void FrameBufferTexture2d(FrameBufferTarget target, uint attachment, Texture2DTarget texTarget,glHandle textureHandle ,int level)
|
||||
{
|
||||
Context.glFramebufferTexture2D(
|
||||
(uint)target, attachment, (uint)texTarget,textureHandle.Value, level
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReadPixels(
|
||||
(int X, int Y) beginPosition, (int width, int height) size, FrameBufferChannel format, ImageChannelLayout dataType, ref byte[] stream
|
||||
)
|
||||
{
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y,
|
||||
size.width, size.height, (uint)format, (uint)dataType, bptr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -143,6 +195,11 @@ namespace StgSharp.Graphics
|
||||
Context.glClear((uint)mask);
|
||||
}
|
||||
|
||||
public static void CombineFrameBufferRenderBuffer(glHandle fboHandle, glHandle rboHandle)
|
||||
{
|
||||
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER,fboHandle.Value,GLconst.RENDERBUFFER, rboHandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
@@ -203,31 +260,8 @@ namespace StgSharp.Graphics
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static unsafe IntPtr CreateWindowHandle(
|
||||
int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
byte[] tittleBytes = Encoding.UTF8.GetBytes(tittle);
|
||||
IntPtr windowPtr;
|
||||
if (share == null)
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, share.id);
|
||||
}
|
||||
|
||||
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
|
||||
{
|
||||
throw new Exception("Cannot create window instance!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return windowPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteBuffer(glHandle handle)
|
||||
@@ -278,7 +312,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawElementsInstanced(
|
||||
GeometryType mode , uint count, TypeCode type, IntPtr ptr, uint amount
|
||||
GeometryType mode, uint count, TypeCode type, IntPtr ptr, uint amount
|
||||
)
|
||||
{
|
||||
uint a;
|
||||
@@ -302,7 +336,7 @@ namespace StgSharp.Graphics
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr,amount);
|
||||
Context.glDrawElementsInstanced((uint)mode, count, a, (void*)ptr, amount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -319,6 +353,15 @@ namespace StgSharp.Graphics
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenRenderBuffer(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenRenderbuffers(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenTextures(int count)
|
||||
{
|
||||
@@ -328,6 +371,14 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetRenderBufferStorage(RenderBufferInternalFormat internalFormat ,(int width, int height) size)
|
||||
{
|
||||
Context.glRenderbufferStorage(
|
||||
GLconst.RENDERBUFFER, (uint)internalFormat,size.width,size.height
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe glHandleSet GenVertexArrays(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
@@ -335,6 +386,16 @@ namespace StgSharp.Graphics
|
||||
return h;
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if (InternalIO.glCheckShaderStatus(ref Context, s.handle[index].Value, key, ref sptr) == 0)
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(sptr);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glSHandle GetUniformLocation(glHandle program, string name)
|
||||
@@ -359,17 +420,16 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void LoadShaderSource(glHandle shaderHandle, string codeStream)
|
||||
public static unsafe void LoadShaderSource(glHandle shaderHandle, byte[] codeStream)
|
||||
{
|
||||
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
|
||||
fixed (byte* streamPtr = stream)
|
||||
fixed (byte* streamPtr = codeStream)
|
||||
{
|
||||
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void MakeContextCurrent(Form form)
|
||||
public static unsafe void MakeContextCurrent(ViewModel form)
|
||||
{
|
||||
if (form.WindowID == IntPtr.Zero)
|
||||
{
|
||||
@@ -420,6 +480,34 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
if (bufferArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
@@ -449,7 +537,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
@@ -499,10 +587,20 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glHandle pixels)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, type, pixels.valuePtr
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, pixels.valuePtr
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glArrayHandle pixelArrayHandle)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, (void*)pixelArrayHandle.handle.AddrOfPinnedObject()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -518,6 +616,12 @@ namespace StgSharp.Graphics
|
||||
Context.glUseProgram(program.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
{
|
||||
Context.glVertexAttribDivisor(layoutIndex, divisor);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
{
|
||||
@@ -51,15 +51,28 @@ namespace StgSharp.Graphics
|
||||
return new ElementBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected RenderBuffer CreateRenderBuffer(int count)
|
||||
{
|
||||
return new RenderBuffer(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected FrameBuffer CreateFrameBuffer(int count)
|
||||
{
|
||||
return new FrameBuffer(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a sets of <see cref="Texture"/>
|
||||
/// Create a sets of <see cref="TextureGL"/>
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of textures to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Texture CreateTexture(int count)
|
||||
protected TextureGL CreateTexture(int count)
|
||||
{
|
||||
return new Texture(count, this);
|
||||
return new TextureGL(count, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -39,15 +39,15 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( GL.CreateShaderSet(count, type), type);
|
||||
return new Shader( glFunc.CreateShaderSet(count, type), type);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader"/> program
|
||||
@@ -72,7 +72,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
this.handle = handle;
|
||||
context = GL.CurrentContextHandle;
|
||||
context = glFunc.CurrentContextHandle;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
@@ -84,31 +84,43 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(int index, ShaderProgram target)
|
||||
{
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
glFunc.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public static string FromCodeFile(string fileRoute)
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (str == "")
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
throw new Exception($"Cannot load and GLSL code from {fileRoute}");
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return str;
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string code)
|
||||
public unsafe void Compile(int index, byte[] codeStream)
|
||||
{
|
||||
if (code == null)
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException("Must provide enough code");
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
GL.LoadShaderSource(handle[index], $"{code}\0");
|
||||
GL.CompileShader(handle[index]);
|
||||
glFunc.LoadShaderSource(handle[index], codeStream);
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index,ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
glFunc.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
@@ -122,7 +134,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this,index, (int)status);
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (log != "")
|
||||
{
|
||||
throw new Exception($"Shader Error\n{status}\n" + log);
|
||||
@@ -147,7 +159,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly IntPtr binding;
|
||||
internal readonly glHandle handle;
|
||||
|
||||
@@ -157,7 +168,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe ShaderProgram(glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
handle = GL.CreateProgram();
|
||||
handle = glFunc.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,7 +253,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(handle);
|
||||
glFunc.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
|
||||
@@ -38,7 +38,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
@@ -65,14 +65,14 @@ namespace StgSharp.Graphics
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -101,14 +101,14 @@ namespace StgSharp.Graphics
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -137,14 +137,14 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = GL.CurrentContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -175,14 +175,14 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = GL.CurrentContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -197,55 +197,57 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
internal static partial class GL
|
||||
internal static partial class glFunc
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
public unsafe static void SetUniformValue
|
||||
(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
{
|
||||
Matrix44 temp = mat;
|
||||
Context.glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
public unsafe static void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float> uniform, float v0)
|
||||
public static unsafe void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.Value , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<int> uniform, int i0)
|
||||
public static unsafe void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.Value , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.Value , v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.Value , v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
@@ -56,9 +56,9 @@ namespace StgSharp.Graphics
|
||||
private static string glExtensionList;
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="Form"/> context.
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewModel"/> context.
|
||||
/// </summary>
|
||||
/// <param name="stream">The <see cref="Form"/> used as current OpenGL context</param>
|
||||
/// <param name="stream">The <see cref="ViewModel"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this glRenderStream stream)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)stream.ContextHandle;
|
||||
@@ -1044,7 +1044,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glPointSize = (delegate*<float, void>)load("glPointSize");
|
||||
contextPtr->glPolygonMode = (delegate*<uint, uint, void>)load("glPolygonMode");
|
||||
contextPtr->glReadBuffer = (delegate*<uint, void>)load("glReadBuffer");
|
||||
contextPtr->glReadPixels = (delegate*<int, int, uint, uint, uint, uint, void*, void>)load("glReadPixels");
|
||||
contextPtr->glReadPixels = (delegate*<int, int, int, int, uint, uint, void*, void>)load("glReadPixels");
|
||||
contextPtr->glScissor = (delegate*<int, int, uint, uint, void>)load("glScissor");
|
||||
contextPtr->glStencilFunc = (delegate*<uint, int, uint, void>)load("glStencilFunc");
|
||||
contextPtr->glStencilMask = (delegate*<uint, void>)load("glStencilMask");
|
||||
@@ -1368,7 +1368,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glFramebufferTexture3D = (delegate*<uint, uint, uint, uint, int, int, void>)load("glFramebufferTexture3D");
|
||||
contextPtr->glFramebufferTextureLayer = (delegate*<uint, uint, uint, int, int, void>)load("glFramebufferTextureLayer");
|
||||
contextPtr->glGenFramebuffers = (delegate*<uint, uint*, void>)load("glGenFramebuffers");
|
||||
contextPtr->glGenRenderbuffers = (delegate*<uint, uint*, void>)load("glGenRenderbuffers");
|
||||
contextPtr->glGenRenderbuffers = (delegate*<int, uint*, void>)load("glGenRenderbuffers");
|
||||
contextPtr->glGenVertexArrays = (delegate*<int, uint*, void>)load("glGenVertexArrays");
|
||||
contextPtr->glGenerateMipmap = (delegate*<uint, void>)load("glGenerateMipmap");
|
||||
contextPtr->glGetBooleani_v = (delegate*<uint, uint, bool*, void>)load("glGetBooleani_v");
|
||||
@@ -1388,7 +1388,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glIsRenderbuffer = (delegate*<uint, bool>)load("glIsRenderbuffer");
|
||||
contextPtr->glIsVertexArray = (delegate*<uint, bool>)load("glIsVertexArray");
|
||||
contextPtr->glMapBufferRange = (delegate*<uint, IntPtr, UIntPtr, uint, void*>)load("glMapBufferRange");
|
||||
contextPtr->glRenderbufferStorage = (delegate*<uint, uint, uint, uint, void>)load("glRenderbufferStorage");
|
||||
contextPtr->glRenderbufferStorage = (delegate*<uint, uint, int, int, void>)load("glRenderbufferStorage");
|
||||
contextPtr->glRenderbufferStorageMultisample = (delegate*<uint, uint, uint, uint, uint, void>)load("glRenderbufferStorageMultisample");
|
||||
contextPtr->glTexParameterIiv = (delegate*<uint, uint, int*, void>)load("glTexParameterIiv");
|
||||
contextPtr->glTexParameterIuiv = (delegate*<uint, uint, uint*, void>)load("glTexParameterIuiv");
|
||||
@@ -1908,7 +1908,7 @@ namespace StgSharp.Graphics
|
||||
contextPtr->glNamedFramebufferTextureLayer = (delegate*<uint, uint, uint, int, int, void>)load("glNamedFramebufferTextureLayer");
|
||||
contextPtr->glNamedRenderbufferStorage = (delegate*<uint, uint, uint, uint, void>)load("glNamedRenderbufferStorage");
|
||||
contextPtr->glNamedRenderbufferStorageMultisample = (delegate*<uint, uint, uint, uint, uint, void>)load("glNamedRenderbufferStorageMultisample");
|
||||
contextPtr->glReadnPixels = (delegate*<int, int, uint, uint, uint, uint, uint, void*, void>)load("glReadnPixels");
|
||||
contextPtr->glReadnPixels = (delegate*<int, int, int, int, uint, uint, uint, void*, void>)load("glReadnPixels");
|
||||
contextPtr->glTextureBarrier = (delegate*<void>)load("glTextureBarrier");
|
||||
contextPtr->glTextureBuffer = (delegate*<uint, uint, uint, void>)load("glTextureBuffer");
|
||||
contextPtr->glTextureBufferRange = (delegate*<uint, uint, uint, IntPtr, UIntPtr, void>)load("glTextureBufferRange");
|
||||
|
||||
@@ -32,7 +32,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
|
||||
@@ -39,14 +39,18 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
protected glRenderStream(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
}
|
||||
protected glRenderStream(RenderStreamConstructArgs args,bool isSharing) : base(args,isSharing)
|
||||
{
|
||||
}
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
@@ -54,19 +58,6 @@ namespace StgSharp.Graphics
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
public static T AsMainStreamOf<T>(Form f, (int x, int y, int z) unitCubeSize) where T : glRenderStream
|
||||
{
|
||||
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
|
||||
args.UnitCubeSize = unitCubeSize;
|
||||
args.Name = f.name;
|
||||
args.Height = f.Height;
|
||||
args.Width = f.Width;
|
||||
T ret = Activator.CreateInstance(typeof(T), args) as T;
|
||||
ret!.InternalInit();
|
||||
f.WindowID = ret.CanvasHandle;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
|
||||
/// current form as current OpenGL context.
|
||||
@@ -82,10 +73,10 @@ namespace StgSharp.Graphics
|
||||
GLcontext* contextID = (GLcontext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
if (GL.CurrentContextHandle != ContextHandle)
|
||||
if (glFunc.CurrentContextHandle != ContextHandle)
|
||||
{
|
||||
GL.CurrentContextHandle = ContextHandle;
|
||||
//Console.WriteLine($"context set as {(ulong)GL.CurrentContextHandle}");
|
||||
glFunc.CurrentContextHandle = ContextHandle;
|
||||
//Console.WriteLine($"context set as {(ulong)glFunc.CurrentContextHandle}");
|
||||
InternalIO.glfwMakeContextCurrent(CanvasHandle);
|
||||
}
|
||||
}
|
||||
@@ -98,11 +89,10 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal override sealed unsafe void CreateCanvas()
|
||||
{
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(name);
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(Name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width, Height, nameCode, Monitor, IntPtr.Zero
|
||||
);
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
@@ -113,6 +103,7 @@ namespace StgSharp.Graphics
|
||||
ProcessInput();
|
||||
Main(in input, in output);
|
||||
}
|
||||
|
||||
internal override sealed void InternalInit()
|
||||
{
|
||||
CreateCanvas();
|
||||
|
||||
+208
-85
@@ -29,11 +29,13 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -41,18 +43,21 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : SSDSerializable
|
||||
public class Image : SSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
internal ImageInfo info;
|
||||
internal byte[] data;
|
||||
internal glHandle pixelArrayHandle;
|
||||
internal ImageInfo info;
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
info = information;
|
||||
int length = info.width * info.height * info.channel;
|
||||
pixelArrayHandle = glHandle.FromPtr(information.pixelPtr);
|
||||
data = Array.Empty<byte>();
|
||||
//int length = info.width * info.height * info.channel;
|
||||
}
|
||||
|
||||
public ref byte[] DataStream
|
||||
{
|
||||
get => ref data;
|
||||
}
|
||||
|
||||
public unsafe Image()
|
||||
@@ -60,104 +65,222 @@ namespace StgSharp.Graphics
|
||||
info = new ImageInfo();
|
||||
}
|
||||
|
||||
public int Channel => info.channel;
|
||||
public int Height => info.height;
|
||||
public ImageChannel Channel => info.Channel;
|
||||
public int ChannelCount => info.ChannelCount;
|
||||
public int Height => info.Height;
|
||||
|
||||
public int Width => info.width;
|
||||
public (int width, int height) Size
|
||||
{
|
||||
get => (info.Width, info.Height);
|
||||
}
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public int Width => info.Width;
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
Image ret = new Image();
|
||||
fixed (ImageInfo* iptr = &ret.info)
|
||||
{
|
||||
InternalIO.InternalLoadImage(route, iptr, loader);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, int channelCount, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
ChannelCount = channelCount,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public glArrayHandle GetArrayHandle()
|
||||
{
|
||||
if ((data == Array.Empty<byte>()) || (data == null))
|
||||
{
|
||||
this.GetBytes();
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes()
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * ChannelCount;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.StreamPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.StreamPtr + i);
|
||||
}
|
||||
}
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes(out int length)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * ChannelCount;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.StreamPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.StreamPtr + i);
|
||||
}
|
||||
}
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
length = data.Length;
|
||||
return data;
|
||||
}
|
||||
|
||||
internal override unsafe void BuildFromByteStream(byte[] stream)
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
$"{($"{typeof(Image).Name} does not support BuildFromByteStream,")}{($"please use Image.FromMemory instead.")}"
|
||||
);
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
~Image()
|
||||
{
|
||||
if (info.pixelPtr!= IntPtr.Zero)
|
||||
if (info.StreamPtr != IntPtr.Zero)
|
||||
{
|
||||
// Marshal.FreeHGlobal(info.pixelPtr);
|
||||
// Marshal.FreeHGlobal(info.StreamPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe override byte[] GetBytes()
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * Channel + 1 + 8;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
*(int*)bptr = Width;
|
||||
*(int*)(bptr + 4) = Height;
|
||||
*(bptr + 8) = (byte)Channel;
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.pixelPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.pixelPtr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Marshal.FreeHGlobal(info.pixelPtr);
|
||||
info.pixelPtr = IntPtr.Zero;
|
||||
return data;
|
||||
}
|
||||
|
||||
public unsafe override byte[] GetBytes(out int length)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * Channel + 1 + 8;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
*(int*)bptr = Width;
|
||||
*(int*)(bptr + 4) = Height;
|
||||
*(bptr + 8) = (byte)Channel;
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.pixelPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.pixelPtr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
length = data.Length;
|
||||
Marshal.FreeHGlobal(info.pixelPtr);
|
||||
info.pixelPtr = IntPtr.Zero;
|
||||
return data;
|
||||
}
|
||||
|
||||
internal unsafe override void BuildFromByteStream(byte[] stream)
|
||||
{
|
||||
info = new ImageInfo();
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
info.width = *(int*)bptr;
|
||||
info.height = *(int*)(bptr + 4);
|
||||
info.channel = *(bptr + 8);
|
||||
info.pixelPtr = IntPtr.Zero;
|
||||
}
|
||||
data = stream;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
internal int width;
|
||||
internal int height;
|
||||
internal int channel;
|
||||
internal IntPtr pixelPtr;
|
||||
|
||||
private ImageChannel channel;
|
||||
private int channelCount;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set
|
||||
{
|
||||
channel = value;
|
||||
switch (channel)
|
||||
{
|
||||
case ImageChannel.SingleColor:
|
||||
channelCount = 1; break;
|
||||
case ImageChannel.DoubleColor:
|
||||
channelCount = 2; break;
|
||||
case ImageChannel.FullColor:
|
||||
channelCount = 3; break;
|
||||
case ImageChannel.WithAlphaChannel:
|
||||
channelCount = 4; break;
|
||||
default:
|
||||
throw new InvalidCastException("Unknown color channel decoding setting.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => channelCount;
|
||||
set
|
||||
{
|
||||
channelCount = value;
|
||||
switch (channelCount)
|
||||
{
|
||||
case 1:
|
||||
channel = ImageChannel.SingleColor; break;
|
||||
case 2:
|
||||
channel = ImageChannel.DoubleColor; break;
|
||||
case 3:
|
||||
channel = ImageChannel.FullColor; break;
|
||||
case 4:
|
||||
channel = ImageChannel.WithAlphaChannel; break;
|
||||
default:
|
||||
throw new InvalidCastException("Unknown color channel decoding setting.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * channelCount;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{pixelPtr}";
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
SingleColor = GLconst.RED,
|
||||
DoubleColor = GLconst.RG,
|
||||
FullColor = GLconst.RGB,
|
||||
WithAlphaChannel = GLconst.RGBA,
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
private IGeometry _shape;
|
||||
private Image _texture;
|
||||
private vec2d[] textureCoord;
|
||||
|
||||
public PlainGeometryMesh(
|
||||
IGeometry shape, Image texture, IEnumerable<vec2d> texCoord
|
||||
)
|
||||
{
|
||||
if (shape==null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(shape));
|
||||
}
|
||||
if (texCoord == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(texCoord));
|
||||
}
|
||||
|
||||
_shape = shape;
|
||||
textureCoord = new vec2d[shape.VertexCount];
|
||||
_texture = texture;
|
||||
if (texCoord is not vec2d[] source)
|
||||
{
|
||||
source = texCoord.ToArray();
|
||||
}
|
||||
if (textureCoord.Length > source.Length)
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
Array.Copy(sourceArray: source, textureCoord, textureCoord.Length);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public vec4d[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image Texture
|
||||
{
|
||||
get => _texture;
|
||||
internal set => _texture = value;
|
||||
}
|
||||
|
||||
public vec2d[] TextureCoord => textureCoord;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
@@ -42,28 +43,56 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream: IConvertableToBlueprintNode
|
||||
public abstract class RenderStream : IConvertableToBlueprintNode
|
||||
{
|
||||
|
||||
private protected (int x, int y, int z) _coordStretch;
|
||||
|
||||
private protected RenderStreamConstructArgs primeArgs;
|
||||
|
||||
private Camera nativeCamera;
|
||||
|
||||
private IntPtr canvasHandle;
|
||||
private IntPtr contextHandle;
|
||||
|
||||
private int height;
|
||||
private IntPtr monitor;
|
||||
private IntPtr sharedCanvas;
|
||||
private int width;
|
||||
protected (int x, int y, int z) _coordStretch;
|
||||
protected string name;
|
||||
private Camera nativeCamera;
|
||||
|
||||
internal TimeSpanProvider timeProvider;
|
||||
|
||||
protected RenderStream(RenderStreamConstructArgs args, bool isSharing)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
if (isSharing)
|
||||
{
|
||||
primeArgs = args;
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
|
||||
primeArgs = newArgs;
|
||||
}
|
||||
|
||||
monitor = args.Monitor;
|
||||
_coordStretch = args.UnitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
public RenderStream(RenderStreamConstructArgs args)
|
||||
{
|
||||
height = args.Height;
|
||||
monitor = args.Monitor;
|
||||
width = args.Width;
|
||||
name = args.Name;
|
||||
monitor = args.Monitor;
|
||||
_coordStretch = args.UnitCubeSize;
|
||||
if (args == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
|
||||
primeArgs = newArgs;
|
||||
|
||||
monitor = newArgs!.Monitor;
|
||||
_coordStretch = newArgs.UnitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
public IntPtr CanvasHandle
|
||||
@@ -78,12 +107,6 @@ namespace StgSharp.Graphics
|
||||
internal set => contextHandle = value;
|
||||
}
|
||||
|
||||
internal protected Camera NativeCamera
|
||||
{
|
||||
get => nativeCamera;
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
public FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
@@ -94,13 +117,13 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
|
||||
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
get => primeArgs.Height;
|
||||
internal set
|
||||
{
|
||||
height = value;
|
||||
primeArgs.Height = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
@@ -113,8 +136,8 @@ namespace StgSharp.Graphics
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
internal set => name = value;
|
||||
get => primeArgs.Name;
|
||||
internal set => primeArgs.Name = value;
|
||||
}
|
||||
|
||||
public IntPtr SharedCanvas
|
||||
@@ -123,35 +146,50 @@ namespace StgSharp.Graphics
|
||||
internal set => sharedCanvas = value;
|
||||
}
|
||||
|
||||
public vec2d Size
|
||||
public (int width, int height) Size
|
||||
{
|
||||
get => new vec2d(width, height);
|
||||
get => (Width, Height);
|
||||
internal set
|
||||
{
|
||||
height = (int)value.Y;
|
||||
width = (int)value.X;
|
||||
primeArgs.Height = value.width;
|
||||
primeArgs.Width = value.height;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
get => primeArgs.Width;
|
||||
internal set
|
||||
{
|
||||
width = value;
|
||||
primeArgs.Width = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
protected internal Camera NativeCamera
|
||||
{
|
||||
get => nativeCamera;
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
protected int Frames
|
||||
{
|
||||
get => timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected abstract string[] InputPortsName { get; }
|
||||
protected abstract string[] OutputPortsName { get; }
|
||||
|
||||
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
|
||||
protected float TimePassed
|
||||
{
|
||||
get => timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
|
||||
|
||||
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
|
||||
protected TimeSpanProvider TimeProvider
|
||||
{
|
||||
get => timeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
@@ -163,10 +201,36 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
|
||||
|
||||
public static TTarget ShareContextWith<TSource, TTarget>(TSource source)
|
||||
where TSource : RenderStream
|
||||
where TTarget : RenderStream
|
||||
{
|
||||
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, true) as TTarget;
|
||||
if (target == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Failed in creating a new {typeof(TTarget).Name} instance when calling ShareContextWith."
|
||||
);
|
||||
}
|
||||
target.timeProvider = source.timeProvider;
|
||||
target.canvasHandle = source.canvasHandle;
|
||||
target.contextHandle = source.contextHandle;
|
||||
target.Init();
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal abstract void CreateCanvas();
|
||||
|
||||
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
|
||||
|
||||
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
|
||||
|
||||
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
|
||||
|
||||
#region native camera operation
|
||||
protected abstract void NativeCameraViewRange(Radius FieldOfRange,vec2d offset, (float frontDepth, float backDepth ) viewDepth );
|
||||
protected abstract void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth);
|
||||
protected abstract void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
|
||||
/// <summary>
|
||||
/// Get <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) uniform from a shader.
|
||||
@@ -198,7 +262,7 @@ namespace StgSharp.Graphics
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output);
|
||||
protected abstract void ProcessInput();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region public resource generator
|
||||
@@ -206,19 +270,32 @@ namespace StgSharp.Graphics
|
||||
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
|
||||
protected abstract ShaderProgram CreateShaderProgram();
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class RenderStreamConstructArgs
|
||||
public class RenderStreamConstructArgs : ICloneable
|
||||
{
|
||||
|
||||
public int Height { get; set; }
|
||||
public IntPtr Monitor { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Width { get; set; }
|
||||
public (int x, int y, int z) UnitCubeSize { get; set; }
|
||||
public int Width { get; set; }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
RenderStreamConstructArgs ret = new RenderStreamConstructArgs();
|
||||
ret.Height = Height;
|
||||
ret.Width = Width;
|
||||
ret.Monitor = Monitor;
|
||||
ret.Name = Name;
|
||||
ret.UnitCubeSize = UnitCubeSize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -36,7 +38,7 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
GLcontext* gl = (GLcontext*) GL.CurrentContextHandle;
|
||||
GLcontext* gl = (GLcontext*) glFunc.CurrentContextHandle;
|
||||
foreach (var uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.Value;
|
||||
@@ -59,6 +61,6 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
"Incorrect type \"Unknown\" defined in this self define type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}//------------------------------------ End of Class ---------------------------------------
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using StgSharp.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TexturePipeline:BlueprintPipelineArgs
|
||||
{
|
||||
public TexturePipeline(Image i)
|
||||
{
|
||||
value = i;
|
||||
}
|
||||
|
||||
private Image value;
|
||||
|
||||
public Image Value
|
||||
{
|
||||
get => value;
|
||||
set => value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user