Exemple #1
0
 public void Dispose()
 {
     enabled = false;
     task.Wait();
     device.Dispose();
     direct.Dispose();
 }
Exemple #2
0
        //--------------------//

        #region Dispose
        protected override void OnDispose()
        {
            Log.Info("Disposing engine\nLast framerate: " + Performance.Fps);

            // Dispose scenes and views
            ExtraRender = null;
            foreach (var view in Views)
            {
                view.Scene.Dispose();
            }
            base.OnDispose();

            // Shutdown music
            Music?.Dispose();

            // Dispose cached assets
            Cache?.Dispose();

            // Dispose default meshes
            SimpleSphere?.Dispose();
            SimpleBox?.Dispose();

            // Dispose Direct3D device
            BackBuffer?.Dispose();
            Device?.Dispose();

            // Dispose DirectSound objects
            //_listener?.Dispose();
            AudioDevice?.Dispose();

            _direct3D?.Dispose();

            // Dispose debug window
            _debugForm?.Dispose();
        }
        public void RenderBezier(ViewportInfo viewportInfo)
        {
            pp                  = new PresentParameters();
            pp.SwapEffect       = SwapEffect.Discard;
            pp.Windowed         = true;
            pp.BackBufferWidth  = viewportInfo.resX;
            pp.BackBufferHeight = viewportInfo.resY;
            pp.BackBufferFormat = Format.A8R8G8B8;

            d3dBezier = new Direct3D();

            deviceBezier = new Device(d3dBezier, 0, DeviceType.Hardware, handleBezier, CreateFlags.HardwareVertexProcessing, pp);

            deviceBezier.SetRenderState(RenderState.Lighting, true);

            deviceBezier.SetLight(0, defLight);
            deviceBezier.EnableLight(0, true);

            deviceBezier.SetRenderState(RenderState.FillMode, wireframe ? 2 : 0);
            deviceBezier.SetRenderState(RenderState.CullMode, 1);

            deviceBezier.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(230, 230, 230), 1.0f, 0);

            deviceBezier.Present();

            d3dBezier.Dispose();
            deviceBezier.Dispose();
        }
Exemple #4
0
 private void TransparentDXOverlay_FormClosing(object sender, FormClosingEventArgs e)
 {
     ExitRequested = true;
     dxThread.Join();
     d3d.Dispose();
     dx.Dispose();
 }
Exemple #5
0
 public void Dispose()
 {
     UnloadGraphicResources();
     resourceManager.Dispose();
     device.Dispose();
     direct3D.Dispose();
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                PresentParams = null;
            }

            if (Direct3D != null)
            {
                Direct3D.Dispose();
                Direct3D = null;
            }
            if (Sprite != null)
            {
                Sprite.Dispose();
                Sprite = null;
            }

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

            if (d3dFont != null)
            {
                d3dFont.Dispose();
                d3dFont = null;
            }
        }
Exemple #7
0
 public void Dispose()
 {
     box.Dispose();
     groundBox.Dispose();
     Device.Dispose();
     direct3D.Dispose();
 }
 /// <summary>
 /// Disposes of object resources.
 /// </summary>
 /// <param name="disposeManagedResources">If true, managed resources should be
 /// disposed of in addition to unmanaged resources.</param>
 protected virtual void Dispose(bool disposeManagedResources)
 {
     if (disposeManagedResources)
     {
         Device.Dispose();
         _direct3D.Dispose();
     }
 }
Exemple #9
0
 // This terminates Direct3D
 public static void Terminate()
 {
     if (d3d != null)
     {
         d3d.Dispose();
         d3d = null;
     }
 }
Exemple #10
0
 public void Dispose()
 {
     lock ( GlobalLock )
     {
         Device.Dispose();
         Direct3D.Dispose();
     }
 }
Exemple #11
0
 public new void Dispose()
 {
     DisposeDeviceResources();
     _parent.DisposeTextures();
     _device.Dispose();
     direct3d.Dispose();
     base.Dispose();
 }
Exemple #12
0
        private static void TryCreateDeviceInternal(IntPtr windowHandle, DeviceType deviceType, MyRenderDeviceSettings settingsToTry, out Device device, out PresentParameters parameters)
        {
            device     = null;
            parameters = CreatePresentParameters(settingsToTry, windowHandle);
            while (device == null)
            {
                try
                {
                    // These calls are here to ensure that none of these calls throw exceptions (even if their results are not used).
                    m_d3d.Dispose();
                    m_d3d = new Direct3D();

                    var d3dCaps = m_d3d.GetDeviceCaps(settingsToTry.AdapterOrdinal, DeviceType.Hardware);

                    device = new Device(m_d3d, settingsToTry.AdapterOrdinal, deviceType, Parameters.DeviceWindowHandle,
                                        CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve,
                                        Parameters);
                    device.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0, 0, 0, 1), 1.0f, 0);

                    var caps = Device.Capabilities;
                }
                catch (SharpDX.SharpDXException e)
                {
                    if (e.ResultCode == ResultCode.NotAvailable ||
                        (e.ResultCode == ResultCode.InvalidCall && GetForegroundWindow() != Parameters.DeviceWindowHandle))
                    {
                        // User has probably Alt+Tabbed or locked his computer before the game has started.
                        // To counter this, we try creating device again a bit later.
                        Thread.Sleep(2000);
                        MyLog.Default.WriteLine("Device creation failed with " + e.Message);
                    }
                    else
                    {
                        // Either settings or graphics card are not supported.
                        MyLog.Default.WriteLine(e);
                        throw;
                    }
                }

                try
                {
                    MyLog.Default.WriteLine("Loading adapters");
                    m_adaptersList = GetAdaptersList(m_d3d);
                    MyLog.Default.WriteLine("Found adapters");
                    foreach (var adapter in m_adaptersList)
                    {
                        adapter.LogInfo(MyLog.Default.WriteLine);
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine(e);
                    throw;
                }
            }
        }
Exemple #13
0
        private void MapForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DisposeDevice();

            if (d3d != null)
            {
                d3d.Dispose();
                d3d = null;
            }
        }
Exemple #14
0
 public void Dispose()
 {
     if (device != null)
     {
         device.Dispose();
     }
     if (direct != null)
     {
         direct.Dispose();
     }
 }
Exemple #15
0
        private void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            Direct3D direct3D = new Direct3D();

            PresentParameters presentParameters = new PresentParameters();

            presentParameters.Windowed   = true;
            presentParameters.SwapEffect = SwapEffect.Discard;
            Device device = new Device(direct3D, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, presentParameters);

            while (!backgroundWorker.CancellationPending)
            {
                Surface surface = Surface.CreateOffscreenPlain(device, Program.ScreenWidth, Program.ScreenHeight, Format.A8R8G8B8, Pool.Scratch);
                device.GetFrontBufferData(0, surface);

                DataRectangle dataRectangle = surface.LockRectangle(LockFlags.None);
                DataStream    dataStream    = dataRectangle.Data;

                lock (SpotSet.Lock) {
                    foreach (Spot spot in SpotSet.Spots)
                    {
                        if (spot.TopLeft.PosDx >= 0 && spot.TopRight.PosDx >= 0 && spot.BottomLeft.PosDx >= 0 && spot.BottomRight.PosDx >= 0)
                        {
                            dataStream.Position = spot.TopLeft.PosDx;
                            dataStream.Read(colorBufferTopLeft, 0, 4);

                            dataStream.Position = spot.TopRight.PosDx;
                            dataStream.Read(colorBufferTopRight, 0, 4);

                            dataStream.Position = spot.Center.PosDx;
                            dataStream.Read(colorBufferCenter, 0, 4);

                            dataStream.Position = spot.BottomLeft.PosDx;
                            dataStream.Read(colorBufferBottomLeft, 0, 4);

                            dataStream.Position = spot.BottomRight.PosDx;
                            dataStream.Read(colorBufferBottomRight, 0, 4);

                            AverageValues();

                            spot.SetColor(colorBuffer[2], colorBuffer[1], colorBuffer[0]);  //BGR -> RGB
                        }
                    }
                }
                surface.UnlockRectangle();
                surface.Dispose();
            }
            device.Dispose();
            direct3D.Dispose();
            e.Cancel = true;
        }
Exemple #16
0
        private void ReleaseDirect3D()
        {
            if (_direct3D != null && !_direct3D.Disposed)
            {
                _direct3D.Dispose();
                _direct3D = null;
            }

            if (_direct3DEx != null && !_direct3DEx.Disposed)
            {
                _direct3DEx.Dispose();
                _direct3DEx = null;
            }
        }
Exemple #17
0
 public void ResetDevice()
 {
     if (_parent != null && _device != null)
     {
         DisposeDeviceResources();
         _parent.DisposeTextures();
         try
         {
             _device.Reset(presentParams);
             isDeviceLost = false;
             InitDeviceResources();
         }
         catch
         {
             _device.Dispose();
             direct3d.Dispose();
             _device  = null;
             direct3d = null;
             Init(_parent);
             isDeviceLost = false;
             _parent.Reload();
         }
     }
 }
Exemple #18
0
        public static void Initiate()
        {
            var form = new RenderForm("SharpDX - MiniCube Direct3D9 Sample");
            // Creates the Device
            var direct3D = new Direct3D();
            var device   = new SharpDX.Direct3D9.Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(form.ClientSize.Width, form.ClientSize.Height));

            // Prepare matrices
            var view     = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
            var proj     = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 0.1f, 100.0f);
            var viewProj = Matrix.Multiply(view, proj);

            // Use clock
            var clock = new Stopwatch();

            clock.Start();

            string Game = "WOT";

            switch (Game)
            {
            case "WOT":
                _list.Add(new DrawTextureAndCatchIt(SharpDX.Direct3D9.Texture.FromFile(device, "Resources/error_enter.png"), SharpDX.Direct3D9.Texture.FromFile(device, "Resources/error_6473.png"), new SharpDX.Mathematics.Interop.RawRectangle(1, 1, 100, 100), new SharpDX.Vector3(100, 100, 0)));
                _list.Add(new DrawTextureAndCatchIt(SharpDX.Direct3D9.Texture.FromFile(device, "Resources/edit-addenter.png"), SharpDX.Direct3D9.Texture.FromFile(device, "Resources/edit-add.png"), new SharpDX.Mathematics.Interop.RawRectangle(1, 1, 100, 100), new SharpDX.Vector3(100, 400, 0)));
                break;
            }
            //choose game


            RenderLoop.Run(form, () =>
            {
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                device.BeginScene();
                foreach (DrawTextureAndCatchIt dr in _list)
                {
                    dr.CheckCursorPosition();
                    dr.DrawTexture(device);
                }

                device.EndScene();
                device.Present();
            });

            device.Dispose();
            direct3D.Dispose();
        }
Exemple #19
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (direct3dInterface != null)
     {
         direct3dInterface.Dispose();
         direct3dInterface = null;
     }
     if (direct3dDevice != null)
     {
         direct3dDevice.Dispose();
         direct3dDevice = null;
     }
     if (vertexBuffer != null)
     {
         vertexBuffer.Dispose();
         vertexBuffer = null;
     }
 }
        public override void Close()
        {
            if (direct3D9 != null && !direct3D9.IsDisposed)
            {
                direct3D9.Dispose();
                direct3D9 = null;
            }

            if (device != null && !device.IsDisposed)
            {
                device.Dispose();
                device = null;
            }

            DisposeSurfaces();

            base.Close();
        }
Exemple #21
0
 /// <summary>
 /// 破棄します。
 /// </summary>
 protected override void DisposeResource()
 {
     base.DisposeResource();
     if (d3d != null)
     {
         d3d.Dispose();
         d3d = null;
     }
     if (device != null)
     {
         device.Dispose();
         device = null;
     }
     if (Sprite != null)
     {
         Sprite.Dispose();
         Sprite = null;
     }
 }
        private void ReleaseDirect3D()
        {
            if (direct3D != null)
            {
                if (!direct3D.IsDisposed)
                {
                    direct3D.Dispose();
                    direct3D = null;
                }
            }

            if (direct3DEx != null)
            {
                if (!direct3DEx.IsDisposed)
                {
                    direct3DEx.Dispose();
                    direct3DEx = null;
                }
            }
        }
Exemple #23
0
 protected override void OnClosing(CancelEventArgs e)
 {
     base.OnClosing(e);
     if (e.Cancel)
     {
         return;
     }
     if (Device != null)
     {
         Device.Dispose();
     }
     if (Direct3D != null)
     {
         Direct3D.Dispose();
     }
     if (water != null)
     {
         water.Dispose();
     }
 }
        public void Close()
        {
            logger.Debug("ScreenPreviewCallback::Close()");

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

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

            if (previewHelper != null)
            {
                Marshal.ReleaseComObject(previewHelper);
                previewHelper = null;
            }
        }
Exemple #25
0
        public void Dispose(bool disposing)
        {
            this.window.Children.Remove((FrameworkElement)_layer);

            this._layer.Dispose();
            this._layer = null;

            this.thread.Do((Action)(() =>
            {
                this.renderframe?.Dispose();
                this.opentk?.Dispose();

                ready.Set();

                this.window.SizeChanged -= Ctl_SizeChanged;

                if (this.olddepth != null)
                {
                    this.device.DepthStencilSurface = this.olddepth;
                    this.olddepth?.Dispose();
                    this.olddepth = null;
                }
                this.frame?.Dispose();
                this.Xwt.FreeWindowInfo(this.widget);
                depthsurface?.Dispose(); depthsurface = null;
                depthtexture?.Dispose(); depthtexture = null;
                effect3?.Dispose(); effect3 = null;
                effect2?.Dispose(); effect2 = null;
                presenteffect?.Dispose(); presenteffect = null;
                vertices2?.Dispose(); vertices2 = null;
                indices?.Dispose(); indices = null;
                device?.Dispose(); device = null;
                direct3D?.Dispose(); direct3D = null;
            }));
            this.thread.Dispose();
        }
Exemple #26
0
 void IDisposable.Dispose()
 {
     DestroyDevice();
     _d3d.Dispose();
 }
Exemple #27
0
 public void Dispose()
 {
     _device?.Dispose();
     _direct3D?.Dispose();
     _disposed = true;
 }
Exemple #28
0
 void IDisposable.Dispose()
 {
     ResetHandlers.Reset();
     DestroyDevice();
     d3d.Dispose();
 }
Exemple #29
0
 public override void Dispose()
 {
     base.Dispose();
     device.Dispose();
     d3d.Dispose();
 }
        private void myWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //Stop render loop before closing
            if (frameTimer != null)
            {
                frameTimer.Tick -= new EventHandler(frameTimer_Tick);
                frameTimer.Stop();
            }

            //Cleanup
            if (graphicsres != null)
            {
                graphicsres.Dispose();
            }
            if (g_mparticles != null)
            {
                g_mparticles.Dispose();
            }
            if (stopwatch != null)
            {
                stopwatch.Dispose();
            }

            if (texref != null)
            {
                texref.Dispose();
            }
            if (g_dvfield != null)
            {
                g_dvfield.Dispose();
            }
            if (g_vxfield != null)
            {
                g_vxfield.Dispose();
            }
            if (g_vyfield != null)
            {
                g_vyfield.Dispose();
            }

            if (g_planc2r != null)
            {
                g_planc2r.Dispose();
            }
            if (g_planr2c != null)
            {
                g_planr2c.Dispose();
            }

            if (g_pVB != null)
            {
                g_pVB.Dispose();
            }
            if (g_pTexture != null)
            {
                g_pTexture.Dispose();
            }

            if (device != null)
            {
                device.Dispose();
            }
            if (d3d != null)
            {
                d3d.Dispose();
            }

            if (ctx != null)
            {
                ctx.Dispose();
            }
        }
        public void RenderBezier(ViewportInfo viewportInfo)
        {
            pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.BackBufferWidth = viewportInfo.resX;
            pp.BackBufferHeight = viewportInfo.resY;
            pp.BackBufferFormat = Format.A8R8G8B8;

            d3dBezier = new Direct3D();

            deviceBezier = new Device(d3dBezier, 0, DeviceType.Hardware, handleBezier, CreateFlags.HardwareVertexProcessing, pp);

            deviceBezier.SetRenderState(RenderState.Lighting, true);

            deviceBezier.SetLight(0, defLight);
            deviceBezier.EnableLight(0, true);

            deviceBezier.SetRenderState(RenderState.FillMode, wireframe ? 2 : 0);
            deviceBezier.SetRenderState(RenderState.CullMode, 1);

            deviceBezier.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(230, 230, 230), 1.0f, 0);

            deviceBezier.Present();

            d3dBezier.Dispose();
            deviceBezier.Dispose();
        }