Skip to content

Commit 4212ee7

Browse files
committed
alpha 4
1 parent 1cd24d8 commit 4212ee7

31 files changed

Lines changed: 1436 additions & 1109 deletions

Directory.build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<Deterministic>true</Deterministic>
4-
<Version>0.3.0-alpha.3</Version>
4+
<Version>0.3.0-alpha.4</Version>
55
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Nullable>enable</Nullable>

examples/Render3D/Program.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
Start<Program>();
88

9-
109
partial class Program : Simulation
1110
{
1211
Vertex[] vertices = [
@@ -48,13 +47,9 @@ partial class Program : Simulation
4847
new Vertex(new(-0.5f, 0.5f, -0.5f), new(0.0f, 1.0f))
4948
];
5049

51-
ITexture logo;
52-
5350
public override void OnInitialize()
5451
{
5552
ShaderCompiler.DumpShaders = true;
56-
logo = Graphics.LoadTexture("logo-512x512.png");
57-
logo.WrapModeY = logo.WrapModeX = WrapMode.Repeat;
5853
}
5954

6055
public override void OnRender(ICanvas canvas)
@@ -63,7 +58,6 @@ public override void OnRender(ICanvas canvas)
6358

6459
var canvasShader = new TheCanvasShader()
6560
{
66-
tex = logo,
6761
};
6862

6963
var vertexShader = new CubeVertexShader()
@@ -95,16 +89,9 @@ class TheCanvasShader : CanvasShader
9589
[VertexShaderOutput]
9690
Vector2 uv;
9791

98-
public ITexture tex;
99-
10092
public override ColorF GetPixelColor(Vector2 position)
10193
{
102-
ColorF x = tex.SampleUV(uv * 10);
103-
if (x.A < 0.001f)
104-
{
105-
ShaderIntrinsics.Discard();
106-
}
107-
return x;
94+
return new(uv.X, uv.Y, 0, 1);
10895
}
10996
}
11097

examples/RenderCube/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ partial class Program : Simulation
5050
ITexture logo;
5151
IDepthMask depthMask;
5252

53+
IGeometry cubeGeometry;
54+
5355
public override void OnInitialize()
5456
{
55-
SetFixedResolution(400, 400, Color.Black);
57+
SetFixedResolution(200, 200, Color.Black);
5658

5759
logo = Graphics.LoadTexture("logo-512x512.png");
5860
logo.WrapModeY = logo.WrapModeX = WrapMode.Repeat;
5961

6062
depthMask = Graphics.CreateDepthMask(Window.Width, Window.Height);
63+
64+
uint[] indices = Enumerable.Range(0, 36).Select(i => (uint)i).ToArray();
65+
cubeGeometry = Graphics.CreateGeometry<Vertex>(vertices, indices);
6166
}
6267

6368
public override void OnRender(ICanvas canvas)
@@ -81,6 +86,9 @@ public override void OnRender(ICanvas canvas)
8186
canvas.Mask(depthMask);
8287
canvas.WriteMask(depthMask);
8388
canvas.DrawTriangles<Vertex>(vertices);
89+
90+
vertexShader.world = Matrix4x4.CreateRotationY(Time.TotalTime * -Angle.ToRadians(60)) * Matrix4x4.CreateTranslation(0, 1, 0);
91+
canvas.DrawGeometry(this.cubeGeometry);
8492
}
8593
}
8694

src/SimulationFramework.Desktop/DesktopMouseProvider.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,6 @@ public unsafe void SetCursor(ReadOnlySpan<Color> colors, int width, int height,
147147

148148
UpdateCursor(glfw.CreateCursor(&image, centerX, centerY));
149149
}
150-
151-
152-
//fixed (Color* colorsPtr = &colors[0])
153-
//{
154-
// var memoryManager = new UnsafePinnedMemoryManager<byte>((byte*)colorsPtr, sizeof(Color) * width * height);
155-
156-
// // TODO: silk.net leaks glfw cursor objects like mad here?!?
157-
// // https://github.com/dotnet/Silk.NET/blob/main/src/Input/Silk.NET.Input.Glfw/GlfwCursor.cs#L266
158-
159-
// this.mouse.Cursor.Image = new(width, height, memoryManager.Memory);
160-
//}
161-
162-
//this.mouse.Cursor.HotspotX = centerX;
163-
//this.mouse.Cursor.HotspotY = centerY;
164-
165-
//this.mouse.Cursor.Type = CursorType.Custom;
166150
}
167151

168152
public void SetCursor(SystemCursor cursor)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
using SimulationFramework.Drawing;
22
using SimulationFramework.OpenGL.Geometry;
3+
using SimulationFramework.OpenGL.Geometry.Streams;
34
using System;
45
using System.Numerics;
56

67
namespace SimulationFramework.OpenGL.Commands;
78

89
class GeometryRenderCommand : RenderCommand
910
{
10-
public IGeometry Geometry { get; init; }
11+
public GLGeometry Geometry { get; init; }
1112
Matrix4x4[] instanceTransforms;
1213

13-
public GeometryRenderCommand(IGeometry geometry, GeometryEffect effect, CanvasState state) : base(effect, state)
14+
public GeometryRenderCommand(GLGeometry geometry, GeometryEffect effect, CanvasState state) : base(effect, state)
1415
{
1516
Geometry = geometry;
1617
}
1718

1819
public override void Submit()
1920
{
20-
throw new NotImplementedException();
21+
Geometry.Draw(in this.State);
2122
}
2223
}

src/SimulationFramework.OpenGL/Commands/StreamRenderCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override void Submit()
2323

2424
for (int i = 0; i < draws.Count; i++)
2525
{
26-
glDrawArrays(draws[i].triangles ? GL_TRIANGLES : GL_LINES, draws[i].offset, draws[i].count);
26+
glDrawArrays(draws[i].triangles ? GL_TRIANGLES : GL_LINES, draws[i].vertexOffset, draws[i].count);
2727
}
2828
}
2929

@@ -32,7 +32,7 @@ public void AddCommand(bool triangles, int offset, int count)
3232
if (draws.Count > 0)
3333
{
3434
DrawInfo lastDraw = draws[^1];
35-
if (lastDraw.offset + lastDraw.count == offset && lastDraw.triangles == triangles)
35+
if (lastDraw.vertexOffset + lastDraw.count == offset && lastDraw.triangles == triangles)
3636
{
3737
lastDraw.count += count;
3838
draws[^1] = lastDraw;
@@ -43,15 +43,15 @@ public void AddCommand(bool triangles, int offset, int count)
4343
draws.Add(new()
4444
{
4545
triangles = triangles,
46-
offset = offset,
46+
vertexOffset = offset,
4747
count = count
4848
});
4949
}
5050

5151
private struct DrawInfo
5252
{
5353
public bool triangles;
54-
public int offset;
54+
public int vertexOffset;
5555
public int count;
5656
}
5757
}

0 commit comments

Comments
 (0)