private unsafe void RenderImDrawData(DrawData *draw_data, RenderContext rc) { VertexDescriptor descriptor = new VertexDescriptor((byte)sizeof(DrawVert), 3, 0, IntPtr.Zero); int vertexOffsetInVertices = 0; int indexOffsetInElements = 0; if (draw_data->CmdListsCount == 0) { return; } for (int i = 0; i < draw_data->CmdListsCount; i++) { DrawList *cmd_list = draw_data->CmdLists[i]; _vertexBuffer.SetVertexData(new IntPtr(cmd_list->VtxBuffer.Data), descriptor, cmd_list->VtxBuffer.Size, vertexOffsetInVertices); _indexBuffer.SetIndices(new IntPtr(cmd_list->IdxBuffer.Data), IndexFormat.UInt16, sizeof(ushort), cmd_list->IdxBuffer.Size, indexOffsetInElements); vertexOffsetInVertices += cmd_list->VtxBuffer.Size; indexOffsetInElements += cmd_list->IdxBuffer.Size; } // Setup orthographic projection matrix into our constant buffer { var io = ImGui.GetIO(); Matrix4x4 mvp = Matrix4x4.CreateOrthographicOffCenter( 0f, io.DisplaySize.X, io.DisplaySize.Y, 0.0f, -1.0f, 1.0f); _projectionMatrixProvider.Data = mvp; } BlendState previousBlendState = rc.BlendState; rc.SetBlendState(_blendState); rc.SetDepthStencilState(_depthDisabledState); RasterizerState previousRasterizerState = rc.RasterizerState; rc.SetRasterizerState(_rasterizerState); rc.SetVertexBuffer(_vertexBuffer); rc.SetIndexBuffer(_indexBuffer); rc.SetMaterial(_material); ImGui.ScaleClipRects(draw_data, ImGui.GetIO().DisplayFramebufferScale); // Render command lists int vtx_offset = 0; int idx_offset = 0; for (int n = 0; n < draw_data->CmdListsCount; n++) { DrawList *cmd_list = draw_data->CmdLists[n]; for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { DrawCmd *pcmd = &(((DrawCmd *)cmd_list->CmdBuffer.Data)[cmd_i]); if (pcmd->UserCallback != IntPtr.Zero) { throw new NotImplementedException(); } else { if (pcmd->TextureId != IntPtr.Zero) { if (pcmd->TextureId == new IntPtr(_fontAtlasID)) { _material.UseTexture(0, _fontTextureBinding); } else { ShaderTextureBinding binding = ImGuiImageHelper.GetShaderTextureBinding(pcmd->TextureId); _material.UseTexture(0, binding); } } // TODO: This doesn't take into account viewport coordinates. rc.SetScissorRectangle( (int)pcmd->ClipRect.X, (int)pcmd->ClipRect.Y, (int)pcmd->ClipRect.Z, (int)pcmd->ClipRect.W); rc.DrawIndexedPrimitives((int)pcmd->ElemCount, idx_offset, vtx_offset); } idx_offset += (int)pcmd->ElemCount; } vtx_offset += cmd_list->VtxBuffer.Size; } rc.ClearScissorRectangle(); rc.SetBlendState(previousBlendState); rc.SetDepthStencilState(rc.DefaultDepthStencilState); rc.SetRasterizerState(previousRasterizerState); }
public FontBatch3D FontBatch(BitmapFont font, int layer = 0, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, BlendState blendState = null, SamplerState samplerState = null) { depthStencilState = (depthStencilState ?? DepthStencilState.Default); rasterizerState = (rasterizerState ?? RasterizerState.CullNoneScissor); blendState = (blendState ?? BlendState.AlphaBlend); samplerState = (samplerState ?? SamplerState.LinearClamp); return(FindFontBatch(font, layer, depthStencilState, rasterizerState, blendState, samplerState)); }
public FlatBatch3D FlatBatch(int layer = 0, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, BlendState blendState = null) { depthStencilState = (depthStencilState ?? DepthStencilState.Default); rasterizerState = (rasterizerState ?? RasterizerState.CullNoneScissor); blendState = (blendState ?? BlendState.AlphaBlend); return(FindFlatBatch(layer, depthStencilState, rasterizerState, blendState)); }
public TexturedBatch3D TexturedBatch(Texture2D texture, bool useAlphaTest = false, int layer = 0, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, BlendState blendState = null, SamplerState samplerState = null) { depthStencilState = (depthStencilState ?? DepthStencilState.Default); rasterizerState = (rasterizerState ?? RasterizerState.CullNoneScissor); blendState = (blendState ?? BlendState.AlphaBlend); samplerState = (samplerState ?? SamplerState.LinearClamp); return(FindTexturedBatch(texture, useAlphaTest, layer, depthStencilState, rasterizerState, blendState, samplerState)); }