예제 #1
0
        protected override void Destroy()
        {
            for (int i = 0; i < VertexBufferCount; i++)
            {
                vertexBuffers[i].Dispose();
            }

            activeVertexBufferIndex = -1;

            mappedVertexBufferPointer = IntPtr.Zero;

            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                indexBuffer = null;
            }

            indexBufferBinding = null;
            pipelineState      = null;

            if (simpleEffect != null)
            {
                simpleEffect.Dispose();
                simpleEffect = null;
            }

            for (int i = 0; i < VertexBufferCount; i++)
            {
                inputElementDescriptions[i] = null;
            }

            charsToRenderCount = -1;

            base.Destroy();
        }
예제 #2
0
        private unsafe void ReleaseDevice()
        {
            EmptyTexelBufferInt.Dispose();
            EmptyTexelBufferInt = null;
            EmptyTexelBufferFloat.Dispose();
            EmptyTexelBufferFloat = null;

            EmptyTexture.Dispose();
            EmptyTexture = null;

            // Wait for all queues to be idle
            vkDeviceWaitIdle(nativeDevice);

            // Destroy all remaining fences
            GetCompletedValue();

            // Mark upload buffer for destruction
            if (nativeUploadBuffer != VkBuffer.Null)
            {
                vkUnmapMemory(NativeDevice, nativeUploadBufferMemory);
                nativeResourceCollector.Add(lastCompletedFence, nativeUploadBuffer);
                nativeResourceCollector.Add(lastCompletedFence, nativeUploadBufferMemory);

                nativeUploadBuffer       = VkBuffer.Null;
                nativeUploadBufferMemory = VkDeviceMemory.Null;
            }

            // Release fenced resources
            nativeResourceCollector.Dispose();
            DescriptorPools.Dispose();

            vkDestroyCommandPool(nativeDevice, NativeCopyCommandPool, null);
            vkDestroyDevice(nativeDevice, null);
        }
예제 #3
0
        public static bool DisposeBufferBySpecs(Stride.Graphics.Buffer buf, int count)
        {
            if (buf == null || buf.ElementCount != count)
            {
                if (buf != null)
                {
                    buf.Dispose();
                }

                return(true);
            }
            return(false);
        }
예제 #4
0
        protected override void Destroy()
        {
            foreach (var renderFeature in RenderFeatures)
            {
                renderFeature.Dispose();
            }

            RenderFeatures.CollectionChanged -= RenderFeatures_CollectionChanged;

            descriptorSets.Dispose();

            emptyBuffer?.Dispose();
            emptyBuffer = null;

            base.Destroy();
        }
        // TODO: make this more easy and clear, improve instancing component to support this better
        protected override void ManageInstancingData()
        {
            var transformUsage = (ModelTransformUsage)(((int)Game.UpdateTime.Total.TotalSeconds) % 3);

            instancingUserBuffer.ModelTransformUsage = ModelTransformUsage.PostMultiply;
            instancingUserBuffer.InstanceCount       = instanceWorldTransformations.Length;

            // Make sure inverse matrices are big enough
            if (worldInverseTransformations.Length != instanceWorldTransformations.Length)
            {
                worldInverseTransformations = new Matrix[instanceWorldTransformations.Length];
            }

            // Invert matrices and update bounding box
            var ibb = BoundingBox.Empty;

            for (int i = 0; i < instanceWorldTransformations.Length; i++)
            {
                Matrix.Invert(ref instanceWorldTransformations[i], out worldInverseTransformations[i]);
                var pos = instanceWorldTransformations[i].TranslationVector;
                BoundingBox.Merge(ref ibb, ref pos, out ibb);
            }

            instancingUserBuffer.BoundingBox = ibb;

            // Manage buffers
            if (InstanceWorldBuffer == null || InstanceWorldBuffer.ElementCount < instancingUserBuffer.InstanceCount)
            {
                InstanceWorldBuffer?.Dispose();
                InstanceWorldInverseBuffer?.Dispose();

                InstanceWorldBuffer = CreateMatrixBuffer(GraphicsDevice, instancingUserBuffer.InstanceCount);
                instancingUserBuffer.InstanceWorldBuffer = InstanceWorldBuffer;

                InstanceWorldInverseBuffer = CreateMatrixBuffer(GraphicsDevice, instancingUserBuffer.InstanceCount);
                instancingUserBuffer.InstanceWorldInverseBuffer = InstanceWorldInverseBuffer;
            }

            instancingUserBuffer.InstanceWorldBuffer.SetData(Game.GraphicsContext.CommandList, instanceWorldTransformations);
            instancingUserBuffer.InstanceWorldInverseBuffer.SetData(Game.GraphicsContext.CommandList, worldInverseTransformations);
        }