• F
    flowerlove

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

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

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

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

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

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

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

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

    程序中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);
    }

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

    项目目前面临着UI和操作的大改版,设计师要求实现很多类似于手机上的动画:按钮弹出动画,窗口切换动画等等(我们是一个大型的红外框项目),但基于我目前对qt widgets的了解,想要实现很困难。是不是必须转到qt quick?还是说qt widgets也可以做?我们甚至考虑换unity 3d。。。总之大家都可以给出些建议,谢谢。

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

    这里不太明白的是,software和desktop的区别。
    另外,只了解到,es是用在移动端的,项目是在Windows下的,故不考虑。

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

    Qt::AA_UseDesktopOpenGL
    Forces the usage of desktop OpenGL (for example, opengl32.dll or libGL.so) on platforms that use dynamic loading of the OpenGL implementation. This value has been added in Qt 5.3. This attribute must be set before Q(Gui)Application is constructed.

    Qt::AA_UseOpenGLES
    Forces the usage of OpenGL ES 2.0 or higher on platforms that use dynamic loading of the OpenGL implementation. This value has been added in Qt 5.3. This attribute must be set before Q(Gui)Application is constructed.

    Qt::AA_UseSoftwareOpenGL
    Forces the usage of a software based OpenGL implementation on platforms that use dynamic loading of the OpenGL implementation. This will typically be a patched build of Mesa llvmpipe, providing OpenGL 2.1. The value may have no effect if no such OpenGL implementation is available. The default name of this library is opengl32sw.dll and can be overridden by setting the environment variable QT_OPENGL_DLL. See the platform-specific pages, for instance Qt for Windows, for more information. This value has been added in Qt 5.4. This attribute must be set before Q(Gui)Application is constructed.

    发布在 Qt 讨论区 阅读更多
  • F
    flowerlove

    连一个简单的弹出动画,都能把CPU占到30%。这在之前的版本是不可能的。

    发布在 Qt 讨论区 阅读更多

与 萌梦社区 的连接断开,我们正在尝试重连,请耐心等待