daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
@@ -1,4 +1,34 @@
using StgSharp.Graphics.OpenGL;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -10,26 +40,26 @@ 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>
public void GainAllUniforms(ShaderProgram source, params string[] uniformName);
/// <summary>
///
/// </summary>
/// <returns></returns>
public ShaderStruct GetConvertedGLtype();
/// <summary>
///
/// </summary>
public void SetAllUniforms();
}
}
@@ -44,30 +44,31 @@ 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( GL.CreateShaderSet(count, type), type, this);
}
/// <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 GlFunction GL;
private readonly OpenGLFunction GL;
internal readonly GlHandle[] handle;
public readonly ShaderType type;
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
internal unsafe Shader(GlHandle[] handle, ShaderType usage, glRenderStream stream)
{
this.handle = handle;
@@ -75,6 +76,8 @@ namespace StgSharp.Graphics.OpenGL
type = usage;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
/// <summary>
/// Attach one shader code to a shader program.
/// </summary>
@@ -86,14 +89,13 @@ namespace StgSharp.Graphics.OpenGL
GL.AttachShader(target.handle, handle[index]);
}
public static byte[] FromCodeFile(string fileRoute)
public void CheckStatus(int index, ShaderStatus status)
{
string str = File.ReadAllText(fileRoute);
if (string.IsNullOrEmpty(str))
string log = GL.GetShaderStatus(this, index, (int)status);
if (!string.IsNullOrEmpty(log))
{
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
throw new Exception($"{$"Shader Error \t{status}\n"}{log}");
}
return Encoding.UTF8.GetBytes(str);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -105,7 +107,7 @@ namespace StgSharp.Graphics.OpenGL
}
GL.LoadShaderSource(handle[index], codeStream);
GL.CompileShader(handle[index]);
CheckStatus(index,ShaderStatus.CompileStatus);
CheckStatus(index, ShaderStatus.CompileStatus);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -115,14 +117,24 @@ namespace StgSharp.Graphics.OpenGL
{
throw new ArgumentNullException(nameof(codeStream));
}
GL.LoadShaderSource(handle[index],Encoding.ASCII.GetBytes( codeStream));
GL.LoadShaderSource(handle[index], Encoding.ASCII.GetBytes(codeStream));
GL.CompileShader(handle[index]);
CheckStatus(index, ShaderStatus.CompileStatus);
}
public override string ToString()
public void FromBytes(byte[] stream)
{
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
throw new NotImplementedException();
}
public static byte[] FromCodeFile(string fileRoute)
{
string str = File.ReadAllText(fileRoute);
if (string.IsNullOrEmpty(str))
{
throw new InvalidOperationException($"Cannot load and GLSL code from {fileRoute}");
}
return Encoding.UTF8.GetBytes(str);
}
public byte[] GetBytes()
@@ -130,24 +142,16 @@ namespace StgSharp.Graphics.OpenGL
return Array.Empty<byte>();
}
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);
}
}
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
@@ -157,7 +161,8 @@ namespace StgSharp.Graphics.OpenGL
public class ShaderProgram
{
private readonly GlFunction GL;
private readonly OpenGLFunction GL;
internal readonly GlHandle handle;
/// <summary>
@@ -191,7 +196,7 @@ namespace StgSharp.Graphics.OpenGL
where T : struct
where U : struct
{
return new Uniform<T, U>(GL.GetUniformLocation(this.handle,name));
return new Uniform<T, U>(GL.GetUniformLocation(this.handle, name));
}
/// <summary>
@@ -42,109 +42,112 @@ 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 unsafe Uniform(GlHandle id)
{
this.id = id;
}
internal Uniform()
{
}
internal unsafe Uniform(GlHandle id)
{
this.id = id;
}
internal static Uniform<T> FromHandle(GlHandle handle)
{
return new Uniform<T>() { id = handle };
return new Uniform<T> { id = handle };
}
}
public sealed class Uniform<T, U>: Uniform
public sealed class Uniform<T, U> : Uniform
where T : struct
where U : struct
{
internal unsafe Uniform(GlHandle id)
{
this.id = id;
}
internal Uniform()
{
}
internal static Uniform<T,U> FromHandle(GlHandle handle)
internal unsafe Uniform(GlHandle id)
{
return new Uniform<T, U>() { id = handle };
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
public sealed class Uniform<T, U, V> : Uniform
where T : struct
where U : struct
where V : struct
{
internal unsafe Uniform(GlHandle id)
{
this.id = id;
}
internal Uniform()
{
}
internal static Uniform<T,U,V> FromHandle(GlHandle handle)
internal unsafe Uniform(GlHandle id)
{
return new Uniform<T, U, V>() { id = handle };
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
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 Uniform()
{
}
internal static Uniform<T, U, V, W> FromHandle(GlHandle handle)
{
return new Uniform<T, U, V, W>() { id = handle };
return new Uniform<T, U, V, W> { id = handle };
}
}
public unsafe partial class GlFunction
public unsafe partial class OpenGLFunction
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue
(Uniform<Matrix44> uniform, Matrix44 mat)
@@ -157,7 +160,7 @@ namespace StgSharp.Graphics.OpenGL
public void SetUniformValue(Uniform<float, float, float, float> uniform, vec4d vec)
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.SignedValue , 4, &temp);
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
}
@@ -165,37 +168,37 @@ namespace StgSharp.Graphics.OpenGL
public void SetUniformValue(Uniform<vec4d> uniform, vec4d vec)
{
vec4d temp = vec;
Context.glUniform1fv(uniform.id.SignedValue , 4, &temp);
Context.glUniform1fv(uniform.id.SignedValue, 4, &temp);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<float> uniform, float v0)
{
Context.glUniform1f(uniform.id.SignedValue , v0);
Context.glUniform1f(uniform.id.SignedValue, v0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetUniformValue(Uniform<int> uniform, int i0)
{
Context.glUniform1i(uniform.id.SignedValue , 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);
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);
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);
Context.glUniform4f(uniform.id.SignedValue, v0, v1, v2, v3);
}
}