Regen patches
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
476bae222f
commit
4ab933a073
12 changed files with 603 additions and 517 deletions
|
@ -1,6 +1,6 @@
|
|||
--- ../Rack/src/window/Window.cpp 2022-09-21 20:25:53.593040323 +0100
|
||||
+++ Window.cpp 2022-09-21 20:18:50.294557597 +0100
|
||||
@@ -1,33 +1,87 @@
|
||||
--- ../Rack/src/window/Window.cpp 2022-09-21 19:49:12.202540796 +0100
|
||||
+++ Window.cpp 2022-12-29 17:16:45.012337253 +0000
|
||||
@@ -1,33 +1,88 @@
|
||||
+/*
|
||||
+ * DISTRHO Cardinal Plugin
|
||||
+ * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
|
||||
|
@ -59,10 +59,10 @@
|
|||
+
|
||||
+// comment out if wanting to generate a local screenshot.png
|
||||
+#define STBI_WRITE_NO_STDIO
|
||||
|
||||
+
|
||||
+// uncomment to generate screenshots without the rack rail background (ie, transparent)
|
||||
+// #define CARDINAL_TRANSPARENT_SCREENSHOTS
|
||||
+
|
||||
|
||||
+// used in Window::screenshot
|
||||
+#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
+#include "stb_image_write.h"
|
||||
|
@ -71,6 +71,7 @@
|
|||
+#include "Application.hpp"
|
||||
+#include "extra/String.hpp"
|
||||
+#include "../CardinalCommon.hpp"
|
||||
+#include "../PluginContext.hpp"
|
||||
+#include "../WindowParameters.hpp"
|
||||
+
|
||||
+#ifndef DGL_NO_SHARED_RESOURCES
|
||||
|
@ -101,7 +102,7 @@
|
|||
|
||||
|
||||
Font::~Font() {
|
||||
@@ -42,9 +96,8 @@
|
||||
@@ -42,9 +97,8 @@
|
||||
// Transfer ownership of font data to font object
|
||||
uint8_t* data = system::readFile(filename, &size);
|
||||
// Don't use nvgCreateFont because it doesn't properly handle UTF-8 filenames on Windows.
|
||||
|
@ -112,7 +113,7 @@
|
|||
throw Exception("Failed to load font %s", filename.c_str());
|
||||
}
|
||||
INFO("Loaded font %s", filename.c_str());
|
||||
@@ -79,375 +132,347 @@
|
||||
@@ -79,375 +133,489 @@
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,14 +134,17 @@
|
|||
- int lastWindowWidth = 0;
|
||||
- int lastWindowHeight = 0;
|
||||
+ DISTRHO_NAMESPACE::UI* ui = nullptr;
|
||||
+ DGL_NAMESPACE::NanoTopLevelWidget* tlw = nullptr;
|
||||
+ DISTRHO_NAMESPACE::WindowParameters params;
|
||||
+ DISTRHO_NAMESPACE::WindowParametersCallback* callback = nullptr;
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ DGL_NAMESPACE::Application hiddenApp;
|
||||
+ DGL_NAMESPACE::Window hiddenWindow;
|
||||
+ NVGcontext* r_vg = nullptr;
|
||||
+ NVGcontext* r_fbVg = nullptr;
|
||||
+ NVGcontext* o_vg = nullptr;
|
||||
+ NVGcontext* o_fbVg = nullptr;
|
||||
+#endif
|
||||
+
|
||||
+ math::Vec size = WINDOW_SIZE_MIN;
|
||||
+
|
||||
|
@ -168,16 +172,8 @@
|
|||
|
||||
bool fbDirtyOnSubpixelChange = true;
|
||||
int fbCount = 0;
|
||||
+
|
||||
+ Internal()
|
||||
+ : hiddenApp(false),
|
||||
+ hiddenWindow(hiddenApp)
|
||||
+ {
|
||||
+ hiddenWindow.setIgnoringKeyRepeat(true);
|
||||
+ hiddenApp.idle();
|
||||
+ }
|
||||
};
|
||||
|
||||
-};
|
||||
-
|
||||
|
||||
-static void windowPosCallback(GLFWwindow* win, int x, int y) {
|
||||
- if (glfwGetWindowAttrib(win, GLFW_MAXIMIZED))
|
||||
|
@ -189,14 +185,19 @@
|
|||
- settings::windowPos = math::Vec(x, y);
|
||||
- // DEBUG("windowPosCallback %d %d", x, y);
|
||||
-}
|
||||
+#ifndef DGL_NO_SHARED_RESOURCES
|
||||
+static int loadFallbackFont(NVGcontext* const vg)
|
||||
+{
|
||||
+ const int font = nvgFindFont(vg, NANOVG_DEJAVU_SANS_TTF);
|
||||
+ if (font >= 0)
|
||||
+ return font;
|
||||
+ Internal()
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ : hiddenApp(false),
|
||||
+ hiddenWindow(hiddenApp)
|
||||
+ {
|
||||
+ hiddenWindow.setIgnoringKeyRepeat(true);
|
||||
+ hiddenApp.idle();
|
||||
+ }
|
||||
+#else
|
||||
+ {}
|
||||
+#endif
|
||||
+};
|
||||
|
||||
+ using namespace dpf_resources;
|
||||
|
||||
-static void windowSizeCallback(GLFWwindow* win, int width, int height) {
|
||||
- if (glfwGetWindowAttrib(win, GLFW_MAXIMIZED))
|
||||
|
@ -207,21 +208,24 @@
|
|||
- return;
|
||||
- settings::windowSize = math::Vec(width, height);
|
||||
- // DEBUG("windowSizeCallback %d %d", width, height);
|
||||
+ return nvgCreateFontMem(vg, NANOVG_DEJAVU_SANS_TTF,
|
||||
+ (uchar*)dejavusans_ttf, dejavusans_ttf_size, 0);
|
||||
}
|
||||
+#endif
|
||||
-}
|
||||
+#ifndef DGL_NO_SHARED_RESOURCES
|
||||
+static int loadFallbackFont(NVGcontext* const vg)
|
||||
+{
|
||||
+ const int font = nvgFindFont(vg, NANOVG_DEJAVU_SANS_TTF);
|
||||
+ if (font >= 0)
|
||||
+ return font;
|
||||
|
||||
+ using namespace dpf_resources;
|
||||
|
||||
-static void windowMaximizeCallback(GLFWwindow* win, int maximized) {
|
||||
- settings::windowMaximized = maximized;
|
||||
- // DEBUG("windowMaximizeCallback %d", maximized);
|
||||
-}
|
||||
+Window::Window() {
|
||||
+ internal = new Internal;
|
||||
|
||||
+ DGL_NAMESPACE::Window::ScopedGraphicsContext sgc(internal->hiddenWindow);
|
||||
|
||||
+ return nvgCreateFontMem(vg, NANOVG_DEJAVU_SANS_TTF,
|
||||
+ (uchar*)dejavusans_ttf, dejavusans_ttf_size, 0);
|
||||
}
|
||||
-
|
||||
-
|
||||
-static void mouseButtonCallback(GLFWwindow* win, int button, int action, int mods) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
-#if defined ARCH_MAC
|
||||
|
@ -234,19 +238,56 @@
|
|||
- if (button == GLFW_MOUSE_BUTTON_LEFT && (mods & RACK_MOD_MASK) == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) {
|
||||
- button = GLFW_MOUSE_BUTTON_MIDDLE;
|
||||
- mods &= ~(GLFW_MOD_CONTROL | GLFW_MOD_SHIFT);
|
||||
- }
|
||||
#endif
|
||||
|
||||
- APP->event->handleButton(APP->window->internal->lastMousePos, button, action, mods);
|
||||
-}
|
||||
-
|
||||
|
||||
-static void cursorPosCallback(GLFWwindow* win, double xpos, double ypos) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- math::Vec mousePos = math::Vec(xpos, ypos).div(APP->window->pixelRatio / APP->window->windowRatio).round();
|
||||
- math::Vec mouseDelta = mousePos.minus(APP->window->internal->lastMousePos);
|
||||
+Window::Window() {
|
||||
+ internal = new Internal;
|
||||
|
||||
- // Workaround for GLFW warping mouse to a different position when the cursor is locked or unlocked.
|
||||
- if (APP->window->internal->ignoreNextMouseDelta) {
|
||||
- APP->window->internal->ignoreNextMouseDelta = false;
|
||||
- mouseDelta = math::Vec();
|
||||
- }
|
||||
+ // Set up NanoVG
|
||||
+ const int nvgFlags = NVG_ANTIALIAS;
|
||||
|
||||
- int cursorMode = glfwGetInputMode(win, GLFW_CURSOR);
|
||||
- (void) cursorMode;
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ DGL_NAMESPACE::Window::ScopedGraphicsContext sgc(internal->hiddenWindow);
|
||||
+ vg = nvgCreateGL(nvgFlags);
|
||||
+#else
|
||||
+ vg = static_cast<CardinalPluginContext*>(APP)->tlw->getContext();
|
||||
+#endif
|
||||
+ DISTRHO_SAFE_ASSERT_RETURN(vg != nullptr,);
|
||||
|
||||
-#if defined ARCH_MAC
|
||||
- // Workaround for Mac. We can't use GLFW_CURSOR_DISABLED because it's buggy, so implement it on our own.
|
||||
- // This is not an ideal implementation. For example, if the user drags off the screen, the new mouse position will be clamped.
|
||||
- if (cursorMode == GLFW_CURSOR_HIDDEN) {
|
||||
- // CGSetLocalEventsSuppressionInterval(0.0);
|
||||
- glfwSetCursorPos(win, APP->window->internal->lastMousePos.x, APP->window->internal->lastMousePos.y);
|
||||
- CGAssociateMouseAndMouseCursorPosition(true);
|
||||
- mousePos = APP->window->internal->lastMousePos;
|
||||
- }
|
||||
- // Because sometimes the cursor turns into an arrow when its position is on the boundary of the window
|
||||
- glfwSetCursor(win, NULL);
|
||||
+#ifdef NANOVG_GLES2
|
||||
+ fbVg = nvgCreateSharedGLES2(vg, nvgFlags);
|
||||
+#else
|
||||
+ fbVg = nvgCreateSharedGL2(vg, nvgFlags);
|
||||
#endif
|
||||
|
||||
- APP->event->handleButton(APP->window->internal->lastMousePos, button, action, mods);
|
||||
-}
|
||||
- APP->window->internal->lastMousePos = mousePos;
|
||||
+ // Load default Blendish font
|
||||
+#ifndef DGL_NO_SHARED_RESOURCES
|
||||
+ uiFont = std::make_shared<Font>();
|
||||
|
@ -263,55 +304,51 @@
|
|||
+ uiFont = loadFont(asset::system("res/fonts/DejaVuSans.ttf"));
|
||||
+#endif
|
||||
|
||||
- APP->event->handleHover(mousePos, mouseDelta);
|
||||
+ if (uiFont != nullptr)
|
||||
+ bndSetFont(uiFont->handle);
|
||||
|
||||
-static void cursorPosCallback(GLFWwindow* win, double xpos, double ypos) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- math::Vec mousePos = math::Vec(xpos, ypos).div(APP->window->pixelRatio / APP->window->windowRatio).round();
|
||||
- math::Vec mouseDelta = mousePos.minus(APP->window->internal->lastMousePos);
|
||||
- // Keyboard/mouse MIDI driver
|
||||
- int width, height;
|
||||
- glfwGetWindowSize(win, &width, &height);
|
||||
- math::Vec scaledPos(xpos / width, ypos / height);
|
||||
- keyboard::mouseMove(scaledPos);
|
||||
+#ifdef DISTRHO_OS_WASM
|
||||
+ emscripten_lock_orientation(EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY);
|
||||
+#endif
|
||||
+}
|
||||
}
|
||||
|
||||
- // Workaround for GLFW warping mouse to a different position when the cursor is locked or unlocked.
|
||||
- if (APP->window->internal->ignoreNextMouseDelta) {
|
||||
- APP->window->internal->ignoreNextMouseDelta = false;
|
||||
- mouseDelta = math::Vec();
|
||||
+void WindowSetPluginUI(Window* const window, DISTRHO_NAMESPACE::UI* const ui)
|
||||
-
|
||||
-static void cursorEnterCallback(GLFWwindow* win, int entered) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- if (!entered) {
|
||||
- APP->event->handleLeave();
|
||||
+void WindowSetPluginRemote(Window* const window, NanoTopLevelWidget* const tlw)
|
||||
+{
|
||||
+ // if nanovg context failed, init only bare minimum
|
||||
+ if (window->vg == nullptr)
|
||||
+ {
|
||||
+ if (ui != nullptr)
|
||||
+ if (tlw != nullptr)
|
||||
+ {
|
||||
+ window->internal->ui = ui;
|
||||
+ window->internal->size = rack::math::Vec(ui->getWidth(), ui->getHeight());
|
||||
+ window->internal->tlw = tlw;
|
||||
+ window->internal->size = rack::math::Vec(tlw->getWidth(), tlw->getHeight());
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ window->internal->ui = nullptr;
|
||||
+ window->internal->tlw = nullptr;
|
||||
+ window->internal->callback = nullptr;
|
||||
+ }
|
||||
+ return;
|
||||
}
|
||||
-}
|
||||
|
||||
- int cursorMode = glfwGetInputMode(win, GLFW_CURSOR);
|
||||
- (void) cursorMode;
|
||||
-
|
||||
-static void scrollCallback(GLFWwindow* win, double x, double y) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- math::Vec scrollDelta = math::Vec(x, y);
|
||||
-#if defined ARCH_MAC
|
||||
- // Workaround for Mac. We can't use GLFW_CURSOR_DISABLED because it's buggy, so implement it on our own.
|
||||
- // This is not an ideal implementation. For example, if the user drags off the screen, the new mouse position will be clamped.
|
||||
- if (cursorMode == GLFW_CURSOR_HIDDEN) {
|
||||
- // CGSetLocalEventsSuppressionInterval(0.0);
|
||||
- glfwSetCursorPos(win, APP->window->internal->lastMousePos.x, APP->window->internal->lastMousePos.y);
|
||||
- CGAssociateMouseAndMouseCursorPosition(true);
|
||||
- mousePos = APP->window->internal->lastMousePos;
|
||||
- }
|
||||
- // Because sometimes the cursor turns into an arrow when its position is on the boundary of the window
|
||||
- glfwSetCursor(win, NULL);
|
||||
+ if (ui != nullptr)
|
||||
- scrollDelta = scrollDelta.mult(10.0);
|
||||
+ if (tlw != nullptr)
|
||||
+ {
|
||||
+ const GLubyte* vendor = glGetString(GL_VENDOR);
|
||||
+ const GLubyte* renderer = glGetString(GL_RENDERER);
|
||||
|
@ -319,18 +356,21 @@
|
|||
+ INFO("Renderer: %s %s", vendor, renderer);
|
||||
+ INFO("OpenGL: %s", version);
|
||||
+
|
||||
+ window->internal->ui = ui;
|
||||
+ window->internal->size = rack::math::Vec(ui->getWidth(), ui->getHeight());
|
||||
+ window->internal->tlw = tlw;
|
||||
+ window->internal->size = rack::math::Vec(tlw->getWidth(), tlw->getHeight());
|
||||
+
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ // Set up NanoVG
|
||||
+ window->internal->r_vg = ui->getContext();
|
||||
+ window->internal->r_vg = tlw->getContext();
|
||||
+#ifdef NANOVG_GLES2
|
||||
+ window->internal->r_fbVg = nvgCreateSharedGLES2(window->internal->r_vg, NVG_ANTIALIAS);
|
||||
+#else
|
||||
#else
|
||||
- scrollDelta = scrollDelta.mult(50.0);
|
||||
+ window->internal->r_fbVg = nvgCreateSharedGL2(window->internal->r_vg, NVG_ANTIALIAS);
|
||||
#endif
|
||||
|
||||
- APP->window->internal->lastMousePos = mousePos;
|
||||
- APP->event->handleScroll(APP->window->internal->lastMousePos, scrollDelta);
|
||||
-}
|
||||
+ // swap contexts
|
||||
+ window->internal->o_vg = window->vg;
|
||||
+ window->internal->o_fbVg = window->fbVg;
|
||||
|
@ -354,16 +394,15 @@
|
|||
+ image.second->handle = nvgCreateImage(window->vg, image.second->ofilename.c_str(),
|
||||
+ NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY);
|
||||
+ }
|
||||
+#endif
|
||||
|
||||
- APP->event->handleHover(mousePos, mouseDelta);
|
||||
+ // Init settings
|
||||
+ WindowParametersRestore(window);
|
||||
|
||||
- // Keyboard/mouse MIDI driver
|
||||
- int width, height;
|
||||
- glfwGetWindowSize(win, &width, &height);
|
||||
- math::Vec scaledPos(xpos / width, ypos / height);
|
||||
- keyboard::mouseMove(scaledPos);
|
||||
-static void charCallback(GLFWwindow* win, unsigned int codepoint) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- if (APP->event->handleText(APP->window->internal->lastMousePos, codepoint))
|
||||
- return;
|
||||
-}
|
||||
+ widget::Widget::ContextCreateEvent e;
|
||||
+ APP->scene->onContextCreate(e);
|
||||
|
@ -372,7 +411,8 @@
|
|||
+ {
|
||||
+ widget::Widget::ContextDestroyEvent e;
|
||||
+ APP->scene->onContextDestroy(e);
|
||||
+
|
||||
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ // swap contexts
|
||||
+ window->uiFont->vg = window->internal->o_vg;
|
||||
+ window->vg = window->internal->o_vg;
|
||||
|
@ -396,75 +436,16 @@
|
|||
+ image.second->ohandle = -1;
|
||||
+ }
|
||||
|
||||
-static void keyCallback(GLFWwindow* win, int key, int scancode, int action, int mods) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- if (APP->event->handleKey(APP->window->internal->lastMousePos, key, scancode, action, mods))
|
||||
- return;
|
||||
+#if defined NANOVG_GLES2
|
||||
+ nvgDeleteGLES2(window->internal->r_fbVg);
|
||||
+#else
|
||||
+ nvgDeleteGL2(window->internal->r_fbVg);
|
||||
+#endif
|
||||
|
||||
-static void cursorEnterCallback(GLFWwindow* win, int entered) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- if (!entered) {
|
||||
- APP->event->handleLeave();
|
||||
+ window->internal->ui = nullptr;
|
||||
+ window->internal->callback = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
+void WindowSetMods(Window* const window, const int mods)
|
||||
+{
|
||||
+ window->internal->mods = mods;
|
||||
+}
|
||||
|
||||
-static void scrollCallback(GLFWwindow* win, double x, double y) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- math::Vec scrollDelta = math::Vec(x, y);
|
||||
-#if defined ARCH_MAC
|
||||
- scrollDelta = scrollDelta.mult(10.0);
|
||||
+Window::~Window() {
|
||||
+ {
|
||||
+ DGL_NAMESPACE::Window::ScopedGraphicsContext sgc(internal->hiddenWindow);
|
||||
+ internal->hiddenWindow.close();
|
||||
+ internal->hiddenApp.idle();
|
||||
+
|
||||
+ // Fonts and Images in the cache must be deleted before the NanoVG context is deleted
|
||||
+ internal->fontCache.clear();
|
||||
+ internal->imageCache.clear();
|
||||
+
|
||||
+ if (vg != nullptr)
|
||||
+ {
|
||||
+#if defined NANOVG_GLES2
|
||||
+ nvgDeleteGLES2(internal->o_fbVg != nullptr ? internal->o_fbVg : fbVg);
|
||||
+ nvgDeleteGLES2(internal->o_vg != nullptr ? internal->o_vg : vg);
|
||||
#else
|
||||
- scrollDelta = scrollDelta.mult(50.0);
|
||||
+ nvgDeleteGL2(internal->o_fbVg != nullptr ? internal->o_fbVg : fbVg);
|
||||
+ nvgDeleteGL2(internal->o_vg != nullptr ? internal->o_vg : vg);
|
||||
#endif
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- APP->event->handleScroll(APP->window->internal->lastMousePos, scrollDelta);
|
||||
+ delete internal;
|
||||
}
|
||||
|
||||
|
||||
-static void charCallback(GLFWwindow* win, unsigned int codepoint) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- if (APP->event->handleText(APP->window->internal->lastMousePos, codepoint))
|
||||
- return;
|
||||
+math::Vec Window::getSize() {
|
||||
+ return internal->size;
|
||||
}
|
||||
|
||||
|
||||
-static void keyCallback(GLFWwindow* win, int key, int scancode, int action, int mods) {
|
||||
- contextSet((Context*) glfwGetWindowUserPointer(win));
|
||||
- if (APP->event->handleKey(APP->window->internal->lastMousePos, key, scancode, action, mods))
|
||||
- return;
|
||||
+void Window::setSize(math::Vec size) {
|
||||
+ size = size.max(WINDOW_SIZE_MIN);
|
||||
+ internal->size = size;
|
||||
+#endif
|
||||
|
||||
- // Keyboard/mouse MIDI driver
|
||||
- if (action == GLFW_PRESS && (mods & RACK_MOD_MASK) == 0) {
|
||||
|
@ -472,9 +453,9 @@
|
|||
- }
|
||||
- if (action == GLFW_RELEASE) {
|
||||
- keyboard::release(key);
|
||||
- }
|
||||
+ if (DISTRHO_NAMESPACE::UI* const ui = internal->ui)
|
||||
+ ui->setSize(internal->size.x, internal->size.y);
|
||||
+ window->internal->tlw = nullptr;
|
||||
+ window->internal->callback = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
-
|
||||
|
@ -483,25 +464,56 @@
|
|||
- std::vector<std::string> pathsVec;
|
||||
- for (int i = 0; i < count; i++) {
|
||||
- pathsVec.push_back(paths[i]);
|
||||
- }
|
||||
+void WindowSetPluginUI(Window* const window, DISTRHO_NAMESPACE::UI* const ui)
|
||||
+{
|
||||
+ // if nanovg context failed, init only bare minimum
|
||||
+ if (window->vg == nullptr)
|
||||
+ {
|
||||
+ if (ui != nullptr)
|
||||
+ {
|
||||
+ window->internal->ui = ui;
|
||||
+ window->internal->size = rack::math::Vec(ui->getWidth(), ui->getHeight());
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ window->internal->ui = nullptr;
|
||||
+ window->internal->callback = nullptr;
|
||||
+ }
|
||||
+ return;
|
||||
}
|
||||
- APP->event->handleDrop(APP->window->internal->lastMousePos, pathsVec);
|
||||
+void WindowSetInternalSize(rack::window::Window* const window, math::Vec size) {
|
||||
+ size = size.max(WINDOW_SIZE_MIN);
|
||||
+ window->internal->size = size;
|
||||
}
|
||||
|
||||
-}
|
||||
-
|
||||
|
||||
-static void errorCallback(int error, const char* description) {
|
||||
- WARN("GLFW error %d: %s", error, description);
|
||||
+void Window::run() {
|
||||
+ internal->frame = 0;
|
||||
}
|
||||
|
||||
|
||||
-}
|
||||
-
|
||||
-
|
||||
-Window::Window() {
|
||||
- internal = new Internal;
|
||||
- int err;
|
||||
-
|
||||
+ if (ui != nullptr)
|
||||
+ {
|
||||
+ const GLubyte* vendor = glGetString(GL_VENDOR);
|
||||
+ const GLubyte* renderer = glGetString(GL_RENDERER);
|
||||
+ const GLubyte* version = glGetString(GL_VERSION);
|
||||
+ INFO("Renderer: %s %s", vendor, renderer);
|
||||
+ INFO("OpenGL: %s", version);
|
||||
+
|
||||
+ window->internal->tlw = ui;
|
||||
+ window->internal->ui = ui;
|
||||
+ window->internal->size = rack::math::Vec(ui->getWidth(), ui->getHeight());
|
||||
+
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ // Set up NanoVG
|
||||
+ window->internal->r_vg = ui->getContext();
|
||||
+#ifdef NANOVG_GLES2
|
||||
+ window->internal->r_fbVg = nvgCreateSharedGLES2(window->internal->r_vg, NVG_ANTIALIAS);
|
||||
+#else
|
||||
+ window->internal->r_fbVg = nvgCreateSharedGL2(window->internal->r_vg, NVG_ANTIALIAS);
|
||||
+#endif
|
||||
|
||||
- // Set window hints
|
||||
-#if defined NANOVG_GL2
|
||||
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
|
@ -582,10 +594,36 @@
|
|||
- const GLubyte* version = glGetString(GL_VERSION);
|
||||
- INFO("Renderer: %s %s", vendor, renderer);
|
||||
- INFO("OpenGL: %s", version);
|
||||
-
|
||||
+ // swap contexts
|
||||
+ window->internal->o_vg = window->vg;
|
||||
+ window->internal->o_fbVg = window->fbVg;
|
||||
+ window->vg = window->internal->r_vg;
|
||||
+ window->fbVg = window->internal->r_fbVg;
|
||||
+
|
||||
+ // also for fonts and images
|
||||
+ window->uiFont->vg = window->vg;
|
||||
+ window->uiFont->handle = loadFallbackFont(window->vg);
|
||||
+ for (auto& font : window->internal->fontCache)
|
||||
+ {
|
||||
+ font.second->vg = window->vg;
|
||||
+ font.second->ohandle = font.second->handle;
|
||||
+ font.second->handle = nvgCreateFont(window->vg,
|
||||
+ font.second->ofilename.c_str(), font.second->ofilename.c_str());
|
||||
+ }
|
||||
+ for (auto& image : window->internal->imageCache)
|
||||
+ {
|
||||
+ image.second->vg = window->vg;
|
||||
+ image.second->ohandle = image.second->handle;
|
||||
+ image.second->handle = nvgCreateImage(window->vg, image.second->ofilename.c_str(),
|
||||
+ NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY);
|
||||
+ }
|
||||
+#endif
|
||||
|
||||
- // GLEW generates GL error because it calls glGetString(GL_EXTENSIONS), we'll consume it here.
|
||||
- glGetError();
|
||||
-
|
||||
+ // Init settings
|
||||
+ WindowParametersRestore(window);
|
||||
|
||||
- // Set up NanoVG
|
||||
- int nvgFlags = NVG_ANTIALIAS;
|
||||
-#if defined NANOVG_GL2
|
||||
|
@ -599,15 +637,146 @@
|
|||
- if (!vg) {
|
||||
- osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Could not initialize NanoVG. Does your graphics card support OpenGL 2.0 or greater? If so, make sure you have the latest graphics drivers installed.");
|
||||
- throw Exception("Could not initialize NanoVG");
|
||||
- }
|
||||
-
|
||||
+ widget::Widget::ContextCreateEvent e;
|
||||
+ APP->scene->onContextCreate(e);
|
||||
}
|
||||
+ else
|
||||
+ {
|
||||
+ widget::Widget::ContextDestroyEvent e;
|
||||
+ APP->scene->onContextDestroy(e);
|
||||
|
||||
- // Load default Blendish font
|
||||
- uiFont = loadFont(asset::system("res/fonts/DejaVuSans.ttf"));
|
||||
- bndSetFont(uiFont->handle);
|
||||
-
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ // swap contexts
|
||||
+ window->uiFont->vg = window->internal->o_vg;
|
||||
+ window->vg = window->internal->o_vg;
|
||||
+ window->fbVg = window->internal->o_fbVg;
|
||||
+ window->internal->o_vg = nullptr;
|
||||
+ window->internal->o_fbVg = nullptr;
|
||||
+
|
||||
+ // also for fonts and images
|
||||
+ window->uiFont->vg = window->vg;
|
||||
+ window->uiFont->handle = loadFallbackFont(window->vg);
|
||||
+ for (auto& font : window->internal->fontCache)
|
||||
+ {
|
||||
+ font.second->vg = window->vg;
|
||||
+ font.second->handle = font.second->ohandle;
|
||||
+ font.second->ohandle = -1;
|
||||
+ }
|
||||
+ for (auto& image : window->internal->imageCache)
|
||||
+ {
|
||||
+ image.second->vg = window->vg;
|
||||
+ image.second->handle = image.second->ohandle;
|
||||
+ image.second->ohandle = -1;
|
||||
+ }
|
||||
|
||||
- if (APP->scene) {
|
||||
- widget::Widget::ContextCreateEvent e;
|
||||
- APP->scene->onContextCreate(e);
|
||||
+#if defined NANOVG_GLES2
|
||||
+ nvgDeleteGLES2(window->internal->r_fbVg);
|
||||
+#else
|
||||
+ nvgDeleteGL2(window->internal->r_fbVg);
|
||||
+#endif
|
||||
+#endif
|
||||
+
|
||||
+ window->internal->tlw = nullptr;
|
||||
+ window->internal->ui = nullptr;
|
||||
+ window->internal->callback = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
+void WindowSetMods(Window* const window, const int mods)
|
||||
+{
|
||||
+ window->internal->mods = mods;
|
||||
+}
|
||||
|
||||
Window::~Window() {
|
||||
- if (APP->scene) {
|
||||
- widget::Widget::ContextDestroyEvent e;
|
||||
- APP->scene->onContextDestroy(e);
|
||||
- }
|
||||
+ {
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+ DGL_NAMESPACE::Window::ScopedGraphicsContext sgc(internal->hiddenWindow);
|
||||
+ internal->hiddenWindow.close();
|
||||
+ internal->hiddenApp.idle();
|
||||
+#endif
|
||||
|
||||
- // Fonts and Images in the cache must be deleted before the NanoVG context is deleted
|
||||
- internal->fontCache.clear();
|
||||
- internal->imageCache.clear();
|
||||
-
|
||||
- // nvgDeleteClone(fbVg);
|
||||
-
|
||||
-#if defined NANOVG_GL2
|
||||
- nvgDeleteGL2(vg);
|
||||
- nvgDeleteGL2(fbVg);
|
||||
-#elif defined NANOVG_GL3
|
||||
- nvgDeleteGL3(vg);
|
||||
-#elif defined NANOVG_GLES2
|
||||
- nvgDeleteGLES2(vg);
|
||||
+ // Fonts and Images in the cache must be deleted before the NanoVG context is deleted
|
||||
+ internal->fontCache.clear();
|
||||
+ internal->imageCache.clear();
|
||||
+
|
||||
+ if (vg != nullptr)
|
||||
+ {
|
||||
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
|
||||
+#if defined NANOVG_GLES2
|
||||
+ nvgDeleteGLES2(internal->o_fbVg != nullptr ? internal->o_fbVg : fbVg);
|
||||
+ nvgDeleteGLES2(internal->o_vg != nullptr ? internal->o_vg : vg);
|
||||
+#else
|
||||
+ nvgDeleteGL2(internal->o_fbVg != nullptr ? internal->o_fbVg : fbVg);
|
||||
+ nvgDeleteGL2(internal->o_vg != nullptr ? internal->o_vg : vg);
|
||||
+#endif
|
||||
+#else
|
||||
+#if defined NANOVG_GLES2
|
||||
+ nvgDeleteGLES2(fbVg);
|
||||
+#else
|
||||
+ nvgDeleteGL2(fbVg);
|
||||
+#endif
|
||||
#endif
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- glfwDestroyWindow(win);
|
||||
delete internal;
|
||||
}
|
||||
|
||||
|
||||
math::Vec Window::getSize() {
|
||||
- int width, height;
|
||||
- glfwGetWindowSize(win, &width, &height);
|
||||
- return math::Vec(width, height);
|
||||
+ return internal->size;
|
||||
}
|
||||
|
||||
|
||||
void Window::setSize(math::Vec size) {
|
||||
size = size.max(WINDOW_SIZE_MIN);
|
||||
- glfwSetWindowSize(win, size.x, size.y);
|
||||
+ internal->size = size;
|
||||
+
|
||||
+ if (DGL_NAMESPACE::NanoTopLevelWidget* const tlw = internal->ui)
|
||||
+ tlw->setSize(internal->size.x, internal->size.y);
|
||||
+}
|
||||
+
|
||||
+void WindowSetInternalSize(rack::window::Window* const window, math::Vec size) {
|
||||
+ size = size.max(WINDOW_SIZE_MIN);
|
||||
+ window->internal->size = size;
|
||||
}
|
||||
|
||||
|
||||
void Window::run() {
|
||||
internal->frame = 0;
|
||||
- while (!glfwWindowShouldClose(win)) {
|
||||
- step();
|
||||
+}
|
||||
+
|
||||
+
|
||||
+#ifndef DGL_USE_GLES
|
||||
+static void Window__flipBitmap(uint8_t* pixels, const int width, const int height, const int depth) {
|
||||
+ for (int y = 0; y < height / 2; y++) {
|
||||
|
@ -620,10 +789,6 @@
|
|||
}
|
||||
|
||||
|
||||
-Window::~Window() {
|
||||
- if (APP->scene) {
|
||||
- widget::Widget::ContextDestroyEvent e;
|
||||
- APP->scene->onContextDestroy(e);
|
||||
+#ifdef STBI_WRITE_NO_STDIO
|
||||
+static void Window__downscaleBitmap(uint8_t* pixels, int& width, int& height) {
|
||||
+ int targetWidth = width;
|
||||
|
@ -650,62 +815,31 @@
|
|||
+ const int xs = static_cast<int>(x * scale);
|
||||
+ std::memmove(pixels + (width * y + x) * 3, pixels + (width * ys + xs) * 3, 3);
|
||||
+ }
|
||||
}
|
||||
|
||||
- // Fonts and Images in the cache must be deleted before the NanoVG context is deleted
|
||||
- internal->fontCache.clear();
|
||||
- internal->imageCache.clear();
|
||||
-
|
||||
- // nvgDeleteClone(fbVg);
|
||||
-
|
||||
-#if defined NANOVG_GL2
|
||||
- nvgDeleteGL2(vg);
|
||||
- nvgDeleteGL2(fbVg);
|
||||
-#elif defined NANOVG_GL3
|
||||
- nvgDeleteGL3(vg);
|
||||
-#elif defined NANOVG_GLES2
|
||||
- nvgDeleteGLES2(vg);
|
||||
-#endif
|
||||
-
|
||||
- glfwDestroyWindow(win);
|
||||
- delete internal;
|
||||
-}
|
||||
-
|
||||
-
|
||||
-math::Vec Window::getSize() {
|
||||
- int width, height;
|
||||
- glfwGetWindowSize(win, &width, &height);
|
||||
- return math::Vec(width, height);
|
||||
+ }
|
||||
+
|
||||
+ width = targetWidth;
|
||||
+ height = targetHeight;
|
||||
}
|
||||
|
||||
-
|
||||
-void Window::setSize(math::Vec size) {
|
||||
- size = size.max(WINDOW_SIZE_MIN);
|
||||
- glfwSetWindowSize(win, size.x, size.y);
|
||||
+}
|
||||
+
|
||||
+static void Window__writeImagePNG(void* context, void* data, int size) {
|
||||
+ USE_NAMESPACE_DISTRHO
|
||||
+ UI* const ui = static_cast<UI*>(context);
|
||||
+ ui->setState("screenshot", String::asBase64(data, size).buffer());
|
||||
}
|
||||
+ CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context);
|
||||
+ if (char* const screenshot = String::asBase64(data, size).getAndReleaseBuffer()) {
|
||||
+ ui->setState("screenshot", screenshot);
|
||||
+ remoteUtils::sendScreenshotToRemote(ui->remoteDetails, screenshot);
|
||||
+ std::free(screenshot);
|
||||
+ }
|
||||
+}
|
||||
+#endif
|
||||
+#endif
|
||||
|
||||
|
||||
-void Window::run() {
|
||||
- internal->frame = 0;
|
||||
- while (!glfwWindowShouldClose(win)) {
|
||||
- step();
|
||||
- }
|
||||
-}
|
||||
+void Window::step() {
|
||||
+ DISTRHO_SAFE_ASSERT_RETURN(internal->ui != nullptr,);
|
||||
|
||||
+
|
||||
+
|
||||
void Window::step() {
|
||||
+ DISTRHO_SAFE_ASSERT_RETURN(internal->tlw != nullptr,);
|
||||
+
|
||||
+ if (vg == nullptr)
|
||||
+ return;
|
||||
|
||||
-void Window::step() {
|
||||
+
|
||||
double frameTime = system::getTime();
|
||||
double lastFrameTime = internal->frameTime;
|
||||
internal->frameTime = frameTime;
|
||||
|
@ -748,12 +882,12 @@
|
|||
if (APP->patch->path != "") {
|
||||
windowTitle += " - ";
|
||||
if (!APP->history->isSaved())
|
||||
@@ -455,246 +480,189 @@
|
||||
@@ -455,246 +623,189 @@
|
||||
windowTitle += system::getFilename(APP->patch->path);
|
||||
}
|
||||
if (windowTitle != internal->lastWindowTitle) {
|
||||
- glfwSetWindowTitle(win, windowTitle.c_str());
|
||||
+ internal->ui->getWindow().setTitle(windowTitle.c_str());
|
||||
+ internal->tlw->getWindow().setTitle(windowTitle.c_str());
|
||||
internal->lastWindowTitle = windowTitle;
|
||||
}
|
||||
|
||||
|
@ -766,7 +900,7 @@
|
|||
- glfwGetWindowContentScale(win, &newPixelRatio, NULL);
|
||||
- newPixelRatio = std::floor(newPixelRatio + 0.5);
|
||||
- }
|
||||
+ float newPixelRatio = internal->ui->getScaleFactor();
|
||||
+ float newPixelRatio = internal->tlw->getScaleFactor();
|
||||
if (newPixelRatio != pixelRatio) {
|
||||
pixelRatio = newPixelRatio;
|
||||
APP->event->handleDirty();
|
||||
|
@ -789,8 +923,8 @@
|
|||
- glfwGetFramebufferSize(win, &fbWidth, &fbHeight);
|
||||
- int winWidth, winHeight;
|
||||
- glfwGetWindowSize(win, &winWidth, &winHeight);
|
||||
+ int winWidth = internal->ui->getWidth();
|
||||
+ int winHeight = internal->ui->getHeight();
|
||||
+ int winWidth = internal->tlw->getWidth();
|
||||
+ int winHeight = internal->tlw->getHeight();
|
||||
+ int fbWidth = winWidth;// * newPixelRatio;
|
||||
+ int fbHeight = winHeight;// * newPixelRatio;
|
||||
windowRatio = (float)fbWidth / winWidth;
|
||||
|
@ -842,19 +976,6 @@
|
|||
- if (frameDurationRemaining > 0.0) {
|
||||
- std::this_thread::sleep_for(std::chrono::duration<double>(frameDurationRemaining));
|
||||
- }
|
||||
-
|
||||
- // t5 = system::getTime();
|
||||
-
|
||||
- // DEBUG("pre-step %6.1f step %6.1f draw %6.1f nvgEndFrame %6.1f glfwSwapBuffers %6.1f total %6.1f",
|
||||
- // (t1 - frameTime) * 1e3f,
|
||||
- // (t2 - t1) * 1e3f,
|
||||
- // (t3 - t2) * 1e3f,
|
||||
- // (t4 - t2) * 1e3f,
|
||||
- // (t5 - t4) * 1e3f,
|
||||
- // (t5 - frameTime) * 1e3f
|
||||
- // );
|
||||
- internal->frame++;
|
||||
-}
|
||||
+#ifndef DGL_USE_GLES
|
||||
+ if (internal->generateScreenshotStep != kScreenshotStepNone) {
|
||||
+ ++internal->generateScreenshotStep;
|
||||
|
@ -867,16 +988,24 @@
|
|||
+ constexpr const int depth = 3;
|
||||
+#endif
|
||||
|
||||
- // t5 = system::getTime();
|
||||
+ // Allocate pixel color buffer
|
||||
+ uint8_t* const pixels = new uint8_t[winHeight * winWidth * 4];
|
||||
|
||||
-void Window::activateContext() {
|
||||
- glfwMakeContextCurrent(win);
|
||||
- // DEBUG("pre-step %6.1f step %6.1f draw %6.1f nvgEndFrame %6.1f glfwSwapBuffers %6.1f total %6.1f",
|
||||
- // (t1 - frameTime) * 1e3f,
|
||||
- // (t2 - t1) * 1e3f,
|
||||
- // (t3 - t2) * 1e3f,
|
||||
- // (t4 - t2) * 1e3f,
|
||||
- // (t5 - t4) * 1e3f,
|
||||
- // (t5 - frameTime) * 1e3f
|
||||
- // );
|
||||
- internal->frame++;
|
||||
-}
|
||||
+ // glReadPixels defaults to GL_BACK, but the back-buffer is unstable, so use the front buffer (what the user sees)
|
||||
+ glReadBuffer(GL_FRONT);
|
||||
+ glReadPixels(0, 0, winWidth, winHeight, depth == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
+
|
||||
|
||||
+ if (internal->generateScreenshotStep == kScreenshotStepSaving)
|
||||
+ {
|
||||
+ // Write pixels to PNG
|
||||
|
@ -892,10 +1021,18 @@
|
|||
+ stbi_write_png("screenshot.png", winWidth, winHeight, depth, pixelsWithOffset, stride);
|
||||
+#endif
|
||||
|
||||
-void Window::activateContext() {
|
||||
- glfwMakeContextCurrent(win);
|
||||
+ internal->generateScreenshotStep = kScreenshotStepNone;
|
||||
+ APP->scene->menuBar->show();
|
||||
+ APP->scene->rack->children.front()->show();
|
||||
+ }
|
||||
+
|
||||
+ delete[] pixels;
|
||||
+ }
|
||||
+#endif
|
||||
}
|
||||
|
||||
|
||||
-static void flipBitmap(uint8_t* pixels, int width, int height, int depth) {
|
||||
- for (int y = 0; y < height / 2; y++) {
|
||||
|
@ -904,9 +1041,8 @@
|
|||
- std::memcpy(tmp, &pixels[y * width * depth], width * depth);
|
||||
- std::memcpy(&pixels[y * width * depth], &pixels[flipY * width * depth], width * depth);
|
||||
- std::memcpy(&pixels[flipY * width * depth], tmp, width * depth);
|
||||
+ delete[] pixels;
|
||||
}
|
||||
+#endif
|
||||
- }
|
||||
+void Window::activateContext() {
|
||||
}
|
||||
|
||||
|
||||
|
@ -975,7 +1111,7 @@
|
|||
- nvgImageSize(vg, fbw->getImageHandle(), &width, &height);
|
||||
- uint8_t* pixels = new uint8_t[height * width * 4];
|
||||
- glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
+void Window::activateContext() {
|
||||
+void Window::screenshot(const std::string&) {
|
||||
+}
|
||||
|
||||
- // Write pixels to PNG
|
||||
|
@ -988,19 +1124,15 @@
|
|||
- delete fbw;
|
||||
- }
|
||||
- }
|
||||
+void Window::screenshot(const std::string&) {
|
||||
+}
|
||||
+
|
||||
+
|
||||
+void Window::screenshotModules(const std::string&, float) {
|
||||
}
|
||||
|
||||
|
||||
void Window::close() {
|
||||
- glfwSetWindowShouldClose(win, GLFW_TRUE);
|
||||
+ DISTRHO_SAFE_ASSERT_RETURN(internal->ui != nullptr,);
|
||||
+ DISTRHO_SAFE_ASSERT_RETURN(internal->tlw != nullptr,);
|
||||
+
|
||||
+ internal->ui->getWindow().close();
|
||||
+ internal->tlw->getWindow().close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1013,7 +1145,7 @@
|
|||
- glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
-#else
|
||||
- glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
+ emscripten_request_pointerlock(internal->ui->getWindow().getApp().getClassName(), false);
|
||||
+ emscripten_request_pointerlock(internal->tlw->getWindow().getApp().getClassName(), false);
|
||||
#endif
|
||||
- internal->ignoreNextMouseDelta = true;
|
||||
}
|
||||
|
@ -1071,7 +1203,7 @@
|
|||
+void Window::setFullScreen(const bool fullscreen) {
|
||||
+#ifdef DISTRHO_OS_WASM
|
||||
+ if (fullscreen)
|
||||
+ emscripten_request_fullscreen(internal->ui->getWindow().getApp().getClassName(), false);
|
||||
+ emscripten_request_fullscreen(internal->tlw->getWindow().getApp().getClassName(), false);
|
||||
+ else
|
||||
+ emscripten_exit_fullscreen();
|
||||
+#endif
|
||||
|
@ -1097,7 +1229,7 @@
|
|||
double Window::getMonitorRefreshRate() {
|
||||
return internal->monitorRefreshRate;
|
||||
}
|
||||
@@ -722,14 +690,15 @@
|
||||
@@ -722,14 +833,15 @@
|
||||
return pair->second;
|
||||
|
||||
// Load font
|
||||
|
@ -1116,7 +1248,7 @@
|
|||
}
|
||||
internal->fontCache[filename] = font;
|
||||
return font;
|
||||
@@ -742,14 +711,15 @@
|
||||
@@ -742,14 +854,15 @@
|
||||
return pair->second;
|
||||
|
||||
// Load image
|
||||
|
@ -1135,7 +1267,7 @@
|
|||
}
|
||||
internal->imageCache[filename] = image;
|
||||
return image;
|
||||
@@ -766,28 +736,156 @@
|
||||
@@ -766,28 +879,156 @@
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue