Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/opengl/kis_opengl_canvas2.cpp
Show All 40 Lines | |||||
41 | #include <QFile> | 41 | #include <QFile> | ||
42 | #include <QOpenGLShaderProgram> | 42 | #include <QOpenGLShaderProgram> | ||
43 | #include <QOpenGLVertexArrayObject> | 43 | #include <QOpenGLVertexArrayObject> | ||
44 | #include <QOpenGLBuffer> | 44 | #include <QOpenGLBuffer> | ||
45 | #include <QMessageBox> | 45 | #include <QMessageBox> | ||
46 | #include "KisOpenGLModeProber.h" | 46 | #include "KisOpenGLModeProber.h" | ||
47 | #include <KoColorModelStandardIds.h> | 47 | #include <KoColorModelStandardIds.h> | ||
48 | 48 | | |||
49 | #ifndef Q_OS_OSX | 49 | #if !defined(Q_OS_OSX) && !defined(HAS_ONLY_OPENGL_ES) | ||
50 | #include <QOpenGLFunctions_2_1> | 50 | #include <QOpenGLFunctions_2_1> | ||
51 | #endif | 51 | #endif | ||
52 | 52 | | |||
53 | #define NEAR_VAL -1000.0 | 53 | #define NEAR_VAL -1000.0 | ||
54 | #define FAR_VAL 1000.0 | 54 | #define FAR_VAL 1000.0 | ||
55 | 55 | | |||
56 | #ifndef GL_CLAMP_TO_EDGE | 56 | #ifndef GL_CLAMP_TO_EDGE | ||
57 | #define GL_CLAMP_TO_EDGE 0x812F | 57 | #define GL_CLAMP_TO_EDGE 0x812F | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 67 | public: | |||
99 | 99 | | |||
100 | // Stores data for drawing tool outlines | 100 | // Stores data for drawing tool outlines | ||
101 | QOpenGLVertexArrayObject outlineVAO; | 101 | QOpenGLVertexArrayObject outlineVAO; | ||
102 | QOpenGLBuffer lineBuffer; | 102 | QOpenGLBuffer lineBuffer; | ||
103 | 103 | | |||
104 | QVector3D vertices[6]; | 104 | QVector3D vertices[6]; | ||
105 | QVector2D texCoords[6]; | 105 | QVector2D texCoords[6]; | ||
106 | 106 | | |||
107 | #ifndef Q_OS_OSX | 107 | #if !defined(Q_OS_OSX) && !defined(HAS_ONLY_OPENGL_ES) | ||
108 | QOpenGLFunctions_2_1 *glFn201; | 108 | QOpenGLFunctions_2_1 *glFn201; | ||
109 | #endif | 109 | #endif | ||
110 | 110 | | |||
111 | qreal pixelGridDrawingThreshold; | 111 | qreal pixelGridDrawingThreshold; | ||
112 | bool pixelGridEnabled; | 112 | bool pixelGridEnabled; | ||
113 | QColor gridColor; | 113 | QColor gridColor; | ||
114 | QColor cursorColor; | 114 | QColor cursorColor; | ||
115 | 115 | | |||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 240 | { | |||
245 | texCoords[4] = QVector2D(rc.right(), rc.top()); | 245 | texCoords[4] = QVector2D(rc.right(), rc.top()); | ||
246 | texCoords[5] = QVector2D(rc.right(), rc.bottom()); | 246 | texCoords[5] = QVector2D(rc.right(), rc.bottom()); | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | void KisOpenGLCanvas2::initializeGL() | 249 | void KisOpenGLCanvas2::initializeGL() | ||
250 | { | 250 | { | ||
251 | KisOpenGL::initializeContext(context()); | 251 | KisOpenGL::initializeContext(context()); | ||
252 | initializeOpenGLFunctions(); | 252 | initializeOpenGLFunctions(); | ||
253 | #ifndef Q_OS_OSX | 253 | #if !defined(Q_OS_OSX) && !defined(HAS_ONLY_OPENGL_ES) | ||
254 | if (!KisOpenGL::hasOpenGLES()) { | 254 | if (!KisOpenGL::hasOpenGLES()) { | ||
255 | d->glFn201 = context()->versionFunctions<QOpenGLFunctions_2_1>(); | 255 | d->glFn201 = context()->versionFunctions<QOpenGLFunctions_2_1>(); | ||
256 | if (!d->glFn201) { | 256 | if (!d->glFn201) { | ||
257 | warnUI << "Cannot obtain QOpenGLFunctions_2_1, glLogicOp cannot be used"; | 257 | warnUI << "Cannot obtain QOpenGLFunctions_2_1, glLogicOp cannot be used"; | ||
258 | } | 258 | } | ||
259 | } else { | 259 | } else { | ||
260 | d->glFn201 = nullptr; | 260 | d->glFn201 = nullptr; | ||
261 | } | 261 | } | ||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Line(s) | 402 | { | |||
411 | 411 | | |||
412 | // Set view/projection matrices | 412 | // Set view/projection matrices | ||
413 | QMatrix4x4 modelMatrix(coordinatesConverter()->flakeToWidgetTransform()); | 413 | QMatrix4x4 modelMatrix(coordinatesConverter()->flakeToWidgetTransform()); | ||
414 | modelMatrix.optimize(); | 414 | modelMatrix.optimize(); | ||
415 | modelMatrix = projectionMatrix * modelMatrix; | 415 | modelMatrix = projectionMatrix * modelMatrix; | ||
416 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | 416 | d->solidColorShader->setUniformValue(d->solidColorShader->location(Uniform::ModelViewProjection), modelMatrix); | ||
417 | 417 | | |||
418 | if (!KisOpenGL::hasOpenGLES()) { | 418 | if (!KisOpenGL::hasOpenGLES()) { | ||
419 | #ifndef HAS_ONLY_OPENGL_ES | ||||
apol: I think it would make sense to have a `HAVE_OPENGL`, it reads random not wanting to do that on… | |||||
I would suggest to use something like HAVE_OPENGL_ES_NO_DESKTOP_OPENGL, maybe in some alternative wording. It should deliver the meaning that OpenGL ES library is available but full desktop OpenGL is not. alvinhochun: I would suggest to use something like `HAVE_OPENGL_ES_NO_DESKTOP_OPENGL`, maybe in some… | |||||
419 | glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); | 420 | glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); | ||
420 | 421 | | |||
421 | glEnable(GL_COLOR_LOGIC_OP); | 422 | glEnable(GL_COLOR_LOGIC_OP); | ||
422 | #ifndef Q_OS_OSX | 423 | #ifndef Q_OS_OSX | ||
423 | if (d->glFn201) { | 424 | if (d->glFn201) { | ||
424 | d->glFn201->glLogicOp(GL_XOR); | 425 | d->glFn201->glLogicOp(GL_XOR); | ||
425 | } | 426 | } | ||
426 | #else | 427 | #else | ||
427 | glLogicOp(GL_XOR); | 428 | glLogicOp(GL_XOR); | ||
428 | #endif | 429 | #endif // Q_OS_OSX | ||
430 | | ||||
431 | #else // HAS_ONLY_OPENGL_ES | ||||
432 | KIS_ASSERT_X(false, "KisOpenGLCanvas2::paintToolOutline", | ||||
433 | "Unexpected KisOpenGL::hasOpenGLES returned false"); | ||||
434 | #endif // HAS_ONLY_OPENGL_ES | ||||
429 | } else { | 435 | } else { | ||
430 | glEnable(GL_BLEND); | 436 | glEnable(GL_BLEND); | ||
431 | glBlendFuncSeparate(GL_ONE_MINUS_DST_COLOR, GL_ZERO, GL_ONE, GL_ONE); | 437 | glBlendFuncSeparate(GL_ONE_MINUS_DST_COLOR, GL_ZERO, GL_ONE, GL_ONE); | ||
432 | } | 438 | } | ||
433 | 439 | | |||
434 | d->solidColorShader->setUniformValue( | 440 | d->solidColorShader->setUniformValue( | ||
435 | d->solidColorShader->location(Uniform::FragmentColor), | 441 | d->solidColorShader->location(Uniform::FragmentColor), | ||
436 | QVector4D(d->cursorColor.redF(), d->cursorColor.greenF(), d->cursorColor.blueF(), 1.0f)); | 442 | QVector4D(d->cursorColor.redF(), d->cursorColor.greenF(), d->cursorColor.blueF(), 1.0f)); | ||
Show All 29 Lines | |||||
466 | } | 472 | } | ||
467 | 473 | | |||
468 | if (KisOpenGL::hasOpenGL3()) { | 474 | if (KisOpenGL::hasOpenGL3()) { | ||
469 | d->lineBuffer.release(); | 475 | d->lineBuffer.release(); | ||
470 | d->outlineVAO.release(); | 476 | d->outlineVAO.release(); | ||
471 | } | 477 | } | ||
472 | 478 | | |||
473 | if (!KisOpenGL::hasOpenGLES()) { | 479 | if (!KisOpenGL::hasOpenGLES()) { | ||
480 | #ifndef HAS_ONLY_OPENGL_ES | ||||
474 | glDisable(GL_COLOR_LOGIC_OP); | 481 | glDisable(GL_COLOR_LOGIC_OP); | ||
482 | #else | ||||
483 | KIS_ASSERT_X(false, "KisOpenGLCanvas2::paintToolOutline", | ||||
484 | "Unexpected KisOpenGL::hasOpenGLES returned false"); | ||||
485 | #endif | ||||
475 | } else { | 486 | } else { | ||
476 | glDisable(GL_BLEND); | 487 | glDisable(GL_BLEND); | ||
477 | } | 488 | } | ||
478 | 489 | | |||
479 | d->solidColorShader->release(); | 490 | d->solidColorShader->release(); | ||
480 | } | 491 | } | ||
481 | 492 | | |||
482 | bool KisOpenGLCanvas2::isBusy() const | 493 | bool KisOpenGLCanvas2::isBusy() const | ||
▲ Show 20 Lines • Show All 502 Lines • Show Last 20 Lines |
I think it would make sense to have a HAVE_OPENGL, it reads random not wanting to do that on a specific platform. (for this one and similar cases).