@@ -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,6 @@ 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 );
108108 mTexUnit ->setTextureFiltering (TFO_NONE);
109109 mTexUnit ->setTextureAddressingMode (TAM_CLAMP);
110110
@@ -175,21 +175,6 @@ ImFont* ImGuiOverlay::addFont(const String& name, const String& group)
175175 return ret;
176176}
177177
178- void ImGuiOverlay::ImGUIRenderable::createFontTexture ()
179- {
180- // Build texture atlas
181- ImGuiIO& io = ImGui::GetIO ();
182- if (io.Fonts ->Fonts .empty ())
183- io.Fonts ->AddFontDefault ();
184- unsigned char * pixels;
185- int width, height;
186- io.Fonts ->GetTexDataAsRGBA32 (&pixels, &width, &height);
187-
188- mFontTex = TextureManager::getSingleton ().createManual (" ImGui/FontTex" , RGN_INTERNAL, TEX_TYPE_2D,
189- width, height, 1 , 1 , PF_BYTE_RGBA);
190-
191- mFontTex ->getBuffer ()->blitFromMemory (PixelBox (Box (0 , 0 , width, height), PF_BYTE_RGBA, pixels));
192- }
193178void ImGuiOverlay::NewFrame ()
194179{
195180 static auto lastTime = Root::getSingleton ().getTimer ()->getMilliseconds ();
@@ -216,6 +201,51 @@ void ImGuiOverlay::NewFrame()
216201 ImGui::NewFrame ();
217202}
218203
204+ #if IMGUI_VERSION_NUM >= 19200
205+ static void updateTextureData (ImVector<ImTextureData*>& textures)
206+ {
207+ static int texCounter = 0 ;
208+
209+ for (auto tex : textures)
210+ {
211+ if (tex->Status == ImTextureStatus_OK)
212+ continue ; // nothing to do
213+
214+ if (tex->Status == ImTextureStatus_WantCreate)
215+ {
216+ OgreAssert (tex->Format == ImTextureFormat_RGBA32, " ImGuiOverlay only supports RGBA32 textures" );
217+ auto otex = TextureManager::getSingleton ().createManual (StringUtil::format (" ImGui/Tex%d" , texCounter++),
218+ RGN_INTERNAL, TEX_TYPE_2D, tex->Width , tex->Height ,
219+ 1 , 0 , PF_BYTE_RGBA);
220+
221+ otex->getBuffer ()->blitFromMemory (
222+ PixelBox (Box (0 , 0 , tex->Width , tex->Height ), PF_BYTE_RGBA, tex->GetPixels ()));
223+
224+ tex->SetTexID ((ImTextureID)otex->getHandle ());
225+ tex->SetStatus (ImTextureStatus_OK);
226+ }
227+ else if (tex->Status == ImTextureStatus_WantUpdates)
228+ {
229+ auto otex =
230+ static_pointer_cast<Texture>(TextureManager::getSingleton ().getByHandle ((ResourceHandle)tex->TexID ));
231+
232+ auto r = tex->UpdateRect ;
233+ PixelBox pb (r.w , r.h , 1 , PF_BYTE_RGBA, tex->GetPixelsAt (r.x , r.y ));
234+ pb.rowPitch = tex->Width ;
235+ otex->getBuffer ()->blitFromMemory (pb, Box (r.x , r.y , r.x + r.w , r.y + r.h ));
236+
237+ tex->SetStatus (ImTextureStatus_OK);
238+ }
239+ else if (tex->Status == ImTextureStatus_WantDestroy)
240+ {
241+ TextureManager::getSingleton ().remove ((ResourceHandle)tex->TexID );
242+ tex->SetTexID (ImTextureID_Invalid);
243+ tex->SetStatus (ImTextureStatus_Destroyed);
244+ }
245+ }
246+ }
247+ #endif
248+
219249void ImGuiOverlay::ImGUIRenderable::_update ()
220250{
221251 if (mMaterial ->getSupportedTechniques ().empty ())
@@ -227,6 +257,13 @@ void ImGuiOverlay::ImGUIRenderable::_update()
227257 ImDrawData* draw_data = ImGui::GetDrawData ();
228258 updateVertexData (draw_data);
229259
260+ #if IMGUI_VERSION_NUM >= 19200
261+ if (draw_data->Textures )
262+ {
263+ updateTextureData (*draw_data->Textures );
264+ }
265+ #endif
266+
230267 RenderSystem* rSys = Root::getSingleton ().getRenderSystem ();
231268
232269 // Construct projection matrix, taking texel offset corrections in account (important for DirectX9)
@@ -285,7 +322,7 @@ bool ImGuiOverlay::ImGUIRenderable::preRender(SceneManager* sm, RenderSystem* rs
285322 if (tex)
286323 {
287324 rsys->_setTexture (0 , true , tex);
288- rsys->_setSampler (0 , *TextureManager::getSingleton (). getDefaultSampler ());
325+ rsys->_setSampler (0 , *tu-> getSampler ());
289326 }
290327 }
291328
@@ -296,13 +333,6 @@ bool ImGuiOverlay::ImGUIRenderable::preRender(SceneManager* sm, RenderSystem* rs
296333
297334 rsys->_render (mRenderOp );
298335
299- if (drawCmd->GetTexID ())
300- {
301- // reset to pass state
302- rsys->_setTexture (0 , true , mFontTex );
303- rsys->_setSampler (0 , *tu->getSampler ());
304- }
305-
306336 // Update counts
307337 mRenderOp .indexData ->indexStart += drawCmd->ElemCount ;
308338 }
@@ -331,7 +361,10 @@ ImGuiOverlay::ImGUIRenderable::ImGUIRenderable()
331361// -----------------------------------------------------------------------------------
332362void ImGuiOverlay::ImGUIRenderable::initialise (void )
333363{
334- createFontTexture ();
364+ ImGuiIO& io = ImGui::GetIO ();
365+ if (io.Fonts ->Fonts .empty ())
366+ io.Fonts ->AddFontDefault ();
367+
335368 createMaterial ();
336369
337370 mRenderOp .vertexData = OGRE_NEW VertexData ();
@@ -359,8 +392,6 @@ void ImGuiOverlay::ImGUIRenderable::initialise(void)
359392// -----------------------------------------------------------------------------------
360393ImGuiOverlay::ImGUIRenderable::~ImGUIRenderable ()
361394{
362- if (mFontTex )
363- TextureManager::getSingleton ().remove (mFontTex );
364395 if (mMaterial )
365396 MaterialManager::getSingleton ().remove (mMaterial );
366397 OGRE_DELETE mRenderOp .vertexData ;
0 commit comments