public void Initialize(AutoArray <GameLine> lines) { Clear(); ResourceSync initsync = new ResourceSync(); GenericVertex[] vertices = new GenericVertex[lines.Count * wellsize]; System.Threading.Tasks.Parallel.For(0, lines.Count, (idx) => { var line = (StandardLine)lines[idx]; var well = GetWell(line); for (int i = 0; i < wellsize; i++) { vertices[idx * wellsize + i] = well[i]; } try { initsync.UnsafeEnterWrite(); _lines.Add(line.ID, idx * wellsize); } finally { initsync.UnsafeExitWrite(); } }); _vertexcounter = vertices.Length; _vbo.Bind(); EnsureVBOSize(vertices.Length, false); _vbo.SetData(vertices, 0, 0, vertices.Length); _vbo.Unbind(); }
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(); }
private void DrawVertices(GLGeometry type) { ShaderInfo.hasReversedNormal.NoWarning().Set(VertexType.ReversedNormal); _shader.Draw(type, _indicesList.Buffer, _indicesList.Length, () => { if (VertexType.HasPosition) { _verticesPositionBuffer.SetData(_verticesPosition.Buffer, 0, _verticesPosition.Length); ShaderInfo.vertexPosition.SetData <float>(_verticesPositionBuffer, 3, 0, sizeof(VertexInfoVector3F), false); } if (VertexType.HasTexture) { _verticesTexcoordsBuffer.SetData(_verticesTexcoords.Buffer, 0, _verticesTexcoords.Length); ShaderInfo.vertexTexCoords.SetData <float>(_verticesTexcoordsBuffer, 3, 0, sizeof(VertexInfoVector3F), false); } if (VertexType.HasColor) { _verticesColorsBuffer.SetData(_verticesColors.Buffer, 0, _verticesColors.Length); ShaderInfo.vertexColor.SetData <float>(_verticesColorsBuffer, 4, 0, sizeof(VertexInfoColor), false); } if (VertexType.HasNormal) { _verticesNormalBuffer.SetData(_verticesNormal.Buffer, 0, _verticesNormal.Length); ShaderInfo.vertexNormal.NoWarning() .SetData <float>(_verticesNormalBuffer, 4, 0, sizeof(VertexInfoVector3F), false); } if (VertexType.HasWeight) { _verticesWeightsBuffer.SetData(_verticesWeights.Buffer, 0, _verticesWeights.Length); var vertexWeights = new[] { ShaderInfo.vertexWeight0, ShaderInfo.vertexWeight1, ShaderInfo.vertexWeight2, ShaderInfo.vertexWeight3, ShaderInfo.vertexWeight4, ShaderInfo.vertexWeight5, ShaderInfo.vertexWeight6, ShaderInfo.vertexWeight7 }; for (var n = 0; n < VertexType.RealSkinningWeightCount; n++) { vertexWeights[n].SetData <float>(_verticesWeightsBuffer, 1, n * sizeof(float), sizeof(VertexInfoWeights), false); } } }); }
public Program() : base(1280, 720, "OpenGL Framework test") { VSync = VSyncMode.Off; Console.Title = $"{GL.GetString(StringName.Vendor)} OpenGL {GL.GetString(StringName.Version)} GLSL {GL.GetString(StringName.ShadingLanguageVersion)}"; vb = new GLBuffer <Vertex>(); vb.SetData(VertexFactory.GetQuad()); batch = new BatchRenderer2D(); tex = new Texture2D("./lmao.png"); shader = new Shader("./vert.glsl", "./frag.glsl"); shader.AddUniform("projectionMatrix"); shader.AddUniform("inputColor"); shader.AddUniform("tex"); GL.ActiveTexture(TextureUnit.Texture0); }