Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/opengl/kis_opengl_canvas2.cpp
Show First 20 Lines • Show All 378 Lines • ▼ Show 20 Line(s) | 377 | QMessageBox::critical(this, i18nc("@title:window", "Krita"), | |||
---|---|---|---|---|---|
379 | QMessageBox::Close); | 379 | QMessageBox::Close); | ||
380 | 380 | | |||
381 | cfg.setUseOpenGL(false); | 381 | cfg.setUseOpenGL(false); | ||
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), devicePixelRatioF()); | ||
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 20 Lines • Show All 187 Lines • ▼ Show 20 Line(s) | |||||
586 | } | 586 | } | ||
587 | 587 | | |||
588 | void KisOpenGLCanvas2::drawGrid() | 588 | void KisOpenGLCanvas2::drawGrid() | ||
589 | { | 589 | { | ||
590 | if (!d->solidColorShader->bind()) { | 590 | if (!d->solidColorShader->bind()) { | ||
591 | return; | 591 | return; | ||
592 | } | 592 | } | ||
593 | 593 | | |||
594 | QSize viewportSize = viewportDevicePixelSize(); | ||||
595 | qreal pixelPerfectScaledWidth = viewportSize.width() / devicePixelRatioF(); | ||||
596 | qreal pixelPerfectScaledHeight = viewportSize.height() / devicePixelRatioF(); | ||||
597 | | ||||
594 | QMatrix4x4 projectionMatrix; | 598 | QMatrix4x4 projectionMatrix; | ||
595 | projectionMatrix.setToIdentity(); | 599 | projectionMatrix.setToIdentity(); | ||
596 | projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL); | 600 | // FIXME: It is probably better to have the projection in device pixel, but | ||
601 | // this requires introducing a new coordinate system. | ||||
602 | projectionMatrix.ortho(0, pixelPerfectScaledWidth, pixelPerfectScaledHeight, 0, NEAR_VAL, FAR_VAL); | ||||
597 | 603 | | |||
598 | // Set view/projection matrices | 604 | // Set view/projection matrices | ||
599 | QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform()); | 605 | QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform()); | ||
600 | modelMatrix.optimize(); | 606 | modelMatrix.optimize(); | ||
601 | modelMatrix = projectionMatrix * modelMatrix; | 607 | modelMatrix = projectionMatrix * modelMatrix; | ||
602 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | 608 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
603 | 609 | | |||
604 | glEnable(GL_BLEND); | 610 | glEnable(GL_BLEND); | ||
605 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 611 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
606 | 612 | | |||
607 | d->solidColorShader->setUniformValue( | 613 | d->solidColorShader->setUniformValue( | ||
608 | d->solidColorShader->location(Uniform::FragmentColor), | 614 | d->solidColorShader->location(Uniform::FragmentColor), | ||
609 | QVector4D(d->gridColor.redF(), d->gridColor.greenF(), d->gridColor.blueF(), 0.5f)); | 615 | QVector4D(d->gridColor.redF(), d->gridColor.greenF(), d->gridColor.blueF(), 0.5f)); | ||
610 | 616 | | |||
611 | if (KisOpenGL::hasOpenGL3()) { | 617 | if (KisOpenGL::hasOpenGL3()) { | ||
612 | d->outlineVAO.bind(); | 618 | d->outlineVAO.bind(); | ||
613 | d->lineBuffer.bind(); | 619 | d->lineBuffer.bind(); | ||
614 | } | 620 | } | ||
615 | 621 | | |||
616 | QRectF widgetRect(0,0, width(), height()); | 622 | QRectF widgetRect(0,0, pixelPerfectScaledWidth, pixelPerfectScaledHeight); | ||
617 | QRectF widgetRectInImagePixels = coordinatesConverter()->documentToImage(coordinatesConverter()->widgetToDocument(widgetRect)); | 623 | QRectF widgetRectInImagePixels = coordinatesConverter()->documentToImage(coordinatesConverter()->widgetToDocument(widgetRect)); | ||
618 | QRect wr = widgetRectInImagePixels.toAlignedRect(); | 624 | QRect wr = widgetRectInImagePixels.toAlignedRect(); | ||
619 | 625 | | |||
620 | if (!d->wrapAroundMode) { | 626 | if (!d->wrapAroundMode) { | ||
621 | wr &= d->openGLImageTextures->storedImageBounds(); | 627 | wr &= d->openGLImageTextures->storedImageBounds(); | ||
622 | } | 628 | } | ||
623 | 629 | | |||
624 | QPoint topLeftCorner = wr.topLeft(); | 630 | QPoint topLeftCorner = wr.topLeft(); | ||
Show All 36 Lines | 663 | { | |||
661 | 667 | | |||
662 | glEnable(GL_BLEND); | 668 | glEnable(GL_BLEND); | ||
663 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 669 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||
664 | 670 | | |||
665 | KisCoordinatesConverter *converter = coordinatesConverter(); | 671 | KisCoordinatesConverter *converter = coordinatesConverter(); | ||
666 | 672 | | |||
667 | d->displayShader->bind(); | 673 | d->displayShader->bind(); | ||
668 | 674 | | |||
675 | QSize viewportSize = viewportDevicePixelSize(); | ||||
676 | qreal pixelPerfectScaledWidth = viewportSize.width() / devicePixelRatioF(); | ||||
677 | qreal pixelPerfectScaledHeight = viewportSize.height() / devicePixelRatioF(); | ||||
678 | | ||||
669 | QMatrix4x4 projectionMatrix; | 679 | QMatrix4x4 projectionMatrix; | ||
670 | projectionMatrix.setToIdentity(); | 680 | projectionMatrix.setToIdentity(); | ||
671 | projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL); | 681 | // FIXME: It is probably better to have the projection in device pixel, but | ||
682 | // this requires introducing a new coordinate system. | ||||
683 | projectionMatrix.ortho(0, pixelPerfectScaledWidth, pixelPerfectScaledHeight, 0, NEAR_VAL, FAR_VAL); | ||||
672 | 684 | | |||
673 | // Set view/projection matrices | 685 | // Set view/projection matrices | ||
674 | QMatrix4x4 modelMatrix(converter->imageToWidgetTransform()); | 686 | QMatrix4x4 modelMatrix(converter->imageToWidgetTransform()); | ||
675 | modelMatrix.optimize(); | 687 | modelMatrix.optimize(); | ||
676 | modelMatrix = projectionMatrix * modelMatrix; | 688 | modelMatrix = projectionMatrix * modelMatrix; | ||
677 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix); | 689 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
678 | 690 | | |||
679 | QMatrix4x4 textureMatrix; | 691 | QMatrix4x4 textureMatrix; | ||
680 | textureMatrix.setToIdentity(); | 692 | textureMatrix.setToIdentity(); | ||
681 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix); | 693 | d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix); | ||
682 | 694 | | |||
683 | QRectF widgetRect(0,0, width(), height()); | 695 | QRectF widgetRect(0,0, pixelPerfectScaledWidth, pixelPerfectScaledHeight); | ||
684 | QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect)); | 696 | QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect)); | ||
685 | 697 | | |||
686 | const QRect renderingLimit = canvas()->renderingLimit(); | 698 | const QRect renderingLimit = canvas()->renderingLimit(); | ||
687 | 699 | | |||
688 | if (!renderingLimit.isEmpty()) { | 700 | if (!renderingLimit.isEmpty()) { | ||
689 | widgetRectInImagePixels &= renderingLimit; | 701 | widgetRectInImagePixels &= renderingLimit; | ||
690 | } | 702 | } | ||
691 | 703 | | |||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | |||||
833 | } | 845 | } | ||
834 | 846 | | |||
835 | glBindTexture(GL_TEXTURE_2D, 0); | 847 | glBindTexture(GL_TEXTURE_2D, 0); | ||
836 | d->displayShader->release(); | 848 | d->displayShader->release(); | ||
837 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 849 | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
838 | glDisable(GL_BLEND); | 850 | glDisable(GL_BLEND); | ||
839 | } | 851 | } | ||
840 | 852 | | |||
853 | QSize KisOpenGLCanvas2::viewportDevicePixelSize() const | ||||
854 | { | ||||
855 | // This is how QOpenGLCanvas sets the FBO and the viewport size. If | ||||
856 | // devicePixelRatioF() is non-integral, the result is truncated. | ||||
857 | int viewportWidth = static_cast<int>(width() * devicePixelRatioF()); | ||||
858 | int viewportHeight = static_cast<int>(height() * devicePixelRatioF()); | ||||
859 | return QSize(viewportWidth, viewportHeight); | ||||
860 | } | ||||
861 | | ||||
841 | void KisOpenGLCanvas2::slotConfigChanged() | 862 | void KisOpenGLCanvas2::slotConfigChanged() | ||
842 | { | 863 | { | ||
843 | KisConfig cfg(true); | 864 | KisConfig cfg(true); | ||
844 | d->checkSizeScale = KisOpenGLImageTextures::BACKGROUND_TEXTURE_CHECK_SIZE / static_cast<GLfloat>(cfg.checkSize()); | 865 | d->checkSizeScale = KisOpenGLImageTextures::BACKGROUND_TEXTURE_CHECK_SIZE / static_cast<GLfloat>(cfg.checkSize()); | ||
845 | d->scrollCheckers = cfg.scrollCheckers(); | 866 | d->scrollCheckers = cfg.scrollCheckers(); | ||
846 | 867 | | |||
847 | d->openGLImageTextures->generateCheckerTexture(createCheckersImage(cfg.checkSize())); | 868 | d->openGLImageTextures->generateCheckerTexture(createCheckersImage(cfg.checkSize())); | ||
848 | d->openGLImageTextures->updateConfig(cfg.useOpenGLTextureBuffer(), cfg.numMipmapLevels()); | 869 | d->openGLImageTextures->updateConfig(cfg.useOpenGLTextureBuffer(), cfg.numMipmapLevels()); | ||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |
This one should also go :)