-
-
Save JulianThijssen/43ab59fef201c567462c83bc09c05f3a to your computer and use it in GitHub Desktop.
Changes made to Krita
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/krita/data/shaders/cursor.frag b/krita/data/shaders/cursor.frag | |
index 086cbce..0cb2826 100644 | |
--- a/krita/data/shaders/cursor.frag | |
+++ b/krita/data/shaders/cursor.frag | |
@@ -1,4 +1,8 @@ | |
+#version 150 | |
+ | |
+out vec4 color; | |
+ | |
void main(void) | |
{ | |
- gl_FragColor = vec4(0.501961, 1.0, 0.501961, 1.0); | |
+ color = vec4(0.501961, 1.0, 0.501961, 1.0); | |
} | |
diff --git a/krita/data/shaders/cursor.vert b/krita/data/shaders/cursor.vert | |
index 583a871..67b0254 100644 | |
--- a/krita/data/shaders/cursor.vert | |
+++ b/krita/data/shaders/cursor.vert | |
@@ -1,6 +1,7 @@ | |
+#version 150 | |
uniform mat4 modelViewProjection; | |
-attribute highp vec4 a_vertexPosition; | |
+in highp vec4 a_vertexPosition; | |
void main() | |
{ | |
diff --git a/krita/data/shaders/highq_downscale.frag b/krita/data/shaders/highq_downscale.frag | |
index c34dde3..bb2a47c 100644 | |
--- a/krita/data/shaders/highq_downscale.frag | |
+++ b/krita/data/shaders/highq_downscale.frag | |
@@ -97,7 +97,7 @@ void main() { | |
#ifdef HIGHQ_SCALING | |
col = filterPureLinear8(texture0, v_textureCoordinate.st); | |
#else /* HIGHQ_SCALING */ | |
- col = texture2D(texture0, v_textureCoordinate.st); | |
+ col = texture(texture0, v_textureCoordinate.st); | |
#endif /* HIGHQ_SCALING */ | |
} | |
@@ -114,7 +114,7 @@ void main() { | |
#endif /* DIRECT_LOD_FETCH */ | |
{ | |
- col = texture2D(texture0, v_textureCoordinate.st); | |
+ col = texture(texture0, v_textureCoordinate.st); | |
} | |
} | |
diff --git a/krita/data/shaders/matrix_transform.vert b/krita/data/shaders/matrix_transform.vert | |
index b2a3703..00c3c2b 100644 | |
--- a/krita/data/shaders/matrix_transform.vert | |
+++ b/krita/data/shaders/matrix_transform.vert | |
@@ -1,4 +1,4 @@ | |
-#version 130 | |
+#version 150 | |
/* | |
* Vertex shader for handling scaling | |
diff --git a/krita/data/shaders/simple_texture.frag b/krita/data/shaders/simple_texture.frag | |
index 4800704..9594a1c 100644 | |
--- a/krita/data/shaders/simple_texture.frag | |
+++ b/krita/data/shaders/simple_texture.frag | |
@@ -1,4 +1,4 @@ | |
-#version 130 | |
+#version 150 | |
/* | |
* shader for handling scaling | |
*/ | |
@@ -8,5 +8,5 @@ in vec4 v_textureCoordinate; | |
out vec4 fragColor; | |
void main() { | |
- fragColor = texture2D(texture0, v_textureCoordinate.st); | |
+ fragColor = texture(texture0, v_textureCoordinate.st); | |
} | |
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt | |
index fbf7590..841b60a 100644 | |
--- a/libs/ui/CMakeLists.txt | |
+++ b/libs/ui/CMakeLists.txt | |
@@ -17,6 +17,11 @@ include_directories(SYSTEM | |
${Boost_INCLUDE_DIRS} | |
) | |
+include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS} | |
+ ${Qt5Core_PRIVATE_INCLUDE_DIRS} | |
+ ${Qt5Widgets_PRIVATE_INCLUDE_DIRS} | |
+) | |
+ | |
add_subdirectory( tests ) | |
if (APPLE) | |
@@ -363,6 +368,7 @@ set(kritaui_LIB_SRCS | |
KisPaletteModel.cpp | |
KisColorsetChooser.cpp | |
KisSaveGroupVisitor.cpp | |
+ | |
) | |
if(WIN32) | |
diff --git a/libs/ui/canvas/kis_canvas2.cpp b/libs/ui/canvas/kis_canvas2.cpp | |
index 44fcf60..d621269 100644 | |
--- a/libs/ui/canvas/kis_canvas2.cpp | |
+++ b/libs/ui/canvas/kis_canvas2.cpp | |
@@ -157,7 +157,8 @@ void KisCanvas2::setup() | |
m_d->vastScrolling = cfg.vastScrolling(); | |
m_d->lodAllowedInCanvas = cfg.levelOfDetailEnabled(); | |
- createCanvas(cfg.useOpenGL()); | |
+ qWarning() << "NOTE: QPainter Canvas is explicitly disabled!"; | |
+ createCanvas(true);//cfg.useOpenGL()); | |
setLodAllowedInCanvas(m_d->lodAllowedInCanvas); | |
m_d->animationPlayer = new KisAnimationPlayer(this); | |
@@ -431,11 +432,11 @@ void KisCanvas2::createCanvas(bool useOpenGL) | |
if (useOpenGL) { | |
if (KisOpenGL::hasOpenGL()) { | |
createOpenGLCanvas(); | |
- if (cfg.canvasState() == "OPENGL_FAILED") { | |
- // Creating the opengl canvas failed, fall back | |
- warnKrita << "OpenGL Canvas initialization returned OPENGL_FAILED. Falling back to QPainter."; | |
- createQPainterCanvas(); | |
- } | |
+// if (cfg.canvasState() == "OPENGL_FAILED") { | |
+// // Creating the opengl canvas failed, fall back | |
+// warnKrita << "OpenGL Canvas initialization returned OPENGL_FAILED. Falling back to QPainter."; | |
+// createQPainterCanvas(); | |
+// } | |
} else { | |
warnKrita << "Tried to create OpenGL widget when system doesn't have OpenGL\n"; | |
createQPainterCanvas(); | |
@@ -926,14 +927,14 @@ void KisCanvas2::bootstrapFinished() | |
void KisCanvas2::setLodAllowedInCanvas(bool value) | |
{ | |
- if (!KisOpenGL::supportsGLSL13()) { | |
+ if (!KisOpenGL::hasOpenGL3()) { | |
qWarning() << "WARNING: Level of Detail functionality is available only with openGL + GLSL 1.3 support"; | |
} | |
m_d->lodAllowedInCanvas = | |
value && | |
m_d->currentCanvasIsOpenGL && | |
- KisOpenGL::supportsGLSL13() && | |
+ KisOpenGL::hasOpenGL3() && | |
(m_d->openGLFilterMode == KisOpenGL::TrilinearFilterMode || | |
m_d->openGLFilterMode == KisOpenGL::HighQualityFiltering); | |
diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc | |
index 3835c53..53ae055 100644 | |
--- a/libs/ui/dialogs/kis_dlg_preferences.cc | |
+++ b/libs/ui/dialogs/kis_dlg_preferences.cc | |
@@ -690,7 +690,7 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name) | |
cmbFilterMode->setEnabled(cfg.useOpenGL()); | |
cmbFilterMode->setCurrentIndex(cfg.openGLFilteringMode()); | |
// Don't show the high quality filtering mode if it's not available | |
- if (!KisOpenGL::supportsGLSL13()) { | |
+ if (!KisOpenGL::hasOpenGL3()) { | |
cmbFilterMode->removeItem(3); | |
} | |
} | |
diff --git a/libs/ui/kis_painting_assistant.cc b/libs/ui/kis_painting_assistant.cc | |
index a2d6323..3362202 100644 | |
--- a/libs/ui/kis_painting_assistant.cc | |
+++ b/libs/ui/kis_painting_assistant.cc | |
@@ -178,7 +178,7 @@ void KisPaintingAssistant::drawPath(QPainter& painter, const QPainterPath &path, | |
int alpha=100; | |
if (drawActive==false) { | |
alpha=20; | |
- } | |
+ } | |
painter.save(); | |
QPen pen_a(QColor(0, 0, 0, alpha), 2); | |
pen_a.setCosmetic(true); | |
@@ -285,7 +285,9 @@ void KisPaintingAssistant::drawAssistant(QPainter& gc, const QRectF& updateRect, | |
if (paintRect.isEmpty()) return; | |
QPixmap cached; | |
- if (!(QPixmapCache::find(d->cached, &cached) && | |
+ bool found = QPixmapCache::find(d->cached, &cached); | |
+ | |
+ if (!(found && | |
d->cachedTransform == transform && | |
d->cachedRect.translated(widgetBound.topLeft()).contains(paintRect))) { | |
const QRect cacheRect = gc.viewport().adjusted(-100, -100, 100, 100).intersected(widgetBound); | |
@@ -688,4 +690,3 @@ KisPaintingAssistantFactoryRegistry* KisPaintingAssistantFactoryRegistry::instan | |
{ | |
return s_instance; | |
} | |
- | |
diff --git a/libs/ui/kis_painting_assistant.h b/libs/ui/kis_painting_assistant.h | |
index 943aca2..c13f209 100644 | |
--- a/libs/ui/kis_painting_assistant.h | |
+++ b/libs/ui/kis_painting_assistant.h | |
@@ -145,7 +145,7 @@ protected: | |
private: | |
struct Private; | |
Private* const d; | |
- | |
+ | |
}; | |
/** | |
@@ -169,7 +169,7 @@ class KRITAUI_EXPORT KisPaintingAssistantFactoryRegistry : public KoGenericRegis | |
~KisPaintingAssistantFactoryRegistry(); | |
static KisPaintingAssistantFactoryRegistry* instance(); | |
- | |
+ | |
}; | |
#endif | |
diff --git a/libs/ui/opengl/kis_opengl.cpp b/libs/ui/opengl/kis_opengl.cpp | |
index 9764535..98819c8 100644 | |
--- a/libs/ui/opengl/kis_opengl.cpp | |
+++ b/libs/ui/opengl/kis_opengl.cpp | |
@@ -148,10 +148,10 @@ void KisOpenGL::initializeContext(QOpenGLContext *ctx) | |
} | |
} | |
-bool KisOpenGL::supportsGLSL13() | |
+bool KisOpenGL::hasOpenGL3() | |
{ | |
initialize(); | |
- return glMajorVersion >= 3 && supportsDeprecatedFunctions; | |
+ return glMajorVersion >= 3; | |
} | |
bool KisOpenGL::supportsFenceSync() | |
@@ -175,15 +175,8 @@ bool KisOpenGL::needsPixmapCacheWorkaround() | |
void KisOpenGL::setDefaultFormat() | |
{ | |
QSurfaceFormat format; | |
-#ifdef Q_OS_MAC | |
-// format.setProfile(QSurfaceFormat::CoreProfile); | |
-// format.setOptions(QSurfaceFormat::DeprecatedFunctions); | |
- format.setVersion(2, 1); | |
-#else | |
- format.setProfile(QSurfaceFormat::CompatibilityProfile); | |
- format.setOptions(QSurfaceFormat::DeprecatedFunctions); | |
- format.setVersion(3, 0); | |
-#endif | |
+ format.setProfile(QSurfaceFormat::CoreProfile); | |
+ format.setVersion(3, 2); | |
format.setDepthBufferSize(24); | |
format.setStencilBufferSize(8); | |
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); | |
diff --git a/libs/ui/opengl/kis_opengl.h b/libs/ui/opengl/kis_opengl.h | |
index 1648fbd..50d2f70 100644 | |
--- a/libs/ui/opengl/kis_opengl.h | |
+++ b/libs/ui/opengl/kis_opengl.h | |
@@ -49,7 +49,7 @@ public: | |
/// Initialize shared OpenGL context | |
static void initializeContext(QOpenGLContext *ctx); | |
- static bool supportsGLSL13(); | |
+ static bool hasOpenGL3(); | |
/// Check for OpenGL | |
static bool hasOpenGL(); | |
diff --git a/libs/ui/opengl/kis_opengl_canvas2.cpp b/libs/ui/opengl/kis_opengl_canvas2.cpp | |
index 4d003dd..404d24a 100644 | |
--- a/libs/ui/opengl/kis_opengl_canvas2.cpp | |
+++ b/libs/ui/opengl/kis_opengl_canvas2.cpp | |
@@ -39,8 +39,13 @@ | |
#include <QThread> | |
#include <QFile> | |
#include <QOpenGLShaderProgram> | |
+#include <QOpenGLVertexArrayObject> | |
+#include <QOpenGLBuffer> | |
#include <QMessageBox> | |
+#include <KoResourcePaths.h> | |
+#include <QOpenGLTimerQuery> | |
+ | |
#define NEAR_VAL -1000.0 | |
#define FAR_VAL 1000.0 | |
@@ -60,6 +65,7 @@ static kis_glLogicOp ptr_glLogicOp = 0; | |
struct KisOpenGLCanvas2::Private | |
{ | |
public: | |
+ | |
~Private() { | |
delete displayShader; | |
delete checkerShader; | |
@@ -69,9 +75,6 @@ public: | |
bool canvasInitialized{false}; | |
- QVector3D vertices[6]; | |
- QVector2D texCoords[6]; | |
- | |
KisOpenGLImageTexturesSP openGLImageTextures; | |
QOpenGLShaderProgram *displayShader{0}; | |
@@ -100,6 +103,14 @@ public: | |
bool wrapAroundMode{false}; | |
+ QOpenGLVertexArrayObject quadVAO; | |
+ QOpenGLBuffer quadBuffers[2]; | |
+ QOpenGLVertexArrayObject outlineVAO; | |
+ QOpenGLBuffer lineBuffer; | |
+ | |
+ QVector3D vertices[6]; | |
+ QVector2D texCoords[6]; | |
+ | |
int xToColWithWrapCompensation(int x, const QRect &imageRect) { | |
int firstImageColumn = openGLImageTextures->xToCol(imageRect.left()); | |
int lastImageColumn = openGLImageTextures->xToCol(imageRect.right()); | |
@@ -133,13 +144,6 @@ KisOpenGLCanvas2::KisOpenGLCanvas2(KisCanvas2 *canvas, | |
, KisCanvasWidgetBase(canvas, coordinatesConverter) | |
, d(new Private()) | |
{ | |
- | |
- | |
- | |
- QSurfaceFormat format; | |
- format.setDepthBufferSize(24); | |
- setFormat(format); | |
- | |
KisConfig cfg; | |
cfg.writeEntry("canvasState", "OPENGL_STARTED"); | |
@@ -212,6 +216,26 @@ void KisOpenGLCanvas2::setWrapAroundViewingMode(bool value) | |
update(); | |
} | |
+inline void rectToVertices(QVector3D* vertices, const QRectF &rc) | |
+{ | |
+ vertices[0] = QVector3D(rc.left(), rc.bottom(), 0.f); | |
+ vertices[1] = QVector3D(rc.left(), rc.top(), 0.f); | |
+ vertices[2] = QVector3D(rc.right(), rc.bottom(), 0.f); | |
+ vertices[3] = QVector3D(rc.left(), rc.top(), 0.f); | |
+ vertices[4] = QVector3D(rc.right(), rc.top(), 0.f); | |
+ vertices[5] = QVector3D(rc.right(), rc.bottom(), 0.f); | |
+} | |
+ | |
+inline void rectToTexCoords(QVector2D* texCoords, const QRectF &rc) | |
+{ | |
+ texCoords[0] = QVector2D(rc.left(), rc.bottom()); | |
+ texCoords[1] = QVector2D(rc.left(), rc.top()); | |
+ texCoords[2] = QVector2D(rc.right(), rc.bottom()); | |
+ texCoords[3] = QVector2D(rc.left(), rc.top()); | |
+ texCoords[4] = QVector2D(rc.right(), rc.top()); | |
+ texCoords[5] = QVector2D(rc.right(), rc.bottom()); | |
+} | |
+ | |
void KisOpenGLCanvas2::initializeGL() | |
{ | |
KisOpenGL::initializeContext(context()); | |
@@ -224,6 +248,32 @@ void KisOpenGLCanvas2::initializeGL() | |
initializeCheckerShader(); | |
initializeDisplayShader(); | |
+ d->quadVAO.create(); | |
+ d->quadVAO.bind(); | |
+ glEnableVertexAttribArray(PROGRAM_VERTEX_ATTRIBUTE); | |
+ glEnableVertexAttribArray(PROGRAM_TEXCOORD_ATTRIBUTE); | |
+ | |
+ d->quadBuffers[0].create(); | |
+ d->quadBuffers[0].setUsagePattern(QOpenGLBuffer::StaticDraw); | |
+ d->quadBuffers[0].bind(); | |
+ d->quadBuffers[0].allocate(d->vertices, 6 * 3 * sizeof(float)); | |
+ glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, 0); | |
+ | |
+ d->quadBuffers[1].create(); | |
+ d->quadBuffers[1].setUsagePattern(QOpenGLBuffer::StaticDraw); | |
+ d->quadBuffers[1].bind(); | |
+ d->quadBuffers[1].allocate(d->texCoords, 6 * 2 * sizeof(float)); | |
+ glVertexAttribPointer(PROGRAM_TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, 0); | |
+ | |
+ d->outlineVAO.create(); | |
+ d->outlineVAO.bind(); | |
+ glEnableVertexAttribArray(PROGRAM_VERTEX_ATTRIBUTE); | |
+ | |
+ d->lineBuffer.create(); | |
+ d->lineBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw); | |
+ d->lineBuffer.bind(); | |
+ glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, 0); | |
+ | |
ptr_glLogicOp = (kis_glLogicOp)(context()->getProcAddress("glLogicOp")); | |
Sync::init(context()); | |
@@ -246,21 +296,19 @@ void KisOpenGLCanvas2::paintGL() | |
KisOpenglCanvasDebugger::instance()->nofityPaintRequested(); | |
- QPainter gc(this); | |
- gc.beginNativePainting(); | |
- | |
renderCanvasGL(); | |
if (d->glSyncObject) { | |
Sync::deleteSync(d->glSyncObject); | |
} | |
d->glSyncObject = Sync::getSync(); | |
- gc.endNativePainting(); | |
+ qDebug() << "DRAWING DECORATIONS"; | |
+ QPainter gc(this); | |
renderDecorations(&gc); | |
+ //renderTests(&gc); | |
gc.end(); | |
- | |
if (!OPENGL_SUCCESS) { | |
KisConfig cfg; | |
cfg.writeEntry("canvasState", "OPENGL_SUCCESS"); | |
@@ -288,7 +336,6 @@ QOpenGLShaderProgram *KisOpenGLCanvas2::getCursorShader() | |
void KisOpenGLCanvas2::paintToolOutline(const QPainterPath &path) | |
{ | |
- | |
QOpenGLShaderProgram *cursorShader = getCursorShader(); | |
cursorShader->bind(); | |
@@ -316,27 +363,33 @@ void KisOpenGLCanvas2::paintToolOutline(const QPainterPath &path) | |
ptr_glLogicOp(GL_XOR); | |
} | |
- // setup the array of vertices | |
- QVector<QVector3D> vertices; | |
+ // Paint the tool outline | |
+ d->outlineVAO.bind(); | |
+ d->lineBuffer.bind(); | |
+ | |
+ // Convert every disjointed subpath to a polygon and draw that polygon | |
QList<QPolygonF> subPathPolygons = path.toSubpathPolygons(); | |
- for (int i=0; i<subPathPolygons.size(); i++) { | |
+ for (int i = 0; i < subPathPolygons.size(); i++) { | |
const QPolygonF& polygon = subPathPolygons.at(i); | |
- for (int j=0; j < polygon.count(); j++) { | |
+ | |
+ QVector<QVector3D> vertices; | |
+ vertices.resize(polygon.count()); | |
+ for (int j = 0; j < polygon.count(); j++) { | |
QPointF p = polygon.at(j); | |
- vertices << QVector3D(p.x(), p.y(), 0.f); | |
+ vertices[j].setX(p.x()); | |
+ vertices[j].setY(p.y()); | |
} | |
- cursorShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE); | |
- cursorShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, vertices.constData()); | |
+ d->lineBuffer.allocate(vertices.constData(), 3 * vertices.size() * sizeof(float)); | |
glDrawArrays(GL_LINE_STRIP, 0, vertices.size()); | |
- | |
- vertices.clear(); | |
} | |
+ d->lineBuffer.release(); | |
+ d->outlineVAO.release(); | |
+ | |
glDisable(GL_COLOR_LOGIC_OP); | |
cursorShader->release(); | |
- | |
} | |
bool KisOpenGLCanvas2::isBusy() const | |
@@ -347,26 +400,6 @@ bool KisOpenGLCanvas2::isBusy() const | |
return isBusyStatus; | |
} | |
-inline void rectToVertices(QVector3D* vertices, const QRectF &rc) | |
-{ | |
- vertices[0] = QVector3D(rc.left(), rc.bottom(), 0.f); | |
- vertices[1] = QVector3D(rc.left(), rc.top(), 0.f); | |
- vertices[2] = QVector3D(rc.right(), rc.bottom(), 0.f); | |
- vertices[3] = QVector3D(rc.left(), rc.top(), 0.f); | |
- vertices[4] = QVector3D(rc.right(), rc.top(), 0.f); | |
- vertices[5] = QVector3D(rc.right(), rc.bottom(), 0.f); | |
-} | |
- | |
-inline void rectToTexCoords(QVector2D* texCoords, const QRectF &rc) | |
-{ | |
- texCoords[0] = QVector2D(rc.left(), rc.bottom()); | |
- texCoords[1] = QVector2D(rc.left(), rc.top()); | |
- texCoords[2] = QVector2D(rc.right(), rc.bottom()); | |
- texCoords[3] = QVector2D(rc.left(), rc.top()); | |
- texCoords[4] = QVector2D(rc.right(), rc.top()); | |
- texCoords[5] = QVector2D(rc.right(), rc.bottom()); | |
-} | |
- | |
void KisOpenGLCanvas2::drawCheckers() | |
{ | |
if (!d->checkerShader) { | |
@@ -389,7 +422,10 @@ void KisOpenGLCanvas2::drawCheckers() | |
textureTransform *= QTransform::fromScale(d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE, | |
d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE); | |
- d->checkerShader->bind(); | |
+ if (!d->checkerShader->bind()) { | |
+ qWarning() << "Could not bind checker shader"; | |
+ return; | |
+ } | |
QMatrix4x4 projectionMatrix; | |
projectionMatrix.setToIdentity(); | |
@@ -399,6 +435,7 @@ void KisOpenGLCanvas2::drawCheckers() | |
QMatrix4x4 modelMatrix(modelTransform); | |
modelMatrix.optimize(); | |
modelMatrix = projectionMatrix * modelMatrix; | |
+ | |
d->checkerShader->setUniformValue(d->checkerUniformLocationModelViewProjection, modelMatrix); | |
QMatrix4x4 textureMatrix(textureTransform); | |
@@ -406,12 +443,13 @@ void KisOpenGLCanvas2::drawCheckers() | |
//Setup the geometry for rendering | |
rectToVertices(d->vertices, modelRect); | |
- d->checkerShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE); | |
- d->checkerShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->vertices); | |
+ | |
+ d->quadBuffers[0].bind(); | |
+ d->quadBuffers[0].write(0, d->vertices, 3 * 6 * sizeof(float)); | |
rectToTexCoords(d->texCoords, textureRect); | |
- d->checkerShader->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE); | |
- d->checkerShader->setAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE, d->texCoords); | |
+ d->quadBuffers[1].bind(); | |
+ d->quadBuffers[1].write(0, d->texCoords, 2 * 6 * sizeof(float)); | |
// render checkers | |
glActiveTexture(GL_TEXTURE0); | |
@@ -421,6 +459,7 @@ void KisOpenGLCanvas2::drawCheckers() | |
glBindTexture(GL_TEXTURE_2D, 0); | |
d->checkerShader->release(); | |
+ glBindBuffer(GL_ARRAY_BUFFER, 0); | |
} | |
void KisOpenGLCanvas2::drawImage() | |
@@ -519,12 +558,13 @@ void KisOpenGLCanvas2::drawImage() | |
//Setup the geometry for rendering | |
rectToVertices(d->vertices, modelRect); | |
- d->displayShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE); | |
- d->displayShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->vertices); | |
+ | |
+ d->quadBuffers[0].bind(); | |
+ d->quadBuffers[0].write(0, d->vertices, 3 * 6 * sizeof(float)); | |
rectToTexCoords(d->texCoords, textureRect); | |
- d->displayShader->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE); | |
- d->displayShader->setAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE, d->texCoords); | |
+ d->quadBuffers[1].bind(); | |
+ d->quadBuffers[1].write(0, d->texCoords, 2 * 6 * sizeof(float)); | |
if (d->displayFilter) { | |
glActiveTexture(GL_TEXTURE0 + 1); | |
@@ -575,6 +615,8 @@ void KisOpenGLCanvas2::drawImage() | |
glBindTexture(GL_TEXTURE_2D, 0); | |
d->displayShader->release(); | |
+ glBindBuffer(GL_ARRAY_BUFFER, 0); | |
+ | |
} | |
void KisOpenGLCanvas2::reportShaderLinkFailedAndExit(bool result, const QString &context, const QString &log) | |
@@ -606,7 +648,7 @@ void KisOpenGLCanvas2::initializeCheckerShader() | |
bool result; | |
- if (KisOpenGL::supportsGLSL13()) { | |
+ if (KisOpenGL::hasOpenGL3()) { | |
vertexShaderName = ":/matrix_transform.vert"; | |
fragmentShaderName = ":/simple_texture.frag"; | |
} | |
@@ -641,13 +683,12 @@ QByteArray KisOpenGLCanvas2::buildFragmentShader() | |
bool haveDisplayFilter = d->displayFilter && !d->displayFilter->program().isEmpty(); | |
bool useHiQualityFiltering = d->filterMode == KisOpenGL::HighQualityFiltering; | |
- bool haveGLSL13 = KisOpenGL::supportsGLSL13(); | |
QString filename; | |
- if (haveGLSL13) { | |
+ if (KisOpenGL::hasOpenGL3()) { | |
filename = "highq_downscale.frag"; | |
- shaderText.append("#version 130\n"); | |
+ shaderText.append("#version 150\n"); | |
} else { | |
filename = "simple_texture_legacy.frag"; | |
} | |
@@ -657,10 +698,10 @@ QByteArray KisOpenGLCanvas2::buildFragmentShader() | |
shaderText.append(d->displayFilter->program().toLatin1()); | |
} | |
- if (haveGLSL13 && useHiQualityFiltering) { | |
+ if (KisOpenGL::hasOpenGL3() && useHiQualityFiltering) { | |
shaderText.append("#define HIGHQ_SCALING\n"); | |
} | |
- if (haveGLSL13) { | |
+ if (KisOpenGL::hasOpenGL3()) { | |
shaderText.append("#define DIRECT_LOD_FETCH\n"); | |
} | |
@@ -683,7 +724,7 @@ void KisOpenGLCanvas2::initializeDisplayShader() | |
bool result = d->displayShader->addShaderFromSourceCode(QOpenGLShader::Fragment, buildFragmentShader()); | |
reportShaderLinkFailedAndExit(result, "Display fragment shader", d->displayShader->log()); | |
- if (KisOpenGL::supportsGLSL13()) { | |
+ if (KisOpenGL::hasOpenGL3()) { | |
result = d->displayShader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/matrix_transform.vert"); | |
} | |
else { | |
@@ -718,7 +759,7 @@ void KisOpenGLCanvas2::initializeDisplayShader() | |
// lod | |
d->displayUniformLocationFixedLodLevel = | |
- KisOpenGL::supportsGLSL13() ? | |
+ KisOpenGL::hasOpenGL3() ? | |
d->displayShader->uniformLocation("fixedLodLevel") : -1; | |
} | |
@@ -756,8 +797,134 @@ void KisOpenGLCanvas2::renderCanvasGL() | |
d->displayFilter->updateShader(); | |
} | |
+ d->quadVAO.bind(); | |
drawCheckers(); | |
drawImage(); | |
+ d->quadVAO.release(); | |
+} | |
+ | |
+void KisOpenGLCanvas2::renderTests(QPainter *gc) | |
+{ | |
+ QOpenGLTimerQuery timer; | |
+ timer.create(); | |
+ timer.begin(); | |
+ | |
+ QPen pen; | |
+ pen.setWidth(10); | |
+ pen.setJoinStyle(Qt::RoundJoin); | |
+ gc->setPen(pen); | |
+ | |
+ //gc->drawRect(100, 100, 100, 100); | |
+ | |
+ //pen.setJoinStyle(Qt::BevelJoin); | |
+ //gc->setPen(pen); | |
+ //gc->drawRect(210, 100, 100, 100); | |
+ | |
+ //QBrush brush(Qt::red); | |
+ //gc->fillRect(320, 100, 100, 100, brush); | |
+ | |
+ // Draw Arc | |
+ pen.setBrush(QColor(255, 0, 0)); gc->setPen(pen); | |
+ QRectF arcRect(10.0, 20.0, 80.0, 60.0); | |
+ int arcStartAngle = 30 * 16; | |
+ int arcSpanAngle = 120 * 16; | |
+ gc->drawArc(arcRect, arcStartAngle, arcSpanAngle); | |
+ | |
+ // Draw Chord | |
+ pen.setBrush(QColor(255, 50, 0)); gc->setPen(pen); | |
+ gc->drawChord(100, 20, 100, 100, 30 * 16, 120 * 16); | |
+ | |
+ // Draw Convex Polygon | |
+ pen.setBrush(QColor(255, 100, 0)); gc->setPen(pen); | |
+ const QPointF points[4] = { | |
+ QPointF(210.0, 80.0), | |
+ QPointF(220.0, 10.0), | |
+ QPointF(280.0, 30.0), | |
+ QPointF(290.0, 70.0) | |
+ }; | |
+ gc->drawConvexPolygon(points, 4); | |
+ | |
+ // Draw Ellipse | |
+ pen.setBrush(QColor(255, 150, 0)); gc->setPen(pen); | |
+ gc->drawEllipse(300, 0, 100, 100); | |
+ | |
+ // Draw Image | |
+ QRectF target(410.0, 20.0, 80.0, 80.0); | |
+ QRectF source(0.0, 0.0, 512.0, 512.0); | |
+ QString filename = KoResourcePaths::findResource("ko_patterns", "22_texture-reptile.png"); | |
+ QImage image(filename); | |
+ gc->drawImage(target, image, source); | |
+ | |
+ // Draw Line | |
+ pen.setBrush(QColor(255, 200, 0)); gc->setPen(pen); | |
+ gc->drawLine(500, 0, 600, 100); | |
+ | |
+ // Draw Lines | |
+ pen.setBrush(QColor(255, 255, 0)); gc->setPen(pen); | |
+ const QPointF linePoints[4] = { | |
+ QPointF(600.0, 0.0), | |
+ QPointF(700.0, 100.0), | |
+ QPointF(650.0, 0.0), | |
+ QPointF(600.0, 100.0) | |
+ }; | |
+ gc->drawLines(linePoints, 2); | |
+ | |
+ // Draw Path | |
+ pen.setBrush(QColor(200, 255, 0)); gc->setPen(pen); | |
+ QPainterPath path; | |
+ path.moveTo(20, 180); | |
+ path.lineTo(20, 130); | |
+ path.cubicTo(80, 100, 50, 150, 80, 180); | |
+ gc->drawPath(path); | |
+ | |
+ // TODO drawPicture? | |
+ | |
+ // Draw Pie | |
+ pen.setBrush(QColor(150, 255, 0)); gc->setPen(pen); | |
+ QRectF pieRect(110.0, 120.0, 80.0, 60.0); | |
+ int pieStartAngle = 30 * 16; | |
+ int pieSpanAngle = 120 * 16; | |
+ gc->drawPie(pieRect, pieStartAngle, pieSpanAngle); | |
+ | |
+ // TODO drawPixmap? | |
+ | |
+ // TODO drawPixmapFragments? | |
+ | |
+ // Draw Point | |
+ pen.setBrush(QColor(100, 255, 0)); gc->setPen(pen); | |
+ gc->drawPoint(250, 150); | |
+ | |
+ // Draw Points | |
+ pen.setBrush(QColor(50, 255, 0)); gc->setPen(pen); | |
+ const QPointF pointPoints[4] = { | |
+ QPointF(320.0, 120.0), | |
+ QPointF(380.0, 120.0), | |
+ QPointF(320.0, 180.0), | |
+ QPointF(380.0, 180.0) | |
+ }; | |
+ gc->drawPoints(pointPoints, 4); | |
+ | |
+ // Draw Polygon | |
+ pen.setBrush(QColor(0, 255, 0)); gc->setPen(pen); | |
+ const QPointF polyPoints[4] = { | |
+ QPointF(420.0, 120.0), | |
+ QPointF(420.0, 180.0), | |
+ QPointF(480.0, 180.0), | |
+ QPointF(480.0, 120.0) | |
+ }; | |
+ gc->drawPolygon(polyPoints, 4); | |
+ | |
+ // Draw Polyline | |
+ pen.setBrush(QColor(0, 255, 50)); gc->setPen(pen); | |
+ const QPointF polyLinePoints[3] = { | |
+ QPointF(510.0, 180.0), | |
+ QPointF(520.0, 110.0), | |
+ QPointF(580.0, 130.0), | |
+ }; | |
+ gc->drawPolyline(polyLinePoints, 3); | |
+ | |
+ timer.end(); | |
+ qDebug() << "Rendering took" << timer.waitForResult() << "microseconds"; | |
} | |
void KisOpenGLCanvas2::renderDecorations(QPainter *painter) | |
diff --git a/libs/ui/opengl/kis_opengl_canvas2.h b/libs/ui/opengl/kis_opengl_canvas2.h | |
index dc8ddaa..a3d9a83 100644 | |
--- a/libs/ui/opengl/kis_opengl_canvas2.h | |
+++ b/libs/ui/opengl/kis_opengl_canvas2.h | |
@@ -22,6 +22,7 @@ | |
#include <QOpenGLWidget> | |
#include <QOpenGLFunctions> | |
+#include <qopenglvertexarrayobject.h> | |
#include "canvas/kis_canvas_widget_base.h" | |
#include "opengl/kis_opengl_image_textures.h" | |
@@ -67,6 +68,7 @@ public: | |
void initializeDisplayShader(); | |
void renderCanvasGL(); | |
void renderDecorations(QPainter *painter); | |
+ void renderTests(QPainter *painter); | |
void paintToolOutline(const QPainterPath &path); | |
bool needsFpsDebugging() const; | |
diff --git a/plugins/assistants/RulerAssistant/PerspectiveAssistant.cc b/plugins/assistants/RulerAssistant/PerspectiveAssistant.cc | |
index d837ba6..02d866b 100644 | |
--- a/plugins/assistants/RulerAssistant/PerspectiveAssistant.cc | |
+++ b/plugins/assistants/RulerAssistant/PerspectiveAssistant.cc | |
@@ -269,6 +269,8 @@ void PerspectiveAssistant::drawCache(QPainter& gc, const KisCoordinatesConverter | |
if (assistantVisible==false) { | |
return; | |
} | |
+ | |
+ | |
gc.setTransform(converter->documentToWidgetTransform()); | |
QPolygonF poly; | |
QTransform transform; | |
diff --git a/plugins/assistants/RulerAssistant/kis_ruler_assistant_tool.cc b/plugins/assistants/RulerAssistant/kis_ruler_assistant_tool.cc | |
index 256296d..36b62c7 100644 | |
--- a/plugins/assistants/RulerAssistant/kis_ruler_assistant_tool.cc | |
+++ b/plugins/assistants/RulerAssistant/kis_ruler_assistant_tool.cc | |
@@ -576,13 +576,12 @@ void KisRulerAssistantTool::mouseMoveEvent(KoPointerEvent *event) | |
void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_converter) | |
{ | |
- | |
QPixmap iconDelete = KisIconUtils::loadIcon("dialog-cancel").pixmap(16, 16); | |
QPixmap iconSnapOn = KisIconUtils::loadIcon("visible").pixmap(16, 16); | |
QPixmap iconSnapOff = KisIconUtils::loadIcon("novisible").pixmap(16, 16); | |
QPixmap iconMove = KisIconUtils::loadIcon("transform-move").pixmap(32, 32); | |
QColor handlesColor(0, 0, 0, 125); | |
- | |
+ | |
if (m_newAssistant) { | |
m_newAssistant->drawAssistant(_gc, QRectF(QPointF(0, 0), QSizeF(m_canvas->image()->size())), m_canvas->coordinatesConverter(), false,m_canvas, true, false); | |
Q_FOREACH (const KisPaintingAssistantHandleSP handle, m_newAssistant->handles()) { | |
@@ -594,7 +593,7 @@ void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_convert | |
// TODO: too many Q_FOREACH loops going through all assistants. Condense this to one to be a little more performant | |
- // render handles for the asssistant | |
+ // Draw corner and middle perspective nodes | |
Q_FOREACH (KisPaintingAssistantSP assistant, m_canvas->paintingAssistantsDecoration()->assistants()) { | |
Q_FOREACH (const KisPaintingAssistantHandleSP handle, m_handles) { | |
QRectF ellipse(_converter.documentToView(*handle) - QPointF(6, 6), QSizeF(12, 12)); | |
@@ -625,9 +624,8 @@ void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_convert | |
} | |
} | |
- | |
- | |
Q_FOREACH (KisPaintingAssistantSP assistant, m_canvas->paintingAssistantsDecoration()->assistants()) { | |
+ // Draw middle perspective handles | |
if(assistant->id()=="perspective") { | |
assistant->findHandleLocation(); | |
QPointF topMiddle, bottomMiddle, rightMiddle, leftMiddle; | |
@@ -663,7 +661,7 @@ void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_convert | |
} | |
} | |
- | |
+ // Draw the assistant widget | |
Q_FOREACH (const KisPaintingAssistantSP assistant, m_canvas->paintingAssistantsDecoration()->assistants()) { | |
@@ -691,7 +689,6 @@ void KisRulerAssistantTool::paint(QPainter& _gc, const KoViewConverter &_convert | |
_gc.fillPath(bgPath, backgroundColor); | |
_gc.drawPath(bgPath); | |
- | |
QPainterPath movePath; // render circle behind by move helper | |
_gc.setPen(stroke); | |
movePath.addEllipse(iconMovePosition.x()-5, iconMovePosition.y()-5, 40, 40);// background behind icon | |
diff --git a/plugins/dockers/lut/ocio_display_filter.cpp b/plugins/dockers/lut/ocio_display_filter.cpp | |
index 6f8bbe0..fead27f 100644 | |
--- a/plugins/dockers/lut/ocio_display_filter.cpp | |
+++ b/plugins/dockers/lut/ocio_display_filter.cpp | |
@@ -307,7 +307,7 @@ void OcioDisplayFilter::updateShader() | |
// Step 1: Create a GPU Shader Description | |
OCIO::GpuShaderDesc shaderDesc; | |
- if (KisOpenGL::supportsGLSL13()) { | |
+ if (KisOpenGL::hasOpenGL3()) { | |
shaderDesc.setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_3); | |
} | |
else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment