Browse Source

Set FrameBuffer::oversample to 1 by default

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
923942e289
5 changed files with 35 additions and 33 deletions
  1. +1
    -0
      .gitignore
  2. +4
    -0
      include/widgets.hpp
  3. +27
    -26
      src/app/RackWidget.cpp
  4. +1
    -1
      src/gui.cpp
  5. +2
    -6
      src/widgets/FramebufferWidget.cpp

+ 1
- 0
.gitignore View File

@@ -8,3 +8,4 @@
*.vcv
/patches
/design
.DS_Store

+ 4
- 0
include/widgets.hpp View File

@@ -230,6 +230,10 @@ Events are not passed to the underlying scene.
struct FramebufferWidget : virtual Widget {
/** Set this to true to re-render the children to the framebuffer the next time it is drawn */
bool dirty = true;
/** A margin in pixels around the children in the framebuffer
This prevents cutting the rendered SVG off on the box edges.
*/
float oversample;
/** The root object in the framebuffer scene
The FramebufferWidget owns the pointer
*/


+ 27
- 26
src/app/RackWidget.cpp View File

@@ -15,14 +15,15 @@ namespace rack {


RackWidget::RackWidget() {
rails = new FramebufferWidget();
rails->box.size = Vec();
{
RackRail *rail = new RackRail();
rail->box.size = Vec();
rails->addChild(rail);
}
addChild(rails);
// rails = new FramebufferWidget();
// rails->box.size = Vec();
// rails->oversample = 1.0;
// {
// RackRail *rail = new RackRail();
// rail->box.size = Vec();
// rails->addChild(rail);
// }
// addChild(rails);

moduleContainer = new Widget();
addChild(moduleContainer);
@@ -340,23 +341,23 @@ void RackWidget::step() {
// We assume that the size is reset by a parent before calling step(). Otherwise it will grow unbounded.
box.size = box.size.max(moduleSize);

// Adjust size and position of rails
Widget *rail = rails->children.front();
Rect bound = getViewport(Rect(Vec(), box.size));
if (!rails->box.contains(bound)) {
// Add a margin around the otherwise tight bound, so that scrolling slightly will not require a re-render of rails.
Vec margin = Vec(100, 100);
bound.pos = bound.pos.minus(margin);
bound.size = bound.size.plus(margin.mult(2));
rails->box = bound;
// Compute offset of rail within rails framebuffer
Vec grid = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
Vec gridPos = bound.pos.div(grid).floor().mult(grid);
bound.pos = gridPos.minus(bound.pos);
bound.size = bound.size.minus(bound.pos);
rail->box = bound;
rails->dirty = true;
}
// // Adjust size and position of rails
// Widget *rail = rails->children.front();
// Rect bound = getViewport(Rect(Vec(), box.size));
// if (!rails->box.contains(bound)) {
// // Add a margin around the otherwise tight bound, so that scrolling slightly will not require a re-render of rails.
// Vec margin = Vec(100, 100);
// bound.pos = bound.pos.minus(margin);
// bound.size = bound.size.plus(margin.mult(2));
// rails->box = bound;
// // Compute offset of rail within rails framebuffer
// Vec grid = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
// Vec gridPos = bound.pos.div(grid).floor().mult(grid);
// bound.pos = gridPos.minus(bound.pos);
// bound.size = bound.size.minus(bound.pos);
// rail->box = bound;
// rails->dirty = true;
// }

// Autosave every 15 seconds
if (gGuiFrame % (60*15) == 0) {
@@ -525,7 +526,7 @@ void RackWidget::onMouseDownOpaque(int button) {
}

void RackWidget::onZoom() {
rails->box.size = Vec();
// rails->box.size = Vec();
Widget::onZoom();
}



+ 1
- 1
src/gui.cpp View File

@@ -358,7 +358,7 @@ void guiRun() {
std::this_thread::sleep_for(std::chrono::duration<double>(minTime - frameTime));
}
endTime = glfwGetTime();
// printf("%lf fps\n", 1.0 / (endTime - startTime));
printf("%lf fps\n", 1.0 / (endTime - startTime));
}
}



+ 2
- 6
src/widgets/FramebufferWidget.cpp View File

@@ -9,12 +9,6 @@
namespace rack {


/** A margin in pixels around the children in the framebuffer
This prevents cutting the rendered SVG off on the box edges.
*/
static const float oversample = 2.0;


struct FramebufferWidget::Internal {
NVGLUframebuffer *fb = NULL;
Rect box;
@@ -32,6 +26,7 @@ struct FramebufferWidget::Internal {

FramebufferWidget::FramebufferWidget() {
internal = new Internal();
oversample = 1.0;
}

FramebufferWidget::~FramebufferWidget() {
@@ -65,6 +60,7 @@ void FramebufferWidget::draw(NVGcontext *vg) {
if (fbSize.x <= 0.0 || fbSize.y <= 0.0)
return;

printf("rendering framebuffer %f %f\n", fbSize.x, fbSize.y);
// 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.


Loading…
Cancel
Save