Skip to content

Commit 8538d54

Browse files
committed
Overlay: update imgui to 1.92
1 parent f76d4c9 commit 8538d54

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
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/src/OgreImGuiOverlay.cpp

Lines changed: 58 additions & 3 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,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+
196244
void 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);

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)