Added GeometryBinding refcounting

This commit is contained in:
Simon Lübeß
2021-02-20 14:52:51 +01:00
parent 9ae376f572
commit 78af9e736e
2 changed files with 33 additions and 19 deletions
+15 -1
View File
@@ -3,7 +3,7 @@ using System.Collections;
namespace GlitchyEngine.Renderer
{
public class GeometryBinding
public class GeometryBinding : RefCounted
{
internal GraphicsContext _context ~ _?.ReleaseRef();
@@ -19,6 +19,16 @@ namespace GlitchyEngine.Renderer
_context = context..AddRef();
}
public ~this()
{
for(let binding in _vertexBuffers)
{
binding.Buffer?.ReleaseRef();
}
_indexBuffer?.ReleaseRef();
}
public VertexBufferBinding GetVertexBuffer(uint32 slot)
{
return _vertexBuffers[slot];
@@ -46,6 +56,7 @@ namespace GlitchyEngine.Renderer
public void SetVertexBufferSlot(VertexBufferBinding vertexBufferBinding, uint32 slot)
{
_vertexBuffers.Add(vertexBufferBinding);
vertexBufferBinding.Buffer.AddRef();
PlatformSetVertexBuffer(vertexBufferBinding, slot);
}
@@ -70,7 +81,10 @@ namespace GlitchyEngine.Renderer
public void SetIndexBuffer(IndexBuffer indexBuffer, uint32 byteOffset = 0, uint32 indexCount = (.)-1)
{
_indexBuffer?.ReleaseRef();
_indexBuffer = indexBuffer;
_indexBuffer.AddRef();
_indexByteOffset = byteOffset;
if(indexCount == (.)-1)
+18 -18
View File
@@ -53,13 +53,9 @@ namespace Sandbox
VertexLayout _vertexLayout ~ delete _;
GeometryBinding _geometryBinding ~ delete _;
VertexBuffer _vertexBuffer ~ _?.ReleaseRef();
IndexBuffer _indexBuffer ~ _?.ReleaseRef();
GeometryBinding _geometryBinding ~ _?.ReleaseRef();
GeometryBinding _quadGeometryBinding ~ delete _;
VertexBuffer _quadVertexBuffer ~ _?.ReleaseRef();
IndexBuffer _quadIndexBuffer ~ _?.ReleaseRef();
GeometryBinding _quadGeometryBinding ~ _?.ReleaseRef();
RasterizerState _rasterizerState ~ delete _;
@@ -109,9 +105,10 @@ namespace Sandbox
VertexColorTexture(CircleCoord(-pO3), Color(255, 0,255)),
);
_vertexBuffer = new VertexBuffer(_context, typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
_vertexBuffer.SetData(vertices);
_geometryBinding.SetVertexBufferSlot(_vertexBuffer, 0);
let vb = new VertexBuffer(_context, typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
vb.SetData(vertices);
_geometryBinding.SetVertexBufferSlot(vb, 0);
vb.ReleaseRef();
uint16[?] indices = .(
0, 1, 2,
@@ -121,9 +118,10 @@ namespace Sandbox
0, 5, 6,
0, 6, 1);
_indexBuffer = new IndexBuffer(_context, (.)indices.Count, .Immutable);
_indexBuffer.SetData(indices);
_geometryBinding.SetIndexBuffer(_indexBuffer);
let ib = new IndexBuffer(_context, (.)indices.Count, .Immutable);
ib.SetData(indices);
_geometryBinding.SetIndexBuffer(ib);
ib.ReleaseRef();
}
// Create Quad
@@ -139,17 +137,19 @@ namespace Sandbox
VertexColorTexture(Vector3(0.75f, 0.75f, 0), Color.White, .(1, 0)),
);
_quadVertexBuffer = new VertexBuffer(_context, typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
_quadVertexBuffer.SetData(vertices);
_quadGeometryBinding.SetVertexBufferSlot(_quadVertexBuffer, 0);
let qvb = new VertexBuffer(_context, typeof(VertexColorTexture), (.)vertices.Count, .Immutable);
qvb.SetData(vertices);
_quadGeometryBinding.SetVertexBufferSlot(qvb, 0);
qvb.ReleaseRef();
uint16[?] indices = .(
0, 1, 2,
2, 3, 0);
_quadIndexBuffer = new IndexBuffer(_context, (.)indices.Count, .Immutable);
_quadIndexBuffer.SetData(indices);
_quadGeometryBinding.SetIndexBuffer(_quadIndexBuffer);
let qib = new IndexBuffer(_context, (.)indices.Count, .Immutable);
qib.SetData(indices);
_quadGeometryBinding.SetIndexBuffer(qib);
qib.ReleaseRef();
}
// Create rasterizer state