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


C# Buffer.Dispose方法代码示例

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


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

示例1: Main


//.........这里部分代码省略.........

            // Use clock
            var clock = new Stopwatch();
            clock.Start();

            // Declare texture for rendering
            bool userResized = true;
            Texture2D backBuffer = null;
            RenderTargetView renderView = null;
            Texture2D depthBuffer = null;
            DepthStencilView depthView = null;

            // Setup handler on resize form
            form.UserResized += (sender, args) => userResized = true;

            // Setup full screen mode change F5 (Full) F4 (Window)
            form.KeyUp += (sender, args) =>
                {
                    if (args.KeyCode == Keys.F5)
                        swapChain.SetFullscreenState(true, null);
                    else if (args.KeyCode == Keys.F4)
                        swapChain.SetFullscreenState(false, null);
                    else if (args.KeyCode == Keys.Escape)
                        form.Close();
                };

            // Main loop
            RenderLoop.Run(form, () =>
            {
                // If Form resized
                if (userResized)
                {
                    // Dispose all previous allocated resources
                    ComObject.Dispose(ref backBuffer);
                    ComObject.Dispose(ref renderView);
                    ComObject.Dispose(ref depthBuffer);
                    ComObject.Dispose(ref depthView);

                    // Resize the backbuffer
                    swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);

                    // Get the backbuffer from the swapchain
                    backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);

                    // Renderview on the backbuffer
                    renderView = new RenderTargetView(device, backBuffer);

                    // Create the depth buffer
                    depthBuffer = 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
                    });

                    // Create the depth buffer view
                    depthView = new DepthStencilView(device, depthBuffer);

                    // Setup targets and viewport for rendering
开发者ID:Nezz,项目名称:SharpDX,代码行数:67,代码来源:Program.cs

示例2: Main


//.........这里部分代码省略.........
            Matrix proj = Matrix.Identity;

            // Use the clock
            var clock = new Stopwatch();
            clock.Start();

            // Declare texture for rendering (even though we aren't
            // using texture here :) ); we also set up our swap chain back buffer
            bool userResized = true;
            Texture2D backBuffer = null;
            RenderTargetView renderView = null;
            Texture2D depthBuffer = null;
            DepthStencilView depthView = null;

            // Set up the light, a grey ambient light and a white positional light
            // The positional light is currently located above and behind the cube
            // (because it's + in Y and + in Z)
            Vector4 lightAmbCol = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
            Vector4 lightPntCol = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            Vector4 lightPntPos = new Vector4(200.0f, 100.0f, -10.0f, 1.0f);

            // Handle events where we resize our window
            form.UserResized += (sender, args) => userResized = true;

            // Main loop: render the objects for each frame of our scene
            RenderLoop.Run(form, () =>
            {
                // If the window was resized, we need to reorganise
                // various properties of the window (don't worry about
                // this right now)
                if (userResized)
                {
                    // Dispose all previous allocated resources
                    ComObject.Dispose(ref backBuffer);
                    ComObject.Dispose(ref renderView);
                    ComObject.Dispose(ref depthBuffer);
                    ComObject.Dispose(ref depthView);

                    // Resize the backbuffer
                    swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);

                    // Get the backbuffer from the swapchain
                    backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);

                    // Renderview on the backbuffer
                    renderView = new RenderTargetView(device, backBuffer);

                    // Create the depth buffer
                    depthBuffer = 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
                    });

                    // Create the depth buffer view
                    depthView = new DepthStencilView(device, depthBuffer);

                    // Setup targets and viewport for rendering
开发者ID:Ox5f3759df,项目名称:Greased-Lighting,代码行数:67,代码来源:week8.cs

示例3: Run


//.........这里部分代码省略.........
            // ---------------------------------------------------------------------------------------------------
            // Acquire the mutexes. These are needed to assure the device in use has exclusive access to the surface
            // ---------------------------------------------------------------------------------------------------

            var device10Mutex = textureD3D10.QueryInterface<KeyedMutex>();
            var device11Mutex = textureD3D11.QueryInterface<KeyedMutex>();

            // ---------------------------------------------------------------------------------------------------
            // Main rendering loop
            // ---------------------------------------------------------------------------------------------------

            bool first = true;

            RenderLoop
                .Run(form,
                     () =>
                         {
                             if(first)
                             {
                                 form.Activate();
                                 first = false;
                             }

                             // clear the render target to black
                             context.ClearRenderTargetView(renderTargetView, Colors.DarkSlateGray);

                             // Draw the triangle
                             context.InputAssembler.InputLayout = layoutColor;
                             context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                             context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferColor, VertexPositionColor.SizeInBytes, 0));
                             context.OutputMerger.BlendState = null;
                             var currentTechnique = effect.GetTechniqueByName("Color");
                             for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
                             {
                                 using (var effectPass = currentTechnique.GetPassByIndex(pass))
                                 {
                                     System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
                                     effectPass.Apply(context);
                                 }
                                 context.Draw(3, 0);
                             };

                             // Draw Ellipse on the shared Texture2D
                             device10Mutex.Acquire(0, 100);
                             renderTarget2D.BeginDraw();
                             renderTarget2D.Clear(Colors.Black);
                             renderTarget2D.DrawGeometry(tesselatedGeometry, solidColorBrush);
                             renderTarget2D.DrawEllipse(new Ellipse(center, 200, 200), solidColorBrush, 20, null);
                             renderTarget2D.EndDraw();
                             device10Mutex.Release(0);

                             // Draw the shared texture2D onto the screen, blending the 2d content in
                             device11Mutex.Acquire(0, 100);
                             var srv = new ShaderResourceView(device11, textureD3D11);
                             effect.GetVariableByName("g_Overlay").AsShaderResource().SetResource(srv);
                             context.InputAssembler.InputLayout = layoutOverlay;
                             context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
                             context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferOverlay, VertexPositionTexture.SizeInBytes, 0));
                             context.OutputMerger.BlendState = blendStateTransparent;
                             currentTechnique = effect.GetTechniqueByName("Overlay");

                             for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
                             {
                                 using (var effectPass = currentTechnique.GetPassByIndex(pass))
                                 {
                                     System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
                                     effectPass.Apply(context);
                                 }
                                 context.Draw(4, 0);
                             }
                             srv.Dispose();
                             device11Mutex.Release(0);

                             swapChain.Present(0, PresentFlags.None);
                         });

            // dispose everything
            vertexBufferColor.Dispose();
            vertexBufferOverlay.Dispose();
            layoutColor.Dispose();
            layoutOverlay.Dispose();
            effect.Dispose();
            shaderByteCode.Dispose();
            renderTarget2D.Dispose();
            swapChain.Dispose();
            device11.Dispose();
            device10.Dispose();
            textureD3D10.Dispose();
            textureD3D11.Dispose();
            factory1.Dispose();
            adapter1.Dispose();
            sharedResource.Dispose();
            factory2D.Dispose();
            surface.Dispose();
            solidColorBrush.Dispose();
            blendStateTransparent.Dispose();

            device10Mutex.Dispose();
            device11Mutex.Dispose();
        }
开发者ID:ernstnaezer,项目名称:SharpDXSharedResources,代码行数:101,代码来源:Program.cs

示例4: InitializeOculus


//.........这里部分代码省略.........
                    int textureIndex = eyeTexture.SwapTextureSet.CurrentIndex++;

                    immediateContext.OutputMerger.SetRenderTargets(eyeTexture.DepthStencilView, eyeTexture.RenderTargetViews[textureIndex]);
                    immediateContext.ClearRenderTargetView(eyeTexture.RenderTargetViews[textureIndex], Color.Black);
                    immediateContext.ClearDepthStencilView(eyeTexture.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
                    immediateContext.Rasterizer.SetViewport(eyeTexture.Viewport);
                    //added a custom rasterizer
                    immediateContext.Rasterizer.State = rasterizerState;

                    // Retrieve the eye rotation quaternion and use it to calculate the LookAt direction and the LookUp direction.
                    Quaternion rotationQuaternion = SharpDXHelpers.ToQuaternion(eyePoses[eyeIndex].Orientation);
                    Matrix rotationMatrix = Matrix.RotationQuaternion(rotationQuaternion);
                    Vector3 lookUp = Vector3.Transform(new Vector3(0, -1, 0), rotationMatrix).ToVector3();
                    Vector3 lookAt = Vector3.Transform(new Vector3(0, 0, 1), rotationMatrix).ToVector3();

                    Vector3 viewPosition = position - eyePoses[eyeIndex].Position.ToVector3();

                    //use this to get the first rotation to goal
                    Matrix world = Matrix.Scaling(1.0f) /** Matrix.RotationX(timeSinceStart*0.2f) */* Matrix.RotationY(timeSinceStart * 2 / 10f) /** Matrix.RotationZ(timeSinceStart*3/10f)*/;
                    Matrix viewMatrix = Matrix.LookAtRH(viewPosition, viewPosition + lookAt, lookUp);

                    Matrix projectionMatrix = OVR.ovrMatrix4f_Projection(eyeTexture.FieldOfView, 0.1f, 10.0f, OVR.ProjectionModifier.None).ToMatrix();
                    projectionMatrix.Transpose();

                    Matrix worldViewProjection = world * viewMatrix * projectionMatrix;
                    worldViewProjection.Transpose();

                    // Update the transformation matrix.
                    immediateContext.UpdateSubresource(ref worldViewProjection, constantBuffer);

                    // Draw the cube
                    //immediateContext.Draw(vertices.Length/2, 0);
                    immediateContext.DrawIndexed(indices.Length, 0, 0);
                }

                hmd.SubmitFrame(0, layers);

                immediateContext.CopyResource(mirrorTextureD3D11, backBuffer);
                swapChain.Present(0, PresentFlags.None);


                if (newTextureArrived == true)
                {
                    newTextureArrived = false;
                    DataBox map = device.ImmediateContext.MapSubresource(myTexture, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);

                    //load the BitMapSource with appropriate formating (Format32bppPRGBA)
                    SharpDX.WIC.BitmapSource bitMap = LoadBitmap(new SharpDX.WIC.ImagingFactory(), streamTexture);
                    //string newFile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\img_merged.jpg";
                    //SharpDX.WIC.BitmapSource bitMap = LoadBitmapFromFile(new SharpDX.WIC.ImagingFactory(), newFile);

                    int width = bitMap.Size.Width;
                    int height = bitMap.Size.Height;
                    int stride = bitMap.Size.Width * 4;

                    bitMap.CopyPixels(stride, map.DataPointer, height * stride);

                    device.ImmediateContext.UnmapSubresource(myTexture, 0);

                    //bitMap.Dispose();
                    streamTexture.Seek(0, SeekOrigin.Begin);
                }


            });
            #endregion
            // Release all resources
            inputLayout.Dispose();
            constantBuffer.Dispose();
            indexBuffer.Dispose();
            vertexBuffer.Dispose();
            inputLayout.Dispose();
            shaderSignature.Dispose();
            pixelShader.Dispose();
            pixelShaderByteCode.Dispose();
            vertexShader.Dispose();
            vertexShaderByteCode.Dispose();
            mirrorTextureD3D11.Dispose();
            layers.Dispose();
            eyeTextures[0].Dispose();
            eyeTextures[1].Dispose();
            immediateContext.ClearState();
            immediateContext.Flush();
            immediateContext.Dispose();
            depthStencilState.Dispose();
            depthStencilView.Dispose();
            depthBuffer.Dispose();
            backBufferRenderTargetView.Dispose();
            backBuffer.Dispose();
            swapChain.Dispose();
            factory.Dispose();

            // Disposing the device, before the hmd, will cause the hmd to fail when disposing.
            // Disposing the device, after the hmd, will cause the dispose of the device to fail.
            // It looks as if the hmd steals ownership of the device and destroys it, when it's shutting down.
            // device.Dispose();

            hmd.Dispose();
            oculus.Dispose();
        }
开发者ID:MatejHrlec,项目名称:OculusView,代码行数:101,代码来源:OculusView.cs


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