Add new APIs which is useful to upload more than one layer at once

It's useful to upload textures storred in .KTX files without dividing the layers.
It's also more efficient than uploading layer by layer.

Change-Id: I92d93c57514e2a3637d1202cb83bd72b8d277edf
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
BogDan Vatra 2016-12-06 11:12:27 +02:00
parent 80fa5f6e76
commit d90c234bac
3 changed files with 75 additions and 26 deletions

View File

@ -1351,7 +1351,7 @@ void QOpenGLTexturePrivate::allocateImmutableStorage()
storageAllocated = true; storageAllocated = true;
} }
void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, void QOpenGLTexturePrivate::setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options) const void *data, const QOpenGLPixelTransferOptions * const options)
{ {
@ -1359,6 +1359,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
case QOpenGLTexture::Target1D: case QOpenGLTexture::Target1D:
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
texFuncs->glTextureSubImage1D(textureId, target, bindingTarget, mipLevel, texFuncs->glTextureSubImage1D(textureId, target, bindingTarget, mipLevel,
0, mipLevelSize( mipLevel, dimensions[0] ), 0, mipLevelSize( mipLevel, dimensions[0] ),
sourceFormat, sourceType, data, options); sourceFormat, sourceType, data, options);
@ -1369,13 +1370,14 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel, texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
0, layer, 0, layer,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
1, layerCount,
sourceFormat, sourceType, data, options); sourceFormat, sourceType, data, options);
break; break;
case QOpenGLTexture::Target2D: case QOpenGLTexture::Target2D:
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel, texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
0, 0, 0, 0,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
@ -1389,12 +1391,13 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
0, 0, layer, 0, 0, layer,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]), mipLevelSize(mipLevel, dimensions[1]),
1, layerCount,
sourceFormat, sourceType, data, options); sourceFormat, sourceType, data, options);
break; break;
case QOpenGLTexture::Target3D: case QOpenGLTexture::Target3D:
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel, texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
0, 0, layer, 0, 0, layer,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
@ -1405,6 +1408,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
case QOpenGLTexture::TargetCubeMap: case QOpenGLTexture::TargetCubeMap:
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(layerCount);
texFuncs->glTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel, texFuncs->glTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel,
0, 0, 0, 0,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
@ -1419,7 +1423,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
0, 0, layerFace, 0, 0, layerFace,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]), mipLevelSize(mipLevel, dimensions[1]),
1, layerCount,
sourceFormat, sourceType, data, options); sourceFormat, sourceType, data, options);
break; break;
} }
@ -1428,6 +1432,7 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
Q_UNUSED(mipLevel); Q_UNUSED(mipLevel);
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, 0, texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, 0,
0, 0, 0, 0,
dimensions[0], dimensions[0],
@ -1450,7 +1455,8 @@ void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::Cub
} }
} }
void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, int layerCount,
QOpenGLTexture::CubeMapFace cubeFace,
int dataSize, const void *data, int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options) const QOpenGLPixelTransferOptions * const options)
{ {
@ -1465,6 +1471,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
case QOpenGLTexture::Target1D: case QOpenGLTexture::Target1D:
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
if (needsFullSpec) { if (needsFullSpec) {
texFuncs->glCompressedTextureImage1D(textureId, target, bindingTarget, mipLevel, texFuncs->glCompressedTextureImage1D(textureId, target, bindingTarget, mipLevel,
format, format,
@ -1483,7 +1490,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel, texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
0, layer, 0, layer,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
1, layerCount,
format, dataSize, data, options); format, dataSize, data, options);
} }
break; break;
@ -1491,6 +1498,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
case QOpenGLTexture::Target2D: case QOpenGLTexture::Target2D:
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
if (needsFullSpec) { if (needsFullSpec) {
texFuncs->glCompressedTextureImage2D(textureId, target, bindingTarget, mipLevel, texFuncs->glCompressedTextureImage2D(textureId, target, bindingTarget, mipLevel,
format, format,
@ -1513,13 +1521,14 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
0, 0, layer, 0, 0, layer,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]), mipLevelSize(mipLevel, dimensions[1]),
1, layerCount,
format, dataSize, data, options); format, dataSize, data, options);
} }
break; break;
case QOpenGLTexture::Target3D: case QOpenGLTexture::Target3D:
Q_UNUSED(cubeFace); Q_UNUSED(cubeFace);
Q_UNUSED(layerCount);
if (needsFullSpec) { if (needsFullSpec) {
texFuncs->glCompressedTextureImage3D(textureId, target, bindingTarget, mipLevel, texFuncs->glCompressedTextureImage3D(textureId, target, bindingTarget, mipLevel,
format, format,
@ -1539,6 +1548,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
case QOpenGLTexture::TargetCubeMap: case QOpenGLTexture::TargetCubeMap:
Q_UNUSED(layer); Q_UNUSED(layer);
Q_UNUSED(layerCount);
if (needsFullSpec) { if (needsFullSpec) {
texFuncs->glCompressedTextureImage2D(textureId, cubeFace, bindingTarget, mipLevel, texFuncs->glCompressedTextureImage2D(textureId, cubeFace, bindingTarget, mipLevel,
format, format,
@ -1562,7 +1572,7 @@ void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTe
0, 0, layerFace, 0, 0, layerFace,
mipLevelSize(mipLevel, dimensions[0]), mipLevelSize(mipLevel, dimensions[0]),
mipLevelSize(mipLevel, dimensions[1]), mipLevelSize(mipLevel, dimensions[1]),
1, layerCount,
format, dataSize, data, options); format, dataSize, data, options);
} }
break; break;
@ -3286,7 +3296,23 @@ void QOpenGLTexture::setData(int mipLevel, int layer, CubeMapFace cubeFace,
"To do so call allocateStorage() before this function"); "To do so call allocateStorage() before this function");
return; return;
} }
d->setData(mipLevel, layer, cubeFace, sourceFormat, sourceType, data, options); d->setData(mipLevel, layer, 1, cubeFace, sourceFormat, sourceType, data, options);
}
/*!
\since 5.9
\overload
*/
void QOpenGLTexture::setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions * const options)
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
if (!isStorageAllocated()) {
qWarning("Cannot set data on a texture that does not have storage allocated.\n"
"To do so call allocateStorage() before this function");
return;
}
d->setData(mipLevel, layer, layerCount, cubeFace, sourceFormat, sourceType, data, options);
} }
/*! /*!
@ -3299,7 +3325,7 @@ void QOpenGLTexture::setData(int mipLevel, int layer,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); d->setData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
} }
/*! /*!
@ -3312,7 +3338,7 @@ void QOpenGLTexture::setData(int mipLevel,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); d->setData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
} }
/*! /*!
@ -3324,7 +3350,7 @@ void QOpenGLTexture::setData(PixelFormat sourceFormat, PixelType sourceType,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); d->setData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
} }
#if QT_DEPRECATED_SINCE(5, 3) #if QT_DEPRECATED_SINCE(5, 3)
@ -3345,7 +3371,7 @@ void QOpenGLTexture::setData(int mipLevel, int layer, CubeMapFace cubeFace,
"To do so call allocateStorage() before this function"); "To do so call allocateStorage() before this function");
return; return;
} }
d->setData(mipLevel, layer, cubeFace, sourceFormat, sourceType, data, options); d->setData(mipLevel, layer, 1, cubeFace, sourceFormat, sourceType, data, options);
} }
/*! /*!
@ -3358,7 +3384,7 @@ void QOpenGLTexture::setData(int mipLevel, int layer,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); d->setData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
} }
/*! /*!
@ -3371,7 +3397,7 @@ void QOpenGLTexture::setData(int mipLevel,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); d->setData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
} }
/*! /*!
@ -3383,7 +3409,7 @@ void QOpenGLTexture::setData(PixelFormat sourceFormat, PixelType sourceType,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); d->setData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options);
} }
#endif #endif
@ -3444,7 +3470,23 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, CubeMapFace cube
"To do so call allocateStorage() before this function"); "To do so call allocateStorage() before this function");
return; return;
} }
d->setCompressedData(mipLevel, layer, cubeFace, dataSize, data, options); d->setCompressedData(mipLevel, layer, 1, cubeFace, dataSize, data, options);
}
/*!
\since 5.9
\overload
*/
void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, int dataSize, const void *data, const QOpenGLPixelTransferOptions * const options)
{
Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId);
if (!isStorageAllocated()) {
qWarning("Cannot set data on a texture that does not have storage allocated.\n"
"To do so call allocateStorage() before this function");
return;
}
d->setCompressedData(mipLevel, layer, layerCount, cubeFace, dataSize, data, options);
} }
/*! /*!
@ -3455,7 +3497,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, co
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setCompressedData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); d->setCompressedData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
} }
/*! /*!
@ -3466,7 +3508,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, const void *d
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setCompressedData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); d->setCompressedData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
} }
/*! /*!
@ -3477,7 +3519,7 @@ void QOpenGLTexture::setCompressedData(int dataSize, const void *data,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setCompressedData(0, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); d->setCompressedData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
} }
#if QT_DEPRECATED_SINCE(5, 3) #if QT_DEPRECATED_SINCE(5, 3)
@ -3496,7 +3538,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, CubeMapFace cube
"To do so call allocateStorage() before this function"); "To do so call allocateStorage() before this function");
return; return;
} }
d->setCompressedData(mipLevel, layer, cubeFace, dataSize, data, options); d->setCompressedData(mipLevel, layer, 1, cubeFace, dataSize, data, options);
} }
/*! /*!
@ -3508,7 +3550,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, vo
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setCompressedData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); d->setCompressedData(mipLevel, layer, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
} }
/*! /*!
@ -3520,7 +3562,7 @@ void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, void *data,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setCompressedData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); d->setCompressedData(mipLevel, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
} }
/*! /*!
@ -3532,7 +3574,7 @@ void QOpenGLTexture::setCompressedData(int dataSize, void *data,
{ {
Q_D(QOpenGLTexture); Q_D(QOpenGLTexture);
Q_ASSERT(d->textureId); Q_ASSERT(d->textureId);
d->setCompressedData(0, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); d->setCompressedData(0, 0, 1, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options);
} }
#endif #endif

View File

@ -472,6 +472,9 @@ public:
void setData(int mipLevel, int layer, CubeMapFace cubeFace, void setData(int mipLevel, int layer, CubeMapFace cubeFace,
PixelFormat sourceFormat, PixelType sourceType, PixelFormat sourceFormat, PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR); const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
void setData(int mipLevel, int layer, int layerCount, CubeMapFace cubeFace,
PixelFormat sourceFormat, PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
void setData(int mipLevel, int layer, void setData(int mipLevel, int layer,
PixelFormat sourceFormat, PixelType sourceType, PixelFormat sourceFormat, PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR); const void *data, const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
@ -499,6 +502,9 @@ public:
void setCompressedData(int mipLevel, int layer, CubeMapFace cubeFace, void setCompressedData(int mipLevel, int layer, CubeMapFace cubeFace,
int dataSize, const void *data, int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options = Q_NULLPTR); const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
void setCompressedData(int mipLevel, int layer, int layerCount, CubeMapFace cubeFace,
int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);
void setCompressedData(int mipLevel, int layer, void setCompressedData(int mipLevel, int layer,
int dataSize, const void *data, int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options = Q_NULLPTR); const QOpenGLPixelTransferOptions * const options = Q_NULLPTR);

View File

@ -98,13 +98,14 @@ public:
void allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType); void allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType);
void allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType); void allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType);
void allocateImmutableStorage(); void allocateImmutableStorage();
void setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, void setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
const void *data, const QOpenGLPixelTransferOptions * const options); const void *data, const QOpenGLPixelTransferOptions * const options);
void setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, void setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
int dataSize, const void *data, int dataSize, const void *data,
const QOpenGLPixelTransferOptions * const options); const QOpenGLPixelTransferOptions * const options);
void setWrapMode(QOpenGLTexture::WrapMode mode); void setWrapMode(QOpenGLTexture::WrapMode mode);
void setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode); void setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode);
QOpenGLTexture::WrapMode wrapMode(QOpenGLTexture::CoordinateDirection direction) const; QOpenGLTexture::WrapMode wrapMode(QOpenGLTexture::CoordinateDirection direction) const;