Exemplo n.º 1
0
 public void Dispose()
 {
     surrogateFacesView.Dispose();
     meshBuffers.Dispose();
     inputLayout.Dispose();
     material.Dispose();
 }
        public override void Dispose()
        {
            effect?.Dispose();
            layout?.Dispose();

            base.Dispose();
        }
Exemplo n.º 3
0
 private void ReleaseResources()
 {
     layout.Dispose();
     effect.Dispose();
     indicesb1.Dispose();
     indicesb2.Dispose();
 }
Exemplo n.º 4
0
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }
            disposed = true;

            texsampler.Dispose();

            sundisc.Dispose();
            moonquad.Dispose();

            skylayout.Dispose();
            sunlayout.Dispose();
            moonlayout.Dispose();

            VSSunMoonVars.Dispose();
            PSSunMoonVars.Dispose();

            SkyLocalVars.Dispose();
            VSSceneVars.Dispose();
            VSEntityVars.Dispose();
            VSModelVars.Dispose();
            PSSceneVars.Dispose();

            skyps.Dispose();
            skyvs.Dispose();
            sunps.Dispose();
            sunvs.Dispose();
            moonps.Dispose();
            moonvs.Dispose();
        }
Exemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                    vertexBuffer = null;
                }

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

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

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

            base.Dispose(disposing);
        }
Exemplo n.º 6
0
 public void Dispose()
 {
     InputLayout.Dispose();
     VertexShader.Dispose();
     GeometryShader?.Dispose();
     FragmentShader.Dispose();
 }
Exemplo n.º 7
0
            public void Unload()
            {
                PixelShader.Dispose();
                VertexShader.Dispose();
                TextureView.Dispose();
                Sampler.Dispose();
                BlendState.Dispose();
                Texture2D.Dispose();
                VertexBufferBinding.Buffer.Dispose();
                VertexBuffer.Dispose();
                Layout.Dispose();
                ConstantBuffer.Dispose();



                this.PixelShader  = null;
                this.VertexShader = null;
                this.TextureView  = null;
                this.Sampler      = null;
                this.BlendState   = null;
                this.Texture2D    = null;
                this.VertexBufferBinding.Buffer = null;
                this.VertexBuffer   = null;
                this.Layout         = null;
                this.ConstantBuffer = null;
            }
Exemplo n.º 8
0
        protected override void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    // cleanup managed stuff
                }

                // cleanup unmanaged stuff
                for (int i = 0; i < 5; i++)
                {
                    if (_vertexBuffer2[i] != null)
                    {
                        _vertexBuffer2[i].Dispose();
                    }
                    if (_indexBuffer2[i] != null)
                    {
                        _indexBuffer2[i].Dispose();
                    }
                }
                if (_inputLayout != null)
                {
                    _inputLayout.Dispose();
                }
                disposed = true;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 9
0
 public void Dispose()
 {
     meshBuffers.Dispose();
     modelToWorldTransform.Dispose();
     inputLayout.Dispose();
     material.Dispose();
 }
Exemplo n.º 10
0
 void ShutdownShader()
 {
     matrixBuffer.Dispose();
     inputLayout.Dispose();
     pixelShader.Dispose();
     vertexShader.Dispose();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Gibt die Resourcen der Instanz frei.
 /// </summary>
 /// <param name="disposing">
 /// true, um managed Resourcen freizugeben; andernfalls false.
 /// </param>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         // Merken, daß die Instanz freigegeben wurde.
         disposed = true;
         // Managed Resourcen freigeben.
         if (disposing)
         {
             if (vertexBuffer != null)
             {
                 vertexBuffer.Dispose();
             }
             if (indexBuffer != null)
             {
                 indexBuffer.Dispose();
             }
             if (inputLayout != null)
             {
                 inputLayout.Dispose();
             }
         }
         // Hier Unmanaged Resourcen freigeben.
     }
 }
Exemplo n.º 12
0
 public void Dispose()
 {
     device.Dispose();
     inputLayout.Dispose();
     rasterizerState.Dispose();
     blendState.Dispose();
 }
Exemplo n.º 13
0
        public void Dispose()
        {
            if (constantLightBuffer != null)
            {
                constantLightBuffer.Dispose();
            }
            if (constantCameraBuffer != null)
            {
                constantCameraBuffer.Dispose();
            }
            if (textureResource != null)
            {
                textureResource.Dispose();
            }

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

            sampleState.Dispose();

            inputLayout.Dispose();
            pixelShader.Dispose();
            vertexShader.Dispose();
        }
Exemplo n.º 14
0
        void ReleaseDesignerOutlets()
        {
            if (HeadImage != null)
            {
                HeadImage.Dispose();
                HeadImage = null;
            }

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

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

            if (PasswordText != null)
            {
                PasswordText.Dispose();
                PasswordText = null;
            }
        }
Exemplo n.º 15
0
 public void Dispose()
 {
     InputLayout.Dispose();
     VertexShader.Dispose();
     FragmentShader.Dispose();
     GL.DeleteProgram(ProgramID);
     Utilities.CheckLastGLES3Error();
 }
Exemplo n.º 16
0
 public void Dispose()
 {
     E.Dispose();
     InputSignaturePNT.Dispose();
     LayoutPNT.Dispose();
     InputSignaturePT.Dispose();
     LayoutPT.Dispose();
 }
Exemplo n.º 17
0
 public void Dispose()
 {
     InputLayout.Dispose();
     VertexShader.Dispose();
     GeometryShader?.Dispose();
     FragmentShader.Dispose();
     GL.DeleteProgram(ProgramID);
 }
Exemplo n.º 18
0
 /// <summary>
 ///     IDisposable実装
 /// </summary>
 public void Dispose()
 {
     axisVertexBuffer.Dispose();
     vertexBuffer.Dispose();
     layout.Dispose();
     axisLayout.Dispose();
     effect.Dispose();
 }
Exemplo n.º 19
0
 public void Dispose()
 {
     inputLayout.Dispose();
     vertexShaderByteCode.Dispose();
     pixelShaderByteCode.Dispose();
     pixelShader.Dispose();
     vertexShader.Dispose();
 }
Exemplo n.º 20
0
 void ShutdownShader()
 {
     samplerState.Dispose();
     matrixBuffer.Dispose();
     inputLayout.Dispose();
     pixelShader.Dispose();
     vertexShader.Dispose();
 }
Exemplo n.º 21
0
        /// <summary>
        /// Disposes of our managed resources.
        /// </summary>
        protected override void DisposeManaged()
        {
            {
                if (m_sampleVertices != null)
                {
                    m_sampleVertices.Dispose();
                    m_sampleVertices = null;
                }

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

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

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

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

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

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

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

            base.DisposeManaged();

            return;
        }
Exemplo n.º 22
0
 public void Dispose()
 {
     inputLayout.Dispose();
     rasterizerState.Dispose();
     texture.Dispose();
     textureTargetView.Dispose();
     resolveTexture.Dispose();
     stagingTexture.Dispose();
 }
Exemplo n.º 23
0
 protected virtual void Dispose(bool managed)
 {
     if (!m_Disposed)
     {
         m_Handle.Dispose();
         m_InputLayout.Dispose();
         m_Disposed = true;
     }
 }
Exemplo n.º 24
0
 public void Dispose()
 {
     _quadVertices.Dispose();
     _layout.Dispose();
     _renderTexture.Dispose();
     _srv.Dispose();
     UAV.Dispose();
     _effect.Dispose();
 }
 public void Dispose()
 {
     if (inputLayout != null)
     {
         inputLayout.Dispose();
     }
     inputSignature.Dispose();
     VertexShader.Dispose();
 }
Exemplo n.º 26
0
 public void Dispose()
 {
     baseShader.Dispose();
     sampler.Dispose();
     inputLayout.Dispose();
     baseShader  = null;
     sampler     = null;
     inputLayout = null;
 }
Exemplo n.º 27
0
 void ShutdownShader()
 {
     pixelBuffer.Dispose();
     samplerState.Dispose();
     constantBuffer.Dispose();
     inputLayout.Dispose();
     pixelShader.Dispose();
     vertexShader.Dispose();
 }
Exemplo n.º 28
0
 public void Dispose()
 {
     InputLayout.Dispose();
     VertexShader.Dispose();
     TessellationControlShader?.Dispose();
     TessellationEvaluationShader?.Dispose();
     GeometryShader?.Dispose();
     FragmentShader.Dispose();
 }
Exemplo n.º 29
0
        void ReleaseDesignerOutlets()
        {
            if (EmailText != null)
            {
                EmailText.Dispose();
                EmailText = null;
            }

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

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

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

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

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

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

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

            if (FacebookLoginButton != null)
            {
                FacebookLoginButton.Dispose();
                FacebookLoginButton = null;
            }
        }
Exemplo n.º 30
0
        public void CleanUp()
        {
            vsByteCode.Dispose();
            vShader.Dispose();
            psByteCode.Dispose();
            pShader.Dispose();

            vertices.Dispose();
            layout.Dispose();
        }
Exemplo n.º 31
0
        static void Main()
        {
            var form = new RenderForm("SlimDX - MiniTri Direct3D 10 Sample");
            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            Device device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(null, DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);

            //Stops Alt+enter from causing fullscreen skrewiness.
            device.Factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
            var renderView = new RenderTargetView(device, backBuffer);
            var effect = Effect.FromFile(device, "MiniTri.fx", "fx_4_0");
            var technique = effect.GetTechniqueByIndex(0);
            var pass = technique.GetPassByIndex(0);
            var layout = new InputLayout(device, pass.Description.Signature, new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) 
            });

            var stream = new DataStream(3 * 32, true, true);
            stream.WriteRange(new[] {
                new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
            });
            stream.Position = 0;

            var vertices = new SlimDX.Direct3D10.Buffer(device, stream, new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = 3 * 32,
                Usage = ResourceUsage.Default
            });
            stream.Dispose();

            device.OutputMerger.SetTargets(renderView);
            device.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));

            MessagePump.Run(form, () =>
            {
                device.ClearRenderTargetView(renderView, Color.Black);

                device.InputAssembler.SetInputLayout(layout);
                device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
                device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 32, 0));

                for (int i = 0; i < technique.Description.PassCount; ++i)
                {
                    pass.Apply();
                    device.Draw(3, 0);
                }

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

            vertices.Dispose();
            layout.Dispose();
            effect.Dispose();
            renderView.Dispose();
            backBuffer.Dispose();
            device.Dispose();
            swapChain.Dispose();
            //foreach (var item in ObjectTable.Objects)
            //    item.Dispose();
        }
Exemplo n.º 32
0
        private static void Main()
        {
            // Device creation
            var form = new RenderForm("Stereo test")
                           {
                               ClientSize = size,
                               //FormBorderStyle = System.Windows.Forms.FormBorderStyle.None,
                               //WindowState = FormWindowState.Maximized
                           };

            form.KeyDown += new KeyEventHandler(form_KeyDown);
               // form.Resize += new EventHandler(form_Resize);

            ModeDescription mDesc = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                                        new Rational(120000, 1000), Format.R8G8B8A8_UNorm);
            mDesc.ScanlineOrdering = DisplayModeScanlineOrdering.Progressive;
            mDesc.Scaling = DisplayModeScaling.Unspecified;

            var desc = new SwapChainDescription()
                           {
                               BufferCount = 1,
                               ModeDescription = mDesc,
                                   Flags = SwapChainFlags.AllowModeSwitch,
                               IsWindowed = false,
                               OutputHandle = form.Handle,
                               SampleDescription = new SampleDescription(1, 0),
                               SwapEffect = SwapEffect.Discard,
                               Usage = Usage.RenderTargetOutput
                           };

            Device.CreateWithSwapChain(null, DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device,
                                       out swapChain);

            //Stops Alt+enter from causing fullscreen skrewiness.
            factory = swapChain.GetParent<Factory>();
            factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

            backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);
            renderView = new RenderTargetView(device, backBuffer);

            ImageLoadInformation info = new ImageLoadInformation()
                                            {
                                                BindFlags = BindFlags.None,
                                                CpuAccessFlags = CpuAccessFlags.Read,
                                                FilterFlags = FilterFlags.None,
                                                Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                MipFilterFlags = FilterFlags.None,
                                                OptionFlags = ResourceOptionFlags.None,
                                                Usage = ResourceUsage.Staging,
                                                MipLevels = 1
                                            };

            // Make texture 3D
            sourceTexture = Texture2D.FromFile(device, "medusa.jpg", info);
            ImageLoadInformation info2 = new ImageLoadInformation()
                                            {
                                                BindFlags = BindFlags.ShaderResource,
                                                CpuAccessFlags = CpuAccessFlags.None,
                                                FilterFlags = FilterFlags.None,
                                                Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                MipFilterFlags = FilterFlags.None,
                                                OptionFlags = ResourceOptionFlags.None,
                                                Usage = ResourceUsage.Default,
                                                MipLevels = 1
                                            };
            Texture2D tShader = Texture2D.FromFile(device, "medusa.jpg", info2);
            srv = new ShaderResourceView(device, tShader);
            //ResizeDevice(new Size(1920, 1080), true);
            // Create a quad that fills the whole screen

            BuildQuad();
            // Create world view (ortho) projection matrices
            //QuaternionCam qCam = new QuaternionCam();

            // Load effect from file. It is a basic effect that renders a full screen quad through
            // an ortho projectio=n matrix
            effect = Effect.FromFile(device, "Texture.fx", "fx_4_0", ShaderFlags.Debug, EffectFlags.None);
            EffectTechnique technique = effect.GetTechniqueByIndex(0);
            EffectPass pass = technique.GetPassByIndex(0);
            InputLayout layout = new InputLayout(device, pass.Description.Signature, new[]
                                                                                         {
                                                                                             new InputElement(
                                                                                                 "POSITION", 0,
                                                                                                 Format.
                                                                                                     R32G32B32A32_Float,
                                                                                                 0, 0),
                                                                                             new InputElement(
                                                                                                 "TEXCOORD", 0,
                                                                                                 Format.
                                                                                                     R32G32_Float,
                                                                                                 16, 0)
                                                                                         });
            //effect.GetVariableByName("mWorld").AsMatrix().SetMatrix(
            //    Matrix.Translation(Layout.OrthographicTransform(Vector2.Zero, 99, size)));
            //effect.GetVariableByName("mView").AsMatrix().SetMatrix(qCam.View);
            //effect.GetVariableByName("mProjection").AsMatrix().SetMatrix(qCam.OrthoProjection);
            //effect.GetVariableByName("tDiffuse").AsResource().SetResource(srv);

            // Set RT and Viewports
            device.OutputMerger.SetTargets(renderView);
            device.Rasterizer.SetViewports(new Viewport(0, 0, size.Width, size.Height, 0.0f, 1.0f));

            // Create solid rasterizer state
            RasterizerStateDescription rDesc = new RasterizerStateDescription()
                                                   {
                                                       CullMode = CullMode.None,
                                                       IsDepthClipEnabled = true,
                                                       FillMode = FillMode.Solid,
                                                       IsAntialiasedLineEnabled = false,
                                                       IsFrontCounterclockwise = true,
                                                       //IsMultisampleEnabled = true,
                                                   };
            RasterizerState rState = RasterizerState.FromDescription(device, rDesc);
            device.Rasterizer.State = rState;

            Texture2DDescription rtDesc = new Texture2DDescription
                                              {
                                                  ArraySize = 1,
                                                  Width = size.Width,
                                                  Height = size.Height,
                                                  BindFlags = BindFlags.RenderTarget,
                                                  CpuAccessFlags = CpuAccessFlags.None,
                                                  Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                                                  OptionFlags = ResourceOptionFlags.None,
                                                  Usage = ResourceUsage.Default,
                                                  MipLevels = 1,
                                                  SampleDescription = new SampleDescription(1, 0)
                                              };
            rtTex = new Texture2D(device, rtDesc);

            rv = new RenderTargetView(device, rtTex);

            stereoizedTexture = Make3D(sourceTexture);
            //ResizeDevice(new Size(1920, 1080), true);
            Console.WriteLine(form.ClientSize);
            // Main Loop
            MessagePump.Run(form, () =>
            {
            device.ClearRenderTargetView(renderView, Color.Cyan);

            //device.InputAssembler.SetInputLayout(layout);
            //device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            //device.OutputMerger.SetTargets(rv);
            //device.InputAssembler.SetVertexBuffers(0,
            //                                new VertexBufferBinding(vertices, 24, 0));
            //device.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);
            //for (int i = 0; i < technique.Description.PassCount; ++i)
            //{
            //    // Render the full screen quad
            //    pass.Apply();
            //    device.DrawIndexed(6, 0, 0);
            //}
            ResourceRegion stereoSrcBox = new ResourceRegion { Front = 0, Back = 1, Top = 0, Bottom = size.Height, Left = 0, Right = size.Width };
            device.CopySubresourceRegion(stereoizedTexture, 0, stereoSrcBox, backBuffer, 0, 0, 0, 0);
            //device.CopyResource(rv.Resource, backBuffer);

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

            // Dispose resources
            vertices.Dispose();
            layout.Dispose();
            effect.Dispose();
            renderView.Dispose();
            backBuffer.Dispose();
            device.Dispose();
            swapChain.Dispose();

            rState.Dispose();
            stereoizedTexture.Dispose();
            sourceTexture.Dispose();
            indices.Dispose();
            srv.Dispose();
        }
Exemplo n.º 33
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var form = new Form1();

            Device device;
            SwapChain swapChain;
            ShaderSignature inputSignature;
            VertexShader vertexShader;
            GeometryShader geometryShader;
            PixelShader pixelShader;

            var description = new SwapChainDescription()
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = form.Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out device, out swapChain);

            // create a view of our render target, which is the backbuffer of the swap chain we just created
            RenderTargetView renderTarget;
            using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
                renderTarget = new RenderTargetView(device, resource);

            // setting a viewport is required if you want to actually see anything
            var context = device.ImmediateContext;
            var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
            context.OutputMerger.SetTargets(renderTarget);
            context.Rasterizer.SetViewports(viewport);

            // load and compile the vertex shader
            using (var bytecode = ShaderBytecode.CompileFromFile("Voxel.fx", "VS", "vs_4_0", ShaderFlags.None, EffectFlags.None))
            {
                inputSignature = ShaderSignature.GetInputSignature(bytecode);
                vertexShader = new VertexShader(device, bytecode);
            }

            using (var bytecode = ShaderBytecode.CompileFromFile("Voxel.fx", "GS", "gs_4_0", ShaderFlags.None, EffectFlags.None))
            {
                geometryShader = new GeometryShader(device, bytecode);
            }

            // load and compile the pixel shader
            using (var bytecode = ShaderBytecode.CompileFromFile("Voxel.fx", "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None))
                pixelShader = new PixelShader(device, bytecode);

            // create test vertex data, making sure to rewind the stream afterward
            var vertices = new DataStream(12 * 3, true, true);
            vertices.Write(new Vector3(0.0f, 0.5f, 0.5f));
            vertices.Write(new Vector3(0.5f, -0.5f, 0.5f));
            vertices.Write(new Vector3(-0.5f, -0.5f, 0.5f));
            vertices.Position = 0;

            // create the vertex layout and buffer
            var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0) };
            var layout = new InputLayout(device, inputSignature, elements);
            var vertexBuffer = new Buffer(device, vertices, 12 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            // configure the Input Assembler portion of the pipeline with the vertex data
            context.InputAssembler.InputLayout = layout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 12, 0));

            // set the shaders
            context.VertexShader.Set(vertexShader);
            // context.GeometryShader.Set(geometryShader);
            context.PixelShader.Set(pixelShader);

            // prevent DXGI handling of alt+enter, which doesn't work properly with Winforms
            using (var factory = swapChain.GetParent<Factory>())
                factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);

            // handle alt+enter ourselves
            form.KeyDown += (o, e) =>
            {
                if (e.Alt && e.KeyCode == Keys.Enter)
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
            };

            // handle form size changes
            form.Resize += (o, e) =>
            {
                renderTarget.Dispose();

                swapChain.ResizeBuffers(2, 0, 0, Format.R8G8B8A8_UNorm, SwapChainFlags.AllowModeSwitch);
                using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
                    renderTarget = new RenderTargetView(device, resource);

                context.OutputMerger.SetTargets(renderTarget);
            };

            MessagePump.Run(form, () =>
            {
                // clear the render target to a soothing blue
                context.ClearRenderTargetView(renderTarget, new Color4(0.5f, 0.5f, 1.0f));

                // draw the triangle
                context.Draw(3, 0);
                swapChain.Present(0, PresentFlags.None);
            });

            // clean up all resources
            // anything we missed will show up in the debug output
            vertices.Close();
            vertexBuffer.Dispose();
            layout.Dispose();
            inputSignature.Dispose();
            vertexShader.Dispose();
            geometryShader.Dispose();
            pixelShader.Dispose();
            renderTarget.Dispose();
            swapChain.Dispose();
            device.Dispose();
        }