@@ -68,6 +68,7 @@ ImGuiOverlay::ImGuiOverlay() : Overlay("ImGuiOverlay")
6868 ImGuiIO& io = ImGui::GetIO ();
6969
7070 io.BackendPlatformName = " OGRE" ;
71+ io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures;
7172}
7273ImGuiOverlay::~ImGuiOverlay ()
7374{
@@ -104,7 +105,7 @@ void ImGuiOverlay::ImGUIRenderable::createMaterial()
104105 mPass ->setSeparateSceneBlending (SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA, SBF_ONE, SBF_ONE_MINUS_SOURCE_ALPHA);
105106
106107 TextureUnitState* mTexUnit = mPass ->createTextureUnitState ();
107- mTexUnit ->setTexture (mFontTex );
108+ // mTexUnit->setTexture(mFontTex);
108109 mTexUnit ->setTextureFiltering (TFO_NONE);
109110 mTexUnit ->setTextureAddressingMode (TAM_CLAMP);
110111
@@ -158,9 +159,11 @@ void ImGuiOverlay::ImGUIRenderable::createFontTexture()
158159 ImGuiIO& io = ImGui::GetIO ();
159160 if (io.Fonts ->Fonts .empty ())
160161 io.Fonts ->AddFontDefault ();
162+
163+ return ;
161164 unsigned char * pixels;
162165 int width, height;
163- io.Fonts ->GetTexDataAsRGBA32 (&pixels, &width, &height);
166+ // io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
164167
165168 mFontTex = TextureManager::getSingleton ().createManual (" ImGui/FontTex" , RGN_INTERNAL, TEX_TYPE_2D,
166169 width, height, 1 , 1 , PF_BYTE_RGBA);
@@ -193,6 +196,51 @@ void ImGuiOverlay::NewFrame()
193196 ImGui::NewFrame ();
194197}
195198
199+ #if IMGUI_VERSION_NUM >= 19200
200+ static void updateTextureData (ImVector<ImTextureData*>& textures)
201+ {
202+ static int texCounter = 0 ;
203+
204+ for (auto tex : textures)
205+ {
206+ if (tex->Status == ImTextureStatus_OK)
207+ continue ; // nothing to do
208+
209+ if (tex->Status == ImTextureStatus_WantCreate)
210+ {
211+ OgreAssert (tex->Format == ImTextureFormat_RGBA32, " ImGuiOverlay only supports RGBA32 textures" );
212+ auto otex = TextureManager::getSingleton ().createManual (StringUtil::format (" ImGui/Tex%d" , texCounter++),
213+ RGN_INTERNAL, TEX_TYPE_2D, tex->Width , tex->Height ,
214+ 1 , 0 , PF_BYTE_RGBA);
215+
216+ otex->getBuffer ()->blitFromMemory (
217+ PixelBox (Box (0 , 0 , tex->Width , tex->Height ), PF_BYTE_RGBA, tex->GetPixels ()));
218+
219+ tex->SetTexID ((ImTextureID)otex->getHandle ());
220+ tex->SetStatus (ImTextureStatus_OK);
221+ }
222+ else if (tex->Status == ImTextureStatus_WantUpdates)
223+ {
224+ auto otex =
225+ static_pointer_cast<Texture>(TextureManager::getSingleton ().getByHandle ((ResourceHandle)tex->TexID ));
226+
227+ auto r = tex->UpdateRect ;
228+ PixelBox pb (r.w , r.h , 1 , PF_BYTE_RGBA, tex->GetPixelsAt (r.x , r.y ));
229+ pb.rowPitch = tex->Width ;
230+ otex->getBuffer ()->blitFromMemory (pb, Box (r.x , r.y , r.x + r.w , r.y + r.h ));
231+
232+ tex->SetStatus (ImTextureStatus_OK);
233+ }
234+ else if (tex->Status == ImTextureStatus_WantDestroy)
235+ {
236+ TextureManager::getSingleton ().remove ((ResourceHandle)tex->TexID );
237+ tex->SetTexID (ImTextureID_Invalid);
238+ tex->SetStatus (ImTextureStatus_Destroyed);
239+ }
240+ }
241+ }
242+ #endif
243+
196244void ImGuiOverlay::ImGUIRenderable::_update ()
197245{
198246 if (mMaterial ->getSupportedTechniques ().empty ())
@@ -204,6 +252,13 @@ void ImGuiOverlay::ImGUIRenderable::_update()
204252 ImDrawData* draw_data = ImGui::GetDrawData ();
205253 updateVertexData (draw_data);
206254
255+ #if IMGUI_VERSION_NUM >= 19200
256+ if (draw_data->Textures )
257+ {
258+ updateTextureData (*draw_data->Textures );
259+ }
260+ #endif
261+
207262 RenderSystem* rSys = Root::getSingleton ().getRenderSystem ();
208263
209264 // Construct projection matrix, taking texel offset corrections in account (important for DirectX9)
@@ -273,7 +328,7 @@ bool ImGuiOverlay::ImGUIRenderable::preRender(SceneManager* sm, RenderSystem* rs
273328
274329 rsys->_render (mRenderOp );
275330
276- if (drawCmd->GetTexID ())
331+ if (drawCmd->GetTexID () & 0 )
277332 {
278333 // reset to pass state
279334 rsys->_setTexture (0 , true , mFontTex );
0 commit comments