private void InitializeRectangleBuffer() { //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 <GuiVertex>() * 8, Utility.SizeOf <GuiVertex>() * 1, mDevice, GpuResourceInfo.VertexBuffer()); mRectangleIndexBuffer = new GpuBuffer( Utility.SizeOf <uint>() * 24, Utility.SizeOf <uint>() * 1, mDevice, GpuResourceInfo.IndexBuffer()); mRectangleIndexBuffer.Update(rectangleIndices); }
private void InitializeDrawComponent() { mDrawBeziersVertexShader = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.DrawBeziersShader, "vs_main")); mDrawBezierVertexShader = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.DrawBezierShader, "vs_main")); mDrawBeziersPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.DrawBeziersShader, "ps_main")); mDrawBezierPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.DrawBezierShader, "ps_main")); mEquationBuffer = new GpuBuffer( Utility.SizeOf <Equation>(), Utility.SizeOf <Equation>(), mDevice, GpuResourceInfo.ConstantBuffer()); mDrawVertexBuffer = new GpuBuffer( Utility.SizeOf <Vertex>() * 4, Utility.SizeOf <Vertex>(), mDevice, GpuResourceInfo.VertexBuffer()); mDrawIndexBuffer = new GpuBuffer( Utility.SizeOf <uint>() * 6, Utility.SizeOf <uint>(), mDevice, GpuResourceInfo.IndexBuffer()); var indices = new uint[] { 0, 1, 2, 0, 2, 3 }; mDrawIndexBuffer.Update(indices); }
private void InitializeSquareBuffer() { //init render object vertex buffer and index buffer //init square vertex data GuiVertex[] squareVertices = new GuiVertex[] { new GuiVertex() { Position = new Vector3f(0, 0, 0), Texcoord = new Vector2f(0, 0) }, new GuiVertex() { Position = new Vector3f(0, 1, 0), Texcoord = new Vector2f(0, 1) }, new GuiVertex() { Position = new Vector3f(1, 1, 0), Texcoord = new Vector2f(1, 1) }, new GuiVertex() { Position = new Vector3f(1, 0, 0), Texcoord = new Vector2f(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 <GuiVertex>() * squareVertices.Length, Utility.SizeOf <GuiVertex>() * 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); }
private void InitializeFillComponent() { //compile vertex and pixel shader to render bezier curve mFillBeziersVertexShader = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.FillBeziersShader, "vs_main")); mFillBezierVertexShader = new GpuVertexShader(mDevice, GpuVertexShader.Compile(Properties.Resources.FillBezierShader, "vs_main")); mFillBeziersPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.FillBeziersShader, "ps_main")); mFillBezierPixelShader = new GpuPixelShader(mDevice, GpuPixelShader.Compile(Properties.Resources.FillBezierShader, "ps_main")); //init vertex and index buffer //vertex data will be made when we draw bezier curve mFillVertexBuffer = new GpuBuffer( Utility.SizeOf <Vertex>() * 3, Utility.SizeOf <Vertex>() * 1, mDevice, GpuResourceInfo.VertexBuffer()); mFillIndexBuffer = new GpuBuffer( Utility.SizeOf <uint>() * 3, Utility.SizeOf <uint>() * 1, mDevice, GpuResourceInfo.IndexBuffer()); uint[] indices = new uint[] { 0, 1, 2 }; mFillIndexBuffer.Update(indices); mTrianglePointsBuffer = new GpuBuffer( Utility.SizeOf <TrianglePoints>(), Utility.SizeOf <TrianglePoints>(), mDevice, GpuResourceInfo.ConstantBuffer()); mTriangleColorsBuffer = new GpuBuffer( Utility.SizeOf <TriangleColors>(), Utility.SizeOf <TriangleColors>(), mDevice, GpuResourceInfo.ConstantBuffer()); }
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()); }
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); }