Skip to content

Instantly share code, notes, and snippets.

@A3Wypiok
Last active July 6, 2023 18:28
Show Gist options
  • Save A3Wypiok/16af9bd22b8b4e4d60159b02f841b19c to your computer and use it in GitHub Desktop.
Save A3Wypiok/16af9bd22b8b4e4d60159b02f841b19c to your computer and use it in GitHub Desktop.
diff --git a/Code/ServerApp/Source/NetImguiServer_RemoteClient.cpp b/Code/ServerApp/Source/NetImguiServer_RemoteClient.cpp
index 21ec2d0..19af2ff 100644
--- a/Code/ServerApp/Source/NetImguiServer_RemoteClient.cpp
+++ b/Code/ServerApp/Source/NetImguiServer_RemoteClient.cpp
@@ -12,11 +12,8 @@ static Client* gpClients = nullptr; // Table of all potentially connected clien
static uint32_t gClientCountMax = 0;
NetImguiImDrawData::NetImguiImDrawData()
-: mCommandList(nullptr)
{
- CmdListsCount = 1; // All draws collapsed in same CmdList
- mpCommandList = &mCommandList;
- CmdLists = &mpCommandList;
+ CmdLists = nullptr;
}
@@ -219,6 +216,28 @@ uint32_t Client::GetFreeIndex()
return kInvalidClient;
}
+static void DestroyDrawData(NetImguiImDrawData*& pDrawData)
+{
+ if( pDrawData )
+ {
+ if( pDrawData->CmdLists )
+ {
+ for(int k(0); k<pDrawData->CmdListsCount; ++k)
+ {
+ ImDrawList * drawList = pDrawData->CmdLists[k];
+ if( drawList )
+ {
+ NetImgui::Internal::netImguiDelete( drawList );
+ }
+ }
+ NetImgui::Internal::netImguiDelete( pDrawData->CmdLists );
+ }
+ NetImgui::Internal::netImguiDeleteSafe( pDrawData );
+ }
+}
+
+
+
//=================================================================================================
// Get the current Dear Imgui drawdata to use for this client rendering content
//=================================================================================================
@@ -228,7 +247,8 @@ NetImguiImDrawData* Client::GetImguiDrawData(void* pEmtpyTextureHAL)
NetImguiImDrawData* pPendingDrawData = mPendingImguiDrawDataIn.Release();
if( pPendingDrawData )
{
- NetImgui::Internal::netImguiDeleteSafe( mpImguiDrawData );
+ DestroyDrawData(mpImguiDrawData);
+
mpImguiDrawData = pPendingDrawData;
const size_t clientTexCount = mvTextures.size();
@@ -274,6 +294,7 @@ NetImguiImDrawData* Client::ConvertToImguiDrawData(const NetImgui::Internal::Cmd
NetImguiImDrawData* pDrawData = NetImgui::Internal::netImguiNew<NetImguiImDrawData>();
pDrawData->Valid = true;
+ pDrawData->CmdListsCount = static_cast<int>(pCmdDrawFrame->mDrawGroupCount);
pDrawData->TotalVtxCount = static_cast<int>(pCmdDrawFrame->mTotalVerticeCount);
pDrawData->TotalIdxCount = static_cast<int>(pCmdDrawFrame->mTotalIndiceCount);
pDrawData->DisplayPos.x = pCmdDrawFrame->mDisplayArea[0];
@@ -283,23 +304,30 @@ NetImguiImDrawData* Client::ConvertToImguiDrawData(const NetImgui::Internal::Cmd
pDrawData->FramebufferScale = ImVec2(1,1); //! @sammyfreg Currently untested, so force set to 1
pDrawData->OwnerViewport = nullptr;
- ImDrawList* pCmdList = pDrawData->CmdLists[0];
- pCmdList->IdxBuffer.resize(pCmdDrawFrame->mTotalIndiceCount);
- pCmdList->VtxBuffer.resize(pCmdDrawFrame->mTotalVerticeCount);
- pCmdList->CmdBuffer.resize(pCmdDrawFrame->mTotalDrawCount);
- pCmdList->Flags = ImDrawListFlags_AllowVtxOffset|ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedFill|ImDrawListFlags_AntiAliasedLinesUseTex;
+ pDrawData->CmdLists = NetImgui::Internal::netImguiNew<ImDrawList*>();
+ pDrawData->CmdLists = new( ImGui::MemAlloc(pDrawData->CmdListsCount*sizeof(ImDrawList*)) ) ImDrawList*();
if( pCmdDrawFrame->mTotalDrawCount == 0 ){
return pDrawData;
}
uint32_t indexOffset(0), vertexOffset(0);
- ImDrawIdx* pIndexDst = &pCmdList->IdxBuffer[0];
- ImDrawVert* pVertexDst = &pCmdList->VtxBuffer[0];
- ImDrawCmd* pCommandDst = &pCmdList->CmdBuffer[0];
for(uint32_t i(0); i<pCmdDrawFrame->mDrawGroupCount; ++i){
+ pDrawData->CmdLists[i] = new( ImGui::MemAlloc(sizeof(ImDrawList)) ) ImDrawList(nullptr);
+ ImDrawList* pCmdList = pDrawData->CmdLists[i];
+
const NetImgui::Internal::ImguiDrawGroup& drawGroup = pCmdDrawFrame->mpDrawGroups[i];
+
+ pCmdList->IdxBuffer.resize(drawGroup.mIndiceCount);
+ pCmdList->VtxBuffer.resize(drawGroup.mVerticeCount);
+ pCmdList->CmdBuffer.resize(drawGroup.mDrawCount);
+ pCmdList->Flags = ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedFill|ImDrawListFlags_AntiAliasedLinesUseTex;
+
+ ImDrawIdx* pIndexDst = &pCmdList->IdxBuffer[0];
+ ImDrawVert* pVertexDst = &pCmdList->VtxBuffer[0];
+ ImDrawCmd* pCommandDst = &pCmdList->CmdBuffer[0];
+
// Copy/Convert Indices from network command to Dear ImGui indices format
const uint16_t* pIndices = reinterpret_cast<const uint16_t*>(drawGroup.mpIndices.Get());
@@ -315,6 +343,7 @@ NetImguiImDrawData* Client::ConvertToImguiDrawData(const NetImgui::Internal::Cmd
}
// Convert the Vertices from network command to Dear Imgui Format
+ unsigned int IndiceOffset = 0;
const NetImgui::Internal::ImguiVert* pVertexSrc = drawGroup.mpVertices.Get();
for (uint32_t vtxIdx(0); vtxIdx < drawGroup.mVerticeCount; ++vtxIdx)
{
@@ -333,12 +362,14 @@ NetImguiImDrawData* Client::ConvertToImguiDrawData(const NetImgui::Internal::Cmd
pCommandDst[drawIdx].ClipRect.y = pDrawSrc[drawIdx].mClipRect[1];
pCommandDst[drawIdx].ClipRect.z = pDrawSrc[drawIdx].mClipRect[2];
pCommandDst[drawIdx].ClipRect.w = pDrawSrc[drawIdx].mClipRect[3];
- pCommandDst[drawIdx].VtxOffset = pDrawSrc[drawIdx].mVtxOffset + vertexOffset;
- pCommandDst[drawIdx].IdxOffset = pDrawSrc[drawIdx].mIdxOffset + indexOffset;
+ pCommandDst[drawIdx].VtxOffset = 0;
+ pCommandDst[drawIdx].IdxOffset = IndiceOffset;
pCommandDst[drawIdx].ElemCount = pDrawSrc[drawIdx].mIdxCount;
pCommandDst[drawIdx].UserCallback = nullptr;
pCommandDst[drawIdx].UserCallbackData = nullptr;
pCommandDst[drawIdx].TextureId = NetImgui::Internal::TextureCastFromUInt(pDrawSrc[drawIdx].mTextureId);
+
+ IndiceOffset += pCommandDst[drawIdx].ElemCount;
}
pIndexDst += drawGroup.mIndiceCount;
diff --git a/Code/ServerApp/Source/NetImguiServer_RemoteClient.h b/Code/ServerApp/Source/NetImguiServer_RemoteClient.h
index 478e5f9..88be1a6 100644
--- a/Code/ServerApp/Source/NetImguiServer_RemoteClient.h
+++ b/Code/ServerApp/Source/NetImguiServer_RemoteClient.h
@@ -19,8 +19,6 @@ namespace NetImguiServer { namespace RemoteClient
struct NetImguiImDrawData : ImDrawData
{
NetImguiImDrawData();
- ImDrawList mCommandList;
- ImDrawList* mpCommandList = nullptr;
};
//=================================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment