コード例 #1
0
ファイル: Sprite.cs プロジェクト: Entrivax/ft_vox
        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),
            });
        }
コード例 #2
0
 public void Dispose()
 {
     Loaded = false;
     ClearVertices();
     VerticesCount = 0;
     _vao?.Dispose();
     _vao = null;
     _vbo?.Dispose();
     _vbo = null;
 }
コード例 #3
0
 public void Dispose()
 {
     Loaded = false;
     Objects?.Clear();
     Objects       = null;
     VerticesCount = 0;
     _vao?.Dispose();
     _vao = null;
     _vbo?.Dispose();
     _vbo = null;
 }
コード例 #4
0
        public void BindVbo(Vbo vbo, Shader shader, VertexAttribute[] attributes)
        {
            Bind();
            vbo.Bind();

            foreach (var attrib in attributes)
            {
                attrib.Set(shader);
            }

            vbo.Unbind();
            Unbind();
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
コード例 #5
0
        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),
            });
        }
コード例 #6
0
        public void LoadInGl()
        {
            if (Loaded)
            {
                return;
            }
            VerticesCount = Objects.Count;
            if (Objects.Count == 0)
            {
                return;
            }
            var objs = Objects.ToArray();

            _vbo = new Vbo();
            _vbo.Bind();
            _vbo.SetData(objs);
            _vbo.Unbind();

            Loaded      = true;
            Invalidated = false;
        }
コード例 #7
0
        public void LoadInGl()
        {
            if (Loaded)
            {
                return;
            }
            VerticesCount = Vertices.Count;
            if (Vertices.Count == 0)
            {
                return;
            }
            var vertices = Vertices.ToArray();

            _vbo = new Vbo();
            _vbo.Bind();
            _vbo.SetData(vertices);
            _vbo.Unbind();

            ClearVertices();
            Loaded = true;
        }