genericed graphic vector design
This commit is contained in:
@@ -9,7 +9,8 @@ using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphics;
|
||||
using StgSharp.Mathematics.Numeric.Graphics;
|
||||
using StgSharp.Mathematics.Numeric.Graphics;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
@@ -202,98 +203,6 @@ namespace StgSharp
|
||||
0)) * rotation;
|
||||
}
|
||||
|
||||
private Shader CreateShaderSet(
|
||||
ShaderType type,
|
||||
int count
|
||||
)
|
||||
{
|
||||
GlHandle[] handles = new GlHandle[count];
|
||||
for (int index = 0; index < handles.Length; index++) {
|
||||
handles[index] = GL.CreateShader((uint)type);
|
||||
}
|
||||
return new Shader(handles, type);
|
||||
}
|
||||
|
||||
private void CompileShaderFromFile(
|
||||
GlHandle shader,
|
||||
string path
|
||||
)
|
||||
{
|
||||
byte[] source = File.ReadAllBytes(path);
|
||||
if (source.Length == 0) {
|
||||
throw new InvalidOperationException($"Shader source is empty: {path}");
|
||||
}
|
||||
|
||||
GL.ShaderSource(shader, source);
|
||||
GL.CompileShader(shader);
|
||||
|
||||
Span<int> status = stackalloc int[1];
|
||||
GL.GetShaderiv(shader, glConst.COMPILE_STATUS, status);
|
||||
if (status[0] != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to compile shader '{path}'.{Environment.NewLine}{GetShaderInfoLog(shader)}");
|
||||
}
|
||||
|
||||
private void LinkShaderProgram(
|
||||
GlHandle program
|
||||
)
|
||||
{
|
||||
GL.LinkProgram(program);
|
||||
|
||||
Span<int> status = stackalloc int[1];
|
||||
GL.GetProgramiv(program, glConst.LINK_STATUS, status);
|
||||
if (status[0] != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to link shader program.{Environment.NewLine}{GetProgramInfoLog(program)}");
|
||||
}
|
||||
|
||||
private string GetShaderInfoLog(
|
||||
GlHandle shader
|
||||
)
|
||||
{
|
||||
Span<int> requiredLength = stackalloc int[1];
|
||||
GL.GetShaderiv(shader, glConst.INFO_LOG_LENGTH, requiredLength);
|
||||
if (requiredLength[0] <= 1) {
|
||||
return "OpenGL did not provide a shader info log.";
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[requiredLength[0]];
|
||||
GL.GetShaderInfoLog(shader, out int written, bytes);
|
||||
return Encoding.UTF8.GetString(bytes, 0, Math.Clamp(written, 0, bytes.Length))
|
||||
.TrimEnd('\0');
|
||||
}
|
||||
|
||||
private string GetProgramInfoLog(
|
||||
GlHandle program
|
||||
)
|
||||
{
|
||||
Span<int> requiredLength = stackalloc int[1];
|
||||
GL.GetProgramiv(program, glConst.INFO_LOG_LENGTH, requiredLength);
|
||||
if (requiredLength[0] <= 1) {
|
||||
return "OpenGL did not provide a program info log.";
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[requiredLength[0]];
|
||||
GL.GetProgramInfoLog(program, out int written, bytes);
|
||||
return Encoding.UTF8.GetString(bytes, 0, Math.Clamp(written, 0, bytes.Length))
|
||||
.TrimEnd('\0');
|
||||
}
|
||||
|
||||
private void DeleteShaderSet(
|
||||
Shader shaderSet
|
||||
)
|
||||
{
|
||||
for (int index = 0; index < shaderSet.Count; index++) {
|
||||
GL.DeleteShader(shaderSet[index]);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CustomizeDeinit()
|
||||
{
|
||||
GL.DeleteProgram(s.Handle);
|
||||
@@ -521,5 +430,99 @@ namespace StgSharp
|
||||
GL.Assert(true);
|
||||
}
|
||||
|
||||
private void CompileShaderFromFile(
|
||||
GlHandle shader,
|
||||
string path
|
||||
)
|
||||
{
|
||||
byte[] source = File.ReadAllBytes(path);
|
||||
if (source.Length == 0) {
|
||||
throw new InvalidOperationException($"Shader source is empty: {path}");
|
||||
}
|
||||
|
||||
GL.ShaderSource(shader, source);
|
||||
GL.CompileShader(shader);
|
||||
|
||||
Span<int> status = stackalloc int[1];
|
||||
GL.GetShaderiv(shader, glConst.COMPILE_STATUS, status);
|
||||
if (status[0] != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to compile shader '{path}'.{Environment.NewLine}{GetShaderInfoLog(shader)}");
|
||||
}
|
||||
|
||||
private Shader CreateShaderSet(
|
||||
ShaderType type,
|
||||
int count
|
||||
)
|
||||
{
|
||||
GlHandle[] handles = new GlHandle[count];
|
||||
for (int index = 0; index < handles.Length; index++) {
|
||||
handles[index] = GL.CreateShader((uint)type);
|
||||
}
|
||||
return new Shader(handles, type);
|
||||
}
|
||||
|
||||
private void DeleteShaderSet(
|
||||
Shader shaderSet
|
||||
)
|
||||
{
|
||||
for (int index = 0; index < shaderSet.Count; index++) {
|
||||
GL.DeleteShader(shaderSet[index]);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetProgramInfoLog(
|
||||
GlHandle program
|
||||
)
|
||||
{
|
||||
Span<int> requiredLength = stackalloc int[1];
|
||||
GL.GetProgramiv(program, glConst.INFO_LOG_LENGTH, requiredLength);
|
||||
if (requiredLength[0] <= 1) {
|
||||
return "OpenGL did not provide a program info log.";
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[requiredLength[0]];
|
||||
GL.GetProgramInfoLog(program, out int written, bytes);
|
||||
return Encoding.UTF8
|
||||
.GetString(bytes, 0, Math.Clamp(written, 0, bytes.Length))
|
||||
.TrimEnd('\0');
|
||||
}
|
||||
|
||||
private string GetShaderInfoLog(
|
||||
GlHandle shader
|
||||
)
|
||||
{
|
||||
Span<int> requiredLength = stackalloc int[1];
|
||||
GL.GetShaderiv(shader, glConst.INFO_LOG_LENGTH, requiredLength);
|
||||
if (requiredLength[0] <= 1) {
|
||||
return "OpenGL did not provide a shader info log.";
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[requiredLength[0]];
|
||||
GL.GetShaderInfoLog(shader, out int written, bytes);
|
||||
return Encoding.UTF8
|
||||
.GetString(bytes, 0, Math.Clamp(written, 0, bytes.Length))
|
||||
.TrimEnd('\0');
|
||||
}
|
||||
|
||||
private void LinkShaderProgram(
|
||||
GlHandle program
|
||||
)
|
||||
{
|
||||
GL.LinkProgram(program);
|
||||
|
||||
Span<int> status = stackalloc int[1];
|
||||
GL.GetProgramiv(program, glConst.LINK_STATUS, status);
|
||||
if (status[0] != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to link shader program.{Environment.NewLine}{GetProgramInfoLog(program)}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user