Given the following code:
// Helper to print relevant QOpenGLTexture state
QString textureToString(const QOpenGLTexture &textureArray){
QString out=R"END(
size: %1x%2
depth: %3
faces: %4
layers: %5
isStorageAllocated: %6
)END";
return out.arg(textureArray.width()).arg(textureArray.height()).arg(textureArray.depth()).arg(textureArray.faces()).arg(textureArray.layers()).arg(textureArray.isStorageAllocated());
}
// ...
QOpenGLTexture textureArray(QOpenGLTexture::Target2DArray);
functions = context->extraFunctions();
Q_ASSERT(nullptr != functions);
functions->glDisable(GL_DEPTH_TEST);
functions->glDisable(GL_CULL_FACE);
// Check for specific OpenGL capabilities
if (functions->hasOpenGLFeature(QOpenGLFunctions::OpenGLFeature::Multitexture)){
qDebug() << "Multitexture is supported.";
}
if (functions->hasOpenGLFeature(QOpenGLFunctions::OpenGLFeature::Framebuffers)){
qDebug() << "Framebuffer objects are supported.";
}
// Check for specific OpenGL extensions
if (context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_buffer_object")))
qDebug() << "OpenGL extension GL_ARB_vertex_buffer_object is supported.";
// Print OpenGL version information
qDebug().nospace() << "OpenGL actual version: " << context->format().version().first << "." << context->format().version().second;
qDebug() << "OpenGL vendor:" << QString(reinterpret_cast<const char*>(functions->glGetString(GL_VENDOR)));
qDebug() << "OpenGL renderer:" << QString(reinterpret_cast<const char*>(functions->glGetString(GL_RENDERER)));
const QSize sz(256, 256);
const int num{10};
qDebug() << "num"<<num<<"sz"<<sz;
qDebug().noquote() <<"BEFORE"<<textureToString(textureArray);
textureArray.setSize(sz.width(), sz.height(), num);
qDebug().noquote() <<"AFTER"<<textureToString(textureArray);
textureArray.setMinificationFilter(QOpenGLTexture::Nearest);
textureArray.setMagnificationFilter(QOpenGLTexture::Nearest);
textureArray.setWrapMode(QOpenGLTexture::ClampToEdge);
textureArray.setMipLevels(1);
auto fmt = inferOpenGLFormat(testImage);
QOpenGLTexture::PixelFormat pixelFormat{fmt.first};
QOpenGLTexture::PixelType pixelType{fmt.second};
textureArray.setFormat(QOpenGLTexture::RGBA8_UNorm);
textureArray.allocateStorage(pixelFormat, pixelType);
QOpenGLPixelTransferOptions uploadOptions;
uploadOptions.setAlignment(1);
for(int i=0;i<num;++i){
//textureArray.setData(testImage);
qDebug()<<"Uploading "<<i<<"of"<<num;
textureArray.setData(0, i, pixelFormat, pixelType, testImage.bits(), &uploadOptions);
I get the following output:
Multitexture is supported.
Framebuffer objects are supported.
OpenGL extension GL_ARB_vertex_buffer_object is supported.
OpenGL actual version: 4.6
OpenGL vendor: "NVIDIA Corporation"
OpenGL renderer: "Quadro P400/PCIe/SSE2"
num 10 sz QSize(256, 256)
BEFORE
size: 1x1
depth: 1
faces: 1
layers: 1
isStorageAllocated: 0
AFTER
size: 256x256
depth: 1
faces: 1
layers: 1
isStorageAllocated: 0
Infering format pixelFormat= QOpenGLTexture::RGBA , pixelType QOpenGLTexture::UInt8 from QImage::Format_RGBA8888
Uploading 0 of 10
Uploading 1 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 2 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 3 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 4 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 5 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 6 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 7 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 8 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
Uploading 9 of 10
OpenGL Message: "GL_INVALID_VALUE error generated. Size and/or offset out of range."
As you can clearly see I am unable to allocate a texture array with 10 "layers". It seems that a single element is allocated and it ca be used later when uploading texture data with QOpenGLTexture::setData()
.
There are no errors indicating that my code fails at the actual QOpenGLTexture::setSize()
call but printing the stats after shows the number of layers has not changed, and also trying to use layers beyond index 0 fails.
What am I doing wrong here?