genericed graphic vector design
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Tests and Experiments
|
||||
|
||||
This directory contains automated tests, manual diagnostic programs, and standalone experiments. It is separate from `src` so test-only dependencies and exploratory code are not included in production assemblies.
|
||||
|
||||
## Directory map
|
||||
|
||||
| Directory | Purpose |
|
||||
| --- | --- |
|
||||
| `StgSharpDebug` | Executable test harness for manual debugging and stress testing of allocators, matrices, rendering, NGRA, and other subsystems. This is not an automated unit-test suite. |
|
||||
| `STgSharpTest` | Older MSTest-based tests for the former Script/EXPRESS and related projects. Some references and machine-specific test data are legacy and may require repair before the project can run. |
|
||||
| `SingleFile` | Standalone source experiments and generated-code samples that are not part of a project or the normal build. |
|
||||
|
||||
Run the active debug harness directly when investigating a subsystem:
|
||||
|
||||
```powershell
|
||||
dotnet run --project test/StgSharpDebug/StgSharpDebug.csproj
|
||||
```
|
||||
|
||||
New repeatable tests should use a test project and avoid machine-specific paths, external mutable data, and dependencies on previous test execution. Keep one-off investigations in `SingleFile` or the manual debug harness until their expected behavior is stable enough for automation.
|
||||
@@ -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