qt5.9.1 QOpenGLWidget绘图崩溃到nvoglv64.dll:drvpresentBuffer();



  • 程序中OpenGLWidget继承QOpenGLWidget和QOpenGLFunctions,同时打开多个OpenGLWidget播放视频(视频解码通过ffmpeg完成,解码出来的YUV数据存储在AVFrame结构体中。)
    绘图类代码如下:
    #define ATTRIB_VERTEX 3
    #define ATTRIB_TEXTURE 4

    #include "openglwidget.h"
    #include <QOpenGLShaderProgram>
    #include <QOpenGLShader>
    #include <QOpenGLTexture>

    const char *vsrc =
    "#version 410\n"
    "in vec4 vertexIn;\n"
    "in vec2 textureIn;\n"
    "out vec2 textureOut;\n"
    "void main(void)\n"
    "{\n"
    " gl_Position = vertexIn;\n"
    " textureOut = textureIn;\n"
    "}";

    const char *fsrc =
    "#version 410\n"
    "in vec2 textureOut;\n"
    "out vec4 fragColor;\n"
    "uniform sampler2D tex_y;\n"
    "uniform sampler2D tex_u;\n"
    "uniform sampler2D tex_v;\n"
    "void main(void)\n"
    "{\n"
    " vec3 yuv;\n"
    " vec3 rgb;\n"
    " yuv.x = texture(tex_y, textureOut).r;\n"
    " yuv.y = texture(tex_u, textureOut).r - 0.5;\n"
    " yuv.z = texture(tex_v, textureOut).r - 0.5;\n"
    " rgb = mat3( 1, 1, 1,\n"
    " 0, -0.21482, 2.12798,\n"
    " 1.28033, -0.38059, 0) * yuv;\n"
    " fragColor = vec4(rgb, 1);\n"
    "}";

    OpenGLWidget::OpenGLWidget(QWidget *parent)
    {
    setParent(parent);
    y_texture = false;
    u_texture = false;
    v_texture = false;
    paint = false;
    width = 0;
    height = 0;
    this->setMouseTracking(true);
    setUpdateBehavior(QOpenGLWidget::PartialUpdate);
    }

    void OpenGLWidget::clearWidget()
    {
    makeCurrent();
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    }

    void OpenGLWidget::initializeGL()
    {
    initializeOpenGLFunctions();
    m_shader = prepareShaderProgram();

    textureUniformY = glGetUniformLocation(m_shader, "tex_y");
    textureUniformU = glGetUniformLocation(m_shader, "tex_u");
    textureUniformV = glGetUniformLocation(m_shader, "tex_v");
    
    
    // Create a interleaved triangle (vec3 position, vec3 color)
    float vertexPoints[] ={
        -1.0f, -1.0f,0.0f, 1.0f,
        1.0f, -1.0f,1.0f, 1.0f,
        -1.0f, 1.0f,0.0f, 0.0f,
        1.0f, 1.0f,1.0f, 0.0f,
    };
    
    glGenVertexArrays(1, &m_vertexBuffer);
    glBindVertexArray(m_vertexBuffer);
    
    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, 4 * 4 * sizeof(float), vertexPoints, GL_STATIC_DRAW);
    vertextAttribute = glGetAttribLocation(m_shader, "vertexIn");
    textureAttribute = glGetAttribLocation(m_shader, "textureIn");
    glEnableVertexAttribArray(vertextAttribute);
    glVertexAttribPointer(vertextAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(float)*4, (const GLvoid *)0);
    glEnableVertexAttribArray(textureAttribute);
    glVertexAttribPointer(textureAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(float)*4, (const GLvoid *)(sizeof(float)*2));
    
    
    //Init Texture
    glGenTextures(1, &id_y);
    glBindTexture(GL_TEXTURE_2D, id_y);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    glGenTextures(1, &id_u);
    glBindTexture(GL_TEXTURE_2D, id_u);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    glGenTextures(1, &id_v);
    glBindTexture(GL_TEXTURE_2D, id_v);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    

    }

    GLuint OpenGLWidget::prepareShaderProgram()
    {
    GLuint program = glCreateProgram();

    //vertex shader
    GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER);
    glShaderSource( vertexShader, 1, (const GLchar**)&vsrc, NULL );
    glCompileShader( vertexShader );
    GLint  compiled;
    glGetShaderiv( vertexShader, GL_COMPILE_STATUS, &compiled );
    glAttachShader( program, vertexShader );
    
    //fragment shader
    GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER);
    glShaderSource( fragmentShader, 1, (const GLchar**)&fsrc, NULL );
    glCompileShader( fragmentShader );
    glGetShaderiv( fragmentShader, GL_COMPILE_STATUS, &compiled );
    glAttachShader( program, fragmentShader );
    
    /* Link output */
    glBindFragDataLocation(program, 0, "fragColor");
    /* link  and error check */
    glLinkProgram(program);
    
    GLint  linked;
    glGetProgramiv( program, GL_LINK_STATUS, &linked );
    if ( !linked ) {
        qWarning() << "Shader program failed to link";
    }
    glUseProgram(program);
    return program;
    

    }

    bool OpenGLWidget::getPaint() const
    {
    return paint;
    }

    void OpenGLWidget::setPaint(bool value)
    {
    paint = value;
    }

    void OpenGLWidget::paintGL()
    {
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    if(paint)
    {
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, id_y);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, this->width, this->height, 0, GL_RED, GL_UNSIGNED_BYTE, frame.data[0]);
            glUniform1i(textureUniformY, 0);
    
            glActiveTexture(GL_TEXTURE1);
            glBindTexture(GL_TEXTURE_2D, id_u);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, this->width/2, this->height/2, 0, GL_RED, GL_UNSIGNED_BYTE, frame.data[1]);
            glUniform1i(textureUniformU, 1);
    
    
    
            glActiveTexture(GL_TEXTURE2);
            glBindTexture(GL_TEXTURE_2D, id_v);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, this->width/2, this->height/2, 0, GL_RED, GL_UNSIGNED_BYTE, frame.data[2]);
            glUniform1i(textureUniformV, 2);
    
        // Draw stuff
        glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
    }
    

    }

    void OpenGLWidget::resizeGL(int w, int h)
    {
    show_width = w;
    show_height = qMax(h,1);
    glViewport(0,0,show_width,show_height);
    }



  • 0_1508382122722_QQ图片20171019110154.png



  • 翻x之后查资料,有2种说法,一种是让关闭nv的线程优化选项(一看就不靠谱),另一种说是显存泄露(??)。线程优化就不用说了,关了之后仍然会崩溃。特来此求教。。。



  • 想问一下,会不会是因为多个窗口同时绘图、访问显存出现了问题?



  • 而且不崩溃的时候创建多个openglwidget窗口时,新窗口的创建会导致老窗口闪烁一下(有时图像绘制出现颜色变化),不解,求大家指导。



  • 蹦到绘图里的问题找到了。是因为frame结构体的多线程读写导致的。但是现在又开始崩溃到mf.dll is required for hardware video decoding。。。无语,翻资料去了。


  • 网站研运

    @flowerlove 多线程来进行渲染?我看到成功的似乎只有Qt的Scene Graph渲染框架,而且这个也分情况,在某些平台下多线程渲染仍然是不足的。


 

最近的回复

  • 0_1531879249244_9090909.jpg
    各位上午好哦。很高兴告诉大家,我们的萌梦社区又进行了一波更新了!
    这次主要更新在论坛代码层面上的,也就是说我们根据NodeBB官方的指示,将论坛从1.9.3升级到了1.10.1了!整个升级过程会产生一些服务暂停的现象,不过没有关系,很快就可以得到恢复,现在咱们可以顺利地在新的论坛上玩耍了!
    这次更新按照NodeBB官方的说法,主要在论坛的稳定性和迎合欧盟的GPDR政策(隐私权保护政策)上,也就是说,咱们论坛默认是支持用户的隐私权保护的~不要担心自己的隐私会被黑客利用什么的,但是大家还是要保护好平时论坛登录的密码哦。合适的时候还是使用浏览器的记住密码功能~

    此外,之前萌梦论坛之前的SSL加密是免费的,费时效果又不好。在手机浏览器上显示并非可靠的颁发者,现在换了新的证书,感觉好了不少。现在又可以在论坛上玩耍啦。

    好了,就是这样~

    阅读更多
  • @jiangcaiyang 是不支持QVector3D类型么,需要引用头文件还是需要转换类型呢

    阅读更多
  • 可能是Qt制作的Python绑定Shiboken遇到了问题。求先行者能够解忧~😵

    阅读更多
  • 0_1531804634749_5.jpg
    我使用的是PyCharm作为IDE,下载了Qt for Python(使用Qt 5.11),并且使用git克隆了pyside的源代码 + 例子。因为自己对OpenGL感兴趣,所以随手运行了一个例子。首先是PyOpenGL没有安装。

    0_1531804316021_1f365ea0-46b3-460d-9a00-c8cdeccf98af-image.png

    通过对话框弹出的命令,在terminal上运行

    python -m pip install PyOpenGL PyOpenGL_accelerate

    就可以了。

    虽然窗体以及3D内容出来了,但是命令提示符中会出现一些问题:

    D:/QtProject/pyside-setup/examples/opengl/hellogl2.py:394: RuntimeWarning: SbkConverter: Unimplemented C++ array type. self.program.setUniformValue(self.lightPosLoc, QVector3D(0, 0, 70)) D:/QtProject/pyside-setup/examples/opengl/hellogl2.py:423: RuntimeWarning: SbkConverter: Unimplemented C++ array type. self.program.setUniformValue(self.projMatrixLoc, self.proj) D:/QtProject/pyside-setup/examples/opengl/hellogl2.py:424: RuntimeWarning: SbkConverter: Unimplemented C++ array type. self.program.setUniformValue(self.mvMatrixLoc, self.camera * self.world) D:/QtProject/pyside-setup/examples/opengl/hellogl2.py:426: RuntimeWarning: SbkConverter: Unimplemented C++ array type. self.program.setUniformValue(self.normalMatrixLoc, normalMatrix)

    刚学习Python,还不清楚是怎么回事,怎么解决才好。

    阅读更多

关注我们

微博
QQ群











召唤伊斯特瓦尔