c++ - QOpenGLContext 获取 GL_MAX_TEXTURE_SIZE 总是返回 0

标签 c++ opengl qt5

我想获取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/

相关文章:

c++ - 为什么第二个变量作为引用和常量传递

c++ - "cout << cout"- 输出代表什么?

c++ - OpenGL GLSL - 投影矩阵不工作

c++ - 为什么 OpenGL 有全局函数?

c++ - QML 实例化 C++ 对象。我如何访问他们的方法?

c++ - 在 C++ unix 中异步写入文件

c++ - Windows .lib 文件是否有一些等效的 GNU 二进制文件描述符 (BFD)?

opengl - OpenGL的LookAt函数中的UP向量到底是什么?

c++ - 使用 Visual Studio 2013 构建 Qt 5.2.1 的静态版本

c++ - 如何将信号转发到私有(private)信号?