daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user