Example #1
0
        public static D3d.Device    CreateDevice(Settings deviceSettings,
                                                 System.Windows.Forms.Control renderWindow)
        {
            EnumerateAdapters();

            // First try full hardware acceleration.
            D3d.PresentParameters presentParams = deviceSettings.GetPresentParameters(renderWindow);
            D3d.CreateFlags       createFlags   = deviceSettings.GetCreateFlags(true, true);

            D3d.Device d3dDevice = CreateDevice(renderWindow, presentParams, createFlags, deviceSettings);

            if (d3dDevice == null)
            {
                log.Warning("Pure device not available.");
                createFlags = deviceSettings.GetCreateFlags(false, true);

                d3dDevice = CreateDevice(renderWindow, presentParams, createFlags, deviceSettings);

                if (d3dDevice == null)
                {
                    log.Warning("Hardware vertex processing not available.");
                    createFlags = deviceSettings.GetCreateFlags(false, false);

                    d3dDevice = CreateDevice(renderWindow, presentParams, createFlags, deviceSettings);
                }
            }

            return(d3dDevice);
        }
Example #2
0
        public D3d.PresentParameters    GetPresentParameters(System.Windows.Forms.Control renderWindow)
        {
            D3d.PresentParameters pp = new D3d.PresentParameters();

            pp.AutoDepthStencilFormat = depthBufferFormat;
            pp.BackBufferCount        = backBufferCount;
            pp.BackBufferFormat       = backBufferFormat;
            pp.Windowed                 = windowed;
            pp.DeviceWindow             = renderWindow;
            pp.EnableAutoDepthStencil   = true;
            pp.ForceNoMultiThreadedFlag = false;
            pp.MultiSample              = (D3d.MultiSampleType)multiSampleLevel;
            pp.MultiSampleQuality       = 0;

            pp.PresentationInterval = D3d.PresentInterval.Default;
            pp.PresentFlag          = D3d.PresentFlag.DiscardDepthStencil;
            pp.SwapEffect           = D3d.SwapEffect.Discard;

            if (windowed)
            {
                pp.BackBufferWidth           = 0;
                pp.BackBufferHeight          = 0;
                pp.FullScreenRefreshRateInHz = 0;
            }
            else
            {
                pp.BackBufferWidth           = fullScreenWidth;
                pp.BackBufferHeight          = fullScreenHeight;
                pp.FullScreenRefreshRateInHz = fullScreenRefresh;
            }

            return(pp);
        }
Example #3
0
        public Form1()
        {
            InitializeComponent();
            this.Text = GetUniqueKey(20);
            //Make the window's border completely transparant
            SetWindowLong(this.Handle, GWL_EXSTYLE,
                          (IntPtr)(GetWindowLong(this.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED ^ WS_EX_TRANSPARENT));

            //Set the Alpha on the Whole Window to 255 (solid)
            SetLayeredWindowAttributes(this.Handle, 0, 255, LWA_ALPHA);

            //Init DirectX
            //This initializes the DirectX device. It needs to be done once.
            //The alpha channel in the backbuffer is critical.
            D3D.PresentParameters presentParameters = new D3D.PresentParameters();
            presentParameters.Windowed         = true;
            presentParameters.SwapEffect       = D3D.SwapEffect.Discard;
            presentParameters.BackBufferFormat = D3D.Format.A8R8G8B8;

            this.device = new D3D.Device(0, D3D.DeviceType.Hardware, this.Handle,
                                         D3D.CreateFlags.HardwareVertexProcessing, presentParameters);

            line = new D3D.Line(this.device);
            font = new D3D.Font(device, new System.Drawing.Font("Tahoma", 9, FontStyle.Regular));

            Thread dx = new Thread(new ThreadStart(this.dxThread));

            dx.IsBackground = true;
            dx.Start();
        }
Example #4
0
        public D3d.PresentParameters GetPresentParameters(System.Windows.Forms.Control renderWindow)
        {
            D3d.PresentParameters pp            = new D3d.PresentParameters();

            pp.AutoDepthStencilFormat           = depthBufferFormat;
            pp.BackBufferCount                  = backBufferCount;
            pp.BackBufferFormat                 = backBufferFormat;
            pp.Windowed                         = windowed;
            pp.DeviceWindow                     = renderWindow;
            pp.EnableAutoDepthStencil           = true;
            pp.ForceNoMultiThreadedFlag         = false;
            pp.MultiSample                      = (D3d.MultiSampleType)multiSampleLevel;
            pp.MultiSampleQuality               = 0;

            pp.PresentationInterval             = D3d.PresentInterval.Default;
            pp.PresentFlag                      = D3d.PresentFlag.DiscardDepthStencil;
            pp.SwapEffect                       = D3d.SwapEffect.Discard;

            if (windowed)
            {
                pp.BackBufferWidth              = 0;
                pp.BackBufferHeight             = 0;
                pp.FullScreenRefreshRateInHz    = 0;
            }
            else
            {
                pp.BackBufferWidth              = fullScreenWidth;
                pp.BackBufferHeight             = fullScreenHeight;
                pp.FullScreenRefreshRateInHz    = fullScreenRefresh;
            }

            return pp;
        }
Example #5
0
        private static D3d.Device CreateDevice(System.Windows.Forms.Control renderWindow,
                                               D3d.PresentParameters presentParams,
                                               D3d.CreateFlags createFlags,
                                               Settings deviceSettings)
        {
            try
            {
                D3d.Device d3dDevice = new D3d.Device(deviceSettings.adapterIndex,
                                                      deviceSettings.deviceType,
                                                      renderWindow,
                                                      createFlags,
                                                      presentParams);
                return(d3dDevice);
            }
            catch (D3d.DeviceLostException e)
            {
                log.Warning("Unable to create Direct3D device: {0}", e.Message);
            }
            catch (D3d.InvalidCallException e)
            {
                log.Warning("Unable to create Direct3D device: {0}", e.Message);
            }
            catch (D3d.NotAvailableException e)
            {
                log.Warning("Unable to create Direct3D device: {0}", e.Message);
            }
            catch (D3d.OutOfVideoMemoryException e)
            {
                log.Warning("Unable to create Direct3D device: {0}", e.Message);
            }

            return(null);
        }
        public Form1()
        {
            InitializeComponent();
            this.Text = GetUniqueKey(20);
            //Make the window's border completely transparant
            SetWindowLong(this.Handle, GWL_EXSTYLE,
                    (IntPtr)(GetWindowLong(this.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED ^ WS_EX_TRANSPARENT));

            //Set the Alpha on the Whole Window to 255 (solid)
            SetLayeredWindowAttributes(this.Handle, 0, 255, LWA_ALPHA);

            //Init DirectX
            //This initializes the DirectX device. It needs to be done once.
            //The alpha channel in the backbuffer is critical.
            D3D.PresentParameters presentParameters = new D3D.PresentParameters();
            presentParameters.Windowed = true;
            presentParameters.SwapEffect = D3D.SwapEffect.Discard;
            presentParameters.BackBufferFormat = D3D.Format.A8R8G8B8;

            this.device = new D3D.Device(0, D3D.DeviceType.Hardware, this.Handle,
            D3D.CreateFlags.HardwareVertexProcessing, presentParameters);

            line = new D3D.Line(this.device);
            font = new D3D.Font(device, new System.Drawing.Font("Tahoma", 9, FontStyle.Regular));

            Thread dx = new Thread(new ThreadStart(this.dxThread));
            dx.IsBackground = true;
            dx.Start();
        }
Example #7
0
        void init()
        {
            Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters();
            pps.SwapEffect           = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
            pps.Windowed             = true;
            pps.BackBufferCount      = 1;
            pps.PresentationInterval = PresentInterval.One;
            pps.BackBufferFormat     = Format.A8R8G8B8;

            if (GameWindow == null)
            {
                //pps.BackBufferWidth = GameControl.Width;
                //pps.BackBufferHeight = GameControl.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            else
            {
                //pps.BackBufferWidth = GameWindow.Width;
                //pps.BackBufferHeight = GameWindow.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;


            //D3DDev.ShowCursor(false);

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            if (GameWindow == null)
            {
                DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }
            else
            {
                DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }

            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed);

            D3DDev.SetStreamSource(0, VertexBuffer, 0);
            D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            Sprite = new Sprite(D3DDev);

            FontDescription fd = new FontDescription();

            fd.FaceName = "新宋体";
            fd.Height   = -12;
            Font2D      = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd);

            Font3D = new System.Drawing.Font("新宋体", 12);
        }
Example #8
0
        void init()
        {
            Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters();
            pps.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
            pps.Windowed = true;
            pps.BackBufferCount = 1;
            pps.PresentationInterval = PresentInterval.One;
            pps.BackBufferFormat = Format.A8R8G8B8;

            if (GameWindow == null)
            {
                //pps.BackBufferWidth = GameControl.Width;
                //pps.BackBufferHeight = GameControl.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            else
            {
                //pps.BackBufferWidth = GameWindow.Width;
                //pps.BackBufferHeight = GameWindow.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;

            //D3DDev.ShowCursor(false);

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            if (GameWindow == null)
            {
                DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }
            else
            {
                DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }

            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed);

            D3DDev.SetStreamSource(0, VertexBuffer, 0);
            D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            Sprite = new Sprite(D3DDev);

            FontDescription fd = new FontDescription();
            fd.FaceName = "新宋体";
            fd.Height = -12;
            Font2D = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd);

            Font3D = new System.Drawing.Font("新宋体", 12);
        }
Example #9
0
        public void InitD3D()
        {
            var d3dpp = new Direct3D.PresentParameters();

            d3dpp.BackBufferFormat     = Direct3D.Format.Unknown;
            d3dpp.BackBufferCount      = 2;
            d3dpp.Windowed             = true;
            d3dpp.SwapEffect           = Direct3D.SwapEffect.Discard;
            d3dpp.DeviceWindow         = this;
            d3dpp.PresentationInterval = Direct3D.PresentInterval.Default;

            m_d3DDevice = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.HardwareVertexProcessing | Direct3D.CreateFlags.MultiThreaded, d3dpp);

            unsafe
            {
                m_previewHelper.Initialize(new IntPtr(m_d3DDevice.UnmanagedComPointer));
            }
        }
Example #10
0
 public bool IniDirect3D()
 {
     try {
         Direct3D.PresentParameters pps = new Direct3D.PresentParameters();
         pps.Windowed   = true;
         pps.SwapEffect = Direct3D.SwapEffect.Discard;
         DXDevice       = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
         DXDevice.RenderState.Lighting = false;
         if (wireFrame)
         {
             DXDevice.RenderState.FillMode = Direct3D.FillMode.WireFrame;
         }
         return(true);
     }
     catch (DirectXException dxe) {
         MessageBox.Show(dxe.ToString());
         return(false);
     }
 }
Example #11
0
        public void InitDevice(D3D.DeviceType forcedDevice, D3D.CreateFlags forcedFlags)
        {
            if (this._dev != null)
            {
                this.Dispose(true);
            }

            try
            {
                D3D.PresentParameters pprms = new Microsoft.DirectX.Direct3D.PresentParameters();
                pprms.Windowed = this._pprmWindowed;
                if (!this._pprmWindowed)
                {
                    pprms.BackBufferWidth           = this._pprmBkBfrW;
                    pprms.BackBufferHeight          = this._pprmBkBfrH;
                    pprms.BackBufferFormat          = this._pprmBkBfrFmt;
                    pprms.FullScreenRefreshRateInHz = this._pprmRefreshRt;
                }
                pprms.AutoDepthStencilFormat = this._pprmDepthStencilFormat;
                pprms.SwapEffect             = this._pprmSwapEffect;
                pprms.PresentationInterval   = this._pprmIntvl;
                pprms.PresentFlag            = this._pprmPrsFlg;
                pprms.MultiSample            = this._pprmMsType;
                pprms.MultiSampleQuality     = 0;
                pprms.BackBufferCount        = this._pprmBkBfrCnt;

                this._dev                 = new D3D.Device(this._adpNum, forcedDevice, this._hWnd, forcedFlags, pprms);
                this._dev.DeviceReset    += new EventHandler(this.dev_onDeviceReset);
                this._dev.DeviceLost     += new EventHandler(this.dev_onDeviceLost);
                this._dev.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.dev_onDeviceResizing);
                this._disposed            = false;
            }
            catch
            {
                throw;
            }
        }
Example #12
0
 public PresentParameters(PresentParameters original)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Initializes the Managed Direct3D Wrapper.
        /// 
        /// This overload is designed for displaying a diferent resolution then the controls size.
        /// </summary>
        /// <param name="renderWindow">Window to render to.</param>
        /// <param name="screenWidth">Width of the screen in pixels.</param>
        /// <param name="screenHeight">Height of the screen in pixels.</param>
        /// <param name="vsync">Should the renderer wait for a vsync before drawing?</param>
        /// <returns>true if successful, false otherwise.</returns>
        public bool InitManagedDirect3D(System.Windows.Forms.Control renderWindow, int screenWidth, int screenHeight, bool vsync)
        {
            try
            {
                // Now  setup our D3D present parameters
                presentParams = new PresentParameters();
                presentParams.BackBufferWidth = screenWidth;
                presentParams.BackBufferHeight = screenHeight;
                //taking out the option for fullscreen mode
                //presentParams.BackBufferFormat = (isWindowed) ? Format.Unknown : Format.R5G6B5;
                presentParams.BackBufferFormat = Format.Unknown;
                presentParams.BackBufferCount = 1;
                presentParams.MultiSample = MultiSampleType.None;
                presentParams.MultiSampleQuality = 0;
                presentParams.SwapEffect = SwapEffect.Copy;// Discard;
                presentParams.DeviceWindow = renderWindow;
                //taking out the option for fullscreen mode
                //presentParams.Windowed = isWindowed;
                presentParams.Windowed = true;
                presentParams.EnableAutoDepthStencil = false;
                presentParams.FullScreenRefreshRateInHz = 0;
                presentParams.PresentationInterval = (vsync) ? PresentInterval.Default : PresentInterval.Immediate;

                // only Create if we haven't done so already
                if(device == null)
                device = new Device(0, DeviceType.Hardware, renderWindow,
                        CreateFlags.HardwareVertexProcessing, presentParams);

                //Create the SwapChain
            lSwapChains.Add(new ManagedSwapChain(device, presentParams));
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create D3D Device", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return false;
            }

            try
            {
                sprite = new Microsoft.DirectX.Direct3D.Sprite(device);
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create the Sprite object", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return false;
            }

            try
            {
                line = new Microsoft.DirectX.Direct3D.Line(device);

                line.Antialias = true;
                line.Width = 3.0f;
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create the Line Object", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return false;
            }

            try
            {
                fontDescription.FaceName = "arial";
                fontDescription.Quality = FontQuality.Default;
                fontDescription.Weight = FontWeight.Bold;

                font = new Microsoft.DirectX.Direct3D.Font(device, fontDescription);

                line.Antialias = true;
                line.Width = 3.0f;
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create the font Object", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return false;
            }

            return true;
        }
        /// <summary>
        /// Changes the display parameters of the Managed Direct3D Wrapper.
        /// 
        /// Use this to change what window you render to.
        /// This overload is designed for displaying a diferent resolution size then the controls size
        /// </summary>
        /// <param name="renderWindow">Window to render to.</param>
        /// <param name="screenWidth">Width of the screen in pixels.</param>
        /// <param name="screenHeight">Height of the screen in pixels.</param>
        /// <param name="vsync">Should the renderer wait for a vsync before drawing?</param>
        /// <returns>true if successful, false otherwise.</returns>
        public bool ChangeDisplayParam(System.Windows.Forms.Control renderWindow, int screenWidth, int screenHeight, bool vsync)
        {
            try
            {
                // Now  setup our D3D present parameters
                presentParams = new PresentParameters();
                presentParams.BackBufferWidth = screenWidth;
                presentParams.BackBufferHeight = screenHeight;
                // taking out option for fullscreen mode
                //presentParams.BackBufferFormat = (isWindowed) ? Format.Unknown : Format.R5G6B5;
                presentParams.BackBufferFormat = Format.Unknown;
                presentParams.BackBufferCount = 1;
                presentParams.MultiSample = MultiSampleType.None;
                presentParams.MultiSampleQuality = 0;
                presentParams.SwapEffect = SwapEffect.Copy;// Discard;
                presentParams.DeviceWindow = renderWindow;
                // taking out option for fullscreen mode
                //presentParams.Windowed = isWindowed;
                presentParams.Windowed = true;
                presentParams.EnableAutoDepthStencil = false;
                presentParams.FullScreenRefreshRateInHz = 0;
                presentParams.PresentationInterval = (vsync) ? PresentInterval.Default : PresentInterval.Immediate;

                // Find the swap chain
                SetActiveSwapChain(renderWindow);

                font.OnLostDevice();
                line.OnLostDevice();
                sprite.OnLostDevice();
                device.Reset(presentParams);
                sprite.OnResetDevice();
                line.OnResetDevice();
                font.OnResetDevice();

                lSwapChains[ActiveChain].Reset(device, presentParams);
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to change the render window", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return false;
            }

            return true;
        }
Example #15
0
        private void InitDirect3D()
        {
            Direct3D.PresentParameters presentParams;
            presentParams = new Direct3D.PresentParameters();

            presentParams.Windowed               = windowed;
            presentParams.EnableAutoDepthStencil = true;
            presentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16;

            if(windowed)
            {
                presentParams.SwapEffect = Direct3D.SwapEffect.Copy;
            }
            else
            {
                presentParams.SwapEffect       = Direct3D.SwapEffect.Flip;
                presentParams.BackBufferFormat = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Format;
                presentParams.BackBufferWidth  = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Width;
                presentParams.BackBufferHeight = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Height;
                presentParams.FullScreenRefreshRateInHz = Direct3D.PresentParameters.DefaultPresentRate;
                presentParams.PresentationInterval      = Direct3D.PresentInterval.One;
            }

            Direct3D.DeviceType deviceType = Direct3D.DeviceType.Hardware;

            // If the hardware doesn't support shaders, emulate them with the reference rasterizer
            Direct3D.Caps caps = Direct3D.Manager.GetDeviceCaps(0, Direct3D.DeviceType.Hardware);
            if(caps.VertexShaderVersion < new System.Version(1, 1) || caps.PixelShaderVersion < new System.Version(1, 1))
            {
                string msg = "The hardware does not support the required shader version (VS " + caps.VertexShaderVersion.ToString() + " PS " + caps.PixelShaderVersion.ToString() + "). Switching to the Reference Rasterizer.";
                System.Windows.Forms.MessageBox.Show(null,
                                                     msg,
                                                     "Shaders unsupported");
                deviceType = Direct3D.DeviceType.Reference;
            }

            device = new Direct3D.Device(0,
                                         deviceType,
                                         this,
                                         Direct3D.CreateFlags.SoftwareVertexProcessing,
                                         presentParams);

            device.DeviceReset += new System.EventHandler(this.OnDeviceReset);

            Direct3D.ShaderFlags shaderFlags = Direct3D.ShaderFlags.None;
            #if (DEBUG)
            shaderFlags |= Direct3D.ShaderFlags.Debug;
            #endif

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream stream;

            Direct3D.GraphicsStream gs;
            stream = assembly.GetManifestResourceStream("_6_ShaderAsm.VertexShader.vsh");
            gs = Direct3D.ShaderLoader.FromStream(stream, null, shaderFlags);
            vertexShader = new Direct3D.VertexShader(device, gs);
            gs.Close();
            stream.Close();

            stream = assembly.GetManifestResourceStream("_6_ShaderAsm.PixelShader.psh");
            gs = Direct3D.ShaderLoader.FromStream(stream, null, shaderFlags);
            pixelShader = new Direct3D.PixelShader(device, gs);
            gs.Close();
            stream.Close();

            Direct3D.VertexElement[] decl = new Direct3D.VertexElement[] { new Direct3D.VertexElement(0,  0, Direct3D.DeclarationType.Float3, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Position, 0),
                                                                           new Direct3D.VertexElement(0, 12, Direct3D.DeclarationType.Color,  Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Color, 0),
                                                                           new Direct3D.VertexElement(0, 16, Direct3D.DeclarationType.Float2, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.TextureCoordinate, 0),
                                                                           Direct3D.VertexElement.VertexDeclarationEnd };
            device.VertexDeclaration = new Direct3D.VertexDeclaration(device, decl);

            OnDeviceReset(device, null);
        }
Example #16
0
        private void InitDirect3D()
        {
            Direct3D.PresentParameters presentParams;
            presentParams = new Direct3D.PresentParameters();

            presentParams.Windowed = windowed;
            if(windowed)
            {
                presentParams.SwapEffect = Direct3D.SwapEffect.Copy;
            }
            else
            {
                presentParams.SwapEffect       = Direct3D.SwapEffect.Flip;
                presentParams.BackBufferFormat = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Format;
                presentParams.BackBufferWidth  = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Width;
                presentParams.BackBufferHeight = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Height;
                presentParams.FullScreenRefreshRateInHz = Direct3D.PresentParameters.DefaultPresentRate;
                presentParams.PresentationInterval      = Direct3D.PresentInterval.One;
            }

            device = new Direct3D.Device(0,
                                         Direct3D.DeviceType.Hardware,
                                         this,
                                         Direct3D.CreateFlags.SoftwareVertexProcessing,
                                         presentParams);
        }
Example #17
0
 public SwapChain(Device device, PresentParameters presentationParameters)
 {
     throw new NotImplementedException();
 }
Example #18
0
        private void InitDirect3D()
        {
            Direct3D.PresentParameters presentParams;
            presentParams = new Direct3D.PresentParameters();

            presentParams.Windowed               = windowed;
            presentParams.EnableAutoDepthStencil = true;
            presentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16;

            if(windowed)
            {
                presentParams.SwapEffect = Direct3D.SwapEffect.Copy;
            }
            else
            {
                presentParams.SwapEffect       = Direct3D.SwapEffect.Flip;
                presentParams.BackBufferFormat = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Format;
                presentParams.BackBufferWidth  = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Width;
                presentParams.BackBufferHeight = Direct3D.Manager.Adapters.Default.CurrentDisplayMode.Height;
                presentParams.FullScreenRefreshRateInHz = Direct3D.PresentParameters.DefaultPresentRate;
                presentParams.PresentationInterval      = Direct3D.PresentInterval.One;
            }

            device = new Direct3D.Device(0,
                                         Direct3D.DeviceType.Hardware,
                                         this,
                                         Direct3D.CreateFlags.SoftwareVertexProcessing,
                                         presentParams);

            device.DeviceReset += new System.EventHandler(this.OnDeviceReset);

            OnDeviceReset(device, null);
        }
Example #19
0
        /// <summary>
        /// Initializes the Managed Direct3D Wrapper.
        /// </summary>
        /// <param name="renderWindow">Window to render to.</param>
        /// <param name="screenWidth">Width of the screen in pixels.</param>
        /// <param name="screenHeight">Height of the screen in pixels.</param>
        /// <param name="isWindowed">Is the application windowed or not (!!ALWAYS PASS true FOR NOW!!).</param>
        /// <param name="vsync">Should the renderer wait for a vsync before drawing?</param>
        /// <returns>true if successful, false otherwise.</returns>
        public bool InitManagedDirect3D(System.Windows.Forms.Control renderWindow, int screenWidth, int screenHeight, bool isWindowed, bool vsync)
        {
            try
            {
                // Now  setup our D3D present parameters
                presentParams = new PresentParameters();
                presentParams.BackBufferWidth           = screenWidth;
                presentParams.BackBufferHeight          = screenHeight;
                presentParams.BackBufferFormat          = (isWindowed) ? Format.Unknown : Format.R5G6B5;
                presentParams.BackBufferCount           = 1;
                presentParams.MultiSample               = MultiSampleType.None;
                presentParams.MultiSampleQuality        = 0;
                presentParams.SwapEffect                = SwapEffect.Copy;// Discard;
                presentParams.DeviceWindow              = renderWindow;
                presentParams.Windowed                  = isWindowed;
                presentParams.EnableAutoDepthStencil    = false;
                presentParams.FullScreenRefreshRateInHz = 0;
                presentParams.PresentationInterval      = (vsync) ? PresentInterval.Default : PresentInterval.Immediate;

                device = new Device(0, DeviceType.Hardware, renderWindow,
                                    CreateFlags.HardwareVertexProcessing, presentParams);
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create D3D Device", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return(false);
            }

            try
            {
                sprite = new Microsoft.DirectX.Direct3D.Sprite(device);
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create the Sprite object", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return(false);
            }

            try
            {
                line = new Microsoft.DirectX.Direct3D.Line(device);

                line.Antialias = true;
                line.Width     = 3.0f;
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create the Line Object", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return(false);
            }

            try
            {
                fontDescription.FaceName = "arial";
                fontDescription.Quality  = FontQuality.Default;
                fontDescription.Weight   = FontWeight.Bold;

                font = new Microsoft.DirectX.Direct3D.Font(device, fontDescription);

                line.Antialias = true;
                line.Width     = 3.0f;
            }
            catch (Exception)
            {
                DialogResult r = MessageBox.Show("Failed to Create the font Object", "ManagedDirect3D::Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return(false);
            }

            return(true);
        }
Example #20
0
        public void InitDevice(D3D.DeviceType forcedDevice, D3D.CreateFlags forcedFlags)
        {
            if (this._dev != null)
                this.Dispose(true);

            try
            {
                D3D.PresentParameters pprms = new Microsoft.DirectX.Direct3D.PresentParameters();
                pprms.Windowed = this._pprmWindowed;
                if (!this._pprmWindowed)
                {
                    pprms.BackBufferWidth = this._pprmBkBfrW;
                    pprms.BackBufferHeight = this._pprmBkBfrH;
                    pprms.BackBufferFormat = this._pprmBkBfrFmt;
                    pprms.FullScreenRefreshRateInHz = this._pprmRefreshRt;
                }
                pprms.AutoDepthStencilFormat = this._pprmDepthStencilFormat;
                pprms.SwapEffect = this._pprmSwapEffect;
                pprms.PresentationInterval = this._pprmIntvl;
                pprms.PresentFlag = this._pprmPrsFlg;
                pprms.MultiSample = this._pprmMsType;
                pprms.MultiSampleQuality = 0;
                pprms.BackBufferCount = this._pprmBkBfrCnt;

                this._dev = new D3D.Device(this._adpNum, forcedDevice, this._hWnd, forcedFlags, pprms);
                this._dev.DeviceReset += new EventHandler(this.dev_onDeviceReset);
                this._dev.DeviceLost += new EventHandler(this.dev_onDeviceLost);
                this._dev.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.dev_onDeviceResizing);
                this._disposed = false;
            }
            catch
            {
                throw;
            }
        }
Example #21
0
        /// <summary>
        /// Initializes the display parameters and creates the game objects.
        /// </summary>
        private void InitializeGraphics()
        {
            D3D.PresentParameters pres = new D3D.PresentParameters();
            pres.Windowed = true;
            pres.SwapEffect = D3D.SwapEffect.Discard;
            pres.EnableAutoDepthStencil = true;
            pres.AutoDepthStencilFormat = D3D.DepthFormat.D16;

            device = new D3D.Device(0, D3D.DeviceType.Hardware, this, D3D.CreateFlags.SoftwareVertexProcessing, pres);
            device.RenderState.CullMode = D3D.Cull.None;

            ContentLoader.initialize(device);
        }
Example #22
0
        public ScreenAccess()
        {
            try
            {
                Direct3D.PresentParameters presentParams = new Direct3D.PresentParameters();
                presentParams.Windowed               = true;
                presentParams.SwapEffect             = Direct3D.SwapEffect.Discard;
                presentParams.EnableAutoDepthStencil = true;
                presentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16;

                Direct3D.Caps        hardware = Direct3D.Manager.GetDeviceCaps(0, Direct3D.DeviceType.Hardware);
                Direct3D.CreateFlags flags    = Direct3D.CreateFlags.SoftwareVertexProcessing;

                // Search for the highest possible shader support and define the device.
                if (hardware.VertexShaderVersion >= new Version(2, 0))
                {
                    if (hardware.DeviceCaps.SupportsHardwareTransformAndLight)
                    {
                        flags = Direct3D.CreateFlags.HardwareVertexProcessing;
                    }

                    if (hardware.DeviceCaps.SupportsPureDevice)
                    {
                        flags |= Direct3D.CreateFlags.PureDevice;
                    }

                    if (hardware.PixelShaderVersion >= new Version(3, 0))
                    {
                        CardShader = GameEngine.ShaderLevel.Pixel_3_0;
                    }
                    else if (hardware.PixelShaderVersion >= new Version(2, 2))
                    {
                        CardShader = GameEngine.ShaderLevel.Pixel_2_b;
                    }
                    else if (hardware.PixelShaderVersion >= new Version(2, 0))
                    {
                        CardShader = GameEngine.ShaderLevel.Pixel_2_0;
                    }
                    else if (hardware.PixelShaderVersion >= new Version(1, 4))
                    {
                        CardShader = GameEngine.ShaderLevel.Pixel_1_4;
                    }
                    else
                    {
                        CardShader = GameEngine.ShaderLevel.NoShaders;
                    }

                    device = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, flags, presentParams);
                }
                else if (hardware.VertexShaderVersion >= new Version(1, 1))
                {
                    if (hardware.DeviceCaps.SupportsHardwareTransformAndLight)
                    {
                        flags = Direct3D.CreateFlags.HardwareVertexProcessing;
                    }

                    if (hardware.DeviceCaps.SupportsPureDevice)
                    {
                        flags |= Direct3D.CreateFlags.PureDevice;
                    }

                    if (hardware.PixelShaderVersion >= new Version(1, 4))
                    {
                        CardShader = GameEngine.ShaderLevel.Pixel_1_4;
                    }
                    else
                    {
                        CardShader = GameEngine.ShaderLevel.NoShaders;
                    }

                    device = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, flags, presentParams);
                }
                //TODO: test this on shit cards and fake cards to see if they can use DeviceType.Hardware
                else
                {
                    CardShader = GameEngine.ShaderLevel.NoShaders;
                    device     = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this,
                                                     Direct3D.CreateFlags.SoftwareVertexProcessing, presentParams);
                }

                //Setup Alpha Blending
                this.device.RenderState.AlphaBlendOperation = Direct3D.BlendOperation.Add;
                this.device.RenderState.AlphaTestEnable     = true;
                this.device.RenderState.ReferenceAlpha      = 0x08;
                this.device.RenderState.AlphaFunction       = Direct3D.Compare.GreaterEqual;

                this.device.SetTextureStageState(0, Direct3D.TextureStageStates.AlphaOperation, true);

                //Get the best texture filtering available from the card
                if (this.device.DeviceCaps.TextureFilterCaps.SupportsMinifyAnisotropic == true &&
                    this.device.DeviceCaps.TextureFilterCaps.SupportsMagnifyAnisotropic == true)
                {
                    this.PreferedTextureFilter = Direct3D.TextureFilter.Anisotropic;
                }
                else if (this.device.DeviceCaps.TextureFilterCaps.SupportsMinifyLinear == true &&
                         this.device.DeviceCaps.TextureFilterCaps.SupportsMagnifyLinear == true)
                {
                    this.PreferedTextureFilter = Direct3D.TextureFilter.Linear;
                }
                else
                {
                    this.PreferedTextureFilter = Direct3D.TextureFilter.None;
                }

                //Add window events to hardware screen device
                this.DeligateEventsToDevices();
            }
            catch (Exception err)
            {
                throw new Exception(err.StackTrace);
            }
        }