Ejemplo n.º 1
0
        public void Batching()
        {
            using (GraphicsDevice device = InitializeDevice())
            {
                GeometryBatch geometry = Geometry.CreateBatch(VertexFormat.Parse("P.Fx3"),
                                                              new IndexFormat(false), 8, 24, 1);


                Vector3f[] vertices = new Vector3f[]
                {
                    new Vector3f(0, 0, 0),
                    new Vector3f(1, 0, 0),
                    new Vector3f(1, 1, 0)
                };

                geometry.BindToDevice(device);

                geometry.BeginBatch();
                geometry.AddVertices(vertices);
                geometry.EndBatch();


                geometry.Dispose();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates dynamic buffers that are are update (usually each frame).
        /// </summary>
        /// <param name="device"></param>
        /// <param name="vertexFormat"></param>
        /// <param name="indexFormat"></param>
        /// <param name="maxVertices"></param>
        /// <param name="maxIndices"></param>
        /// <returns></returns>
        public static GeometryBatch CreateBatch(VertexFormat vertexFormat, IndexFormat indexFormat,
                                                ulong maxVertices, ulong maxIndices, uint maxCyclicBuffers)
        {
            if (maxCyclicBuffers == 0)
            {
                maxCyclicBuffers = 1;
            }

            VertexBufferView[] vbufferView = new VertexBufferView[maxCyclicBuffers];
            IndexBufferView[]  ibufferView = new IndexBufferView[maxCyclicBuffers];

            for (uint i = 0; i < maxCyclicBuffers; i++)
            {
                // We create vertex buffer.
                TypelessBuffer vbuffer = new TypelessBuffer(Usage.Dynamic, BufferUsage.VertexBuffer, CPUAccess.Write,
                                                            GraphicsLocality.DeviceOrSystemMemory, vertexFormat.ByteSize * maxVertices);
                vbuffer.DisposeOnViewDispose = true;

                // We create view.
                vbufferView[i] = vbuffer.CreateVertexBuffer(vertexFormat);

                // We may also create index buffer.
                if (maxIndices > 0)
                {
                    TypelessBuffer ibuffer = new TypelessBuffer(Usage.Dynamic, BufferUsage.IndexBuffer, CPUAccess.Write,
                                                                GraphicsLocality.DeviceOrSystemMemory, indexFormat.ByteSize * maxIndices);
                    ibuffer.DisposeOnViewDispose = true;

                    // We create view.
                    ibufferView[i] = ibuffer.CreateIndexBuffer(indexFormat);
                }
            }

            // We create geometry.
            GeometryBatch geometry = new GeometryBatch(vbufferView, ibufferView);

            return(geometry);
        }