public static GpuVertexBuffer CreateVertexBuffer(int vertexCount, SharpBgfx.VertexLayout vertexDeclaration, GpuBufferFlags flags) { if (vertexCount == 0) { Log.Fatal("GpuBufferManager: CreateVertexBuffer: vertexCount == 0."); } return(new GpuVertexBuffer(null, vertexCount, vertexDeclaration, flags)); }
public static SharpBgfx.VertexLayout CreateVertexDeclaration(this VertexElement[] elements, int forSource) { GetInfo(elements, out var vertexSize, out var holes); //!!!! if (holes) { Log.Fatal("VertexElement: CreateVertexDeclaration: holes. impl."); } //!!!! if (forSource != 0) { Log.Fatal("VertexElement: CreateVertexDeclaration: forSource != 0. impl."); } //if( element.Source == forSource ) //{ //} var result = new SharpBgfx.VertexLayout(); result.Begin(); var sorted = (VertexElement[])elements.Clone(); CollectionUtility.SelectionSort(sorted, delegate(VertexElement element1, VertexElement element2) { if (element1.Offset < element2.Offset) { return(-1); } if (element1.Offset > element2.Offset) { return(1); } return(0); }); foreach (var element in sorted) { element.GetBfgx(out var attribute, out var count, out var type, out var asInt); result.Add(attribute, count, type, false, asInt); } result.End(); if (vertexSize != result.Stride) { Log.Fatal("VertexElement: CreateVertexDeclaration: vertexSize != result.Stride."); } return(result); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //public static GpuBuffer[] GetBuffers() //{ // lock( buffers ) // return buffers.ToArray(); //} public static GpuVertexBuffer CreateVertexBuffer(byte[] vertices, SharpBgfx.VertexLayout vertexDeclaration, GpuBufferFlags flags = 0) { if (vertices.Length == 0) { Log.Fatal("GpuBufferManager: CreateVertexBuffer: vertices.Length == 0."); } if (flags.HasFlag(GpuBufferFlags.ComputeWrite)) { Log.Fatal("GpuBufferManager: CreateVertexBuffer: ComputeWrite buffer can't write data from CPU."); } var vertexCount = vertices.Length / vertexDeclaration.Stride; return(new GpuVertexBuffer(vertices, vertexCount, vertexDeclaration, flags)); }
// internal unsafe GpuVertexBuffer(byte[] vertices, int vertexCount, SharpBgfx.VertexLayout vertexDeclaration, GpuBufferFlags flags) { lock (GpuBufferManager.vertexBuffers) GpuBufferManager.vertexBuffers.Add(this); this.vertices = vertices; this.vertexDeclaration = vertexDeclaration; this.vertexCount = vertexCount; vertexCountActual = vertexCount; this.flags = flags; vertexSize = vertexDeclaration.Stride; if (Flags.HasFlag(GpuBufferFlags.Dynamic)) { if (this.vertices == null) { this.vertices = new byte[vertexCount * vertexSize]; } dynamic_needUpdateNative = true; } }