|
|
@@ -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() { |
|
|
|