我想获取GL_MAX_TEXTURE_SIZE
的值在 Qt “早期”,因为我将为我的应用程序生成一些纹理图集。
我明白 glGetIntegerv
没有“有效”上下文将无法工作。所以我创建了一个 QOpenGLContext
然后调用glGetIntegerv
但这仍然返回 0,为什么?
QOpenGLContext c;
if ( !c.create() )
{
abort();
}
int maxSize = 0;
glEnable(GL_TEXTURE_2D);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
// maxSize == 0
auto err = glGetError();
// err == 0 too!
目标平台是Linux,运行glxinfo -l | grep MAX_TEXTURE_SIZE
在终端返回
GL_MAX_TEXTURE_SIZE = 16384
GL_MAX_TEXTURE_SIZE = 16384
我应该注意到我创建了一个 QApplication
QOpenGLContext
之前的实例, 但此代码在 QApplication
之前执行事件循环。
最佳答案
经过大量挖掘,您的上下文似乎必须是最新的,这需要一个表面。由于您可能不希望为此闲置一些随机的 QWindow
,Qt 人员添加了 QOffscreenSurface
:
http://qt-project.org/doc/qt-5.1/qtgui/qoffscreensurface.html
// Create a temp context - required if this is called from another thread
QOpenGLContext ctx;
if ( !ctx.create() )
{
// TODO handle the error
}
// rather than using a QWindow - which actually dosen't seem to work in this case either!
QOffscreenSurface surface;
surface.setFormat( ctx.format() );
surface.create();
ctx.makeCurrent(&surface);
// Now the call works
int maxSize = 0;
glEnable(GL_TEXTURE_2D);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
关于c++ - QOpenGLContext 获取 GL_MAX_TEXTURE_SIZE 总是返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748869/