Beispiel #1
0
 protected virtual void OnBeforeDeviceCreation( DXCreateParametersEventArgs e )
 {
     if( BeforeDeviceCreation != null )
         BeforeDeviceCreation( this, e );
 }
Beispiel #2
0
        private void CreateDevice()
        {
            if( Site != null && Site.DesignMode )
                //don't unduly slow down the winforms designer
                return;

            if( !enable3D )
                return;

            if( ClientSize.Width == 0 ||
                ClientSize.Height == 0 )
                return;

            if( !IsHandleCreated )
                return;

            try
            {
                int adapter = SelectAdapter();
                Format adapterFormat = Manager.Adapters[adapter].CurrentDisplayMode.Format;

                PresentParameters pp = CreatePresentParameters( adapter, adapterFormat );

                DXCreateParametersEventArgs evArgs = new DXCreateParametersEventArgs( adapter, DeviceType.Hardware, adapterFormat, pp );
                OnBeforeDeviceCreation( evArgs );

                if( evArgs.CancelCreation )
                    return;

                Device.IsUsingEventHandlers = false; //wheee! a global control flag! WHY MICROSOFT WHY?!
                device = new Device( adapter, DeviceType.Hardware, this,
                    CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve, pp );
                devicePresentParams = (PresentParameters)pp.Clone();
                isLost = false;
            }
            catch( Exception e )
            {
                Text = string.Format( "Failed to create a device:\n{0}", e.Message );

                device = null;
                isLost = true;
            }

            if( device != null )
            {
                try
                {
                    OnDeviceCreated( EventArgs.Empty );
                }
                catch
                {
                    try
                    {
                        OnDeviceDestroyed( EventArgs.Empty );
                    }
                    finally
                    {
                        Helpers.DisposeAndClear( ref device );
                        isLost = true;
                    }
                    throw;
                }

                try
                {
                    OnDeviceReset( EventArgs.Empty );
                }
                catch
                {
                    try
                    {
                        OnDeviceLost( EventArgs.Empty );
                        OnDeviceDestroyed( EventArgs.Empty );
                    }
                    finally
                    {
                        Helpers.DisposeAndClear( ref device );
                        isLost = true;
                    }

                    throw;
                }
            }

            Invalidate();
        }
Beispiel #3
0
        private void pn3D_BeforeDeviceCreation( object sender, DXCreateParametersEventArgs e )
        {
            bool good = true;

            try
            {
                if( e.Caps.VertexShaderVersion < new Version( 2, 0 ) )
                {
                    good = false;
                    return;
                }

                if( e.Caps.PixelShaderVersion < new Version( 2, 0 ) )
                {
                    good = false;
                    return;
                }

                if( !Manager.CheckDeviceFormat( e.AdapterOrdinal, e.DeviceType,
                    e.DeviceFormat, Usage.RenderTarget, ResourceType.Textures,
                    Format.A32B32G32R32F ) )
                {
                    good = false;
                    return;
                }
            }
            finally
            {
                if( !good )
                {
                    pn3D.Text = "The 3D card connected to this monitor does not support the necessary render target format.";
                    e.CancelCreation = true;
                }
            }
        }