///<summary> A set of rectangle indexes of reccount rectangles, with a restart after each rectangle, in short indexes </summary> public void CreateRectangleElementIndexUShort(GLBuffer elementbuf, int reccount, uint restartindex = 0xffff) { ElementBuffer = elementbuf; ElementBuffer.FillRectangularIndicesShort(reccount, restartindex); ElementIndexSize = DrawElementsType.UnsignedShort; DrawCount = ElementBuffer.Length - 1; }
// a buffer returned /// <summary> Make a new entry of this type with an optional name </summary> public GLBuffer NewBuffer(bool std430 = true, string name = null) { GLBuffer b = new GLBuffer(std430); items[EnsureName(name)] = b; return(b); }
/// <summary> Make a new entry of this type with an optional name </summary> public GLBuffer NewBuffer(int size, bool std430 = false, BufferUsageHint hint = BufferUsageHint.StaticDraw, string name = null) { GLBuffer b = new GLBuffer(size, std430, hint); items[EnsureName(name)] = b; return(b); }
///<summary> A set of rectangle indexes of reccount rectangles, with a restart after each rectangle, in Byte indexes </summary> public void CreateRectangleElementIndexByte(GLBuffer elementbuf, int reccount, uint restartindex = 0xff) { ElementBuffer = elementbuf; ElementBuffer.FillRectangularIndicesBytes(reccount, restartindex); ElementIndexSize = DrawElementsType.UnsignedByte; DrawCount = ElementBuffer.Length - 1; // -1 because we do not need the last restart index to be processed //byte[] b = elementbuf.ReadBuffer(0, elementbuf.BufferSize); // test read back }
///<summary> Given a elementbuffer, fill with indexes from an array. Set ElementBuffer, ElementIndexSize, BaseIndexOffset, DrawCount </summary> public void CreateElementIndexUShort(GLBuffer elementbuf, ushort[] indexes, int base_index = 0) { ElementBuffer = elementbuf; ElementBuffer.AllocateFill(indexes); ElementIndexSize = DrawElementsType.UnsignedShort; BaseIndexOffset = base_index; DrawCount = indexes.Length; }
/// <summary> /// Copy to another buffer. Other buffer must be Allocated to the size otherpos+length /// </summary> /// <param name="other">Other buffer</param> /// <param name="startpos">Start posiiton in buffer</param> /// <param name="otherpos">Position to store it in other buffer</param> /// <param name="length">Copy length</param> /// <param name="hint"></param> public void CopyTo(GLBuffer other, int startpos, int otherpos, int length, BufferUsageHint hint = BufferUsageHint.StaticDraw) // newlength can be zero, meaning discard and go back to start { System.Diagnostics.Debug.Assert(context == GLStatics.GetContext(), "Context incorrect"); // safety int ourend = startpos + length; int otherend = otherpos + length; System.Diagnostics.Debug.Assert(Length >= ourend && other.Length >= otherend); GL.CopyNamedBufferSubData(Id, other.Id, (IntPtr)startpos, (IntPtr)otherpos, length); }
///<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, Vector2 and Matrix4 in buffers. First is model, second is coords, third is instance matrix translation /// All are supplied by buffer references /// Attributes in 0,1,4-7 set up.</summary> public static GLRenderableItem CreateVector4Vector2Matrix4(GLItemsList items, PrimitiveType prim, GLRenderState pt, GLBuffer vbuf1, GLBuffer vbuf2, GLBuffer vbuf3, int vertexcount, IGLRenderItemData id = null, int ic = 1, int matrixdivisor = 1, int buf1pos = 0, int buf2pos = 0, int buf3pos = 0) { var va = items.NewArray(); vbuf1.Bind(va, 0, buf1pos, 16); va.Attribute(0, 0, 4, VertexAttribType.Float); // bp 0 at 0 vbuf2.Bind(va, 1, buf2pos, 8); va.Attribute(1, 1, 2, VertexAttribType.Float); // bp 1 at 1 va.MatrixAttribute(2, 4); // bp 2 at 4-7 vbuf3.Bind(va, 2, buf3pos, 64, matrixdivisor); // use a binding return(new GLRenderableItem(prim, pt, vertexcount, va, id, ic)); }
///<summary> Given a elementbuffer, fill with indexes from an array. Drawtype sets the element index size. Set ElementBuffer, ElementIndexSize, BaseIndexOffset, DrawCount </summary> public void CreateElementIndex(GLBuffer elementbuf, uint[] eids, DrawElementsType drawtype, int base_index = 0) { ElementBuffer = elementbuf; if (drawtype == DrawElementsType.UnsignedByte) { ElementBuffer.AllocateFill(eids.Select(x => (byte)x).ToArray()); } else if (drawtype == DrawElementsType.UnsignedShort) { ElementBuffer.AllocateFill(eids.Select(x => (ushort)x).ToArray()); ElementIndexSize = DrawElementsType.UnsignedShort; } else { ElementBuffer.AllocateFill(eids.ToArray()); ElementIndexSize = DrawElementsType.UnsignedInt; } ElementIndexSize = drawtype; BaseIndexOffset = base_index; DrawCount = eids.Length; }
/// <summary> Add this type with an optional name </summary> public GLBuffer Add(GLBuffer disp, string name = null) { System.Diagnostics.Debug.Assert(!items.ContainsValue(disp)); items.Add(EnsureName(name), disp); return(disp); }
/// <summary> Use a buffer for Vector4 elements in attribute 0</summary> public static GLRenderableItem CreateVector4(GLItemsList items, PrimitiveType prim, GLRenderState pt, GLBuffer vb, int drawcount, int pos = 0, IGLRenderItemData id = null, int ic = 1) { var va = items.NewArray(); vb.Bind(va, 0, pos, 16); va.Attribute(0, 0, 4, VertexAttribType.Float); return(new GLRenderableItem(prim, pt, drawcount, va, id, ic)); }
///<summary> Given a elementbuffer, fill with indexes from an array. Set ElementBuffer, ElementIndexSize, BaseIndexOffset, DrawCount </summary> public void CreateElementIndex(GLBuffer elementbuf, uint[] eids, int base_index = 0) { CreateElementIndex(elementbuf, eids, GL4Statics.DrawElementsTypeFromMaxEID(eids.Max()), base_index); }
/// <summary> Two Vector4s, second in a given buffer. Second vector can be instance divided. In attributes 0,1</summary> public static GLRenderableItem CreateVector4Vector4(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, GLBuffer buf2, int bufoff = 0, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0) { var vb = items.NewBuffer(); vb.AllocateBytes(GLBuffer.Vec4size * vectors.Length); vb.Fill(vectors); var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], 16); va.Attribute(0, 0, 4, VertexAttribType.Float); buf2.Bind(va, 1, bufoff, 16, seconddivisor); va.Attribute(1, 1, 4, VertexAttribType.Float); return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
/// <summary> Two Vector4s, and a Vector2. Second given in buffer. First/Second in one buffer. Second and Third vector can be instance divided. In attributes 0,1,2</summary> public static GLRenderableItem CreateVector4Vector4Vector2(GLItemsList items, PrimitiveType prim, GLRenderState pt, Vector4[] vectors, GLBuffer secondvector, int secondoffset, Vector2[] thirdvector, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0, int thirddivisor = 0) { var vb = items.NewBuffer(); vb.AllocateBytes(GLBuffer.Vec4size * vectors.Length + GLBuffer.Vec2size * thirdvector.Length); // vec2 aligned vec4 vb.Fill(vectors); vb.Fill(thirdvector); var va = items.NewArray(); vb.Bind(va, 0, vb.Positions[0], 16); va.Attribute(0, 0, 4, VertexAttribType.Float); secondvector.Bind(va, 1, secondoffset, 16, seconddivisor); va.Attribute(1, 1, 4, VertexAttribType.Float); vb.Bind(va, 2, vb.Positions[1], 8, thirddivisor); va.Attribute(2, 2, 2, VertexAttribType.Float); return(new GLRenderableItem(prim, pt, vectors.Length, va, id, ic)); }
///<summary> Matrix4 as a buffer reference. /// Attributes in 4-7 set up.</summary> public static GLRenderableItem CreateMatrix4(GLItemsList items, PrimitiveType prim, GLRenderState pt, GLBuffer vb, int bufoffset, int drawcount, IGLRenderItemData id = null, int ic = 1, int matrixdivisor = 1) { var va = items.NewArray(); vb.Bind(va, 2, bufoffset, 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. Both are buffer references. /// Attributes in 0,4-7 set up.</summary> public static GLRenderableItem CreateVector4Matrix4(GLItemsList items, PrimitiveType prim, GLRenderState pt, GLBuffer shape, GLBuffer matrix, int drawcount, IGLRenderItemData id = null, int ic = 1, int matrixdivisor = 1) { var va = items.NewArray(); shape.Bind(va, 0, shape.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, 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> Two Vector4s, both in buffers. Second vector can be instance divided. In attributes 0,1</summary> public static GLRenderableItem CreateVector4Vector4(GLItemsList items, PrimitiveType prim, GLRenderState pt, GLBuffer buf1, int buf1off, int drawcount, GLBuffer buf2, int buf2off = 0, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0) { var va = items.NewArray(); buf1.Bind(va, 0, buf1off, 16); // binding index 0 va.Attribute(0, 0, 4, VertexAttribType.Float); // attribute 0 buf2.Bind(va, 1, buf2off, 16, seconddivisor); // binding index 1 va.Attribute(1, 1, 4, VertexAttribType.Float); // attribute 1 return(new GLRenderableItem(prim, pt, drawcount, va, id, ic)); }
/// <summary> Vector4 and Vector2 in one buffer, with buffer given and positions given. Second vector can be instance divided. In attributes 0,1</summary> public static GLRenderableItem CreateVector4Vector2(GLItemsList items, PrimitiveType prim, GLRenderState pt, GLBuffer vb, int pos1, int pos2, int drawcount, IGLRenderItemData id = null, int ic = 1, int seconddivisor = 0) { 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, drawcount, va, id, ic)); }