Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt QOpenGLTexture::allocateStorage导致GL\u无效\u值错误_Qt_Opengl_Textures - Fatal编程技术网

Qt QOpenGLTexture::allocateStorage导致GL\u无效\u值错误

Qt QOpenGLTexture::allocateStorage导致GL\u无效\u值错误,qt,opengl,textures,Qt,Opengl,Textures,我已经把它提炼成了一段平凡的Qt代码,其中唯一有趣的是同步处理纹理时的几行代码。我从AllocatesTrage行获得一个GL\u无效值。有人知道为什么吗?我怀疑这可能是由于我传递给这个函数的参数 我的代码: main.cpp: 你有 QOpenGLTexture tex(QOpenGLTexture::Target2D); 根据,它实际上并不创建底层纹理对象。我想你需要 tex.create(); 在设置大小和分配存储之前。所以 QOpenGLTexture tex(QOpenGLText

我已经把它提炼成了一段平凡的Qt代码,其中唯一有趣的是同步处理纹理时的几行代码。我从AllocatesTrage行获得一个GL\u无效值。有人知道为什么吗?我怀疑这可能是由于我传递给这个函数的参数

我的代码:

main.cpp:

你有

QOpenGLTexture tex(QOpenGLTexture::Target2D);
根据,它实际上并不创建底层纹理对象。我想你需要

tex.create();
在设置大小和分配存储之前。所以

QOpenGLTexture tex(QOpenGLTexture::Target2D);
if (!tex.create()) {

  /*
   * Take appropriate action.
   */
}
tex.setSize(100, 100);
tex.allocateStorage(QOpenGLTexture::BGRA, QOpenGLTexture::Int8);
编辑1:


实际上,从代码中可以看出,tex.allocatestrage应该在必要时分配纹理id。但是,如果由于某些原因(例如,没有当前上下文)而失败,则可能导致您看到的问题。

在分配存储期间,您正在向opeGL驱动程序传递有关纹理存储格式的信息

对于格式GL_BGRA或GL_RGBA,OpenGL建议使用GL_UNSIGNED_BYTE

对于GL_BGRA,在Qt---QOpenGLTexture::BGRA中,对于GL_UNSIGNED_字节,在QOpenGLTexture::UInt8中

因此,基于openGL建议的分配存储函数应该是

tex.allocateStorage(QOpenGLTexture::BGRA, QOpenGLTexture::UInt8);

在查看QOPENGLTEXTRE::createMutableTexture和QOPENGLTEXTRE::AllocateStrage无参数版本的源代码后,我发现两个参数的AllocateStrage重载确实非常误导。文档使得它的2个参数似乎将在实现中用作glTexImage2D调用的纹理第3个参数的内部格式,而实际上它们仅用作从系统RAM格式/键入glTexImage2D的第7和第8个参数传输的源数据,在向glTexImage2D传递空指针的情况下,除了在边缘OpenGL ES 2的情况下,这一点都不重要

为纹理实际请求某种内部格式的方法是在调用tex.allocatestrage之前调用tex.setFormat。因此,我将我的allocateStorage行替换为:

tex.setFormat(QOpenGLTexture::RGBA8_UNorm);
tex.allocateStorage();

这修复了错误。

谢谢,但我打印了tex.isCreated,在allocateStorage之后,我得到了true。好吧,为了听到另一个钟声,allocateStorage的两个枚举类型的参数清楚地说明它们是关于外部格式的,而不是内部格式的…Qt的GL包装是灾难性的。+1作为答案,否则,我可能会花费数小时来解决这个问题。设计此API的人并不真正了解OpenGL:/
tex.allocateStorage(QOpenGLTexture::BGRA, QOpenGLTexture::UInt8);
tex.setFormat(QOpenGLTexture::RGBA8_UNorm);
tex.allocateStorage();