diff --git a/include/gui.hpp b/include/gui.hpp index 0fadecb1..de41840c 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -17,6 +17,7 @@ namespace rack { extern GLFWwindow *gWindow; extern NVGcontext *gVg; +extern NVGcontext *gFramebufferVg; extern std::shared_ptr gGuiFont; extern float gPixelRatio; extern bool gAllowCursorLock; diff --git a/include/widgets.hpp b/include/widgets.hpp index cdf56b9b..ea020cab 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -228,7 +228,6 @@ struct FramebufferWidget : virtual Widget { FramebufferWidget(); ~FramebufferWidget(); - void step() override; void draw(NVGcontext *vg) override; int getImageHandle(); }; diff --git a/src/app/RackScene.cpp b/src/app/RackScene.cpp index e13e3cea..fa16827a 100644 --- a/src/app/RackScene.cpp +++ b/src/app/RackScene.cpp @@ -31,7 +31,7 @@ RackScene::RackScene() { scrollWidget = new RackScrollWidget(); { zoomWidget = new ZoomWidget(); - zoomWidget->zoom = 1.0; + zoomWidget->zoom = 0.5; { assert(!gRackWidget); gRackWidget = new RackWidget(); diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 1d32c3e3..d237d145 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -404,6 +404,9 @@ struct AddManufacturerMenuItem : MenuItem { for (Model *model : models) { AddModuleMenuItem *item = new AddModuleMenuItem(); item->text = model->name; + // item->rightText = model->plugin->slug; + // if (!model->plugin->version.empty()) + // item->rightText += " v" + model->plugin->version; item->model = model; item->modulePos = modulePos; menu->pushChild(item); diff --git a/src/gui.cpp b/src/gui.cpp index eb789cef..d7a08a59 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -29,6 +29,7 @@ namespace rack { GLFWwindow *gWindow = NULL; NVGcontext *gVg = NULL; +NVGcontext *gFramebufferVg = NULL; std::shared_ptr gGuiFont; float gPixelRatio = 0.0; bool gAllowCursorLock = true; @@ -220,15 +221,15 @@ void renderGui() { gPixelRatio = (float)width / windowWidth; // Update and render - glViewport(0, 0, width, height); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); nvgBeginFrame(gVg, width, height, gPixelRatio); nvgReset(gVg); nvgScale(gVg, gPixelRatio, gPixelRatio); gScene->draw(gVg); + glViewport(0, 0, width, height); + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); nvgEndFrame(gVg); glfwSwapBuffers(gWindow); } @@ -288,6 +289,9 @@ void guiInit() { // gVg = nvgCreateGL3(NVG_ANTIALIAS); assert(gVg); + gFramebufferVg = nvgCreateGL2(NVG_ANTIALIAS); + assert(gFramebufferVg); + // Set up Blendish gGuiFont = Font::load(assetGlobal("res/DejaVuSans.ttf")); bndSetFont(gGuiFont->handle); @@ -298,6 +302,7 @@ void guiDestroy() { gGuiFont.reset(); nvgDeleteGL2(gVg); // nvgDeleteGL3(gVg); + nvgDeleteGL2(gFramebufferVg); glfwDestroyWindow(gWindow); glfwTerminate(); } diff --git a/src/widgets/FramebufferWidget.cpp b/src/widgets/FramebufferWidget.cpp index 21a14158..bb95ca00 100644 --- a/src/widgets/FramebufferWidget.cpp +++ b/src/widgets/FramebufferWidget.cpp @@ -32,11 +32,7 @@ FramebufferWidget::~FramebufferWidget() { delete internal; } -void FramebufferWidget::step() { - // Step children before rendering - Widget::step(); - - // Render the scene to the framebuffer if dirty +void FramebufferWidget::draw(NVGcontext *vg) { if (dirty) { internal->box.pos = Vec(0, 0); internal->box.size = box.size; @@ -50,6 +46,7 @@ void FramebufferWidget::step() { // Delete old one first to free up GPU memory internal->setFramebuffer(NULL); + // Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. NVGLUframebuffer *fb = nvgluCreateFramebuffer(gVg, fbSize.x, fbSize.y, NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); if (!fb) return; @@ -59,36 +56,19 @@ void FramebufferWidget::step() { glViewport(0.0, 0.0, fbSize.x, fbSize.y); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - nvgBeginFrame(gVg, fbSize.x, fbSize.y, gPixelRatio * oversample); - nvgScale(gVg, gPixelRatio * oversample, gPixelRatio * oversample); - Widget::draw(gVg); + nvgBeginFrame(gFramebufferVg, fbSize.x, fbSize.y, gPixelRatio * oversample); - nvgEndFrame(gVg); + nvgScale(gFramebufferVg, gPixelRatio * oversample, gPixelRatio * oversample); + Widget::draw(gFramebufferVg); + + nvgEndFrame(gFramebufferVg); nvgluBindFramebuffer(NULL); dirty = false; } -} - -void FramebufferWidget::draw(NVGcontext *vg) { - // { - // float xform[6]; - // nvgCurrentTransform(vg, xform); - // printf("%f %f %f %f %f %f\n", xform[0], xform[1], xform[2], xform[3], xform[4], xform[5]); - // nvgSave(vg); - // nvgResetTransform(vg); - // nvgTranslate(vg, xform[5], xform[6]); - // nvgBeginPath(vg); - // nvgRect(vg, 0, 0, 50, 50); - // nvgFillColor(vg, nvgRGBf(1.0, 0.0, 0.0)); - // nvgFill(vg); - // nvgRestore(vg); - // } if (!internal->fb) { - // Bypass framebuffer cache entirely - // Widget::draw(vg); return; } @@ -102,6 +82,22 @@ void FramebufferWidget::draw(NVGcontext *vg) { // For debugging bounding box of framebuffer image // nvgFillColor(vg, nvgRGBA(255, 0, 0, 64)); // nvgFill(vg); + + { + float xform[6]; + nvgCurrentTransform(vg, xform); + // printf("%f %f %f %f; %f %f\n", xform[0], xform[1], xform[2], xform[3], xform[4], xform[5]); + nvgSave(vg); + nvgResetTransform(vg); + nvgTranslate(vg, xform[4], xform[5]); + nvgScale(vg, xform[0], xform[3]); + nvgBeginPath(vg); + nvgRect(vg, 0, 0, internal->box.size.x, internal->box.size.y); + nvgStrokeWidth(vg, 2.0); + nvgStrokeColor(vg, nvgRGBf(1.0, 0.0, 0.0)); + nvgStroke(vg); + nvgRestore(vg); + } } int FramebufferWidget::getImageHandle() {