daily update on 20240427 by nitload youmu
This commit is contained in:
@@ -279,25 +279,25 @@ namespace StgSharp.Graphics
|
||||
// _GLFWcontext context; // 根据_GLFWcontext的定义转换
|
||||
|
||||
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
|
||||
struct Callbacks
|
||||
internal struct Callbacks
|
||||
{
|
||||
IntPtr pos;
|
||||
IntPtr size;
|
||||
IntPtr close;
|
||||
IntPtr refresh;
|
||||
IntPtr focus;
|
||||
IntPtr iconify;
|
||||
IntPtr maximize;
|
||||
IntPtr fbsize;
|
||||
IntPtr scale;
|
||||
IntPtr mouseButton;
|
||||
IntPtr cursorPos;
|
||||
IntPtr cursorEnter;
|
||||
IntPtr scroll;
|
||||
IntPtr key;
|
||||
IntPtr character;
|
||||
IntPtr charmods;
|
||||
IntPtr drop;
|
||||
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 drop;
|
||||
}
|
||||
Callbacks callbacks;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe delegate void GLFWvkproc();
|
||||
internal unsafe delegate void GLFWscrollfun(glfwWindow* window, double xoffset, double yoffset);
|
||||
internal unsafe delegate void GLFWmousebuttonfun(glfwWindow* window, int button, int action, int mods);
|
||||
internal unsafe delegate void GLFWmonitorfun(GLFWmonitor* monitor, int monitorevent);
|
||||
internal unsafe delegate void GLFWmonitorfun(glfwMonitor* monitor, int monitorevent);
|
||||
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();
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace StgSharp.Graphics
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minSize">
|
||||
/// Minimun size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// Minimum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
/// <param name="maxSize">
|
||||
/// Maximum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
@@ -213,7 +213,10 @@ namespace StgSharp.Graphics
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
|
||||
{
|
||||
//TODO 重做form的尺寸极限控制
|
||||
InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract partial class Form
|
||||
{
|
||||
|
||||
|
||||
private List<FrameAsyncThread> multiFrameAsyncThreadList = new List<FrameAsyncThread>();
|
||||
private List<FrameAsyncThread> singleFrameAsyncThreadList = new List<FrameAsyncThread>();
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Create a sets of <see cref="Texture"/>
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of textures to be crated.</param>
|
||||
/// <param name="count">Amount of textures to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Texture CreateTexture(int count)
|
||||
@@ -65,7 +65,7 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexArray"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of VAO to be crated.</param>
|
||||
/// <param name="count">Amount of VAO to be created.</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected VertexArray CreateVertexArray(int count)
|
||||
@@ -74,7 +74,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create aset of <see cref="VertexBuffer"/>.
|
||||
/// Create a set of <see cref="VertexBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of Object to be created.</param>
|
||||
/// <returns></returns>
|
||||
@@ -84,5 +84,6 @@ namespace StgSharp.Graphics
|
||||
return new VertexBuffer(count, this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,14 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class Form
|
||||
public partial class glRenderStream
|
||||
{
|
||||
protected glRenderStream(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected Shader CreateShader(ShaderType type, int count)
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( GL.CreateShaderSet(count, type), type);
|
||||
}
|
||||
@@ -51,7 +55,7 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
/// <returns>New instance of <see cref="Shader"/> instance. </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected ShaderProgram CreateShaderProgram()
|
||||
protected sealed override ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
@@ -126,9 +130,9 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// Init a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram(Form binding)
|
||||
internal unsafe ShaderProgram(glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
this.binding = binding.ContextHandle;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, Form binding)
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, Form binding)
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
@@ -141,9 +141,9 @@ namespace StgSharp.Graphics
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
public unsafe Uniform(ShaderProgram program, string name, Form binding)
|
||||
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
@@ -172,9 +172,9 @@ namespace StgSharp.Graphics
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal unsafe Uniform(ShaderProgram program, string name, Form binding)
|
||||
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.graphicContextID;
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,16 +56,16 @@ namespace StgSharp.Graphics
|
||||
private static string glExtensionList;
|
||||
|
||||
/// <summary>
|
||||
/// Load all aupportable OpenGL APIs and bind them to given <see cref="Form"/> context.
|
||||
/// Load all supportted OpenGL APIs and bind them to given <see cref="Form"/> context.
|
||||
/// </summary>
|
||||
/// <param name="form">The <see cref="Form"/> used as current OpenGL context</param>
|
||||
/// <param name="loader">A delegate to get address of OprnGL api</param>
|
||||
public static unsafe void LoadGLapi(this Form form)
|
||||
/// <param name="stream">The <see cref="Form"/> used as current OpenGL context</param>
|
||||
/// <param name="loader">A delegate to get address of OpenGL api</param>
|
||||
public static unsafe void LoadGLapi(this glRenderStream stream)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)form.graphicContextID;
|
||||
GLcontext* context = (GLcontext*)stream.ContextHandle;
|
||||
GLfuncLoader loader = InternalIO.glfwGetProcAddress;
|
||||
#pragma warning disable CS8909
|
||||
if (((GLcontext*)form.graphicContextID)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
if (((GLcontext*)stream.ContextHandle)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
#pragma warning restore CS8909
|
||||
{
|
||||
return;
|
||||
@@ -103,25 +103,25 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
#region load_core_gl
|
||||
|
||||
LoadGLcore10((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore11((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore12((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore13((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore14((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore15((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore20((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore21((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore30((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore31((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore32((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore33((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore40((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore41((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore42((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore43((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore44((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore45((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore46((GLcontext*)form.graphicContextID, loader);
|
||||
LoadGLcore10((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore11((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore12((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore13((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore14((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore15((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore20((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore21((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore30((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore31((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore32((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore33((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore40((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore41((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore42((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore43((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore44((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore45((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore46((GLcontext*)stream.ContextHandle, loader);
|
||||
|
||||
#endregion load_core_gl
|
||||
}
|
||||
@@ -779,7 +779,7 @@ namespace StgSharp.Graphics
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in form of <see cref="IntPtr"/></returns>
|
||||
/// <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);
|
||||
|
||||
@@ -1,28 +1,47 @@
|
||||
using System;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract partial class glRenderStream:RenderStream
|
||||
public abstract partial class glRenderStream: RenderStream
|
||||
{
|
||||
protected sealed override void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
|
||||
{
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
protected sealed override Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name)
|
||||
{
|
||||
NativeCamera.GainAllUniforms(source, name);
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
internal sealed override void CreateCanvas((int width, int height, int depth) size, (int x_stretch, int y_stretch, int z_stretch) coordStrech, string name)
|
||||
internal unsafe sealed override void CreateCanvas()
|
||||
{
|
||||
Width = size.width; Height = size.height;
|
||||
Depth = size.depth;
|
||||
_coordStretch = coordStrech;
|
||||
Name = name;
|
||||
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width,Height,nameCode,Monitor,IntPtr.Zero
|
||||
);
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override void NativeCameraViewRange(Radius fieldOfRange,vec2d offset, (float frontDepth, float backDepth) viewDepth)
|
||||
{
|
||||
NativeCamera.SetViewRange(fieldOfRange,this.Size, offset, viewDepth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,11 +59,11 @@ namespace StgSharp.Graphics
|
||||
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
|
||||
if (SharedCanvas == IntPtr.Zero)
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, monitor, IntPtr.Zero);
|
||||
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, Monitor, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, monitor, SharedCanvas.CanvasHandle);
|
||||
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, Monitor, SharedCanvas);
|
||||
}
|
||||
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
|
||||
{
|
||||
@@ -64,8 +83,16 @@ namespace StgSharp.Graphics
|
||||
InternalIO.glfwMakeContextCurrent(CanvasHandle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
internal sealed override void InternalInit()
|
||||
{
|
||||
CreateCanvas();
|
||||
MakeAsCurrentContext();
|
||||
this.LoadGLapi();
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -80,5 +107,6 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
Deinit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -41,18 +43,27 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream
|
||||
{
|
||||
protected (int x, int y, int z) _coordStretch;
|
||||
private int refDepth;
|
||||
protected Camera NativeCamera;
|
||||
|
||||
private IntPtr canvasHandle;
|
||||
private IntPtr contextHandle;
|
||||
private IntPtr monitor;
|
||||
private IntPtr sharedCanvas;
|
||||
|
||||
private int height;
|
||||
private IntPtr monitor;
|
||||
private IntPtr sharedCanvas;
|
||||
private int width;
|
||||
protected (int x, int y, int z) _coordStretch;
|
||||
protected string name;
|
||||
private Camera nativeCamera;
|
||||
|
||||
protected RenderStream(RenderStreamConstructArgs args)
|
||||
{
|
||||
height = args.Height;
|
||||
monitor = args.Monitor;
|
||||
width = args.Width;
|
||||
name = args.Name;
|
||||
monitor = args.Monitor;
|
||||
_coordStretch = args.UnitCubeSize;
|
||||
}
|
||||
|
||||
public IntPtr CanvasHandle
|
||||
{
|
||||
@@ -66,26 +77,30 @@ namespace StgSharp.Graphics
|
||||
internal set => contextHandle = value;
|
||||
}
|
||||
|
||||
public int Depth
|
||||
internal protected Camera NativeCamera
|
||||
{
|
||||
get => refDepth;
|
||||
internal set => refDepth = value;
|
||||
get => nativeCamera;
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
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 => height;
|
||||
internal set => height = value;
|
||||
}
|
||||
|
||||
public vec3d GlobalCoordSize
|
||||
{
|
||||
get
|
||||
internal set
|
||||
{
|
||||
return (
|
||||
Width * 1.0f / _coordStrech.x,
|
||||
Height * 1.0f / _coordStrech.y,
|
||||
refDepth * 1.0f / _coordStrech.z);
|
||||
height = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,24 +122,86 @@ namespace StgSharp.Graphics
|
||||
internal set => sharedCanvas = value;
|
||||
}
|
||||
|
||||
public vec2d Size
|
||||
{
|
||||
get => new vec2d(width, height);
|
||||
internal set
|
||||
{
|
||||
height = (int)value.Y;
|
||||
width = (int)value.X;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
internal set => width = value;
|
||||
internal set
|
||||
{
|
||||
width = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract void CreateCanvas(
|
||||
(int width,int height,int depth) size, (int x_stretch,int y_stretch, int z_stretch) coordStrech, string name
|
||||
);
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minWidth">Minimum width of current form</param>
|
||||
/// <param name="minHeight">Minimum height of current form</param>
|
||||
/// <param name="maxWidth">Maximum width of current form</param>
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
|
||||
|
||||
internal abstract void CreateCanvas();
|
||||
|
||||
#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{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.
|
||||
/// </summary>
|
||||
/// <param name="source">Shader using this camera</param>
|
||||
/// <param name="name">Name of projection camera named in shader</param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}"/>(T 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();
|
||||
internal abstract void InternalInit();
|
||||
internal abstract void InternalTerminate();
|
||||
#endregion
|
||||
|
||||
#region public operation
|
||||
protected abstract void Deinit();
|
||||
protected abstract void Init();
|
||||
protected abstract void Main();
|
||||
protected abstract void Deinit();
|
||||
protected abstract void ProcessInput();
|
||||
#endregion
|
||||
|
||||
internal abstract void InternalInit();
|
||||
internal abstract void InternalDraw();
|
||||
internal abstract void InternalTerminate();
|
||||
#region public resource generator
|
||||
|
||||
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
|
||||
protected abstract ShaderProgram CreateShaderProgram();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class RenderStreamConstructArgs
|
||||
{
|
||||
|
||||
public int Height { get; set; }
|
||||
public IntPtr Monitor { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Width { get; set; }
|
||||
public (int x, int y, int z) UnitCubeSize { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ShaderGenerator.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.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderGenerator
|
||||
{
|
||||
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>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShaderFunction
|
||||
{
|
||||
private List<string> codeList;
|
||||
private List<ShaderParameter> inputList;
|
||||
private string name;
|
||||
private ShaderParameter outPut;
|
||||
|
||||
public int ParameterCount => inputList.Count;
|
||||
|
||||
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
|
||||
{
|
||||
if (inputParams.Length != function.ParameterCount)
|
||||
{
|
||||
// Param list length not equal
|
||||
throw new ArgumentException("Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
if (!ShaderParameter.IsSameType(outPut, function.outPut))
|
||||
{
|
||||
// Type of returning value not qual
|
||||
throw new Exception("Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
for (int i = 0; i < inputParams.Length; i++)
|
||||
{
|
||||
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
|
||||
{
|
||||
// Input type not match
|
||||
throw new Exception("Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
}
|
||||
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
|
||||
if (outPut != ShaderParameter.Void)
|
||||
{
|
||||
codeLine += $"{outPut.name} = ";
|
||||
}
|
||||
codeLine += $"{function.name}(";
|
||||
foreach (ShaderParameter inputParam in inputParams)
|
||||
{
|
||||
codeLine += inputParam.name;
|
||||
}
|
||||
codeLine += ");\n";
|
||||
codeList.Add(codeLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public ShaderParameter(string name, InternalShaderType type)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
isReadOnly = false;
|
||||
}
|
||||
|
||||
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
|
||||
{
|
||||
if (param1.type != InternalShaderType.Struct)
|
||||
{
|
||||
return param1.type == param2.type;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Struct is currently not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public static InternalShaderType TypeMarshal<T>() where T : struct
|
||||
{
|
||||
switch (Type.GetTypeCode(typeof(T)))
|
||||
{
|
||||
case TypeCode.Single:
|
||||
return InternalShaderType.Float;
|
||||
case TypeCode.Double:
|
||||
return InternalShaderType.Double;
|
||||
case TypeCode.Int32:
|
||||
return InternalShaderType.Int;
|
||||
case TypeCode.UInt32:
|
||||
return InternalShaderType.UInt;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (typeof(T).Name)
|
||||
{
|
||||
case "vec4d":
|
||||
return InternalShaderType.Vector4;
|
||||
case "Matrix2x2":
|
||||
return InternalShaderType.Matrix2x2;
|
||||
case "Matrix2x3":
|
||||
return InternalShaderType.Matrix2x3;
|
||||
case "Matrix2x4":
|
||||
return InternalShaderType.Matrix2x4;
|
||||
case "Matrix3x2":
|
||||
return InternalShaderType.Matrix3x2;
|
||||
case "Matrix3x3":
|
||||
return InternalShaderType.Matrix3x3;
|
||||
case "Matrix3x4":
|
||||
return InternalShaderType.Matrix3x4;
|
||||
case "Matrix4x2":
|
||||
return InternalShaderType.Matrix4x2;
|
||||
case "Matrix4x3":
|
||||
return InternalShaderType.Matrix4x3;
|
||||
case "Matrix4x4":
|
||||
return InternalShaderType.Matrix4x4;
|
||||
default:
|
||||
throw new ArgumentException("Not supported shader data type.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum InternalShaderType
|
||||
{
|
||||
#pragma warning disable CS1591
|
||||
Struct, Void,
|
||||
Int, UInt,
|
||||
Float, Double,
|
||||
Vector2, Vector3, Vector4,
|
||||
VectorD2, VectorD3, VectorD4,
|
||||
Matrix2x2, Matrix2x3, Matrix2x4,
|
||||
Matrix3x2, Matrix3x3, Matrix3x4,
|
||||
Matrix4x2, Matrix4x3, Matrix4x4,
|
||||
#pragma warning restore CS1591
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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)[] UniformPais)
|
||||
{
|
||||
uniformPair = new Dictionary<glSHandle, ShaderStructMember>();
|
||||
if (UniformPais.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in UniformPais)
|
||||
{
|
||||
uniformPair.Add(item.Item1,item.Item2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal ShaderStruct() { }
|
||||
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
GLcontext* gl = GL.api;
|
||||
foreach (var uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.Value;
|
||||
ShaderStructMember s = uniform.Value;
|
||||
switch (s.type)
|
||||
{
|
||||
case InternalShaderType.Struct: throw new ArgumentException(
|
||||
"Incorrect type \"Struct\" defined in this self define type");
|
||||
case InternalShaderType.Void:throw new ArgumentException(
|
||||
"Incorrect type \"Void\" defined in this self define type");
|
||||
case InternalShaderType.Float:
|
||||
gl->glUniform1f(id, (float)s.value);
|
||||
break;
|
||||
case InternalShaderType.Int:
|
||||
gl->glUniform1f(id, (int)s.value);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Unknown\" defined in this self define type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user