0

My OpenGL|ES 2.0 glClear command freezes until the window state changes (eg. the window gets hidden or shown).

The target platform is ARM7 with a Mali 400 GPU.

All code is mostly copied from the Qt OpenGL ES Cube example.

What am I forgetting?

Leon

Source: #include "streamplayer.h"

#include <QtOpenGL>
#include <QGLFunctions>



StreamPlayer::StreamPlayer(QWidget *parent) :
    QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    program = new QGLShaderProgram();

}

StreamPlayer::~StreamPlayer()
{
}

void StreamPlayer::initializeGL()
{
    qDebug() << "Initializing GL";
    initShaders();

    glClearColor(0.5f, 0.5f, 0.7f, 1.0f);
    return;
}

void StreamPlayer::paintGL()
{
    qDebug() << "Paint GL";
    qDebug() << "Clearing buffers";
    glClear(GL_COLOR_BUFFER_BIT);
    qDebug() << "Never comes here until a window state change";

}

void StreamPlayer::resizeGL(int width, int height)
{
    qDebug() << "Resizing GL to " << width << "x" << height;
    glViewport(0, 0, width, height);
    qDebug() << "Done resizing";
}

void StreamPlayer::initShaders()
{
    qDebug() << "Initializing shaders";
    setlocale(LC_NUMERIC, "C");

    if(!program->addShaderFromSourceFile(QGLShader::Vertex, ":/shaders/vshader.glsl")) {
        qDebug() << "Failed to create vertex shader";
    }
    if(!program->addShaderFromSourceFile(QGLShader::Fragment, ":/shaders/fshader.glsl")) {
        qDebug() << "Failed to create fragment shader";
    }

    if(!program->link()) {
        qDebug() << "Failed to link";
    }

    _gl_vertex = program->attributeLocation("vertex");
    _gl_texCoord = program->attributeLocation("texCoord");
    _gl_matrix = program->attributeLocation("matrix");
    _gl_texture = program->attributeLocation("tex");

    if(!program->bind()) {
        qDebug() << "Failed to bind";
    }

    setlocale(LC_ALL, "");
    qDebug() << "Shaders ready";
}
Supergrover
  • 74
  • 1
  • 6

1 Answers1

0

Have you kept the timer asking for frame updates ? It is this timer that is asking for openGL redraw by calling updateGL() on the glwidget, that ask for a (delayed) paintGL(). Otherwise paintGL will only be called when Qt estimates necessary (for example window shown).

QTimer *timer = new QTimer(this);
timer->setInterval(10);
QObject::connect(timer, SIGNAL(timeout()), glwidget, SLOT(updateGL()));
//And at the end of MainWindow initialization
timer->start();

See this SO thread for related question.

Community
  • 1
  • 1
florentbuisson
  • 526
  • 5
  • 12
  • Yes, I do have an update timer (not obvious from the included code). The update command gets called from the parent class. The problem is not the lack of updates, but the blocking on glClear.. – Supergrover Nov 14 '13 at 22:24
  • Then I'd go for the missing QPainter. I personally manage buffers myself but in the example you need to surround glClear with these this: QPainter painter(this); painter.beginNativePainting(); glClear(...); painter.endNativePainting(); – florentbuisson Nov 18 '13 at 13:23