Exemplo n.º 1
0
 public void UpdateMesh <T>(T[] indices, PrimitiveType primitive) where T : struct
 {
     GL.BindVertexArray(0);
     Primitive    = primitive;
     ElementCount = indices.Length * PrimitiveHelper.GetElementCountForPrimitive(primitive);
     _indexBuffer.BufferSubData(BufferTarget.ElementArrayBuffer, indices, ElementCount * sizeof(int), IntPtr.Zero);
 }
Exemplo n.º 2
0
        public void SetMesh <T>(Vector3[] vertices, Vector3[] normals, T[] indices, PrimitiveType primitive) where T : struct
        {
            if (vertices == null || indices == null)
            {
                throw new ArgumentNullException();
            }

            if (vertices.Length == 0 || indices.Length == 0)
            {
                throw new ArgumentException("Invalid vertices or faces count");
            }

            // compute the number of vertices
            ElementCount = indices.Length * PrimitiveHelper.GetElementCountForPrimitive(primitive);
            Primitive    = primitive;

            // send the vertices, normals and indices to the buffer.
            _vertexBuffer.BufferData(BufferTarget.ArrayBuffer, vertices, vertices.Length * Vector3.SizeInBytes);
            _indexBuffer.BufferData(BufferTarget.ElementArrayBuffer, indices, ElementCount * sizeof(int));
            if (normals != null && normals.Length != 0)
            {
                _normalBuffer.BufferData(BufferTarget.ArrayBuffer, normals, vertices.Length * Vector3.SizeInBytes);
            }

            // Remove the old Vertex array, if any, and construct a new one.
            if (_vaoHandle.Handle != 0)
            {
                _vaoHandle.Dispose();
                _vaoHandle = new VertexArray();
            }
            // bind the buffers to the VertexArray
            _vaoHandle.BindBuffers(_vertexBuffer, _normalBuffer, _indexBuffer);
        }
Exemplo n.º 3
0
        public void UpdateMesh <T>(T[] indices, PrimitiveType primitive) where T : struct
        {
            if (primitive != Primitive)
            {
                throw new InvalidOperationException();
            }

            // Unbind the previous vertex array.
            GL.BindVertexArray(0); // Important! 4 Hours wasted!
            Primitive = primitive;
            // update the buffer
            ElementCount = indices.Length * PrimitiveHelper.GetElementCountForPrimitive(primitive);
            _indexBuffer.BufferSubData(BufferTarget.ElementArrayBuffer, indices, ElementCount * sizeof(int), IntPtr.Zero);
        }
Exemplo n.º 4
0
        public void SetMesh <T>(DataBuffer vertices, DataBuffer normals, T[] indices, PrimitiveType primitive) where T : struct
        {
            Primitive    = primitive;
            ElementCount = PrimitiveHelper.GetElementCountForPrimitive(primitive) * indices.Length;

            _vaoHandle?.Dispose();
            _vaoHandle = new VertexArray();

            if (indices.Length == 0)
            {
                ElementCount = 0;
                return;
            }

            // ignore the normals on lines and points
            _vaoHandle.BindBuffers(vertices, PrimitiveHelper.GetElementCountForPrimitive(primitive) <= 2 ? null : normals, _indexBuffer);
            _indexBuffer.BufferData(BufferTarget.ElementArrayBuffer, indices, ElementCount * sizeof(int));
        }