Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/opengl/kis_opengl_canvas2.cpp
Show First 20 Lines • Show All 381 Lines • ▼ Show 20 Line(s) | 373 | { | |||
---|---|---|---|---|---|
382 | cfg.setCanvasState("OPENGL_FAILED"); | 382 | cfg.setCanvasState("OPENGL_FAILED"); | ||
383 | } | 383 | } | ||
384 | 384 | | |||
385 | void KisOpenGLCanvas2::resizeGL(int width, int height) | 385 | void KisOpenGLCanvas2::resizeGL(int width, int height) | ||
386 | { | 386 | { | ||
387 | coordinatesConverter()->setCanvasWidgetSize(QSize(width, height)); | 387 | coordinatesConverter()->setCanvasWidgetSize(QSize(width, height)); | ||
388 | paintGL(); | 388 | paintGL(); | ||
389 | } | 389 | } | ||
390 | 390 | | |||
dkazakov: This one should also go :) | |||||
391 | void KisOpenGLCanvas2::paintGL() | 391 | void KisOpenGLCanvas2::paintGL() | ||
392 | { | 392 | { | ||
393 | if (!OPENGL_SUCCESS) { | 393 | if (!OPENGL_SUCCESS) { | ||
394 | KisConfig cfg(false); | 394 | KisConfig cfg(false); | ||
395 | cfg.writeEntry("canvasState", "OPENGL_PAINT_STARTED"); | 395 | cfg.writeEntry("canvasState", "OPENGL_PAINT_STARTED"); | ||
396 | } | 396 | } | ||
397 | 397 | | |||
398 | KisOpenglCanvasDebugger::instance()->nofityPaintRequested(); | 398 | KisOpenglCanvasDebugger::instance()->nofityPaintRequested(); | ||
Show All 17 Lines | |||||
416 | } | 416 | } | ||
417 | 417 | | |||
418 | void KisOpenGLCanvas2::paintToolOutline(const QPainterPath &path) | 418 | void KisOpenGLCanvas2::paintToolOutline(const QPainterPath &path) | ||
419 | { | 419 | { | ||
420 | if (!d->solidColorShader->bind()) { | 420 | if (!d->solidColorShader->bind()) { | ||
421 | return; | 421 | return; | ||
422 | } | 422 | } | ||
423 | 423 | | |||
424 | QSizeF widgetSize = widgetSizeAlignedToDevicePixel(); | ||||
425 | | ||||
424 | // setup the mvp transformation | 426 | // setup the mvp transformation | ||
425 | QMatrix4x4 projectionMatrix; | 427 | QMatrix4x4 projectionMatrix; | ||
426 | projectionMatrix.setToIdentity(); | 428 | projectionMatrix.setToIdentity(); | ||
427 | projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL); | 429 | // FIXME: It may be better to have the projection in device pixel, but | ||
430 | // this requires introducing a new coordinate system. | ||||
431 | projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL); | ||||
428 | 432 | | |||
429 | // Set view/projection matrices | 433 | // Set view/projection matrices | ||
430 | QMatrix4x4 modelMatrix(coordinatesConverter()->flakeToWidgetTransform()); | 434 | QMatrix4x4 modelMatrix(coordinatesConverter()->flakeToWidgetTransform()); | ||
431 | modelMatrix.optimize(); | 435 | modelMatrix.optimize(); | ||
432 | modelMatrix = projectionMatrix * modelMatrix; | 436 | modelMatrix = projectionMatrix * modelMatrix; | ||
433 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | 437 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
434 | 438 | | |||
435 | if (!KisOpenGL::hasOpenGLES()) { | 439 | if (!KisOpenGL::hasOpenGLES()) { | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 517 | { | |||
516 | } | 520 | } | ||
517 | 521 | | |||
518 | KisCoordinatesConverter *converter = coordinatesConverter(); | 522 | KisCoordinatesConverter *converter = coordinatesConverter(); | ||
519 | QTransform textureTransform; | 523 | QTransform textureTransform; | ||
520 | QTransform modelTransform; | 524 | QTransform modelTransform; | ||
521 | QRectF textureRect; | 525 | QRectF textureRect; | ||
522 | QRectF modelRect; | 526 | QRectF modelRect; | ||
523 | 527 | | |||
528 | QSizeF widgetSize = widgetSizeAlignedToDevicePixel(); | ||||
524 | QRectF viewportRect = !d->wrapAroundMode ? | 529 | QRectF viewportRect = !d->wrapAroundMode ? | ||
525 | converter->imageRectInViewportPixels() : | 530 | converter->imageRectInViewportPixels() : | ||
526 | converter->widgetToViewport(this->rect()); | 531 | converter->widgetToViewport(QRectF(0, 0, widgetSize.width(), widgetSize.height())); | ||
527 | 532 | | |||
528 | if (!canvas()->renderingLimit().isEmpty()) { | 533 | if (!canvas()->renderingLimit().isEmpty()) { | ||
529 | const QRect vrect = converter->imageToViewport(canvas()->renderingLimit()).toAlignedRect(); | 534 | const QRect vrect = converter->imageToViewport(canvas()->renderingLimit()).toAlignedRect(); | ||
530 | viewportRect &= vrect; | 535 | viewportRect &= vrect; | ||
531 | } | 536 | } | ||
532 | 537 | | |||
533 | converter->getOpenGLCheckersInfo(viewportRect, | 538 | converter->getOpenGLCheckersInfo(viewportRect, | ||
534 | &textureTransform, &modelTransform, &textureRect, &modelRect, d->scrollCheckers); | 539 | &textureTransform, &modelTransform, &textureRect, &modelRect, d->scrollCheckers); | ||
535 | 540 | | |||
536 | textureTransform *= QTransform::fromScale(d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE, | 541 | textureTransform *= QTransform::fromScale(d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE, | ||
537 | d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE); | 542 | d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE); | ||
538 | 543 | | |||
539 | if (!d->checkerShader->bind()) { | 544 | if (!d->checkerShader->bind()) { | ||
540 | qWarning() << "Could not bind checker shader"; | 545 | qWarning() << "Could not bind checker shader"; | ||
541 | return; | 546 | return; | ||
542 | } | 547 | } | ||
543 | 548 | | |||
544 | QMatrix4x4 projectionMatrix; | 549 | QMatrix4x4 projectionMatrix; | ||
545 | projectionMatrix.setToIdentity(); | 550 | projectionMatrix.setToIdentity(); | ||
546 | projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL); | 551 | // FIXME: It may be better to have the projection in device pixel, but | ||
552 | // this requires introducing a new coordinate system. | ||||
553 | projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL); | ||||
547 | 554 | | |||
548 | // Set view/projection matrices | 555 | // Set view/projection matrices | ||
549 | QMatrix4x4 modelMatrix(modelTransform); | 556 | QMatrix4x4 modelMatrix(modelTransform); | ||
550 | modelMatrix.optimize(); | 557 | modelMatrix.optimize(); | ||
551 | modelMatrix = projectionMatrix * modelMatrix; | 558 | modelMatrix = projectionMatrix * modelMatrix; | ||
552 | d->checkerShader->setUniformValue(d->checkerShader->location(Uniform::ModelViewProjection), modelMatrix); | 559 | d->checkerShader->setUniformValue(d->checkerShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
553 | 560 | | |||
554 | QMatrix4x4 textureMatrix(textureTransform); | 561 | QMatrix4x4 textureMatrix(textureTransform); | ||
Show All 31 Lines | |||||
586 | } | 593 | } | ||
587 | 594 | | |||
588 | void KisOpenGLCanvas2::drawGrid() | 595 | void KisOpenGLCanvas2::drawGrid() | ||
589 | { | 596 | { | ||
590 | if (!d->solidColorShader->bind()) { | 597 | if (!d->solidColorShader->bind()) { | ||
591 | return; | 598 | return; | ||
592 | } | 599 | } | ||
593 | 600 | | |||
601 | QSizeF widgetSize = widgetSizeAlignedToDevicePixel(); | ||||
602 | | ||||
594 | QMatrix4x4 projectionMatrix; | 603 | QMatrix4x4 projectionMatrix; | ||
595 | projectionMatrix.setToIdentity(); | 604 | projectionMatrix.setToIdentity(); | ||
596 | projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL); | 605 | // FIXME: It may be better to have the projection in device pixel, but | ||
606 | // this requires introducing a new coordinate system. | ||||
607 | projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL); | ||||
597 | 608 | | |||
598 | // Set view/projection matrices | 609 | // Set view/projection matrices | ||
599 | QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform()); | 610 | QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform()); | ||
600 | modelMatrix.optimize(); | 611 | modelMatrix.optimize(); | ||
601 | modelMatrix = projectionMatrix * modelMatrix; | 612 | modelMatrix = projectionMatrix * modelMatrix; | ||
602 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | 613 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
603 | 614 | | |||
604 | glEnable(GL_BLEND); | 615 | glEnable(GL_BLEND); | ||
605 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 616 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
606 | 617 | | |||
607 | d->solidColorShader->setUniformValue( | 618 | d->solidColorShader->setUniformValue( | ||
608 | d->solidColorShader->location(Uniform::FragmentColor), | 619 | d->solidColorShader->location(Uniform::FragmentColor), | ||
609 | QVector4D(d->gridColor.redF(), d->gridColor.greenF(), d->gridColor.blueF(), 0.5f)); | 620 | QVector4D(d->gridColor.redF(), d->gridColor.greenF(), d->gridColor.blueF(), 0.5f)); | ||
610 | 621 | | |||
611 | if (KisOpenGL::hasOpenGL3()) { | 622 | if (KisOpenGL::hasOpenGL3()) { | ||
612 | d->outlineVAO.bind(); | 623 | d->outlineVAO.bind(); | ||
613 | d->lineBuffer.bind(); | 624 | d->lineBuffer.bind(); | ||
614 | } | 625 | } | ||
615 | 626 | | |||
616 | QRectF widgetRect(0,0, width(), height()); | 627 | QRectF widgetRect(0,0, widgetSize.width(), widgetSize.height()); | ||
617 | QRectF widgetRectInImagePixels = coordinatesConverter()->documentToImage(coordinatesConverter()->widgetToDocument(widgetRect)); | 628 | QRectF widgetRectInImagePixels = coordinatesConverter()->documentToImage(coordinatesConverter()->widgetToDocument(widgetRect)); | ||
618 | QRect wr = widgetRectInImagePixels.toAlignedRect(); | 629 | QRect wr = widgetRectInImagePixels.toAlignedRect(); | ||
619 | 630 | | |||
620 | if (!d->wrapAroundMode) { | 631 | if (!d->wrapAroundMode) { | ||
621 | wr &= d->openGLImageTextures->storedImageBounds(); | 632 | wr &= d->openGLImageTextures->storedImageBounds(); | ||
622 | } | 633 | } | ||
623 | 634 | | |||
624 | QPoint topLeftCorner = wr.topLeft(); | 635 | QPoint topLeftCorner = wr.topLeft(); | ||
Show All 36 Lines | 668 | { | |||
661 | 672 | | |||
662 | glEnable(GL_BLEND); | 673 | glEnable(GL_BLEND); | ||
663 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 674 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
664 | 675 | | |||
665 | KisCoordinatesConverter *converter = coordinatesConverter(); | 676 | KisCoordinatesConverter *converter = coordinatesConverter(); | ||
666 | 677 | | |||
667 | d->displayShader->bind(); | 678 | d->displayShader->bind(); | ||
668 | 679 | | |||
680 | QSizeF widgetSize = widgetSizeAlignedToDevicePixel(); | ||||
681 | | ||||
669 | QMatrix4x4 projectionMatrix; | 682 | QMatrix4x4 projectionMatrix; | ||
670 | projectionMatrix.setToIdentity(); | 683 | projectionMatrix.setToIdentity(); | ||
671 | projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL); | 684 | // FIXME: It may be better to have the projection in device pixel, but | ||
685 | // this requires introducing a new coordinate system. | ||||
686 | projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL); | ||||
672 | 687 | | |||
673 | // Set view/projection matrices | 688 | // Set view/projection matrices | ||
674 | QMatrix4x4 modelMatrix(converter->imageToWidgetTransform()); | 689 | QMatrix4x4 modelMatrix(converter->imageToWidgetTransform()); | ||
675 | modelMatrix.optimize(); | 690 | modelMatrix.optimize(); | ||
676 | modelMatrix = projectionMatrix * modelMatrix; | 691 | modelMatrix = projectionMatrix * modelMatrix; | ||
677 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix); | 692 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
678 | 693 | | |||
679 | QMatrix4x4 textureMatrix; | 694 | QMatrix4x4 textureMatrix; | ||
680 | textureMatrix.setToIdentity(); | 695 | textureMatrix.setToIdentity(); | ||
681 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix); | 696 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix); | ||
682 | 697 | | |||
683 | QRectF widgetRect(0,0, width(), height()); | 698 | QRectF widgetRect(0,0, widgetSize.width(), widgetSize.height()); | ||
684 | QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect)); | 699 | QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect)); | ||
685 | 700 | | |||
686 | const QRect renderingLimit = canvas()->renderingLimit(); | 701 | const QRect renderingLimit = canvas()->renderingLimit(); | ||
687 | 702 | | |||
688 | if (!renderingLimit.isEmpty()) { | 703 | if (!renderingLimit.isEmpty()) { | ||
689 | widgetRectInImagePixels &= renderingLimit; | 704 | widgetRectInImagePixels &= renderingLimit; | ||
690 | } | 705 | } | ||
691 | 706 | | |||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | |||||
833 | } | 848 | } | ||
834 | 849 | | |||
835 | glBindTexture(GL_TEXTURE_2D, 0); | 850 | glBindTexture(GL_TEXTURE_2D, 0); | ||
836 | d->displayShader->release(); | 851 | d->displayShader->release(); | ||
837 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 852 | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
838 | glDisable(GL_BLEND); | 853 | glDisable(GL_BLEND); | ||
839 | } | 854 | } | ||
840 | 855 | | |||
856 | QSize KisOpenGLCanvas2::viewportDevicePixelSize() const | ||||
857 | { | ||||
858 | // This is how QOpenGLCanvas sets the FBO and the viewport size. If | ||||
859 | // devicePixelRatioF() is non-integral, the result is truncated. | ||||
860 | int viewportWidth = static_cast<int>(width() * devicePixelRatioF()); | ||||
861 | int viewportHeight = static_cast<int>(height() * devicePixelRatioF()); | ||||
862 | return QSize(viewportWidth, viewportHeight); | ||||
863 | } | ||||
864 | | ||||
865 | QSizeF KisOpenGLCanvas2::widgetSizeAlignedToDevicePixel() const | ||||
866 | { | ||||
867 | QSize viewportSize = viewportDevicePixelSize(); | ||||
868 | qreal scaledWidth = viewportSize.width() / devicePixelRatioF(); | ||||
869 | qreal scaledHeight = viewportSize.height() / devicePixelRatioF(); | ||||
870 | return QSizeF(scaledWidth, scaledHeight); | ||||
871 | } | ||||
872 | | ||||
841 | void KisOpenGLCanvas2::slotConfigChanged() | 873 | void KisOpenGLCanvas2::slotConfigChanged() | ||
842 | { | 874 | { | ||
843 | KisConfig cfg(true); | 875 | KisConfig cfg(true); | ||
844 | d->checkSizeScale = KisOpenGLImageTextures::BACKGROUND_TEXTURE_CHECK_SIZE / static_cast<GLfloat>(cfg.checkSize()); | 876 | d->checkSizeScale = KisOpenGLImageTextures::BACKGROUND_TEXTURE_CHECK_SIZE / static_cast<GLfloat>(cfg.checkSize()); | ||
845 | d->scrollCheckers = cfg.scrollCheckers(); | 877 | d->scrollCheckers = cfg.scrollCheckers(); | ||
846 | 878 | | |||
847 | d->openGLImageTextures->generateCheckerTexture(createCheckersImage(cfg.checkSize())); | 879 | d->openGLImageTextures->generateCheckerTexture(createCheckersImage(cfg.checkSize())); | ||
848 | d->openGLImageTextures->updateConfig(cfg.useOpenGLTextureBuffer(), cfg.numMipmapLevels()); | 880 | d->openGLImageTextures->updateConfig(cfg.useOpenGLTextureBuffer(), cfg.numMipmapLevels()); | ||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |
This one should also go :)