public static Vbo AcquireVbo(this IShape shape, VboType vboType) { var vbo = Vbos.FirstOrDefault(p => p.Matches(shape, vboType)); if (vbo == null) { Vbos.Add(vbo = new Vbo(shape, vboType)); } vbo.AddRef(); return(vbo); }
public Vbo(IShape shape, VboType vboType) { if (shape == null) { return; } _pattern = shape.Pattern; _stripeCount = shape.StripeCount; _vboType = vboType; GL.GenBuffers(1, out int buffer); BufferID = buffer; GL.BindBuffer(BufferTarget, BufferID); switch (_vboType) { case VboType.Vertex: BufferData(shape.GetCoordsCount() * sizeof(float), shape.GetCoords()); break; case VboType.Index: ElementsCount = shape.GetIndicesCount(); BufferData(ElementsCount * sizeof(int), shape.GetIndices()); break; } }
public bool Matches(IShape shape, VboType vboType) => shape != null && _vboType == vboType && _stripeCount.EquiAxial(shape.StripeCount) && (_vboType != VboType.Index || _pattern == shape.Pattern);