Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace Mist
- {
- /// <summary>
- /// The graphics module controls all graphical rendering in the engine
- /// </summary>
- public class Graphics : IGraphicsDeviceService
- {
- /// <summary>
- /// The graphics device that we'll use for rendering
- /// </summary>
- private GraphicsDevice Device;
- /// <summary>
- /// The presentation paramters is basically device initialization data
- /// </summary>
- private PresentationParameters DeviceData;
- /// <summary>
- /// Occurs when we finally get added to the engine.
- /// </summary>
- protected override void Initialize()
- {
- base.Initialize();
- // Tell the engine to add us as a service
- // Note that 'Services' is my implementation of IServiceContainer
- this.Engine.Services.AddService<IGraphicsDeviceService>(this);
- }
- /// <summary>
- /// An event that occurs when the device is initially created
- /// </summary>
- public event EventHandler<EventArgs> DeviceCreated;
- /// <summary>
- /// An event that occurs when the device is disposing
- /// </summary>
- public event EventHandler<EventArgs> DeviceDisposing;
- /// <summary>
- /// An event that occurs when the device is reset
- /// </summary>
- public event EventHandler<EventArgs> DeviceReset;
- /// <summary>
- /// An event that occurs when the device is resetting
- /// </summary>
- public event EventHandler<EventArgs> DeviceResetting;
- /// <summary>
- /// Gets the graphics device from the graphics manager
- /// </summary>
- public GraphicsDevice GraphicsDevice
- {
- get { return this.Device; }
- }
- /// <summary>
- /// Initialize the graphics device
- /// </summary>
- /// <param name="windowHandle">The handle to the window we'd like to draw to</param>
- /// <param name="width">The width of the back buffer</param>
- /// <param name="height">The height of the back buffer</param>
- private void SetupGraphics(IntPtr windowHandle, Int32 width, Int32 height)
- {
- // Fill out the presentation parameters
- this.DeviceData = new PresentationParameters();
- // Keep the contents around for the editor
- this.DeviceData.RenderTargetUsage = RenderTargetUsage.PreserveContents;
- // Set the window handle
- this.DeviceData.DeviceWindowHandle = windowHandle;
- // Set the back buffer width and height
- this.DeviceData.BackBufferWidth = width;
- this.DeviceData.BackBufferHeight = height;
- // Don't launch in full screen yet
- this.DeviceData.IsFullScreen = false;
- // Make sure we have a stencil buffer
- this.DeviceData.DepthStencilFormat = DepthFormat.Depth24Stencil8;
- // Create the new graphics device
- this.Device = new GraphicsDevice(
- GraphicsAdapter.DefaultAdapter,
- GraphicsProfile.HiDef,
- this.DeviceData);
- // If we have any listeners to the device created event...
- if (this.DeviceCreated != null)
- {
- this.DeviceCreated(this, new EventArgs());
- }
- // You have to create a draw function, and manually call it!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment