Skip to content

Commit

Permalink
alpha 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Redninja106 committed Aug 25, 2024
1 parent 1cd24d8 commit 4212ee7
Show file tree
Hide file tree
Showing 31 changed files with 1,436 additions and 1,109 deletions.
2 changes: 1 addition & 1 deletion Directory.build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Deterministic>true</Deterministic>
<Version>0.3.0-alpha.3</Version>
<Version>0.3.0-alpha.4</Version>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
15 changes: 1 addition & 14 deletions examples/Render3D/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

Start<Program>();


partial class Program : Simulation
{
Vertex[] vertices = [
Expand Down Expand Up @@ -48,13 +47,9 @@ partial class Program : Simulation
new Vertex(new(-0.5f, 0.5f, -0.5f), new(0.0f, 1.0f))
];

ITexture logo;

public override void OnInitialize()
{
ShaderCompiler.DumpShaders = true;
logo = Graphics.LoadTexture("logo-512x512.png");
logo.WrapModeY = logo.WrapModeX = WrapMode.Repeat;
}

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

var canvasShader = new TheCanvasShader()
{
tex = logo,
};

var vertexShader = new CubeVertexShader()
Expand Down Expand Up @@ -95,16 +89,9 @@ class TheCanvasShader : CanvasShader
[VertexShaderOutput]
Vector2 uv;

public ITexture tex;

public override ColorF GetPixelColor(Vector2 position)
{
ColorF x = tex.SampleUV(uv * 10);
if (x.A < 0.001f)
{
ShaderIntrinsics.Discard();
}
return x;
return new(uv.X, uv.Y, 0, 1);
}
}

Expand Down
10 changes: 9 additions & 1 deletion examples/RenderCube/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ partial class Program : Simulation
ITexture logo;
IDepthMask depthMask;

IGeometry cubeGeometry;

public override void OnInitialize()
{
SetFixedResolution(400, 400, Color.Black);
SetFixedResolution(200, 200, Color.Black);

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

depthMask = Graphics.CreateDepthMask(Window.Width, Window.Height);

uint[] indices = Enumerable.Range(0, 36).Select(i => (uint)i).ToArray();
cubeGeometry = Graphics.CreateGeometry<Vertex>(vertices, indices);
}

public override void OnRender(ICanvas canvas)
Expand All @@ -81,6 +86,9 @@ public override void OnRender(ICanvas canvas)
canvas.Mask(depthMask);
canvas.WriteMask(depthMask);
canvas.DrawTriangles<Vertex>(vertices);

vertexShader.world = Matrix4x4.CreateRotationY(Time.TotalTime * -Angle.ToRadians(60)) * Matrix4x4.CreateTranslation(0, 1, 0);
canvas.DrawGeometry(this.cubeGeometry);
}
}

Expand Down
16 changes: 0 additions & 16 deletions src/SimulationFramework.Desktop/DesktopMouseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,6 @@ public unsafe void SetCursor(ReadOnlySpan<Color> colors, int width, int height,

UpdateCursor(glfw.CreateCursor(&image, centerX, centerY));
}


//fixed (Color* colorsPtr = &colors[0])
//{
// var memoryManager = new UnsafePinnedMemoryManager<byte>((byte*)colorsPtr, sizeof(Color) * width * height);

// // TODO: silk.net leaks glfw cursor objects like mad here?!?
// // https://github.com/dotnet/Silk.NET/blob/main/src/Input/Silk.NET.Input.Glfw/GlfwCursor.cs#L266

// this.mouse.Cursor.Image = new(width, height, memoryManager.Memory);
//}

//this.mouse.Cursor.HotspotX = centerX;
//this.mouse.Cursor.HotspotY = centerY;

//this.mouse.Cursor.Type = CursorType.Custom;
}

public void SetCursor(SystemCursor cursor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using SimulationFramework.Drawing;
using SimulationFramework.OpenGL.Geometry;
using SimulationFramework.OpenGL.Geometry.Streams;
using System;
using System.Numerics;

namespace SimulationFramework.OpenGL.Commands;

class GeometryRenderCommand : RenderCommand
{
public IGeometry Geometry { get; init; }
public GLGeometry Geometry { get; init; }
Matrix4x4[] instanceTransforms;

public GeometryRenderCommand(IGeometry geometry, GeometryEffect effect, CanvasState state) : base(effect, state)
public GeometryRenderCommand(GLGeometry geometry, GeometryEffect effect, CanvasState state) : base(effect, state)
{
Geometry = geometry;
}

public override void Submit()
{
throw new NotImplementedException();
Geometry.Draw(in this.State);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Submit()

for (int i = 0; i < draws.Count; i++)
{
glDrawArrays(draws[i].triangles ? GL_TRIANGLES : GL_LINES, draws[i].offset, draws[i].count);
glDrawArrays(draws[i].triangles ? GL_TRIANGLES : GL_LINES, draws[i].vertexOffset, draws[i].count);
}
}

Expand All @@ -32,7 +32,7 @@ public void AddCommand(bool triangles, int offset, int count)
if (draws.Count > 0)
{
DrawInfo lastDraw = draws[^1];
if (lastDraw.offset + lastDraw.count == offset && lastDraw.triangles == triangles)
if (lastDraw.vertexOffset + lastDraw.count == offset && lastDraw.triangles == triangles)
{
lastDraw.count += count;
draws[^1] = lastDraw;
Expand All @@ -43,15 +43,15 @@ public void AddCommand(bool triangles, int offset, int count)
draws.Add(new()
{
triangles = triangles,
offset = offset,
vertexOffset = offset,
count = count
});
}

private struct DrawInfo
{
public bool triangles;
public int offset;
public int vertexOffset;
public int count;
}
}
Loading

0 comments on commit 4212ee7

Please sign in to comment.