コード例 #1
0
        void Dispose(bool fin)
        {
            AssertNotLocked();

            ClearCache();

            if (!isDisposed && associateBuffers)
            {
                foreach (VertexBufferView view in vertexBuffers)
                {
                    view.Dispose();
                }
                if (indexBuffer != null)
                {
                    indexBuffer.Dispose();
                }
            }

            if (!isDisposed)
            {
                if (!fin)
                {
                    GC.SuppressFinalize(this);
                }
                else
                {
                    // Make sure we don't hold references.
                    indexBuffer = null;
                    vertexBuffers.Clear();
                }
            }

            isDisposed = true;
        }
コード例 #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);
        }