Exemplo n.º 1
0
        private void DisposeWave()
        {
            lock (mutex)
            {
                if (dataStream != null)
                {
                    dataStream.Dispose();
                    dataStream = null;
                }

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

                if (sourceVoice != null)
                {
                    if (currentStream != null)
                    {
                        sourceVoice.BufferEnd -= bufferEndCallback;
                    }
                    sourceVoice.Stop();
                    sourceVoice.FlushSourceBuffers();
                    sourceVoice.Dispose();
                    sourceVoice = null;
                }

                current       = null;
                currentStream = null;
            }
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     if (ptr != null)
     {
         mp.UnmanagedPool.PutMemory(ptr, FLength);
     }
     ds?.Dispose();
     tex?.Dispose();
     SRV?.Dispose();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Converts mesh to DX-buffers.
        /// </summary>
        private static void MeshToBuffers(Device device,
                                          Mesh mesh,
                                          out SlimDX.Direct3D11.Buffer vertices,
                                          out SlimDX.Direct3D11.Buffer indices)
        {
            SlimDX.DataStream dsVertices = new SlimDX.DataStream(mesh.Vertices.Length * 6 * sizeof(float), true, true);
            SlimDX.DataStream dsIndices  = new SlimDX.DataStream(mesh.Indices.Length * 3 * sizeof(int), true, true);
            vertices = null;
            indices  = null;

            try
            {
                foreach (Vertex v in mesh.Vertices)
                {
                    v.WriteTo(dsVertices);
                }
                dsVertices.Position = 0;
                BufferDescription bdVertices = new BufferDescription();
                bdVertices.BindFlags      = BindFlags.VertexBuffer;
                bdVertices.CpuAccessFlags = CpuAccessFlags.None;
                bdVertices.OptionFlags    = ResourceOptionFlags.None;
                bdVertices.SizeInBytes    = mesh.Vertices.Length * 6 * sizeof(float);
                bdVertices.Usage          = ResourceUsage.Default;
                vertices = new SlimDX.Direct3D11.Buffer(device, dsVertices, bdVertices);

                dsIndices.WriteRange(mesh.Indices);
                dsIndices.Position = 0;
                BufferDescription bdIndices = new BufferDescription();
                bdIndices.BindFlags      = BindFlags.IndexBuffer;
                bdIndices.CpuAccessFlags = CpuAccessFlags.None;
                bdIndices.OptionFlags    = ResourceOptionFlags.None;
                bdIndices.SizeInBytes    = mesh.Indices.Length * 3 * sizeof(int);
                bdIndices.Usage          = ResourceUsage.Default;
                indices = new SlimDX.Direct3D11.Buffer(device, dsIndices, bdIndices);
            }
            catch (Exception)
            {
                if (vertices != null)
                {
                    vertices.Dispose();
                    vertices = null;
                }
                if (indices != null)
                {
                    indices.Dispose();
                    indices = null;
                }
                throw;
            }
            finally
            {
                dsVertices.Dispose();
                dsIndices.Dispose();
            }
        }
        public void Dispose()
        {
            SRV?.Dispose();
            tex?.Dispose();
            ds?.Dispose();

            if (bitmapData != null)
            {
                bitmap.UnlockBits(bitmapData);
            }

            bitmap?.Dispose();
        }
Exemplo n.º 5
0
        protected override DX11VertexGeometry GetGeom(DX11RenderContext device, int slice)
        {
            if (d2dFactory == null)
            {
                d2dFactory = new D2DFactory();
                dwFactory  = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared);
            }

            TextFormat fmt = new TextFormat(dwFactory, this.FFontInput[slice].Name, FFontSize[slice]);
            TextLayout tl  = new TextLayout(dwFactory, FText[slice], fmt, 0.0f, 32.0f);

            tl.WordWrapping       = WordWrapping.NoWrap;
            tl.TextAlignment      = FHAlignment[slice];
            tl.ParagraphAlignment = FVAlignment[slice];

            OutlineRenderer renderer = new OutlineRenderer(d2dFactory);
            Extruder        ex       = new Extruder(d2dFactory);


            tl.Draw(renderer, 0.0f, 0.0f);

            var outlinedGeometry = renderer.GetGeometry();

            ex.GetVertices(outlinedGeometry, vertexList, this.FExtrude[slice]);
            outlinedGeometry.Dispose();

            Vector3 min = new Vector3(float.MaxValue);
            Vector3 max = new Vector3(float.MinValue);

            for (int i = 0; i < vertexList.Count; i++)
            {
                Pos3Norm3VertexSDX pn = vertexList[i];

                min.X = pn.Position.X < min.X ? pn.Position.X : min.X;
                min.Y = pn.Position.Y < min.Y ? pn.Position.Y : min.Y;
                min.Z = pn.Position.Z < min.Z ? pn.Position.Z : min.Z;

                max.X = pn.Position.X > max.X ? pn.Position.X : max.X;
                max.Y = pn.Position.Y > max.Y ? pn.Position.Y : max.Y;
                max.Z = pn.Position.Z > max.Z ? pn.Position.Z : max.Z;
            }

            SlimDX.DataStream ds = new SlimDX.DataStream(vertexList.Count * Pos3Norm3VertexSDX.VertexSize, true, true);
            ds.Position = 0;

            for (int i = 0; i < vertexList.Count; i++)
            {
                ds.Write(vertexList[i]);
            }

            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(device.Device, ds, new SlimDX.Direct3D11.BufferDescription()
            {
                BindFlags      = SlimDX.Direct3D11.BindFlags.VertexBuffer,
                CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None,
                OptionFlags    = SlimDX.Direct3D11.ResourceOptionFlags.None,
                SizeInBytes    = (int)ds.Length,
                Usage          = SlimDX.Direct3D11.ResourceUsage.Default
            });

            ds.Dispose();

            DX11VertexGeometry vg = new DX11VertexGeometry(device);

            vg.InputLayout    = Pos3Norm3VertexSDX.Layout;
            vg.Topology       = SlimDX.Direct3D11.PrimitiveTopology.TriangleList;
            vg.VertexBuffer   = vbuffer;
            vg.VertexSize     = Pos3Norm3VertexSDX.VertexSize;
            vg.VerticesCount  = vertexList.Count;
            vg.HasBoundingBox = true;
            vg.BoundingBox    = new SlimDX.BoundingBox(new SlimDX.Vector3(min.X, min.Y, min.Z), new SlimDX.Vector3(max.X, max.Y, max.Z));

            renderer.Dispose();
            fmt.Dispose();
            tl.Dispose();

            return(vg);
        }
Exemplo n.º 6
0
        protected override DX11VertexGeometry GetGeom(DX11RenderContext device, int slice)
        {
            if (d2dFactory == null)
            {
                d2dFactory = new D2DFactory();
                dwFactory = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared);
            }

            TextFormat fmt = new TextFormat(dwFactory, this.FFontInput[slice].Name, FFontSize[slice]);

            TextLayout tl = new TextLayout(dwFactory, FText[slice], fmt, 0.0f, 32.0f);
            tl.WordWrapping = WordWrapping.NoWrap;
            tl.TextAlignment = FHAlignment[slice];
            tl.ParagraphAlignment = FVAlignment[slice];

            OutlineRenderer renderer = new OutlineRenderer(d2dFactory);
            Extruder ex = new Extruder(d2dFactory);

            tl.Draw(renderer, 0.0f, 0.0f);

            var result = ex.GetVertices(renderer.GetGeometry(), this.FExtrude[slice]);

            Vector3 min = new Vector3(float.MaxValue);
            Vector3 max = new Vector3(float.MinValue);

            result.ForEach(pn =>
            {
                min.X = pn.Position.X < min.X ? pn.Position.X : min.X;
                min.Y = pn.Position.Y < min.Y ? pn.Position.Y : min.Y;
                min.Z = pn.Position.Z < min.Z ? pn.Position.Z : min.Z;

                max.X = pn.Position.X > max.X ? pn.Position.X : max.X;
                max.Y = pn.Position.Y > max.Y ? pn.Position.Y : max.Y;
                max.Z = pn.Position.Z > max.Z ? pn.Position.Z : max.Z;
            });

            SlimDX.DataStream ds = new SlimDX.DataStream(result.Count * Pos3Norm3VertexSDX.VertexSize, true, true);
            ds.Position = 0;

            ds.WriteRange(result.ToArray());

            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(device.Device, ds, new SlimDX.Direct3D11.BufferDescription()
            {
                BindFlags = SlimDX.Direct3D11.BindFlags.VertexBuffer,
                CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None,
                OptionFlags = SlimDX.Direct3D11.ResourceOptionFlags.None,
                SizeInBytes = (int)ds.Length,
                Usage = SlimDX.Direct3D11.ResourceUsage.Default
            });

            ds.Dispose();

            DX11VertexGeometry vg = new DX11VertexGeometry(device);
            vg.InputLayout = Pos3Norm3VertexSDX.Layout;
            vg.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList;
            vg.VertexBuffer = vbuffer;
            vg.VertexSize = Pos3Norm3VertexSDX.VertexSize;
            vg.VerticesCount = result.Count;
            vg.HasBoundingBox = true;
            vg.BoundingBox = new SlimDX.BoundingBox(new SlimDX.Vector3(min.X, min.Y, min.Z), new SlimDX.Vector3(max.X, max.Y, max.Z));

            return vg;
        }