当前位置: 首页>>代码示例>>C#>>正文


C# Device.QueryInterface方法代码示例

本文整理汇总了C#中SharpDX.Direct3D11.Device.QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C# Device.QueryInterface方法的具体用法?C# Device.QueryInterface怎么用?C# Device.QueryInterface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharpDX.Direct3D11.Device的用法示例。


在下文中一共展示了Device.QueryInterface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDeviceResources

        private 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
	        };

            // Create the Direct3D 11 API device object and a corresponding context.
            using (var defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags, featureLevels))
                _device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();

            // Get Direct3D 11.1 context
            _deviceContext = ToDispose(_device.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>());
        }
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:27,代码来源:DrawingSurfaceUpdateHandler.cs

示例2: Initialize

        public void Initialize()
        {
            DestroyResources();

            var flags = DeviceCreationFlags.BgraSupport;
            #if DEBUG
            flags |= DeviceCreationFlags.Debug;
            #endif

            var featureLevels = new[]
            {
                FeatureLevel.Level_11_1,
                FeatureLevel.Level_11_0
            };

            using(var device = new Device(DriverType.Hardware, flags, featureLevels))
            {
                Device = device.QueryInterface<Device1>();
                Context = device.ImmediateContext.QueryInterface<DeviceContext1>();
            }

            IsInitialized = true;

            // todo: Reinitialize all dependent resources by having them hook this event
            var handler = Initialized;
            if(handler != null)
                handler();
        }
开发者ID:gitter-badger,项目名称:Grasshopper,代码行数:28,代码来源:DeviceManager.cs

示例3: D3D11_2D1

		public D3D11_2D1(Device11 drawdevice, Device10 textdevice)
			: base(false) // nothing!
		{
			if (drawdevice == null || textdevice == null)
			{
				using (var dg = new DisposeGroup())
				{
					if (drawdevice == null && textdevice == null)
					{
						Adapter a = null;
						foreach (var item in DeviceUtil.GetAdapters(dg))
						{
							if (!item.IsInterfaceSupported<Device10>())
								continue;
							if (Device11.GetSupportedFeatureLevel(item) < Direct3D.FeatureLevel.Level_10_1)
								continue;
							a = item;
							break;
						}
						device = new Device11(a, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.Debug);
						device10 = new Device10(a, Direct3D10.DeviceCreationFlags.BgraSupport | Direct3D10.DeviceCreationFlags.Singlethreaded | Direct3D10.DeviceCreationFlags.Debug);
					}
					else
					{
						if (drawdevice == null)
						{
							using (var xgidtext = textdevice.QueryInterface<DeviceXGI>())
								device = new Device11(xgidtext.Adapter, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.Debug);
							textdevice.AddReference();
							device10 = textdevice;
						}
						else
						{
							using (var xgiddraw = drawdevice.QueryInterface<DeviceXGI>())
								device10 = new Device10(xgiddraw.Adapter, Direct3D10.DeviceCreationFlags.BgraSupport | Direct3D10.DeviceCreationFlags.Singlethreaded | Direct3D10.DeviceCreationFlags.Debug);
							drawdevice.AddReference();
							device = drawdevice;
						}
					}
				}
			}
			else
			{
				using (var xgidev10 = device10.QueryInterface<DeviceXGI>())
				using (var xgidev11 = device.QueryInterface<DeviceXGI>())
				{
					if (xgidev10.Adapter.NativePointer != xgidev11.Adapter.NativePointer)
						throw new ArgumentException("drawdevice.Adapter.NativePointer != textdevice.Adapter.NativePointer");
				}
				textdevice.AddReference();
				drawdevice.AddReference();
				device = drawdevice;
				device10 = textdevice;
			}

			factory2D = new SharpDX.Direct2D1.Factory();
			factoryDW = new FactoryDW();
		}
开发者ID:MercurialForge,项目名称:SharpDX.WPF,代码行数:58,代码来源:D3D11_2D1.cs

示例4: RendererUtil

        public RendererUtil()
        {
            var defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport);

            d3dDevice = defaultDevice.QueryInterface<D3D11.Device1>();
            dxgiDevice = d3dDevice.QueryInterface<Device>();

            d2dFactory = new D2D.Factory(D2D.FactoryType.MultiThreaded);

            d2dDevice = new D2D.Device(dxgiDevice);
            d2dDeviceContext = new D2D.DeviceContext(d2dDevice, D2D.DeviceContextOptions.None);

            imagingFactory = new ImagingFactory2();
        }
开发者ID:rantingmong,项目名称:blocm,代码行数:14,代码来源:RendererUtil.cs

示例5: CreateDeviceResources

        // Initialize hardware-dependent resources.
        private void CreateDeviceResources()
        {
            // Unlike the original C++ sample, we don't have smart pointers so we need to
            // dispose Direct3D objects explicitly
            Utilities.Dispose(ref d3dDevice);
            Utilities.Dispose(ref d2dDevice);
            Utilities.Dispose(ref d2dContext);

            // This flag adds support for surfaces with a different color channel ordering
            // than the API default. It is required for compatibility with Direct2D.
            var creationFlags = DeviceCreationFlags.BgraSupport;

#if DEBUG
            // If the project is in a debug build, enable debugging via SDK Layers.
            creationFlags |= DeviceCreationFlags.Debug;
#endif

            // 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.
            FeatureLevel[] featureLevels =
            {
                FeatureLevel.Level_11_1,
                FeatureLevel.Level_11_0,
                FeatureLevel.Level_10_1,
                FeatureLevel.Level_10_0,
                FeatureLevel.Level_9_3,
                FeatureLevel.Level_9_2,
                FeatureLevel.Level_9_1,
            };

            // Create the Direct3D 11 API device object.
            d3dDevice = new Device(DriverType.Hardware, creationFlags, featureLevels);

            // Get the Direct3D 11.1 API device.
            using (var dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>())
            {
                // Create the Direct2D device object and a corresponding context.
                d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice);

                d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, DeviceContextOptions.EnableMultithreadedOptimizations);

                // Query for ISurfaceImageSourceNative interface.
                using (var sisNative = ComObject.QueryInterface<ISurfaceImageSourceNative>(this))
                    sisNative.Device = dxgiDevice;
            }
        }
开发者ID:vulcanlee,项目名称:Windows8Lab,代码行数:49,代码来源:VulcanImageSource.cs

示例6: Load

        /// <summary>
        /// Now that we have a CoreWindow object, the DirectX device/context can be created.
        /// </summary>
        /// <param name="entryPoint"></param>
        public void Load(string entryPoint)
        {
            // Get the default hardware device and enable debugging. Don't care about the available feature level.
            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug);

            // Query the default device for the supported device and context interfaces.
            device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            context = device.ImmediateContext.QueryInterface<DeviceContext1>();

            // Query for the adapter and more advanced DXGI objects.
            SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface<SharpDX.DXGI.Device2>();
            SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter;
            SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.Factory2>();

            // Description for our swap chain settings.
            SwapChainDescription1 description = new SwapChainDescription1()
            {
                // 0 means to use automatic buffer sizing.
                Width = 0,
                Height = 0,
                // 32 bit RGBA color.
                Format = Format.B8G8R8A8_UNorm,
                // No stereo (3D) display.
                Stereo = false,
                // No multisampling.
                SampleDescription = new SampleDescription(1, 0),
                // Use the swap chain as a render target.
                Usage = Usage.RenderTargetOutput,
                // Enable double buffering to prevent flickering.
                BufferCount = 2,
                // No scaling.
                Scaling = Scaling.None,
                // Flip between both buffers.
                SwapEffect = SwapEffect.FlipSequential,
            };

            // Generate a swap chain for our window based on the specified description.
            swapChain = dxgiFactory2.CreateSwapChainForCoreWindow(device, new ComObject(window), ref description, null);

            // Create the texture and render target that will hold our backbuffer.
            Texture2D backBufferTexture = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
            backBuffer = new RenderTargetView(device, backBufferTexture);

            backBufferTexture.Dispose();
        }
开发者ID:denkapustin,项目名称:MyFirstSharpDX,代码行数:49,代码来源:MyViewProvider.cs

示例7: Renderer

        public Renderer(Device device, Form window)
        {
            // Default parameter values

            P1Color = new Vector3(1.0f, 0.0f, 0.0f);
            P2Color = new Vector3(0.0f, 1.0f, 0.0f);
            P3Color = new Vector3(0.0f, 0.0f, 1.0f);
            Wireframe = false;
            Scale = 0.5f;

            // Create swapchain for device and window

            this.window = window;
            this.device = device;

            this.factory = device.QueryInterface<DXGIDevice>().GetParent<Adapter>().GetParent<Factory>();

            this.swapChain = new SwapChain(factory, device, new SwapChainDescription()
            {
                BufferCount = 1,
                IsWindowed = true,
                Flags = SwapChainFlags.None,
                OutputHandle = window.Handle,
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput,
                SampleDescription = new SampleDescription(1, 0),
                ModeDescription = new ModeDescription()
                {
                    Width = 0,
                    Height = 0,
                    Format = Format.R8G8B8A8_UNorm,
                    RefreshRate = new Rational(60, 1),
                }
            });

            context = device.ImmediateContext;
            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);

            // Load shaders, create vertex buffers and stuff

            vertexBuffer = new Buffer(device, new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = (32 * 3),
                StructureByteStride = 16,
                Usage = ResourceUsage.Dynamic
            });

            var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "VS", "vs_4_0");
            vertexShader = new VertexShader(device, vertexShaderByteCode);

            var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "PS", "ps_4_0");
            pixelShader = new PixelShader(device, pixelShaderByteCode);

            // Get input layout from the vertex shader
            
            layout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
            });

            Resize(window.ClientSize); // first time resize
        }
开发者ID:TomCrypto,项目名称:AntTweakBar.NET,代码行数:65,代码来源:Program.cs

示例8: CreateDeviceResources

        protected virtual void CreateDeviceResources()
        {
            var creationFlags = D3D11.DeviceCreationFlags.BgraSupport;
            creationFlags |= D3D11.DeviceCreationFlags.Debug;

            var device = new D3D11.Device(D3D.DriverType.Hardware, creationFlags,
                D3D.FeatureLevel.Level_11_1,
                D3D.FeatureLevel.Level_11_0,
                D3D.FeatureLevel.Level_10_1,
                D3D.FeatureLevel.Level_10_0,
                D3D.FeatureLevel.Level_9_3,
                D3D.FeatureLevel.Level_9_2,
                D3D.FeatureLevel.Level_9_1);
            _device = device.QueryInterface<D3D11.Device1>();
            _deviceContext = device.ImmediateContext.QueryInterface<D3D11.DeviceContext1>();
        }
开发者ID:Bananattack,项目名称:ankh,代码行数:16,代码来源:MetroGraphicsDevice.cs

示例9: CreateDeviceDependentResources

        /// <summary>
        /// Creates resources that depend on the current device.
        /// </summary>
        protected override void CreateDeviceDependentResources()
        {
            this.ReleaseDeviceDependentResources();

#if DEBUG
            DeviceCreationFlags creationFlags = DeviceCreationFlags.Debug;
#else
            DeviceCreationFlags creationFlags = DeviceCreationFlags.None;
#endif

            using (SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
            {
                SharpDX.Direct3D11.Device1 newDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
                DeviceContext1 newContext = newDevice.ImmediateContext.QueryInterface<DeviceContext1>();

                this.OnDeviceReset(newDevice, newContext);
            }
        }
开发者ID:r2d2rigo,项目名称:SharpDX.SimpleInitializer,代码行数:21,代码来源:SharpDXContext.cs

示例10: InitializeOculus


//.........这里部分代码省略.........
            Texture2D backBuffer = swapChain.GetBackBuffer<Texture2D>(0);
            RenderTargetView backBufferRenderTargetView = new RenderTargetView(device, backBuffer);

            // Create a depth buffer, using the same width and height as the back buffer.
            Texture2DDescription depthBufferDescription = new Texture2DDescription();
            depthBufferDescription.Format = Format.D32_Float;
            depthBufferDescription.ArraySize = 1;
            depthBufferDescription.MipLevels = 1;
            depthBufferDescription.Width = form.Width;
            depthBufferDescription.Height = form.Height;
            depthBufferDescription.SampleDescription = new SampleDescription(1, 0);
            depthBufferDescription.Usage = ResourceUsage.Default;
            depthBufferDescription.BindFlags = BindFlags.DepthStencil;
            depthBufferDescription.CpuAccessFlags = CpuAccessFlags.None;
            depthBufferDescription.OptionFlags = ResourceOptionFlags.None;

            // Define how the depth buffer will be used to filter out objects, based on their distance from the viewer.
            DepthStencilStateDescription depthStencilStateDescription = new DepthStencilStateDescription();
            depthStencilStateDescription.IsDepthEnabled = true;
            depthStencilStateDescription.DepthComparison = Comparison.Less;
            depthStencilStateDescription.DepthWriteMask = DepthWriteMask.Zero;

            // Create the depth buffer.
            Texture2D depthBuffer = new Texture2D(device, depthBufferDescription);
            DepthStencilView depthStencilView = new DepthStencilView(device, depthBuffer);
            DepthStencilState depthStencilState = new DepthStencilState(device, depthStencilStateDescription);
            Viewport viewport = new Viewport(0, 0, hmd.Resolution.Width, hmd.Resolution.Height, 0.0f, 1.0f);

            immediateContext.OutputMerger.SetDepthStencilState(depthStencilState);
            immediateContext.OutputMerger.SetRenderTargets(depthStencilView, backBufferRenderTargetView);
            immediateContext.Rasterizer.SetViewport(viewport);

            // Retrieve the DXGI device, in order to set the maximum frame latency.
            using (SharpDX.DXGI.Device1 dxgiDevice = device.QueryInterface<SharpDX.DXGI.Device1>())
            {
                dxgiDevice.MaximumFrameLatency = 1;
            }

            Layers layers = new Layers();
            LayerEyeFov layerEyeFov = layers.AddLayerEyeFov();

            for (int eyeIndex = 0; eyeIndex < 2; eyeIndex++)
            {
                OVR.EyeType eye = (OVR.EyeType)eyeIndex;
                EyeTexture eyeTexture = new EyeTexture();
                eyeTextures[eyeIndex] = eyeTexture;

                // Retrieve size and position of the texture for the current eye.
                eyeTexture.FieldOfView = hmd.DefaultEyeFov[eyeIndex];
                eyeTexture.TextureSize = hmd.GetFovTextureSize(eye, hmd.DefaultEyeFov[eyeIndex], 1.0f);
                eyeTexture.RenderDescription = hmd.GetRenderDesc(eye, hmd.DefaultEyeFov[eyeIndex]);
                eyeTexture.HmdToEyeViewOffset = eyeTexture.RenderDescription.HmdToEyeViewOffset;
                eyeTexture.ViewportSize.Position = new OVR.Vector2i(0, 0);
                eyeTexture.ViewportSize.Size = eyeTexture.TextureSize;
                eyeTexture.Viewport = new Viewport(0, 0, eyeTexture.TextureSize.Width, eyeTexture.TextureSize.Height, 0.0f, 1.0f);

                // Define a texture at the size recommended for the eye texture.
                eyeTexture.Texture2DDescription = new Texture2DDescription();
                eyeTexture.Texture2DDescription.Width = eyeTexture.TextureSize.Width;
                eyeTexture.Texture2DDescription.Height = eyeTexture.TextureSize.Height;
                eyeTexture.Texture2DDescription.ArraySize = 1;
                eyeTexture.Texture2DDescription.MipLevels = 1;
                eyeTexture.Texture2DDescription.Format = Format.R8G8B8A8_UNorm;
                eyeTexture.Texture2DDescription.SampleDescription = new SampleDescription(1, 0);
                eyeTexture.Texture2DDescription.Usage = ResourceUsage.Default;
                eyeTexture.Texture2DDescription.CpuAccessFlags = CpuAccessFlags.None;
开发者ID:MatejHrlec,项目名称:OculusView,代码行数:67,代码来源:OculusView.cs

示例11: CreateDevice

        internal static MyRenderDeviceSettings CreateDevice(IntPtr windowHandle, MyRenderDeviceSettings? settingsToTry)
        {
            if (Device != null)
            { 
                Device.Dispose();
                Device = null;
            }

            FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 };
            DeviceCreationFlags flags = DeviceCreationFlags.None;
      
    #if DEBUG_DEVICE    
            flags |= DeviceCreationFlags.Debug;
    #endif

            WinApi.DEVMODE mode = new WinApi.DEVMODE();
            WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode);

            var adapters = GetAdaptersList();

            int adapterIndex = settingsToTry.HasValue ? settingsToTry.Value.AdapterOrdinal : - 1;

            bool adapterIndexNotValid = 
                adapterIndex == -1
                || adapters.Length <= settingsToTry.Value.AdapterOrdinal
                || !adapters[settingsToTry.Value.AdapterOrdinal].IsSupported;
            if(adapterIndexNotValid)
            {
                var maxVram = 0ul;

                for(int i=0; i<adapters.Length; i++)
                {
                    if(adapters[i].IsSupported)
                    {
                        maxVram = (ulong) Math.Max(maxVram, adapters[i].VRAM);
                    }
                }

                // taking supporting adapter with most VRAM
                for (int i = 0; i < adapters.Length; i++)
                {
                    if(adapters[i].IsSupported && adapters[i].VRAM == maxVram)
                    {
                        adapterIndex = i;
                        break;
                    }
                }
            }

            if(adapterIndex == -1)
            {
                throw new MyRenderException("No supporting device detected!", MyRenderExceptionEnum.GpuNotSupported);
            }

            var settings = settingsToTry ?? new MyRenderDeviceSettings()
            {
                AdapterOrdinal = adapterIndex,
                BackBufferHeight = mode.dmPelsHeight,
                BackBufferWidth = mode.dmPelsWidth,
                WindowMode = MyWindowModeEnum.Fullscreen,
                VSync = false,
            };
            m_settings = settings;

            Device = new Device(GetFactory().Adapters[adapters[m_settings.AdapterOrdinal].AdapterDeviceId], flags, FeatureLevel.Level_11_0);

            // HACK: This is required for Steam overlay to work. Apparently they hook only CreateDevice methods with DriverType argument.
            try
            {
                using (new Device(DriverType.Hardware, flags, FeatureLevel.Level_11_0)){}
            }
            catch { }

            if (flags.HasFlag(DeviceCreationFlags.Debug))
            {
                if (DebugDevice != null)
                {
                    DebugDevice.Dispose();
                    DebugDevice = null;
                }

                DebugDevice = new DeviceDebug(Device);
                DebugInfoQueue = DebugDevice.QueryInterface<InfoQueue>();

                new System.Threading.Thread(ProcessDebugOutput).Start();
            }

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

            ImmediateContext = Device.ImmediateContext;

            m_windowHandle = windowHandle;

            m_resolution = new Vector2I(m_settings.BackBufferWidth, m_settings.BackBufferHeight);

            if (!m_initialized)
//.........这里部分代码省略.........
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:101,代码来源:MyRender-Device.cs

示例12: Main

        static void Main()
        {
            // input and output files are supposed to be in the program folder
            var inputPath = "Input.png";
            var outputPath = "Output.png";

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // INITIALIZATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            // initialize the D3D device which will allow to render to image any graphics - 3D or 2D
            var defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware,
                                                              d3d.DeviceCreationFlags.VideoSupport
                                                              | d3d.DeviceCreationFlags.BgraSupport
                                                              | d3d.DeviceCreationFlags.Debug); // take out the Debug flag for better performance

            var d3dDevice = defaultDevice.QueryInterface<d3d.Device1>(); // get a reference to the Direct3D 11.1 device
            var dxgiDevice = d3dDevice.QueryInterface<dxgi.Device>(); // get a reference to DXGI device

            var d2dDevice = new d2.Device(dxgiDevice); // initialize the D2D device

            var imagingFactory = new wic.ImagingFactory2(); // initialize the WIC factory

            // initialize the DeviceContext - it will be the D2D render target and will allow all rendering operations
            var d2dContext = new d2.DeviceContext(d2dDevice, d2.DeviceContextOptions.None);

            var dwFactory = new dw.Factory();

            // specify a pixel format that is supported by both D2D and WIC
            var d2PixelFormat = new d2.PixelFormat(dxgi.Format.R8G8B8A8_UNorm, d2.AlphaMode.Premultiplied);
            // if in D2D was specified an R-G-B-A format - use the same for wic
            var wicPixelFormat = wic.PixelFormat.Format32bppPRGBA;

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // IMAGE LOADING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            var decoder = new wic.PngBitmapDecoder(imagingFactory); // we will load a PNG image
            var inputStream = new wic.WICStream(imagingFactory, inputPath, NativeFileAccess.Read); // open the image file for reading
            decoder.Initialize(inputStream, wic.DecodeOptions.CacheOnLoad);

            // decode the loaded image to a format that can be consumed by D2D
            var formatConverter = new wic.FormatConverter(imagingFactory);
            formatConverter.Initialize(decoder.GetFrame(0), wicPixelFormat);

            // load the base image into a D2D Bitmap
            //var inputBitmap = d2.Bitmap1.FromWicBitmap(d2dContext, formatConverter, new d2.BitmapProperties1(d2PixelFormat));

            // store the image size - output will be of the same size
            var inputImageSize = formatConverter.Size;
            var pixelWidth = inputImageSize.Width;
            var pixelHeight = inputImageSize.Height;

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // EFFECT SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            // Effect 1 : BitmapSource - take decoded image data and get a BitmapSource from it
            var bitmapSourceEffect = new d2.Effects.BitmapSource(d2dContext);
            bitmapSourceEffect.WicBitmapSource = formatConverter;

            // Effect 2 : GaussianBlur - give the bitmapsource a gaussian blurred effect
            var gaussianBlurEffect = new d2.Effects.GaussianBlur(d2dContext);
            gaussianBlurEffect.SetInput(0, bitmapSourceEffect.Output, true);
            gaussianBlurEffect.StandardDeviation = 5f;

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // OVERLAY TEXT SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            var textFormat = new dw.TextFormat(dwFactory, "Arial", 15f); // create the text format of specified font configuration

            // draw a long text to show the automatic line wrapping
            var textToDraw = "Some long text to show the drawing of preformatted "
                             + "glyphs using DirectWrite on the Direct2D surface."
                             + " Notice the automatic wrapping of line if it exceeds desired width.";

            // create the text layout - this improves the drawing performance for static text
            // as the glyph positions are precalculated
            var textLayout = new dw.TextLayout(dwFactory, textToDraw, textFormat, 300f, 1000f);

            var textBrush = new d2.SolidColorBrush(d2dContext, Color.LightGreen);

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // RENDER TARGET SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            // create the d2d bitmap description using default flags (from SharpDX samples) and 96 DPI
            var d2dBitmapProps = new d2.BitmapProperties1(d2PixelFormat, 96, 96, d2.BitmapOptions.Target | d2.BitmapOptions.CannotDraw);

            // the render target
            var d2dRenderTarget = new d2.Bitmap1(d2dContext, new Size2(pixelWidth, pixelHeight), d2dBitmapProps);
            d2dContext.Target = d2dRenderTarget; // associate bitmap with the d2d context

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // DRAWING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            // slow preparations - fast drawing:
            d2dContext.BeginDraw();
            d2dContext.DrawImage(gaussianBlurEffect);
            d2dContext.DrawTextLayout(new Vector2(5f, 5f), textLayout, textBrush);
            d2dContext.EndDraw();

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // IMAGE SAVING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//.........这里部分代码省略.........
开发者ID:MaybeMars,项目名称:SharpDX-Samples,代码行数:101,代码来源:Program.cs

示例13: Load

        /// <summary>
        /// Now that we have a CoreWindow object, the DirectX device/context can be created.
        /// </summary>
        /// <param name="entryPoint"></param>
        public void Load(string entryPoint)
        {
            // Get the default hardware device and enable debugging. Don't care about the available feature level.
            // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop.
            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);

            // Query the default device for the supported device and context interfaces.
            device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            d3dContext = device.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>();

            // Query for the adapter and more advanced DXGI objects.
            SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface<SharpDX.DXGI.Device2>();
            SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter;
            SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.Factory2>();

            // Description for our swap chain settings.
            SwapChainDescription1 description = new SwapChainDescription1()
            {
                // 0 means to use automatic buffer sizing.
                Width = 0,
                Height = 0,
                // 32 bit RGBA color.
                Format = Format.B8G8R8A8_UNorm,
                // No stereo (3D) display.
                Stereo = false,
                // No multisampling.
                SampleDescription = new SampleDescription(1, 0),
                // Use the swap chain as a render target.
                Usage = Usage.RenderTargetOutput,
                // Enable double buffering to prevent flickering.
                BufferCount = 2,
                // No scaling.
                Scaling = Scaling.None,
                // Flip between both buffers.
                SwapEffect = SwapEffect.FlipSequential,
            };

            // Generate a swap chain for our window based on the specified description.
            swapChain = new SwapChain1(dxgiFactory2, device, new ComObject(window), ref description);

            // Get the default Direct2D device and create a context.
            SharpDX.Direct2D1.Device d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice2);
            d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

            // Specify the properties for the bitmap that we will use as the target of our Direct2D operations.
            // We want a 32-bit BGRA surface with premultiplied alpha.
            BitmapProperties1 properties = new BitmapProperties1(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied),
                DisplayProperties.LogicalDpi, DisplayProperties.LogicalDpi, BitmapOptions.Target | BitmapOptions.CannotDraw);

            // Get the default surface as a backbuffer and create the Bitmap1 that will hold the Direct2D drawing target.
            Surface backBuffer = swapChain.GetBackBuffer<Surface>(0);
            d2dTarget = new Bitmap1(d2dContext, backBuffer, properties);

            // Load bitmap images
            playerBitmap = this.LoadBitmapFromContentFile("/Assets/Bitmaps/player.png");
            terrainBitmap = this.LoadBitmapFromContentFile("/Assets/Bitmaps/terrain.png");

            // Create hue rotation effect
            hueRotationEffect = new SharpDX.Direct2D1.Effects.HueRotation(d2dContext);

            // Create image shadow effect
            shadowEffect = new SharpDX.Direct2D1.Effects.Shadow(d2dContext);

            // Create image transform effect
            affineTransformEffect = new SharpDX.Direct2D1.Effects.AffineTransform2D(d2dContext);
            affineTransformEffect.SetInputEffect(0, shadowEffect);
            affineTransformEffect.TransformMatrix = Matrix3x2.Translation(terrainBitmap.PixelSize.Width * 0.25f, terrainBitmap.PixelSize.Height * 0.25f);

            // Create composite effect
            compositeEffect = new SharpDX.Direct2D1.Effects.Composite(d2dContext);
            compositeEffect.InputCount = 2;
            compositeEffect.SetInputEffect(0, affineTransformEffect);

            // Create tiling brush for terrain bitmap
            terrainBrush = new ImageBrush(d2dContext, terrainBitmap, new ImageBrushProperties()
            {
                ExtendModeX = ExtendMode.Wrap,
                ExtendModeY = ExtendMode.Wrap,
                SourceRectangle = new RectangleF(0, 0, terrainBitmap.Size.Width, terrainBitmap.Size.Height),
            });

            // Create rendertarget for drawing the tiling brush
            brushTarget = new Bitmap1(d2dContext, new Size2((int)(terrainBitmap.Size.Width * 10), (int)terrainBitmap.Size.Height), new BitmapProperties1()
            {
                PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied),
                BitmapOptions = BitmapOptions.Target
            });
        }
开发者ID:r2d2rigo,项目名称:Direct2DBuiltinEffect,代码行数:92,代码来源:MyViewProvider.cs

示例14: CreateDeviceInternal

        private static MyRenderDeviceSettings CreateDeviceInternal(IntPtr windowHandle, MyRenderDeviceSettings? settingsToTry)
        {
            if (Device != null)
            { 
                Device.Dispose();
                Device = null;
            }

            if (settingsToTry != null)
            {
                Log.WriteLine("CreateDevice - original settings");
                var originalSettings = settingsToTry.Value;
                LogSettings(ref originalSettings);
            }

            FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 };
            DeviceCreationFlags flags = DeviceCreationFlags.None;
      
    #if DEBUG_DEVICE && DEBUG
            flags |= DeviceCreationFlags.Debug;
    #endif

            WinApi.DEVMODE mode = new WinApi.DEVMODE();
            WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode);

            var settings = settingsToTry ?? new MyRenderDeviceSettings()
            {
                AdapterOrdinal = -1,
                BackBufferHeight = mode.dmPelsHeight,
                BackBufferWidth = mode.dmPelsWidth,
                WindowMode = MyWindowModeEnum.Fullscreen,
                RefreshRate = 60000,
                VSync = false,
            };
            settings.AdapterOrdinal = ValidateAdapterIndex(settings.AdapterOrdinal);

            if (settings.AdapterOrdinal == -1)
            {
                throw new MyRenderException("No supported device detected!", MyRenderExceptionEnum.GpuNotSupported);
            }

            m_settings = settings;

            Log.WriteLine("CreateDevice settings");
            LogSettings(ref m_settings);

            // If this line crashes cmd this: Dism /online /add-capability /capabilityname:Tools.Graphics.DirectX~~~~0.0.1.0
            var adapters = GetAdaptersList();
            if (m_settings.AdapterOrdinal >= adapters.Length)
                throw new MyRenderException("No supported device detected!", MyRenderExceptionEnum.GpuNotSupported);
            var adapterId = adapters[m_settings.AdapterOrdinal].AdapterDeviceId;
            if (adapterId >= GetFactory().Adapters.Length)
                throw new MyRenderException("Invalid adapter id binding!", MyRenderExceptionEnum.GpuNotSupported);
            var adapter = GetFactory().Adapters[adapterId];
            Device = new Device(adapter, flags, FeatureLevel.Level_11_0);

            // HACK: This is required for Steam overlay to work. Apparently they hook only CreateDevice methods with DriverType argument.
            try
            {
                using (new Device(DriverType.Hardware, flags, FeatureLevel.Level_11_0)){}
            }
            catch { }

            if (flags.HasFlag(DeviceCreationFlags.Debug))
            {
                if (DebugDevice != null)
                {
                    DebugDevice.Dispose();
                    DebugDevice = null;
                }

                DebugDevice = new DeviceDebug(Device);
                DebugInfoQueue = DebugDevice.QueryInterface<InfoQueue>();

                new System.Threading.Thread(ProcessDebugOutput).Start();
            }

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

            DeviceContext = Device.ImmediateContext;

            m_windowHandle = windowHandle;

            m_resolution = new Vector2I(m_settings.BackBufferWidth, m_settings.BackBufferHeight);

            if (!m_initialized)
            {
                InitSubsystems();
                m_initialized = true;
            }

            if (m_swapchain != null)
            {
                m_swapchain.Dispose();
                m_swapchain = null;
            }
//.........这里部分代码省略.........
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:101,代码来源:MyRender-Device.cs

示例15: Load

        /// <summary>
        /// Now that we have a CoreWindow object, the DirectX device/context can be created.
        /// </summary>
        /// <param name="entryPoint"></param>
        public async void Load(string entryPoint)
        {
            // Get the default hardware device and enable debugging. Don't care about the available feature level.
            // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop.
            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);

            // Query the default device for the supported device and context interfaces.
            device = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            d3dContext = device.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>();

            // Query for the adapter and more advanced DXGI objects.
            SharpDX.DXGI.Device2 dxgiDevice2 = device.QueryInterface<SharpDX.DXGI.Device2>();
            SharpDX.DXGI.Adapter dxgiAdapter = dxgiDevice2.Adapter;
            SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.Factory2>();

            // Description for our swap chain settings.
            SwapChainDescription1 description = new SwapChainDescription1()
            {
                // 0 means to use automatic buffer sizing.
                Width = 0,
                Height = 0,
                // 32 bit RGBA color.
                Format = Format.B8G8R8A8_UNorm,
                // No stereo (3D) display.
                Stereo = false,
                // No multisampling.
                SampleDescription = new SampleDescription(1, 0),
                // Use the swap chain as a render target.
                Usage = Usage.RenderTargetOutput,
                // Enable double buffering to prevent flickering.
                BufferCount = 2,
                // No scaling.
                Scaling = Scaling.None,
                // Flip between both buffers.
                SwapEffect = SwapEffect.FlipSequential,
            };

            // Generate a swap chain for our window based on the specified description.
            swapChain = dxgiFactory2.CreateSwapChainForCoreWindow(device, new ComObject(window), ref description, null);

            // Get the default Direct2D device and create a context.
            SharpDX.Direct2D1.Device d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice2);
            d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

            // Specify the properties for the bitmap that we will use as the target of our Direct2D operations.
            // We want a 32-bit BGRA surface with premultiplied alpha.
            BitmapProperties1 properties = new BitmapProperties1(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied),
                DisplayProperties.LogicalDpi, DisplayProperties.LogicalDpi, BitmapOptions.Target | BitmapOptions.CannotDraw);

            // Get the default surface as a backbuffer and create the Bitmap1 that will hold the Direct2D drawing target.
            Surface backBuffer = swapChain.GetBackBuffer<Surface>(0);
            d2dTarget = new Bitmap1(d2dContext, backBuffer, properties);

            // Create the DirectWrite factory objet.
            SharpDX.DirectWrite.Factory fontFactory = new SharpDX.DirectWrite.Factory();

            // Create a TextFormat object that will use the Segoe UI font with a size of 24 DIPs.
            textFormat = new TextFormat(fontFactory, "Segoe UI", 24.0f);

            // Create two TextLayout objects for rendering the moving text.
            textLayout1 = new TextLayout(fontFactory, "This is an example of a moving TextLayout object with snapped pixel boundaries.", textFormat, 400.0f, 200.0f);
            textLayout2 = new TextLayout(fontFactory, "This is an example of a moving TextLayout object with no snapped pixel boundaries.", textFormat, 400.0f, 200.0f);

            // Vertical offset for the moving text.
            layoutY = 0.0f;

            // Create the brushes for the text background and text color.
            backgroundBrush = new SolidColorBrush(d2dContext, Color.White);
            textBrush = new SolidColorBrush(d2dContext, Color.Black);
        }
开发者ID:r2d2rigo,项目名称:MyFirstDirectWrite,代码行数:74,代码来源:MyViewProvider.cs


注:本文中的SharpDX.Direct3D11.Device.QueryInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。