Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/opengl/kis_opengl_image_textures.cpp
Context not available. | |||||
32 | #include "kis_image.h" | 32 | #include "kis_image.h" | ||
---|---|---|---|---|---|
33 | #include "kis_config.h" | 33 | #include "kis_config.h" | ||
34 | #include "KisPart.h" | 34 | #include "KisPart.h" | ||
35 | #include "KisOpenGLModeProber.h" | ||||
35 | 36 | | |||
36 | #ifdef HAVE_OPENEXR | 37 | #ifdef HAVE_OPENEXR | ||
37 | #include <half.h> | 38 | #include <half.h> | ||
Context not available. | |||||
59 | KisOpenGLImageTextures::KisOpenGLImageTextures() | 60 | KisOpenGLImageTextures::KisOpenGLImageTextures() | ||
60 | : m_image(0) | 61 | : m_image(0) | ||
61 | , m_monitorProfile(0) | 62 | , m_monitorProfile(0) | ||
62 | , m_tilesDestinationColorSpace(0) | | |||
63 | , m_internalColorManagementActive(true) | 63 | , m_internalColorManagementActive(true) | ||
64 | , m_checkerTexture(0) | 64 | , m_checkerTexture(0) | ||
65 | , m_glFuncs(0) | 65 | , m_glFuncs(0) | ||
Context not available. | |||||
83 | , m_monitorProfile(monitorProfile) | 83 | , m_monitorProfile(monitorProfile) | ||
84 | , m_renderingIntent(renderingIntent) | 84 | , m_renderingIntent(renderingIntent) | ||
85 | , m_conversionFlags(conversionFlags) | 85 | , m_conversionFlags(conversionFlags) | ||
86 | , m_tilesDestinationColorSpace(0) | | |||
87 | , m_internalColorManagementActive(true) | 86 | , m_internalColorManagementActive(true) | ||
88 | , m_checkerTexture(0) | 87 | , m_checkerTexture(0) | ||
89 | , m_glFuncs(0) | 88 | , m_glFuncs(0) | ||
Context not available. | |||||
109 | m_updateInfoBuilder.setTextureInfoPool(s_poolRegistry.getPool(m_texturesInfo.width, m_texturesInfo.height)); | 108 | m_updateInfoBuilder.setTextureInfoPool(s_poolRegistry.getPool(m_texturesInfo.width, m_texturesInfo.height)); | ||
110 | 109 | | |||
111 | m_glFuncs->glGenTextures(1, &m_checkerTexture); | 110 | m_glFuncs->glGenTextures(1, &m_checkerTexture); | ||
112 | createImageTextureTiles(); | 111 | recreateImageTextureTiles(); | ||
113 | 112 | | |||
114 | KisOpenGLUpdateInfoSP info = updateCache(m_image->bounds(), m_image); | 113 | KisOpenGLUpdateInfoSP info = updateCache(m_image->bounds(), m_image); | ||
115 | recalculateCache(info, false); | 114 | recalculateCache(info, false); | ||
Context not available. | |||||
175 | } | 174 | } | ||
176 | } | 175 | } | ||
177 | 176 | | |||
178 | void KisOpenGLImageTextures::createImageTextureTiles() | 177 | void KisOpenGLImageTextures::recreateImageTextureTiles() | ||
179 | { | 178 | { | ||
180 | 179 | | |||
181 | destroyImageTextureTiles(); | 180 | destroyImageTextureTiles(); | ||
182 | updateTextureFormat(); | 181 | updateTextureFormat(); | ||
183 | 182 | | |||
184 | if (!m_tilesDestinationColorSpace) { | 183 | const KoColorSpace *tilesDestinationColorSpace = | ||
184 | m_updateInfoBuilder.destinationColorSpace(); | ||||
185 | | ||||
186 | if (!tilesDestinationColorSpace) { | ||||
185 | qDebug() << "No destination colorspace!!!!"; | 187 | qDebug() << "No destination colorspace!!!!"; | ||
186 | return; | 188 | return; | ||
187 | } | 189 | } | ||
Context not available. | |||||
194 | m_numCols = lastCol + 1; | 196 | m_numCols = lastCol + 1; | ||
195 | 197 | | |||
196 | // Default color is transparent black | 198 | // Default color is transparent black | ||
197 | const int pixelSize = m_tilesDestinationColorSpace->pixelSize(); | 199 | const int pixelSize = tilesDestinationColorSpace->pixelSize(); | ||
198 | QByteArray emptyTileData((m_texturesInfo.width) * (m_texturesInfo.height) * pixelSize, 0); | 200 | QByteArray emptyTileData((m_texturesInfo.width) * (m_texturesInfo.height) * pixelSize, 0); | ||
199 | 201 | | |||
200 | KisConfig config(true); | 202 | KisConfig config(true); | ||
Context not available. | |||||
339 | 341 | | |||
340 | void KisOpenGLImageTextures::slotImageSizeChanged(qint32 /*w*/, qint32 /*h*/) | 342 | void KisOpenGLImageTextures::slotImageSizeChanged(qint32 /*w*/, qint32 /*h*/) | ||
341 | { | 343 | { | ||
342 | createImageTextureTiles(); | 344 | recreateImageTextureTiles(); | ||
343 | } | 345 | } | ||
344 | 346 | | |||
345 | KisOpenGLUpdateInfoBuilder &KisOpenGLImageTextures::updateInfoBuilder() | 347 | KisOpenGLUpdateInfoBuilder &KisOpenGLImageTextures::updateInfoBuilder() | ||
Context not available. | |||||
354 | m_renderingIntent = renderingIntent; | 356 | m_renderingIntent = renderingIntent; | ||
355 | m_conversionFlags = conversionFlags; | 357 | m_conversionFlags = conversionFlags; | ||
356 | 358 | | |||
357 | m_updateInfoBuilder.setConversionOptions( | 359 | recreateImageTextureTiles(); | ||
358 | ConversionOptions(m_tilesDestinationColorSpace, | 360 | } | ||
359 | m_renderingIntent, | 361 | | ||
360 | m_conversionFlags)); | 362 | bool KisOpenGLImageTextures::setImageColorSpace(const KoColorSpace *cs) | ||
363 | { | ||||
364 | Q_UNUSED(cs); | ||||
365 | // TODO: implement lazy update: do not re-upload textures when not needed | ||||
361 | 366 | | |||
362 | createImageTextureTiles(); | 367 | recreateImageTextureTiles(); | ||
368 | return true; | ||||
363 | } | 369 | } | ||
364 | 370 | | |||
365 | void KisOpenGLImageTextures::setChannelFlags(const QBitArray &channelFlags) | 371 | void KisOpenGLImageTextures::setChannelFlags(const QBitArray &channelFlags) | ||
Context not available. | |||||
436 | 442 | | |||
437 | if (needsFinalRegeneration) { | 443 | if (needsFinalRegeneration) { | ||
438 | m_internalColorManagementActive = value; | 444 | m_internalColorManagementActive = value; | ||
439 | createImageTextureTiles(); | 445 | recreateImageTextureTiles(); | ||
440 | 446 | | |||
441 | // at this point the value of m_internalColorManagementActive might | 447 | // at this point the value of m_internalColorManagementActive might | ||
442 | // have been forcely reverted to 'false' in case of some problems | 448 | // have been forcely reverted to 'false' in case of some problems | ||
Context not available. | |||||
445 | return needsFinalRegeneration; | 451 | return needsFinalRegeneration; | ||
446 | } | 452 | } | ||
447 | 453 | | |||
454 | namespace { | ||||
455 | void initializeRGBA16FTextures(QOpenGLContext *ctx, KisGLTexturesInfo &texturesInfo, KoID &destinationColorDepthId) | ||||
456 | { | ||||
457 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | ||||
458 | texturesInfo.internalFormat = GL_RGBA16F; | ||||
459 | dbgUI << "Using half (GLES or GL3)"; | ||||
460 | } else if (ctx->hasExtension("GL_ARB_texture_float")) { | ||||
461 | texturesInfo.internalFormat = GL_RGBA16F_ARB; | ||||
462 | dbgUI << "Using ARB half"; | ||||
463 | } | ||||
464 | else if (ctx->hasExtension("GL_ATI_texture_float")) { | ||||
465 | texturesInfo.internalFormat = GL_RGBA_FLOAT16_ATI; | ||||
466 | dbgUI << "Using ATI half"; | ||||
467 | } | ||||
468 | | ||||
469 | bool haveBuiltInOpenExr = false; | ||||
470 | #ifdef HAVE_OPENEXR | ||||
471 | haveBuiltInOpenExr = true; | ||||
472 | #endif | ||||
473 | | ||||
474 | if (haveBuiltInOpenExr && (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3())) { | ||||
475 | texturesInfo.type = GL_HALF_FLOAT; | ||||
476 | destinationColorDepthId = Float16BitsColorDepthID; | ||||
477 | dbgUI << "Pixel type half (GLES or GL3)"; | ||||
478 | } else if (haveBuiltInOpenExr && ctx->hasExtension("GL_ARB_half_float_pixel")) { | ||||
479 | texturesInfo.type = GL_HALF_FLOAT_ARB; | ||||
480 | destinationColorDepthId = Float16BitsColorDepthID; | ||||
481 | dbgUI << "Pixel type half"; | ||||
482 | } else { | ||||
483 | texturesInfo.type = GL_FLOAT; | ||||
484 | destinationColorDepthId = Float32BitsColorDepthID; | ||||
485 | dbgUI << "Pixel type float"; | ||||
486 | } | ||||
487 | texturesInfo.format = GL_RGBA; | ||||
488 | } | ||||
489 | } | ||||
490 | | ||||
448 | void KisOpenGLImageTextures::updateTextureFormat() | 491 | void KisOpenGLImageTextures::updateTextureFormat() | ||
449 | { | 492 | { | ||
450 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | 493 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | ||
Context not available. | |||||
467 | } | 510 | } | ||
468 | } | 511 | } | ||
469 | 512 | | |||
470 | KoID colorModelId = m_image->colorSpace()->colorModelId(); | 513 | const bool useHDRMode = KisOpenGLModeProber::instance()->useHDRMode(); | ||
471 | KoID colorDepthId = m_image->colorSpace()->colorDepthId(); | 514 | const KoID colorModelId = m_image->colorSpace()->colorModelId(); | ||
515 | const KoID colorDepthId = useHDRMode ? Float16BitsColorDepthID : m_image->colorSpace()->colorDepthId(); | ||||
472 | 516 | | |||
473 | KoID destinationColorModelId = RGBAColorModelID; | 517 | KoID destinationColorModelId = RGBAColorModelID; | ||
474 | KoID destinationColorDepthId = Integer8BitsColorDepthID; | 518 | KoID destinationColorDepthId = Integer8BitsColorDepthID; | ||
Context not available. | |||||
477 | 521 | | |||
478 | if (colorModelId == RGBAColorModelID) { | 522 | if (colorModelId == RGBAColorModelID) { | ||
479 | if (colorDepthId == Float16BitsColorDepthID) { | 523 | if (colorDepthId == Float16BitsColorDepthID) { | ||
480 | 524 | initializeRGBA16FTextures(ctx, m_texturesInfo, destinationColorDepthId); | |||
481 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | | |||
482 | m_texturesInfo.internalFormat = GL_RGBA16F; | | |||
483 | dbgUI << "Using half (GLES or GL3)"; | | |||
484 | } else if (ctx->hasExtension("GL_ARB_texture_float")) { | | |||
485 | m_texturesInfo.internalFormat = GL_RGBA16F_ARB; | | |||
486 | dbgUI << "Using ARB half"; | | |||
487 | } | | |||
488 | else if (ctx->hasExtension("GL_ATI_texture_float")) { | | |||
489 | m_texturesInfo.internalFormat = GL_RGBA_FLOAT16_ATI; | | |||
490 | dbgUI << "Using ATI half"; | | |||
491 | } | | |||
492 | | ||||
493 | bool haveBuiltInOpenExr = false; | | |||
494 | #ifdef HAVE_OPENEXR | | |||
495 | haveBuiltInOpenExr = true; | | |||
496 | #endif | | |||
497 | | ||||
498 | if (haveBuiltInOpenExr && (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3())) { | | |||
499 | m_texturesInfo.type = GL_HALF_FLOAT; | | |||
500 | destinationColorDepthId = Float16BitsColorDepthID; | | |||
501 | dbgUI << "Pixel type half (GLES or GL3)"; | | |||
502 | } else if (haveBuiltInOpenExr && ctx->hasExtension("GL_ARB_half_float_pixel")) { | | |||
503 | m_texturesInfo.type = GL_HALF_FLOAT_ARB; | | |||
504 | destinationColorDepthId = Float16BitsColorDepthID; | | |||
505 | dbgUI << "Pixel type half"; | | |||
506 | } else { | | |||
507 | m_texturesInfo.type = GL_FLOAT; | | |||
508 | destinationColorDepthId = Float32BitsColorDepthID; | | |||
509 | dbgUI << "Pixel type float"; | | |||
510 | } | | |||
511 | m_texturesInfo.format = GL_RGBA; | | |||
512 | } | 525 | } | ||
513 | else if (colorDepthId == Float32BitsColorDepthID) { | 526 | else if (colorDepthId == Float32BitsColorDepthID) { | ||
514 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | 527 | if (KisOpenGL::hasOpenGLES() || KisOpenGL::hasOpenGL3()) { | ||
Context not available. | |||||
545 | m_texturesInfo.format = GL_BGRA; | 558 | m_texturesInfo.format = GL_BGRA; | ||
546 | destinationColorDepthId = Integer16BitsColorDepthID; | 559 | destinationColorDepthId = Integer16BitsColorDepthID; | ||
547 | dbgUI << "Using conversion to 16 bits rgba"; | 560 | dbgUI << "Using conversion to 16 bits rgba"; | ||
561 | } else if (colorDepthId == Float16BitsColorDepthID && KisOpenGL::hasOpenGLES()) { | ||||
562 | // TODO: try removing opengl es limit | ||||
563 | initializeRGBA16FTextures(ctx, m_texturesInfo, destinationColorDepthId); | ||||
548 | } | 564 | } | ||
549 | // TODO: for ANGLE, see if we can convert to 16f to support 10-bit display | 565 | // TODO: for ANGLE, see if we can convert to 16f to support 10-bit display | ||
550 | } | 566 | } | ||
Context not available. | |||||
584 | * would not be called when not needed (DK) | 600 | * would not be called when not needed (DK) | ||
585 | */ | 601 | */ | ||
586 | 602 | | |||
587 | m_tilesDestinationColorSpace = | 603 | const KoColorSpace *tilesDestinationColorSpace = | ||
588 | KoColorSpaceRegistry::instance()->colorSpace(destinationColorModelId.id(), | 604 | KoColorSpaceRegistry::instance()->colorSpace(destinationColorModelId.id(), | ||
589 | destinationColorDepthId.id(), | 605 | destinationColorDepthId.id(), | ||
590 | profile); | 606 | profile); | ||
591 | 607 | | |||
592 | m_updateInfoBuilder.setConversionOptions( | 608 | m_updateInfoBuilder.setConversionOptions( | ||
593 | ConversionOptions(m_tilesDestinationColorSpace, | 609 | ConversionOptions(tilesDestinationColorSpace, | ||
594 | m_renderingIntent, | 610 | m_renderingIntent, | ||
595 | m_conversionFlags)); | 611 | m_conversionFlags)); | ||
596 | } | 612 | } | ||
Context not available. |