简体   繁体   中英

Qt5 - glTexStorage2D/glBindImageTexture undefined?

I am using Qt 5.7.0 with OpenGL 4.4 and I'm trying to port over some old code to work with Qt. As far as I understand, Qt doesn't have its own way to handle shader textures so I'm using the following code that works fine in my GLEW, non-Qt project:

    float* data = new float[IMAGE_WIDTH * IMAGE_HEIGHT];
    for (int i = 0; i < IMAGE_WIDTH * IMAGE_HEIGHT; ++i)
        data[i] = 0.f;

    GLuint tex[1];
    glGenTextures(1, tex);
    glBindTexture(GL_TEXTURE_2D, tex[0]);
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, IMAGE_WIDTH, IMAGE_HEIGHT);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GL_RED, GL_FLOAT, data);
    glBindImageTexture(0, tex[0], 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32F);

    delete[] data;

However apparently glTexStorage2D and glBindImageTexture are undefined. I have looked at the documentation and they should exist. I have tried #include ing QOpenGLFunctions_4_4_Core , QOpenGLFunctions_4_2_Core , QOpenGLTexture and QOpenGLFunctions but none have solved the problem. I have even looked into the source of QOpenGLFunctions_4_4_Core :

inline void QOpenGLFunctions_4_4_Core::glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
{
    d_4_2_Core->f.TexStorage2D(target, levels, internalformat, width, height);
}

Even creating an instance gives me an error:

QOpenGLFunctions_4_4_Core gl;
gl.glTexStorage2D((GL_TEXTURE_2D, 1, GL_R32F, IMAGE_WIDTH, IMAGE_HEIGHT);

crashes with "Exception thrown: read access violation. this->d_4_2_Core was nullptr."

Is there a) any way to fix this problem; or better yet b) a Qt way to do image load/store?

You should acquire a pointer to a QOpenGLFunctions_4_4_Core object via QOpenGLContext::versionFunctions() . ALternativelt, you can create your own object, but then have to to manually load the function pointers using the initializeOpenGLFunctions() member function, while the context is made current.

Inheriting a specific version of the functions worked for me.

class MyWidget: public QOpenGLWidget, protected QOpenGLFunctions_4_4_Core
{
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM