Esempio n. 1
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);
                }
            }
        }