VertexBuffer, VertexLayout and GeometryBinding improvements

- VertexBuffer: Added constructor that takes stride instead of type
- VertexLayout: Added Refcounting to VertexLayout and ownership parameters for VertexElements
- Fixed: GeometryBinding using stride and offset from buffer instead of buffer binding
This commit is contained in:
Simon Lübeß
2021-08-05 18:32:21 +02:00
parent e04d058381
commit 5c0ee3bae0
7 changed files with 65 additions and 32 deletions
+25 -4
View File
@@ -24,6 +24,10 @@ namespace GlitchyEngine.Renderer
* The semantic associated with this element in a shader input-signature.
*/
public String SemanticName;
/**
* If set to True, the VertexLayout will delete SemanticName once it's reference count is 0.
*/
public bool OwnsName;
/**
* The semantic index for the element.
* A semantic index modifies a semantic, with an integer index number.
@@ -56,10 +60,11 @@ namespace GlitchyEngine.Renderer
public this() => this = default;
public this(Format format, String semanticName, uint32 semanticIndex = 0, uint32 inputSlot = 0, uint32 offset = (.)-1, InputClassification slotClass = .PerVertexData, uint32 instanceStepRate = 0)
public this(Format format, String semanticName, bool ownsName = false, uint32 semanticIndex = 0, uint32 inputSlot = 0, uint32 offset = (.)-1, InputClassification slotClass = .PerVertexData, uint32 instanceStepRate = 0)
{
Format = format;
SemanticName = semanticName;
OwnsName = ownsName;
SemanticIndex = semanticIndex;
InputSlot = inputSlot;
AlignedByteOffset = offset;
@@ -73,24 +78,40 @@ namespace GlitchyEngine.Renderer
public static readonly uint32 AppendAligned = 0xffffffff;
}
public class VertexLayout
public class VertexLayout : RefCounted
{
private GraphicsContext _context ~ _?.ReleaseRef();
private VertexElement[] _elements;
private bool _ownsElements;
public GraphicsContext Context => _context;
public VertexElement[] Elements => _elements;
public this(GraphicsContext context, VertexElement[] elements, VertexShader vertexShader)
public this(GraphicsContext context, VertexElement[] elements, bool ownsElements, VertexShader vertexShader)
{
_context = context..AddRef();
_elements = elements;
_ownsElements = ownsElements;
CreateNativeLayout();
}
public ~this()
{
if(_ownsElements)
{
for(var element in _elements)
{
if(element.OwnsName)
delete element.SemanticName;
}
delete _elements;
}
}
protected extern void CreateNativeLayout();
}