Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGuiHelper: add support for Y flip. #5748

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A new header is inserted each time a *tag* is created.

## v1.23.3

- ImGuiHelper: add support for Y flip.
bejado marked this conversation as resolved.
Show resolved Hide resolved
- 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.
Expand Down
4 changes: 3 additions & 1 deletion libs/filagui/include/filagui/ImGuiHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class UTILS_PUBLIC ImGuiHelper {
~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,
Expand Down Expand Up @@ -93,6 +94,7 @@ class UTILS_PUBLIC ImGuiHelper {
bool mHasSynced = false;
ImGuiContext* mImGuiContext;
filament::TextureSampler mSampler;
bool mFlipVertical = false;
};

} // namespace filagui
Expand Down
27 changes: 17 additions & 10 deletions libs/filagui/src/ImGuiHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down