Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions data/map01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 13 additions & 18 deletions src/Box2D.NET.Samples/Draw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class Draw
private GLBackground m_background;
private GLPoints m_points;
private GLLines m_lines;
private GLTriangles m_triangles;
private GLCircles m_circles;
private GLSolidCircles m_solidCircles;
private GLSolidCapsules m_solidCapsules;
Expand All @@ -41,7 +40,6 @@ public Draw()
m_background = new GLBackground();
m_points = new GLPoints();
m_lines = new GLLines();
m_triangles = new GLTriangles();
m_circles = new GLCircles();
m_solidCircles = new GLSolidCircles();
m_solidCapsules = new GLSolidCapsules();
Expand All @@ -51,28 +49,30 @@ public Draw()
B2AABB bounds = new B2AABB(new B2Vec2(-float.MaxValue, -float.MaxValue), new B2Vec2(float.MaxValue, float.MaxValue));

m_debugDraw = new B2DebugDraw();
m_debugDraw.DrawPolygon = DrawPolygonFcn;
m_debugDraw.DrawSolidPolygon = DrawSolidPolygonFcn;
m_debugDraw.DrawCircle = DrawCircleFcn;
m_debugDraw.DrawSolidCircle = DrawSolidCircleFcn;
m_debugDraw.DrawSolidCapsule = DrawSolidCapsuleFcn;
m_debugDraw.DrawSegment = DrawSegmentFcn;
m_debugDraw.DrawTransform = DrawTransformFcn;
m_debugDraw.DrawPoint = DrawPointFcn;
m_debugDraw.DrawString = DrawStringFcn;
m_debugDraw.DrawPolygonFcn = DrawPolygonFcn;
m_debugDraw.DrawSolidPolygonFcn = DrawSolidPolygonFcn;
m_debugDraw.DrawCircleFcn = DrawCircleFcn;
m_debugDraw.DrawSolidCircleFcn = DrawSolidCircleFcn;
m_debugDraw.DrawSolidCapsuleFcn = DrawSolidCapsuleFcn;
m_debugDraw.DrawSegmentFcn = DrawSegmentFcn;
m_debugDraw.DrawTransformFcn = DrawTransformFcn;
m_debugDraw.DrawPointFcn = DrawPointFcn;
m_debugDraw.DrawStringFcn = DrawStringFcn;
m_debugDraw.drawingBounds = bounds;

m_debugDraw.useDrawingBounds = false;
m_debugDraw.drawShapes = true;
m_debugDraw.drawJoints = true;
m_debugDraw.drawJointExtras = false;
m_debugDraw.drawAABBs = false;
m_debugDraw.drawBounds = false;
m_debugDraw.drawMass = false;
m_debugDraw.drawContacts = false;
m_debugDraw.drawGraphColors = false;
m_debugDraw.drawContactNormals = false;
m_debugDraw.drawContactImpulses = false;
m_debugDraw.drawContactFeatures = false;
m_debugDraw.drawFrictionImpulses = false;
m_debugDraw.drawIslands = false;

m_debugDraw.context = this;

Expand All @@ -91,7 +91,6 @@ public void Create(SampleAppContext context)
m_background.Create(context);
m_points.Create(context);
m_lines.Create(context);
m_triangles.Create(context);
m_circles.Create(context);
m_solidCircles.Create(context);
m_solidCapsules.Create(context);
Expand All @@ -109,9 +108,6 @@ public void Destroy()
m_lines.Destroy();
m_lines = null;

m_triangles.Destroy();
m_triangles = null;

m_circles.Destroy();
m_circles = null;

Expand Down Expand Up @@ -228,11 +224,10 @@ public void Flush()
m_solidCircles.Flush();
m_solidCapsules.Flush();
m_solidPolygons.Flush();
m_triangles.Flush();
m_circles.Flush();
m_lines.Flush();
m_points.Flush();
_gl.CheckErrorGL();
_gl.CheckOpenGL();
}

public void DrawBackground()
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Graphics/GLBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Create(SampleAppContext context)
_gl.BufferData<B2Vec2>(GLEnum.ArrayBuffer, vertices, GLEnum.StaticDraw);
_gl.VertexAttribPointer(vertexAttribute, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/Box2D.NET.Samples/Graphics/GLCircles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void Create(SampleAppContext context)
_gl.VertexAttribDivisor(radiusInstance, 1);
_gl.VertexAttribDivisor(colorInstance, 1);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down Expand Up @@ -141,7 +141,7 @@ public void Flush()
_gl.BufferSubData<CircleData>(GLEnum.ArrayBuffer, 0, circles.Slice(@base, batchCount));
_gl.DrawArraysInstanced(GLEnum.Triangles, 0, 6, (uint)batchCount);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

count -= e_batchSize;
@base += e_batchSize;
Expand Down
11 changes: 9 additions & 2 deletions src/Box2D.NET.Samples/Graphics/GLLines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void Create(SampleAppContext context)
// save bandwidth by expanding color to floats in the shader
_gl.VertexAttribPointer(colorAttribute, 4, VertexAttribPointerType.UnsignedByte, true, SizeOf<VertexData>.Size, IntPtr.Zero + 8);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down Expand Up @@ -115,6 +115,11 @@ public void Flush()

Debug.Assert(count % 2 == 0);

_gl.Enable(GLEnum.LineSmooth);
_gl.Enable(GLEnum.Blend);
_gl.BlendFunc(GLEnum.SrcAlpha, GLEnum.OneMinusSrcAlpha);
_gl.LineWidth(1.0f);

_gl.UseProgram(m_programId);

B2FixedArray16<float> array16 = new B2FixedArray16<float>();
Expand All @@ -137,7 +142,7 @@ public void Flush()

_gl.DrawArrays(GLEnum.Lines, 0, (uint)batchCount);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

count -= e_batchSize;
@base += e_batchSize;
Expand All @@ -147,6 +152,8 @@ public void Flush()
_gl.BindVertexArray(0);
_gl.UseProgram(0);

_gl.Disable(GLEnum.Blend);

m_points.Clear();
}
}
4 changes: 2 additions & 2 deletions src/Box2D.NET.Samples/Graphics/GLPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Create(SampleAppContext context)
// save bandwidth by expanding color to floats in the shader
_gl.VertexAttribPointer(colorAttribute, 4, VertexAttribPointerType.UnsignedByte, true, SizeOf<PointData>.Size, IntPtr.Zero + 12);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down Expand Up @@ -137,7 +137,7 @@ public void Flush()
_gl.BufferSubData<PointData>(GLEnum.ArrayBuffer, 0, points.Slice(@base, batchCount));
_gl.DrawArrays(GLEnum.Points, 0, (uint)batchCount);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

count -= e_batchSize;
@base += e_batchSize;
Expand Down
4 changes: 2 additions & 2 deletions src/Box2D.NET.Samples/Graphics/GLSolidCapsules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void Create(SampleAppContext context)
_gl.VertexAttribDivisor(lengthInstance, 1);
_gl.VertexAttribDivisor(colorInstance, 1);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down Expand Up @@ -165,7 +165,7 @@ public void Flush()
_gl.BufferSubData<CapsuleData>(GLEnum.ArrayBuffer, 0, capsules.Slice(@base, batchCount));
_gl.DrawArraysInstanced(GLEnum.Triangles, 0, 6, (uint)batchCount);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

count -= e_batchSize;
@base += e_batchSize;
Expand Down
4 changes: 2 additions & 2 deletions src/Box2D.NET.Samples/Graphics/GLSolidCircles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Create(SampleAppContext context)
_gl.VertexAttribDivisor(radiusInstance, 1);
_gl.VertexAttribDivisor(colorInstance, 1);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down Expand Up @@ -146,7 +146,7 @@ public void Flush()
_gl.BufferSubData<SolidCircleData>(GLEnum.ArrayBuffer, 0, circles.Slice(@base, batchCount));
_gl.DrawArraysInstanced(GLEnum.Triangles, 0, 6, (uint)batchCount);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

count -= e_batchSize;
@base += e_batchSize;
Expand Down
6 changes: 3 additions & 3 deletions src/Box2D.NET.Samples/Graphics/GLSolidPolygons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void Create(SampleAppContext context)
_gl.VertexAttribDivisor(instanceRadius, 1);
_gl.VertexAttribDivisor(instanceColor, 1);

_gl.CheckErrorGL();
_gl.CheckOpenGL();

// Cleanup
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
Expand Down Expand Up @@ -149,7 +149,7 @@ public void Flush()
}

_gl.UseProgram(m_programId);
_gl.CheckErrorGL();
_gl.CheckOpenGL();

B2FixedArray16<float> array16 = new B2FixedArray16<float>();
Span<float> proj = array16.AsSpan();
Expand All @@ -173,7 +173,7 @@ public void Flush()

_gl.BufferSubData<PolygonData>(GLEnum.ArrayBuffer, 0, polygons.Slice(@base, batchCount));
_gl.DrawArraysInstanced(GLEnum.Triangles, 0, 6, (uint)batchCount);
_gl.CheckErrorGL();
_gl.CheckOpenGL();

count -= e_batchSize;
@base += e_batchSize;
Expand Down
Loading
Loading