/// @author https://bitbucket.org/ChaosCreator/imgui-ogre2.1-binding/src/8f1a01db510f543a987c3c16859d0a33400d9097/ImguiRenderable.cpp?at=master&fileviewer=file-view-default /// Commentary on OGRE forums: http://www.ogre3d.org/forums/viewtopic.php?f=5&t=89081#p531059 void OgreImGui::ImGUIRenderable::updateVertexData(const ImDrawVert* vtxBuf, const ImDrawIdx* idxBuf, unsigned int vtxCount, unsigned int idxCount) { Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; if (bind->getBindings().empty() || mVertexBufferSize != vtxCount) { mVertexBufferSize = vtxCount; bind->setBinding(0, Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(ImDrawVert), mVertexBufferSize, Ogre::HardwareBuffer::HBU_WRITE_ONLY)); } if (mRenderOp.indexData->indexBuffer.isNull() || mIndexBufferSize != idxCount) { mIndexBufferSize = idxCount; mRenderOp.indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, mIndexBufferSize, Ogre::HardwareBuffer::HBU_WRITE_ONLY); } // Copy all vertices ImDrawVert* vtxDst = (ImDrawVert*)(bind->getBuffer(0)->lock(Ogre::HardwareBuffer::HBL_DISCARD)); ImDrawIdx* idxDst = (ImDrawIdx*)(mRenderOp.indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD)); memcpy(vtxDst, vtxBuf, mVertexBufferSize * sizeof(ImDrawVert)); memcpy(idxDst, idxBuf, mIndexBufferSize * sizeof(ImDrawIdx)); mRenderOp.vertexData->vertexStart = 0; mRenderOp.vertexData->vertexCount = vtxCount; mRenderOp.indexData->indexStart = 0; mRenderOp.indexData->indexCount = idxCount; bind->getBuffer(0)->unlock(); mRenderOp.indexData->indexBuffer->unlock(); }
void OgreImGui::ImGUIRenderable::updateVertexData(ImDrawData* draw_data,unsigned int cmdIndex) { Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; const ImDrawList* cmd_list = draw_data->CmdLists[cmdIndex]; if (bind->getBindings().empty() || mVertexBufferSize != cmd_list->VtxBuffer.size()) { mVertexBufferSize = cmd_list->VtxBuffer.size(); bind->setBinding(0,Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(ImDrawVert),mVertexBufferSize,Ogre::HardwareBuffer::HBU_WRITE_ONLY)); } if (mRenderOp.indexData->indexBuffer.isNull() || mIndexBufferSize != cmd_list->IdxBuffer.size()) { mIndexBufferSize = cmd_list->IdxBuffer.size(); mRenderOp.indexData->indexBuffer= Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT,mIndexBufferSize,Ogre::HardwareBuffer::HBU_WRITE_ONLY); } // Copy all vertices ImDrawVert* vtx_dst = (ImDrawVert*)(bind->getBuffer(0)->lock(Ogre::HardwareBuffer::HBL_DISCARD)); ImDrawIdx* idx_dst = (ImDrawIdx*)(mRenderOp.indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD)); memcpy(vtx_dst, &cmd_list->VtxBuffer[0], mVertexBufferSize * sizeof(ImDrawVert)); memcpy(idx_dst, &cmd_list->IdxBuffer[0], mIndexBufferSize * sizeof(ImDrawIdx)); mRenderOp.vertexData->vertexStart = 0; mRenderOp.vertexData->vertexCount = cmd_list->VtxBuffer.size(); mRenderOp.indexData->indexStart = 0; mRenderOp.indexData->indexCount = cmd_list->IdxBuffer.size(); bind->getBuffer(0)->unlock(); mRenderOp.indexData->indexBuffer->unlock(); }