Beispiel #1
0
        internal IndexBufferView(TypelessBuffer buffer, ulong offset, IndexFormat format)
        {
            this.typelessBuffer = buffer;
            this.offset         = offset;
            this.format         = format;

            buffer.AddRef();
        }
Beispiel #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);
        }
 /// <summary>
 /// Creates an index buffer.
 /// </summary>
 /// <param name="format">The format.</param>
 /// <param name="offset">The offset.</param>
 public IndexBufferView CreateIndexBuffer([NotNull] IndexFormat format, ulong offset)
 {
     return(new IndexBufferView(this, offset, format));
 }
 /// <summary>
 /// Creates an index buffer.
 /// </summary>
 /// <param name="format">The format.</param>
 public IndexBufferView CreateIndexBuffer([NotNull] IndexFormat format)
 {
     return(CreateIndexBuffer(format, 0));
 }