示例#1
0
 public void Clear()
 {
     points.Clear();
     vertFront.Clear();
     vertBack.Clear();
     indBoth.SetCount(0);             // we don't deallocate indices, we only set "used" count
 }
示例#2
0
        /// <summary>
        /// Updates the vertex buffer object from the <see cref="Vertices"/> array.
        /// </summary>
        /// <typeparam name="TVertex">The type of vertex buffer to use.</typeparam>
        /// <param name="transform">Function that transforms the vertex array data to a interleaved struct format.</param>
        private void UpdateVertices <TVertex>(
            Func <Vector3, Vector3, Color4, TVertex> transform
            ) where TVertex : struct, IVertexData
        {
            // if the type of the vertex data has changed we need to create a new buffer
            if (m_vertexBuffer != null && m_vertexBuffer.GetType() != typeof(VertexBuffer <TVertex>))
            {
                m_vertexBuffer.Dispose();
                m_vertexBuffer = null;
            }

            // create vertex buffer if needed
            if (m_vertexBuffer == null)
            {
                m_vertexBuffer = new VertexBuffer <TVertex>(m_vertices.Length);
            }

            // copy the vertices into the buffer
            VertexBuffer <TVertex> buffer = m_vertexBuffer as VertexBuffer <TVertex>;

            buffer.Clear();

            int offset;

            TVertex[] vertexArray = buffer.WriteDirectly(m_vertices.Length, out offset);

            for (int i = 0; i < m_vertices.Length; i++)
            {
                vertexArray[i] = transform(m_vertices[i], m_normals[i], m_colors[i]);
            }

            // upload to the GPU
            buffer.BufferData();
            m_vertexBufferDirty = false;
        }
示例#3
0
 public void ClearBuffers()
 {
     if (BufferInitialized)
     {
         IndexBuffer.Clear(BufferTarget.ElementArrayBuffer);
         VertexBuffer.Clear(BufferTarget.ArrayBuffer);
     }
 }
示例#4
0
 public void SetVertices(IEnumerable <T> vertices)
 {
     if (!BufferInitialized)
     {
         CreateBuffers();
     }
     VertexBuffer.Clear(BufferTarget.ArrayBuffer);
     VertexBuffer.Init(BufferTarget.ArrayBuffer, vertices.ToArray());
 }
示例#5
0
        public void AppendVertices(IEnumerable <T> vertices)
        {
            if (!BufferInitialized)
            {
                CreateBuffers();
            }
            var currentVerts = VertexBuffer.Content;

            VertexBuffer.Clear(BufferTarget.ArrayBuffer);
            VertexBuffer.Init(BufferTarget.ArrayBuffer, currentVerts.Concat(vertices).ToArray());
        }
示例#6
0
 public void ClearBuffers()
 {
     if (BufferInitialized)
     {
         IndexBuffer.Clear(BufferTarget.ElementArrayBuffer);
         VertexBuffer.Clear(BufferTarget.ArrayBuffer);
     }
     else
     {
         TempIndices.Clear();
         TempVertices.Clear();
     }
 }
示例#7
0
        /// <summary>
        /// Called just prior to rendering the component.
        /// </summary>
        protected override void OnRender()
        {
            if (m_vertexBuffer == null)
            {
                m_vertexBuffer = new VertexBuffer <VertexPNC>(24);
                m_surface.SetVertexBuffer(m_vertexBuffer, PrimitiveType.Lines);
            }

            if (m_dirty)
            {
                ReadOnlyCollection <Vector3> corners = m_mesh.Bounds.Corners;

                // clear any lines
                m_vertexBuffer.Clear();

                // get the underlying buffer
                int         offset;
                VertexPNC[] verts = m_vertexBuffer.WriteDirectly(24, out offset);

                // each consecutive pair of elements forms a line segment drawn to form the box wireframe
                verts[0] = new VertexPNC(corners[0], Vector3.Zero, Color4.White);
                verts[1] = new VertexPNC(corners[4], Vector3.Zero, Color4.White);
                verts[2] = new VertexPNC(corners[1], Vector3.Zero, Color4.White);
                verts[3] = new VertexPNC(corners[5], Vector3.Zero, Color4.White);
                verts[4] = new VertexPNC(corners[2], Vector3.Zero, Color4.White);
                verts[5] = new VertexPNC(corners[6], Vector3.Zero, Color4.White);
                verts[6] = new VertexPNC(corners[3], Vector3.Zero, Color4.White);
                verts[7] = new VertexPNC(corners[7], Vector3.Zero, Color4.White);

                verts[8]  = new VertexPNC(corners[0], Vector3.Zero, Color4.White);
                verts[9]  = new VertexPNC(corners[1], Vector3.Zero, Color4.White);
                verts[10] = new VertexPNC(corners[1], Vector3.Zero, Color4.White);
                verts[11] = new VertexPNC(corners[3], Vector3.Zero, Color4.White);
                verts[12] = new VertexPNC(corners[3], Vector3.Zero, Color4.White);
                verts[13] = new VertexPNC(corners[2], Vector3.Zero, Color4.White);
                verts[14] = new VertexPNC(corners[2], Vector3.Zero, Color4.White);
                verts[15] = new VertexPNC(corners[0], Vector3.Zero, Color4.White);

                verts[16] = new VertexPNC(corners[4], Vector3.Zero, Color4.White);
                verts[17] = new VertexPNC(corners[5], Vector3.Zero, Color4.White);
                verts[18] = new VertexPNC(corners[5], Vector3.Zero, Color4.White);
                verts[19] = new VertexPNC(corners[7], Vector3.Zero, Color4.White);
                verts[20] = new VertexPNC(corners[7], Vector3.Zero, Color4.White);
                verts[21] = new VertexPNC(corners[6], Vector3.Zero, Color4.White);
                verts[22] = new VertexPNC(corners[6], Vector3.Zero, Color4.White);
                verts[23] = new VertexPNC(corners[4], Vector3.Zero, Color4.White);

                // upload the lines to the GPU if changed
                m_vertexBuffer.BufferData();
            }
        }
示例#8
0
        public void SetVertices(IEnumerable <T> vertices)
        {
            //if (!BufferInitialized)
            //    CreateBuffers();

            if (BufferInitialized)
            {
                VertexBuffer.Clear(BufferTarget.ArrayBuffer);
                VertexBuffer.Init(BufferTarget.ArrayBuffer, vertices.ToArray());
            }
            else
            {
                TempVertices = vertices.ToList();
            }
        }
示例#9
0
        public void AppendVertices(IEnumerable <T> vertices)
        {
            //if (!BufferInitialized)
            //    CreateBuffers();

            if (BufferInitialized)
            {
                var currentVerts = VertexBuffer.Content;
                VertexBuffer.Clear(BufferTarget.ArrayBuffer);
                VertexBuffer.Init(BufferTarget.ArrayBuffer, currentVerts.Concat(vertices).ToArray());
            }
            else
            {
                TempVertices.AddRange(vertices);
            }
        }
示例#10
0
        private void PrepareBuffer()
        {
            if (InstanceDataVertexBuffer == null)
            {
                if (SceneObjects.Count > 0)
                {
                    InstanceDataVertexBuffer = PrivateRendererContext.CreateVertexBuffer(IntPtr.Zero,
                        SceneObjectArrayInstanceData.SIZE, 
                        RendererBufferUsage.DynamicDraw, "SceneObjectArrayInstanceData_VBO_" + ObjectName + "_" + DateTime.Now.Ticks);
                    

                    SceneObjectArrayInstanceData[] data = CollectData();

                    InstanceDataVertexBuffer.Clear();

                    InstanceDataVertexBuffer.UpdateSubBuffer<SceneObjectArrayInstanceData>(data, 0, data.Length * SceneObjectArrayInstanceData.SIZE);
                }
            }
            else
            {
                SceneObjectArrayInstanceData[] data = CollectData();

                if ((SceneObjects.Count * SceneObjectArrayInstanceData.SIZE) > InstanceDataVertexBuffer.SizeInBytes)
                {
                    int actual_size = data.Length * SceneObjectArrayInstanceData.SIZE;

                    PrivateRendererContext.DeleteGraphicsResource(InstanceDataVertexBuffer);

                    if (SceneObjects.Count > 0)
                    {
                        InstanceDataVertexBuffer = PrivateRendererContext.CreateVertexBuffer(IntPtr.Zero, actual_size, 
                            RendererBufferUsage.DynamicDraw, "SceneObjectArrayInstanceData_VBO_" + ObjectName + "_" + DateTime.Now.Ticks);
                    }

                    InstanceDataVertexBuffer.Clear();

                    InstanceDataVertexBuffer.UpdateSubBuffer<SceneObjectArrayInstanceData>(data, 0, data.Length * SceneObjectArrayInstanceData.SIZE);
                }
            }
        }
示例#11
0
        public override void Render()
        {
            VertexBuffer.Clear();

            Draw();
        }