Esempio n. 1
0
        public GuiRender(GpuDevice device)
        {
            //gui render is a simple render to render gui object
            //gui render can provide some simple object draw function
            //we can replace it to our render and we can use it in the gui system render function
            mDevice = device;

            //default transform is I
            mTransforms = new Stack <Matrix4x4>();

            //init blend state
            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
            });

            //init vertex shader, for all draw command we use same vertex shader
            mVertexShader = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.GuiRenderShader, "vs_main"));

            //init pixel shader, we will choose the best pixel shader for different draw command
            mPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.GuiRenderShader, "ps_main"));

            //init sampler state
            mSamplerState = new GpuSamplerState(mDevice);

            //init input layout
            //Position : float3
            //Texcoord : float2
            mInputLayout = new GpuInputLayout(mDevice, new InputElement[]
            {
                new InputElement("POSITION", 0, 12),
                new InputElement("TEXCOORD", 0, 8)
            }, mVertexShader);


            InitializeSquareBuffer();
            InitializeConstantBuffer();
            InitializeRectangleBuffer();
        }
Esempio n. 2
0
        public GuiRender(GpuDevice device)
        {
            //gui render is a simple render to render gui object
            //gui render can provide some simple object draw function
            //we can replace it to our render and we can use it in the gui system render function
            mDevice = device;

            //default transform is I
            Transform = Matrix4x4.Identity;

            //init blend state
            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
            });

            //init vertex shader, for all draw command we use same vertex shader
            mVertexShader = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.GuiRenderCommonVertexShader));

            //init pixel shader, we will choose the best pixel shader for different draw command
            mColorPixelShader   = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.GuiRenderColorPixelShader));
            mTexturePixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.GuiRenderTexturePixelShader));

            //init sampler state
            mSamplerState = new GpuSamplerState(mDevice);

            //init input layout
            //Position : float3
            //Texcoord : float2
            mInputLayout = new GpuInputLayout(mDevice, new InputElement[]
            {
                new InputElement("POSITION", 0, 12),
                new InputElement("TEXCOORD", 0, 8)
            }, mVertexShader);


            //init render object vertex buffer and index buffer
            //init square vertex data
            Vertex[] squareVertices = new Vertex[]
            {
                new Vertex()
                {
                    Position = new Vector3(0, 0, 0), TexCoord = new Vector2(0, 0)
                },
                new Vertex()
                {
                    Position = new Vector3(0, 1, 0), TexCoord = new Vector2(0, 1)
                },
                new Vertex()
                {
                    Position = new Vector3(1, 1, 0), TexCoord = new Vector2(1, 1)
                },
                new Vertex()
                {
                    Position = new Vector3(1, 0, 0), TexCoord = new Vector2(1, 0)
                }
            };

            //init square index data
            uint[] squareIndices = new uint[] { 0, 1, 2, 0, 2, 3 };

            //init square buffer and update
            mSquareVertexBuffer = new GpuBuffer(
                Utility.SizeOf <Vertex>() * squareVertices.Length,
                Utility.SizeOf <Vertex>() * 1,
                mDevice,
                GpuResourceInfo.VertexBuffer());

            mSquareIndexBuffer = new GpuBuffer(
                Utility.SizeOf <uint>() * squareIndices.Length,
                Utility.SizeOf <uint>() * 1,
                mDevice,
                GpuResourceInfo.IndexBuffer());

            mSquareVertexBuffer.Update(squareVertices);
            mSquareIndexBuffer.Update(squareIndices);

            //init rectangle index data
            uint[] rectangleIndices = new uint[]
            {
                0, 4, 1, 1, 4, 5,
                0, 3, 4, 3, 7, 4,
                3, 6, 7, 2, 6, 3,
                2, 1, 6, 1, 5, 6
            };

            //init rectangle vertex and index buffer
            mRectangleVertexBuffer = new GpuBuffer(
                Utility.SizeOf <Vertex>() * 8,
                Utility.SizeOf <Vertex>() * 1,
                mDevice,
                GpuResourceInfo.VertexBuffer());

            mRectangleIndexBuffer = new GpuBuffer(
                Utility.SizeOf <uint>() * 24,
                Utility.SizeOf <uint>() * 1,
                mDevice,
                GpuResourceInfo.IndexBuffer());

            mRectangleIndexBuffer.Update(rectangleIndices);


            //init shader buffer
            mMatrixDataBuffer = new GpuBuffer(
                Utility.SizeOf <MatrixData>(),
                Utility.SizeOf <MatrixData>(),
                mDevice,
                GpuResourceInfo.ConstantBuffer());

            mRenderConfigBuffer = new GpuBuffer(
                Utility.SizeOf <RenderConfig>(),
                Utility.SizeOf <RenderConfig>(),
                mDevice,
                GpuResourceInfo.ConstantBuffer());
        }
Esempio n. 3
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);
        }