Exemplo n.º 1
0
        public virtual void BeginDraw(Image image)
        {
            //begin draw and we need set the render target before we draw anything

            //reset device and set render target
            mDevice.Reset();
            mDevice.SetRenderTarget(image.GpuRenderTarget);

            //set blend state
            mDevice.SetBlendState(mBlendState);

            //set input layout ,vertex shader and primitive type
            mDevice.SetInputLayout(mInputLayout);
            mDevice.SetPixelShader(mPixelShader);
            mDevice.SetVertexShader(mVertexShader);
            mDevice.SetPrimitiveType(GpuPrimitiveType.TriangleList);

            //set view port
            mDevice.SetViewPort(new Rectanglef(0, 0, image.Size.Width, image.Size.Height));

            mDevice.SetSamplerState(mSamplerState, mSamplerStateSlot, GpuShaderType.All);

            //set the project matrix, need set null when we end draw
            mProject = Matrix4x4.CreateOrthographicOffCenter(
                0, image.Size.Width,
                0, image.Size.Height, 0, 1);
        }
Exemplo n.º 2
0
        public virtual void DrawLine(Position <float> start, Position <float> end, Color <float> color,
                                     float padding = 2.0f)
        {
            //draw line with start and end position
            //padding means the width of line
            //color.Alpha means the opacity of line

            //first, we compute the matrix of world transform
            MatrixData matrixData = new MatrixData();
            Vector2    vector     = new Vector2(end.X - start.X, end.Y - start.Y);

            //1.compute the scale component, x-component is euqal the length of line, y-component is equal the padding
            matrixData.World = Matrix4x4.CreateScale(vector.Length(), padding, 1.0f);
            //2.compute the angle of rotate, we only rotate it at the z-axis
            matrixData.World *= Matrix4x4.CreateRotationZ((float)Math.Atan2(vector.Y, vector.X), new Vector3(0, padding * 0.5f, 0));
            //3.compute the translation, the position of start, but the y is start.y - padding * 0.5f
            matrixData.World *= Matrix4x4.CreateTranslation(new Vector3(start.X, start.Y - padding * 0.5f, 0));
            //4.keep transform matrix data
            matrixData.World *= Transform;

            //set project matrix
            matrixData.Project = mProject;

            //second, we set the render config
            RenderConfig renderConfig = new RenderConfig()
            {
                Color = color
            };

            //update buffer
            mMatrixDataBuffer.Update(matrixData);
            mRenderConfigBuffer.Update(renderConfig);

            //set buffer and shader
            mDevice.SetPixelShader(mColorPixelShader);
            mDevice.SetVertexBuffer(mSquareVertexBuffer);
            mDevice.SetIndexBuffer(mSquareIndexBuffer);

            mDevice.SetBuffer(mMatrixDataBuffer, mMatrixDataBufferSlot, GpuShaderType.VertexShader);
            mDevice.SetBuffer(mRenderConfigBuffer, mRenderConfigBufferSlot, GpuShaderType.PixelShader);

            //draw
            mDevice.DrawIndexed(6, 0, 0);
        }
Exemplo n.º 3
0
        public void BeginDraw()
        {
            //reset graphics pipeline and set render target
            mDevice.Reset();
            mDevice.SetRenderTarget(mSwapChain.RenderTarget);
            mDevice.ClearRenderTarget(mSwapChain.RenderTarget, new Colorf(1, 1, 1, 1));

            //set graphics pipeline
            mDevice.SetBlendState(mBlendState);

            mDevice.SetInputLayout(mInputLayout);
            mDevice.SetVertexBuffer(mVertexBuffer);
            mDevice.SetIndexBuffer(mIndexBuffer);
            mDevice.SetPrimitiveType(GpuPrimitiveType.TriangleList);

            mDevice.SetVertexShader(mVertexShader);
            mDevice.SetPixelShader(mDrawPixelShader);

            mDevice.SetViewPort(new Rectanglef(0, 0, mSwapChain.Size.Width, mSwapChain.Size.Height));
        }
Exemplo n.º 4
0
        public void BeginDraw(Image image, RenderMode mode)
        {
            //begin draw and we need set the render target before we draw anything
            Mode = mode;

            //reset device and set render target
            mDevice.Reset();
            mDevice.SetRenderTarget(image);

            //set blend and raster state and input layout
            mDevice.SetBlendState(mBlendState);
            mDevice.SetInputLayout(mInputLayout);
            mDevice.SetRasterizerState(mRasterizerState);

            //set vertex shader, pixel shader
            switch (Mode)
            {
            case RenderMode.Fill:
                mDevice.SetPixelShader(mFillBezierPixelShader);
                mDevice.SetVertexShader(mFillBezierVertexShader);
                break;

            case RenderMode.Draw:
                mDevice.SetPixelShader(mDrawBezierPixelShader);
                mDevice.SetVertexShader(mDrawBezierVertexShader);
                break;

            default: throw new Exception("Mode Not Supported.");
            }

            //set primitive type
            mDevice.SetPrimitiveType(GpuPrimitiveType.TriangleList);

            //set view port
            mDevice.SetViewPort(new Rectangle <float>(0, 0, image.Size.Width, image.Size.Height));

            //set the project matrix, need set null when we end draw
            mProjection = Matrix4x4.CreateOrthographicOffCenter(
                0, image.Size.Width,
                0, image.Size.Height, 0, 1);

            //set the canvas size
            mCanvasSize = image.Size;
        }