public void UploadInGl() { var vertices = new Vertex[] { new Vertex(new Vector3(0, 0 + Size.Y, 0f), new Vector3(0, 0, 1), new Vector2(_uvStart.X, _uvStart.Y)), new Vertex(new Vector3(0, 0, 0f), new Vector3(0, 0, 1), new Vector2(_uvStart.X, _uvEnd.Y)), new Vertex(new Vector3(0 + Size.X, 0 + Size.Y, 0f), new Vector3(0, 0, 1), new Vector2(_uvEnd.X, _uvStart.Y)), new Vertex(new Vector3(0 + Size.X, 0 + Size.Y, 0f), new Vector3(0, 0, 1), new Vector2(_uvEnd.X, _uvStart.Y)), new Vertex(new Vector3(0, 0, 0f), new Vector3(0, 0, 1), new Vector2(_uvStart.X, _uvEnd.Y)), new Vertex(new Vector3(0 + Size.X, 0, 0f), new Vector3(0, 0, 1), new Vector2(_uvEnd.X, _uvEnd.Y)), }; if (_vbo == null) { _vbo = new Vbo(); } _vbo.Bind(); _trianglesCount = vertices.Length; _vbo.SetData(vertices); _vbo.Unbind(); if (_vao == null) { _vao = new Vao <Vertex>(); } _vao.BindVbo(_vbo, Shader, new[] { new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, 0), new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes * 2), }); }
public void Dispose() { Loaded = false; ClearVertices(); VerticesCount = 0; _vao?.Dispose(); _vao = null; _vbo?.Dispose(); _vbo = null; }
public void Dispose() { Loaded = false; Objects?.Clear(); Objects = null; VerticesCount = 0; _vao?.Dispose(); _vao = null; _vbo?.Dispose(); _vbo = null; }
private void UpdateString() { var chars = new List <Vertex>(3 * _str.Length); var split = _str.Split(new[] { '\n' }, StringSplitOptions.None); var prevY = 0f; for (int i = 0; i < split.Length; i++) { var prevX = 0f; var leftPadding = TextAlignment == Alignment.LEFT ? 0 : (TextAlignment == Alignment.RIGHT ? -Font.GetStringWidth(split[i]) : -Font.GetStringWidth(split[i]) / 2); prevY -= Font.CharHeight; foreach (var c in split[i]) { var u = Font.GetUFor(c); chars.AddRange(new Vertex[] { new Vertex(new Vector3(prevX + leftPadding, prevY + Font.CharHeight, 0f), new Vector3(0, 0, 1), new Vector2(u, 0)), new Vertex(new Vector3(prevX + leftPadding, prevY, 0f), new Vector3(0, 0, 1), new Vector2(u, Font.CharTextureHeight)), new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY + Font.CharHeight, 0f), new Vector3(0, 0, 1), new Vector2(u + Font.CharTextureLength, 0)), new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY + Font.CharHeight, 0f), new Vector3(0, 0, 1), new Vector2(u + Font.CharTextureLength, 0)), new Vertex(new Vector3(prevX + leftPadding, prevY, 0f), new Vector3(0, 0, 1), new Vector2(u, Font.CharTextureHeight)), new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY, 0f), new Vector3(0, 0, 1), new Vector2(u + Font.CharTextureLength, Font.CharTextureHeight)), }); prevX += Font.CharWidth; } } if (_vbo == null) { _vbo = new Vbo(); } _vbo.Bind(); var charsArray = chars.ToArray(); _trianglesCount = charsArray.Length; _vbo.SetData(charsArray); _vbo.Unbind(); if (_vao == null) { _vao = new Vao <Vertex>(); } _vao.BindVbo(_vbo, Shader, new[] { new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, 0), new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes * 2), }); }
public void BindVao(Shader shader) { if (VerticesCount <= 0) { return; } if (_vao == null) { _vao = new Vao <DebugObject>(); } if (_lastUsedShader != shader.ProgramId) { _vao.BindVbo(_vbo, shader, new[] { new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector3.SizeInBytes * 2 + 4, 0), new VertexAttribute("_pos2", 3, VertexAttribPointerType.Float, Vector3.SizeInBytes * 2 + 4, Vector3.SizeInBytes), new VertexAttribute("_type", 1, VertexAttribIntegerType.Int, Vector3.SizeInBytes * 2 + 4, Vector3.SizeInBytes * 2), }); _lastUsedShader = shader.ProgramId; } }
public void BindVao(Shader shader) { if (VerticesCount <= 0) { return; } if (_vao == null) { _vao = new Vao <BlockInfo>(); } if (_lastUsedShader != shader.ProgramId) { _vao.BindVbo(_vbo, shader, new[] { new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector3.SizeInBytes + 8, 0), new VertexAttribute("_blockIdAndVisibilityAndMetadata", 1, VertexAttribIntegerType.Int, Vector3.SizeInBytes + 8, Vector3.SizeInBytes), new VertexAttribute("_humidityAndTemperature", 1, VertexAttribIntegerType.Int, Vector3.SizeInBytes + 8, Vector3.SizeInBytes + 4), }); _lastUsedShader = shader.ProgramId; } }
public void BindVao(Shader shader) { if (VerticesCount <= 0) { return; } if (_vao == null) { _vao = new Vao <Vertex>(); } if (_lastUsedShader != shader.ProgramId) { _vao.BindVbo(_vbo, shader, new[] { new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, 0), new VertexAttribute("_norm", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes), new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes * 2), new VertexAttribute("_color", 4, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes * 2 + Vector2.SizeInBytes), }); _lastUsedShader = shader.ProgramId; } }