Exemplo n.º 1
0
        public D3DDevice(IntPtr windowPtr, bool bWindowed, long Width, long Height)
        {
            m_bWindowed = bWindowed;
            m_Format = Find16BitMode();

            PresentParameters presentParameters		 = new PresentParameters();
            presentParameters.Windowed				 = m_bWindowed;
            presentParameters.SwapEffect			 = SwapEffect.Discard;
            presentParameters.BackBufferCount		 = 1;
            presentParameters.PresentationInterval	 = PresentInterval.Immediate;
            presentParameters.AutoDepthStencilFormat = DepthFormat.D16;
            presentParameters.EnableAutoDepthStencil = true;

            if(!bWindowed)
            {
                presentParameters.BackBufferFormat	= m_Format;
                presentParameters.BackBufferWidth	= (int)Width;
                presentParameters.BackBufferHeight	= (int)Height;
            }
            else
            {
                presentParameters.BackBufferFormat	= Format.Unknown;
                presentParameters.BackBufferWidth	= (int)Width;
                presentParameters.BackBufferHeight	= (int)Height;
            }

            m_D3DDevice = new Microsoft.DirectX.Direct3D.Device(0,
                DeviceType.Hardware, windowPtr,
                CreateFlags.SoftwareVertexProcessing, presentParameters);
        }
Exemplo n.º 2
0
        public bool InitializeDirect3D()
        {
            try
            {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed = true; //指定以Windows窗体形式显示
                presentParams.SwapEffect = SwapEffect.Discard; //当前屏幕绘制后它将自动从内存中删除
                presentParams.BackBufferFormat = Format.Unknown;
                presentParams.BackBufferHeight = mImageRect.Height;
                presentParams.BackBufferWidth = mImageRect.Width;
                presentParams.BackBufferCount = 1;
                presentParams.PresentFlag = PresentFlag.LockableBackBuffer;

                dxForm = new Form();   //仅供创建device用,不会在其表面绘图
                dxDevice = new Device(0, DeviceType.Hardware, dxForm,
                    CreateFlags.HardwareVertexProcessing | CreateFlags.MultiThreaded | CreateFlags.FpuPreserve, presentParams); //实例化device对象
                
                dxSurface = dxDevice.GetBackBuffer(0, 0, BackBufferType.Mono);

                return true;
            }
            catch (DirectXException )
            {
                return false;
            }
        }
Exemplo n.º 3
0
        private static Device CreateDevice()
        {
            var presentParameters = new PresentParameters()
            {
                Windowed = true,
                SwapEffect = SwapEffect.Discard,
                BackBufferFormat = Format.Unknown,
                AutoDepthStencilFormat = DepthFormat.D16,
                EnableAutoDepthStencil = true
            };

            var deviceCaps = Manager.GetDeviceCaps(Manager.Adapters.Default.Adapter, DeviceType.Hardware).DeviceCaps;
            var createFlags = ((deviceCaps.SupportsHardwareTransformAndLight) 
                ? CreateFlags.HardwareVertexProcessing 
                : CreateFlags.SoftwareVertexProcessing);
            if (deviceCaps.SupportsPureDevice)
                createFlags |= CreateFlags.PureDevice;

            var device = new Device(0, DeviceType.Hardware, RenderForm, createFlags, presentParameters);
            device.RenderState.CullMode = Cull.None;
            device.RenderState.Lighting = false;

            device.DeviceReset += (sender, e) => 
            {
                System.Diagnostics.Debug.WriteLine("DeviceReset");
                var d = (Device)sender;
                d.RenderState.CullMode = Cull.None;
                d.RenderState.Lighting = false;
            };
            device.DeviceLost += (sender, e) => { System.Diagnostics.Debug.WriteLine("DeviceLost"); };
            device.DeviceResizing += (sender, e) => { System.Diagnostics.Debug.WriteLine("DeviceResizing"); };
            
            return device;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        public void InitializeGraphics()
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = DepthFormat.D16;
            presentParams.EnableAutoDepthStencil = true;

            // Create our device
            this.dxDevice = new Device(0, DeviceType.Hardware, this.Handle, CreateFlags.SoftwareVertexProcessing, presentParams);
            this.dxDevice.RenderState.ZBufferEnable = true;
            this.dxDevice.RenderState.ZBufferFunction = Compare.LessEqual;
            this.dxDevice.RenderState.MultiSampleAntiAlias = true;

            this.vtrOrigin[0] = new Vector3(-1.0f * this.fOriginBounds, 0, 0);
            this.vtrOrigin[1] = new Vector3(this.fOriginBounds, 0, 0);
            this.vtrOrigin[2] = new Vector3(0, 0, 0);
            this.vtrOrigin[3] = new Vector3(0, -1.0f * this.fOriginBounds, 0);
            this.vtrOrigin[4] = new Vector3(0, this.fOriginBounds, 0);
            this.vtrOrigin[5] = new Vector3(0, 0, 0);
            this.vtrOrigin[6] = new Vector3(0, 0, -1.0f * this.fOriginBounds);
            this.vtrOrigin[7] = new Vector3(0, 0, this.fOriginBounds);

            this.boxMesh = Mesh.Box(this.dxDevice, 4, 0.7f, 6); //change to robot model :-)
            this.boxMaterial = new Material();
            this.boxMaterial.Emissive = Color.DarkOliveGreen;
            this.boxMaterial.Ambient = Color.WhiteSmoke;
            this.boxMaterial.Diffuse = Color.WhiteSmoke;
        }
Exemplo n.º 5
0
 public void InitializeDevice()
 {
     PresentParameters presentParameters = new PresentParameters();
     presentParameters.Windowed = true;
     presentParameters.SwapEffect = SwapEffect.Discard;
     Device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParameters);
 }
Exemplo n.º 6
0
 public void InitializeGraphics()
 {
     try
     {
         PresentParameters presentParams = new PresentParameters();
         presentParams.Windowed = true;
         presentParams.SwapEffect = SwapEffect.Discard;
         DirectXGraphicsCard = new Device(0,
             DeviceType.Hardware,
             this,
             CreateFlags.HardwareVertexProcessing,
             presentParams);
         // Create a new Event Handler which is triggered if somebody resizes the window or something
         DirectXGraphicsCard.DeviceReset += new System.EventHandler(this.OnResetDevice);
         // Currently nobody is resizing any windows so the trigger is set to off
         OnResetDevice(DirectXGraphicsCard, null);
     }
     catch (DirectXException e)
     {
         MessageBox.Show(null,
             "Error intializing graphics: "
             + e.Message, "Error");
         Close();
     }
 }
Exemplo n.º 7
0
 public DxScreenCapture()
 {
     PresentParameters present_params = new PresentParameters();
     present_params.Windowed = true;
     present_params.SwapEffect = SwapEffect.Discard;
     d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
 }
Exemplo n.º 8
0
        public Controller(Control target, Renderer renderer, 
            Size size, EventHandler progressReport)
        {
            _target = target;
            _renderer = renderer;
            _size = size;
            _deviceLost = false;
            _presentParameters = new PresentParameters();
            _timer = new PerformanceTimer();

            InitializeGraphics(progressReport);
            OnDeviceReset(_device, null);

            if (progressReport != null)
            {
                progressReport(this, EventArgs.Empty);
            }

            CreateGraphicObjects(progressReport);

            _timer.Start();
            _elapsedTime = _timer.GetTime();
            _previousElapsedTime = _elapsedTime;

            if (progressReport != null)
            {
                progressReport(this, EventArgs.Empty);
            }
        }
Exemplo n.º 9
0
        public static void Initialize(System.Windows.Forms.Form OurForm)
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.SwapEffect = SwapEffect.Discard;
            Format current = Manager.Adapters[0].CurrentDisplayMode.Format;
            if (Screen.ScreenType == ScreenMode.fullscreen)
            {
                presentParams.Windowed = false;
                presentParams.BackBufferFormat = current;
                presentParams.BackBufferCount = 1;
                presentParams.BackBufferWidth = Screen.ResolutionW;
                presentParams.BackBufferHeight = Screen.ResolutionH;
            }
            else
            {
                presentParams.Windowed = true;
                OurForm.Size = new Size(Screen.ResolutionW, Screen.ResolutionH);
            }
            //presentParams.EnableAutoDepthStencil = true;
            //presentParams.AutoDepthStencilFormat = DepthFormat.D16;

            OurDevice = new Microsoft.DirectX.Direct3D.Device(0, DeviceType.Hardware, OurForm, CreateFlags.SoftwareVertexProcessing, presentParams);
            OurDevice.RenderState.AlphaBlendEnable = true;
            OurDevice.RenderState.SourceBlend = Blend.SourceAlpha;
            OurDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;
            OurSprite = new Sprite(OurDevice);
            MeshRenderer.Initialize(OurDevice);
            TextRenderer.Initialize(OurDevice);
        }
Exemplo n.º 10
0
        // Init the Managed Direct3D Device
        public void InitializeGraphics()
        {
            presentParams = new PresentParameters();

              // This sample is only windowed
              presentParams.Windowed = true;

              // Enable Z-Buffer
              // This is not really needed in this sample but real applications generaly use it
              presentParams.EnableAutoDepthStencil = true;
              presentParams.AutoDepthStencilFormat = DepthFormat.D16;

              // Hint to the Device Driver : This is a video playing application
              presentParams.PresentFlag = PresentFlag.Video;

              // How to swap backbuffer in front and how many frames per screen refresh
              presentParams.SwapEffect = SwapEffect.Discard;
              presentParams.PresentationInterval = PresentInterval.One;

              // Disable Managed Direct3D events
              Device.IsUsingEventHandlers = false;

              // Create the device
              device = new Device(
            Manager.Adapters.Default.Adapter,
            DeviceType.Hardware,
            this,
            CreateFlags.SoftwareVertexProcessing | CreateFlags.MultiThreaded,
            presentParams
            );

              AllocateResources();
              InitializeDevice();
        }
Exemplo n.º 11
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            FileSystem.Instance.AddWorkingDir(@".\");
            FileSystem.Instance.AddWorkingDir(@"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug");
            FileSystem.Instance.AddWorkingDir(@"F:\ic10gd\Source\Code2015\bin\x86\Debug");
            // zou jia's res dir
            FileSystem.Instance.AddWorkingDir(@"D:\zonelink2");

            PluginManager.Initiailze(null, null);

            DeviceContent dc = GraphicsAPIManager.Instance.CreateDeviceContent();

            PresentParameters pm2 = new PresentParameters();
            pm2.IsWindowed = true;
            pm2.BackBufferFormat = ImagePixelFormat.A8R8G8B8;
            pm2.BackBufferHeight = 600;
            pm2.BackBufferWidth = 800;

            RenderWindow wnd = (RenderWindow)dc.Create(pm2);
            Viewer = new RenderViewer(dc.RenderSystem);
            wnd.EventHandler = Viewer;
            Window = wnd;
            MainForm frm = new MainForm(dc.RenderSystem);
            frm.Show();
            
            wnd.Run();
        }
Exemplo n.º 12
0
        public D3dManager(Form i_main_window, NyARParam i_nyparam, int i_profile_id)
        {
            PresentParameters pp = new PresentParameters();
            // ウインドウモードなら true、フルスクリーンモードなら false を指定
            pp.Windowed = true;
            // スワップとりあえずDiscardを指定。
            pp.SwapEffect = SwapEffect.Discard;
            pp.EnableAutoDepthStencil = true;
            pp.AutoDepthStencilFormat = DepthFormat.D16;
            pp.BackBufferCount = 0;
            pp.BackBufferFormat = Format.R5G6B5;
            this._d3d_device = new Device(0, DeviceType.Default, i_main_window.Handle, CreateFlags.None, pp);

            //ビューポートを指定
            float scale = setupView(i_nyparam,i_main_window.ClientSize);
            this._scale = scale;
            // ライトを無効
            this._d3d_device.RenderState.Lighting = false;

            //カメラ画像の転写矩形を作成
            Viewport vp=this._d3d_device.Viewport;
            this._view_rect = new Rectangle(vp.X, vp.Y, vp.Width, vp.Height);

            NyARIntSize cap_size = i_nyparam.getScreenSize();
            this._background_size = new Size(cap_size.w, cap_size.h);
            return;
        }
Exemplo n.º 13
0
        static RenderWindow CreateRenderWindow()
        {
            //GraphicsAPIManager.Instance.RegisterGraphicsAPI(new Apoc3D.RenderSystem.Xna.XnaGraphicsAPIFactory());
            devContent = GraphicsAPIManager.Instance.CreateDeviceContent();

            PresentParameters pm = new PresentParameters();
            
            pm.BackBufferFormat = ImagePixelFormat.A8R8G8B8;
            pm.BackBufferWidth = ScreenWidth;
            pm.BackBufferHeight = ScreenHeight;
            pm.IsWindowed = true;
            pm.DepthFormat = DepthFormat.Depth32;            

            RenderControl ctrl = devContent.Create(pm);

            RenderWindow window = (RenderWindow)ctrl;

            window.EventHandler = new Code2015(devContent.RenderSystem, (X.Game)window.Tag);
            
            #region hacks
            //X.Game game = (X.Game)window.Tag;
            //XGS.GamerServicesComponent liveComp = new XGS.GamerServicesComponent(game);
            //game.Components.Add(liveComp);
            #endregion

            return window;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContext9"/> class.
        /// </summary>
        /// <param name="handle">The window handle to associate with the device.</param>
        /// <param name="settings">The settings used to configure the device.</param>
        internal DeviceContext9(IntPtr handle, DeviceSettings9 settings)
        {
            if (handle == IntPtr.Zero)
                throw new ArgumentException("Value must be a valid window handle.", "handle");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.settings = settings;

            PresentParameters = new PresentParameters();
            PresentParameters.BackBufferFormat = Format.X8R8G8B8;
            PresentParameters.BackBufferCount = 1;
            PresentParameters.BackBufferWidth = settings.Width;
            PresentParameters.BackBufferHeight = settings.Height;
            PresentParameters.Multisample = MultisampleType.None;
            PresentParameters.SwapEffect = SwapEffect.Discard;
            PresentParameters.EnableAutoDepthStencil = true;
            PresentParameters.AutoDepthStencilFormat = Format.D24X8;
            PresentParameters.PresentFlags = PresentFlags.DiscardDepthStencil;
            PresentParameters.PresentationInterval = PresentInterval.Default;
            PresentParameters.Windowed = true;
            PresentParameters.DeviceWindowHandle = handle;

            direct3D = new Direct3D();
            int msaaQuality = 0;
            if (direct3D.CheckDeviceMultisampleType(settings.AdapterOrdinal, DeviceType.Hardware, Format.A8R8G8B8, true, MultisampleType.FourSamples, out msaaQuality))
            {
                this.MultisampleType = SlimDX.Direct3D9.MultisampleType.FourSamples;
                this.MultisampleQuality = msaaQuality - 1;
                PresentParameters.Multisample = MultisampleType.FourSamples;
                PresentParameters.MultisampleQuality = msaaQuality - 1;
            }

            Device = new Device(direct3D, settings.AdapterOrdinal, DeviceType.Hardware, handle, settings.CreationFlags, PresentParameters);
        }
Exemplo n.º 15
0
 public ScreenCapture()
 {
     PresentParameters _presentParameters =new PresentParameters();
     _presentParameters.Windowed = true;
     _presentParameters.SwapEffect=SwapEffect.Discard;
     _device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.MixedVertexProcessing, _presentParameters);
 }
Exemplo n.º 16
0
 public static void Init(PictureBox handle)
 {
     try
     {
         presentParams = new PresentParameters();
         presentParams.Windowed = true;
         presentParams.EnableAutoDepthStencil = true;
         presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;
         presentParams.SwapEffect = SwapEffect.Discard;
         device = new Device(0, DeviceType.Hardware, handle, CreateFlags.SoftwareVertexProcessing, presentParams);
         if (device == null)
             return;
         SetupEnvironment();                
         CreateCoordLines();
         CamDistance = 4;
         init = true;
         cam = new Vector3(0, 0, 0);
         dir = new Vector3(1, 1, 1);
         camdist = 3f;
         DebugLog.PrintLn(presentParams.ToString());
         DebugLog.PrintLn(device.DeviceCaps.ToString());
         DebugLog.PrintLn("DirectX Init succeeded...");
     }
     catch (DirectXException ex)
     {
         string s = "DirectX Init error:"
                         + "\n\n" + ex.ToString()
                         + "\n\n" + presentParams.ToString();
         if (device != null)
             s += "\n\n" + device.DeviceCaps.ToString();
         DebugLog.PrintLn(s);
         error = true;
     }
 }
Exemplo n.º 17
0
        /* Direct3Dデバイスを準備する関数
         */
        private Device PrepareD3dDevice(Control i_window)
        {
            PresentParameters pp = new PresentParameters();
            pp.Windowed = true;
            pp.SwapEffect = SwapEffect.Flip;
            pp.BackBufferFormat = Format.X8R8G8B8;
            pp.BackBufferCount = 1;
            pp.EnableAutoDepthStencil = true;
            pp.AutoDepthStencilFormat = DepthFormat.D16;
            CreateFlags fl_base = CreateFlags.FpuPreserve;

            try{
                return new Device(0, DeviceType.Hardware, i_window.Handle, fl_base|CreateFlags.HardwareVertexProcessing, pp);
            }catch (Exception ex1){
                Debug.WriteLine(ex1.ToString());
                try{
                    return new Device(0, DeviceType.Hardware, i_window.Handle, fl_base | CreateFlags.SoftwareVertexProcessing, pp);
                }catch (Exception ex2){
                    // 作成に失敗
                    Debug.WriteLine(ex2.ToString());
                    try{
                        return new Device(0, DeviceType.Reference, i_window.Handle, fl_base | CreateFlags.SoftwareVertexProcessing, pp);
                    }catch (Exception ex3){
                        throw ex3;
                    }
                }
            }
        }
Exemplo n.º 18
0
        private D3DDeviceService(IntPtr windowIntPtr)
        {
            isDeviceLost = false;
            m_pp = new PresentParameters
                                       {
                                           Windowed = true,
                                           SwapEffect = SwapEffect.Discard,
                                           PresentationInterval = PresentInterval.One,
                                           BackBufferFormat = Manager.Adapters.Default.CurrentDisplayMode.Format,
                                           BackBufferWidth = Manager.Adapters.Default.CurrentDisplayMode.Width,
                                           BackBufferHeight = Manager.Adapters.Default.CurrentDisplayMode.Height,
                                       };

            CreateFlags flags = new CreateFlags();
            Caps caps = Manager.GetDeviceCaps(0, DeviceType.Hardware);

            if(caps.DeviceCaps.SupportsHardwareTransformAndLight)
                flags |= CreateFlags.HardwareVertexProcessing;
            else
                flags |= CreateFlags.SoftwareVertexProcessing;

            if(caps.DeviceCaps.SupportsPureDevice)
                flags |= CreateFlags.PureDevice;

            D3DDevice = new Device(0, caps.DeviceType, windowIntPtr, flags, m_pp);
        }
Exemplo n.º 19
0
        public DXControl()
        {
            // start timer
            _sw.Start();

            // initialize d3d device
            _direct3d = new Direct3D();
            _presentParam = new PresentParameters()
            {
                BackBufferWidth = ClientSize.Width,
                BackBufferHeight = ClientSize.Height,
                Windowed = true,
                BackBufferFormat = Format.X8R8G8B8,
                BackBufferCount = 1,
                SwapEffect = SwapEffect.Discard,
                EnableAutoDepthStencil = true,
                AutoDepthStencilFormat = Format.D24S8,
            };
            _device = new Device(_direct3d, 0,
                    DeviceType.Hardware, Handle,
                    CreateFlags.HardwareVertexProcessing, _presentParam);

            // event handlers
            Resize += OnResize;
        }
Exemplo n.º 20
0
 public void load_image(string DDS)
 {
     if (this.gs != null)
     {
         this.gs.Dispose();
     }
     try
     {
         PresentParameters presentParameters = new PresentParameters();
         presentParameters.SwapEffect = SwapEffect.Discard;
         Format format = Manager.Adapters[0].CurrentDisplayMode.Format;
         presentParameters.Windowed = true;
         Device device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, new PresentParameters[]
         {
             presentParameters
         });
         Texture texture = TextureLoader.FromFile(device, DDS);
         this.gs = TextureLoader.SaveToStream(ImageFileFormat.Png, texture);
         texture.Dispose();
         this.pictureBox.Image = Image.FromStream(this.gs);
         device.Dispose();
         this.gs.Close();
     }
     catch (Exception var_4_B4)
     {
     }
 }
Exemplo n.º 21
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            FileSystem.Instance.AddWorkingDir(@".\");
            FileSystem.Instance.AddWorkingDir(@"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug");
            // zou jia's res dir
            FileSystem.Instance.AddWorkingDir(@"C:\Users\penser\Documents\Visual Studio 2008\Projects\lrvbsvnicg\Source\Code2015\bin\x86\Debug");

            GraphicsAPIManager.Instance.RegisterGraphicsAPI(new Apoc3D.RenderSystem.Xna.XnaGraphicsAPIFactory());

            DeviceContent dc = GraphicsAPIManager.Instance.CreateDeviceContent();

            PresentParameters pm2 = new PresentParameters();
            pm2.IsWindowed = true;
            pm2.BackBufferFormat = ImagePixelFormat.A8R8G8B8;
            pm2.BackBufferHeight = 600;
            pm2.BackBufferWidth = 800;

            RenderWindow wnd = (RenderWindow)dc.Create(pm2);
            Viewer = new RenderViewer(dc.RenderSystem);
            wnd.EventHandler = Viewer;
            Window = wnd;
            
            wnd.Run();
        }
Exemplo n.º 22
0
        internal DeviceContext9(Form form, DeviceSettings9 settings)
        {
            if (form.Handle == IntPtr.Zero)
                throw new ArgumentException("Value must be a valid window handle.", "handle");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.settings = settings;

            PresentParameters = new PresentParameters();
            PresentParameters.BackBufferFormat = Format.X8R8G8B8;
            PresentParameters.BackBufferCount = 1;
            PresentParameters.BackBufferWidth = form.ClientSize.Width;
            PresentParameters.BackBufferHeight = form.ClientSize.Height;
            PresentParameters.Multisample = settings.MultisampleType;
            PresentParameters.SwapEffect = SwapEffect.Discard;
            PresentParameters.EnableAutoDepthStencil = true;
            PresentParameters.AutoDepthStencilFormat = Format.D24S8;
            PresentParameters.PresentFlags = PresentFlags.DiscardDepthStencil;
            PresentParameters.PresentationInterval = PresentInterval.Immediate;
            PresentParameters.Windowed = settings.Windowed;
            PresentParameters.DeviceWindowHandle = form.Handle;

            direct3D = new Direct3D();
            Device = new Device(direct3D, settings.AdapterOrdinal, DeviceType.Hardware, form.Handle, settings.CreationFlags, PresentParameters);
        }
 public InitializeGraphics()
 {
     pp = new PresentParameters();
     pp.Windowed = true;
     pp.SwapEffect = SwapEffect.Discard;
     pp.AutoDepthStencilFormat = DepthFormat.D16;
     pp.EnableAutoDepthStencil = true;
 }
Exemplo n.º 24
0
        public void InstalizeDevice()
        {
            PresentParameters presentparams= new PresentParameters();
            presentparams.Windowed = true;
            presentparams.SwapEffect = SwapEffect.Discard;

            device = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentparams);
        }
        public DxScreenCapture()
        {
            //InitializeComponent(); //Don't need, we're only a form to get a handle for directX - I think this is cheating/wrong, there's got to be a better way.

            PresentParameters present_params = new PresentParameters();
            present_params.Windowed = true;
            present_params.SwapEffect = SwapEffect.Discard;
            d = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, present_params);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes an instance of the class <see cref="DirectxScreenCapturer"/>
        /// </summary>
        public DirectxScreenCapturer()
        {
            this.CalculatePositions();

            var parameters = new PresentParameters();
            parameters.Windowed = true;
            parameters.SwapEffect = SwapEffect.Discard;
            this._device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, parameters);
        }
Exemplo n.º 27
0
 public Device CreateView(PictureBox p)
 {
     PresentParameters presentParams = new PresentParameters();
     presentParams.Windowed = true;
     presentParams.SwapEffect = SwapEffect.Discard;
     presentParams.EnableAutoDepthStencil = true;
     presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;
     return new Device(0, DeviceType.Hardware, p.Handle, CreateFlags.SoftwareVertexProcessing, presentParams);
 }
Exemplo n.º 28
0
 public DxScreenCapture()
 {
     PresentParameters present_params = new PresentParameters();
     present_params.Windowed = true;
     present_params.SwapEffect = SwapEffect.Discard;
     //present_params.BackBufferCount = 1;
     //present_params.FullScreenRefreshRateInHertz = 0;
     d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
     //d2 = new Device(new Direct3D(), 1, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
 }
Exemplo n.º 29
0
        static DxScreenCapture()
        {
            var d3d = new Direct3D();
            var adapterInfo = d3d.Adapters.DefaultAdapter;
            PresentParameters parameters = new PresentParameters();
            parameters.Windowed = true;
            parameters.SwapEffect = SwapEffect.Discard;

            d = new Device(d3d, adapterInfo.Adapter, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, parameters);
        }
Exemplo n.º 30
0
    void InitGraphics()
    {
        PresentParameters present_params = new PresentParameters();

           present_params.Windowed = true;
           present_params.SwapEffect = SwapEffect.Discard;

           m_device = new Device(0, DeviceType.Hardware, this,
            CreateFlags.SoftwareVertexProcessing, present_params);
    }
Exemplo n.º 31
0
        public static void Create()
        {
            Parameters = new PresentParameters
            {
                BackBufferFormat     = Format.X8R8G8B8,
                PresentFlag          = PresentFlag.LockableBackBuffer,
                BackBufferWidth      = Settings.ScreenWidth,
                BackBufferHeight     = Settings.ScreenHeight,
                SwapEffect           = SwapEffect.Discard,
                PresentationInterval = Settings.FPSCap ? PresentInterval.One : PresentInterval.Immediate,
                Windowed             = !Settings.FullScreen,
            };


            Caps        devCaps  = Manager.GetDeviceCaps(0, DeviceType.Hardware);
            DeviceType  devType  = DeviceType.Reference;
            CreateFlags devFlags = CreateFlags.HardwareVertexProcessing;

            if (devCaps.VertexShaderVersion.Major >= 2 && devCaps.PixelShaderVersion.Major >= 2)
            {
                devType = DeviceType.Hardware;
            }

            if (devCaps.DeviceCaps.SupportsHardwareTransformAndLight)
            {
                devFlags = CreateFlags.HardwareVertexProcessing;
            }


            if (devCaps.DeviceCaps.SupportsPureDevice)
            {
                devFlags |= CreateFlags.PureDevice;
            }


            Device = new Device(Manager.Adapters.Default.Adapter, devType, Program.Form, devFlags, Parameters);

            Device.DeviceLost     += (o, e) => DeviceLost = true;
            Device.DeviceResizing += (o, e) => e.Cancel = true;
            Device.DeviceReset    += (o, e) => LoadTextures();
            Device.Disposing      += (o, e) => Clean();

            Device.SetDialogBoxesEnabled(true);

            LoadTextures();
            LoadPixelsShaders();
        }
Exemplo n.º 32
0
        } // construtor

        public void initGfx()
        {
            // Configuração dos parâmetros de apresentação
            PresentParameters pps = new PresentParameters();

            pps.Windowed   = true;
            pps.SwapEffect = SwapEffect.Discard;

            // Adaptador default, processamento no hardware, processamento de vértice no
            // software, janela (this), parâmetros de apresentação (pps)
            int adaptador = 0;

            device = new Device(adaptador, DeviceType.Hardware, this,
                                CreateFlags.SoftwareVertexProcessing, pps);

            // Configuração dos vértices no espaço 3d com mapeamento da textura
            montar_triangulos();

            // ****** Montagem do buffer de vértices (vertexbuffer) *****
            // O buffer de vértices vbQuadrado é criado.
            vbQuadrado = new VertexBuffer(typeof(CustomVertex.PositionColored),
                                          4, device, Usage.Dynamic | Usage.WriteOnly,
                                          CustomVertex.PositionColored.Format,
                                          Pool.Default);

            // Joga os vértices no buffer de vértices
            vbQuadrado.SetData(triangulo, 0, LockFlags.None);

            // configura o método calback da recriação do buffer de vértices
            vbQuadrado.Created += new EventHandler(this.quandoVertexBufferCriado);

            // ****** Montagem do buffer de índices (indexbuffer) *****
            // Caminho de ligação dos vértices para montar o quadrado
            // 0,1,2 - Primeiro triângulo   2,3,0 - Segundo triângulo
            ndxQuadrado = new short[] { 0, 1, 2, 2, 3, 0 };

            // Inicialização do buffer de índices
            ibQuadrado = new IndexBuffer(typeof(short),
                                         ndxQuadrado.Length, device, Usage.Dynamic | Usage.WriteOnly,
                                         Pool.Default);

            // Joga dentro do buffer de índices os elementos da array ndxQuadrado
            ibQuadrado.SetData(ndxQuadrado, 0, LockFlags.None);

            // configura o método calback da recriação do buffer de índices
            ibQuadrado.Created += new EventHandler(this.quandoIndexBufferCriado);
        } // initGfx()
Exemplo n.º 33
0
        public DxScreenCapture(int monitorIndex)
        {
            try
            {
                var presentParams = new PresentParameters
                {
                    Windowed             = true,
                    SwapEffect           = SwapEffect.Discard,
                    PresentationInterval = PresentInterval.Immediate
                };

                _d = new Device(new Direct3D(), GetMonitor(monitorIndex), DeviceType.Hardware, IntPtr.Zero,
                                CreateFlags.SoftwareVertexProcessing, presentParams);
            }
            catch (Exception) {
            }
        }
Exemplo n.º 34
0
        void InitD3D9()
        {
            if (NumActiveImages == 0)
            {
                D3DContext = new Direct3DEx();

                PresentParameters presentparams = new PresentParameters();
                presentparams.Windowed             = true;
                presentparams.SwapEffect           = SwapEffect.Discard;
                presentparams.DeviceWindowHandle   = GetDesktopWindow();
                presentparams.PresentationInterval = PresentInterval.Immediate;
                presentparams.MultiSampleQuality   = 0;
                presentparams.MultiSampleType      = 0;

                D3DDevice = new DeviceEx(D3DContext, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve, presentparams);
            }
        }
Exemplo n.º 35
0
 public bool InitializeDirect3D()
 {
     try
     {
         PresentParameters presentParams = new PresentParameters();
         presentParams.Windowed   = true;                                                                                //指定以Windows窗体形式显示
         presentParams.SwapEffect = SwapEffect.Discard;                                                                  //当前屏幕绘制后,它将自动从内存中删除
         device1 = new Device(0, DeviceType.Hardware, this.panel1, CreateFlags.SoftwareVertexProcessing, presentParams); //实例化device对象
         device2 = new Device(0, DeviceType.Hardware, this.panel2, CreateFlags.SoftwareVertexProcessing, presentParams); //实例化device对象
         return(true);
     }
     catch (DirectXException e)
     {
         MessageBox.Show(e.ToString(), "Error"); //处理异常
         return(false);
     }
 }
Exemplo n.º 36
0
 public bool InitializeGraphics()
 {
     try
     {
         // Now let's setup our D3D stuff
         PresentParameters presentParams = new PresentParameters();
         presentParams.Windowed   = true;
         presentParams.SwapEffect = SwapEffect.Discard;
         device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
         this.OnCreateDevice(device, null);
         return(true);
     }
     catch (DirectXException)
     {
         return(false);
     }
 }
Exemplo n.º 37
0
        /// <summary>
        /// Initializes DirectX Graphics.
        /// </summary>
        public void InitializeDirectX()
        {
            try
            {
                SetStyle(ControlStyles.Opaque | ControlStyles.AllPaintingInWmPaint, true);
                UpdateStyles();
                var presentParams = new PresentParameters();
                presentParams.Windowed   = true;
                presentParams.SwapEffect = SwapEffect.Discard;

                device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 38
0
        private void InitializeGraphics()
        {
            this.presentParams                        = new PresentParameters();
            this.presentParams.Windowed               = true;
            this.presentParams.SwapEffect             = SwapEffect.Discard;
            this.presentParams.EnableAutoDepthStencil = true;
            this.presentParams.AutoDepthStencilFormat = Format.D16;
            this.presentParams.DeviceWindowHandle     = this.Handle;


            // Create our device
            Direct3D _direct3D = new Direct3D();

            this.device = new Device(_direct3D, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, this.presentParams);
            //device.DeviceReset += new EventHandler(device_DeviceReset);
            device_DeviceReset(null, null);
        }
Exemplo n.º 39
0
        internal void OnLoad()
        {
            NativeImport.SetWindowLong(this.Handle, DrawFactory.GWL_EXSTYLE, (IntPtr)(NativeImport.GetWindowLong(this.Handle, DrawFactory.GWL_EXSTYLE) ^ (DrawFactory.WS_EX_LAYERED ^ DrawFactory.WS_EX_TRANSPARENT)));/*(IntPtr)(NativeImport.GetWindowLong(this.Handle, DrawFactory.GWL_EXSTYLE) ^*/
            NativeImport.SetLayeredWindowAttributes(this.Handle, 0, 255, DrawFactory.LWA_ALPHA);
            NativeImport.RECT rct = default;
            NativeImport.GetWindowRect(Utils.GetPubgWindow(), out rct);

            this.Width    = rct.Right - rct.Left;
            this.Height   = rct.Bottom - rct.Top;
            this.Location = new System.Drawing.Point(rct.Left, rct.Top);

            if (IsInitialised == false)
            {
                PresentParameters presentParameters = new PresentParameters();
                presentParameters.Windowed         = true;
                presentParameters.SwapEffect       = SwapEffect.Discard;
                presentParameters.BackBufferFormat = Format.A8R8G8B8;

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

                DrawFactory.drawLine          = new Line(DrawFactory.device);
                DrawFactory.drawBoxLine       = new Line(DrawFactory.device);
                DrawFactory.drawCircleLine    = new Line(DrawFactory.device);
                DrawFactory.drawFilledBoxLine = new Line(DrawFactory.device);
                DrawFactory.drawTriLine       = new Line(DrawFactory.device);

                FontDescription fontDescription = new FontDescription()
                {
                    FaceName        = "Fixedsys Regular",
                    CharacterSet    = FontCharacterSet.Default,
                    Height          = 20,
                    Weight          = FontWeight.Regular,
                    MipLevels       = 0,
                    OutputPrecision = FontPrecision.Default,
                    PitchAndFamily  = FontPitchAndFamily.Default,
                    Quality         = FontQuality.ClearType
                };

                DrawFactory.font = new SharpDX.Direct3D9.Font(DrawFactory.device, fontDescription);
                DrawFactory.InitialiseCircleDrawing(DrawFactory.device);

                IsInitialised = true;

                OnDraw();
            }
        }
Exemplo n.º 40
0
        public void Present()
        {
            if (!_ready)
            {
                return;
            }
            var pp = new PresentParameters()
            {
                DirtyRectangles = null,
                ScrollOffset    = null,
                ScrollRectangle = null
            };

            // Present
            _swap.Present(1, PresentFlags.None, pp);
            _context.DiscardView(_rtv);
        }
Exemplo n.º 41
0
        private void Initialize()
        {
            var width  = this.ClientSize.Width;
            var height = this.ClientSize.Height;

            water = new Water(160, 120);

            Direct3D = new Direct3D();

            PresentParameters = new PresentParameters();
            PresentParameters.BackBufferFormat   = Format.X8R8G8B8;
            PresentParameters.BackBufferCount    = 1;
            PresentParameters.BackBufferWidth    = width;
            PresentParameters.BackBufferHeight   = height;
            PresentParameters.SwapEffect         = SwapEffect.Discard;
            PresentParameters.Windowed           = true;
            PresentParameters.DeviceWindowHandle = this.Handle;

            Device = new Device(Direct3D, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, PresentParameters);

            Device.SetTexture(0, Texture.FromFile(Device, "back.jpg"));

            map = new Texture(Device, water.Width, water.Height, 0, Usage.None, Format.R32F, Pool.Managed);

            effect = Effect.FromString(Device, Properties.Resources.Shader, ShaderFlags.None);

            //声明顶点
            vertices = new VertexBuffer(Device, 4 * 24, Usage.WriteOnly, VertexFormat.None, SlimDX.Direct3D9.Pool.Managed);
            var dat = vertices.Lock(0, 0, LockFlags.None);

            dat.WriteRange(new float[] { 0, 0, 0f, 1f, 0, 0 });
            dat.WriteRange(new float[] { width, 0, 0f, 1f, 1, 0 });
            dat.WriteRange(new float[] { 0, height, 0f, 1f, 0, 1 });
            dat.WriteRange(new float[] { width, height, 0f, 1f, 1, 1 });
            vertices.Unlock();

            //声明顶点格式
            var vertexElems = new[]
            {
                new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
                new VertexElement(0, 16, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                VertexElement.VertexDeclarationEnd
            };

            Device.VertexDeclaration = new VertexDeclaration(Device, vertexElems);
        }
Exemplo n.º 42
0
        public bool InitializeGraphics()
        {
            try
            {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed   = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                state          = new D3DState();
                state.graphics = new Direct3D.Device(0, DeviceType.Hardware, control,
                                                     Direct3D.CreateFlags.SoftwareVertexProcessing, presentParams);
                //The previous code creates a new graphics device. It’s not going to make a whole lot of
                //sense to you right now, but don’t worry that much about it. Just know that it works, and
                //that I’ll get to it in much more detail in Chapter 7.
                //The next part of the code sets up the event handlers (which are delegates):
                state.graphics.DeviceLost     += new EventHandler(this.InvalidateDeviceObjects);
                state.graphics.DeviceReset    += new EventHandler(this.RestoreDeviceObjects);
                state.graphics.Disposing      += new EventHandler(this.DeleteDeviceObjects);
                state.graphics.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing);

                /* 2d feature for turning off back culling on badly chosen flat rectangels */
                state.graphics.RenderState.CullMode = Direct3D.Cull.None;

                // yes I want this.
                state.graphics.RenderState.AlphaBlendEnable = true;


                //The first three events handle whenever a device is lost (say, if the user switches to another
                //window), the device is reset for any reason, or the device is disposed of. These first three
                //events are solid events; when they happen, you have to handle them. No ifs, ands, or buts
                //about it—the operating system is telling you something happened and your event handler
                //has to take care of the situation.
                //The final event handles when the graphics device is resized, which is a special kind of
                //event because it can be cancelled. A cancelable event is an event that your program can
                //decide to reject. For example, if the user says he’s going to resize your game window, your
                //program will get the event, but you can tell the operating system, “Nope, it’s not gonna
                //happen!” and the event won’t complete. This behavior is used mostly to prevent forms
                //from closing before the user saves his data in windows applications.
                //The final part of the code returns true for a successful initialization, or catches any
                //DirectXExceptions that may have been thrown and returns false:
                return(true);
            }
            catch (DirectXException)
            {
                return(false);
            }
        }
Exemplo n.º 43
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                // Устанавливаем режим отображения трехмерной графики
                PresentParameters d3dpp = new PresentParameters();
                d3dpp.BackBufferCount        = 1;
                d3dpp.SwapEffect             = SwapEffect.Discard;
                d3dpp.Windowed               = true;                      // Выводим графику в окно
                d3dpp.MultiSample            = MultiSampleType.None;      // Выключаем антиалиасинг
                d3dpp.EnableAutoDepthStencil = true;                      // Разрешаем создание z-буфера
                d3dpp.AutoDepthStencilFormat = DepthFormat.D16;           // Z-буфер в 16 бит
                device = new Device(0,                                    // D3D_ADAPTER_DEFAULT - видеоадаптер по умолчанию
                                    DeviceType.Hardware,                  // Тип устройства - аппаратный ускоритель
                                    this,                                 // Окно для вывода графики

                                    CreateFlags.SoftwareVertexProcessing, // Геометрию обрабатывает CPU
                                    d3dpp);
                device.RenderState.Lighting = Enabled;
                device.RenderState.Ambient  = System.Drawing.Color.White;
                device.RenderState.CullMode = Cull.None;
                device.Lights[0].Enabled    = true;
                device.Lights[0].Diffuse    = Color.White;
                device.Lights[0].Position   = new Vector3(10, 10, 10);
                device.Lights[0].Range      = 1000f;

                device.Lights[1].Enabled  = true;
                device.Lights[1].Diffuse  = Color.White;
                device.Lights[1].Position = new Vector3(-10, 10, -10);
                device.Lights[1].Range    = 1000f;

                device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 3, Width / (float)Height, 0.5f, 500f);

                MouseX = Cursor.Position.X;
                MouseY = Cursor.Position.Y;
                Camera.Initialize(new Vector3(-Constants.AxisLength, Constants.AxisLength, Constants.AxisLength), new Vector3(0, 0, 0), new Vector3(0, 1, 0));


                //code for testing
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message, "Ошибка инициализации");
                Close();
            }
        }
Exemplo n.º 44
0
        private bool CreateDevice_DX()// 建立DirectX9裝置
        {
            try
            {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed   = true;                                                                            //指定以Windows窗体形式显示
                presentParams.SwapEffect = SwapEffect.Copy;                                                                 //当前屏幕绘制后它将自动从内存中删除
                pD3DDevice = new Device(0, DeviceType.Hardware, Hwnd, CreateFlags.HardwareVertexProcessing, presentParams); //实例化device对象

                return(true);
            }
            catch (DirectXException e)
            {
                MessageBox.Show(e.ToString(), "Error"); //处理异常
                return(false);
            }
        }
Exemplo n.º 45
0
        private void StartD3D()
        {
            context = new Direct3DEx();
            // Ref: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/wpf-and-direct3d9-interoperation
            var presentparams = new PresentParameters
            {
                Windowed   = true,
                SwapEffect = SwapEffect.Discard,
                //DeviceWindowHandle = GetDesktopWindow(),
                PresentationInterval = PresentInterval.Default,
                BackBufferHeight     = 1,
                BackBufferWidth      = 1,
                BackBufferFormat     = Format.Unknown
            };

            device = new DeviceEx(context, this.adapterIndex, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve, presentparams);
        }
Exemplo n.º 46
0
        public static void ApplySettings(MyRenderDeviceSettings settings)
        {
            bool canReset = m_settings.AdapterOrdinal == settings.AdapterOrdinal;

            m_settings   = settings;
            m_parameters = CreatePresentParameters(m_settings, m_windowHandle);
            SupportsHDR  = GetAdaptersList()[m_settings.AdapterOrdinal].HDRSupported;

            if (canReset)
            {
                Reset();
            }
            else
            {
                Recreate();
            }
        }
Exemplo n.º 47
0
        public TgcD3dDevice(Control panel3d)
        {
            this.panel3d = panel3d;
            aspectRatio  = (float)this.panel3d.Width / this.panel3d.Height;

            Caps        caps = Manager.GetDeviceCaps(Manager.Adapters.Default.Adapter, DeviceType.Hardware);
            CreateFlags flags;

            Console.WriteLine("Max primitive count:" + caps.MaxPrimitiveCount);

            if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
            {
                flags = CreateFlags.HardwareVertexProcessing;
            }
            else
            {
                flags = CreateFlags.SoftwareVertexProcessing;
            }

            PresentParameters d3dpp = new PresentParameters();

            d3dpp.BackBufferFormat       = Format.Unknown;
            d3dpp.SwapEffect             = SwapEffect.Discard;
            d3dpp.Windowed               = true;
            d3dpp.EnableAutoDepthStencil = true;
            d3dpp.AutoDepthStencilFormat = DepthFormat.D24S8;
            d3dpp.PresentationInterval   = PresentInterval.Immediate;

            //Antialiasing
            if (Manager.CheckDeviceMultiSampleType(Manager.Adapters.Default.Adapter, DeviceType.Hardware,
                                                   Manager.Adapters.Default.CurrentDisplayMode.Format, true, MultiSampleType.NonMaskable))
            {
                d3dpp.MultiSample        = MultiSampleType.TwoSamples;
                d3dpp.MultiSampleQuality = 0;
            }
            else
            {
                d3dpp.MultiSample = MultiSampleType.None;
            }


            //Crear Graphics Device
            Device.IsUsingEventHandlers = false;
            d3dDevice              = new Device(0, DeviceType.Hardware, panel3d, flags, d3dpp);
            d3dDevice.DeviceReset += new System.EventHandler(this.OnResetDevice);
        }
Exemplo n.º 48
0
        public void RefreshControlSwapChain(GLControlWrapper_SlimDX9 control)
        {
            FreeControlSwapChain(control);

            var pp = new PresentParameters
            {
                BackBufferWidth      = Math.Max(8, control.ClientSize.Width),
                BackBufferHeight     = Math.Max(8, control.ClientSize.Height),
                BackBufferCount      = 1,
                BackBufferFormat     = Format.X8R8G8B8,
                DeviceWindowHandle   = control.Handle,
                Windowed             = true,
                PresentationInterval = control.Vsync ? PresentInterval.One : PresentInterval.Immediate
            };

            control.SwapChain = new SwapChain(dev, pp);
        }
Exemplo n.º 49
0
        internal void OnLoad()
        {
            NativeImport.SetWindowLong(Handle, DrawFactory.GWL_EXSTYLE,
                                       (IntPtr)(NativeImport.GetWindowLong(Handle, DrawFactory.GWL_EXSTYLE) ^ DrawFactory.WS_EX_LAYERED ^
                                                DrawFactory.WS_EX_TRANSPARENT));

            NativeImport.SetLayeredWindowAttributes(Handle, 0, 255, DrawFactory.LWA_ALPHA);

            if (IsInitialised)
            {
                return;
            }
            var presentParameters = new PresentParameters
            {
                Windowed = true, SwapEffect = SwapEffect.Discard, BackBufferFormat = Format.A8R8G8B8
            };

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

            DrawFactory.drawLine          = new Line(DrawFactory.device);
            DrawFactory.drawBoxLine       = new Line(DrawFactory.device);
            DrawFactory.drawCircleLine    = new Line(DrawFactory.device);
            DrawFactory.drawFilledBoxLine = new Line(DrawFactory.device);
            DrawFactory.drawTriLine       = new Line(DrawFactory.device);

            var fontDescription = new FontDescription
            {
                FaceName        = "Fixedsys Regular",
                CharacterSet    = FontCharacterSet.Default,
                Height          = 20,
                Weight          = FontWeight.Bold,
                MipLevels       = 0,
                OutputPrecision = FontPrecision.Default,
                PitchAndFamily  = FontPitchAndFamily.Default,
                Quality         = FontQuality.ClearType
            };

            DrawFactory.font = new Font(DrawFactory.device, fontDescription);
            DrawFactory.InitialiseCircleDrawing(DrawFactory.device);

            IsInitialised = true;

            OnDraw();
        }
Exemplo n.º 50
0
        public void InitializeDevice()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            PresentParameters presentParams = new PresentParameters
            {
                BackBufferWidth        = ClientSize.Width,
                BackBufferHeight       = ClientSize.Height,
                DeviceWindowHandle     = Handle,
                PresentFlags           = PresentFlags.None,
                Multisample            = MultisampleType.None,
                BackBufferCount        = 0,
                PresentationInterval   = PresentInterval.One, // VSYNC ON
                SwapEffect             = SwapEffect.Discard,
                BackBufferFormat       = Format.X8R8G8B8,
                Windowed               = true,
                EnableAutoDepthStencil = false,
            };

            if (d3d == null)
            {
                d3d = new Direct3D();
            }

            device          = new Device(d3d, 0, DeviceType.Hardware, Handle, CreateFlags.HardwareVertexProcessing, presentParams);
            device.Viewport = new Viewport(0, 0, ClientSize.Width, ClientSize.Height);

            sprite = new Sprite(device);

            if (Icons != null)
            {
                foreach (MapIcon icon in Icons)
                {
                    LoadIconTexture(icon);
                }
            }

            if ((CurrentMap != null) && (CurrentMap.Tex == null))
            {
                LoadImageTexture(CurrentMap);
            }
        }
Exemplo n.º 51
0
        static public bool ReCreateDevice()
        {
            try
            {
                //mpD3DDevice.Dispose();

                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed               = true;
                presentParams.BackBufferWidth        = mWidth;
                presentParams.BackBufferHeight       = mHeight;
                presentParams.SwapEffect             = SwapEffect.Discard;
                presentParams.EnableAutoDepthStencil = true;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;

                presentParams.PresentationInterval = PresentInterval.Immediate;

                mpD3DDevice.Reset(presentParams);

                //defaultD3DStates();
                //InitVertexTypes();
                mTextureManager.reloadTexturesIfNeeded(true); //..init();
                mShaderManager.reloadShadersIfNeeded(true);   //.init();


                changePerspectiveParams(mFov, mWindowWidth, mWindowHeight);
            }
            catch (System.Exception ex)
            {
                return(false);
            }

            return(true);

            //string time = DateTime.Now.ToString();

            //mpD3DDevice.Dispose();
            ////mbDeviceLost = false;
            //bool status =  createDevice(mParentWindow, mWidth, mHeight, true, true);

            //System.Threading.Thread.Sleep(3000);
            //mTextureManager.reloadTexturesIfNeeded(true);
            //mShaderManager.reloadShadersIfNeeded(true);

            //return status;
        }
Exemplo n.º 52
0
        internal SwapChain CreateSwapChain(SDX_DisplayWindow displayWindow,
                                           int width, int height, int bpp, bool fullScreen)
        {
            if (fullScreen == true)
            {
                PresentParameters present =
                    CreateFullScreenPresentParameters(displayWindow, width, height, bpp);

                OnDeviceAboutToReset();

                System.Diagnostics.Debug.Print("{0} Going to full screen...", DateTime.Now);
                mDevice.Device.Reset(present);
                System.Diagnostics.Debug.Print("{0} Full screen success.", DateTime.Now);

                return(mDevice.Device.GetSwapChain(0));
            }
            else
            {
                PresentParameters present =
                    CreateWindowedPresentParameters(displayWindow, width, height, bpp);

                if (displayWindow.FrameBuffer != null && displayWindow.IsFullScreen == true)
                {
                    // if we are in full screen mode already, we must
                    // reset the device before creating the windowed swap chain.
                    present.BackBufferHeight   = 1;
                    present.BackBufferWidth    = 1;
                    present.DeviceWindowHandle = displayWindow.RenderTarget.TopLevelControl.Handle;

                    OnDeviceAboutToReset();

                    var result = mDevice.Device.TestCooperativeLevel();

                    System.Diagnostics.Debug.Print("TestCooperativeLevel result: {0}", result);
                    System.Diagnostics.Debug.Print("{0} Going to windowed mode...", DateTime.Now);
                    mDevice.Device.Reset(present);
                    System.Diagnostics.Debug.Print("{0} Windowed mode success.", DateTime.Now);


                    present = CreateWindowedPresentParameters(displayWindow, width, height, bpp);
                }

                return(new Direct3D.SwapChain(mDevice.Device, present));
            }
        }
Exemplo n.º 53
0
        private void ResizeRendering()
        {
            if (_texture != null)
            {
                _texture.Dispose();
            }

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

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

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

            double NewWidth  = ActualWidth;
            double NewHeight = ActualHeight;

            PresentParameters pp = new PresentParameters();

            pp.DeviceWindowHandle   = _hwnd;
            pp.Windowed             = true;
            pp.SwapEffect           = SwapEffect.Flip;
            pp.PresentationInterval = PresentInterval.Default;
            pp.BackBufferWidth      = (int)NewWidth;
            pp.BackBufferHeight     = (int)NewHeight;
            pp.BackBufferFormat     = Format.X8R8G8B8;
            pp.BackBufferCount      = 1;

            _device       = new DeviceEx(_d3dex, 0, DeviceType.Hardware, _hwnd, CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice | CreateFlags.FpuPreserve | CreateFlags.Multithreaded, pp);
            _texture      = new Texture(_device, (int)ActualWidth, (int)ActualHeight, 1, Usage.None, Format.X8R8G8B8, Pool.Default);
            _renderBuffer = _texture.GetSurfaceLevel(0);

            d3dimg.Lock();
            _backBuffer = _device.GetBackBuffer(0, 0);
            d3dimg.SetBackBuffer(D3DResourceType.IDirect3DSurface9, _backBuffer.ComPointer);
            d3dimg.Unlock();
        }
Exemplo n.º 54
0
        } // construtor

        public void initGfx()
        {
            // Configuração dos parâmetros de apresentação
            PresentParameters pps = new PresentParameters();

            pps.Windowed   = true;
            pps.SwapEffect = SwapEffect.Discard;

            // Adaptador default, processamento no hardware, processamento de vértice no
            // software, janela (this), parâmetros de apresentação (pps)
            int adaptador = 0;

            device = new Device(adaptador, DeviceType.Hardware, this,
                                CreateFlags.SoftwareVertexProcessing, pps);

            // Configura a camera
            SetupCamera();
        } // initGfx()
Exemplo n.º 55
0
        private void StartD3D()
        {
            if (DX10ImageSource.ActiveClients != 0)
            {
                return;
            }

            D3DContext = new Direct3DEx();

            PresentParameters presentparams = new PresentParameters();

            presentparams.Windowed             = true;
            presentparams.SwapEffect           = SwapEffect.Discard;
            presentparams.DeviceWindowHandle   = GetDesktopWindow();
            presentparams.PresentationInterval = PresentInterval.Default;

            DX10ImageSource.D3DDevice = new DeviceEx(D3DContext, 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve, presentparams);
        }
Exemplo n.º 56
0
        public void InitializeDevice()
        {
            PresentParameters presentParams = new PresentParameters();

            presentParams.Windowed   = true;
            presentParams.SwapEffect = SwapEffect.Discard;

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


            device.RenderState.CullMode = Cull.None;
            device.RenderState.FillMode = FillMode.Solid;
            //device.RenderState.ZBufferEnable = false;
            device.RenderState.Lighting = false;


            device.DeviceReset += new EventHandler(HandleResetEvent);
        }
Exemplo n.º 57
0
        public void InitD3D()
        {
            logger.Debug("InitD3D()");
            var d3d = new Direct3D();

            presentParameters = new PresentParameters();
            presentParameters.BackBufferFormat     = Format.Unknown;
            presentParameters.BackBufferCount      = 2;
            presentParameters.Windowed             = true;
            presentParameters.SwapEffect           = SwapEffect.Discard;
            presentParameters.DeviceWindowHandle   = this.Handle;
            presentParameters.PresentationInterval = PresentInterval.Default;

            device = new Device(d3d, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded, presentParameters);
            var comObj = device as SharpDX.ComObject;

            previewHelper.Initialize(comObj.NativePointer);
        }
Exemplo n.º 58
0
        public void InitD3D()
        {
            Rect rect = this.window.ClientRect();
            PresentParameters presentParameters = new PresentParameters();

            presentParameters.Windowed             = true;
            presentParameters.SwapEffect           = SwapEffect.Discard;
            presentParameters.BackBufferFormat     = Format.A8R8G8B8;
            presentParameters.BackBufferWidth      = rect.W;
            presentParameters.BackBufferHeight     = rect.H;
            presentParameters.PresentationInterval = PresentInterval.One;
            this.dx = new Device(new Direct3D(), 0, DeviceType.Hardware, base.Handle, CreateFlags.Multithreaded | CreateFlags.HardwareVertexProcessing, new PresentParameters[]
            {
                presentParameters
            });
            this.RC = new RenderingContext(this.dx, this.window);
            Configuration.AddResultWatch(ResultCode.DeviceLost, ResultWatchFlags.AlwaysIgnore);
        }
Exemplo n.º 59
0
        private PresentParameters GetPresentParameters(int width, int height)
        {
            PresentParameters presentParams = new PresentParameters();

            presentParams.PresentFlags       = PresentFlags.Video | PresentFlags.OverlayYCbCr_BT709;
            presentParams.Windowed           = true;
            presentParams.DeviceWindowHandle = this.hwnd;
            presentParams.BackBufferWidth    = width == 0 ? 1 : width;
            presentParams.BackBufferHeight   = height == 0 ? 1 : height;
            presentParams.SwapEffect         = SwapEffect.Discard;
            //presentParams.Multisample = MultisampleType.NonMaskable;
            presentParams.PresentationInterval   = PresentInterval.Immediate;
            presentParams.BackBufferFormat       = this.displayMode.Format;
            presentParams.BackBufferCount        = 1;
            presentParams.EnableAutoDepthStencil = false;

            return(presentParams);
        }
Exemplo n.º 60
0
        /// <summary>
        ///     必要ありそうなら、DirectX9を初期化する。(WPF用)
        /// </summary>
        private void InitD3D9()
        {
            if (ActiveImageCount == 0)
            {
                D3DContext = new Direct3DEx();

                var presentParam = new PresentParameters();
                presentParam.Windowed             = true;
                presentParam.SwapEffect           = SwapEffect.Discard;
                presentParam.DeviceWindowHandle   = GetDesktopWindow();
                presentParam.PresentationInterval = PresentInterval.Immediate;

                D3DDevice = new DeviceEx(D3DContext, 0, DeviceType.Hardware, IntPtr.Zero,
                                         CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve,
                                         presentParam);
                D3DDevice.SetRenderState(RenderState.AlphaBlendEnable, false);
            }
        }