Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOpenGLCanvasRenderer Class Reference

#include <KisOpenGLCanvasRenderer.h>

+ Inheritance diagram for KisOpenGLCanvasRenderer:

Classes

class  CanvasBridge
 
struct  Private
 

Public Member Functions

void channelSelectionChanged (const QBitArray &channelFlags)
 
void finishResizingImage (qint32 w, qint32 h)
 
void initializeGL ()
 
 KisOpenGLCanvasRenderer (CanvasBridge *canvasBridge, KisImageWSP image, const KisDisplayConfig &displayConfig, QSharedPointer< KisDisplayFilter > displayFilter)
 
void notifyImageColorSpaceChanged (const KoColorSpace *cs)
 
KisOpenGLImageTexturesSP openGLImageTextures () const
 
void paintCanvasOnly (const QRect &canvasImageDirtyRect, const QRect &viewportUpdateRect=QRect())
 
void paintToolOutline (const KisOptimizedBrushOutline &path, const QRect &viewportUpdateRect, const int thickness=1)
 
void resizeGL (int width, int height)
 
void setDisplayConfig (const KisDisplayConfig &config)
 
void setDisplayFilter (QSharedPointer< KisDisplayFilter > displayFilter)
 
void setLodResetInProgress (bool value)
 
void setWrapAroundViewingMode (bool value)
 
void setWrapAroundViewingModeAxis (WrapAroundAxis value)
 
KisUpdateInfoSP startUpdateCanvasProjection (const QRect &rc)
 
QRect updateCanvasProjection (KisUpdateInfoSP info)
 
void updateConfig ()
 
void updateCursorColor ()
 
void updatePixelGridMode ()
 
bool wrapAroundViewingMode () const
 
WrapAroundAxis wrapAroundViewingModeAxis () const
 
 ~KisOpenGLCanvasRenderer ()
 

Private Member Functions

QColor borderColor () const
 
KisCanvas2canvas () const
 
QColor colorToDisplaySpace (const QColor &c)
 
QOpenGLContext * context () const
 
KisCoordinatesConvertercoordinatesConverter () const
 
qreal devicePixelRatioF () const
 
void drawBackground (const QRect &updateRect)
 
void drawCheckers (const QRect &updateRect)
 
void drawGrid (const QRect &updateRect)
 
void drawImage (const QRect &updateRect)
 
void drawImageTiles (int firstCol, int lastCol, int firstRow, int lastRow, qreal scaleX, qreal scaleY, const QPoint &wrapAroundOffset)
 
void initializeDisplayShader ()
 
void initializeShaders ()
 
void renderCanvasGL (const QRect &updateRect)
 
void reportFailedShaderCompilation (const QString &context)
 
void setDisplayFilterImpl (QSharedPointer< KisDisplayFilter > displayFilter, bool initializing)
 
QRectF surfaceToWidget (const QRectF &rc)
 
QRectF widgetToSurface (const QRectF &rc)
 

Private Attributes

Private *const d
 

Detailed Description

KisOpenGLCanvasRenderer is the class that shows the actual image using OpenGL

Definition at line 43 of file KisOpenGLCanvasRenderer.h.

Constructor & Destructor Documentation

◆ KisOpenGLCanvasRenderer()

KisOpenGLCanvasRenderer::KisOpenGLCanvasRenderer ( CanvasBridge * canvasBridge,
KisImageWSP image,
const KisDisplayConfig & displayConfig,
QSharedPointer< KisDisplayFilter > displayFilter )

Definition at line 144 of file KisOpenGLCanvasRenderer.cpp.

148 : d(new Private())
149{
150 d->canvasBridge = canvasBridge;
151
152 const KisDisplayConfig &config = displayConfig;
153
156 config.profile,
157 config.intent,
158 config.conversionFlags);
159
160
161 setDisplayFilterImpl(displayFilter, true);
162}
KisDisplayConfig This class keeps track of the color management configuration for image to display....
KoColorConversionTransformation::ConversionFlags conversionFlags
const KoColorProfile * profile
KoColorConversionTransformation::Intent intent
void setDisplayFilterImpl(QSharedPointer< KisDisplayFilter > displayFilter, bool initializing)
static KisOpenGLImageTexturesSP createImageTextures(KisImageWSP image, const KoColorProfile *monitorProfile, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)

References KisOpenGLCanvasRenderer::Private::canvasBridge, KisDisplayConfig::conversionFlags, KisOpenGLImageTextures::createImageTextures(), d, KisDisplayConfig::intent, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisDisplayConfig::profile, and setDisplayFilterImpl().

◆ ~KisOpenGLCanvasRenderer()

KisOpenGLCanvasRenderer::~KisOpenGLCanvasRenderer ( )

Definition at line 164 of file KisOpenGLCanvasRenderer.cpp.

165{
166 delete d;
167}

References d.

Member Function Documentation

◆ borderColor()

QColor KisOpenGLCanvasRenderer::borderColor ( ) const
private

◆ canvas()

KisCanvas2 * KisOpenGLCanvasRenderer::canvas ( ) const
private

◆ channelSelectionChanged()

void KisOpenGLCanvasRenderer::channelSelectionChanged ( const QBitArray & channelFlags)

◆ colorToDisplaySpace()

QColor KisOpenGLCanvasRenderer::colorToDisplaySpace ( const QColor & c)
private

Definition at line 1086 of file KisOpenGLCanvasRenderer.cpp.

1086 {
1087 KoColor convertedColor = KoColor(c, KoColorSpaceRegistry::instance()->rgb8());
1090}
KoColorDisplayRendererInterface * displayRendererInterface() const override
displayRendererInterface The display renderer interface has a number of color conversion functions wh...
KisOpenGLUpdateInfoBuilder & updateInfoBuilder()
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const =0
convertColorToDisplayColorSpace
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
const KoColorSpace * destinationColorSpace() const
static KoColorSpaceRegistry * instance()

References canvas(), KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), d, KisOpenGLUpdateInfoBuilder::destinationColorSpace(), KisCanvas2::displayRendererInterface(), KoColorSpaceRegistry::instance(), KisOpenGLCanvasRenderer::Private::openGLImageTextures, KoColor::toQColor(), and KisOpenGLImageTextures::updateInfoBuilder().

◆ context()

QOpenGLContext * KisOpenGLCanvasRenderer::context ( ) const
private

◆ coordinatesConverter()

KisCoordinatesConverter * KisOpenGLCanvasRenderer::coordinatesConverter ( ) const
private

◆ devicePixelRatioF()

qreal KisOpenGLCanvasRenderer::devicePixelRatioF ( ) const
private

◆ drawBackground()

void KisOpenGLCanvasRenderer::drawBackground ( const QRect & updateRect)
private

Definition at line 589 of file KisOpenGLCanvasRenderer.cpp.

590{
591 Q_UNUSED(updateRect);
592
593 // Draw the border (that is, clear the whole widget to the border color)
594
595 QColor bgColor = colorToDisplaySpace(borderColor());
596 glClearColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF(), 1.0);
597 glClear(GL_COLOR_BUFFER_BIT);
598}
QColor colorToDisplaySpace(const QColor &c)

References borderColor(), and colorToDisplaySpace().

◆ drawCheckers()

void KisOpenGLCanvasRenderer::drawCheckers ( const QRect & updateRect)
private

Definition at line 600 of file KisOpenGLCanvasRenderer.cpp.

601{
602 Q_UNUSED(updateRect);
603
604 if (!d->checkerShader) {
605 return;
606 }
607
609 QTransform textureTransform;
610 QTransform modelTransform;
611 QRectF textureRect;
612 QRectF modelRect;
613
614 const QSizeF &widgetSize = d->pixelAlignedWidgetSize;
615 QRectF viewportRect;
616 if (!d->wrapAroundMode) {
617 viewportRect = converter->imageRectInViewportPixels();
618 }
619 else {
620 const QRectF ir = converter->imageRectInViewportPixels();
621 viewportRect = converter->widgetToViewport(QRectF(0, 0, widgetSize.width(), widgetSize.height()));
623 viewportRect.setTop(ir.top());
624 viewportRect.setBottom(ir.bottom());
625 }
627 viewportRect.setLeft(ir.left());
628 viewportRect.setRight(ir.right());
629 }
630 }
631
632 // TODO: check if it works correctly
633 if (!canvas()->renderingLimit().isEmpty()) {
634 const QRect vrect = converter->imageToViewport(canvas()->renderingLimit()).toAlignedRect();
635 viewportRect &= vrect;
636 }
637
638 converter->getOpenGLCheckersInfo(viewportRect,
639 &textureTransform, &modelTransform, &textureRect, &modelRect, d->scrollCheckers);
640
641 textureTransform *= QTransform::fromScale(d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE,
643
644 if (!d->checkerShader->bind()) {
645 qWarning() << "Could not bind checker shader";
646 return;
647 }
648
649 QMatrix4x4 projectionMatrix;
650 projectionMatrix.setToIdentity();
651 // FIXME: It may be better to have the projection in device pixel, but
652 // this requires introducing a new coordinate system.
653 projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL);
654
655 // Set view/projection matrices
656 QMatrix4x4 modelMatrix(modelTransform);
657 modelMatrix.optimize();
658 modelMatrix = projectionMatrix * modelMatrix;
659 d->checkerShader->setUniformValue(d->checkerShader->location(Uniform::ModelViewProjection), modelMatrix);
660
661 QMatrix4x4 textureMatrix(textureTransform);
662 d->checkerShader->setUniformValue(d->checkerShader->location(Uniform::TextureMatrix), textureMatrix);
663
664 //Setup the geometry for rendering
667 QOpenGLBuffer *vertexBuf = d->checkersVertexBuffer.getNextBuffer();
668
669 vertexBuf->bind();
670 vertexBuf->write(0, d->vertices, 3 * 6 * sizeof(float));
671 glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, 0);
672
673
675 QOpenGLBuffer *vertexTextureBuf = d->checkersTextureVertexBuffer.getNextBuffer();
676
677 vertexTextureBuf->bind();
678 vertexTextureBuf->write(0, d->texCoords, 2 * 6 * sizeof(float));
679 glVertexAttribPointer(PROGRAM_TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, 0);
680 }
681 else {
683 d->checkerShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
684 d->checkerShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->vertices);
685
687 d->checkerShader->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
689 }
690
691 // render checkers
692 glActiveTexture(GL_TEXTURE0);
693 glBindTexture(GL_TEXTURE_2D, d->openGLImageTextures->checkerTexture());
694
695 glDrawArrays(GL_TRIANGLES, 0, 6);
696
697 glBindTexture(GL_TEXTURE_2D, 0);
698 d->checkerShader->release();
699 glBindBuffer(GL_ARRAY_BUFFER, 0);
700}
#define NEAR_VAL
#define FAR_VAL
@ WRAPAROUND_HORIZONTAL
@ WRAPAROUND_VERTICAL
_Private::Traits< T >::Result widgetToViewport(const T &obj) const
void getOpenGLCheckersInfo(const QRectF &viewportRect, QTransform *textureTransform, QTransform *modelTransform, QRectF *textureRect, QRectF *modelRect, const bool scrollCheckers) const
_Private::Traits< T >::Result imageToViewport(const T &obj) const
KisCoordinatesConverter * coordinatesConverter() const
static bool supportsVAO()
int location(Uniform uniform)
#define PROGRAM_TEXCOORD_ATTRIBUTE
#define PROGRAM_VERTEX_ATTRIBUTE
@ ModelViewProjection
void rectToTexCoords(QVector2D *texCoords, const QRectF &rc)
void rectToVertices(QVector3D *vertices, const QRectF &rc)
KisOpenGLBufferCircularStorage checkersVertexBuffer
KisOpenGLBufferCircularStorage checkersTextureVertexBuffer

References KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE, canvas(), KisOpenGLCanvasRenderer::Private::checkerShader, KisOpenGLCanvasRenderer::Private::checkersTextureVertexBuffer, KisOpenGLCanvasRenderer::Private::checkersVertexBuffer, KisOpenGLImageTextures::checkerTexture(), KisOpenGLCanvasRenderer::Private::checkSizeScale, coordinatesConverter(), d, FAR_VAL, KisOpenGLBufferCircularStorage::getNextBuffer(), KisCoordinatesConverter::getOpenGLCheckersInfo(), KisCoordinatesConverter::imageRectInViewportPixels(), KisCoordinatesConverter::imageToViewport(), KisShaderProgram::location(), ModelViewProjection, NEAR_VAL, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, PROGRAM_TEXCOORD_ATTRIBUTE, PROGRAM_VERTEX_ATTRIBUTE, KisPaintingTweaks::rectToTexCoords(), KisPaintingTweaks::rectToVertices(), KisOpenGLCanvasRenderer::Private::scrollCheckers, KisOpenGL::supportsVAO(), KisOpenGLCanvasRenderer::Private::texCoords, TextureMatrix, KisOpenGLCanvasRenderer::Private::vertices, KisCoordinatesConverter::widgetToViewport(), WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, KisOpenGLCanvasRenderer::Private::wrapAroundMode, and KisOpenGLCanvasRenderer::Private::wrapAroundModeAxis.

◆ drawGrid()

void KisOpenGLCanvasRenderer::drawGrid ( const QRect & updateRect)
private

Definition at line 702 of file KisOpenGLCanvasRenderer.cpp.

703{
704 if (!d->solidColorShader->bind()) {
705 return;
706 }
707
708 const QSizeF &widgetSize = d->pixelAlignedWidgetSize;
709
710 QMatrix4x4 projectionMatrix;
711 projectionMatrix.setToIdentity();
712 // FIXME: It may be better to have the projection in device pixel, but
713 // this requires introducing a new coordinate system.
714 projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL);
715
716 // Set view/projection matrices
717 QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform());
718 modelMatrix.optimize();
719 modelMatrix = projectionMatrix * modelMatrix;
721
722 glEnable(GL_BLEND);
723 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
724
725 d->solidColorShader->setUniformValue(
727 QVector4D(d->gridColor.redF(), d->gridColor.greenF(), d->gridColor.blueF(), 0.5f));
728
729 QRectF widgetRect(0,0, widgetSize.width(), widgetSize.height());
730 QRectF widgetRectInImagePixels = coordinatesConverter()->documentToImage(coordinatesConverter()->widgetToDocument(widgetRect));
731 QRect wr = widgetRectInImagePixels.toAlignedRect();
732
733 if (!d->wrapAroundMode) {
735 }
736
737 if (!updateRect.isEmpty()) {
738 const QRect updateRectInImagePixels = coordinatesConverter()->widgetToImage(updateRect).toAlignedRect();
739 wr &= updateRectInImagePixels;
740 }
741
742 QPoint topLeftCorner = wr.topLeft();
743 QPoint bottomRightCorner = wr.bottomRight() + QPoint(1, 1);
745
746 for (int i = topLeftCorner.x(); i <= bottomRightCorner.x(); ++i) {
747 grid.append(QVector3D(i, topLeftCorner.y(), 0));
748 grid.append(QVector3D(i, bottomRightCorner.y(), 0));
749 }
750 for (int i = topLeftCorner.y(); i <= bottomRightCorner.y(); ++i) {
751 grid.append(QVector3D(topLeftCorner.x(), i, 0));
752 grid.append(QVector3D(bottomRightCorner.x(), i, 0));
753 }
754
756 d->outlineVAO.bind();
757 d->lineVertexBuffer.bind();
758 d->lineVertexBuffer.allocate(grid.constData(), 3 * grid.size() * sizeof(float));
759 }
760 else {
761 d->solidColorShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
762 d->solidColorShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, grid.constData());
763 }
764
765 glDrawArrays(GL_LINES, 0, grid.size());
766
768 d->lineVertexBuffer.release();
769 d->outlineVAO.release();
770 }
771
772 d->solidColorShader->release();
773 glDisable(GL_BLEND);
774}
_Private::Traits< T >::Result widgetToImage(const T &obj) const
_Private::Traits< T >::Result documentToImage(const T &obj) const

References coordinatesConverter(), d, KisCoordinatesConverter::documentToImage(), FAR_VAL, FragmentColor, KisOpenGLCanvasRenderer::Private::gridColor, KisOpenGLCanvasRenderer::Private::lineVertexBuffer, KisShaderProgram::location(), ModelViewProjection, NEAR_VAL, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLCanvasRenderer::Private::outlineVAO, KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, PROGRAM_VERTEX_ATTRIBUTE, KisOpenGLCanvasRenderer::Private::solidColorShader, KisOpenGLImageTextures::storedImageBounds(), KisOpenGL::supportsVAO(), KisCoordinatesConverter::widgetToImage(), and KisOpenGLCanvasRenderer::Private::wrapAroundMode.

◆ drawImage()

void KisOpenGLCanvasRenderer::drawImage ( const QRect & updateRect)
private

Definition at line 776 of file KisOpenGLCanvasRenderer.cpp.

777{
778 if (!d->displayShader) {
779 return;
780 }
781
782 glEnable(GL_BLEND);
783 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
784
786
787 d->displayShader->bind();
788
789 const QSizeF &widgetSize = d->pixelAlignedWidgetSize;
790
791 QMatrix4x4 textureMatrix;
792 textureMatrix.setToIdentity();
793 d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix);
794
795 QRectF widgetRect(0,0, widgetSize.width(), widgetSize.height());
796
797 if (!updateRect.isEmpty()) {
798 widgetRect &= updateRect;
799 }
800
801 QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect));
802
803 const QRect renderingLimit = canvas()->renderingLimit();
804
805 if (!renderingLimit.isEmpty()) {
806 widgetRectInImagePixels &= renderingLimit;
807 }
808
809 qreal scaleX, scaleY;
810 converter->imagePhysicalScale(&scaleX, &scaleY);
811
812 d->displayShader->setUniformValue(d->displayShader->location(Uniform::ViewportScale), (GLfloat) scaleX);
814
816 QRect wr = widgetRectInImagePixels.toAlignedRect();
817
818 if (!d->wrapAroundMode) {
819 // if we don't want to paint wrapping images, just limit the
820 // processing area, and the code will handle all the rest
821 wr &= ir;
822 }
824 wr.setTop(ir.top());
825 wr.setBottom(ir.bottom());
826 }
828 wr.setLeft(ir.left());
829 wr.setRight(ir.right());
830 }
831
832 const int firstColumn = d->xToColWithWrapCompensation(wr.left(), ir);
833 const int lastColumn = d->xToColWithWrapCompensation(wr.right(), ir);
834 const int firstRow = d->yToRowWithWrapCompensation(wr.top(), ir);
835 const int lastRow = d->yToRowWithWrapCompensation(wr.bottom(), ir);
836
837 const int minColumn = d->openGLImageTextures->xToCol(ir.left());
838 const int maxColumn = d->openGLImageTextures->xToCol(ir.right());
839 const int minRow = d->openGLImageTextures->yToRow(ir.top());
840 const int maxRow = d->openGLImageTextures->yToRow(ir.bottom());
841
842 const int imageColumns = maxColumn - minColumn + 1;
843 const int imageRows = maxRow - minRow + 1;
844
845 if (d->displayFilter) {
846 d->displayFilter->setupTextures(this, d->displayShader);
847 }
848
849 const int firstCloneX = qFloor(qreal(firstColumn) / imageColumns);
850 const int lastCloneX = qFloor(qreal(lastColumn) / imageColumns);
851 const int firstCloneY = qFloor(qreal(firstRow) / imageRows);
852 const int lastCloneY = qFloor(qreal(lastRow) / imageRows);
853
854 for (int cloneY = firstCloneY; cloneY <= lastCloneY; cloneY++) {
855 for (int cloneX = firstCloneX; cloneX <= lastCloneX; cloneX++) {
856
857 const int localFirstCol = cloneX == firstCloneX ? KisAlgebra2D::wrapValue(firstColumn, imageColumns) : 0;
858 const int localLastCol = cloneX == lastCloneX ? KisAlgebra2D::wrapValue(lastColumn, imageColumns) : imageColumns - 1;
859
860 const int localFirstRow = cloneY == firstCloneY ? KisAlgebra2D::wrapValue(firstRow, imageRows) : 0;
861 const int localLastRow = cloneY == lastCloneY ? KisAlgebra2D::wrapValue(lastRow, imageRows) : imageRows - 1;
862
863 drawImageTiles(localFirstCol, localLastCol,
864 localFirstRow, localLastRow,
865 scaleX, scaleY, QPoint(cloneX, cloneY));
866 }
867 }
868
869 d->displayShader->release();
870
871 glDisable(GL_BLEND);
872}
QRect renderingLimit
_Private::Traits< T >::Result widgetToDocument(const T &obj) const
void imagePhysicalScale(qreal *scaleX, qreal *scaleY) const
void drawImageTiles(int firstCol, int lastCol, int firstRow, int lastRow, qreal scaleX, qreal scaleY, const QPoint &wrapAroundOffset)
T wrapValue(T value, T wrapBounds)
int yToRowWithWrapCompensation(int y, const QRect &imageRect)
int xToColWithWrapCompensation(int x, const QRect &imageRect)
QSharedPointer< KisDisplayFilter > displayFilter

References canvas(), coordinatesConverter(), d, KisOpenGLCanvasRenderer::Private::displayFilter, KisOpenGLCanvasRenderer::Private::displayShader, KisCoordinatesConverter::documentToImage(), drawImageTiles(), KisCoordinatesConverter::imagePhysicalScale(), KisShaderProgram::location(), KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, KisCanvas2::renderingLimit, KisOpenGLImageTextures::storedImageBounds(), KisOpenGLImageTextures::texelSize(), TexelSize, TextureMatrix, ViewportScale, KisCoordinatesConverter::widgetToDocument(), WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, KisOpenGLCanvasRenderer::Private::wrapAroundMode, KisOpenGLCanvasRenderer::Private::wrapAroundModeAxis, KisAlgebra2D::wrapValue(), KisOpenGLImageTextures::xToCol(), KisOpenGLCanvasRenderer::Private::xToColWithWrapCompensation(), KisOpenGLImageTextures::yToRow(), and KisOpenGLCanvasRenderer::Private::yToRowWithWrapCompensation().

◆ drawImageTiles()

void KisOpenGLCanvasRenderer::drawImageTiles ( int firstCol,
int lastCol,
int firstRow,
int lastRow,
qreal scaleX,
qreal scaleY,
const QPoint & wrapAroundOffset )
private

Definition at line 874 of file KisOpenGLCanvasRenderer.cpp.

875{
877 const QSizeF &widgetSize = d->pixelAlignedWidgetSize;
878
879 QMatrix4x4 projectionMatrix;
880 projectionMatrix.setToIdentity();
881 // FIXME: It may be better to have the projection in device pixel, but
882 // this requires introducing a new coordinate system.
883 projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL);
884
885 QTransform modelTransform = converter->imageToWidgetTransform();
886
887 if (!wrapAroundOffset.isNull()) {
888 const QRect ir = d->openGLImageTextures->storedImageBounds();
889
890 const QTransform wrapAroundTranslate = QTransform::fromTranslate(ir.width() * wrapAroundOffset.x(),
891 ir.height() * wrapAroundOffset.y());
892 modelTransform = wrapAroundTranslate * modelTransform;
893 }
894
895 // Set view/projection matrices
896 QMatrix4x4 modelMatrix(modelTransform);
897 modelMatrix.optimize();
898 modelMatrix = projectionMatrix * modelMatrix;
899 d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix);
900
901 int lastTileLodPlane = -1;
902
903 for (int col = firstCol; col <= lastCol; col++) {
904 for (int row = firstRow; row <= lastRow; row++) {
905
906 KisTextureTile *tile =
908
909 if (!tile) {
910 warnUI << "OpenGL: Trying to paint texture tile but it has not been created yet.";
911 continue;
912 }
913
914 //Setup the geometry for rendering
916 const int tileIndex = d->openGLImageTextures->getTextureBufferIndexCR(col, row);
917
918 const int vertexRectSize = 6 * 3 * sizeof(float);
920 glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<void*>(tileIndex * vertexRectSize));
921
922 const int textureRectSize = 6 * 2 * sizeof(float);
924 glVertexAttribPointer(PROGRAM_TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<void*>(tileIndex * textureRectSize));
925
926 } else {
927
928 const QRectF textureRect = tile->tileRectInTexturePixels();
929 const QRectF modelRect = tile->tileRectInImagePixels();
930
932 d->checkerShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
933 d->checkerShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->vertices);
934
936 d->checkerShader->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
938 }
939
940 glActiveTexture(GL_TEXTURE0);
941
942 // switching uniform is a rather expensive operation on macOS, so we change it only
943 // when it is really needed
944 const int currentLodPlane = tile->bindToActiveTexture(d->lodSwitchInProgress);
946 (lastTileLodPlane < 0 || lastTileLodPlane != currentLodPlane)) {
947
949 (GLfloat) currentLodPlane);
950 lastTileLodPlane = currentLodPlane;
951 }
952
953 if (currentLodPlane > 0) {
954 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
955 } else if (SCALE_MORE_OR_EQUAL_TO(scaleX, scaleY, 2.0)) {
956 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
957 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
958 } else {
959 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
960
961 switch(d->filterMode) {
963 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
964 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
965 break;
967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
968 break;
970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
971 break;
973 if (SCALE_LESS_THAN(scaleX, scaleY, 0.5)) {
974 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
975 } else {
976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
977 }
978 break;
979 }
980 }
981
982 glDrawArrays(GL_TRIANGLES, 0, 6);
983 }
984 }
985
986 glBindTexture(GL_TEXTURE_2D, 0);
987 glBindBuffer(GL_ARRAY_BUFFER, 0);
988}
int getTextureBufferIndexCR(int col, int row)
KisTextureTile * getTextureTileCR(int col, int row)
@ NearestFilterMode
Definition kis_opengl.h:34
@ HighQualityFiltering
Definition kis_opengl.h:37
@ BilinearFilterMode
Definition kis_opengl.h:35
@ TrilinearFilterMode
Definition kis_opengl.h:36
QRect tileRectInImagePixels()
QRectF tileRectInTexturePixels()
int bindToActiveTexture(bool blockMipmapRegeneration)
#define SCALE_LESS_THAN(scX, scY, value)
#define SCALE_MORE_OR_EQUAL_TO(scX, scY, value)
#define warnUI
Definition kis_debug.h:94

References KisOpenGL::BilinearFilterMode, KisTextureTile::bindToActiveTexture(), KisOpenGLCanvasRenderer::Private::checkerShader, coordinatesConverter(), d, KisOpenGLCanvasRenderer::Private::displayShader, FAR_VAL, KisOpenGLCanvasRenderer::Private::filterMode, FixedLodLevel, KisOpenGLImageTextures::getTextureBufferIndexCR(), KisOpenGLImageTextures::getTextureTileCR(), KisOpenGL::HighQualityFiltering, KisCoordinatesConverter::imageToWidgetTransform(), KisShaderProgram::location(), KisOpenGLCanvasRenderer::Private::lodSwitchInProgress, ModelViewProjection, NEAR_VAL, KisOpenGL::NearestFilterMode, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, PROGRAM_TEXCOORD_ATTRIBUTE, PROGRAM_VERTEX_ATTRIBUTE, KisPaintingTweaks::rectToTexCoords(), KisPaintingTweaks::rectToVertices(), SCALE_LESS_THAN, SCALE_MORE_OR_EQUAL_TO, KisOpenGLImageTextures::storedImageBounds(), KisOpenGL::supportsVAO(), KisOpenGLCanvasRenderer::Private::texCoords, KisTextureTile::tileRectInImagePixels(), KisTextureTile::tileRectInTexturePixels(), KisOpenGLImageTextures::tileTexCoordBuffer(), KisOpenGLImageTextures::tileVertexBuffer(), KisOpenGL::TrilinearFilterMode, KisOpenGLCanvasRenderer::Private::vertices, and warnUI.

◆ finishResizingImage()

◆ initializeDisplayShader()

void KisOpenGLCanvasRenderer::initializeDisplayShader ( )
private

Definition at line 308 of file KisOpenGLCanvasRenderer.cpp.

309{
311
312 bool useHiQualityFiltering = d->filterMode == KisOpenGL::HighQualityFiltering;
313
314 delete d->displayShader;
315 d->displayShader = 0;
316
317 try {
318 d->displayShader = d->shaderLoader.loadDisplayShader(d->displayFilter, useHiQualityFiltering);
320 } catch (const ShaderLoaderException &e) {
322 }
323}
void reportFailedShaderCompilation(const QString &context)
KisShaderProgram * loadDisplayShader(QSharedPointer< KisDisplayFilter > displayFilter, bool useHiQualityFiltering)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KisOpenGLCanvasRenderer::Private::canvasInitialized, d, KisOpenGLCanvasRenderer::Private::displayFilter, KisOpenGLCanvasRenderer::Private::displayShader, KisOpenGLCanvasRenderer::Private::displayShaderCompiledWithDisplayFilterSupport, KisOpenGLCanvasRenderer::Private::filterMode, KisOpenGL::HighQualityFiltering, KIS_SAFE_ASSERT_RECOVER_RETURN, KisOpenGLShaderLoader::loadDisplayShader(), reportFailedShaderCompilation(), and KisOpenGLCanvasRenderer::Private::shaderLoader.

◆ initializeGL()

void KisOpenGLCanvasRenderer::initializeGL ( )

Definition at line 246 of file KisOpenGLCanvasRenderer.cpp.

247{
249 initializeOpenGLFunctions();
250
251 KisConfig cfg(true);
252 d->openGLImageTextures->setProofingConfig(canvas()->proofingConfiguration());
253 d->openGLImageTextures->initGL(context()->functions());
255
257
258 // If we support OpenGL 3.0, then prepare our VAOs and VBOs for drawing
260 d->quadVAO.create();
261 d->quadVAO.bind();
262
263 glEnableVertexAttribArray(PROGRAM_VERTEX_ATTRIBUTE);
264 glEnableVertexAttribArray(PROGRAM_TEXCOORD_ATTRIBUTE);
265
266 d->checkersVertexBuffer.allocate(NumberOfBuffers, 6 * 3 * sizeof(float));
267 d->checkersTextureVertexBuffer.allocate(NumberOfBuffers, 6 * 2 * sizeof(float));
268
269 // Create the outline buffer, this buffer will store the outlines of
270 // tools and will frequently change data
271 d->outlineVAO.create();
272 d->outlineVAO.bind();
273
274 glEnableVertexAttribArray(PROGRAM_VERTEX_ATTRIBUTE);
275
276 // The outline buffer has a StreamDraw usage pattern, because it changes constantly
277 d->lineVertexBuffer.create();
278 d->lineVertexBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
279 d->lineVertexBuffer.bind();
280 glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, 0);
281 }
282
283 d->canvasInitialized = true;
284}
static constexpr int NumberOfBuffers
static QImage createCheckersImage(qint32 checkSize=-1)
QOpenGLContext * context() const
void generateCheckerTexture(const QImage &checkImage)
void initGL(QOpenGLFunctions *f)
void setProofingConfig(KisProofingConfigurationSP)
static void initializeContext(QOpenGLContext *ctx)
Initialize shared OpenGL context.
void allocate(int numBuffers, int bufferSize)

References KisOpenGLBufferCircularStorage::allocate(), canvas(), KisOpenGLCanvasRenderer::Private::canvasInitialized, KisOpenGLCanvasRenderer::Private::checkersTextureVertexBuffer, KisOpenGLCanvasRenderer::Private::checkersVertexBuffer, KisConfig::checkSize(), context(), KisCanvasWidgetBase::createCheckersImage(), d, KisOpenGLImageTextures::generateCheckerTexture(), KisOpenGLImageTextures::initGL(), KisOpenGL::initializeContext(), initializeShaders(), KisOpenGLCanvasRenderer::Private::lineVertexBuffer, NumberOfBuffers, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLCanvasRenderer::Private::outlineVAO, PROGRAM_TEXCOORD_ATTRIBUTE, PROGRAM_VERTEX_ATTRIBUTE, KisOpenGLCanvasRenderer::Private::quadVAO, KisOpenGLImageTextures::setProofingConfig(), and KisOpenGL::supportsVAO().

◆ initializeShaders()

◆ notifyImageColorSpaceChanged()

void KisOpenGLCanvasRenderer::notifyImageColorSpaceChanged ( const KoColorSpace * cs)

Definition at line 216 of file KisOpenGLCanvasRenderer.cpp.

217{
218 // FIXME: on color space change the data is refetched multiple
219 // times by different actors!
220
222 canvas()->startUpdateInPatches(canvas()->image()->bounds());
223 }
224}
void startUpdateInPatches(const QRect &imageRect)
bool setImageColorSpace(const KoColorSpace *cs)
#define bounds(x, a, b)

References bounds, canvas(), d, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLImageTextures::setImageColorSpace(), and KisCanvas2::startUpdateInPatches().

◆ openGLImageTextures()

KisOpenGLImageTexturesSP KisOpenGLCanvasRenderer::openGLImageTextures ( ) const

Definition at line 1135 of file KisOpenGLCanvasRenderer.cpp.

1136{
1137 return d->openGLImageTextures;
1138}

References d, and KisOpenGLCanvasRenderer::Private::openGLImageTextures.

◆ paintCanvasOnly()

void KisOpenGLCanvasRenderer::paintCanvasOnly ( const QRect & canvasImageDirtyRect,
const QRect & viewportUpdateRect = QRect() )

Paint only the canvas background and image tiles.

Definition at line 371 of file KisOpenGLCanvasRenderer.cpp.

372{
373 if (d->canvasFBO) {
374 if (!canvasImageDirtyRect.isEmpty()) {
375 d->canvasFBO->bind();
376 renderCanvasGL(canvasImageDirtyRect);
377 d->canvasFBO->release();
378 }
379 QRect blitRect;
380 if (viewportUpdateRect.isEmpty()) {
381 blitRect = QRect(QPoint(), d->viewportDevicePixelSize);
382 } else {
383 const QTransform scale = QTransform::fromScale(1.0, -1.0) * QTransform::fromTranslate(0, d->pixelAlignedWidgetSize.height()) * QTransform::fromScale(devicePixelRatioF(), devicePixelRatioF());
384 blitRect = scale.mapRect(QRectF(viewportUpdateRect)).toAlignedRect();
385 }
386 QOpenGLFramebufferObject::blitFramebuffer(nullptr, blitRect, d->canvasFBO.data(), blitRect, GL_COLOR_BUFFER_BIT, GL_NEAREST);
387 QOpenGLFramebufferObject::bindDefault();
388 } else {
389 QRect fullUpdateRect = canvasImageDirtyRect | viewportUpdateRect;
390 if (fullUpdateRect.isEmpty()) {
391 fullUpdateRect = QRect(QPoint(), d->viewportDevicePixelSize);
392 }
393 renderCanvasGL(fullUpdateRect);
394 }
395}
void renderCanvasGL(const QRect &updateRect)
QScopedPointer< QOpenGLFramebufferObject > canvasFBO

References KisOpenGLCanvasRenderer::Private::canvasFBO, d, devicePixelRatioF(), KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, renderCanvasGL(), and KisOpenGLCanvasRenderer::Private::viewportDevicePixelSize.

◆ paintToolOutline()

void KisOpenGLCanvasRenderer::paintToolOutline ( const KisOptimizedBrushOutline & path,
const QRect & viewportUpdateRect,
const int thickness = 1 )

Definition at line 397 of file KisOpenGLCanvasRenderer.cpp.

398{
399 if (!d->solidColorShader->bind()) {
400 return;
401 }
402
403 const QSizeF &widgetSize = d->pixelAlignedWidgetSize;
404
405 // setup the mvp transformation
406 QMatrix4x4 projectionMatrix;
407 projectionMatrix.setToIdentity();
408 // FIXME: It may be better to have the projection in device pixel, but
409 // this requires introducing a new coordinate system.
410 projectionMatrix.ortho(0, widgetSize.width(), widgetSize.height(), 0, NEAR_VAL, FAR_VAL);
411
412 // Set view/projection matrices
413 QMatrix4x4 modelMatrix(coordinatesConverter()->flakeToWidgetTransform());
414 modelMatrix.optimize();
415 modelMatrix = projectionMatrix * modelMatrix;
417
418 d->solidColorShader->setUniformValue(
420 QVector4D(d->cursorColor.redF(), d->cursorColor.greenF(), d->cursorColor.blueF(), 1.0f));
421
422 glEnable(GL_BLEND);
423 glBlendFuncSeparate(GL_ONE, GL_SRC_COLOR, GL_ONE, GL_ONE);
424 glBlendEquationSeparate(GL_FUNC_SUBTRACT, GL_FUNC_ADD);
425
426
427 if (!viewportUpdateRect.isEmpty()) {
428 const QRect deviceUpdateRect = widgetToSurface(viewportUpdateRect).toAlignedRect();
429 glScissor(deviceUpdateRect.x(), deviceUpdateRect.y(), deviceUpdateRect.width(), deviceUpdateRect.height());
430 glEnable(GL_SCISSOR_TEST);
431 }
432
433 // Paint the tool outline
435 d->outlineVAO.bind();
436 d->lineVertexBuffer.bind();
437 }
438
439
440 if (thickness > 1) {
441 // Because glLineWidth is not supported on all versions of OpenGL (or rather,
442 // is limited to 1, as returned by GL_ALIASED_LINE_WIDTH_RANGE),
443 // we'll instead generate mitered-triangles.
444
445 const qreal halfWidth = (thickness * 0.5) / devicePixelRatioF();
446 const qreal miterLimit = (5 * thickness) / devicePixelRatioF();
447
448 for (auto it = path.begin(); it != path.end(); ++it) {
449 const QPolygonF& polygon = *it;
450
451 if (KisAlgebra2D::maxDimension(polygon.boundingRect()) < 0.5 * thickness) {
452 continue;
453 }
454
455 int triangleCount = 0;
457 d->lineVerticesStagingBuffer.reserve((polygon.count() - 1) * 6);
458 const bool closed = polygon.isClosed();
459
460 for( int i = 1; i < polygon.count(); i++) {
461 bool adjustFirst = closed? true: i > 1;
462 bool adjustSecond = closed? true: i + 1 < polygon.count();
463
464 QPointF p1 = polygon.at(i - 1);
465 QPointF p2 = polygon.at(i);
466 QPointF normal = p2 - p1;
467 normal = KisAlgebra2D::normalize(QPointF(-normal.y(), normal.x()));
468
469 QPointF c1 = p1 - (normal * halfWidth);
470 QPointF c2 = p1 + (normal * halfWidth);
471 QPointF c3 = p2 - (normal * halfWidth);
472 QPointF c4 = p2 + (normal * halfWidth);
473
474 // Add miter
475 if (adjustFirst) {
476 QPointF pPrev = i >= 2 ?
477 QPointF(polygon.at(i-2)) :
478 QPointF(polygon.at(qMax(polygon.count() - 2, 0)));
479
480 pPrev = p1 - pPrev;
481
482 QPointF miter =
485 QPointF(-pPrev.y(), pPrev.x())));
486
487 const qreal dot = KisAlgebra2D::dotProduct(miter, normal);
488
489 const qreal dotMulti = dot != 0? 1.0/dot: 0.0;
490
491 if (KisAlgebra2D::norm((miter * halfWidth) * dotMulti) < miterLimit) {
492 c1 = p1 + ((miter * -halfWidth) * dotMulti);
493 c2 = p1 + ((miter * halfWidth) * dotMulti);
494 }
495 }
496
497 if (adjustSecond) {
498 QPointF pNext = i + 1 < polygon.count()? QPointF(polygon.at(i+1))
499 : QPointF(polygon.at(qMin(polygon.count(), 1)));
500 pNext = pNext - p2;
501 QPointF miter =
503 normal + KisAlgebra2D::normalize(QPointF(-pNext.y(), pNext.x())));
504 const qreal dot = KisAlgebra2D::dotProduct(miter, normal);
505 const qreal dotMulti = dot != 0? 1.0/dot: 0.0;
506
507 if (KisAlgebra2D::norm((miter * halfWidth) * dotMulti) < miterLimit) {
508 c3 = p2 + ((miter * -halfWidth) * dotMulti);
509 c4 = p2 + (miter * halfWidth) * dotMulti;
510 }
511 }
512
513 d->lineVerticesStagingBuffer.append(QVector3D(c1));
514 d->lineVerticesStagingBuffer.append(QVector3D(c3));
515 d->lineVerticesStagingBuffer.append(QVector3D(c2));
516 d->lineVerticesStagingBuffer.append(QVector3D(c4));
517 d->lineVerticesStagingBuffer.append(QVector3D(c2));
518 d->lineVerticesStagingBuffer.append(QVector3D(c3));
519 triangleCount += 2;
520 }
521
523 d->lineVertexBuffer.bind();
524 d->lineVertexBuffer.allocate(d->lineVerticesStagingBuffer.constData(), 3 * d->lineVerticesStagingBuffer.size() * sizeof(float));
525 }
526 else {
527 d->solidColorShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
528 d->solidColorShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->lineVerticesStagingBuffer.constData());
529 }
530
531 glDrawArrays(GL_TRIANGLES, 0, triangleCount * 3);
532 }
533 } else {
534 // Convert every disjointed subpath to a polygon and draw that polygon
535 for (auto it = path.begin(); it != path.end(); ++it) {
536 const QPolygonF& polygon = *it;
537
538 if (KisAlgebra2D::maxDimension(polygon.boundingRect()) < 0.5) {
539 continue;
540 }
541
542 const int verticesCount = polygon.count();
543
544 if (d->lineVerticesStagingBuffer.size() < verticesCount) {
545 d->lineVerticesStagingBuffer.resize(verticesCount);
546 }
547
548 for (int vertIndex = 0; vertIndex < verticesCount; vertIndex++) {
549 QPointF point = polygon.at(vertIndex);
550 d->lineVerticesStagingBuffer[vertIndex].setX(point.x());
551 d->lineVerticesStagingBuffer[vertIndex].setY(point.y());
552 }
554 d->lineVertexBuffer.bind();
555 d->lineVertexBuffer.allocate(d->lineVerticesStagingBuffer.constData(), 3 * verticesCount * sizeof(float));
556 }
557 else {
558 d->solidColorShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
559 d->solidColorShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->lineVerticesStagingBuffer.constData());
560 }
561
562
563
564 glDrawArrays(GL_LINE_STRIP, 0, verticesCount);
565 }
566 }
567
569 d->lineVertexBuffer.release();
570 d->outlineVAO.release();
571 }
572
573 if (!viewportUpdateRect.isEmpty()) {
574 glDisable(GL_SCISSOR_TEST);
575 }
576
577 glBlendEquation(GL_FUNC_ADD);
578 glBlendFunc(GL_ONE, GL_ZERO);
579 glDisable(GL_BLEND);
580
581 d->solidColorShader->release();
582}
QPointF p2
QPointF p1
QRectF widgetToSurface(const QRectF &rc)
auto maxDimension(Size size) -> decltype(size.width())
Point normalize(const Point &a)
qreal norm(const T &a)
PointTypeTraits< T >::value_type dotProduct(const T &a, const T &b)

References coordinatesConverter(), KisOpenGLCanvasRenderer::Private::cursorColor, d, devicePixelRatioF(), KisAlgebra2D::dotProduct(), FAR_VAL, FragmentColor, KisOpenGLCanvasRenderer::Private::lineVertexBuffer, KisOpenGLCanvasRenderer::Private::lineVerticesStagingBuffer, KisShaderProgram::location(), KisAlgebra2D::maxDimension(), ModelViewProjection, NEAR_VAL, KisAlgebra2D::norm(), KisAlgebra2D::normalize(), KisOpenGLCanvasRenderer::Private::outlineVAO, p1, p2, KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, PROGRAM_VERTEX_ATTRIBUTE, KisOpenGLCanvasRenderer::Private::solidColorShader, KisOpenGL::supportsVAO(), and widgetToSurface().

◆ renderCanvasGL()

void KisOpenGLCanvasRenderer::renderCanvasGL ( const QRect & updateRect)
private

Definition at line 1043 of file KisOpenGLCanvasRenderer.cpp.

1044{
1045 if ((d->displayFilter && d->displayFilter->updateShader()) ||
1047
1049
1050 d->canvasInitialized = false; // TODO: check if actually needed?
1052 d->canvasInitialized = true;
1053 }
1054
1055 if (KisOpenGL::supportsVAO()) {
1056 d->quadVAO.bind();
1057 }
1058
1059 QRect alignedUpdateRect = updateRect;
1060
1061 if (!updateRect.isEmpty()) {
1062 const QRect deviceUpdateRect = widgetToSurface(updateRect).toAlignedRect();
1063 alignedUpdateRect = surfaceToWidget(deviceUpdateRect).toAlignedRect();
1064
1065 glScissor(deviceUpdateRect.x(), deviceUpdateRect.y(), deviceUpdateRect.width(), deviceUpdateRect.height());
1066 glEnable(GL_SCISSOR_TEST);
1067 }
1068
1069 drawBackground(alignedUpdateRect);
1070 drawCheckers(alignedUpdateRect);
1071 drawImage(alignedUpdateRect);
1072
1073 if ((coordinatesConverter()->effectivePhysicalZoom() > d->pixelGridDrawingThreshold - 0.00001) && d->pixelGridEnabled) {
1074 drawGrid(alignedUpdateRect);
1075 }
1076
1077 if (!updateRect.isEmpty()) {
1078 glDisable(GL_SCISSOR_TEST);
1079 }
1080
1081 if (KisOpenGL::supportsVAO()) {
1082 d->quadVAO.release();
1083 }
1084}
void drawImage(const QRect &updateRect)
void drawBackground(const QRect &updateRect)
QRectF surfaceToWidget(const QRectF &rc)
void drawGrid(const QRect &updateRect)
void drawCheckers(const QRect &updateRect)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisOpenGLCanvasRenderer::Private::canvasInitialized, coordinatesConverter(), d, KisOpenGLCanvasRenderer::Private::displayFilter, KisOpenGLCanvasRenderer::Private::displayShaderCompiledWithDisplayFilterSupport, drawBackground(), drawCheckers(), drawGrid(), drawImage(), initializeDisplayShader(), KIS_SAFE_ASSERT_RECOVER_NOOP, KisOpenGLCanvasRenderer::Private::pixelGridDrawingThreshold, KisOpenGLCanvasRenderer::Private::pixelGridEnabled, KisOpenGLCanvasRenderer::Private::quadVAO, KisOpenGL::supportsVAO(), surfaceToWidget(), and widgetToSurface().

◆ reportFailedShaderCompilation()

void KisOpenGLCanvasRenderer::reportFailedShaderCompilation ( const QString & context)
private

Displays a message box telling the user that shader compilation failed and turns off OpenGL.

Definition at line 329 of file KisOpenGLCanvasRenderer.cpp.

330{
331 KisConfig cfg(false);
332
333 qDebug() << "Shader Compilation Failure: " << context;
334 // TODO: Should do something else when using QtQuick2
335 QMessageBox::critical(qApp->activeWindow(), i18nc("@title:window", "Krita"),
336 i18n("Krita could not initialize the OpenGL canvas:\n\n%1\n\n Krita will disable OpenGL and close now.", context),
337 QMessageBox::Close);
338
339 cfg.disableOpenGL();
340 cfg.setCanvasState("OPENGL_FAILED");
341}

References context(), KisConfig::disableOpenGL(), and KisConfig::setCanvasState().

◆ resizeGL()

void KisOpenGLCanvasRenderer::resizeGL ( int width,
int height )

Definition at line 343 of file KisOpenGLCanvasRenderer.cpp.

344{
345 {
346 // just a sanity check!
347 //
348 // This is how QOpenGLCanvas sets the FBO and the viewport size. If
349 // devicePixelRatioF() is non-integral, the result is truncated.
350 // *Correction*: The FBO size is actually rounded, but the glViewport call
351 // uses integer truncation and that's what really matters.
352 int viewportWidth = static_cast<int>(width * devicePixelRatioF());
353 int viewportHeight = static_cast<int>(height * devicePixelRatioF());
354
355 // We expect the size to be adjusted in the converter at the higher
356 // level of hierarchy. It happens in KisCanvasControllerWidget, which
357 // then explicitly resizes the canvas widget.
358 KIS_SAFE_ASSERT_RECOVER_NOOP(QSize(viewportWidth, viewportHeight) == coordinatesConverter()->viewportDevicePixelSize());
359 }
360
363
365 QOpenGLFramebufferObjectFormat format;
366 format.setInternalTextureFormat(d->canvasBridge->internalTextureFormat());
367 d->canvasFBO.reset(new QOpenGLFramebufferObject(d->viewportDevicePixelSize, format));
368 }
369}
virtual GLenum internalTextureFormat() const =0
static bool useFBOForToolOutlineRendering()
supportsRenderToFBO

References KisOpenGLCanvasRenderer::Private::canvasBridge, KisOpenGLCanvasRenderer::Private::canvasFBO, coordinatesConverter(), d, devicePixelRatioF(), KisCoordinatesConverter::getCanvasWidgetSize(), KisOpenGLCanvasRenderer::CanvasBridge::internalTextureFormat(), KIS_SAFE_ASSERT_RECOVER_NOOP, KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize, KisOpenGL::useFBOForToolOutlineRendering(), KisCoordinatesConverter::viewportDevicePixelSize(), and KisOpenGLCanvasRenderer::Private::viewportDevicePixelSize.

◆ setDisplayConfig()

void KisOpenGLCanvasRenderer::setDisplayConfig ( const KisDisplayConfig & config)

Definition at line 1092 of file KisOpenGLCanvasRenderer.cpp.

1093{
1095 config.intent,
1096 config.conversionFlags);
1097 updateConfig();
1098}
void setMonitorProfile(const KoColorProfile *monitorProfile, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)

References KisDisplayConfig::conversionFlags, d, KisDisplayConfig::intent, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisDisplayConfig::profile, KisOpenGLImageTextures::setMonitorProfile(), and updateConfig().

◆ setDisplayFilter()

void KisOpenGLCanvasRenderer::setDisplayFilter ( QSharedPointer< KisDisplayFilter > displayFilter)

Definition at line 194 of file KisOpenGLCanvasRenderer.cpp.

195{
196 setDisplayFilterImpl(displayFilter, false);
197}

References setDisplayFilterImpl().

◆ setDisplayFilterImpl()

void KisOpenGLCanvasRenderer::setDisplayFilterImpl ( QSharedPointer< KisDisplayFilter > displayFilter,
bool initializing )
private

Definition at line 199 of file KisOpenGLCanvasRenderer.cpp.

200{
201 bool needsInternalColorManagement =
202 !displayFilter || displayFilter->useInternalColorManagement();
203
204 bool needsFullRefresh = d->openGLImageTextures->setInternalColorManagementActive(needsInternalColorManagement, initializing);
205
206 d->displayFilter = displayFilter;
207
208 if (!initializing && needsFullRefresh) {
209 canvas()->startUpdateInPatches(canvas()->image()->bounds());
210 }
211 else if (!initializing) {
212 canvas()->updateCanvas();
213 }
214}
void updateCanvas(const QRectF &rc) override
bool setInternalColorManagementActive(bool value, bool iniializing=false)

References bounds, canvas(), d, KisOpenGLCanvasRenderer::Private::displayFilter, KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLImageTextures::setInternalColorManagementActive(), KisCanvas2::startUpdateInPatches(), and KisCanvas2::updateCanvas().

◆ setLodResetInProgress()

void KisOpenGLCanvasRenderer::setLodResetInProgress ( bool value)

Definition at line 584 of file KisOpenGLCanvasRenderer.cpp.

585{
587}
float value(const T *src, size_t ch)

References d, KisOpenGLCanvasRenderer::Private::lodSwitchInProgress, and value().

◆ setWrapAroundViewingMode()

void KisOpenGLCanvasRenderer::setWrapAroundViewingMode ( bool value)

Definition at line 226 of file KisOpenGLCanvasRenderer.cpp.

227{
229}

References d, value(), and KisOpenGLCanvasRenderer::Private::wrapAroundMode.

◆ setWrapAroundViewingModeAxis()

void KisOpenGLCanvasRenderer::setWrapAroundViewingModeAxis ( WrapAroundAxis value)

◆ startUpdateCanvasProjection()

KisUpdateInfoSP KisOpenGLCanvasRenderer::startUpdateCanvasProjection ( const QRect & rc)

Definition at line 1113 of file KisOpenGLCanvasRenderer.cpp.

1114{
1115 if (canvas()->proofingConfigUpdated()) {
1116 d->openGLImageTextures->setProofingConfig(canvas()->proofingConfiguration());
1118 }
1120}
void setProofingConfigUpdated(bool updated)
setProofingConfigUpdated This function is to set whether the proofing config is updated,...
KisOpenGLUpdateInfoSP updateCache(const QRect &rect, KisImageSP srcImage)

References canvas(), d, KisOpenGLImageTextures::image(), KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisOpenGLImageTextures::setProofingConfig(), KisCanvas2::setProofingConfigUpdated(), and KisOpenGLImageTextures::updateCache().

◆ surfaceToWidget()

QRectF KisOpenGLCanvasRenderer::surfaceToWidget ( const QRectF & rc)
private

Definition at line 1032 of file KisOpenGLCanvasRenderer.cpp.

1033{
1034 const qreal ratio = devicePixelRatioF();
1035
1036 return QRectF(rc.x() / ratio,
1037 d->pixelAlignedWidgetSize.height() - (rc.y() + rc.height()) / ratio,
1038 rc.width() / ratio,
1039 rc.height() / ratio);
1040}

References d, devicePixelRatioF(), and KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize.

◆ updateCanvasProjection()

QRect KisOpenGLCanvasRenderer::updateCanvasProjection ( KisUpdateInfoSP info)

Definition at line 1123 of file KisOpenGLCanvasRenderer.cpp.

1124{
1125 // See KisQPainterCanvas::updateCanvasProjection for more info
1126 bool isOpenGLUpdateInfo = dynamic_cast<KisOpenGLUpdateInfo*>(info.data());
1127 if (isOpenGLUpdateInfo) {
1129 }
1130
1131 const QRect dirty = kisGrowRect(coordinatesConverter()->imageToWidget(info->dirtyImageRect()).toAlignedRect(), 2);
1132 return dirty;
1133}
void recalculateCache(KisUpdateInfoSP info, bool blockMipmapRegeneration)
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186

References coordinatesConverter(), d, KisSharedPtr< T >::data(), kisGrowRect(), KisOpenGLCanvasRenderer::Private::lodSwitchInProgress, KisOpenGLCanvasRenderer::Private::openGLImageTextures, and KisOpenGLImageTextures::recalculateCache().

◆ updateConfig()

void KisOpenGLCanvasRenderer::updateConfig ( )

Definition at line 990 of file KisOpenGLCanvasRenderer.cpp.

991{
992 KisConfig cfg(true);
993 d->checkSizeScale = KisOpenGLImageTextures::BACKGROUND_TEXTURE_CHECK_SIZE / static_cast<GLfloat>(cfg.checkSize());
994 d->scrollCheckers = cfg.scrollCheckers();
995
997 d->openGLImageTextures->updateConfig(cfg.useOpenGLTextureBuffer(), cfg.numMipmapLevels());
998 d->filterMode = (KisOpenGL::FilterMode) cfg.openGLFilteringMode();
999
1002}
static const int BACKGROUND_TEXTURE_CHECK_SIZE
void updateConfig(bool useBuffer, int NumMipmapLevels)

References KisOpenGLImageTextures::BACKGROUND_TEXTURE_CHECK_SIZE, KisConfig::checkSize(), KisOpenGLCanvasRenderer::Private::checkSizeScale, KisCanvasWidgetBase::createCheckersImage(), d, KisOpenGLCanvasRenderer::Private::filterMode, KisOpenGLImageTextures::generateCheckerTexture(), KisConfig::numMipmapLevels(), KisConfig::openGLFilteringMode(), KisOpenGLCanvasRenderer::Private::openGLImageTextures, KisConfig::scrollCheckers(), KisOpenGLCanvasRenderer::Private::scrollCheckers, KisOpenGLImageTextures::updateConfig(), updateCursorColor(), updatePixelGridMode(), and KisConfig::useOpenGLTextureBuffer().

◆ updateCursorColor()

void KisOpenGLCanvasRenderer::updateCursorColor ( )

Definition at line 1004 of file KisOpenGLCanvasRenderer.cpp.

1005{
1006 KisConfig cfg(true);
1007 bool useSeparateEraserCursor = cfg.separateEraserCursor() &&
1009
1010 d->cursorColor = colorToDisplaySpace((!useSeparateEraserCursor) ? cfg.getCursorMainColor() : cfg.getEraserCursorMainColor());
1011}
const QString COMPOSITE_ERASE
QPointer< KoCanvasResourceProvider > resourceManager

References canvas(), colorToDisplaySpace(), COMPOSITE_ERASE, KoCanvasResource::CurrentEffectiveCompositeOp, KisOpenGLCanvasRenderer::Private::cursorColor, d, KisConfig::getCursorMainColor(), KisConfig::getEraserCursorMainColor(), KoCanvasBase::resourceManager, and KisConfig::separateEraserCursor().

◆ updatePixelGridMode()

void KisOpenGLCanvasRenderer::updatePixelGridMode ( )

◆ widgetToSurface()

QRectF KisOpenGLCanvasRenderer::widgetToSurface ( const QRectF & rc)
private

Definition at line 1022 of file KisOpenGLCanvasRenderer.cpp.

1023{
1024 const qreal ratio = devicePixelRatioF();
1025
1026 return QRectF(rc.x() * ratio,
1027 (d->pixelAlignedWidgetSize.height() - rc.y() - rc.height()) * ratio,
1028 rc.width() * ratio,
1029 rc.height() * ratio);
1030}

References d, devicePixelRatioF(), and KisOpenGLCanvasRenderer::Private::pixelAlignedWidgetSize.

◆ wrapAroundViewingMode()

bool KisOpenGLCanvasRenderer::wrapAroundViewingMode ( ) const

Definition at line 231 of file KisOpenGLCanvasRenderer.cpp.

232{
233 return d->wrapAroundMode;
234}

References d, and KisOpenGLCanvasRenderer::Private::wrapAroundMode.

◆ wrapAroundViewingModeAxis()

WrapAroundAxis KisOpenGLCanvasRenderer::wrapAroundViewingModeAxis ( ) const

Definition at line 241 of file KisOpenGLCanvasRenderer.cpp.

242{
243 return d->wrapAroundModeAxis;
244}

References d, and KisOpenGLCanvasRenderer::Private::wrapAroundModeAxis.

Member Data Documentation

◆ d

Private* const KisOpenGLCanvasRenderer::d
private

Definition at line 117 of file KisOpenGLCanvasRenderer.h.


The documentation for this class was generated from the following files: