Ejemplo n.º 1
0
            public void DoDraw(DateTime dateTime, GpuSwapChain swapChain)
            {
                using (var uniformTimeCpuBufferStream = UniformTimeCpuBuffer.AsStream())
                    using (var uniformTimeCpuBufferWriter = new BinaryWriter(uniformTimeCpuBufferStream))
                    {
                        float frametime = ((float)(dateTime - StartDateTime).TotalMilliseconds) / 1000;
                        uniformTimeCpuBufferWriter.Write(frametime);
                    }
                Device.DefaultQueue.WriteBuffer(UniformBuffer, TimeOffset, UniformTimeCpuBuffer);
                var renderPassDesriptor = new GpuRenderPassDescriptor(new GpuRenderPassColorAttachment[]
                {
                    new GpuRenderPassColorAttachment(swapChain.GetCurrentTexture().CreateView(), new GpuColorDict {
                        R = 0, B = 0, G = 0, A = 1.0f
                    })
                });
                var commandEncoder = Device.CreateCommandEncoder();
                var passEncoder    = commandEncoder.BeginRenderPass(renderPassDesriptor);

                if (Settings.RenderBundles)
                {
                    passEncoder.ExecuteBundles(new GpuRenderBundle[] { RenderBundle });
                }
                else
                {
                    RecordRenderPass(passEncoder);
                }
                passEncoder.EndPass();
                Device.DefaultQueue.Sumit(new GpuCommandBuffer[] { commandEncoder.Finish() });
            }
Ejemplo n.º 2
0
        public PresentRender(GpuDevice device, IntPtr handle, Size size)
        {
            mHandle    = handle;
            mDevice    = device;
            mSwapChain = new GpuSwapChain(handle, size, GpuPixelFormat.R8G8B8A8Unknown, mDevice);

            mBlendState = new GpuBlendState(mDevice, new RenderTargetBlendDescription()
            {
                AlphaBlendOperation   = GpuBlendOperation.Add,
                BlendOperation        = GpuBlendOperation.Add,
                DestinationAlphaBlend = GpuBlendOption.InverseSourceAlpha,
                DestinationBlend      = GpuBlendOption.InverseSourceAlpha,
                SourceAlphaBlend      = GpuBlendOption.SourceAlpha,
                SourceBlend           = GpuBlendOption.SourceAlpha,
                IsBlendEnable         = true
            });

            //compile shader
            mVertexShader    = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.PresentVertexShader));
            mDrawPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.PresentDrawPixelShader));
            mMaskPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.PresentMaskPixelShader));

            //create input layout, we only need to render texture
            mInputLayout = new GpuInputLayout(mDevice, new InputElement[]
            {
                new InputElement("POSITION", 0, 12),
                new InputElement("TEXCOORD", 0, 8)
            }, mVertexShader);

            //init vertex and index data
            Vertex[] vertices = new Vertex[]
            {
                new Vertex()
                {
                    Position = new System.Numerics.Vector3(0, 0, 0), TexCoord = new System.Numerics.Vector2(0, 0)
                },
                new Vertex()
                {
                    Position = new System.Numerics.Vector3(0, 1, 0), TexCoord = new System.Numerics.Vector2(0, 1)
                },
                new Vertex()
                {
                    Position = new System.Numerics.Vector3(1, 1, 0), TexCoord = new System.Numerics.Vector2(1, 1)
                },
                new Vertex()
                {
                    Position = new System.Numerics.Vector3(1, 0, 0), TexCoord = new System.Numerics.Vector2(1, 0)
                }
            };

            uint[] indices = new uint[]
            {
                0, 1, 2,
                2, 3, 0
            };

            //create vertex and index buffer
            mVertexBuffer = new GpuBuffer(
                Utility.SizeOf <Vertex>() * vertices.Length,
                Utility.SizeOf <Vertex>(),
                mDevice, GpuResourceInfo.VertexBuffer());

            mIndexBuffer = new GpuBuffer(
                Utility.SizeOf <uint>() * indices.Length,
                Utility.SizeOf <uint>(),
                mDevice, GpuResourceInfo.IndexBuffer());

            mVertexBuffer.Update(vertices);
            mIndexBuffer.Update(indices);

            //create constant buffer
            //transform buffer is used for vertex shader to do transform
            //render config buffer is used for pixel shader to render with opacity
            mTransformBuffer = new GpuBuffer(
                Utility.SizeOf <Transform>(),
                Utility.SizeOf <Transform>(),
                mDevice, GpuResourceInfo.ConstantBuffer());

            mRenderConfigBuffer = new GpuBuffer(
                Utility.SizeOf <RenderConfig>(),
                Utility.SizeOf <RenderConfig>(),
                mDevice, GpuResourceInfo.ConstantBuffer());

            mGpuSamplerState = new GpuSamplerState(mDevice);
        }
Ejemplo n.º 3
0
        public void ReSize(Size newSize)
        {
            Utility.Dispose(ref mSwapChain);

            mSwapChain = new GpuSwapChain(mHandle, newSize, GpuPixelFormat.R8G8B8A8Unknown, mDevice);
        }