Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/opengl/kis_opengl_image_textures.cpp
Show All 12 Lines | |||||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "opengl/kis_opengl_image_textures.h" | 19 | #include "opengl/kis_opengl_image_textures.h" | ||
20 | 20 | | |||
21 | #ifdef HAS_ONLY_OPENGL_ES | ||||
22 | #include <qopengl.h> | ||||
23 | #endif | ||||
24 | | ||||
25 | #ifndef HAS_ONLY_OPENGL_ES | ||||
21 | #include <QOpenGLFunctions> | 26 | #include <QOpenGLFunctions> | ||
27 | #endif | ||||
22 | #include <QOpenGLContext> | 28 | #include <QOpenGLContext> | ||
23 | 29 | | |||
24 | #include <QMessageBox> | 30 | #include <QMessageBox> | ||
25 | #include <QApplication> | 31 | #include <QApplication> | ||
26 | #include <QDesktopWidget> | 32 | #include <QDesktopWidget> | ||
27 | 33 | | |||
28 | #include <KoColorSpaceRegistry.h> | 34 | #include <KoColorSpaceRegistry.h> | ||
29 | #include <KoColorProfile.h> | 35 | #include <KoColorProfile.h> | ||
▲ Show 20 Lines • Show All 423 Lines • ▼ Show 20 Line(s) | |||||
453 | 459 | | |||
454 | namespace { | 460 | namespace { | ||
455 | void initializeRGBA16FTextures(QOpenGLContext *ctx, KisGLTexturesInfo &texturesInfo, KoID &destinationColorDepthId) | 461 | void initializeRGBA16FTextures(QOpenGLContext *ctx, KisGLTexturesInfo &texturesInfo, KoID &destinationColorDepthId) | ||
456 | { | 462 | { | ||
457 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | 463 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | ||
458 | texturesInfo.internalFormat = GL_RGBA16F; | 464 | texturesInfo.internalFormat = GL_RGBA16F; | ||
459 | dbgUI << "Using half (GLES or GL3)"; | 465 | dbgUI << "Using half (GLES or GL3)"; | ||
460 | } else if (ctx->hasExtension("GL_ARB_texture_float")) { | 466 | } else if (ctx->hasExtension("GL_ARB_texture_float")) { | ||
467 | #ifndef HAS_ONLY_OPENGL_ES | ||||
461 | texturesInfo.internalFormat = GL_RGBA16F_ARB; | 468 | texturesInfo.internalFormat = GL_RGBA16F_ARB; | ||
462 | dbgUI << "Using ARB half"; | 469 | dbgUI << "Using ARB half"; | ||
463 | } | 470 | } | ||
464 | else if (ctx->hasExtension("GL_ATI_texture_float")) { | 471 | else if (ctx->hasExtension("GL_ATI_texture_float")) { | ||
465 | texturesInfo.internalFormat = GL_RGBA_FLOAT16_ATI; | 472 | texturesInfo.internalFormat = GL_RGBA_FLOAT16_ATI; | ||
466 | dbgUI << "Using ATI half"; | 473 | dbgUI << "Using ATI half"; | ||
474 | #else | ||||
475 | KIS_ASSERT_X(false, "initializeRGBA16FTextures", | ||||
476 | "Unexpected KisOpenGL::hasOpenGLES and \ | ||||
477 | KisOpenGL::hasOpenGL3 returned false"); | ||||
478 | #endif | ||||
467 | } | 479 | } | ||
468 | 480 | | |||
469 | bool haveBuiltInOpenExr = false; | 481 | bool haveBuiltInOpenExr = false; | ||
470 | #ifdef HAVE_OPENEXR | 482 | #ifdef HAVE_OPENEXR | ||
471 | haveBuiltInOpenExr = true; | 483 | haveBuiltInOpenExr = true; | ||
472 | #endif | 484 | #endif | ||
473 | 485 | | |||
474 | if (haveBuiltInOpenExr && (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3())) { | 486 | if (haveBuiltInOpenExr && (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3())) { | ||
475 | texturesInfo.type = GL_HALF_FLOAT; | 487 | texturesInfo.type = GL_HALF_FLOAT; | ||
476 | destinationColorDepthId = Float16BitsColorDepthID; | 488 | destinationColorDepthId = Float16BitsColorDepthID; | ||
477 | dbgUI << "Pixel type half (GLES or GL3)"; | 489 | dbgUI << "Pixel type half (GLES or GL3)"; | ||
478 | } else if (haveBuiltInOpenExr && ctx->hasExtension("GL_ARB_half_float_pixel")) { | 490 | } else if (haveBuiltInOpenExr && ctx->hasExtension("GL_ARB_half_float_pixel")) { | ||
491 | #ifndef HAS_ONLY_OPENGL_ES | ||||
479 | texturesInfo.type = GL_HALF_FLOAT_ARB; | 492 | texturesInfo.type = GL_HALF_FLOAT_ARB; | ||
480 | destinationColorDepthId = Float16BitsColorDepthID; | 493 | destinationColorDepthId = Float16BitsColorDepthID; | ||
481 | dbgUI << "Pixel type half"; | 494 | dbgUI << "Pixel type half"; | ||
482 | } else { | 495 | } else { | ||
483 | texturesInfo.type = GL_FLOAT; | 496 | texturesInfo.type = GL_FLOAT; | ||
484 | destinationColorDepthId = Float32BitsColorDepthID; | 497 | destinationColorDepthId = Float32BitsColorDepthID; | ||
485 | dbgUI << "Pixel type float"; | 498 | dbgUI << "Pixel type float"; | ||
499 | #else | ||||
500 | KIS_ASSERT_X(false, "KisOpenGLCanvas2::paintToolOutline", | ||||
501 | "Unexpected KisOpenGL::hasOpenGLES and \ | ||||
502 | KisOpenGL::hasOpenGL3 returned false"); | ||||
503 | #endif | ||||
486 | } | 504 | } | ||
487 | texturesInfo.format = GL_RGBA; | 505 | texturesInfo.format = GL_RGBA; | ||
488 | } | 506 | } | ||
489 | } | 507 | } | ||
490 | 508 | | |||
491 | void KisOpenGLImageTextures::updateTextureFormat() | 509 | void KisOpenGLImageTextures::updateTextureFormat() | ||
492 | { | 510 | { | ||
493 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | 511 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | ||
494 | if (!(m_image && ctx)) return; | 512 | if (!(m_image && ctx)) return; | ||
495 | 513 | | |||
496 | if (!KisOpenGL::hasOpenGLES()) { | 514 | if (!KisOpenGL::hasOpenGLES()) { | ||
515 | #ifndef HAS_ONLY_OPENGL_ES | ||||
497 | m_texturesInfo.internalFormat = GL_RGBA8; | 516 | m_texturesInfo.internalFormat = GL_RGBA8; | ||
498 | m_texturesInfo.type = GL_UNSIGNED_BYTE; | 517 | m_texturesInfo.type = GL_UNSIGNED_BYTE; | ||
499 | m_texturesInfo.format = GL_BGRA; | 518 | m_texturesInfo.format = GL_BGRA; | ||
519 | #else | ||||
520 | KIS_ASSERT_X(false, "KisOpenGLImageTextures::updateTextureFormat", | ||||
521 | "Unexpected KisOpenGL::hasOpenGLES returned false"); | ||||
522 | #endif | ||||
500 | } else { | 523 | } else { | ||
501 | m_texturesInfo.internalFormat = GL_BGRA8_EXT; | 524 | m_texturesInfo.internalFormat = GL_BGRA8_EXT; | ||
502 | m_texturesInfo.type = GL_UNSIGNED_BYTE; | 525 | m_texturesInfo.type = GL_UNSIGNED_BYTE; | ||
503 | m_texturesInfo.format = GL_BGRA_EXT; | 526 | m_texturesInfo.format = GL_BGRA_EXT; | ||
504 | if(!ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_format_BGRA8888"))) { | 527 | if(!ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_format_BGRA8888"))) { | ||
505 | // The red and blue channels are swapped, but it will be re-swapped | 528 | // The red and blue channels are swapped, but it will be re-swapped | ||
506 | // by texture swizzle mask set in KisTextureTile::setTextureParameters | 529 | // by texture swizzle mask set in KisTextureTile::setTextureParameters | ||
507 | m_texturesInfo.internalFormat = GL_RGBA8; | 530 | m_texturesInfo.internalFormat = GL_RGBA8; | ||
Show All 15 Lines | 545 | if (colorModelId == RGBAColorModelID) { | |||
523 | if (colorDepthId == Float16BitsColorDepthID) { | 546 | if (colorDepthId == Float16BitsColorDepthID) { | ||
524 | initializeRGBA16FTextures(ctx, m_texturesInfo, destinationColorDepthId); | 547 | initializeRGBA16FTextures(ctx, m_texturesInfo, destinationColorDepthId); | ||
525 | } | 548 | } | ||
526 | else if (colorDepthId == Float32BitsColorDepthID) { | 549 | else if (colorDepthId == Float32BitsColorDepthID) { | ||
527 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | 550 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | ||
528 | m_texturesInfo.internalFormat = GL_RGBA32F; | 551 | m_texturesInfo.internalFormat = GL_RGBA32F; | ||
529 | dbgUI << "Using float (GLES or GL3)"; | 552 | dbgUI << "Using float (GLES or GL3)"; | ||
530 | } else if (ctx->hasExtension("GL_ARB_texture_float")) { | 553 | } else if (ctx->hasExtension("GL_ARB_texture_float")) { | ||
554 | #ifndef HAS_ONLY_OPENGL_ES | ||||
531 | m_texturesInfo.internalFormat = GL_RGBA32F_ARB; | 555 | m_texturesInfo.internalFormat = GL_RGBA32F_ARB; | ||
532 | dbgUI << "Using ARB float"; | 556 | dbgUI << "Using ARB float"; | ||
533 | } else if (ctx->hasExtension("GL_ATI_texture_float")) { | 557 | } else if (ctx->hasExtension("GL_ATI_texture_float")) { | ||
534 | m_texturesInfo.internalFormat = GL_RGBA_FLOAT32_ATI; | 558 | m_texturesInfo.internalFormat = GL_RGBA_FLOAT32_ATI; | ||
535 | dbgUI << "Using ATI float"; | 559 | dbgUI << "Using ATI float"; | ||
560 | #else | ||||
561 | KIS_ASSERT_X(false, "KisOpenGLCanvas2::updateTextureFormat", | ||||
562 | "Unexpected KisOpenGL::hasOpenGLES and \ | ||||
563 | KisOpenGL::hasOpenGL3 returned false"); | ||||
564 | #endif | ||||
536 | } | 565 | } | ||
537 | 566 | | |||
538 | m_texturesInfo.type = GL_FLOAT; | 567 | m_texturesInfo.type = GL_FLOAT; | ||
539 | m_texturesInfo.format = GL_RGBA; | 568 | m_texturesInfo.format = GL_RGBA; | ||
540 | destinationColorDepthId = Float32BitsColorDepthID; | 569 | destinationColorDepthId = Float32BitsColorDepthID; | ||
541 | } | 570 | } | ||
542 | else if (colorDepthId == Integer16BitsColorDepthID) { | 571 | else if (colorDepthId == Integer16BitsColorDepthID) { | ||
572 | #ifndef HAS_ONLY_OPENGL_ES | ||||
543 | if (!KisOpenGL::hasOpenGLES()) { | 573 | if (!KisOpenGL::hasOpenGLES()) { | ||
544 | m_texturesInfo.internalFormat = GL_RGBA16; | 574 | m_texturesInfo.internalFormat = GL_RGBA16; | ||
545 | m_texturesInfo.type = GL_UNSIGNED_SHORT; | 575 | m_texturesInfo.type = GL_UNSIGNED_SHORT; | ||
546 | m_texturesInfo.format = GL_BGRA; | 576 | m_texturesInfo.format = GL_BGRA; | ||
547 | destinationColorDepthId = Integer16BitsColorDepthID; | 577 | destinationColorDepthId = Integer16BitsColorDepthID; | ||
548 | dbgUI << "Using 16 bits rgba"; | 578 | dbgUI << "Using 16 bits rgba"; | ||
549 | } | 579 | } | ||
580 | #endif | ||||
550 | // TODO: for ANGLE, see if we can convert to 16f to support 10-bit display | 581 | // TODO: for ANGLE, see if we can convert to 16f to support 10-bit display | ||
551 | } | 582 | } | ||
552 | } | 583 | } | ||
553 | else { | 584 | else { | ||
554 | // We will convert the colorspace to 16 bits rgba, instead of 8 bits | 585 | // We will convert the colorspace to 16 bits rgba, instead of 8 bits | ||
555 | if (colorDepthId == Integer16BitsColorDepthID && !KisOpenGL::hasOpenGLES()) { | 586 | if (colorDepthId == Integer16BitsColorDepthID && !KisOpenGL::hasOpenGLES()) { | ||
587 | #ifndef HAS_ONLY_OPENGL_ES | ||||
556 | m_texturesInfo.internalFormat = GL_RGBA16; | 588 | m_texturesInfo.internalFormat = GL_RGBA16; | ||
557 | m_texturesInfo.type = GL_UNSIGNED_SHORT; | 589 | m_texturesInfo.type = GL_UNSIGNED_SHORT; | ||
558 | m_texturesInfo.format = GL_BGRA; | 590 | m_texturesInfo.format = GL_BGRA; | ||
559 | destinationColorDepthId = Integer16BitsColorDepthID; | 591 | destinationColorDepthId = Integer16BitsColorDepthID; | ||
560 | dbgUI << "Using conversion to 16 bits rgba"; | 592 | dbgUI << "Using conversion to 16 bits rgba"; | ||
593 | #else | ||||
594 | KIS_ASSERT_X(false, "KisOpenGLCanvas2::updateTextureFormat", | ||||
595 | "Unexpected KisOpenGL::hasOpenGLES returned false"); | ||||
596 | #endif | ||||
561 | } else if (colorDepthId == Float16BitsColorDepthID && KisOpenGL::hasOpenGLES()) { | 597 | } else if (colorDepthId == Float16BitsColorDepthID && KisOpenGL::hasOpenGLES()) { | ||
562 | // TODO: try removing opengl es limit | 598 | // TODO: try removing opengl es limit | ||
563 | initializeRGBA16FTextures(ctx, m_texturesInfo, destinationColorDepthId); | 599 | initializeRGBA16FTextures(ctx, m_texturesInfo, destinationColorDepthId); | ||
564 | } | 600 | } | ||
565 | // TODO: for ANGLE, see if we can convert to 16f to support 10-bit display | 601 | // TODO: for ANGLE, see if we can convert to 16f to support 10-bit display | ||
566 | } | 602 | } | ||
567 | 603 | | |||
568 | if (!m_internalColorManagementActive && | 604 | if (!m_internalColorManagementActive && | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |