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


C# Program.ToDispose方法代码示例

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


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

示例1: Pipeline

        // Constructor - Must be initialized before the assets.
        public Pipeline(Program program, String title, int initialWidth, int initialHeight)
        {
            // Set program reference.
            this.program = program;

            // Set dimentions.
            this.width = initialWidth;
            this.height = initialHeight;

            // Create Windows form.
            form = program.ToDispose(new RenderForm(title));
            form.ClientSize = new System.Drawing.Size(width, height);

            // Create SwapChain description
            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription =
                    new ModeDescription(width, height,
                                        new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput,
            };

            // Create Device, SwapChain and DeviceContext.
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);
            program.ToDispose(device);
            program.ToDispose(swapChain);
            context = program.ToDispose(device.ImmediateContext);

            // Create the RenderView.
            var backBuffer = program.ToDispose(Texture2D.FromSwapChain<Texture2D>(swapChain, 0));
            renderView = program.ToDispose(new RenderTargetView(device, backBuffer));

            // Create the DepthStencilView.
            var depthBuffer = program.ToDispose(new Texture2D(device, new Texture2DDescription()
            {
                Format = Format.D32_Float_S8X24_UInt,
                ArraySize = 1,
                MipLevels = 1,
                Width = form.ClientSize.Width,
                Height = form.ClientSize.Height,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            }));
            depthView = program.ToDispose(new DepthStencilView(device, depthBuffer));

            // Create the texture sampler.
            sampler = program.ToDispose(new SamplerState(device, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Colors.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = 0,
                MaximumLod = 16,
            }));
            context.PixelShader.SetSampler(0, sampler);

            // Initialise the transformation matrices.
            world = Matrix.Identity;
            view = Matrix.Identity;
            proj = Matrix.Identity;
            worldViewProj = Matrix.Identity;

            // Create the Constant Buffer.
            constantBuffer = program.ToDispose(new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            context.VertexShader.SetConstantBuffer(0, constantBuffer);

            // Set the view port.
            context.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));

            // Set the output target.
            context.OutputMerger.SetTargets(depthView, renderView);
        }
开发者ID:Ox5f3759df,项目名称:SharpDX-Abstraction-Maria,代码行数:86,代码来源:Pipeline.cs


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