daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IImageProvider.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.Text;
|
||||
|
||||
@@ -7,6 +37,5 @@ namespace StgSharp.Graphics
|
||||
public interface IImageProvider
|
||||
{
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+31
-29
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FormThreading.cs"
|
||||
// file="ImageHelper.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,47 +28,49 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class View
|
||||
public static class ImageHelper
|
||||
{
|
||||
internal Blueprint localLogic;
|
||||
|
||||
/*
|
||||
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
|
||||
public static void Resize(Image i, int width, int height, ImageMovement move)
|
||||
{
|
||||
if (methods.Length == 0)
|
||||
if (i == null)
|
||||
{
|
||||
return;
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
|
||||
Array.Resize(ref i.Data, width * height * i.PixelSize);
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
switch (move)
|
||||
{
|
||||
RenderActivityAttribute attr = m.GetCustomAttribute<RenderActivityAttribute>(false);
|
||||
if (attr == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
|
||||
{
|
||||
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
|
||||
}
|
||||
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
|
||||
FrameAsyncThread thread = new(s, attr._priority);
|
||||
//singleFrameAsyncThreadList.Add(thread);
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
i.PixelUpdateCount++;
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ImageMovement
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
Discard = 0,
|
||||
#pragma warning restore CA1008
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = Top | Left,
|
||||
BottomLeft = Bottom | Left,
|
||||
TopRight = Top | Right,
|
||||
BottomRight = Bottom | Right,
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -28,28 +28,31 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL buffer objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
|
||||
protected GlHandle[] _bufferHandle;
|
||||
protected RenderStream binding;
|
||||
protected glHandleSet _bufferHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public glHandle this[int index] => _bufferHandle[index];
|
||||
public GlHandle this[int index] => _bufferHandle[index];
|
||||
|
||||
/// <summary>
|
||||
/// Bind a buffer instance to OpenGL
|
||||
@@ -66,7 +69,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {GetType().FullName}, containing {_bufferHandle.length} buffer handles: {_bufferHandle.ToString()}.";
|
||||
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
|
||||
}
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -49,22 +49,9 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWcontext
|
||||
{
|
||||
|
||||
private int client;
|
||||
private IntPtr destroy;
|
||||
private delegate*<byte*> extensionSupported;
|
||||
private GLFWbool forward, debug, noerror;
|
||||
|
||||
//PFNGLGETINTEGERVPROC GetIntegerv;
|
||||
private IntPtr GetIntegerv;
|
||||
private delegate*<delegate*<void>, void> getProcAddress;
|
||||
|
||||
//PFNGLGETSTRINGPROC GetString;
|
||||
private IntPtr GetString;
|
||||
|
||||
//PFNGLGETSTRINGIPROC GetStringi;
|
||||
private IntPtr GetStringi;
|
||||
private int major, minor, revision;
|
||||
|
||||
/*
|
||||
void (* makeCurrent) (glfwWindow*);
|
||||
void (* swapBuffers) (glfwWindow*);
|
||||
@@ -75,12 +62,26 @@ namespace StgSharp.Graphics
|
||||
*/
|
||||
|
||||
private delegate*<glfwWindow*> makeCurrent;
|
||||
private delegate*<glfwWindow*> swapBuffer;
|
||||
private delegate*<int> swapInterval;
|
||||
private GLFWbool forward, debug, noerror;
|
||||
|
||||
private int client;
|
||||
private int major, minor, revision;
|
||||
private int profile;
|
||||
private int release;
|
||||
private int robustness;
|
||||
private int source;
|
||||
private delegate*<glfwWindow*> swapBuffer;
|
||||
private delegate*<int> swapInterval;
|
||||
private IntPtr destroy;
|
||||
|
||||
//PFNGLGETINTEGERVPROC GetIntegerv;
|
||||
private IntPtr GetIntegerv;
|
||||
|
||||
//PFNGLGETSTRINGPROC GetString;
|
||||
private IntPtr GetString;
|
||||
|
||||
//PFNGLGETSTRINGIPROC GetStringi;
|
||||
private IntPtr GetStringi;
|
||||
|
||||
internal struct egl
|
||||
{
|
||||
@@ -165,15 +166,16 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWimage
|
||||
{
|
||||
|
||||
/*! The pixel _data of this image, arranged left-to-right, top-to-bottom.
|
||||
*/
|
||||
private byte* pixels;
|
||||
|
||||
/*! The height, in pixels, of this image.
|
||||
*/
|
||||
private int height;
|
||||
/*! The width, in pixels, of this image.
|
||||
*/
|
||||
private int width;
|
||||
/*! The pixel data of this image, arranged left-to-right, top-to-bottom.
|
||||
*/
|
||||
private byte* pixels;
|
||||
|
||||
|
||||
}
|
||||
@@ -182,22 +184,24 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWgamepadstate
|
||||
{
|
||||
|
||||
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
|
||||
* to 1.0 inclusive.
|
||||
*/
|
||||
public fixed float axes[6];
|
||||
|
||||
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
|
||||
* or `GLFW_RELEASE`.
|
||||
*/
|
||||
public fixed byte buttons[15];
|
||||
|
||||
/*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0
|
||||
* to 1.0 inclusive.
|
||||
*/
|
||||
public fixed float axes[6];
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct GLFWallocator
|
||||
{
|
||||
|
||||
private void* user;
|
||||
|
||||
//GLFWallocatefun allocate;
|
||||
private IntPtr allocate;
|
||||
|
||||
@@ -207,34 +211,32 @@ namespace StgSharp.Graphics
|
||||
//GLFWreallocatefun reallocate;
|
||||
private IntPtr reallocate;
|
||||
|
||||
private void* user;
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct glfwMonitor
|
||||
{
|
||||
|
||||
private fixed byte name[128];
|
||||
private IntPtr userPointer;
|
||||
|
||||
private int width, height;
|
||||
private glfwVideomode* modes;
|
||||
|
||||
private glfwWindow* window;
|
||||
|
||||
private glfwVideomode* modes;
|
||||
private int modeCount;
|
||||
private glfwVideomode currentMode;
|
||||
private fixed byte name[128];
|
||||
private glfwGammaramp currentRamp;
|
||||
|
||||
private glfwGammaramp originalRamp;
|
||||
private glfwGammaramp currentRamp;
|
||||
private glfwVideomode currentMode;
|
||||
private int modeCount;
|
||||
|
||||
private int width, height;
|
||||
private IntPtr userPointer;
|
||||
|
||||
public glfwMonitor()
|
||||
{ }
|
||||
|
||||
public unsafe string Name
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
fixed (byte* cptr = name)
|
||||
{
|
||||
@@ -242,69 +244,73 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
unsafe struct glfwWindow
|
||||
{
|
||||
|
||||
glfwWindow* next;
|
||||
|
||||
// Window settings and state
|
||||
int resizable;
|
||||
int decorated;
|
||||
int autoIconify;
|
||||
int floating;
|
||||
int focusOnShow;
|
||||
int mousePassthrough;
|
||||
int shouldClose;
|
||||
void* userPointer;
|
||||
int doublebuffer;
|
||||
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
|
||||
IntPtr monitor; // _GLFWmonitor* monitor;
|
||||
IntPtr cursor; // _GLFWcursor* cursor;
|
||||
|
||||
int minwidth, minheight;
|
||||
int maxwidth, maxheight;
|
||||
int numer, denom;
|
||||
|
||||
int stickyKeys;
|
||||
int stickyMouseButtons;
|
||||
int lockKeyMods;
|
||||
int cursorMode;
|
||||
public fixed byte mouseButtons[GLconst.GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
public fixed byte keys[GLconst.GLFW_KEY_LAST + 1];
|
||||
bool rawMouseMotion;
|
||||
Callbacks callbacks;
|
||||
|
||||
// Virtual cursor position when cursor is disabled
|
||||
double virtualCursorPosX, virtualCursorPosY;
|
||||
bool rawMouseMotion;
|
||||
int autoIconify;
|
||||
int cursorMode;
|
||||
int decorated;
|
||||
int doublebuffer;
|
||||
int floating;
|
||||
int focusOnShow;
|
||||
int lockKeyMods;
|
||||
int maxwidth, maxheight;
|
||||
|
||||
// _GLFWcontext context; // 根据_GLFWcontext的定义转换
|
||||
int minwidth, minheight;
|
||||
int mousePassthrough;
|
||||
int numer, denom;
|
||||
|
||||
// Window settings and state
|
||||
int resizable;
|
||||
int shouldClose;
|
||||
|
||||
int stickyKeys;
|
||||
int stickyMouseButtons;
|
||||
IntPtr cursor; // _GLFWcursor* cursor;
|
||||
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
|
||||
IntPtr monitor; // _GLFWmonitor* monitor;
|
||||
public fixed byte keys[GLconst.GLFW_KEY_LAST + 1];
|
||||
public fixed byte mouseButtons[GLconst.GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
|
||||
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
|
||||
|
||||
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
|
||||
internal struct Callbacks
|
||||
{
|
||||
internal IntPtr pos;
|
||||
internal IntPtr size;
|
||||
internal IntPtr close;
|
||||
internal IntPtr refresh;
|
||||
internal IntPtr focus;
|
||||
internal IntPtr iconify;
|
||||
internal IntPtr maximize;
|
||||
internal IntPtr fbsize;
|
||||
internal IntPtr scale;
|
||||
internal IntPtr mouseButton;
|
||||
internal IntPtr cursorPos;
|
||||
internal IntPtr cursorEnter;
|
||||
internal IntPtr scroll;
|
||||
internal IntPtr key;
|
||||
|
||||
internal IntPtr character;
|
||||
internal IntPtr charmods;
|
||||
internal IntPtr close;
|
||||
internal IntPtr cursorEnter;
|
||||
internal IntPtr cursorPos;
|
||||
internal IntPtr drop;
|
||||
}
|
||||
Callbacks callbacks;
|
||||
internal IntPtr fbsize;
|
||||
internal IntPtr focus;
|
||||
internal IntPtr iconify;
|
||||
internal IntPtr key;
|
||||
internal IntPtr maximize;
|
||||
internal IntPtr mouseButton;
|
||||
internal IntPtr pos;
|
||||
internal IntPtr refresh;
|
||||
internal IntPtr scale;
|
||||
internal IntPtr scroll;
|
||||
internal IntPtr size;
|
||||
|
||||
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
|
||||
}
|
||||
}
|
||||
|
||||
// GLFW_PLATFORM_WINDOW_STATE platformWindowState;
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -345,9 +351,9 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWinitconfig
|
||||
{
|
||||
|
||||
private int angleType;
|
||||
|
||||
private GLFWbool hatButtons;
|
||||
|
||||
private int angleType;
|
||||
private int platformID;
|
||||
|
||||
//PFN_vkGetInstanceProcAddr vulkanLoader;
|
||||
@@ -359,19 +365,20 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWwndconfig
|
||||
{
|
||||
|
||||
private byte* title;
|
||||
|
||||
private GLFWbool autoIconify;
|
||||
private GLFWbool centerCursor;
|
||||
private GLFWbool decorated;
|
||||
private GLFWbool floating;
|
||||
private GLFWbool focused;
|
||||
private GLFWbool focusOnShow;
|
||||
private int height;
|
||||
private GLFWbool maximized;
|
||||
private GLFWbool mousePassthrough;
|
||||
private GLFWbool resizable;
|
||||
private GLFWbool scaleToMonitor;
|
||||
private byte* title;
|
||||
private GLFWbool visible;
|
||||
private int height;
|
||||
private int width;
|
||||
|
||||
private int xpos;
|
||||
@@ -437,19 +444,20 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWctxconfig
|
||||
{
|
||||
|
||||
private int client;
|
||||
private GLFWbool debug;
|
||||
private GLFWbool forward;
|
||||
private GLFWbool noerror;
|
||||
|
||||
private int client;
|
||||
private int major;
|
||||
private int minor;
|
||||
private GLFWbool noerror;
|
||||
private int profile;
|
||||
private int release;
|
||||
private int robustness;
|
||||
private int source;
|
||||
|
||||
//glfwWindow* share;
|
||||
private IntPtr share;
|
||||
private int source;
|
||||
|
||||
internal Nsgl nsgl = new Nsgl();
|
||||
|
||||
@@ -470,6 +478,11 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWfbconfig
|
||||
{
|
||||
|
||||
private GLFWbool doublebuffer;
|
||||
private GLFWbool sRGB;
|
||||
private GLFWbool stereo;
|
||||
private GLFWbool transparent;
|
||||
|
||||
private int accumAlphaBits;
|
||||
private int accumBlueBits;
|
||||
private int accumGreenBits;
|
||||
@@ -478,16 +491,12 @@ namespace StgSharp.Graphics
|
||||
private int auxBuffers;
|
||||
private int blueBits;
|
||||
private int depthBits;
|
||||
private GLFWbool doublebuffer;
|
||||
private int greenBits;
|
||||
private uintptr_t handle;
|
||||
|
||||
private int redBits;
|
||||
private int samples;
|
||||
private GLFWbool sRGB;
|
||||
private int stencilBits;
|
||||
private GLFWbool stereo;
|
||||
private GLFWbool transparent;
|
||||
private uintptr_t handle;
|
||||
|
||||
}
|
||||
|
||||
@@ -495,37 +504,37 @@ namespace StgSharp.Graphics
|
||||
internal unsafe struct GLFWlibrary
|
||||
{
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1)]
|
||||
private GLFWjoystick[] joysticks = new GLFWjoystick[GLconst.GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
private GLFWallocator allocator;
|
||||
|
||||
private GLFWbool initialized;
|
||||
|
||||
private GLFWbool joysticksInitialized;
|
||||
private GLFWls contextSlot;
|
||||
|
||||
private GLFWls errorSlot;
|
||||
private GLFWmutex errorLock;
|
||||
|
||||
private GLFWplatform platform;
|
||||
|
||||
private int mappingCount;
|
||||
|
||||
private int monitorCount;
|
||||
|
||||
//GLFWcursor* cursorListHead;
|
||||
private IntPtr cursorListHead;
|
||||
|
||||
//GLFWerror* errorListHead;
|
||||
private IntPtr errorListHead;
|
||||
private GLFWmutex errorLock;
|
||||
|
||||
private GLFWls errorSlot;
|
||||
|
||||
private GLFWbool initialized;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GLconst.GLFW_JOYSTICK_LAST + 1)]
|
||||
private GLFWjoystick[] joysticks = new GLFWjoystick[GLconst.GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
private GLFWbool joysticksInitialized;
|
||||
|
||||
private int mappingCount;
|
||||
|
||||
//GLFWmapping* mappings;
|
||||
private IntPtr mappings;
|
||||
|
||||
private int monitorCount;
|
||||
|
||||
//GLFWmonitor** monitors;
|
||||
private IntPtr monitors;
|
||||
|
||||
private GLFWplatform platform;
|
||||
|
||||
//glfwWindow* windowListHead;
|
||||
private IntPtr windowListHead;
|
||||
|
||||
@@ -548,8 +557,8 @@ namespace StgSharp.Graphics
|
||||
private GLFWfbconfig framebuffer;
|
||||
|
||||
private GLFWinitconfig init;
|
||||
private int refreshRate;
|
||||
private GLFWwndconfig window;
|
||||
private int refreshRate;
|
||||
|
||||
}
|
||||
|
||||
@@ -566,23 +575,36 @@ namespace StgSharp.Graphics
|
||||
internal unsafe struct Egl
|
||||
{
|
||||
|
||||
internal void* display;
|
||||
|
||||
internal void* handle;
|
||||
|
||||
internal bool ANGLE_platform_angle;
|
||||
internal bool ANGLE_platform_angle_d3d;
|
||||
internal bool ANGLE_platform_angle_metal;
|
||||
internal bool ANGLE_platform_angle_opengl;
|
||||
internal bool ANGLE_platform_angle_vulkan;
|
||||
internal bool EXT_client_extensions;
|
||||
internal bool EXT_platform_base;
|
||||
internal bool EXT_platform_wayland;
|
||||
internal bool EXT_platform_x11;
|
||||
internal bool EXT_present_opaque;
|
||||
internal bool KHR_colorSpace;
|
||||
internal bool KHR_context_flush_control;
|
||||
|
||||
internal bool KHR_create_context;
|
||||
internal bool KHR_create_context_no_error;
|
||||
internal bool KHR_get_all_proc_addresses;
|
||||
internal bool prefix;
|
||||
internal int major, minor;
|
||||
|
||||
internal int platform;
|
||||
internal IntPtr BindAPI;
|
||||
internal IntPtr CreateContext;
|
||||
internal IntPtr CreatePlatformWindowSurfaceEXT;
|
||||
internal IntPtr CreateWindowSurface;
|
||||
internal IntPtr DestroyContext;
|
||||
internal IntPtr DestroySurface;
|
||||
internal void* display;
|
||||
internal bool EXT_client_extensions;
|
||||
internal bool EXT_platform_base;
|
||||
internal bool EXT_platform_wayland;
|
||||
internal bool EXT_platform_x11;
|
||||
internal bool EXT_present_opaque;
|
||||
|
||||
internal IntPtr GetConfigAttrib;
|
||||
internal IntPtr GetConfigs;
|
||||
@@ -591,20 +613,8 @@ namespace StgSharp.Graphics
|
||||
|
||||
internal IntPtr GetPlatformDisplayEXT;
|
||||
internal IntPtr GetProcAddress;
|
||||
|
||||
internal void* handle;
|
||||
internal IntPtr Initialize;
|
||||
internal bool KHR_colorSpace;
|
||||
internal bool KHR_context_flush_control;
|
||||
|
||||
internal bool KHR_create_context;
|
||||
internal bool KHR_create_context_no_error;
|
||||
internal bool KHR_get_all_proc_addresses;
|
||||
internal int major, minor;
|
||||
internal IntPtr MakeCurrent;
|
||||
|
||||
internal int platform;
|
||||
internal bool prefix;
|
||||
internal IntPtr QueryString;
|
||||
internal IntPtr SwapBuffers;
|
||||
internal IntPtr SwapInterval;
|
||||
@@ -615,6 +625,8 @@ namespace StgSharp.Graphics
|
||||
internal unsafe struct Osmesa
|
||||
{
|
||||
|
||||
private void* handle;
|
||||
|
||||
private IntPtr CreateContextAttribs;
|
||||
|
||||
private IntPtr CreateContextExt;
|
||||
@@ -622,8 +634,6 @@ namespace StgSharp.Graphics
|
||||
private IntPtr GetColorBuffer;
|
||||
private IntPtr GetDepthBuffer;
|
||||
private IntPtr GetProcAddress;
|
||||
|
||||
private void* handle;
|
||||
private IntPtr MakeCurrent;
|
||||
|
||||
}
|
||||
@@ -631,17 +641,18 @@ namespace StgSharp.Graphics
|
||||
internal unsafe struct vk
|
||||
{
|
||||
|
||||
private void* handle;
|
||||
|
||||
private GLFWbool available;
|
||||
private GLFWbool EXT_metal_surface;
|
||||
private fixed ulong extensions[2];
|
||||
private IntPtr GetInstanceProcAddr;
|
||||
private void* handle;
|
||||
private GLFWbool KHR_surface;
|
||||
private GLFWbool KHR_wayland_surface;
|
||||
private GLFWbool KHR_win32_surface;
|
||||
private GLFWbool KHR_xcb_surface;
|
||||
private GLFWbool KHR_xlib_surface;
|
||||
private GLFWbool MVK_macos_surface;
|
||||
private IntPtr GetInstanceProcAddr;
|
||||
private fixed ulong extensions[2];
|
||||
|
||||
public vk()
|
||||
{
|
||||
@@ -664,12 +675,13 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWmapelement
|
||||
{
|
||||
|
||||
private sbyte axisOffset;
|
||||
private sbyte axisScale;
|
||||
private byte index;
|
||||
|
||||
private byte type;
|
||||
|
||||
private sbyte axisOffset;
|
||||
private sbyte axisScale;
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -694,20 +706,21 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWjoystick
|
||||
{
|
||||
|
||||
private GLFWbool allocated;
|
||||
private float* axes;
|
||||
private byte* buttons;
|
||||
private byte* hats;
|
||||
private void* userPointer;
|
||||
private fixed byte guid[33];
|
||||
private fixed byte name[128];
|
||||
|
||||
private GLFWbool allocated;
|
||||
private GLFWbool connected;
|
||||
private int axisCount;
|
||||
private int buttonCount;
|
||||
private byte* buttons;
|
||||
private GLFWbool connected;
|
||||
private fixed byte guid[33];
|
||||
private int hatCount;
|
||||
private byte* hats;
|
||||
|
||||
//GLFWmapping* mapping;
|
||||
private IntPtr mapping;
|
||||
private fixed byte name[128];
|
||||
private void* userPointer;
|
||||
|
||||
// This is defined in platform.h
|
||||
// not completed in transforming
|
||||
@@ -730,12 +743,12 @@ namespace StgSharp.Graphics
|
||||
public unsafe struct GLFWplatform
|
||||
{
|
||||
|
||||
private int platformID;
|
||||
|
||||
// init
|
||||
//GLFWbool(*init)(void);
|
||||
private IntPtr init;
|
||||
|
||||
private int platformID;
|
||||
|
||||
//void (* terminate) (void);
|
||||
private IntPtr terminate;
|
||||
internal IntPtr createCursor;
|
||||
@@ -953,6 +966,9 @@ namespace StgSharp.Graphics
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GLsync
|
||||
{
|
||||
|
||||
public IntPtr Handle;
|
||||
|
||||
}
|
||||
|
||||
#endregion glad struct
|
||||
|
||||
@@ -28,14 +28,6 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
/*
|
||||
* This file is created to link functions in OpenGL to version in C#
|
||||
* The name of delegates and organization to init all these delegates
|
||||
* are refferd from GLAD1 in agreement of MIT license generated from
|
||||
* https://glad.dav1d.de/
|
||||
*/
|
||||
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -44,19 +36,22 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
#region StgSharpDele
|
||||
|
||||
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Function handler to load an opengl function by searching its name.
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the Opengl function</param>
|
||||
/// <returns>An intptr value representing the pointer to the function</returns>
|
||||
/// <returns>An Intptr value representing the pointer to the function</returns>
|
||||
public delegate IntPtr glLoader(string name);
|
||||
|
||||
#region StgSharpDele
|
||||
|
||||
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
|
||||
|
||||
public unsafe delegate void FramePositionHandler(IntPtr window, float width, float height);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region glDEBUG
|
||||
|
||||
internal unsafe delegate void GLDEBUGPROC(int source, int type, uint id, int severity, int length, sbyte* message, void* userParam);
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
//rename types in style of GLconst
|
||||
|
||||
@@ -4849,13 +4849,18 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
public static class glAttachment
|
||||
{
|
||||
|
||||
public const uint Depth = GLconst.DEPTH_ATTACHMENT;
|
||||
public const uint DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT;
|
||||
public const uint Stencil = GLconst.STENCIL_ATTACHMENT;
|
||||
|
||||
private static int colorRange =
|
||||
glFunc.GetMaskInteger((uint)GLconst.MAX_COLOR_ATTACHMENTS);
|
||||
OpenGLFunction.CurrentGL.GetMaskInteger((uint)GLconst.MAX_COLOR_ATTACHMENTS);
|
||||
|
||||
public static uint Color(int i)
|
||||
{
|
||||
#if DEBUG
|
||||
if (i>colorRange||i<0)
|
||||
if ((i > colorRange) || (i < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -4863,8 +4868,5 @@ namespace StgSharp.Graphics.GL
|
||||
return (uint)(GLconst.COLOR_ATTACHMENT0 + i);
|
||||
}
|
||||
|
||||
public const uint Depth = GLconst.DEPTH_ATTACHMENT;
|
||||
public const uint Stencil = GLconst.STENCIL_ATTACHMENT;
|
||||
public const uint DepthAndStencil = GLconst.DEPTH_STENCIL_ATTACHMENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,11 @@
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public enum ImageChannelLayout
|
||||
public enum PixelChannelLayout
|
||||
{
|
||||
UByte = GLconst.UNSIGNED_BYTE,
|
||||
Byte = GLconst.BYTE,
|
||||
@@ -41,20 +43,31 @@ namespace StgSharp.Graphics.GL
|
||||
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
|
||||
UByte332 = GLconst.UNSIGNED_BYTE_3_3_2,
|
||||
UByte233Rev = GLconst.UNSIGNED_BYTE_2_3_3_REV,
|
||||
UShort565 = GLconst.UNSIGNED_SHORT_5_6_5,
|
||||
UShort565Rev = GLconst.UNSIGNED_SHORT_5_6_5_REV,
|
||||
UShort4444 = GLconst.UNSIGNED_SHORT_4_4_4_4,
|
||||
UShort4444Rev = GLconst.UNSIGNED_SHORT_4_4_4_4_REV,
|
||||
UShort5551 = GLconst.UNSIGNED_SHORT_5_5_5_1,
|
||||
UShort1555Rev = GLconst.UNSIGNED_SHORT_1_5_5_5_REV,
|
||||
UInt8888 = GLconst.UNSIGNED_INT_8_8_8_8,
|
||||
UInt8888Rev = GLconst.UNSIGNED_INT_8_8_8_8_REV,
|
||||
UInt1010102 = GLconst.UNSIGNED_INT_10_10_10_2,
|
||||
UInt2101010Rev = GLconst.UNSIGNED_INT_2_10_10_10_REV
|
||||
}
|
||||
|
||||
public enum FrameBufferStatus
|
||||
{
|
||||
Complete = GLconst.FRAMEBUFFER_COMPLETE, // GL_FRAMEBUFFER_COMPLETE
|
||||
IncompleteAttachment = GLconst.FRAMEBUFFER_INCOMPLETE_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
||||
IncompleteMissingAttachment = GLconst.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
||||
IncompleteDrawBuffer = GLconst.FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
|
||||
IncompleteReadBuffer = GLconst.FRAMEBUFFER_INCOMPLETE_READ_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
|
||||
Unsupported = GLconst.FRAMEBUFFER_UNSUPPORTED, // GL_FRAMEBUFFER_UNSUPPORTED
|
||||
IncompleteMultisample = GLconst.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
|
||||
IncompleteLayerTargets = GLconst.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS // GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
|
||||
}
|
||||
|
||||
internal enum VkStructureType : uint
|
||||
{
|
||||
@@ -81,6 +94,12 @@ namespace StgSharp.Graphics.GL
|
||||
BGRA = GLconst.BGRA
|
||||
}
|
||||
|
||||
public enum FrameBufferAttachment
|
||||
{
|
||||
Color = GLconst.COLOR_ATTACHMENT0,
|
||||
Depth = GLconst.DEPTH_ATTACHMENT,
|
||||
Stencil = GLconst.STENCIL_ATTACHMENT,
|
||||
}
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
|
||||
@@ -103,7 +103,6 @@ namespace StgSharp.Graphics
|
||||
internal unsafe delegate void GLFWkeyfun(glfwWindow* window, int key, int scancode, int action, int mods);
|
||||
internal unsafe delegate void GLFWjoystickfun(int jid, int keyevent);
|
||||
public unsafe delegate void GLFWglproc();
|
||||
internal unsafe delegate void FramebuffersizeHandler(IntPtr window, int width, int height); //window is the pointer to a glfwWindow instance
|
||||
internal unsafe delegate void GLFWerrorfun(int error_code, sbyte* description);
|
||||
internal unsafe delegate void GLFWdropfun(glfwWindow* window, int path_count, sbyte*[] paths);
|
||||
internal unsafe delegate void GLFWcursorposfun(glfwWindow* window, double xpos, double ypos);
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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,
|
||||
Draw = GLconst.DRAW_FRAMEBUFFER,
|
||||
}
|
||||
|
||||
public class FrameBuffer : BufferObjectBase
|
||||
{
|
||||
internal unsafe FrameBuffer(int count, glRenderStream contextBinding)
|
||||
{
|
||||
binding = contextBinding;
|
||||
_bufferHandle = new glHandleSet(count);
|
||||
((GLcontext*)binding.ContextHandle)->glGenFramebuffers((uint)count,_bufferHandle.handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified by target.
|
||||
/// <see langword="FrameBufferTarget.All"/> will be set as default target.
|
||||
/// </summary>
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
public unsafe override void Bind(int index)
|
||||
{
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,_bufferHandle[index]);
|
||||
}
|
||||
|
||||
public static void BindNull()
|
||||
{
|
||||
glFunc.BindFrameBuffer(FrameBufferTarget.All,glHandle.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified by target.
|
||||
/// Target of this frame buffer should be set manually.
|
||||
/// </summary>
|
||||
/// <param name="target">The frame buffer target of the binding operation.</param>
|
||||
/// <param name="index">Index of object to be binded in handle set</param>
|
||||
public unsafe void Bind(FrameBufferTarget target, int index)
|
||||
{
|
||||
((GLcontext*)binding.ContextHandle)->glBindFramebuffer((uint)target, _bufferHandle[index].Value);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLhandle.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.Data.Common;
|
||||
using System.Linq;
|
||||
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;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object,
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
/// Direct call will cause <see langword="InvalidOperationException"/>
|
||||
/// </summary>
|
||||
public unsafe class glHandle: IDisposable
|
||||
{
|
||||
private static uint* zeroHandle = (uint*)Marshal.AllocHGlobal(Marshal.SizeOf<uint>());
|
||||
|
||||
internal uint* source;
|
||||
internal uint* valuePtr;
|
||||
|
||||
private glHandle(IntPtr handle)
|
||||
{
|
||||
this.valuePtr = (uint*)handle;
|
||||
source = (uint*)0;
|
||||
}
|
||||
|
||||
private glHandle(uint value)
|
||||
{
|
||||
source = (uint*)0;
|
||||
valuePtr = (uint*)Marshal.AllocHGlobal(sizeof(uint));
|
||||
*valuePtr = value;
|
||||
}
|
||||
|
||||
internal glHandle(uint* val, glHandleSet set)
|
||||
{
|
||||
source = set!=null ? set!.handle:(uint*)0;
|
||||
valuePtr = val;
|
||||
}
|
||||
|
||||
[Obsolete("Cannot init instance of this type", true)]
|
||||
public glHandle()
|
||||
{
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get=> (IntPtr)valuePtr;
|
||||
}
|
||||
|
||||
public bool IsIsolated
|
||||
{
|
||||
get => source == (uint*)0;
|
||||
}
|
||||
|
||||
public uint Value
|
||||
{
|
||||
get => *valuePtr;
|
||||
set => *valuePtr = value;
|
||||
}
|
||||
|
||||
public static glHandle ZeroHandle => FromPtr(IntPtr.Zero);
|
||||
|
||||
public static glHandle Zero => Alloc(0);
|
||||
|
||||
public static glHandle Alloc(uint value)
|
||||
{
|
||||
return new glHandle(value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glHandle FromPtr(IntPtr p)
|
||||
{
|
||||
return new glHandle(p);
|
||||
}
|
||||
|
||||
~glHandle()
|
||||
{
|
||||
if (valuePtr != zeroHandle && IsIsolated)
|
||||
{
|
||||
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
|
||||
{
|
||||
private static int* zeroHandle = (int*)Marshal.AllocHGlobal(Marshal.SizeOf<int>());
|
||||
|
||||
internal int* source;
|
||||
internal int* valuePtr;
|
||||
|
||||
private glSHandle(IntPtr handle)
|
||||
{
|
||||
this.valuePtr = (int*)handle;
|
||||
source = (int*)0;
|
||||
}
|
||||
|
||||
private glSHandle(int value)
|
||||
{
|
||||
source = (int*)0;
|
||||
valuePtr = (int*)Marshal.AllocHGlobal(sizeof(int));
|
||||
*valuePtr = value;
|
||||
}
|
||||
|
||||
internal glSHandle(int* val, glHandleSet set)
|
||||
{
|
||||
source = set != null ? (int*)set!.handle : (int*)0;
|
||||
valuePtr = val;
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Cannot init instance of this type", true)]
|
||||
public glSHandle()
|
||||
{
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get => (IntPtr)valuePtr;
|
||||
}
|
||||
|
||||
public bool IsIsolated
|
||||
{
|
||||
get => source == (uint*)0;
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get => *valuePtr;
|
||||
set => *valuePtr = value;
|
||||
}
|
||||
|
||||
public static glSHandle Zero => Alloc(0);
|
||||
|
||||
public static glSHandle Alloc(int value)
|
||||
{
|
||||
return new glSHandle(value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glSHandle FromPtr(IntPtr p)
|
||||
{
|
||||
return new glSHandle(p);
|
||||
}
|
||||
|
||||
~glSHandle()
|
||||
{
|
||||
if (valuePtr != zeroHandle && IsIsolated)
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)valuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe class glArrayHandle
|
||||
{
|
||||
internal readonly Array a;
|
||||
internal GCHandle handle;
|
||||
private bool disposedValue;
|
||||
|
||||
internal glArrayHandle(Array array)
|
||||
{
|
||||
this.a = array;
|
||||
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IntPtr AddressOfArray()
|
||||
{
|
||||
if (handle != default)
|
||||
{
|
||||
return handle.AddrOfPinnedObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle Alloc<T>(T[] array) where T : struct
|
||||
{
|
||||
return new glArrayHandle(array);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
|
||||
{
|
||||
Array copy = new T[array.Length];
|
||||
array.CopyTo(copy, 0);
|
||||
return new glArrayHandle(copy);
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
handle.Free();
|
||||
handle = default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object.
|
||||
/// </summary>
|
||||
public unsafe class glHandleSet
|
||||
{
|
||||
|
||||
private readonly uint[] _value;
|
||||
internal uint* handle;
|
||||
internal int length;
|
||||
|
||||
public glHandleSet(int count)
|
||||
{
|
||||
_value = new uint[count];
|
||||
length = count;
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get => (IntPtr)handle;
|
||||
}
|
||||
|
||||
public glHandle this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new glHandle(handle + index, this);
|
||||
}
|
||||
}
|
||||
|
||||
public glSHandle this[uint index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index > length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new glSHandle(((int*)handle) + index, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy(in glHandleSet source, glHandleSet target)
|
||||
{
|
||||
if ((source == null) || (target == null))
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
if (source.length != target.length)
|
||||
{
|
||||
throw new Exception($"Lengths of {nameof(source)} and {nameof(target)} are not equal.");
|
||||
}
|
||||
for (int i = 0; i < source.length; i++)
|
||||
{
|
||||
target._value[i] = source._value[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void Pin()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release all resource in this handle.
|
||||
/// This will release all resource in this <see cref="glHandle"/>.
|
||||
/// This <see langword="glHandle"/> will be not usable.
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)handle).Free();
|
||||
handle = (uint*)IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetValue(int index, uint value)
|
||||
{
|
||||
_value[index] = value;
|
||||
}
|
||||
|
||||
~glHandleSet()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
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 SetAllUniforms();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Uniform.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.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
protected IntPtr binding;
|
||||
internal glSHandle id;
|
||||
|
||||
|
||||
public glSHandle Handle
|
||||
{
|
||||
get => id;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform
|
||||
where T : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U>: Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V>:Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string 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 = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T,U,V> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W>:Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
|
||||
internal unsafe Uniform(glSHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(glSHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V, W>() { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static partial class glFunc
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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 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 static unsafe void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.Value , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.Value , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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 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 SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IGraphicAPIs.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.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IGraphicAPIs
|
||||
{
|
||||
|
||||
public IntPtr GraphicApiPackageHandle { get; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+151
-104
@@ -29,11 +29,12 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -45,37 +46,82 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
internal byte[] data;
|
||||
internal ImageInfo info;
|
||||
private byte[] _data;
|
||||
private ImageInfo info;
|
||||
private int _pixelUpdateCount = 0;
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
info = information;
|
||||
data = Array.Empty<byte>();
|
||||
//int length = info.width * info.height * info.channel;
|
||||
}
|
||||
|
||||
public ref byte[] DataStream
|
||||
{
|
||||
get => ref data;
|
||||
}
|
||||
|
||||
public unsafe Image()
|
||||
internal unsafe Image()
|
||||
{
|
||||
info = new ImageInfo();
|
||||
}
|
||||
|
||||
public ImageChannel Channel => info.Channel;
|
||||
public int ChannelCount => info.ChannelCount;
|
||||
public int Height => info.Height;
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
info = information;
|
||||
_data = Array.Empty<byte>();
|
||||
//int length = info.width * info.height * info.channel;
|
||||
}
|
||||
|
||||
internal ref byte[] Data
|
||||
{
|
||||
get => ref _data;
|
||||
}
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
get => (info.Width, info.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hash code of time pixels updated last time.
|
||||
/// </summary>
|
||||
public int PixelUpdateCount
|
||||
{
|
||||
get => _pixelUpdateCount;
|
||||
internal set => _pixelUpdateCount = value;
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((_data.Length == 0) || (_data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return _data!;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageChannel Channel => info.Channel;
|
||||
public int ChannelCount => info.ChannelCount;
|
||||
public int Height
|
||||
{
|
||||
get => info.Height;
|
||||
internal set => info.Height = value;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => info.Width;
|
||||
internal set => info.Width = value;
|
||||
}
|
||||
|
||||
public int PixelSize => GlHelper.GetPixelSize(info.pixelLayout, info.Channel);
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => info.pixelLayout;
|
||||
private set => info.pixelLayout = value;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public int Width => info.Width;
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
@@ -87,76 +133,57 @@ namespace StgSharp.Graphics
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, int channelCount, byte[] stream)
|
||||
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
ChannelCount = channelCount,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.data = stream;
|
||||
ret.PixelLayout = PixelChannelLayout.Byte;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public glArrayHandle GetArrayHandle()
|
||||
public static Image FromMemory((int width, int height) size, ImageChannel channel, PixelChannelLayout layout, byte[] stream)
|
||||
{
|
||||
if ((data == Array.Empty<byte>()) || (data == null))
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
this.GetBytes();
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
return new glArrayHandle(data);
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = layout;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (data == null)
|
||||
if (_data.Length == 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
int size = Width * Height * GlHelper.GetPixelSize(PixelLayout, Channel);
|
||||
_data = new Span<byte>((byte*)info.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return data;
|
||||
return _data;
|
||||
}
|
||||
public Image ProvideImage() => this;
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
byte[] ISSDSerializable.GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
~Image()
|
||||
{
|
||||
if (info.StreamPtr != IntPtr.Zero)
|
||||
{
|
||||
// Marshal.FreeHGlobal(info.StreamPtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -164,53 +191,20 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
|
||||
private ImageChannel channel;
|
||||
private int channelCount;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
internal PixelChannelLayout pixelLayout;
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
get => GlHelper.GetChannelCount(channel);
|
||||
}
|
||||
|
||||
public int Height
|
||||
@@ -219,15 +213,9 @@ namespace StgSharp.Graphics
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * channelCount;
|
||||
get => width * height * GlHelper.GetPixelSize(pixelLayout, channel);
|
||||
}
|
||||
|
||||
public int Width
|
||||
@@ -236,20 +224,79 @@ namespace StgSharp.Graphics
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 17 + width;
|
||||
hash = hash * 17 + height;
|
||||
hash = hash * 17 + (int)channel;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
SingleColor = GLconst.RED,
|
||||
DoubleColor = GLconst.RG,
|
||||
FullColor = GLconst.RGB,
|
||||
TripleColor = GLconst.RGB,
|
||||
WithAlphaChannel = GLconst.RGBA,
|
||||
}
|
||||
}
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public static partial class GlHelper
|
||||
{
|
||||
|
||||
internal static int GetChannelCount(ImageChannel channel)
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
ImageChannel.SingleColor => 1,
|
||||
ImageChannel.DoubleColor => 2,
|
||||
ImageChannel.TripleColor => 3,
|
||||
ImageChannel.WithAlphaChannel => 4,
|
||||
_ => throw new InvalidCastException("Unknown color channel decoding setting.")
|
||||
};
|
||||
}
|
||||
|
||||
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel cahnnel)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.Short => sizeof(short) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.Int => sizeof(int) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.Float => sizeof(float) * GetChannelCount(cahnnel),
|
||||
PixelChannelLayout.UByte332 => sizeof(byte),
|
||||
PixelChannelLayout.UByte233Rev => sizeof(byte),
|
||||
PixelChannelLayout.UShort565 => sizeof(short),
|
||||
PixelChannelLayout.UShort565Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort4444 => sizeof(short),
|
||||
PixelChannelLayout.UShort4444Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort5551 => sizeof(short),
|
||||
PixelChannelLayout.UShort1555Rev => sizeof(short),
|
||||
PixelChannelLayout.UInt8888 => sizeof(int),
|
||||
PixelChannelLayout.UInt8888Rev => sizeof(int),
|
||||
PixelChannelLayout.UInt1010102 => sizeof(int),
|
||||
PixelChannelLayout.UInt2101010Rev => sizeof(int),
|
||||
_ => throw new ArgumentException("Unknown layout type"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="AutoTexture.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.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using StgSharp.Collections;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class AutoTextureGL
|
||||
{
|
||||
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 TextureProperty[] propertyCache;
|
||||
private TextureGL texturePackage;
|
||||
|
||||
private TextureProperty _textureProperty;
|
||||
|
||||
private OpenGLFunction GL
|
||||
{
|
||||
get => texturePackage.GL;
|
||||
}
|
||||
|
||||
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]glRenderStream 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;
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+12
-12
@@ -28,6 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -36,47 +38,45 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of handle to Element Buffer Object in OpenglFunc.
|
||||
/// Each <see langword="uint"/> value indexed from instance of this class this
|
||||
/// is the only handle to one Element Buffer Object.
|
||||
/// </summary>
|
||||
public unsafe class ElementBuffer : BufferObjectBase
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRenderStream binding)
|
||||
internal ElementBuffer(int n, glRenderStream binding) : base(binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ElementArrayBuffer, bufferArray, usage);
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.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);
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FBO.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.Graphics.OpenGL;
|
||||
|
||||
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
|
||||
public enum FrameBufferTarget : uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
Read = GLconst.READ_FRAMEBUFFER,
|
||||
All = GLconst.FRAMEBUFFER,
|
||||
Draw = GLconst.DRAW_FRAMEBUFFER,
|
||||
}
|
||||
|
||||
public sealed class FrameBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal unsafe FrameBuffer(int count, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenFrameBuffers(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame buffer object with name frame buffer to the frame buffer target specified by target.
|
||||
/// <see langword="FrameBufferTarget.All"/> will be set as default target.
|
||||
/// </summary>
|
||||
/// <param name="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 buffer object with name frame buffer to the frame buffer target specified by target.
|
||||
/// Target of this frame buffer should be set manually.
|
||||
/// </summary>
|
||||
/// <param name="target">The frame buffer target of the binding operation.</param>
|
||||
/// <param name="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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLBufferObjectBase.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.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract class GlBufferObjectBase : BufferObjectBase
|
||||
{
|
||||
|
||||
private readonly glRenderStream _contextBinding;
|
||||
|
||||
protected GlBufferObjectBase(glRenderStream contextBinding)
|
||||
{
|
||||
binding = contextBinding;
|
||||
_contextBinding = contextBinding;
|
||||
}
|
||||
|
||||
protected OpenGLFunction GL => _contextBinding.GL;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="RBO.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.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
|
||||
|
||||
|
||||
public sealed class RenderBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
public RenderBuffer(int count, glRenderStream binding) : base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenRenderBuffer(count);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
StgSharp.LogWarning("FrameBuffer is larger than current canvas binding");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TextureGL.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.Data;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class TextureGL
|
||||
{
|
||||
|
||||
private int currentEditingTextureIndex;
|
||||
|
||||
private OpenGLFunction _gl;
|
||||
internal GlHandle[] _textureHandle;
|
||||
|
||||
internal TextureGL( int count, glRenderStream binding )
|
||||
{
|
||||
//sourceList = new Image[count];
|
||||
this._gl = binding.GL;
|
||||
_textureHandle = _gl.GenTextures( count );
|
||||
}
|
||||
|
||||
internal OpenGLFunction GL => _gl;
|
||||
|
||||
public GlHandle this[ int index ]
|
||||
{
|
||||
get => _textureHandle[ index ];
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => _textureHandle.Length;
|
||||
}
|
||||
|
||||
//internal Image[] sourceList;
|
||||
|
||||
public int IndexOfCurrentTexture
|
||||
{
|
||||
get => currentEditingTextureIndex;
|
||||
}
|
||||
|
||||
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 name="index"> </param>
|
||||
/// <param name="i"> </param>
|
||||
public unsafe void LoadTexture( int index, Image i )
|
||||
{
|
||||
byte[] handle = i.PixelBuffer;
|
||||
_gl.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, ( uint )i.Channel, ( uint )i.Width, ( uint )i.Height,
|
||||
( uint )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 onHorizontial,
|
||||
TextureWrap onVertical )
|
||||
{
|
||||
FilterOnMagnify = onMagnify;
|
||||
FilterOnMinify = onMinify;
|
||||
WrapOnHorizontial = onHorizontial;
|
||||
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 int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial, WrapOnVertical );
|
||||
}
|
||||
|
||||
public override bool Equals([NotNullWhen(true)] object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"FilterOnMagnify:{FilterOnMagnify}, " +
|
||||
$"FilterOnMagnify:{FilterOnMagnify}, " +
|
||||
$"WrapOnHorizontial:{WrapOnHorizontial}, " +
|
||||
$"WrapOnVertical:{WrapOnVertical}";
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureFilter
|
||||
#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 TextureWrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Repeat = GLconst.REPEAT,
|
||||
MirroredRepeat = GLconst.MIRRORED_REPEAT,
|
||||
ClampToEdge = GLconst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = GLconst.CLAMP_TO_BORDER,
|
||||
|
||||
}
|
||||
}
|
||||
+9
-11
@@ -35,33 +35,32 @@ using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe class VertexArray : BufferObjectBase
|
||||
public sealed unsafe class VertexArray : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray(int n, glRenderStream binding)
|
||||
internal VertexArray(int n, glRenderStream binding) : base(binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenVertexArrays(n);
|
||||
_bufferHandle = GL.GenVertexArrays(n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
glFunc.BindVertexArray(_bufferHandle[index]);
|
||||
GL.BindVertexArray(_bufferHandle[index]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindNull()
|
||||
{
|
||||
glFunc.BindVertexArray(glHandle.Zero);
|
||||
OpenGLFunction.CurrentGL.BindVertexArray(GlHandle.Zero);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
public void SetVertexAttribute(uint index, int vertexLength, TypeCode dataType, bool isNomalized, uint stride, int pointer)
|
||||
{
|
||||
glFunc.SetVertexAttribute(
|
||||
GL.SetVertexAttribute(
|
||||
index, vertexLength, dataType,
|
||||
isNomalized,
|
||||
stride, pointer);
|
||||
@@ -71,8 +70,7 @@ namespace StgSharp.Graphics.GL
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
glFunc.DeleteVertexArrays(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
+85
-88
@@ -28,7 +28,6 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -39,98 +38,19 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe class VertexBuffer : BufferObjectBase
|
||||
public sealed unsafe class VertexBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer(int n, glRenderStream binding)
|
||||
internal VertexBuffer(int n, glRenderStream binding) : base(binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
_bufferHandle = glFunc.GenBuffers(n);
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public override sealed void Bind(int index)
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferData">Data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteMatrixData<T>(int index, T bufferData, BufferUsage usage)
|
||||
where T : struct, IMat
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, bufferData, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferArray">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, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <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, ReadOnlySpan<T> scalerSpan, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <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, ReadOnlySpan<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="vectorArray">A array 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, T[] vectorArray, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
glFunc.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,15 +59,92 @@ namespace StgSharp.Graphics.GL
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Unbind()
|
||||
{
|
||||
glFunc.BindBuffer(BufferType.ArrayBuffer, glHandle.Zero);
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, GlHandle.Zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferData">Data to write in</param>
|
||||
/// <param name="usage">How OpenGL use these _data, defined by <see cref="BufferUsage"/></param>
|
||||
public void WriteMatrixData<T>(int index, T bufferData, BufferUsage usage)
|
||||
where T : struct, IMat
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, bufferData, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="bufferArray">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, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <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, ReadOnlySpan<T> scalerSpan, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <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, ReadOnlySpan<T> vectorSpan, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex buffer object
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of bufferData</typeparam>
|
||||
/// <param name="index">Index to find certain VBO in this instance</param>
|
||||
/// <param name="vectorArray">A array 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, T[] vectorArray, BufferUsage usage) where T : struct, IVector
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
protected override sealed void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
glFunc.DeleteBuffers(_bufferHandle);
|
||||
_bufferHandle.Release();
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GlHandle.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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
#if Windows
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
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;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 4)]
|
||||
public struct GlHandle
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public int SignedValue;
|
||||
[FieldOffset(0)] public uint Value;
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
get => new GlHandle { Value = 0 };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle Alloc(uint value)
|
||||
{
|
||||
return new GlHandle { Value = value };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle SignedAlloc(int value)
|
||||
{
|
||||
return new GlHandle { SignedValue = value };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IglConvertable.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.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();
|
||||
|
||||
}
|
||||
}
|
||||
+72
-67
@@ -39,43 +39,45 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( glFunc.CreateShaderSet(count, type), type);
|
||||
}
|
||||
/// <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()
|
||||
protected override sealed ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected override sealed Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader(GL.CreateShaderSet(count, type), type, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly IntPtr context;
|
||||
internal readonly glHandleSet handle;
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle[] handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
internal unsafe Shader(GlHandle[] handle, ShaderType usage, glRenderStream stream)
|
||||
{
|
||||
this.handle = handle;
|
||||
context = glFunc.CurrentContextHandle;
|
||||
GL = stream.GL;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
@@ -84,7 +86,45 @@ namespace StgSharp.Graphics.GL
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(int index, ShaderProgram target)
|
||||
{
|
||||
glFunc.AttachShader(target.handle, handle[index]);
|
||||
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 Exception($"{$"Shader Error \t{status}\n"}{log}");
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, byte[] codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(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)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
GL.LoadShaderSource(handle[index], Encoding.ASCII.GetBytes(codeStream));
|
||||
GL.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
@@ -97,58 +137,21 @@ namespace StgSharp.Graphics.GL
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, byte[] codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
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()}.";
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
throw new Exception($"Shader Error \t{status}\n" + log);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetBytes(out int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] stream)
|
||||
public override string ToString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
@@ -158,16 +161,17 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
private readonly IntPtr binding;
|
||||
internal readonly glHandle handle;
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle handle;
|
||||
|
||||
/// <summary>
|
||||
/// Init a program with no shader attached.
|
||||
/// CustomizeInit a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
handle = glFunc.CreateProgram();
|
||||
GL = binding.GL;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,7 +183,7 @@ namespace StgSharp.Graphics.GL
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
|
||||
{
|
||||
return new Uniform<T>(this, name, binding);
|
||||
return new Uniform<T>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -192,7 +196,7 @@ namespace StgSharp.Graphics.GL
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
return new Uniform<T, U>(this, name, binding);
|
||||
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,8 +210,9 @@ namespace StgSharp.Graphics.GL
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
return new Uniform<T, U, V>(this, name);
|
||||
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.
|
||||
@@ -220,15 +225,15 @@ namespace StgSharp.Graphics.GL
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
return new Uniform<T, U, V, W>(this, name);
|
||||
return new Uniform<T, U, V, W>(GL.GetUniformLocation(this.handle, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current context.
|
||||
/// Link the shader to current viewPortDisplay.
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if (InternalIO.InternalLinkShaderProgram((GLcontext*)this.binding, handle.Value) == 0)
|
||||
if (InternalIO.InternalLinkShaderProgram((OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadSSCLog();
|
||||
try
|
||||
@@ -247,12 +252,12 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current context use this shader.
|
||||
/// Let the current viewPortDisplay use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
glFunc.UseProgram(handle);
|
||||
GL.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
@@ -0,0 +1,206 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Uniform.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.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle
|
||||
{
|
||||
get => id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform
|
||||
where T : struct
|
||||
{
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U> : Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
{
|
||||
|
||||
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T, U> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V> : Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
{
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W> : Uniform
|
||||
where T : struct
|
||||
where U : struct
|
||||
where V : struct
|
||||
where W : struct
|
||||
{
|
||||
|
||||
internal Uniform()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal unsafe Uniform(GlHandle id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle(GlHandle handle)
|
||||
{
|
||||
return new Uniform<T, U, V, W> { id = handle };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue
|
||||
(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
{
|
||||
Matrix44 temp = mat;
|
||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, false, (float*)&temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.SignedValue, v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.SignedValue, i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.SignedValue, v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.SignedValue, v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glAPICalling.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.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class OpenGLAPICallingAttribute : Attribute
|
||||
{
|
||||
|
||||
public OpenGLAPICallingAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+75
-57
@@ -29,6 +29,9 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.MVVM.View;
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,7 +40,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
@@ -45,8 +48,7 @@ namespace StgSharp.Graphics.GL
|
||||
private const int glExtension = 0x1f03;
|
||||
private const int glVersion = 0x1f02;
|
||||
|
||||
private static readonly string[] glBranch =
|
||||
new string[] {
|
||||
private static readonly string[] glBranch = {
|
||||
"OpenGL ES-CM ",
|
||||
"OpenGL ES-CL ",
|
||||
"OpenGL ES ",
|
||||
@@ -55,17 +57,34 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
private static string glExtensionList;
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> context.
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this ViewPort vp)
|
||||
/// <param name="name">ContextName of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
|
||||
public static IntPtr LoadGLfunc(string name)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)vp.GraphicHandle;
|
||||
delegate*<string,IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
#pragma warning disable CS8909
|
||||
if (context->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
#pragma warning restore CS8909
|
||||
IntPtr ret = InternalIO.glfwGetProcAddress(name);
|
||||
if (ret == default)
|
||||
{
|
||||
InternalIO.InternalAppendLog(
|
||||
$"Cannot load OpenGL api called {name}, this api may not exist or supported.");
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/>.
|
||||
/// </summary>
|
||||
/// <param name="contextHandle">The handle to current OpenGL viewPortDisplay</param>
|
||||
public static unsafe void LoadOpenGLApiTo(IntPtr contextHandle)
|
||||
{
|
||||
OpenglContext* context = (OpenglContext*)contextHandle;
|
||||
delegate*<string, IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
if ((IntPtr)context->glGetString != IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -73,7 +92,7 @@ namespace StgSharp.Graphics.GL
|
||||
if (proc == IntPtr.Zero)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Cannot load glFunc.");
|
||||
Console.WriteLine("Cannot load GL.");
|
||||
#endif
|
||||
throw new Exception("Cannot load gl");
|
||||
}
|
||||
@@ -84,7 +103,7 @@ namespace StgSharp.Graphics.GL
|
||||
{
|
||||
InternalIO.InternalWriteLog("Failed to call glGetString", LogType.Error);
|
||||
}
|
||||
coreVersion = Marshal.PtrToStringAnsi(context->glGetString(glVersion));
|
||||
coreVersion = Marshal.PtrToStringAnsi(context->glGetString(glVersion)) ?? string.Empty;
|
||||
|
||||
foreach (string branch in glBranch)
|
||||
{
|
||||
@@ -132,20 +151,31 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
IntPtr strPtr = context->glGetString(glExtension);
|
||||
string extension;
|
||||
if (strPtr == IntPtr.Zero)
|
||||
uint code = context->glGetError();
|
||||
Console.WriteLine(code);
|
||||
if (code != 0)
|
||||
{
|
||||
throw new GlExecutionException(code);
|
||||
}
|
||||
|
||||
int extensionCount;
|
||||
context->glGetIntegerv(GLconst.NUM_EXTENSIONS, &extensionCount);
|
||||
if (extensionCount == 0)
|
||||
{
|
||||
InternalIO.InternalWriteLog("No supported OpenGL extensions are found.", LogType.Info);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
List<string> extensions = new List<string>();
|
||||
|
||||
for (uint i = 0; i < extensionCount; i++)
|
||||
{
|
||||
extension = Marshal.PtrToStringAnsi(strPtr);
|
||||
byte* strPtr = context->glGetStringi(GLconst.EXTENSIONS, i);
|
||||
extensions.Add(Marshal.PtrToStringAnsi((IntPtr)strPtr));
|
||||
}
|
||||
|
||||
List<string> extensions =
|
||||
extension.Split(" ").ToList();
|
||||
InternalIO.InternalWriteLog($"{$"Find OpenGL extensions:"}{Environment.NewLine}{($"{string.Join(';', extensions)}")}",
|
||||
LogType.Info);
|
||||
|
||||
#region checkGLextensions
|
||||
|
||||
@@ -771,28 +801,16 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
#endregion checkGLextensions
|
||||
|
||||
InternalIO.InternalWriteLog("Find OpenGL extensions.", LogType.Info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="name">ContextName of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
|
||||
public static IntPtr LoadGLfunc(string name)
|
||||
{
|
||||
IntPtr ret = InternalIO.glfwGetProcAddress(name);
|
||||
if (ret == default)
|
||||
{
|
||||
InternalIO.InternalAppendLog(
|
||||
$"Cannot load OpenGL api called {name}, this api may not exist or supported.");
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (majorVersion < 3)
|
||||
{
|
||||
throw new InvalidOperationException("StgSharp does not support OpenGL immediate mode.");
|
||||
}
|
||||
|
||||
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 0)))
|
||||
{
|
||||
core10 = true;
|
||||
@@ -971,7 +989,7 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe string GetExtensions(this GLcontext context)
|
||||
internal static unsafe string GetExtensions(this OpenglContext context)
|
||||
{
|
||||
if (context.glGetString == null)
|
||||
{
|
||||
@@ -998,7 +1016,7 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore10(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore10(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core10)
|
||||
{
|
||||
@@ -1062,7 +1080,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore11(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore11(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core11)
|
||||
{
|
||||
@@ -1092,7 +1110,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore12(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore12(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core12)
|
||||
{
|
||||
@@ -1112,7 +1130,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore13(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore13(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core13)
|
||||
{
|
||||
@@ -1137,7 +1155,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore14(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore14(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core14)
|
||||
{
|
||||
@@ -1162,7 +1180,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.4 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore15(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore15(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core15)
|
||||
{
|
||||
@@ -1197,7 +1215,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.5 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore20(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore20(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core20)
|
||||
{
|
||||
@@ -1306,7 +1324,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore21(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore21(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core21)
|
||||
{
|
||||
@@ -1328,7 +1346,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore30(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore30(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core30)
|
||||
{
|
||||
@@ -1428,7 +1446,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore31(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore31(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core31)
|
||||
{
|
||||
@@ -1459,7 +1477,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore32(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore32(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core32)
|
||||
{
|
||||
@@ -1494,7 +1512,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore33(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore33(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core33)
|
||||
{
|
||||
@@ -1538,7 +1556,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore40(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore40(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core40)
|
||||
{
|
||||
@@ -1600,7 +1618,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.0 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore41(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore41(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core41)
|
||||
{
|
||||
@@ -1704,7 +1722,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.1 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore42(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore42(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core42)
|
||||
{
|
||||
@@ -1732,7 +1750,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.2 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore43(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore43(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core43)
|
||||
{
|
||||
@@ -1792,7 +1810,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.3 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore44(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore44(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core44)
|
||||
{
|
||||
@@ -1817,7 +1835,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.4 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore45(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore45(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core45)
|
||||
{
|
||||
@@ -1943,7 +1961,7 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.5 APIs");
|
||||
}
|
||||
|
||||
internal static unsafe void LoadGLcore46(GLcontext* contextPtr, delegate*<string, IntPtr> load)
|
||||
internal static unsafe void LoadGLcore46(OpenglContext* contextPtr, delegate*<string, IntPtr> load)
|
||||
{
|
||||
if (!core46)
|
||||
{
|
||||
+1
-1
@@ -32,7 +32,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public static partial class glManager
|
||||
{
|
||||
@@ -0,0 +1,104 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glException.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.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class GlExecutionException : Exception
|
||||
{
|
||||
|
||||
public GlExecutionException()
|
||||
{
|
||||
}
|
||||
|
||||
public GlExecutionException(uint errorCode) : base($"Critical OpenGL error: {errorCode}")
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+320
-191
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLpack.cs"
|
||||
// file="glFunction.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -29,13 +29,15 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
@@ -47,193 +49,174 @@ namespace StgSharp
|
||||
[DllImport(SSC_libName, EntryPoint = "glCheckShaderStat",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
#pragma warning disable CA5392
|
||||
internal static extern int glCheckShaderStatus(ref GLcontext context, uint shaderHandle, int key, ref IntPtr logPtr);
|
||||
internal static extern int glCheckShaderStatus(ref OpenglContext context, uint shaderHandle, int key, ref IntPtr logPtr);
|
||||
#pragma warning restore CA5392
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
namespace StgSharp.Graphics.GL
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
internal static unsafe partial class glFunc
|
||||
|
||||
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private static GLcontext* context;
|
||||
private static Dictionary<IntPtr, OpenGLFunction> contextToGLMap = new Dictionary<IntPtr, OpenGLFunction>();
|
||||
private OpenglContext* _context;
|
||||
|
||||
public static IntPtr CurrentContextHandle
|
||||
private OpenGLFunction()
|
||||
{
|
||||
get { return (IntPtr)context; }
|
||||
set { context = (GLcontext*)value; }
|
||||
textureUnitCountGetter = new Lazy<int>(() => GetMaskInteger(GLconst.MAX_TEXTURE_IMAGE_UNITS));
|
||||
unusedTextureImageUintInitilizing = new Lazy<ConcurrentQueue<TextureUnit>>(InitializeUnusedTextureImageUint);
|
||||
}
|
||||
|
||||
private static ref GLcontext Context
|
||||
internal IntPtr ContextHandle => (IntPtr)_context;
|
||||
|
||||
internal static OpenGLFunction CurrentGL { get; set; }
|
||||
|
||||
protected ref OpenglContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if ((IntPtr)context==IntPtr.Zero)
|
||||
if ((IntPtr)_context == IntPtr.Zero)
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
#endif
|
||||
return ref (*context);
|
||||
return ref (*_context);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static 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 static void AttachShader(glHandle program, glHandle shader)
|
||||
public void AttachShader(GlHandle program, GlHandle shader)
|
||||
{
|
||||
Context.glAttachShader(program.Value, shader.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindBuffer(BufferType bufferType, glHandle handle)
|
||||
public void BindBuffer(BufferType bufferType, GlHandle handle)
|
||||
{
|
||||
Context.glBindBuffer((uint)bufferType, handle.Value);
|
||||
}
|
||||
|
||||
[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
|
||||
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = dataStream)
|
||||
{
|
||||
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
/// <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>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindFrameBuffer(FrameBufferTarget target, glHandle handle)
|
||||
public void BindFrameBuffer(FrameBufferTarget target, GlHandle handle)
|
||||
{
|
||||
Context.glBindFramebuffer((uint)target, handle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void BindRenderBuffer(glHandle handle)
|
||||
public 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)
|
||||
public 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)
|
||||
public void BindVertexArray(GlHandle handle)
|
||||
{
|
||||
Context.glBindVertexArray(handle.Value);
|
||||
}
|
||||
|
||||
public static void RereadImage(
|
||||
this Image i, (int X, int Y) beginPosition, FrameBufferChannel format, ImageChannelLayout dataType)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public FrameBufferStatus CheckFrameBufferStatus(FrameBufferTarget target)
|
||||
{
|
||||
glArrayHandle handle = i.GetArrayHandle();
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, i.Width, i.Height, (uint)format, (uint)dataType, (byte*)handle.AddressOfArray()
|
||||
);
|
||||
return (FrameBufferStatus)Context.glCheckFramebufferStatus((uint)target);
|
||||
}
|
||||
|
||||
[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)]
|
||||
public static void Clear(MaskBufferBit mask)
|
||||
public void Clear(MaskBufferBit mask)
|
||||
{
|
||||
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)
|
||||
public unsafe void ClearColor(float R, float G, float B, float A)
|
||||
{
|
||||
Context.glClearColor(R, G, B, A);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ClearGraphicError()
|
||||
public void ClearError()
|
||||
{
|
||||
while (Context.glGetError() != 0) { }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void CompileShader(glHandle shaderhandle)
|
||||
public unsafe void ClearGraphicError()
|
||||
{
|
||||
while (Context.glGetError() != 0) { }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CombineFrameBufferRenderBuffer(FrameBufferAttachment attachment, GlHandle rboHandle)
|
||||
{
|
||||
Context.glFramebufferRenderbuffer(GLconst.FRAMEBUFFER, (uint)attachment, GLconst.RENDERBUFFER, rboHandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CompileShader(GlHandle shaderhandle)
|
||||
{
|
||||
Context.glCompileShader(shaderhandle.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandle CreateGraphicProgram()
|
||||
public unsafe GlHandle CreateGraphicProgram()
|
||||
{
|
||||
return glHandle.Alloc(Context.glCreateProgram());
|
||||
return GlHandle.Alloc(Context.glCreateProgram());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glHandle CreateProgram()
|
||||
public GlHandle CreateProgram()
|
||||
{
|
||||
return glHandle.Alloc(Context.glCreateProgram());
|
||||
return GlHandle.Alloc(Context.glCreateProgram());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet CreateProgram(int count)
|
||||
public unsafe GlHandle[] CreateProgram(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
h.SetValue(i, Context.glCreateProgram());
|
||||
@@ -242,9 +225,9 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static glHandleSet CreateShaderSet(int count, ShaderType type)
|
||||
public GlHandle[] CreateShaderSet(int count, ShaderType type)
|
||||
{
|
||||
glHandleSet ret = new glHandleSet(count);
|
||||
GlHandle[] ret = new GlHandle[count];
|
||||
uint t = (uint)type;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
@@ -252,66 +235,66 @@ namespace StgSharp.Graphics.GL
|
||||
if (id == 0)
|
||||
{
|
||||
uint error = Context.glGetError();
|
||||
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
|
||||
throw new Exception();
|
||||
throw new InvalidOperationException($"Failed in creating shader: {error}");
|
||||
}
|
||||
ret.SetValue(i, id);
|
||||
ret[i] = GlHandle.Alloc(id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteBuffer(glHandle handle)
|
||||
public unsafe void DeleteBuffer(GlHandle handle)
|
||||
{
|
||||
Context.glDeleteBuffers(1, (uint*)handle.Handle);
|
||||
Context.glDeleteBuffers(1, (uint*)&handle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteBuffers(glHandleSet handle)
|
||||
public unsafe void DeleteBuffers(GlHandle[] handle)
|
||||
{
|
||||
Context.glDeleteBuffers(handle.length, (uint*)handle.Handle);
|
||||
handle.Release();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DeleteVertexArrays(glHandleSet arrays)
|
||||
public unsafe void DeleteVertexArrays(GlHandle[] arrays)
|
||||
{
|
||||
Context.glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
|
||||
arrays.Release();
|
||||
fixed (GlHandle* hptr = arrays)
|
||||
{
|
||||
uint* iptr = (uint*)hptr;
|
||||
for (int i = 0; i < arrays.Length; i++)
|
||||
{
|
||||
Context.glDeleteVertexArrays(1, iptr + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void DrawElements(GeometryType mode, uint count, TypeCode type, IntPtr ptr)
|
||||
public unsafe void DrawElements(GeometryType mode, uint count, TypeCode type, IntPtr ptr)
|
||||
{
|
||||
uint a;
|
||||
switch (type)
|
||||
a = type switch
|
||||
{
|
||||
case TypeCode.UInt32:
|
||||
a = GLconst.UNSIGNED_INT;
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
a = GLconst.UNSIGNED_SHORT;
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
a = GLconst.UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
default:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
TypeCode.UInt32 => GLconst.UNSIGNED_INT,
|
||||
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."}"}")
|
||||
};
|
||||
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawElementsInstanced(
|
||||
public void DrawElementsInstanced(
|
||||
GeometryType mode, uint count, TypeCode type, IntPtr ptr, uint amount
|
||||
)
|
||||
{
|
||||
@@ -340,53 +323,98 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Enable(GLOperation operation)
|
||||
public void Enable(GLOperation operation)
|
||||
{
|
||||
Context.glEnable((uint)operation);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glHandleSet GenBuffers(int count)
|
||||
public void FrameBufferTexture2d(FrameBufferTarget target, uint attachment, Texture2DTarget texTarget, GlHandle textureHandle, int level)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenBuffers(count, (uint*)h.Handle);
|
||||
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)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenTextures(count, (uint*)h.Handle);
|
||||
return h;
|
||||
}
|
||||
|
||||
[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
|
||||
Context.glFramebufferTexture2D(
|
||||
(uint)target, attachment, (uint)texTarget, textureHandle.Value, level
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static unsafe glHandleSet GenVertexArrays(int count)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe GlHandle[] GenBuffers(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
Context.glGenVertexArrays(count, (uint*)h.Handle);
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed (GlHandle* hptr = h)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Context.glGenBuffers(count, ((uint*)hptr) + i);
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public static string GetShaderStatus(Shader s, int index, int key)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GenerateMipmap(Texture2DTarget target)
|
||||
{
|
||||
Context.glGenerateMipmap((uint)target);
|
||||
}
|
||||
|
||||
public unsafe GlHandle[] GenFrameBuffers(int count)
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed (GlHandle* hptr = h)
|
||||
{
|
||||
Context.glGenFramebuffers(1, (uint*)hptr);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe GlHandle[] GenRenderBuffer(int count)
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed (GlHandle* hptr = h)
|
||||
{
|
||||
Context.glGenRenderbuffers(count, (uint*)hptr);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe GlHandle[] GenTextures(int count)
|
||||
{
|
||||
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed (GlHandle* hptr = h)
|
||||
{
|
||||
Context.glGenTextures(count, (uint*)hptr);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
public unsafe GlHandle[] GenVertexArrays(int count)
|
||||
{
|
||||
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed (GlHandle* hptr = h)
|
||||
{
|
||||
Context.glGenVertexArrays(count, (uint*)hptr);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint GetError()
|
||||
{
|
||||
return Context.glGetError();
|
||||
}
|
||||
|
||||
public unsafe int GetMaskInteger(uint statusCode)
|
||||
{
|
||||
int ret = 0;
|
||||
Context.glGetIntegerv(statusCode, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public 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)
|
||||
@@ -396,31 +424,48 @@ namespace StgSharp.Graphics.GL
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void GetTextureImage<T>(Texture2DTarget target, int level, ImageChannel channel, PixelChannelLayout channelLayout, T[] dataStream)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = dataStream)
|
||||
{
|
||||
Context.glGetTexImage((uint)target, level, (uint)channel, (uint)channelLayout, tptr);
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe glSHandle GetUniformLocation(glHandle program, string name)
|
||||
public unsafe GlHandle GetUniformLocation(GlHandle program, string name)
|
||||
{
|
||||
byte[] code = Encoding.UTF8.GetBytes(name);
|
||||
fixed (byte* ptr = code)
|
||||
{
|
||||
int ret = Context.glGetUniformLocation(program.Value, ptr);
|
||||
#if DEBUG
|
||||
if (ret == (int)(GLconst.INVALID_OPERATION) ||
|
||||
ret == (int)(GLconst.INVALID_VALUE))
|
||||
if ((ret == GLconst.INVALID_OPERATION) ||
|
||||
(ret == GLconst.INVALID_VALUE))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
if (ret == -1 )
|
||||
if (ret == -1)
|
||||
{
|
||||
throw new UniformEmptyReferenceException(nameof(program), name);
|
||||
}
|
||||
#endif
|
||||
return glSHandle.Alloc(ret);
|
||||
return GlHandle.SignedAlloc(ret);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void LoadShaderSource(glHandle shaderHandle, byte[] codeStream)
|
||||
public unsafe void LoadShaderSource(GlHandle shaderHandle, byte[] codeStream)
|
||||
{
|
||||
fixed (byte* streamPtr = codeStream)
|
||||
{
|
||||
@@ -428,8 +473,38 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
public void ReadPixels(
|
||||
(int X, int Y) beginPosition, (int width, int height) size, FrameBufferChannel format, PixelChannelLayout dataType, ref byte[] stream
|
||||
)
|
||||
{
|
||||
fixed (byte* bptr = stream)
|
||||
{
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y,
|
||||
size.width, size.height, (uint)format, (uint)dataType, bptr);
|
||||
}
|
||||
}
|
||||
|
||||
public void RereadImage(
|
||||
in Image i, (int X, int Y) beginPosition, FrameBufferChannel format, PixelChannelLayout dataType)
|
||||
{
|
||||
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, bptr);
|
||||
}
|
||||
i.PixelUpdateCount++;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
where T : struct
|
||||
{
|
||||
int size = Marshal.SizeOf<T>();
|
||||
@@ -444,7 +519,7 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
public unsafe void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
@@ -471,7 +546,7 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
public unsafe void SetBufferData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
@@ -498,7 +573,7 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
public unsafe void SetBufferData<T>(BufferType bufferType, Span<T> bufferArray, BufferUsage usage)
|
||||
where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
@@ -526,7 +601,7 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
public unsafe void SetBufferVectorData<T>(BufferType bufferType, ReadOnlySpan<T> bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
@@ -547,7 +622,7 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferVectorData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
public unsafe void SetBufferVectorData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
|
||||
where T : struct, IVector
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf(typeof(T));
|
||||
@@ -568,7 +643,15 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
|
||||
public unsafe void SetRenderBufferStorage(RenderBufferInternalFormat internalFormat, (int width, int height) size)
|
||||
{
|
||||
Context.glRenderbufferStorage(
|
||||
GLconst.RENDERBUFFER, (uint)internalFormat, size.width, size.height
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
|
||||
{
|
||||
uint type = InternalIO.GLtype[t];
|
||||
Context.glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
|
||||
@@ -576,47 +659,93 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glHandle pixels)
|
||||
public void TextureImage2d<T>(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, PixelChannelLayout type, T[] pixels) where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, pixels.valuePtr
|
||||
);
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = ((pixels == null) || (pixels.Length == 0)) ? null : pixels)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, tptr);
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureImage2d(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, ImageChannelLayout type, glArrayHandle pixelArrayHandle)
|
||||
public void TextureImage2d<T>(Texture2DTarget target, int level, uint internalformat, uint width, uint height,
|
||||
uint format, PixelChannelLayout type, Span<T> pixelSpan) where T : struct,
|
||||
#if NET8_0_OR_GREATER
|
||||
INumber
|
||||
#else
|
||||
IConvertible
|
||||
#endif
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, (void*)pixelArrayHandle.handle.AddrOfPinnedObject()
|
||||
);
|
||||
#pragma warning disable CS8500
|
||||
fixed (T* tptr = pixelSpan)
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
(uint)target, level, internalformat, width, height, 0, format, (uint)type, tptr);
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void TextureParameter(int target, uint pname, int param)
|
||||
public void TextureParameter(int target, uint pname, int param)
|
||||
{
|
||||
Context.glTexParameteri((uint)target, pname, param);
|
||||
}
|
||||
|
||||
public static bool TryGetFunctionPackage(IntPtr handle, out OpenGLFunction functionPackage)
|
||||
{
|
||||
return contextToGLMap.TryGetValue(handle, out functionPackage);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void UseProgram(glHandle program)
|
||||
public void UseProgram(GlHandle program)
|
||||
{
|
||||
Context.glUseProgram(program.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void VertexAttributeDivisor(uint layoutIndex, uint divisor)
|
||||
public 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)
|
||||
public void Viewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
Context.glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
|
||||
public void WaitAccomplishment()
|
||||
{
|
||||
Context.glFinish();
|
||||
}
|
||||
|
||||
internal static OpenGLFunction BuildGlFunctionPackage(IntPtr handle)
|
||||
{
|
||||
OpenGLFunction pack;
|
||||
if (contextToGLMap.TryGetValue(handle, out pack))
|
||||
{
|
||||
return pack;
|
||||
}
|
||||
pack = new OpenGLFunction { _context = (OpenglContext*)handle };
|
||||
contextToGLMap.Add(handle, pack);
|
||||
return pack;
|
||||
}
|
||||
|
||||
~OpenGLFunction()
|
||||
{
|
||||
contextToGLMap.Remove(ContextHandle);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+27
-36
@@ -28,52 +28,53 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Logic;
|
||||
|
||||
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;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
protected glRenderStream(ViewPort v, (int,int,int) cube) : base(v,cube)
|
||||
{
|
||||
}
|
||||
private OpenGLFunction _context;
|
||||
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
protected internal OpenGLFunction GL
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
get { return _context; }
|
||||
}
|
||||
|
||||
/// <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.
|
||||
/// Initialize an OpenGl viewPortDisplay if current form has not been binded to any viewPortDisplay.
|
||||
/// and set the viewPortDisplay binded to current form as current OpenGL viewPortDisplay.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">
|
||||
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
|
||||
/// Something goes wrong and StgSharp fails in creating a new OpenGL viewPortDisplay.
|
||||
/// </exception>
|
||||
public unsafe void MakeAsCurrentContext()
|
||||
{
|
||||
if (ContextHandle == default)
|
||||
{
|
||||
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
|
||||
GLcontext* contextID = (GLcontext*)ContextHandle;
|
||||
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(OpenglContext)));
|
||||
OpenglContext* contextID = (OpenglContext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
|
||||
}
|
||||
if (glFunc.CurrentContextHandle != ContextHandle)
|
||||
if (GL == null)
|
||||
{
|
||||
glFunc.CurrentContextHandle = ContextHandle;
|
||||
//Console.WriteLine($"context set as {(ulong)glFunc.CurrentContextHandle}");
|
||||
_context = OpenGLFunction.BuildGlFunctionPackage(ContextHandle);
|
||||
}
|
||||
if (OpenGLFunction.CurrentGL != GL)
|
||||
{
|
||||
OpenGLFunction.CurrentGL = GL;
|
||||
InternalIO.glfwMakeContextCurrent(CanvasHandle);
|
||||
}
|
||||
}
|
||||
@@ -84,25 +85,24 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal override sealed void Draw()
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
ProcessInput();
|
||||
Main(in input, in output);
|
||||
Main();
|
||||
}
|
||||
|
||||
internal override sealed void InternalInit()
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal override sealed void PlatformSpecifiedInitialize()
|
||||
{
|
||||
MakeAsCurrentContext();
|
||||
this.Port.LoadGLapi();
|
||||
Init();
|
||||
glManager.LoadOpenGLApiTo(Port.GraphicHandle);
|
||||
}
|
||||
|
||||
internal override sealed void InternalTerminate()
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal override sealed void Terminate()
|
||||
{
|
||||
Deinit();
|
||||
CustomizeDeinit();
|
||||
}
|
||||
|
||||
protected override sealed Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
|
||||
@@ -122,16 +122,6 @@ namespace StgSharp.Graphics.GL
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
protected static void PollEvents()
|
||||
{
|
||||
InternalIO.glfwPollEvents();
|
||||
}
|
||||
|
||||
protected void SwapBuffers()
|
||||
{
|
||||
InternalIO.glfwSwapBuffers(CanvasHandle);
|
||||
}
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(KeyboardKey key)
|
||||
@@ -151,5 +141,6 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+16
-9
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLresourceGenrator.cs"
|
||||
// file="glResourceGenrator.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -35,7 +35,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.GL
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
{
|
||||
@@ -51,6 +51,12 @@ namespace StgSharp.Graphics.GL
|
||||
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)
|
||||
@@ -58,12 +64,6 @@ namespace StgSharp.Graphics.GL
|
||||
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="TextureGL"/>
|
||||
/// </summary>
|
||||
@@ -75,6 +75,13 @@ namespace StgSharp.Graphics.GL
|
||||
return new TextureGL(count, this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected AutoTextureGL CreateAutoTexture(int count)
|
||||
{
|
||||
return new AutoTextureGL(count, this);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexArray"/>.
|
||||
/// </summary>
|
||||
@@ -97,6 +104,6 @@ namespace StgSharp.Graphics.GL
|
||||
return new VertexBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glResourceManager.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;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private Lazy<int> textureUnitCountGetter;
|
||||
private Lazy<ConcurrentQueue<TextureUnit>> unusedTextureImageUintInitilizing;
|
||||
|
||||
public int TextureUnitCount
|
||||
{
|
||||
get => textureUnitCountGetter.Value;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
|
||||
{
|
||||
get => unusedTextureImageUintInitilizing.Value;
|
||||
}
|
||||
|
||||
internal void ReturnAvailableUnit(IEnumerable<TextureUnit> source)
|
||||
{
|
||||
int v = GLconst.TEXTURE0 + TextureUnitCount;
|
||||
foreach (TextureUnit unit in source)
|
||||
{
|
||||
if ((int)unit > v)
|
||||
{
|
||||
throw new InvalidOperationException("Source contains texture unit beyond context support.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal int TryGetAvailableTextureUnit(int count, out IEnumerable<TextureUnit> result)
|
||||
{
|
||||
result = new Queue<TextureUnit>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (UnusedTextureImageUint.TryDequeue(out TextureUnit unit))
|
||||
{
|
||||
(result as Queue<TextureUnit>)!.Enqueue(unit);
|
||||
}
|
||||
else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> InitializeUnusedTextureImageUint()
|
||||
{
|
||||
ConcurrentQueue<TextureUnit> result = new ConcurrentQueue<TextureUnit>();
|
||||
for (int index = 0; index < TextureUnitCount; index++)
|
||||
{
|
||||
result.Enqueue((TextureUnit)(GLconst.TEXTURE0 + index));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Pixels.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.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IPixel
|
||||
{
|
||||
|
||||
public float Red { get; set; }
|
||||
public float Green { get; set; }
|
||||
public float Blue { get; set; }
|
||||
public float Alpha { get; set; }
|
||||
|
||||
internal int Size { get; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32)]
|
||||
public unsafe struct Pixel32
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private unsafe fixed byte data[4];
|
||||
|
||||
internal int Size => 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,24 +1,67 @@
|
||||
using StgSharp.Geometries;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="PlainGeometryMesh.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.Geometries;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
|
||||
private PlainGeometry _shape;
|
||||
private Image _texture;
|
||||
private vec4d[] textureCoord;
|
||||
private TextureProvider _texture;
|
||||
|
||||
public PlainGeometryMesh([NotNull] PlainGeometry shape, [NotNull] TextureProvider texture)
|
||||
{
|
||||
if (shape.VertexCount > texture.TextureCoordinate.Length)
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texture), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
_texture = texture;
|
||||
_shape = shape;
|
||||
}
|
||||
//private Image _texture;
|
||||
|
||||
public PlainGeometryMesh(
|
||||
PlainGeometry shape, Image texture, vec4d[] texCoord
|
||||
PlainGeometry shape, Image texture, vec2d[] texCoord
|
||||
)
|
||||
{
|
||||
if (shape==null)
|
||||
if (shape == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(shape));
|
||||
}
|
||||
@@ -27,31 +70,29 @@ namespace StgSharp.Graphics
|
||||
throw new ArgumentNullException(nameof(texCoord));
|
||||
}
|
||||
|
||||
_shape = shape;
|
||||
_texture = texture;
|
||||
if (shape.VertexCount > texCoord.Length)
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
textureCoord = texCoord;
|
||||
return;
|
||||
_texture = new TextureProvider(texture, texCoord);
|
||||
}
|
||||
|
||||
public PlainGeometryMesh Resize(PlainGeometry newShape)
|
||||
public vec4d[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image TextureImage
|
||||
{
|
||||
return new PlainGeometryMesh(newShape, _texture, textureCoord);
|
||||
get => _texture.ProvideImage();
|
||||
internal set => _texture.ReadImage(value);
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public vec4d[] VertexArray => _shape.VertexStream;
|
||||
public ReadOnlySpan<vec4d> TextureCoord => MemoryMarshal.Cast<vec2d, vec4d>(_texture.TextureCoordinate);
|
||||
|
||||
public Image TextureImage
|
||||
public PlainGeometryMesh Resize(PlainGeometry newShape)
|
||||
{
|
||||
get => _texture;
|
||||
internal set => _texture = value;
|
||||
return new PlainGeometryMesh(newShape, _texture);
|
||||
}
|
||||
|
||||
public vec4d[] TextureCoord => textureCoord;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,12 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using StgSharp.Math;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.MVVM.View;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -43,103 +46,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream : IConvertableToBlueprintNode
|
||||
public abstract class RenderStream
|
||||
{
|
||||
private ViewPort primeArgs;
|
||||
|
||||
private protected (int x, int y, int z) _coordStretch;
|
||||
|
||||
private protected ViewPort primeArgs;
|
||||
private Camera nativeCamera;
|
||||
|
||||
public ViewPort Port => primeArgs;
|
||||
|
||||
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
|
||||
|
||||
|
||||
internal IntPtr ContextHandle
|
||||
{
|
||||
get => primeArgs.GraphicHandle;
|
||||
private protected set => primeArgs.GraphicHandle = value;
|
||||
}
|
||||
|
||||
private IntPtr monitor;
|
||||
private IntPtr sharedCanvas;
|
||||
|
||||
internal TimeSpanProvider timeProvider;
|
||||
/*
|
||||
protected RenderStream(View v, bool isSharing)
|
||||
{
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
if (isSharing)
|
||||
{
|
||||
primeArgs = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
View? newArgs = args.Clone() as View;
|
||||
primeArgs = newArgs;
|
||||
}
|
||||
|
||||
monitor = args.Monitor;
|
||||
_coordStretch = args.UnitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
/**/
|
||||
|
||||
public RenderStream(ViewPort v, (int,int,int) unitCubeSize)
|
||||
{
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
primeArgs = v;
|
||||
|
||||
monitor = v!.Monitor;
|
||||
_coordStretch = unitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
|
||||
public FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
{
|
||||
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
|
||||
InternalIO.glfwSetFramebufferSizeCallback(CanvasHandle, handlerPtr);
|
||||
}
|
||||
}
|
||||
|
||||
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => primeArgs.Height;
|
||||
internal set
|
||||
{
|
||||
primeArgs.Height = value;
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Monitor
|
||||
{
|
||||
get => monitor;
|
||||
internal set => monitor = value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
}
|
||||
|
||||
public IntPtr SharedCanvas
|
||||
{
|
||||
get => sharedCanvas;
|
||||
internal set => sharedCanvas = value;
|
||||
}
|
||||
internal TimeSpanProvider _timeProvider;
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
@@ -152,14 +65,49 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public abstract bool IsContextSharable
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => primeArgs.Height;
|
||||
internal set { primeArgs.Height = value; }
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => primeArgs.Width;
|
||||
internal set
|
||||
{
|
||||
primeArgs.Width = value;
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
internal set { primeArgs.Width = value; }
|
||||
}
|
||||
|
||||
public IntPtr Monitor
|
||||
{
|
||||
get => primeArgs.Monitor;
|
||||
internal set => primeArgs.Monitor = value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
}
|
||||
|
||||
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
|
||||
|
||||
public ViewPort Port
|
||||
{
|
||||
get => primeArgs;
|
||||
internal set => primeArgs = value;
|
||||
}
|
||||
|
||||
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
|
||||
|
||||
|
||||
internal IntPtr ContextHandle
|
||||
{
|
||||
get => primeArgs.GraphicHandle;
|
||||
private protected set => primeArgs.GraphicHandle = value;
|
||||
}
|
||||
|
||||
protected internal Camera NativeCamera
|
||||
@@ -168,22 +116,24 @@ namespace StgSharp.Graphics
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
protected int Frames
|
||||
protected float FramePassed
|
||||
{
|
||||
get => timeProvider.CurrentSpan;
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected abstract string[] InputPortsName { get; }
|
||||
protected abstract string[] OutputPortsName { get; }
|
||||
protected int PassedFrames
|
||||
{
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected float TimePassed
|
||||
{
|
||||
get => timeProvider.CurrentSpan;
|
||||
get => _timeProvider.CurrentSecond;
|
||||
}
|
||||
|
||||
protected TimeSpanProvider TimeProvider
|
||||
{
|
||||
get => timeProvider;
|
||||
get => _timeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -196,34 +146,31 @@ 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)
|
||||
public static TTarget ShareContextFrom<TSource, TTarget>(TSource source)
|
||||
where TSource : RenderStream
|
||||
where TTarget : RenderStream
|
||||
where TTarget : RenderStream, new()
|
||||
{
|
||||
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) 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.Init();
|
||||
TTarget target = new TTarget();
|
||||
target.Initialize(source.Port, source._coordStretch, source._timeProvider);
|
||||
return target;
|
||||
}
|
||||
|
||||
protected internal static void PollEvents()
|
||||
{
|
||||
InternalIO.glfwPollEvents();
|
||||
}
|
||||
|
||||
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
|
||||
|
||||
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
|
||||
|
||||
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
|
||||
protected internal void SwapBuffers()
|
||||
{
|
||||
InternalIO.glfwSwapBuffers(CanvasHandle);
|
||||
}
|
||||
|
||||
#region native camera operation
|
||||
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.
|
||||
/// Get <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) uniform from a shader.
|
||||
/// This uniform will be used as projection matrix of this camera.
|
||||
/// Additionally, for multi-shader rendering, each shader requires a uniform,
|
||||
/// so do not ignore return value of this method.
|
||||
@@ -231,27 +178,38 @@ namespace StgSharp.Graphics
|
||||
/// <param name="source">Shader using this camera</param>
|
||||
/// <param name="name">ContextName of projection camera named in shader</param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) representing
|
||||
/// <see cref="Uniform{T}"/>(TView is <see cref="Matrix44"/>) representing
|
||||
/// projection matrix in shader program.
|
||||
/// </returns>
|
||||
protected abstract Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name);
|
||||
#endregion
|
||||
|
||||
#region internal operation
|
||||
internal abstract void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output);
|
||||
internal abstract void InternalInit();
|
||||
internal abstract void InternalTerminate();
|
||||
internal abstract void Draw();
|
||||
|
||||
public void Initialize(ViewPort v, (int, int, int) unitCubeSize, TimeSpanProvider timeProvider)
|
||||
{
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
primeArgs = v;
|
||||
this._timeProvider = timeProvider;
|
||||
_coordStretch = unitCubeSize;
|
||||
nativeCamera = new Camera();
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
}
|
||||
|
||||
internal abstract void PlatformSpecifiedInitialize();
|
||||
|
||||
internal abstract void Terminate();
|
||||
#endregion
|
||||
|
||||
#region public operation
|
||||
protected abstract void Deinit();
|
||||
protected abstract void Init();
|
||||
protected abstract void Main(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output);
|
||||
protected abstract void ProcessInput();
|
||||
protected abstract void CustomizeDeinit();
|
||||
protected abstract void CustomizeInit();
|
||||
protected abstract void Main();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -260,8 +218,6 @@ namespace StgSharp.Graphics
|
||||
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
|
||||
protected abstract ShaderProgram CreateShaderProgram();
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -43,15 +43,16 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderGenerator
|
||||
{
|
||||
private Dictionary<int,ShaderParameter> uniformDefine;
|
||||
|
||||
private Dictionary<int, ShaderParameter> uniformDefine;
|
||||
private List<string> codeList;
|
||||
private List<ShaderFunction> usedShaderFunctions;
|
||||
|
||||
public Uniform<T> DefineUniform<T>(string name, int index) where T : struct
|
||||
{
|
||||
ShaderParameter p = new ShaderParameter(name,ShaderParameter.TypeMarshal<T>());
|
||||
uniformDefine.Add(index,p);
|
||||
//return new Uniform<T>();
|
||||
ShaderParameter p = new ShaderParameter(name, ShaderParameter.TypeMarshal<T>());
|
||||
uniformDefine.Add(index, p);
|
||||
//return new Uniform<TView>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -59,10 +60,11 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
|
||||
public class ShaderFunction
|
||||
{
|
||||
|
||||
private List<string> codeList;
|
||||
private List<ShaderParameter> inputList;
|
||||
private string name;
|
||||
private ShaderParameter outPut;
|
||||
private string name;
|
||||
|
||||
public int ParameterCount => inputList.Count;
|
||||
|
||||
@@ -104,10 +106,11 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
|
||||
public class ShaderParameter
|
||||
{
|
||||
|
||||
public static readonly ShaderParameter Void = new ShaderParameter(string.Empty, InternalShaderType.Void);
|
||||
internal readonly bool isReadOnly;
|
||||
internal readonly string name;
|
||||
internal readonly InternalShaderType type;
|
||||
internal readonly string name;
|
||||
|
||||
public ShaderParameter(string name, InternalShaderType type)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Graphics.GL;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ShaderStruct.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.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,44 +40,49 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderStructMember
|
||||
{
|
||||
|
||||
internal InternalShaderType type;
|
||||
internal object value;
|
||||
|
||||
}
|
||||
|
||||
public class ShaderStruct
|
||||
{
|
||||
internal Dictionary<glSHandle, ShaderStructMember> uniformPair;
|
||||
|
||||
public ShaderStruct(params (glSHandle, ShaderStructMember)[] uniformPairs)
|
||||
internal Dictionary<GlHandle, ShaderStructMember> uniformPair;
|
||||
|
||||
internal ShaderStruct() { }
|
||||
|
||||
public ShaderStruct(params (GlHandle, ShaderStructMember)[] uniformPairs)
|
||||
{
|
||||
uniformPair = new Dictionary<glSHandle, ShaderStructMember>();
|
||||
uniformPair = new Dictionary<GlHandle, ShaderStructMember>();
|
||||
if (uniformPairs.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in uniformPairs)
|
||||
foreach ((GlHandle, ShaderStructMember) item in uniformPairs)
|
||||
{
|
||||
uniformPair.Add(item.Item1,item.Item2);
|
||||
uniformPair.Add(item.Item1, item.Item2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal ShaderStruct() { }
|
||||
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
GLcontext* gl = (GLcontext*) glFunc.CurrentContextHandle;
|
||||
foreach (var uniform in uniformPair)
|
||||
OpenglContext* gl = (OpenglContext*)OpenGL.OpenGLFunction.CurrentGL.ContextHandle;
|
||||
foreach (KeyValuePair<GlHandle, ShaderStructMember> uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.Value;
|
||||
int id = uniform.Key.SignedValue;
|
||||
ShaderStructMember s = uniform.Value;
|
||||
switch (s.type)
|
||||
{
|
||||
case InternalShaderType.Struct: throw new ArgumentException(
|
||||
case InternalShaderType.Struct:
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Struct\" defined in this self define type");
|
||||
case InternalShaderType.Void:throw new ArgumentException(
|
||||
case InternalShaderType.Void:
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Void\" defined in this self define type");
|
||||
case InternalShaderType.Float:
|
||||
gl->glUniform1f(id, (float)s.value);
|
||||
@@ -62,5 +97,6 @@ namespace StgSharp.Graphics.ShaderEdit
|
||||
}
|
||||
}
|
||||
}//------------------------------------ End of Class ---------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TextureImage : IImageProvider
|
||||
{
|
||||
private Image _tex;
|
||||
private vec2d[] _texCoord;
|
||||
|
||||
Image IImageProvider.ProvideImage()
|
||||
{
|
||||
return _tex;
|
||||
}
|
||||
|
||||
public TextureImage(Image image, vec2d[] coord)
|
||||
{
|
||||
_tex = image;
|
||||
_texCoord = coord;
|
||||
}
|
||||
|
||||
public ref vec2d this[int index]
|
||||
{
|
||||
get => ref _texCoord[index];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,36 @@
|
||||
using StgSharp.Logic;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TexturePipeline.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.BluePrint;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,19 +40,21 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TexturePipeline:BlueprintPipelineArgs
|
||||
public class TexturePipeline : BlueprintPipelineArgs
|
||||
{
|
||||
|
||||
private Image _value;
|
||||
|
||||
public TexturePipeline(Image i)
|
||||
{
|
||||
value = i;
|
||||
_value = i;
|
||||
}
|
||||
|
||||
private Image value;
|
||||
|
||||
public Image Value
|
||||
public new Image Value
|
||||
{
|
||||
get => value;
|
||||
set => value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
get => _value;
|
||||
set => _value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+38
-36
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="AnimationBuilder.cs"
|
||||
// file="TextureProvider.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,61 +28,63 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public delegate Image BuildAnimationDelegate(float time, out Polygon4 texutreFrame);
|
||||
|
||||
public sealed class AnimationBuilder: IImageProvider
|
||||
public class TextureProvider : IImageProvider
|
||||
{
|
||||
|
||||
private Image cache;
|
||||
private Polygon4 textureFrame;
|
||||
private TimeFunction time;
|
||||
private vec2d[] _texCoord;
|
||||
private Image _tex;
|
||||
|
||||
public AnimationBuilder(
|
||||
BuildAnimationDelegate builderFunc,
|
||||
TimeFunction timeline
|
||||
)
|
||||
public TextureProvider(Image image, vec2d[] coord)
|
||||
{
|
||||
textureFrame = new Polygon4();
|
||||
time = timeline;
|
||||
BuilderFunc = builderFunc;
|
||||
cache = BuilderFunc(time.Calculate(), out textureFrame);
|
||||
_tex = image;
|
||||
_texCoord = coord;
|
||||
}
|
||||
|
||||
public Polygon4 TextureFrame { get => textureFrame; }
|
||||
|
||||
public BuildAnimationDelegate BuilderFunc { get; set; }
|
||||
|
||||
public bool IsComplete
|
||||
public ref vec2d this[int index]
|
||||
{
|
||||
get => time.IsComplete;
|
||||
get => ref _texCoord[index];
|
||||
}
|
||||
|
||||
public Image GetAnimationFrame()
|
||||
public Span<vec2d> TextureCoordinate
|
||||
{
|
||||
if (!time.IsComplete)
|
||||
get => new Span<vec2d>(_texCoord);
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return _tex;
|
||||
}
|
||||
|
||||
public void ReadImage(IImageProvider provider)
|
||||
{
|
||||
_tex = provider.ProvideImage();
|
||||
}
|
||||
|
||||
public void UpdateFromImage(Image i)
|
||||
{
|
||||
if (i == _tex)
|
||||
{
|
||||
cache = BuilderFunc(time.Calculate(),out textureFrame);
|
||||
return;
|
||||
}
|
||||
return cache;
|
||||
if (i.Size == _tex.Size)
|
||||
{
|
||||
_tex = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Size of {nameof(i)} does not equals to current image.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
time.Reset();
|
||||
}
|
||||
|
||||
Image IImageProvider.ProvideImage()
|
||||
{
|
||||
return GetAnimationFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="View.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public unsafe partial class View
|
||||
{
|
||||
|
||||
private (int w, int h) sizeCache;
|
||||
private (int x, int y, int z) unitCubeSize;
|
||||
|
||||
private ViewPort context;
|
||||
|
||||
private ViewPortDesigner design;
|
||||
|
||||
public ViewPort Port
|
||||
{
|
||||
get => context;
|
||||
}
|
||||
|
||||
public View(ViewPort vp, ViewPortDesigner design)
|
||||
{
|
||||
context = vp;
|
||||
sizeCache = (0, 0);
|
||||
unitCubeSize = (1, 1, 1);
|
||||
localLogic = new Logic.Blueprint();
|
||||
this.design = design;
|
||||
SelfName = string.Empty;
|
||||
}
|
||||
|
||||
public View(ViewPort vp, ViewPortDesigner design, (int, int, int) cubeSize)
|
||||
{
|
||||
context = vp;
|
||||
sizeCache = (0, 0);
|
||||
unitCubeSize = cubeSize;
|
||||
localLogic = new Logic.Blueprint();
|
||||
}
|
||||
|
||||
public bool Activated { get; internal set; }
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
if (context.Height != sizeCache.h)
|
||||
{
|
||||
sizeCache.h = context.Height;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
return sizeCache.h;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
sizeCache.h = value;
|
||||
context.Height = value;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Monitor => context.Monitor;
|
||||
|
||||
public IntPtr ViewHandle => context.ViewPortID;
|
||||
|
||||
public string ContextName => context.Name;
|
||||
|
||||
public string SelfName { get; set; }
|
||||
|
||||
public (int x, int y, int z) UnitCubeSize
|
||||
{
|
||||
get => unitCubeSize;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
if (context.Width != sizeCache.w)
|
||||
{
|
||||
sizeCache.w = context.Width;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
return sizeCache.h;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
sizeCache.w = value;
|
||||
context.Width = value;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class ViewPort
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public IntPtr Monitor { get; internal set; }
|
||||
|
||||
public IntPtr ViewPortID { get; private set; }
|
||||
public IntPtr GraphicHandle { get; internal set; }
|
||||
|
||||
internal ViewPort()
|
||||
{
|
||||
Height = 800;
|
||||
Width = 600;
|
||||
Name = new StackFrame(1, false).
|
||||
GetMethod()!.DeclaringType!.Name;
|
||||
Monitor = IntPtr.Zero;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(Width,Height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
|
||||
public ViewPort(vec2d size,string name, IntPtr monitor)
|
||||
{
|
||||
Height = (int) size.Y;
|
||||
Width = (int) size.X;
|
||||
Name = name;
|
||||
Monitor = monitor;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(Width, Height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ namespace StgSharp
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(IntPtr window);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(IntPtr window, GLFWwindowposfun callback);
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(IntPtr window, IntPtr callback);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(IntPtr window, GLFWwindowsizefun callback);
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace StgSharp
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(IntPtr window, GLFWwindowmaximizefun callback);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FrameBufferSizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(IntPtr window, GLFWwindowcontentscalefun callback);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user