Skip to content

Commit 13d07cb

Browse files
committed
Overlay: update imgui to 1.92
1 parent f76d4c9 commit 13d07cb

File tree

6 files changed

+63
-34
lines changed

6 files changed

+63
-34
lines changed

Components/Bites/src/OgreApplicationContextBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void ApplicationContextBase::runRenderingSettingsDialog()
306306
float vpScale = getDisplayDPI()/96;
307307
Ogre::OverlayManager::getSingleton().setPixelRatio(vpScale);
308308
auto overlay = initialiseImGui();
309-
ImGui::GetIO().FontGlobalScale = std::round(vpScale); // default font does not work with fractional scaling
309+
ImGui::GetStyle().FontScaleMain = std::round(vpScale); // default font does not work with fractional scaling
310310
overlay->show();
311311

312312
addInputListener(getImGuiInputListener());

Components/Overlay/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ list(APPEND HEADER_FILES
1919
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
2020

2121
if(OGRE_BUILD_COMPONENT_OVERLAY_IMGUI)
22-
set(IMGUI_DIR "${PROJECT_BINARY_DIR}/imgui-1.91.9b" CACHE PATH "")
22+
set(IMGUI_DIR "${PROJECT_BINARY_DIR}/imgui-1.92.0" CACHE PATH "")
2323
if(NOT EXISTS ${IMGUI_DIR})
2424
message(STATUS "Downloading imgui")
2525
file(DOWNLOAD
26-
https://github.com/ocornut/imgui/archive/v1.91.9b.tar.gz
26+
https://github.com/ocornut/imgui/archive/v1.92.0.tar.gz
2727
${PROJECT_BINARY_DIR}/imgui.tar.gz)
2828
execute_process(COMMAND ${CMAKE_COMMAND}
2929
-E tar xf imgui.tar.gz WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

Components/Overlay/include/OgreImGuiOverlay.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class _OgreOverlayExport ImGuiOverlay : public Overlay
7070
const LightList& getLights(void) const override;
7171

7272
void createMaterial();
73-
void createFontTexture();
7473

7574
const MaterialPtr& getMaterial() const override { return mMaterial; }
7675

@@ -80,7 +79,6 @@ class _OgreOverlayExport ImGuiOverlay : public Overlay
8079

8180
Matrix4 mXform;
8281
RenderOperation mRenderOp;
83-
TexturePtr mFontTex;
8482
MaterialPtr mMaterial;
8583
};
8684

Components/Overlay/src/OgreImGuiOverlay.cpp

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ ImGuiOverlay::ImGuiOverlay() : Overlay("ImGuiOverlay")
6868
ImGuiIO& io = ImGui::GetIO();
6969

7070
io.BackendPlatformName = "OGRE";
71+
io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures;
7172
}
7273
ImGuiOverlay::~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

@@ -152,21 +152,6 @@ ImFont* ImGuiOverlay::addFont(const String& name, const String& group)
152152
cprangePtr);
153153
}
154154

155-
void ImGuiOverlay::ImGUIRenderable::createFontTexture()
156-
{
157-
// Build texture atlas
158-
ImGuiIO& io = ImGui::GetIO();
159-
if (io.Fonts->Fonts.empty())
160-
io.Fonts->AddFontDefault();
161-
unsigned char* pixels;
162-
int width, height;
163-
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
164-
165-
mFontTex = TextureManager::getSingleton().createManual("ImGui/FontTex", RGN_INTERNAL, TEX_TYPE_2D,
166-
width, height, 1, 1, PF_BYTE_RGBA);
167-
168-
mFontTex->getBuffer()->blitFromMemory(PixelBox(Box(0, 0, width, height), PF_BYTE_RGBA, pixels));
169-
}
170155
void ImGuiOverlay::NewFrame()
171156
{
172157
static auto lastTime = Root::getSingleton().getTimer()->getMilliseconds();
@@ -193,6 +178,51 @@ void ImGuiOverlay::NewFrame()
193178
ImGui::NewFrame();
194179
}
195180

181+
#if IMGUI_VERSION_NUM >= 19200
182+
static void updateTextureData(ImVector<ImTextureData*>& textures)
183+
{
184+
static int texCounter = 0;
185+
186+
for (auto tex : textures)
187+
{
188+
if (tex->Status == ImTextureStatus_OK)
189+
continue; // nothing to do
190+
191+
if (tex->Status == ImTextureStatus_WantCreate)
192+
{
193+
OgreAssert(tex->Format == ImTextureFormat_RGBA32, "ImGuiOverlay only supports RGBA32 textures");
194+
auto otex = TextureManager::getSingleton().createManual(StringUtil::format("ImGui/Tex%d", texCounter++),
195+
RGN_INTERNAL, TEX_TYPE_2D, tex->Width, tex->Height,
196+
1, 0, PF_BYTE_RGBA);
197+
198+
otex->getBuffer()->blitFromMemory(
199+
PixelBox(Box(0, 0, tex->Width, tex->Height), PF_BYTE_RGBA, tex->GetPixels()));
200+
201+
tex->SetTexID((ImTextureID)otex->getHandle());
202+
tex->SetStatus(ImTextureStatus_OK);
203+
}
204+
else if (tex->Status == ImTextureStatus_WantUpdates)
205+
{
206+
auto otex =
207+
static_pointer_cast<Texture>(TextureManager::getSingleton().getByHandle((ResourceHandle)tex->TexID));
208+
209+
auto r = tex->UpdateRect;
210+
PixelBox pb(r.w, r.h, 1, PF_BYTE_RGBA, tex->GetPixelsAt(r.x, r.y));
211+
pb.rowPitch = tex->Width;
212+
otex->getBuffer()->blitFromMemory(pb, Box(r.x, r.y, r.x + r.w, r.y + r.h));
213+
214+
tex->SetStatus(ImTextureStatus_OK);
215+
}
216+
else if (tex->Status == ImTextureStatus_WantDestroy)
217+
{
218+
TextureManager::getSingleton().remove((ResourceHandle)tex->TexID);
219+
tex->SetTexID(ImTextureID_Invalid);
220+
tex->SetStatus(ImTextureStatus_Destroyed);
221+
}
222+
}
223+
}
224+
#endif
225+
196226
void ImGuiOverlay::ImGUIRenderable::_update()
197227
{
198228
if (mMaterial->getSupportedTechniques().empty())
@@ -204,6 +234,13 @@ void ImGuiOverlay::ImGUIRenderable::_update()
204234
ImDrawData* draw_data = ImGui::GetDrawData();
205235
updateVertexData(draw_data);
206236

237+
#if IMGUI_VERSION_NUM >= 19200
238+
if (draw_data->Textures)
239+
{
240+
updateTextureData(*draw_data->Textures);
241+
}
242+
#endif
243+
207244
RenderSystem* rSys = Root::getSingleton().getRenderSystem();
208245

209246
// Construct projection matrix, taking texel offset corrections in account (important for DirectX9)
@@ -262,7 +299,7 @@ bool ImGuiOverlay::ImGUIRenderable::preRender(SceneManager* sm, RenderSystem* rs
262299
if (tex)
263300
{
264301
rsys->_setTexture(0, true, tex);
265-
rsys->_setSampler(0, *TextureManager::getSingleton().getDefaultSampler());
302+
rsys->_setSampler(0, *tu->getSampler());
266303
}
267304
}
268305

@@ -273,13 +310,6 @@ bool ImGuiOverlay::ImGUIRenderable::preRender(SceneManager* sm, RenderSystem* rs
273310

274311
rsys->_render(mRenderOp);
275312

276-
if (drawCmd->GetTexID())
277-
{
278-
// reset to pass state
279-
rsys->_setTexture(0, true, mFontTex);
280-
rsys->_setSampler(0, *tu->getSampler());
281-
}
282-
283313
// Update counts
284314
mRenderOp.indexData->indexStart += drawCmd->ElemCount;
285315
}
@@ -308,7 +338,10 @@ ImGuiOverlay::ImGUIRenderable::ImGUIRenderable()
308338
//-----------------------------------------------------------------------------------
309339
void ImGuiOverlay::ImGUIRenderable::initialise(void)
310340
{
311-
createFontTexture();
341+
ImGuiIO& io = ImGui::GetIO();
342+
if (io.Fonts->Fonts.empty())
343+
io.Fonts->AddFontDefault();
344+
312345
createMaterial();
313346

314347
mRenderOp.vertexData = OGRE_NEW VertexData();
@@ -336,8 +369,6 @@ void ImGuiOverlay::ImGUIRenderable::initialise(void)
336369
//-----------------------------------------------------------------------------------
337370
ImGuiOverlay::ImGUIRenderable::~ImGUIRenderable()
338371
{
339-
if(mFontTex)
340-
TextureManager::getSingleton().remove(mFontTex);
341372
if(mMaterial)
342373
MaterialManager::getSingleton().remove(mMaterial);
343374
OGRE_DELETE mRenderOp.vertexData;

Components/Overlay/src/OgreOverlaySystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace Ogre {
127127
//---------------------------------------------------------------------
128128
void OverlaySystem::renderQueueStarted(uint8 queueGroupId, const String& cameraName, bool& skipThisInvocation)
129129
{
130-
if(queueGroupId == Ogre::RENDER_QUEUE_OVERLAY)
130+
if(queueGroupId == Ogre::RENDER_QUEUE_BACKGROUND)
131131
{
132132
Ogre::Viewport* vp = Ogre::Root::getSingletonPtr()->getRenderSystem()->_getViewport();
133133
if(vp != NULL)

Samples/Simple/include/ImGuiDemo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _OgreSampleClassExport Sample_ImGui : public SdkSample, public RenderTarge
3434
auto imguiOverlay = mContext->initialiseImGui();
3535

3636
float vpScale = OverlayManager::getSingleton().getPixelRatio();
37-
ImGui::GetIO().FontGlobalScale = std::round(vpScale); // default font does not work with fractional scaling
37+
ImGui::GetStyle().FontScaleMain = std::round(vpScale); // default font does not work with fractional scaling
3838

3939
imguiOverlay->setZOrder(300);
4040
imguiOverlay->show();

0 commit comments

Comments
 (0)