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

#include <kis_texture_tile.h>

Public Member Functions

int bindToActiveTexture (bool blockMipmapRegeneration)
 
QRectF imageRectInTexturePixels (const QRect &imageRect) const
 
 KisTextureTile (const QRect &imageRect, const KisGLTexturesInfo *texturesInfo, const QByteArray &fillData, KisOpenGL::FilterMode mode, KisOpenGLBufferCircularStorage *bufferStorage, int numMipmapLevels, QOpenGLFunctions *f)
 
void setBufferStorage (KisOpenGLBufferCircularStorage *bufferStorage)
 
void setNumMipmapLevels (int num)
 
QRect textureRectInImagePixels ()
 
QRect tileRectInImagePixels ()
 
QRectF tileRectInTexturePixels ()
 
void update (const KisTextureTileUpdateInfo &updateInfo, bool blockMipmapRegeneration)
 
 ~KisTextureTile ()
 

Private Member Functions

void regenerateMipmap ()
 
void restoreTextureParameters ()
 
void setNeedsMipmapRegeneration ()
 
void setPreparedLodPlane (int lod)
 
void setTextureParameters ()
 

Private Attributes

QOpenGLFunctions * f
 
KisOpenGLBufferCircularStoragem_bufferStorage
 
KisOpenGL::FilterMode m_filter
 
bool m_mipmapHasBeenAllocated = false
 
bool m_needsMipmapRegeneration
 
int m_numMipmapLevels
 
int m_preparedLodPlane
 
GLuint m_textureId
 
QRect m_textureRectInImagePixels
 
const KisGLTexturesInfom_texturesInfo
 
QRect m_tileRectInImagePixels
 
QRectF m_tileRectInTexturePixels
 

Detailed Description

Definition at line 40 of file kis_texture_tile.h.

Constructor & Destructor Documentation

◆ KisTextureTile()

KisTextureTile::KisTextureTile ( const QRect & imageRect,
const KisGLTexturesInfo * texturesInfo,
const QByteArray & fillData,
KisOpenGL::FilterMode mode,
KisOpenGLBufferCircularStorage * bufferStorage,
int numMipmapLevels,
QOpenGLFunctions * f )

Definition at line 72 of file kis_texture_tile.cpp.

76 : m_textureId(0)
77 , m_tileRectInImagePixels(imageRect)
78 , m_filter(filter)
79 , m_texturesInfo(texturesInfo)
82 , m_numMipmapLevels(numMipmapLevels)
83 , f(fcn)
84 , m_bufferStorage(bufferStorage)
85{
86 const GLvoid *fd = fillData.constData();
87
90
94
95 f->glGenTextures(1, &m_textureId);
96 f->glBindTexture(GL_TEXTURE_2D, m_textureId);
97
99
102
103 f->glTexImage2D(GL_TEXTURE_2D, 0,
108 m_texturesInfo->type, fd);
109
111
113}
QRect m_textureRectInImagePixels
const KisGLTexturesInfo * m_texturesInfo
QOpenGLFunctions * f
void restoreTextureParameters()
QRectF m_tileRectInTexturePixels
KisOpenGL::FilterMode m_filter
void setNeedsMipmapRegeneration()
QRect m_tileRectInImagePixels
KisOpenGLBufferCircularStorage * m_bufferStorage
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
void fillData(KisPaintDeviceSP pd, int w, int h, QDataStream &stream)
QRectF relativeRect(const QRect &br, const QRect &cr, const KisGLTexturesInfo *texturesInfo)

References KisGLTexturesInfo::border, f, fillData(), KisGLTexturesInfo::format, KisGLTexturesInfo::height, KisGLTexturesInfo::internalFormat, kisGrowRect(), m_bufferStorage, m_textureId, m_textureRectInImagePixels, m_texturesInfo, m_tileRectInImagePixels, m_tileRectInTexturePixels, relativeRect(), restoreTextureParameters(), setNeedsMipmapRegeneration(), setTextureParameters(), KisOpenGLBufferCircularStorage::size(), KisGLTexturesInfo::type, and KisGLTexturesInfo::width.

◆ ~KisTextureTile()

KisTextureTile::~KisTextureTile ( )

Definition at line 115 of file kis_texture_tile.cpp.

116{
117 f->glDeleteTextures(1, &m_textureId);
118}

References f, and m_textureId.

Member Function Documentation

◆ bindToActiveTexture()

int KisTextureTile::bindToActiveTexture ( bool blockMipmapRegeneration)

Binds the tile's texture to the current GL_TEXTURE_2D binding point, regenerates the mipmap if needed and returns the levelOfDetail that should be used for painting

Definition at line 120 of file kis_texture_tile.cpp.

121{
122 f->glBindTexture(GL_TEXTURE_2D, m_textureId);
123
124 if (m_needsMipmapRegeneration && !blockMipmapRegeneration) {
127 }
128
129 return m_preparedLodPlane;
130}
void setPreparedLodPlane(int lod)

References f, m_needsMipmapRegeneration, m_preparedLodPlane, m_textureId, regenerateMipmap(), and setPreparedLodPlane().

◆ imageRectInTexturePixels()

QRectF KisTextureTile::imageRectInTexturePixels ( const QRect & imageRect) const

Definition at line 378 of file kis_texture_tile.cpp.

379{
381 imageRect,
383
384}

References m_textureRectInImagePixels, m_texturesInfo, and relativeRect().

◆ regenerateMipmap()

void KisTextureTile::regenerateMipmap ( )
private

Definition at line 147 of file kis_texture_tile.cpp.

148{
149 f->glGenerateMipmap(GL_TEXTURE_2D);
152}

References f, m_mipmapHasBeenAllocated, and m_needsMipmapRegeneration.

◆ restoreTextureParameters()

void KisTextureTile::restoreTextureParameters ( )
inlineprivate

Definition at line 51 of file kis_texture_tile.cpp.

52{
53 // QPainter::drawText relies on this.
54 // Ref: https://bugreports.qt.io/browse/QTBUG-65496
55 f->glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
56}

References f.

◆ setBufferStorage()

void KisTextureTile::setBufferStorage ( KisOpenGLBufferCircularStorage * bufferStorage)
inline

Definition at line 48 of file kis_texture_tile.h.

48 {
49 m_bufferStorage = bufferStorage;
50 }

References m_bufferStorage.

◆ setNeedsMipmapRegeneration()

void KisTextureTile::setNeedsMipmapRegeneration ( )
private

◆ setNumMipmapLevels()

void KisTextureTile::setNumMipmapLevels ( int num)
inline

Definition at line 52 of file kis_texture_tile.h.

52 {
54 }

References m_numMipmapLevels.

◆ setPreparedLodPlane()

void KisTextureTile::setPreparedLodPlane ( int lod)
private

Definition at line 141 of file kis_texture_tile.cpp.

142{
143 m_preparedLodPlane = lod;
145}

References m_needsMipmapRegeneration, and m_preparedLodPlane.

◆ setTextureParameters()

void KisTextureTile::setTextureParameters ( )
inlineprivate

Definition at line 26 of file kis_texture_tile.cpp.

27{
28
29 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
30 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
31 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0);
32 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, m_numMipmapLevels);
33 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
34 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, m_numMipmapLevels);
35
36 if ((m_texturesInfo->internalFormat == GL_RGBA8 && m_texturesInfo->format == GL_RGBA)
37#ifndef QT_OPENGL_ES_2
38 || (m_texturesInfo->internalFormat == GL_RGBA16 && m_texturesInfo->format == GL_RGBA)
39#endif
41 ) {
42 // If image format is RGBA8, swap the red and blue channels for the proper color
43 // This is for OpenGL ES support and only used if lacking GL_EXT_texture_format_BGRA8888
44 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
45 f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
46 }
47
48 f->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
49}
#define GL_RGBA16_EXT
#define GL_CLAMP_TO_EDGE

References f, KisGLTexturesInfo::format, GL_CLAMP_TO_EDGE, GL_RGBA16_EXT, KisGLTexturesInfo::internalFormat, m_numMipmapLevels, and m_texturesInfo.

◆ textureRectInImagePixels()

QRect KisTextureTile::textureRectInImagePixels ( )
inline

Definition at line 62 of file kis_texture_tile.h.

62 {
64 }

References m_textureRectInImagePixels.

◆ tileRectInImagePixels()

QRect KisTextureTile::tileRectInImagePixels ( )
inline

Definition at line 58 of file kis_texture_tile.h.

58 {
60 }

References m_tileRectInImagePixels.

◆ tileRectInTexturePixels()

QRectF KisTextureTile::tileRectInTexturePixels ( )
inline

Definition at line 66 of file kis_texture_tile.h.

66 {
68 }

References m_tileRectInTexturePixels.

◆ update()

void KisTextureTile::update ( const KisTextureTileUpdateInfo & updateInfo,
bool blockMipmapRegeneration )

In some special case, when the Lod0 stroke is cancelled the following situation is possible:

1) The stroke is cancelled, Lod0 update is issued by the image. LodN level of the openGL times is still dirty.

2) [here, ideally, the canvas should be re-rendered, so that the mipmap would be regenerated in bindToActiveTexture() call, by in some cases (if you cancel and paint to quickly), that doesn't have time to happen]

3) The new LodN stroke issues a partial update of a LodN plane of the tile. But the plane is still dirty! We update a part of it, but we cannot regenerate the mipmap anymore, because the Lod0 level is not known yet!

To avoid this issue, we should regenerate the dirty mipmap before doing anything with the low-resolution plane.

Another case is when the user has Bilinear or Nearest Neighbour filtering selected and tries to use LoD functionality in animation. glTexSubImage2D() and textureLod() are defined only when all the planes were explicitly initialized with glTexImage2D(), which doesn't happen in case of bilinear- or nn-filtering. In this case !m_mipmapHasBeenAllocated condition comes in.

On the boundaries of KisImage, there is a border-effect as well. So we just repeat the bounding pixels of the image to make bilinear interpolator happy.

WARN: The width of the stripes will be equal to the broader width of the tiles.

When in a mode that doesn't use mipmaps we should just switch back onto lod0 plane instead of requesting full mipmap regeneration.

Definition at line 154 of file kis_texture_tile.cpp.

155{
156 f->initializeOpenGLFunctions();
157 f->glBindTexture(GL_TEXTURE_2D, m_textureId);
158
160
161 const int patchLevelOfDetail = updateInfo.patchLevelOfDetail();
162 const QSize patchSize = updateInfo.realPatchSize();
163 const QPoint patchOffset = updateInfo.realPatchOffset();
164
165 const GLvoid *fd = updateInfo.data();
166
195 if (!blockMipmapRegeneration &&
196 patchLevelOfDetail > 0 &&
198 !updateInfo.isEntireTileUpdated())
200
202 }
203
204
205 if (updateInfo.isEntireTileUpdated()) {
207 m_bufferStorage, &fd, updateInfo.patchPixelsLength());
208
209 f->glTexImage2D(GL_TEXTURE_2D, patchLevelOfDetail,
211 patchSize.width(),
212 patchSize.height(), 0,
215 fd);
216 }
217 else {
218 const int size = patchSize.width() * patchSize.height() * updateInfo.pixelSize();
220 m_bufferStorage, &fd, size);
221
222 f->glTexSubImage2D(GL_TEXTURE_2D, patchLevelOfDetail,
223 patchOffset.x(), patchOffset.y(),
224 patchSize.width(), patchSize.height(),
227 fd);
228
229 }
230
242 const int pixelSize = updateInfo.pixelSize();
243 const QSize tileSize = updateInfo.realTileSize();
244
245 if(updateInfo.isTopmost()) {
246 int start = 0;
247 int end = patchOffset.y() - 1;
248
249 const GLvoid *fd = updateInfo.data();
250 const int size = patchSize.width() * pixelSize;
252 m_bufferStorage, &fd, size);
253
254 for (int i = start; i <= end; i++) {
255 f->glTexSubImage2D(GL_TEXTURE_2D, patchLevelOfDetail,
256 patchOffset.x(), i,
257 patchSize.width(), 1,
260 fd);
261 }
262 }
263
264 if (updateInfo.isBottommost()) {
265 int shift = patchSize.width() * (patchSize.height() - 1) *
266 pixelSize;
267
268 int start = patchOffset.y() + patchSize.height();
269 int end = tileSize.height() - 1;
270
271 const GLvoid *fd = updateInfo.data() + shift;
272 const int size = patchSize.width() * pixelSize;
274 m_bufferStorage, &fd, size);
275
276 for (int i = start; i < end; i++) {
277 f->glTexSubImage2D(GL_TEXTURE_2D, patchLevelOfDetail,
278 patchOffset.x(), i,
279 patchSize.width(), 1,
282 fd);
283 }
284 }
285
286 if (updateInfo.isLeftmost()) {
287
288 QByteArray columnBuffer(patchSize.height() * pixelSize, 0);
289
290 quint8 *srcPtr = updateInfo.data();
291 quint8 *dstPtr = (quint8*) columnBuffer.data();
292 for(int i = 0; i < patchSize.height(); i++) {
293 memcpy(dstPtr, srcPtr, pixelSize);
294
295 srcPtr += patchSize.width() * pixelSize;
296 dstPtr += pixelSize;
297 }
298
299 int start = 0;
300 int end = patchOffset.x() - 1;
301
302 const GLvoid *fd = columnBuffer.constData();
303 const int size = columnBuffer.size();
305 m_bufferStorage, &fd, size);
306
307 for (int i = start; i <= end; i++) {
308 f->glTexSubImage2D(GL_TEXTURE_2D, patchLevelOfDetail,
309 i, patchOffset.y(),
310 1, patchSize.height(),
313 fd);
314 }
315 }
316
317 if (updateInfo.isRightmost()) {
318
319 QByteArray columnBuffer(patchSize.height() * pixelSize, 0);
320
321 quint8 *srcPtr = updateInfo.data() + (patchSize.width() - 1) * pixelSize;
322 quint8 *dstPtr = (quint8*) columnBuffer.data();
323 for(int i = 0; i < patchSize.height(); i++) {
324 memcpy(dstPtr, srcPtr, pixelSize);
325
326 srcPtr += patchSize.width() * pixelSize;
327 dstPtr += pixelSize;
328 }
329
330 int start = patchOffset.x() + patchSize.width();
331 int end = tileSize.width() - 1;
332
333 const GLvoid *fd = columnBuffer.constData();
334 const int size = columnBuffer.size();
336 m_bufferStorage, &fd, size);
337
338 for (int i = start; i <= end; i++) {
339 f->glTexSubImage2D(GL_TEXTURE_2D, patchLevelOfDetail,
340 i, patchOffset.y(),
341 1, patchSize.height(),
344 fd);
345 }
346 }
347
350 // if (!updateInfo.isEntireTileUpdated() &&
351 // !(!patchLevelOfDetail || !m_preparedLodPlane || patchLevelOfDetail == m_preparedLodPlane)) {
352 // qDebug() << "WARNING: LodN switch is requested for the partial tile update!. Flickering is possible..." << ppVar(patchSize);
353 // qDebug() << " " << ppVar(m_preparedLodPlane);
354 // qDebug() << " " << ppVar(patchLevelOfDetail);
355 // }
356
358
359 if (!patchLevelOfDetail) {
370 } else {
372 }
373 } else {
374 setPreparedLodPlane(patchLevelOfDetail);
375 }
376}
@ NearestFilterMode
Definition kis_opengl.h:34
@ BilinearFilterMode
Definition kis_opengl.h:35
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KisOpenGL::BilinearFilterMode, KisTextureTileUpdateInfo::data(), f, KisGLTexturesInfo::format, KisGLTexturesInfo::internalFormat, KisTextureTileUpdateInfo::isBottommost(), KisTextureTileUpdateInfo::isEntireTileUpdated(), KisTextureTileUpdateInfo::isLeftmost(), KisTextureTileUpdateInfo::isRightmost(), KisTextureTileUpdateInfo::isTopmost(), m_bufferStorage, m_filter, m_mipmapHasBeenAllocated, m_needsMipmapRegeneration, m_textureId, m_texturesInfo, KisOpenGL::NearestFilterMode, KisTextureTileUpdateInfo::patchLevelOfDetail(), KisTextureTileUpdateInfo::patchPixelsLength(), KisTextureTileUpdateInfo::pixelSize(), KisTextureTileUpdateInfo::realPatchOffset(), KisTextureTileUpdateInfo::realPatchSize(), KisTextureTileUpdateInfo::realTileSize(), regenerateMipmap(), restoreTextureParameters(), setNeedsMipmapRegeneration(), setPreparedLodPlane(), setTextureParameters(), and KisGLTexturesInfo::type.

Member Data Documentation

◆ f

QOpenGLFunctions* KisTextureTile::f
private

Definition at line 97 of file kis_texture_tile.h.

◆ m_bufferStorage

KisOpenGLBufferCircularStorage* KisTextureTile::m_bufferStorage
private

Definition at line 98 of file kis_texture_tile.h.

◆ m_filter

KisOpenGL::FilterMode KisTextureTile::m_filter
private

Definition at line 92 of file kis_texture_tile.h.

◆ m_mipmapHasBeenAllocated

bool KisTextureTile::m_mipmapHasBeenAllocated = false
private

Definition at line 99 of file kis_texture_tile.h.

◆ m_needsMipmapRegeneration

bool KisTextureTile::m_needsMipmapRegeneration
private

Definition at line 94 of file kis_texture_tile.h.

◆ m_numMipmapLevels

int KisTextureTile::m_numMipmapLevels
private

Definition at line 96 of file kis_texture_tile.h.

◆ m_preparedLodPlane

int KisTextureTile::m_preparedLodPlane
private

Definition at line 95 of file kis_texture_tile.h.

◆ m_textureId

GLuint KisTextureTile::m_textureId
private

Definition at line 87 of file kis_texture_tile.h.

◆ m_textureRectInImagePixels

QRect KisTextureTile::m_textureRectInImagePixels
private

Definition at line 91 of file kis_texture_tile.h.

◆ m_texturesInfo

const KisGLTexturesInfo* KisTextureTile::m_texturesInfo
private

Definition at line 93 of file kis_texture_tile.h.

◆ m_tileRectInImagePixels

QRect KisTextureTile::m_tileRectInImagePixels
private

Definition at line 89 of file kis_texture_tile.h.

◆ m_tileRectInTexturePixels

QRectF KisTextureTile::m_tileRectInTexturePixels
private

Definition at line 90 of file kis_texture_tile.h.


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