///<summary> Vector4, Vector2 and Matrix4 in buffers. First is model, second is coords, third is instance matrix translation /// if separbuffer = true and instancematrix is null, it makes a buffer for you to fill up externally. /// if separbuffer = true it makes as separate buffer for instancematrix /// if separbuffer = true and instancematrix is null, you fill up the separbuffer yourself outside of this (maybe auto generated). /// You can get this buffer using items.LastBuffer() /// Attributes in 0,1,4-7 set up.</summary> public static GLRenderableItem CreateVector4Vector2Matrix4(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, Vector2[] coords, Matrix4[] instancematrix, IGLRenderItemData id = null, int ic = 1, bool separbuf = false, int matrixdivisor = 1) { var va = items.NewArray(); GLBuffer vbuf1 = items.NewBuffer(); GLBuffer vbuf2 = vbuf1; int posi = 2; if (separbuf) { vbuf1.AllocateBytes(GLBuffer.Vec4size * vectors.Length + GLBuffer.Vec2size * coords.Length); vbuf2 = items.NewBuffer(); if (instancematrix != null) { vbuf2.AllocateBytes(GLBuffer.Mat4size * instancematrix.Length); } posi = 0; } else { vbuf1.AllocateBytes(GLBuffer.Vec4size * vectors.Length + GLBuffer.Vec2size * coords.Length + GLBuffer.Vec4size + GLBuffer.Mat4size * instancematrix.Length); // due to alignment, add on a little } vbuf1.Fill(vectors); vbuf1.Fill(coords); if (instancematrix != null) { vbuf2.Fill(instancematrix); } vbuf1.Bind(va, 0, vbuf1.Positions[0], 16); va.Attribute(0, 0, 4, VertexAttribType.Float); // bp 0 at 0 vbuf1.Bind(va, 1, vbuf1.Positions[1], 8); va.Attribute(1, 1, 2, VertexAttribType.Float); // bp 1 at 1 va.MatrixAttribute(2, 4); // bp 2 at 4-7 vbuf2.Bind(va, 2, instancematrix != null ? vbuf2.Positions[posi]: 0, 64, matrixdivisor); // use a binding return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
/// <summary> Vector4 and Vector2 and index array in a tuple. Element index is created. In attributes 0,1. No primitive restart</summary> public static GLRenderableItem CreateVector4Vector2Indexed(GLItemsList items, PrimitiveType prim, GLRenderState pt, Tuple <Vector4[], Vector2[], uint[]> vectors, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0) { var dt = GL4Statics.DrawElementsTypeFromMaxEID((uint)vectors.Item1.Length - 1); var ri = CreateVector4Vector2(items, prim, pt, vectors.Item1, vectors.Item2, id, ic, seconddivisor); ri.CreateElementIndex(items.NewBuffer(), vectors.Item3, dt); return(ri); }
/// <summary> Two Vector4s, in separate buffers. Second vector can be instance divided. In attributes 0,1</summary> public static GLRenderableItem CreateVector4Vector4Buf2(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, Vector4[] secondvector, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0) { var v1 = items.NewBuffer(); v1.AllocateBytes(GLBuffer.Vec4size * vectors.Length); v1.Fill(vectors); var v2 = items.NewBuffer(); v2.AllocateBytes(GLBuffer.Vec4size * secondvector.Length); v2.Fill(secondvector); var va = items.NewArray(); v1.Bind(va, 0, v1.Positions[0], 16); va.Attribute(0, 0, 4, VertexAttribType.Float); v2.Bind(va, 1, v2.Positions[0], 16, seconddivisor); va.Attribute(1, 1, 4, VertexAttribType.Float); return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
/// <summary>Vector4, in attribute 0</summary> public static GLRenderableItem CreateVector4(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, IGLRenderItemData id = null, int ic = 1) { var vb = items.NewBuffer(); vb.AllocateFill(vectors); var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], 16); // bind buffer to binding point 0 va.Attribute(0, 0, 4, VertexAttribType.Float); // bind binding point 0 to attribute point 0 with 4 float components return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
///<summary> Floats packed into buffer with configurable component number (1,2,4) /// Attributes in 0.</summary> public static GLRenderableItem CreateFloats(GLItemsList items, PrimitiveType prim, GLRenderState pt, float[] floats, int components, IGLRenderItemData id = null, int ic = 1) { var vb = items.NewBuffer(); vb.AllocateFill(floats); //float[] ouwt = vb.ReadFloats(0, floats.Length); // test read back var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], sizeof(float) * components); va.Attribute(0, 0, components, VertexAttribType.Float); return(new GLRenderableItem(prim, pt, floats.Length / components, va, id, ic)); }
///<summary> Vector3 packed using GLBuffer.FillPacked2vec. Offsets and mult specify range /// Attributes in 0.</summary> public static GLRenderableItem CreateVector3Packed2(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector3[] vectors, Vector3 offsets, float mult, IGLRenderItemData id = null, int ic = 1) { var vb = items.NewBuffer(); vb.AllocateBytes(sizeof(uint) * 2 * vectors.Length); vb.FillPacked2vec(vectors, offsets, mult); var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], 8); va.AttributeI(0, 0, 2, VertexAttribType.UnsignedInt); return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
///<summary> Matrix4. /// Attributes in 4-7 set up.</summary> public static GLRenderableItem CreateMatrix4(GLItemsList items, PrimitiveType prim, GLRenderState pt, Matrix4[] matrix, int drawcount, IGLRenderItemData id = null, int ic = 1, int matrixdivisor = 1) { var vb = items.NewBuffer(); vb.AllocateBytes(GLBuffer.Mat4size * matrix.Length); vb.Fill(matrix); var va = items.NewArray(); vb.Bind(va, 2, vb.Positions[0], 64, matrixdivisor); // use a binding va.MatrixAttribute(2, 4); // bp 2 at attribs 4-7 return(new GLRenderableItem(prim, pt, drawcount, va, id, ic)); }
///<summary> Vector4 and Matrix4. Matrix4 is a buffer reference. /// Attributes in 0,4-7 set up.</summary> public static GLRenderableItem CreateVector4Matrix4(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, GLBuffer matrix, IGLRenderItemData id = null, int ic = 1, int matrixdivisor = 1) { var vb = items.NewBuffer(); vb.AllocateFill(vectors); // push in model vectors var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], 16); va.Attribute(0, 0, 4, VertexAttribType.Float); // bp 0 at attrib 0 matrix.Bind(va, 2, matrix.Positions[0], 64, matrixdivisor); // use a binding va.MatrixAttribute(2, 4); // bp 2 at attribs 4-7 return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
/// <summary> Vector4 and Vector2. Second vector can be instance divided. In attributes 0,1</summary> public static GLRenderableItem CreateVector4Vector2(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, Vector2[] coords, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0) { var vb = items.NewBuffer(); vb.AllocateBytes(GLBuffer.Vec4size * vectors.Length + GLBuffer.Vec2size * coords.Length); vb.Fill(vectors); vb.Fill(coords); var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], 16); va.Attribute(0, 0, 4, VertexAttribType.Float); vb.Bind(va, 1, vb.Positions[1], 8, seconddivisor); va.Attribute(1, 1, 2, VertexAttribType.Float); return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
/// <summary>Vector4, Color4, optional instance data and count /// in attribute 0 and 1 setup vector4 and vector4 colours</summary> public static GLRenderableItem CreateVector4Color4(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, Color4[] colours, IGLRenderItemData id = null, int ic = 1) { var vb = items.NewBuffer(); // they all follow this pattern, grab a buffer (unless supplied) vb.AllocateBytes(GLBuffer.Vec4size * vectors.Length * 2); // allocate vb.Fill(vectors); // fill vb.Fill(colours, vectors.Length); var va = items.NewArray(); // vertex array vb.Bind(va, 0, vb.Positions[0], 16); // buffer bind to vertex array at bindingpoint 0, bufferpos, stride va.Attribute(0, 0, 4, VertexAttribType.Float); // bind bindingpoint 0 to attribute index 0 (in shader), 4 components, float vb.Bind(va, 1, vb.Positions[1], 16); // buffer bind to vertex array at bindingpoint 1, bufferpos, stride va.Attribute(1, 1, 4, VertexAttribType.Float); // bind bindingpoint 1 to attribute index 1 (in shader), 4 components, float return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); // create new RI }