daily update on 20240528 by nitload youmu
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -39,15 +39,15 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public partial class glRenderStream
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override Shader CreateShaderSegment(ShaderType type, int count)
|
||||
{
|
||||
return new Shader( GL.CreateShaderSet(count, type), type);
|
||||
return new Shader( glFunc.CreateShaderSet(count, type), type);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader"/> program
|
||||
@@ -72,7 +72,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
this.handle = handle;
|
||||
context = GL.CurrentContextHandle;
|
||||
context = glFunc.CurrentContextHandle;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
@@ -84,31 +84,43 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AttachTo(int index, ShaderProgram target)
|
||||
{
|
||||
GL.AttachShader(target.handle, handle[index]);
|
||||
glFunc.AttachShader(target.handle, handle[index]);
|
||||
}
|
||||
|
||||
public static string FromCodeFile(string fileRoute)
|
||||
public static byte[] FromCodeFile(string fileRoute)
|
||||
{
|
||||
string str = File.ReadAllText(fileRoute);
|
||||
if (str == "")
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
throw new Exception($"Cannot load and GLSL code from {fileRoute}");
|
||||
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
|
||||
}
|
||||
return str;
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string code)
|
||||
public unsafe void Compile(int index, byte[] codeStream)
|
||||
{
|
||||
if (code == null)
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException("Must provide enough code");
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
GL.LoadShaderSource(handle[index], $"{code}\0");
|
||||
GL.CompileShader(handle[index]);
|
||||
glFunc.LoadShaderSource(handle[index], codeStream);
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index,ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Compile(int index, string codeStream)
|
||||
{
|
||||
if (codeStream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeStream));
|
||||
}
|
||||
glFunc.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
|
||||
glFunc.CompileShader(handle[index]);
|
||||
CheckStatus(index, ShaderStatus.CompileStatus);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
@@ -122,7 +134,7 @@ namespace StgSharp.Graphics
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = GL.GetShaderStatus(this,index, (int)status);
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (log != "")
|
||||
{
|
||||
throw new Exception($"Shader Error\n{status}\n" + log);
|
||||
@@ -147,7 +159,6 @@ namespace StgSharp.Graphics
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly IntPtr binding;
|
||||
internal readonly glHandle handle;
|
||||
|
||||
@@ -157,7 +168,7 @@ namespace StgSharp.Graphics
|
||||
internal unsafe ShaderProgram(glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
handle = GL.CreateProgram();
|
||||
handle = glFunc.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,7 +253,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram(handle);
|
||||
glFunc.UseProgram(handle);
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
|
||||
@@ -38,7 +38,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
namespace StgSharp.Graphics.GL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
@@ -65,14 +65,14 @@ namespace StgSharp.Graphics
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -101,14 +101,14 @@ namespace StgSharp.Graphics
|
||||
ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name, IntPtr binding)
|
||||
{
|
||||
this.binding = binding;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -137,14 +137,14 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = GL.CurrentContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
public unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -175,14 +175,14 @@ namespace StgSharp.Graphics
|
||||
internal unsafe Uniform(ShaderProgram program, string name, glRenderStream binding)
|
||||
{
|
||||
this.binding = binding.ContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal unsafe Uniform(
|
||||
ShaderProgram program, string name)
|
||||
{
|
||||
this.binding = GL.CurrentContextHandle;
|
||||
id = GL.GetUniformLocation(program.handle, name);
|
||||
this.binding = glFunc.CurrentContextHandle;
|
||||
id = glFunc.GetUniformLocation(program.handle, name);
|
||||
}
|
||||
|
||||
internal Uniform()
|
||||
@@ -197,55 +197,57 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
internal static partial class GL
|
||||
internal static partial class glFunc
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
public unsafe static void SetUniformValue
|
||||
(Uniform<Matrix44> uniform, Matrix44 mat)
|
||||
{
|
||||
Matrix44 temp = mat;
|
||||
Context.glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
public unsafe static void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static void SetValue(Uniform<vec4d> uniform, vec4d vec)
|
||||
{
|
||||
vec4d temp = vec;
|
||||
Context.glUniform1fv(uniform.id.Value , 4, &temp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float> uniform, float v0)
|
||||
public static unsafe void SetUniformValue(Uniform<float> uniform, float v0)
|
||||
{
|
||||
Context.glUniform1f(uniform.id.Value , v0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<int> uniform, int i0)
|
||||
public static unsafe void SetUniformValue(Uniform<int> uniform, int i0)
|
||||
{
|
||||
Context.glUniform1i(uniform.id.Value , i0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float> uniform, float v0, float v1)
|
||||
{
|
||||
Context.glUniform2f(uniform.id.Value , v0, v1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
|
||||
{
|
||||
Context.glUniform3f(uniform.id.Value , v0, v1, v2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
public static unsafe void SetUniformValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
|
||||
{
|
||||
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user