public override void Resize(int width, int height)
 {
     _presentParams.BackBufferWidth  = width;
     _presentParams.BackBufferHeight = height;
     _pp.BackBufferWidth             = width;
     _pp.BackBufferHeight            = height;
     _graphicsDevice.Reset(_pp);
 }
Esempio n. 2
0
        public override void Initialize()
        {
            // A reference to the graphics service is mandatory since we need to get the graphics device after it's destroyed
            graphicsService = Game.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
            graphicsDevice = graphicsService.GraphicsDevice;

            // Those three events are necessary to keep a "fresh" state, see individual methods
            graphicsService.DeviceCreated += delegate { OnDeviceCreated(); };
            graphicsService.DeviceResetting += delegate { OnDeviceResetting(); };
            graphicsService.DeviceReset += delegate { OnDeviceReset(); };

            // Here's the trick... We know it's a form, so let's cast it as a form!
            // No need to say that this won't work on the Xbox 360...
            windowsGameForm = Control.FromHandle(Game.Window.Handle) as Form;

            // After, we add up our own components to it
            InitializeComponent();
            Game.Window.Title = "nu";

            // We can then map events to the components like in a normal Windows Forms context
            //someButton.Click += new EventHandler(someButton_Click);
            //quitMenuItem.Click += delegate { Game.Exit(); };

            // And force a reset so that we set the right target to begin with
            graphicsDevice.Reset();

            base.Initialize();
        }
 internal XNASwapChainImplementation(XNA.GraphicsDeviceManager gdManager, IntPtr windowHandle, PresentationParameters presentParams)
 {
     _gdManager             = gdManager;
     _graphicsDevice        = gdManager.GraphicsDevice;
     _windowHandle          = windowHandle;
     _presentParams         = presentParams;
     _pp                    = new XFG.PresentationParameters();
     _pp.DeviceWindowHandle = windowHandle;
     _pp.IsFullScreen       = false;
     _pp.DisplayOrientation = XNA.DisplayOrientation.Default;
     SetXNAPresentationParameters(presentParams);
     _graphicsDevice.Reset(_pp);
 }
Esempio n. 4
0
        /// <summary>
        /// Constructor is private, because this is a singleton class:
        /// client controls should use the public AddRef method instead.
        /// </summary>
        private GraphicsDeviceService(IntPtr windowHandle, int width, int height) {
            parameters = new PresentationParameters {
                BackBufferWidth = Math.Max(width, 1),
                BackBufferHeight = Math.Max(height, 1),
                BackBufferFormat = SurfaceFormat.Color,
                DepthStencilFormat = DepthFormat.Depth24,
                DeviceWindowHandle = windowHandle,
                PresentationInterval = PresentInterval.Immediate,
                IsFullScreen = false
            };

            //graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters);
            graphicsDevice = new GraphicsDevice();
            graphicsDevice.GraphicsProfile = GraphicsProfile.Reach;
            graphicsDevice.Reset(parameters, GraphicsAdapter.DefaultAdapter);
        }
        public override void End()
        {
            base.End();

            if (device.GraphicsDeviceStatus == GraphicsDeviceStatus.Lost)
            {
                throw new DeviceLostException();
            }

            if (device.GraphicsDeviceStatus == GraphicsDeviceStatus.NotReset)
            {
                device.Reset();
            }

            var previousState = device.RasterizerState;

            device.RasterizerState = rasterizerState;

            DrawTriangleBuffer();

            device.RasterizerState = previousState;
        }
Esempio n. 6
0
        private void InitializeMainScrn()
        {
            mainScreen = new MainScreen();

            PresentationParameters pp = new PresentationParameters();
            pp.BackBufferCount = 1;
            pp.IsFullScreen = false;
            pp.SwapEffect = SwapEffect.Discard;
            pp.BackBufferWidth = mainScreen.canvas.Width;
            pp.BackBufferHeight = mainScreen.canvas.Height;

            pp.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8;
            pp.EnableAutoDepthStencil = true;
            pp.PresentationInterval = PresentInterval.Default;
            pp.BackBufferFormat = SurfaceFormat.Unknown;
            pp.MultiSampleType = MultiSampleType.None;

            mainDevice = new GraphicsDevice( GraphicsAdapter.DefaultAdapter,
                DeviceType.Hardware, this.mainScreen.canvas.Handle,
                pp );

            mainScreen.canvas.SizeChanged += new EventHandler( mainScreen_canvas_SizeChanged );
            mainScreen.canvas.Paint += new EventHandler( mainScreen_canvas_Paint );

            mainDevice.Reset();

            mainScreen.Show( dockPanel, DockState.Document );

            mainScrnBatch = new SpriteBatch( mainDevice );

            //BasicGraphics.Initial( mainDevice );
        }
Esempio n. 7
0
        /// <summary>
        /// Method to instantiate and initialize a graphics device
        /// </summary>
        private void CreateDevice()
        {
            PresentationParameters presentation = new PresentationParameters();
            presentation.AutoDepthStencilFormat = DepthFormat.Depth24;
            presentation.BackBufferCount = 1;
            presentation.BackBufferFormat = SurfaceFormat.Color;
            System.Drawing.Rectangle a = this.scrMainLayout.Panel2.Bounds;
            presentation.BackBufferWidth = a.Width;
            presentation.BackBufferHeight = a.Height;
            presentation.DeviceWindowHandle = this.Handle;
            presentation.EnableAutoDepthStencil = true;
            presentation.FullScreenRefreshRateInHz = 0;
            presentation.IsFullScreen = false;
            presentation.MultiSampleQuality = 0;
            presentation.MultiSampleType = MultiSampleType.None;
            presentation.PresentationInterval = PresentInterval.One;
            presentation.PresentOptions = PresentOptions.None;
            presentation.SwapEffect = SwapEffect.Discard;
            presentation.RenderTargetUsage = RenderTargetUsage.DiscardContents;

            gfxDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, this.scrMainLayout.Panel2.Handle,
                presentation);
            gfxDevice.RenderState.CullMode = CullMode.None;

            gfxDevice.Reset();
            //Setup cliping frustum
            Viewport v = gfxDevice.Viewport;
            v.MinDepth = nearClip;
            v.MaxDepth = farClip;
            gfxDevice.Viewport = v;
        }
        public bool CreateGraphicsContext(IntPtr hwnd, ref PresentationParameters pp)
        {
            //define presentation parameters
            pp = new PresentationParameters();
            pp.BackBufferFormat = SurfaceFormat.Color;
            pp.DeviceWindowHandle = hwnd;
            pp.IsFullScreen = false;
            pp.BackBufferHeight = Control.FromHandle(hwnd).Height;
            pp.BackBufferWidth = Control.FromHandle(hwnd).Width;
            //Initialize Z-buffer - need this for winform
            pp.DepthStencilFormat = DepthFormat.Depth24;

            if (m_GraphicsDevice != null)
                return false;
            //create an XNA graphics device
            m_GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
                    GraphicsProfile.HiDef,
                    pp);

            m_DefaultState = new RasterizerState();
            m_DefaultState.CullMode = CullMode.None;
            m_DefaultState.FillMode = FillMode.Solid;
            m_GraphicsDevice.RasterizerState = m_DefaultState;

            //check if graphics device was created
            Debug.Assert(m_GraphicsDevice != null, "XNA Graphics Device did not Initialize");

            m_GraphicsDevice.Reset();
            m_GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            RGraphicsDeviceService gS = new RGraphicsDeviceService();
            gS.GraphicsDevice = m_GraphicsDevice;
            mService = new RGameView();
            mService.SetService(gS);
            mResources = new ContentManager(mService);
            mResources.RootDirectory = "./Content/";

            Initialize();

            return true;
        }
Esempio n. 9
0
 /// <summary>
 /// This is needed for multi-screen setups, where the device is killed and reset
 /// whenever the window is tossed from one screen to another. Probably other situations 
 /// would cause the device to be re-created too, so make sure you have it.
 /// </summary>
 void OnDeviceCreated()
 {
     graphicsDevice = graphicsService.GraphicsDevice;
     graphicsDevice.Reset();
 }