Example #1
0
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _effect.Dispose();
                    _vertDecl.Dispose();
                    _device.Dispose();
                    _presentParams.Dispose();
                }

                _handle = IntPtr.Zero;

                _disposed = true;
            }
        }
Example #2
0
        /// <summary>
        /// Set Default Hardware Adapter Targeting Current SLForm with Custom Settings
        /// </summary>
        /// <param name="buffercount">0-3</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="refreshrate">windowed mode(0), fullscreen mode(>0)</param>
        /// <param name="isvsync"></param>
        public void SetGraphicsDevice(int buffercount, int width, int height, int refreshrate, bool isvsync)
        {
            if (pp != null)
            {
                pp.Dispose();
            }
            pp = new PresentationParameters();

            // Check Shader Model 2.0 Support
            GraphicsDeviceCapabilities gdcap = GraphicsAdapter.DefaultAdapter.GetCapabilities(DeviceType.Hardware);

            if (gdcap.MaxPixelShaderProfile < ShaderProfile.PS_2_0 || gdcap.MaxVertexShaderProfile < ShaderProfile.VS_2_0)
            {
                MessageBox.Show("This Adapter Does Not Support Shader Model 2.0.", "Warning !");
            }

            // Check Full Screen MultiSampling Support
            int quality;

            if (GraphicsAdapter.DefaultAdapter.CheckDeviceMultiSampleType(DeviceType.Hardware, SurfaceFormat.Color, false, MultiSampleType.NonMaskable, out quality))
            {
                pp.MultiSampleType = MultiSampleType.NonMaskable;
                if (quality < 2)
                {
                    pp.MultiSampleQuality = quality;
                }
                else
                {
                    pp.MultiSampleQuality = 2;
                }
            }

            // Set Screen Presentation
            if (isvsync)
            {
                pp.PresentationInterval = PresentInterval.One;
            }
            else
            {
                pp.PresentationInterval = PresentInterval.Immediate;
            }
            if (refreshrate == 0)
            {
                pp.IsFullScreen = false;
                ClientSize      = new System.Drawing.Size(width, height);
            }
            else
            {
                pp.IsFullScreen = true;
            }
            pp.FullScreenRefreshRateInHz = refreshrate;

            // Set Buffer
            if (buffercount > 3)
            {
                buffercount = 3;
            }
            pp.BackBufferCount        = buffercount;
            pp.BackBufferWidth        = Math.Max(1, width);
            pp.BackBufferHeight       = Math.Max(1, height);
            pp.BackBufferFormat       = SurfaceFormat.Color;
            pp.EnableAutoDepthStencil = true;
            pp.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8;

            SetGraphicsDevice(pp);
        }