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; }