public IGraphicsDevice CreateDevice(DeviceCreationFlags flags) { this.Visible = true; GraphicsContext context = (GraphicsContext)this.Context; return(new GraphicsDevice(this, this, context, flags)); }
public D3D11GraphicsDevice(GraphicsDeviceOptions options, SwapchainDescription?swapchainDesc) { #if DEBUG DeviceCreationFlags creationFlags = DeviceCreationFlags.Debug; #else DeviceCreationFlags creationFlags = options.Debug ? DeviceCreationFlags.Debug : DeviceCreationFlags.None; #endif _device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags); if (swapchainDesc != null) { SwapchainDescription desc = swapchainDesc.Value; _mainSwapchain = new D3D11Swapchain(_device, ref desc); } _immediateContext = _device.ImmediateContext; _device.CheckThreadingSupport(out _supportsConcurrentResources, out _supportsCommandLists); Features = new GraphicsDeviceFeatures( computeShader: true, geometryShader: true, tessellationShaders: true, multipleViewports: true, samplerLodBias: true, drawBaseVertex: true, drawBaseInstance: true, fillModeWireframe: true, samplerAnisotropy: true, depthClipDisable: true, texture1D: true, independentBlend: true); _d3d11ResourceFactory = new D3D11ResourceFactory(this); PostDeviceCreated(); }
public Renderer() { if (Instance != null) { throw CargoEngineException.Create("multiple instances of renderer"); } Instance = this; DeviceCreationFlags devFlags = 0; #if DEBUG devFlags |= DeviceCreationFlags.Debug; #endif Device = new Device(SharpDX.Direct3D.DriverType.Hardware, devFlags); ImmPipeline = new RenderPipeline(Device.ImmediateContext); inputLayouts = new Dictionary <int, InputLayout>(); for (var i = 0; i < NUM_THREADS; i++) { var pipeline = new RenderPipeline(Device); deferredPipelines[i] = pipeline; } Shaders = new ShaderLoader(this); }
public virtual void CreateDeviceResources() { // This flag adds support for surfaces with a different color channel ordering // than the API default. It is required for compatibility with Direct2D. DeviceCreationFlags creationFlags = DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug; // This array defines the set of DirectX hardware feature levels this app will support. // Note the ordering should be preserved. // Don't forget to declare your application's minimum required feature level in its // description. All applications are assumed to support 9.1 unless otherwise stated. SharpDX.Direct3D.FeatureLevel[] featureLevels = { SharpDX.Direct3D.FeatureLevel.Level_11_1, SharpDX.Direct3D.FeatureLevel.Level_11_0, SharpDX.Direct3D.FeatureLevel.Level_10_1, SharpDX.Direct3D.FeatureLevel.Level_10_0, SharpDX.Direct3D.FeatureLevel.Level_9_3 }; // Dispose previous references and set to null RemoveAndDispose(ref _device); RemoveAndDispose(ref _deviceContext); // Create the Direct3D 11 API device object and a corresponding context. using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags, featureLevels)) _device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); _featureLevel = _device.FeatureLevel; //_deviceContext = new DeviceContext(_device); // <== this was creating a deffered context // Get Direct3D 11.1 context _deviceContext = ToDispose(_device.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>()); }
public unsafe static Result D3D11On12CreateDevice( IUnknown d3d12Device, DeviceCreationFlags flags, FeatureLevel[] featureLevels, IUnknown[] commandQueues, int nodeMask, out ID3D11Device device, out ID3D11DeviceContext immediateContext, out FeatureLevel chosenFeatureLevel) { var result = D3D11On12CreateDevice(d3d12Device, flags, featureLevels, featureLevels.Length, commandQueues, commandQueues.Length, nodeMask, out device, out immediateContext, out chosenFeatureLevel); if (result.Failure) { return(result); } if (immediateContext != null) { device.AddRef(); device.ImmediateContext__ = immediateContext; immediateContext.Device__ = device; } return(result); }
private static Result RawD3D11CreateDeviceNoContext( IntPtr adapterPtr, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device?device, out FeatureLevel featureLevel) { device = default; fixed(void *featureLevelsPtr = &featureLevels[0]) fixed(void *featureLevelPtr = &featureLevel) { IntPtr devicePtr = IntPtr.Zero; Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? featureLevelsPtr : null, featureLevels?.Length ?? 0, SdkVersion, &devicePtr, featureLevelPtr, null); if (result.Success && devicePtr != IntPtr.Zero) { device = new ID3D11Device(devicePtr); } return(result); } }
private void InitDeviceAndSwapChain(SwapChainDescription currentDescription) { DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG // flags |= DeviceCreationFlags.Debug; #endif flags |= DeviceCreationFlags.SingleThreaded; DriverType type; #if SOFTWARE type = DriverType.Warp; #else type = DriverType.Hardware; #endif Device.CreateWithSwapChain(null, type, flags, currentDescription, out device, out swapChain); // Stops Alt + Enter from causing fullscreen skrewiness. using (Factory factory = swapChain.GetParent <Factory>()) { factory.SetWindowAssociation(renderFrame.Handle, WindowAssociationFlags.IgnoreAltEnter); } }
public void Recreate(GraphicsAdapter adapter, GraphicsProfile[] profile, DeviceCreationFlags deviceCreationFlags, WindowHandle windowHandle) { if (adapter == null) { throw new ArgumentNullException("adapter"); } if (profile == null) { throw new ArgumentNullException("profile"); } Adapter = adapter; IsDebugMode = (deviceCreationFlags & DeviceCreationFlags.Debug) != 0; // Initialize this instance InitializePlatformDevice(profile, deviceCreationFlags, windowHandle); InitializeFactories(); // Create a new graphics device Features = new GraphicsDeviceFeatures(this); SamplerStates = new SamplerStateFactory(this); BlendStates = new BlendStateFactory(this); RasterizerStates = new RasterizerStateFactory(this); DepthStencilStates = new DepthStencilStateFactory(this); currentState = null; allocatedStates.Clear(); currentStateIndex = -1; PushState(); ClearState(); }
public DxDevice(DXGIFactory factory, DXGIAdapter adapter, DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport) { this.WICFactory = new WICFactory(); this.D2DFactory = new D2DFactory(); this.DWriteFactory = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared); this.adapterindex = 0; FeatureLevel[] levels = new FeatureLevel[] { #if DIRECTX11_1 FeatureLevel.Level_11_1, #endif FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3 }; var dev = new Device(adapter, flags, levels); #if DIRECTX11_1 this.Device = dev.QueryInterface <DirectXDevice>(); Marshal.Release(this.Device.NativePointer); #else this.Device = dev; #endif this.Adapter = adapter; this.Factory = factory; this.OnLoad(); }
private static Result RawD3D11CreateDeviceNoDeviceAndContext( IntPtr adapterPtr, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out FeatureLevel featureLevel) { unsafe { fixed(void *featureLevelsPtr = &featureLevels[0]) fixed(void *featureLevelPtr = &featureLevel) { Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? featureLevelsPtr : null, featureLevels?.Length ?? 0, SdkVersion, null, featureLevelPtr, null); return(result); } } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Device" /> class along with a new <see cref = "T:SharpDX.DXGI.SwapChain" /> used for rendering. /// </summary> /// <param name = "driverType">The type of device to create.</param> /// <param name = "flags">A list of runtime layers to enable.</param> /// <param name = "featureLevels">A list of feature levels which determine the order of feature levels to attempt to create.</param> /// <param name = "swapChainDescription">Details used to create the swap chain.</param> /// <param name = "device">When the method completes, contains the created device instance.</param> /// <param name = "swapChain">When the method completes, contains the created swap chain instance.</param> /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns> public static void CreateWithSwapChain(DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, SwapChainDescription swapChainDescription, out Device device, out SwapChain swapChain) { CreateWithSwapChain(null, driverType, flags, featureLevels, swapChainDescription, out device, out swapChain); }
private void CreateAndInitializeDevice() { var swapChainDescription = new SwapChainDescription() { BufferCount = 1, IsWindowed = true, ModeDescription = new ModeDescription(renderForm.ClientSize.Width, renderForm.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), OutputHandle = renderForm.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, flags, swapChainDescription, out device, out swapChain); deviceContext = device.ImmediateContext; #if TEXT_RENDERER __2dGraphicsDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(device); #endif var factory = SwapChain.GetParent <Factory>(); factory.MakeWindowAssociation(renderForm.Handle, WindowAssociationFlags.IgnoreAll); SetRasterizerState(); SetDepthBufferState(); SetSamplerState(); SetBlendState(); CreateConstantBuffers(); renderForm.Resize += OnFormResized; PerformResizing(); SetRegularTargets(); }
public void LoadDirect3D() { // Set up description of swap chain SwapChainDescription scd = new SwapChainDescription(); scd.BufferCount = 1; scd.ModeDescription = new ModeDescription(Width, Height, new Rational(60, 1), Format.B8G8R8A8_UNorm); scd.Usage = Usage.RenderTargetOutput; scd.OutputHandle = Handle; scd.SampleDescription.Count = 1; scd.SampleDescription.Quality = 0; scd.IsWindowed = true; scd.ModeDescription.Width = Width; scd.ModeDescription.Height = Height; // Create device and swap chain according to the description above SharpDX.Direct3D11.Device d; SwapChain sc; DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, flags, scd, out d, out sc); this.SwapChain = sc; // we have to use these temp variables Context.LoadDirect3D(d); UpdateSize(); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.Device" /> class along with a new <see cref = "T:SharpDX.DXGI.SwapChain" /> used for rendering. /// </summary> /// <param name = "adapter">The video adapter on which the device should be created.</param> /// <param name = "flags">A list of runtime layers to enable.</param> /// <param name = "featureLevels">A list of feature levels which determine the order of feature levels to attempt to create.</param> /// <param name = "swapChainDescription">Details used to create the swap chain.</param> /// <param name = "device">When the method completes, contains the created device instance.</param> /// <param name = "swapChain">When the method completes, contains the created swap chain instance.</param> /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns> public static void CreateWithSwapChain(Adapter adapter, DeviceCreationFlags flags, FeatureLevel[] featureLevels, SwapChainDescription swapChainDescription, out Device device, out SwapChain swapChain) { CreateWithSwapChain(adapter, DriverType.Unknown, flags, featureLevels, swapChainDescription, out device, out swapChain); }
public virtual DX11RenderContext GetRenderContext(DXGIScreen screen) { this.logger.Log(LogType.Message, "Creating DX11 Render Context"); T key = this.GetDeviceKey(screen); if (!contexts.ContainsKey(key)) { DX11RenderContext ctx; #if DEBUG try { ctx = new DX11RenderContext(this.displaymanager.Factory, screen, this.flags); } catch { this.logger.Log(LogType.Warning, "Could not create debug device, if you want debug informations make sure DirectX SDK is installed"); this.logger.Log(LogType.Warning, "Creating default DirectX 11 device"); this.flags = DeviceCreationFlags.BgraSupport; ctx = new DX11RenderContext(this.displaymanager.Factory, screen, this.flags); } #else ctx = new DX11RenderContext(this.displaymanager.Factory, screen, this.flags); #endif ctx.Initialize(); contexts.Add(key, ctx); if (this.RenderContextCreated != null) { this.RenderContextCreated(ctx); } } return(contexts[key]); }
private static D3D11MetaResource CreateCore(Adapter adapter, DriverType type, DeviceCreationFlags creationFlags, SwapChainDescription1?description, FeatureLevel[] levels, bool allowWarpFallbackDriver, SwapChainTarget target) { SwapChainDescription1 desc; if (description.HasValue) { desc = description.Value; } else { GetDefaultSwapChainDescription(out desc, target); } #if DEBUG // Note: These have no impact on solution outside // of this project. This is only for internal testing // purposes creationFlags |= DeviceCreationFlags.Debug; #endif return(new D3D11MetaResource(new D3D11MetaResourceOptions { Adapter = adapter, SwapChainDescription = desc, Target = target, Type = type, WarpFallbackEnabled = allowWarpFallbackDriver, CreationFlags = creationFlags, Levels = levels })); }
/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != null) { // Destroy previous device ReleaseDevice(); } // Profiling is supported through pix markers IsProfilingSupported = true; // Map GraphicsProfile to D3D11 FeatureLevel SharpDX.Direct3D.FeatureLevel[] levels = graphicsProfiles.ToFeatureLevel(); creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags; // Create Device D3D11 with feature Level based on profile nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, levels); nativeDeviceContext = nativeDevice.ImmediateContext; if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } InitializeStages(); // Create the input layout manager if (InputLayoutManager == null) { InputLayoutManager = new InputLayoutManager(this).DisposeBy(this); } }
public static Result D3D11CreateDevice(IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device, out FeatureLevel featureLevel, out ID3D11DeviceContext immediateContext) { var result = D3D11CreateDevice(adapter, driverType, IntPtr.Zero, (int)flags, featureLevels, (featureLevels != null) ? featureLevels.Length : 0, SdkVersion, out device, out featureLevel, out immediateContext); if (result.Failure) { return(result); } if (immediateContext != null) { device.AddRef(); device.ImmediateContext__ = immediateContext; immediateContext.Device__ = device; } return(result); }
private void InitDirect3D() { SwapChainDescription sd = new SwapChainDescription { ModeDescription = new ModeDescription(Width, Height, new SlimDX.Rational(60, 1), Format.R8G8B8A8_UNorm), SampleDescription = new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, BufferCount = 1, OutputHandle = Handle, IsWindowed = true, SwapEffect = SwapEffect.Discard, Flags = SwapChainFlags.None }; // Create the device DeviceCreationFlags createDeviceFlags = DeviceCreationFlags.None; #if DEBUG createDeviceFlags |= DeviceCreationFlags.Debug; #endif SlimDX.Direct3D10.Device.CreateWithSwapChain(null, DriverType.Hardware, createDeviceFlags, sd, out _d3dDevice, out _swapChain); ResizeBackBuffer(); }
private static Result RawD3D11CreateDeviceNoDeviceAndContext( IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out FeatureLevel featureLevel) { unsafe { var adapterPtr = CppObject.ToCallbackPtr <IDXGIAdapter>(adapter); fixed(void *featureLevelPtr = &featureLevel) { Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? Unsafe.AsPointer(ref featureLevels[0]) : null, featureLevels?.Length ?? 0, SdkVersion, null, featureLevelPtr, null); GC.KeepAlive(adapter); return(result); } } }
public void Recreate(GraphicsAdapter adapter, GraphicsProfile[] profile, DeviceCreationFlags deviceCreationFlags, WindowHandle windowHandle) { if (adapter == null) { throw new ArgumentNullException("adapter"); } if (profile == null) { throw new ArgumentNullException("profile"); } Adapter = adapter; IsDebugMode = deviceCreationFlags == DeviceCreationFlags.Debug || deviceCreationFlags == DeviceCreationFlags.DebugAndBreak || deviceCreationFlags == DeviceCreationFlags.DebugAndBreakUnique || deviceCreationFlags == DeviceCreationFlags.DebugAndLogUnique; // Initialize this instance InitializePlatformDevice(profile, deviceCreationFlags, windowHandle); // Create a new graphics device Features = new GraphicsDeviceFeatures(this); SamplerStates = new SamplerStateFactory(this); var defaultPipelineStateDescription = new PipelineStateDescription(); defaultPipelineStateDescription.SetDefaults(); AdjustDefaultPipelineStateDescription(ref defaultPipelineStateDescription); DefaultPipelineState = PipelineState.New(this, ref defaultPipelineStateDescription, null); InitializePostFeatures(); }
public IGraphicsDevice CreateDevice(DeviceCreationFlags flags) { //SDL2 supported das Einbinden in ein Fenster nicht Toolkit toolkit = Toolkit.Init(new ToolkitOptions() { Backend = PlatformBackend.PreferNative }); if (OpenTK.Configuration.RunningOnWindows) { WindowInfo = Utilities.CreateWindowsWindowInfo(control.Handle); } else if (OpenTK.Configuration.RunningOnMacOS) { WindowInfo = Utilities.CreateMacOSWindowInfo(control.Handle); } GraphicsContextFlags contextFlags = GraphicsContextFlags.Default; if (flags.HasFlag(DeviceCreationFlags.Debug)) { contextFlags = GraphicsContextFlags.Debug; } GraphicsContext context = new GraphicsContext(GraphicsMode.Default, WindowInfo, 4, 5, contextFlags); context.LoadAll(); return(new GraphicsDevice(this, this, context, flags)); }
public void CreateDevice(object hostControl, DeviceCreationFlags flags) { OnDeviceChangeBegin(this, EventArgs.Empty); // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(PreferredBackBufferWidth, PreferredBackBufferHeight, new Rational(60, 1), PreferredBackBufferFormat), IsWindowed = true, OutputHandle = (IntPtr)hostControl, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; IsDebugMode = flags.HasFlag(DeviceCreationFlags.Debug); var device = ToDispose(new Device(DriverType.Hardware, flags, PreferredGraphicsProfile[0])); this.device = ToDispose(device.QueryInterface <Device1>()); var factory = ToDispose(new Factory1()); swapChain = ToDispose(new SwapChain(factory, device, desc)); factory.MakeWindowAssociation(swapChain.Description.OutputHandle, WindowAssociationFlags.IgnoreAll); // New RenderTargetView from the backbuffer backBuffer = ToDispose(Resource.FromSwapChain <Texture2D>(swapChain, 0)); renderTargetView = ToDispose(new RenderTargetView(device, backBuffer)); context = ToDispose(this.device.ImmediateContext.QueryInterface <DeviceContext1>()); OnDeviceCreated(this, EventArgs.Empty); OnDeviceChangeEnd(this, EventArgs.Empty); }
public D3D11GraphicsDevice(IntPtr hwnd, int width, int height) { SwapChainDescription swapChainDescription = new SwapChainDescription() { BufferCount = 1, IsWindowed = true, ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm), OutputHandle = hwnd, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; #if DEBUG DeviceCreationFlags creationFlags = DeviceCreationFlags.Debug; #else DeviceCreationFlags creationFlags = DeviceCreationFlags.None; #endif SharpDX.Direct3D11.Device.CreateWithSwapChain( SharpDX.Direct3D.DriverType.Hardware, creationFlags, swapChainDescription, out _device, out _swapChain); _immediateContext = _device.ImmediateContext; _device.CheckThreadingSupport(out _supportsConcurrentResources, out _supportsCommandLists); Factory factory = _swapChain.GetParent <Factory>(); factory.MakeWindowAssociation(hwnd, WindowAssociationFlags.IgnoreAll); ResourceFactory = new D3D11ResourceFactory(this); RecreateSwapchainFramebuffer(width, height); PostContextCreated(); }
public void Initialize() { SwapChainDescription scdesc = new SwapChainDescription() { BufferCount = 1, IsWindowed = true, Flags = SwapChainFlags.None, ModeDescription = new ModeDescription(Width, Height, new Rational(60, 1), Format.B8G8R8A8_UNorm), OutputHandle = Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, flags, scdesc, out SharpDX.Direct3D11.Device device, out SwapChain sc); DXGISwapChain = sc; D3DDevice = device; D3DContext = D3DDevice.ImmediateContext; Backbuffer = DXGISwapChain.GetBackBuffer <Texture2D>(0); BackbufferRTV = new RenderTargetView(D3DDevice, Backbuffer); D3DContext.OutputMerger.SetRenderTargets(BackbufferRTV); Screen.OnCreate(); D3DContext.Rasterizer.SetViewport(new Viewport(0, 0, Width, Height)); Screen.OnCreateBuffers(); watch = new System.Diagnostics.Stopwatch(); watch.Start(); Application.Idle += OnTick; }
public Direct3D11Base(Form form, SwapChainDescription swapDesc, Adapter adapter = null, DriverType type = DriverType.Hardware, DeviceCreationFlags flags = DeviceCreationFlags.None, FeatureLevel[] levels = null) { IsDisposed = false; try { _isInitializing = true; _form = form; _isComposited = DwmApi.IsCompositionEnabled; if (_isComposited) { DwmApi.EnableMMCSS(true); DwmPresentParameters present = new DwmPresentParameters() { IsQueued = true, BufferCount = 2, RefreshesPerFrame = 1, }; DwmApi.SetPresentParameters(form.Handle, ref present); } if (swapDesc.OutputHandle != IntPtr.Zero) { throw new ArgumentException("Output handle must not be set."); } if (swapDesc.Usage != Usage.RenderTargetOutput) { throw new ArgumentException("Usage must be RenderTargetOutput."); } swapDesc.OutputHandle = _form.Handle; bool setFullscreen = !swapDesc.IsWindowed; swapDesc.IsWindowed = true; Device.CreateWithSwapChain(adapter, type, DeviceCreationFlags.None, levels, swapDesc, out _device, out _swapChain); _swapChain.ResizeTarget(swapDesc.ModeDescription); _factory = _swapChain.GetParent<Factory>(); _factory.SetWindowAssociation(_form.Handle, WindowAssociationFlags.IgnoreAll); _form.SizeChanged += SizeChanged_Handler; _form.ResizeBegin += ResizeBegin_Handler; _form.Resize += Resize_Handler; _form.ResizeEnd += ResizeEnd_Handler; _form.KeyDown += KeyDown_Handler; if (setFullscreen) { ChangeMode(true); } _isInitializing = false; } catch { Dispose(); throw; } }
public DX11RenderContext(Factory1 factory, DXGIScreen screen, DeviceCreationFlags flags = DeviceCreationFlags.None) { this.Factory = factory; this.Screen = screen; this.Device = new Device(screen.Adapter, flags, GetFeatureLevels()); this.immediatecontext = this.Device.ImmediateContext; this.CurrentDeviceContext = this.immediatecontext; }
public static Result D3D11CreateDevice(IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device) { return(D3D11CreateDevice(adapter, driverType, flags, featureLevels, out device, out var featureLevel, out var immediateContext)); }
public DX11RenderContext(Factory1 factory, DXGIScreen screen, DeviceCreationFlags flags = DeviceCreationFlags.None) { this.Factory = factory; this.Screen = screen; this.Device = new Device(screen.Adapter, flags); this.immediatecontext = this.Device.ImmediateContext; this.CurrentDeviceContext = this.immediatecontext; }
public DX11RenderContext(Adapter1 adapter, DeviceCreationFlags flags = DeviceCreationFlags.None) { this.Device = new Device(adapter, flags, GetFeatureLevels()); this.Adapter = adapter; this.Factory = this.Device.Factory as Factory1; this.immediatecontext = this.Device.ImmediateContext; this.CurrentDeviceContext = this.immediatecontext; }
public D3D11DxgiOptions(Adapter adapter, DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded, FeatureLevel[] levels = null, bool warpFallbackEnabled = true) { this.Adapter = adapter; this.CreationFlags = flags; this.Levels = levels; this.WarpFallbackEnabled = warpFallbackEnabled; }
public D3D11DxgiOptions(DriverType type, DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded, FeatureLevel[] levels = null, bool warpFallbackEnabled = true) { this.Type = type; this.CreationFlags = flags; this.Levels = levels; this.WarpFallbackEnabled = warpFallbackEnabled; }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Device1" /> class along with a new <see cref = "T:SharpDX.DXGI.SwapChain" /> used for rendering. /// </summary> /// <param name = "driverType">The type of device to create.</param> /// <param name = "flags">A list of runtime layers to enable.</param> /// <param name = "swapChainDescription">Details used to create the swap chain.</param> /// <param name="featureLevel">Desired feature level</param> /// <param name = "device">When the method completes, contains the created device instance.</param> /// <param name = "swapChain">When the method completes, contains the created swap chain instance.</param> /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns> public static void CreateWithSwapChain(DriverType driverType, DeviceCreationFlags flags, SwapChainDescription swapChainDescription, FeatureLevel featureLevel, out Device1 device, out SwapChain swapChain) { CreateWithSwapChain(null, driverType, flags, swapChainDescription, featureLevel, out device, out swapChain); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Device1" /> class along with a new <see cref = "T:SharpDX.DXGI.SwapChain" /> used for rendering. /// </summary> /// <param name = "adapter">The video adapter on which the device should be created.</param> /// <param name = "flags">A list of runtime layers to enable.</param> /// <param name = "swapChainDescription">Details used to create the swap chain.</param> /// <param name="featureLevel">Desired feature level</param> /// <param name = "device">When the method completes, contains the created device instance.</param> /// <param name = "swapChain">When the method completes, contains the created swap chain instance.</param> /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns> public static void CreateWithSwapChain(Adapter adapter, DeviceCreationFlags flags, SwapChainDescription swapChainDescription, FeatureLevel featureLevel,out Device1 device, out SwapChain swapChain) { CreateWithSwapChain(adapter, DriverType.Hardware, flags, swapChainDescription, featureLevel, out device, out swapChain); }
/// <summary> /// This overload has been deprecated. Use one of the alternatives that does not take both an adapter and a driver type. /// </summary> internal static void CreateWithSwapChain(Adapter adapter, DriverType driverType, DeviceCreationFlags flags, SwapChainDescription swapChainDescription, FeatureLevel featureLevel, out Device1 device, out SwapChain swapChain) { D3D10.CreateDeviceAndSwapChain1(adapter, driverType, IntPtr.Zero, flags, featureLevel, D3D10.SdkVersion1, ref swapChainDescription, out swapChain, out device); }
/// <summary> /// Constructor for a D3D10.1 Device. See <see cref = "SharpDX.Direct3D10.D3D10.CreateDevice1" /> for more information. /// </summary> /// <param name = "driverType"></param> /// <param name = "flags"></param> public Device1(DriverType driverType, DeviceCreationFlags flags) : this(driverType, flags, FeatureLevel.Level_10_1) { }
public GenericGraphicsDevice(DriverType type, DeviceCreationFlags flags = DeviceCreationFlags.None, params FeatureLevel[] featureLevels) : base(type, flags, featureLevels) { }
private void CreateDevice(Adapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel featureLevel) { D3D10.CreateDevice1(adapter, driverType, IntPtr.Zero, flags, featureLevel, D3D10.SdkVersion1, this); }
public DX11RenderContext(DeviceCreationFlags flags = DeviceCreationFlags.None) { this.Device = new Device(DriverType.Hardware,flags); this.immediatecontext = this.Device.ImmediateContext; this.CurrentDeviceContext = this.immediatecontext; }
public DX11RenderContext(Adapter1 adapter, DeviceCreationFlags flags = DeviceCreationFlags.None) { this.Device = new Device(adapter, flags); this.immediatecontext = this.Device.ImmediateContext; this.CurrentDeviceContext = this.immediatecontext; }
/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != null) { // Destroy previous device ReleaseDevice(); } rendererName = Adapter.NativeAdapter.Description.Description; // Profiling is supported through pix markers IsProfilingSupported = true; // Map GraphicsProfile to D3D11 FeatureLevel creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags; // Default fallback if (graphicsProfiles.Length == 0) graphicsProfiles = new[] { GraphicsProfile.Level_11_0, GraphicsProfile.Level_10_1, GraphicsProfile.Level_10_0, GraphicsProfile.Level_9_3, GraphicsProfile.Level_9_2, GraphicsProfile.Level_9_1 }; // Create Device D3D11 with feature Level based on profile for (int index = 0; index < graphicsProfiles.Length; index++) { var graphicsProfile = graphicsProfiles[index]; try { // D3D12 supports only feature level 11+ var level = graphicsProfile.ToFeatureLevel(); // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10. if (Adapter.VendorId == 0x8086) { if (level < SharpDX.Direct3D.FeatureLevel.Level_10_0) level = SharpDX.Direct3D.FeatureLevel.Level_10_0; } nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, level); // INTEL workaround: force ShaderProfile to be 10+ as well if (Adapter.VendorId == 0x8086) { if (graphicsProfile < GraphicsProfile.Level_10_0 && (!ShaderProfile.HasValue || ShaderProfile.Value < GraphicsProfile.Level_10_0)) ShaderProfile = GraphicsProfile.Level_10_0; } RequestedProfile = graphicsProfile; break; } catch (Exception) { if (index == graphicsProfiles.Length - 1) throw; } } nativeDeviceContext = nativeDevice.ImmediateContext; if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } }
/// <summary> /// Constructor for a D3D10.1 Device. See <see cref = "SharpDX.Direct3D10.D3D10.CreateDevice1" /> for more information. /// </summary> /// <param name = "adapter"></param> /// <param name = "flags"></param> /// <param name="featureLevel"></param> public Device1(Adapter adapter, DeviceCreationFlags flags, FeatureLevel featureLevel) : base(IntPtr.Zero) { CreateDevice(adapter, DriverType.Hardware, flags, featureLevel); }
/// <summary> /// Constructor for a D3D10.1 Device. See <see cref = "SharpDX.Direct3D10.D3D10.CreateDevice1" /> for more information. /// </summary> /// <param name = "driverType"></param> /// <param name = "flags"></param> /// <param name="featureLevel"></param> public Device1(DriverType driverType, DeviceCreationFlags flags, FeatureLevel featureLevel) : base(IntPtr.Zero) { CreateDevice(null, driverType, flags, featureLevel); }
public GenericGraphicsDevice(GraphicsAdapter adapter, DeviceCreationFlags flags = DeviceCreationFlags.None, params FeatureLevel[] featureLevels) : base(adapter, flags, featureLevels) { }
/// <summary> /// Constructor for a D3D10.1 Device. See <see cref = "SharpDX.Direct3D10.D3D10.CreateDevice1" /> for more information. /// </summary> /// <param name = "adapter"></param> /// <param name = "flags"></param> public Device1(Adapter adapter, DeviceCreationFlags flags) : this(adapter, flags, FeatureLevel.Level_10_1) { }
/// <summary> /// Create our OutsideWindow app, but do not initialize Direct3D. /// </summary> /// <param name="hInstance">hInstance of the application</param> protected OutsideWindowBase(IntPtr hInstance) { AppInst = hInstance; MainWindowCaption = "Outside Engine"; ClientWidth = 800; ClientHeight = 600; Window = null; AppPaused = false; Minimized = false; Maximized = false; Resizing = false; _isD3DInitialized = false; BackBufferFormat = Format.R8G8B8A8_UNorm; DepthStencilBufferFormat = Format.D24_UNorm_S8_UInt; DeviceCreationFlags = DeviceCreationFlags.None; #if DEBUG //DeviceCreationFlags |= DeviceCreationFlags.Debug; //DeviceCreationFlags |= DeviceCreationFlags.SingleThreaded; #endif SampleDescription = new SampleDescription(1, 0); DriverType = DriverType.Hardware; Device = null; ImmediateContext = null; SwapChain = null; DepthStencilView = null; DepthStencilBuffer = null; RenderTargetView = null; Viewport = new Viewport(); Timer = new GameTimer(); }
/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != null) { // Destroy previous device ReleaseDevice(); } // Profiling is supported through pix markers IsProfilingSupported = true; // Map GraphicsProfile to D3D11 FeatureLevel SharpDX.Direct3D.FeatureLevel[] levels = graphicsProfiles.ToFeatureLevel(); creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags; // Create Device D3D11 with feature Level based on profile nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, levels); nativeDeviceContext = nativeDevice.ImmediateContext; if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } InitializeStages(); // Create the input layout manager if (InputLayoutManager == null) InputLayoutManager = new InputLayoutManager(this).DisposeBy(this); }