public Dictionary <int, int> AddLines(List <GameLine> lines, LineVertex[] vertices) { Dictionary <int, int> ret = new Dictionary <int, int>(lines.Count); int startidx = _indices.Count; int startvert = _vertexcount; _indices.EnsureCapacity(vertices.Length); for (int ix = 0; ix < lines.Count; ix++) { var baseoffset = (ix * linesize); for (int i = 0; i < linesize; i++) { _indices.Add(startvert + baseoffset + i); } ret.Add(lines[ix].ID, startidx + baseoffset); } _vbo.Bind(); EnsureVBOSize(_vertexcount + vertices.Length); _vbo.SetData(vertices, 0, _vertexcount, vertices.Length); _vbo.Unbind(); _vertexcount += vertices.Length; _ibo.Bind(); EnsureIBOSize(_indices.Count + vertices.Length); _ibo.SetData(_indices.unsafe_array, startidx, startidx, vertices.Length); _ibo.Unbind(); return(ret); }
public void Initialize(List <RedLine> lines) { Clear(); if (lines.Count == 0) { return; } //max size for init var redshapes = new GenericVertex[lines.Count * ShapeSize * 3][]; ResourceSync initsync = new ResourceSync(); int vertcount = 0; System.Threading.Tasks.Parallel.For(0, lines.Count, (idx) => { var acc = GetAccelDecor(lines[idx]); redshapes[idx] = acc; System.Threading.Interlocked.Add(ref vertcount, acc.Length); }); GenericVertex[] verts = new GenericVertex[vertcount]; _indices.EnsureCapacity(vertcount); _indices.UnsafeSetCount(vertcount); int shapepos = 0; for (int idx = 0; idx < lines.Count; idx++) { var acc = redshapes[idx]; var entry = new accelentry() { start = shapepos, shapes = acc.Length / ShapeSize }; for (int i = 0; i < acc.Length; i++) { verts[shapepos] = acc[i]; _indices.unsafe_array[shapepos] = shapepos; shapepos++; } _lookup.Add(lines[idx].ID, entry); } _vertcount = verts.Length; _accelbuffer.Bind(); EnsureVBOSize(verts.Length, false); _accelbuffer.SetData(verts, 0, 0, verts.Length); _accelbuffer.Unbind(); _accelibo.Bind(); EnsureIBOSize(_indices.Count, false); _accelibo.SetData(_indices.unsafe_array, 0, 0, _indices.Count); _accelibo.Unbind(); }
public void Draw(DrawOptions draw) { using (new GLEnableCap(EnableCap.Blend)) { _vbo.Bind(); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.VertexPointer(2, VertexPointerType.Float, GenericVertex.Size, 0); GL.ColorPointer(4, ColorPointerType.UnsignedByte, GenericVertex.Size, 8); GL.DrawArrays(PrimitiveType.Triangles, 0, _vertexcounter); GL.DisableClientState(ArrayCap.ColorArray); GL.DisableClientState(ArrayCap.VertexArray); _vbo.Unbind(); } }
public WellRenderer() { _vbo = new GLBuffer <GenericVertex>(BufferTarget.ArrayBuffer); _vbo.Bind(); _vbo.SetSize( LineRenderer.StartingLineCount * wellsize, BufferUsageHint.DynamicDraw); _vbo.Unbind(); }
public LineAccelRenderer() { _accelbuffer = new GLBuffer <GenericVertex>(BufferTarget.ArrayBuffer); _accelbuffer.Bind(); _accelbuffer.SetSize((LineRenderer.StartingLineCount / 2) * 3, BufferUsageHint.DynamicDraw, false); _accelbuffer.Unbind(); _accelibo = new GLBuffer <int>(BufferTarget.ElementArrayBuffer); _accelibo.Bind(); _accelibo.SetSize((LineRenderer.StartingLineCount / 2) * 3, BufferUsageHint.DynamicDraw, false); _accelibo.Unbind(); }
public LineRenderer(Shader sh) { if (sh == null) { throw new ArgumentNullException("shader"); } _shader = sh; _vbo = new GLBuffer <LineVertex>(BufferTarget.ArrayBuffer); _ibo = new GLBuffer <int>(BufferTarget.ElementArrayBuffer); _vbo.Bind(); _vbo.SetSize(StartingLineCount * linesize, BufferUsageHint.DynamicDraw); _vbo.Unbind(); _ibo.Bind(); _ibo.SetSize(StartingLineCount * linesize, BufferUsageHint.DynamicDraw); _ibo.Unbind(); }