/// <summary> /// Simple initializa /// </summary> public GraphicsDevice InitializeDevice() { GraphicsService init = Service; // Create device. RenderTargetParameters p = new RenderTargetParameters(); p.BackBufferWidth = 1024; p.BackBufferHeight = 768; p.MultiSampleType = 1; p.MultiSampleQuality = 0; p.Format = PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"); p.Windowed = true; return(init.CreateDevice(false, false, p, out window)); }
/// <summary> /// Creates the device. /// </summary> /// <param name="shared">Is the device shared (can call obtain device from other processes).</param> /// <param name="parameters">The parameters that define swap chain.</param> /// <param name="window">Window created with device (and swap chain).</param> /// <returns>Device object.</returns> public GraphicsDevice CreateDevice(bool shared, bool debug, RenderTargetParameters parameters, out Window window) { Driver.ISwapChain dr_chain; Driver.IWindowBackend dr_window; Driver.IDevice dr_device = service.Create(shared, parameters, out dr_chain, out dr_window, debug); GraphicsDevice device = new GraphicsDevice(dr_device); // For now set null for device backend. window = new Window(device, parameters.BackBufferWidth, parameters.BackBufferHeight, dr_window); SwapChain chain = new SwapChain(device, window, parameters.Format, !parameters.Windowed, dr_chain); // TODO: create depth stencil. // Intialize device. device.Initialize(chain, null); return(device); }
/// <summary> /// Obtains an already created device. /// </summary> /// <param name="parameters">Parameters for default rendering surface, may be null for shared mode only.</param> /// <returns></returns> public GraphicsDevice ObtainDevice(RenderTargetParameters parameters) { GraphicsDevice device = new GraphicsDevice(service.Obtain()); // We now create a render target. if (parameters != null) { // TODO account for multisampling. TypelessTexture2D rt = new TypelessTexture2D(Usage.Default, TextureUsage.RenderTarget, CPUAccess.None, parameters.Format, parameters.BackBufferWidth, parameters.BackBufferHeight, 1, GraphicsLocality.DeviceMemoryOnly, null); if (parameters.DepthStencilCommonFormat != CommonPixelFormatLayout.NotCommonLayout) { TypelessTexture2D dt = new TypelessTexture2D(Usage.Default, TextureUsage.DepthStencilTarget, CPUAccess.None, parameters.DepthStencilFormat, parameters.BackBufferWidth, parameters.BackBufferHeight, 1, GraphicsLocality.DeviceMemoryOnly, null); // Associate render target and depth stencil with graphics device. device.Initialize(rt.CreateRenderTarget(), dt.CreateDepthStencil()); } else { device.Initialize(rt.CreateRenderTarget(), null); } // They will be auto-bound. } else { device.Initialize(null, null); } return(device); }