Changeset View
Changeset View
Standalone View
Standalone View
effects/blur/blur.cpp
Show First 20 Lines • Show All 516 Lines • ▼ Show 20 Line(s) | 516 | { | |||
---|---|---|---|---|---|
517 | const QRegion expanded = expand(shape) & screen; | 517 | const QRegion expanded = expand(shape) & screen; | ||
518 | const QRect r = expanded.boundingRect(); | 518 | const QRect r = expanded.boundingRect(); | ||
519 | 519 | | |||
520 | // Upload geometry for the horizontal and vertical passes | 520 | // Upload geometry for the horizontal and vertical passes | ||
521 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | 521 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | ||
522 | uploadGeometry(vbo, expanded, shape); | 522 | uploadGeometry(vbo, expanded, shape); | ||
523 | vbo->bindArrays(); | 523 | vbo->bindArrays(); | ||
524 | 524 | | |||
525 | const qreal scale = GLRenderTarget::virtualScreenScale(); | ||||
526 | | ||||
525 | // Create a scratch texture and copy the area in the back buffer that we're | 527 | // Create a scratch texture and copy the area in the back buffer that we're | ||
526 | // going to blur into it | 528 | // going to blur into it | ||
527 | GLTexture scratch(GL_RGBA8, r.width(), r.height()); | 529 | // for HIGH DPI scratch is captured in native resolution, it is then implicitly downsampled | ||
530 | // when rendering into tex | ||||
531 | GLTexture scratch(GL_RGBA8, r.width() * scale, r.height() * scale); | ||||
528 | scratch.setFilter(GL_LINEAR); | 532 | scratch.setFilter(GL_LINEAR); | ||
529 | scratch.setWrapMode(GL_CLAMP_TO_EDGE); | 533 | scratch.setWrapMode(GL_CLAMP_TO_EDGE); | ||
530 | scratch.bind(); | 534 | scratch.bind(); | ||
531 | 535 | | |||
532 | const QRect sg = GLRenderTarget::virtualScreenGeometry(); | 536 | const QRect sg = GLRenderTarget::virtualScreenGeometry(); | ||
533 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x() - sg.x(), sg.height() - sg.y() - r.y() - r.height(), | 537 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (r.x() - sg.x()) * scale, (sg.height() - sg.y() - r.y() - r.height()) * scale, | ||
534 | r.width(), r.height()); | 538 | scratch.width(), scratch.height()); | ||
535 | 539 | | |||
536 | // Draw the texture on the offscreen framebuffer object, while blurring it horizontally | 540 | // Draw the texture on the offscreen framebuffer object, while blurring it horizontally | ||
537 | target->attachTexture(tex); | 541 | target->attachTexture(tex); | ||
538 | GLRenderTarget::pushRenderTarget(target); | 542 | GLRenderTarget::pushRenderTarget(target); | ||
539 | 543 | | |||
540 | shader->bind(); | 544 | shader->bind(); | ||
541 | shader->setDirection(Qt::Horizontal); | 545 | shader->setDirection(Qt::Horizontal); | ||
542 | shader->setPixelDistance(1.0 / r.width()); | 546 | shader->setPixelDistance(1.0 / r.width()); | ||
543 | 547 | | |||
544 | QMatrix4x4 modelViewProjectionMatrix; | 548 | QMatrix4x4 modelViewProjectionMatrix; | ||
545 | modelViewProjectionMatrix.ortho(0, tex.width(), tex.height(), 0 , 0, 65535); | 549 | modelViewProjectionMatrix.ortho(0, tex.width(), tex.height(), 0 , 0, 65535); | ||
546 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | 550 | shader->setModelViewProjectionMatrix(modelViewProjectionMatrix); | ||
547 | 551 | | |||
548 | // Set up the texture matrix to transform from screen coordinates | 552 | // Set up the texture matrix to transform from screen coordinates | ||
549 | // to texture coordinates. | 553 | // to texture coordinates. | ||
550 | QMatrix4x4 textureMatrix; | 554 | QMatrix4x4 textureMatrix; | ||
551 | textureMatrix.scale(1.0 / scratch.width(), -1.0 / scratch.height(), 1); | 555 | textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1); | ||
552 | textureMatrix.translate(-r.x(), -scratch.height() - r.y(), 0); | 556 | textureMatrix.translate(-r.x(), (-r.height() - r.y()), 0); | ||
553 | shader->setTextureMatrix(textureMatrix); | 557 | shader->setTextureMatrix(textureMatrix); | ||
554 | 558 | | |||
555 | vbo->draw(GL_TRIANGLES, 0, expanded.rectCount() * 6); | 559 | vbo->draw(GL_TRIANGLES, 0, expanded.rectCount() * 6); | ||
556 | 560 | | |||
557 | GLRenderTarget::popRenderTarget(); | 561 | GLRenderTarget::popRenderTarget(); | ||
558 | scratch.unbind(); | 562 | scratch.unbind(); | ||
559 | scratch.discard(); | 563 | scratch.discard(); | ||
560 | 564 | | |||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |