ImGuiHelper: add support for Y flip. (#5748)
Reflects a change from Betty and should be cherry picked to v1.23.3 Users could customize the ImGuiHelper camera, but they had no control over the scissor coordinates. This allows them to use vertically flipped coordinates, which, unfortunately, is required for MediaPipe integration.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user