diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 307b1bd41d..ed60f44970 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -7,6 +7,7 @@ A new header is inserted each time a *tag* is created. ## v1.23.3 +- ImGuiHelper: add support for Y flip. - materials: add a new `instanced` material parameter that is now mandatory in order to call `getInstanceIndex()` - gltfio: UbershaderProvider now takes the ubershader archive in its constructor [⚠️ **API Change**] - gltfio: Fix morphing with sparse accessors. diff --git a/libs/filagui/include/filagui/ImGuiHelper.h b/libs/filagui/include/filagui/ImGuiHelper.h index 29c4f9e8fa..f953acbc91 100644 --- a/libs/filagui/include/filagui/ImGuiHelper.h +++ b/libs/filagui/include/filagui/ImGuiHelper.h @@ -53,7 +53,8 @@ public: ~ImGuiHelper(); // Informs ImGui of the current display size, as well as a scaling factor when scissoring. - void setDisplaySize(int width, int height, float scaleX = 1.0f, float scaleY = 1.0f); + void setDisplaySize(int width, int height, float scaleX = 1.0f, + float scaleY = 1.0f, bool flipVertical = false); // High-level utility method that takes a callback for creating all ImGui windows and widgets. // Clients are responsible for rendering the View. This should be called on every frame, @@ -93,6 +94,7 @@ public: bool mHasSynced = false; ImGuiContext* mImGuiContext; filament::TextureSampler mSampler; + bool mFlipVertical = false; }; } // namespace filagui diff --git a/libs/filagui/src/ImGuiHelper.cpp b/libs/filagui/src/ImGuiHelper.cpp index 6c02823fb2..e78e258eb8 100644 --- a/libs/filagui/src/ImGuiHelper.cpp +++ b/libs/filagui/src/ImGuiHelper.cpp @@ -45,8 +45,8 @@ namespace filagui { #include "generated/resources/filagui_resources.h" -ImGuiHelper::ImGuiHelper(Engine* engine, filament::View* view, const Path& fontPath, - ImGuiContext *imGuiContext) +ImGuiHelper::ImGuiHelper(Engine* engine, filament::View* view, const Path& fontPath, + ImGuiContext *imGuiContext) : mEngine(engine), mView(view), mScene(engine->createScene()), mImGuiContext(imGuiContext ? imGuiContext : ImGui::CreateContext()) { ImGuiIO& io = ImGui::GetIO(); @@ -137,16 +137,20 @@ ImGuiHelper::~ImGuiHelper() { mImGuiContext = nullptr; } -void ImGuiHelper::setDisplaySize(int width, int height, float scaleX, float scaleY) { +void ImGuiHelper::setDisplaySize(int width, int height, float scaleX, float scaleY, + bool flipVertical) { ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2(width, height); io.DisplayFramebufferScale.x = scaleX; io.DisplayFramebufferScale.y = scaleY; - mCamera->setProjection(Camera::Projection::ORTHO, - 0.0, double(width), - double(height), 0.0, - 0.0, 1.0); -} + mFlipVertical = flipVertical; + if (flipVertical) { + mCamera->setProjection(Camera::Projection::ORTHO, 0.0, double(width), + 0.0, double(height), 0.0, 1.0); + } else { + mCamera->setProjection(Camera::Projection::ORTHO, 0.0, double(width), + double(height), 0.0, 0.0, 1.0); + }} void ImGuiHelper::render(float timeStepInSeconds, Callback imguiCommands) { ImGui::SetCurrentContext(mImGuiContext); @@ -213,12 +217,15 @@ void ImGuiHelper::processImGuiCommands(ImDrawData* commands, const ImGuiIO& io) pcmd.UserCallback(cmds, &pcmd); } else { MaterialInstance* materialInstance = mMaterialInstances[primIndex]; - materialInstance->setScissor( pcmd.ClipRect.x, fbheight - pcmd.ClipRect.w, + materialInstance->setScissor( + pcmd.ClipRect.x, + mFlipVertical ? pcmd.ClipRect.y : (fbheight - pcmd.ClipRect.w), (uint16_t) (pcmd.ClipRect.z - pcmd.ClipRect.x), (uint16_t) (pcmd.ClipRect.w - pcmd.ClipRect.y)); if (pcmd.TextureId) { TextureSampler sampler(MinFilter::LINEAR, MagFilter::LINEAR); - materialInstance->setParameter("albedo", (Texture const*)pcmd.TextureId, sampler); + materialInstance->setParameter("albedo", + (Texture const*)pcmd.TextureId, sampler); } else { materialInstance->setParameter("albedo", mTexture, mSampler); }