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


C# SwapChain.GetBuffer方法代码示例

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


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

示例1: CreateDeviceSwapChainAndRenderTarget

        public static void CreateDeviceSwapChainAndRenderTarget(Form form,
            out Device device, out SwapChain swapChain, out RenderTargetView renderTarget)
        {
            try
            {
                // the debug mode requires the sdk to be installed otherwise an exception is thrown
                device = new Device(DeviceCreationFlags.Debug);
            }
            catch (Direct3D10Exception)
            {
                device = new Device(DeviceCreationFlags.None);
            }

            var swapChainDescription = new SwapChainDescription();
            var modeDescription = new ModeDescription();
            var sampleDescription = new SampleDescription();

            modeDescription.Format = Format.R8G8B8A8_UNorm;
            modeDescription.RefreshRate = new Rational(60, 1);
            modeDescription.Scaling = DisplayModeScaling.Unspecified;
            modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;

            modeDescription.Width = WIDTH;
            modeDescription.Height = HEIGHT;

            sampleDescription.Count = 1;
            sampleDescription.Quality = 0;

            swapChainDescription.ModeDescription = modeDescription;
            swapChainDescription.SampleDescription = sampleDescription;
            swapChainDescription.BufferCount = 1;
            swapChainDescription.Flags = SwapChainFlags.None;
            swapChainDescription.IsWindowed = true;
            swapChainDescription.OutputHandle = form.Handle;
            swapChainDescription.SwapEffect = SwapEffect.Discard;
            swapChainDescription.Usage = Usage.RenderTargetOutput;

            using (var factory = new Factory())
            {
                swapChain = new SwapChain(factory, device, swapChainDescription);
            }

            using (var resource = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTarget = new RenderTargetView(device, resource);
            }

            var viewport = new Viewport
            {
                X = 0,
                Y = 0,
                Width = WIDTH,
                Height = HEIGHT,
                MinZ = 0.0f,
                MaxZ = 1.0f
            };

            device.Rasterizer.SetViewports(viewport);
            device.OutputMerger.SetTargets(renderTarget);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:60,代码来源:EmptyWindow.cs

示例2: InitDevice

        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        public void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(host.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)host.ActualWidth,
                Height = (uint)host.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        } 
开发者ID:Corillian,项目名称:Windows-API-Code-Pack-1.1,代码行数:29,代码来源:TutorialWindow.xaml.cs

示例3: InitDevice

        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)directControl.ClientSize.Width,
                Height = (uint)directControl.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        } 
开发者ID:Corillian,项目名称:Windows-API-Code-Pack-1.1,代码行数:29,代码来源:TutorialWindow.cs

示例4: InitDevice

        void InitDevice()
        {
            // create Direct 3D device
            device = D3DDevice.CreateDeviceAndSwapChain(renderHost.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            // Create depth stencil texture
            Texture2DDescription descDepth = new Texture2DDescription()
            {
                Width = (uint)renderHost.ActualWidth,
                Height = (uint)renderHost.ActualHeight,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.D32Float,
                SampleDescription = new SampleDescription()
                {
                    Count = 1,
                    Quality = 0
                },
                BindingOptions = BindingOptions.DepthStencil,
            };

            depthStencil = device.CreateTexture2D(descDepth);

            // Create the depth stencil view
            DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
            {
                Format = descDepth.Format,
                ViewDimension = DepthStencilViewDimension.Texture2D
            };
            depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc);

            // bind the views to the device
            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)renderHost.ActualWidth,
                Height = (uint)renderHost.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };
            
            device.RS.Viewports = new Viewport[] { vp };
        }
开发者ID:Corillian,项目名称:Windows-API-Code-Pack-1.1,代码行数:54,代码来源:TexturizerDemo.xaml.cs

示例5: CreateDeviceResources

        void CreateDeviceResources()
        {
            uint width = (uint) host.ActualWidth;
            uint height = (uint) host.ActualHeight;

            // If we don't have a device, need to create one now and all
            // accompanying D3D resources.
            CreateDevice();

            DXGIFactory dxgiFactory = DXGIFactory.CreateFactory();

            SwapChainDescription swapDesc = new SwapChainDescription();
            swapDesc.BufferDescription.Width = width;
            swapDesc.BufferDescription.Height = height;
            swapDesc.BufferDescription.Format = Format.R8G8B8A8_UNORM;
            swapDesc.BufferDescription.RefreshRate.Numerator = 60;
            swapDesc.BufferDescription.RefreshRate.Denominator = 1;
            swapDesc.SampleDescription.Count = 1;
            swapDesc.SampleDescription.Quality = 0;
            swapDesc.BufferUsage = UsageOption.RenderTargetOutput;
            swapDesc.BufferCount = 1;
            swapDesc.OutputWindowHandle = host.Handle;
            swapDesc.Windowed = true;

            swapChain = dxgiFactory.CreateSwapChain(
                device, swapDesc);

            // Create rasterizer state object
            RasterizerDescription rsDesc = new RasterizerDescription();
            rsDesc.AntialiasedLineEnable = false;
            rsDesc.CullMode = CullMode.None;
            rsDesc.DepthBias = 0;
            rsDesc.DepthBiasClamp = 0;
            rsDesc.DepthClipEnable = true;
            rsDesc.FillMode = D3D10.FillMode.Solid;
            rsDesc.FrontCounterClockwise = false; // Must be FALSE for 10on9
            rsDesc.MultisampleEnable = false;
            rsDesc.ScissorEnable = false;
            rsDesc.SlopeScaledDepthBias = 0;

            rasterizerState = device.CreateRasterizerState(
                rsDesc);

            device.RS.SetState(
                rasterizerState
                );

            // If we don't have a D2D render target, need to create all of the resources
            // required to render to one here.
            // Ensure that nobody is holding onto one of the old resources
            device.OM.SetRenderTargets(new RenderTargetView[] {null});

            InitializeDepthStencil(width, height);

            // Create views on the RT buffers and set them on the device
            RenderTargetViewDescription renderDesc = new RenderTargetViewDescription();
            renderDesc.Format = Format.R8G8B8A8_UNORM;
            renderDesc.ViewDimension = RenderTargetViewDimension.Texture2D;
            renderDesc.Texture2D.MipSlice = 0;

            using (D3DResource spBackBufferResource = swapChain.GetBuffer<D3DResource>(0))
            {
                renderTargetView = device.CreateRenderTargetView(
                    spBackBufferResource,
                    renderDesc);
            }

            device.OM.SetRenderTargets(new RenderTargetView[] {renderTargetView}, depthStencilView);

            SetViewport(width, height);


            // Create a D2D render target which can draw into the surface in the swap chain
            RenderTargetProperties props =
                new RenderTargetProperties(
                    RenderTargetType.Default, new PixelFormat(Format.Unknown, AlphaMode.Premultiplied),
                    96, 96, RenderTargetUsage.None, FeatureLevel.Default);

            // Allocate a offscreen D3D surface for D2D to render our 2D content into
            Texture2DDescription tex2DDescription;
            tex2DDescription.ArraySize = 1;
            tex2DDescription.BindFlags = BindFlag.RenderTarget | BindFlag.ShaderResource;
            tex2DDescription.CpuAccessFlags = CpuAccessFlag.Unspecified;
            tex2DDescription.Format = Format.R8G8B8A8_UNORM;
            tex2DDescription.Height = 4096;
            tex2DDescription.Width = 512;
            tex2DDescription.MipLevels = 1;
            tex2DDescription.MiscFlags = 0;
            tex2DDescription.SampleDescription.Count = 1;
            tex2DDescription.SampleDescription.Quality = 0;
            tex2DDescription.Usage = Usage.Default;

            offscreenTexture = device.CreateTexture2D(tex2DDescription);

            using (Surface dxgiSurface = offscreenTexture.GetDXGISurface())
            {
                // Create a D2D render target which can draw into our offscreen D3D surface
                renderTarget = d2DFactory.CreateDxgiSurfaceRenderTarget(
                    dxgiSurface,
                    props);
//.........这里部分代码省略.........
开发者ID:Prashant-Jonny,项目名称:phever,代码行数:101,代码来源:Window1.xaml.cs

示例6: FromSwapChain

 /// <summary>
 /// Gets a swap chain back buffer.
 /// </summary>
 /// <param name="swapChain">The swap chain to get the buffer from.</param>
 /// <param name="index">The index of the desired buffer.</param>
 /// <returns>The buffer interface, or <c>null</c> on failure.</returns>
 public static Surface FromSwapChain(SwapChain swapChain, int index)
 {
     IntPtr surfacePointer;
     swapChain.GetBuffer(index, Utilities.GetGuidFromType(typeof (Surface)), out surfacePointer);
     return new Surface(surfacePointer);
 }
开发者ID:numo16,项目名称:SharpDX,代码行数:12,代码来源:Surface.cs

示例7: FromSwapChain

		public static Texture2D FromSwapChain(SwapChain swapChain, int index)
		{
			return swapChain.GetBuffer(index);
		}
开发者ID:modulexcite,项目名称:rasterizr,代码行数:4,代码来源:Texture2D.cs

示例8: CreateDeviceResources

        void CreateDeviceResources()
        {
            uint nWidth = (uint)host.ActualWidth;
            uint nHeight = (uint)host.ActualHeight;

            // Create D3D device and swap chain
            SwapChainDescription swapDesc = new SwapChainDescription
            {
                BufferDescription = new ModeDescription
                {
                    Width = nWidth, Height = nHeight,
                    Format = Format.R8G8B8A8UNorm,
                    RefreshRate = new Rational { Numerator = 60, Denominator = 1 }
                },
                SampleDescription = new SampleDescription { Count = 1, Quality = 0 },
                BufferUsage = UsageOptions.RenderTargetOutput,
                BufferCount = 1,
                OutputWindowHandle = host.Handle,
                Windowed = true
            };

            device = D3DDevice1.CreateDeviceAndSwapChain1(
                null,
                DriverType.Hardware,
                null,
                CreateDeviceOptions.SupportBgra,
                FeatureLevel.NinePointThree,
                swapDesc
                );
            swapChain = device.SwapChain;

            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            MakeBothSidesRendered();
            InitializeDepthStencil(nWidth, nHeight);

            device.OM.RenderTargets = new OutputMergerRenderTargets(new[] { renderTargetView }, depthStencilView);

            // Set a new viewport based on the new dimensions
            SetViewport(nWidth, nHeight);

            // Load pixel shader
            shader = LoadResourceShader(device, "Microsoft.WindowsAPICodePack.DirectX.Samples.dxgisample.fxo");

            // Obtain the technique
            technique = shader.GetTechniqueByName("Render");

            // Create the input layout
            InitializeGeometryBuffers();

            // Obtain the variables
            Initialize3DTransformations(nWidth, nHeight);

            // Allocate a offscreen D3D surface for D2D to render our 2D content into
            InitializeTextureRenderTarget();

            // Create a D2D render target which can draw into the surface in the swap chain
            CreateD2DRenderTargets();
        }
开发者ID:QuocHuy7a10,项目名称:Arianrhod,代码行数:62,代码来源:Window1.xaml.cs

示例9: CreateSwapChainRenderTargetAndViewport

        private void CreateSwapChainRenderTargetAndViewport()
        {
            var swapChainDescription = CreateSwapChainDescription();

            using (var factory = new Factory())
            {
                mSwapChain = new SwapChain(factory, mDevice, swapChainDescription);
            }

            using (var resource = mSwapChain.GetBuffer<Texture2D>(0))
            {
                mRenderTarget = new RenderTargetView(mDevice, resource);
            }

            var viewport = new Viewport
            {
                X = 0,
                Y = 0,
                Width = mWidth,
                Height = mHeight,
                MinZ = 0.0f,
                MaxZ = 1.0f
            };

            CreateDepthBuffer();

            mDevice.Rasterizer.SetViewports(viewport);
            mDevice.OutputMerger.SetTargets(
                mDepthStencilView, mRenderTarget);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:30,代码来源:SlimDXRenderWindow.cs


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