PDA

View Full Version : qt quick with opengl underlay



sajis997
15th December 2014, 18:39
Hello forum,

I am trying to draw a teapot as opengl underlay rendering and qt quick UI on top of the underlay to interact with the teapot. Since qt quick 2 uses opengl 2 for all of its rendering , i am using the compatibility profile with the modern opengl pipeline .

I am having QQuickView subclass as follows:




class Window : public QQuickView
{
Q_OBJECT

public:

explicit Window(QWindow *parent = 0);

public slots:
void renderOpenGLScene();

private:

QScopedPointer<AbstractScene> mScene;
QTime mTime;
};



All the opengl commands are initiated in the following class :



class TeapotTessellation : public AbstractScene, protected QOpenGLFunctions_4_3_Compatibility
{
Q_OBJECT

public:

explicit TeapotTessellation(QObject *parent = 0);
~TeapotTessellation();

//scene related functions
virtual void initialise();
virtual void update(float t);
virtual void render();
virtual void resize(int w,int h);

private:

void loadShaders();

GLSLShader *mTessellationShader;

TeapotVboPatch *mTeapotPatch;

....................
....................
};

I can see the teapot, but the QML scene is not behaving properly(spring animation of a rounded rectangle) and i get the following info in the cosole:



QSGContext::initialize: stencil buffer support missing, expect rendering errors


The qml code is tested separately and i works fine.

Where should i look into the debug this issue ?

wysota
15th December 2014, 19:22
We cannot see how you get your GL code called. You should connect to the beforeRendering() signal with a slot that performs rendering. Remember to reset the state of the GL engine to what QtQuick expects by calling resetOpenGLState().

sajis997
15th December 2014, 20:24
Hi

I am already connecting the signal as follows:




Window::Window(QWindow *parent)
: QQuickView(parent),
mScene(new TeapotTessellation(this))
{
setClearBeforeRendering(false);

QObject::connect(this,SIGNAL(beforeRendering()),SL OT(renderOpenGLScene()),Qt::DirectConnection);

QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(update() ));
timer->start();

QSurfaceFormat format;
format.setMajorVersion(4);
format.setMinorVersion(3);
format.setSamples(4);
format.setProfile(QSurfaceFormat::CompatibilityPro file);

setFormat(format);
}



And after every rendering commands i am unbinding the shaders and vertex array object explicitly and i am not sure where to call this resetOpenGLState(). Check also the following snippet:




void Window::update()
{
float time = mTime.elapsed() / 1000.0f;

mScene->update(time);

QQuickView::update();
}

void Window::renderOpenGLScene()
{
static bool firstTime = true;

if(firstTime)
{
mScene->initialise();
mScene->resize(width(),height());
firstTime = false;
}

mScene->render();

//SHOULD I CALL THE FUNCTION resetOpenGLState() here ?
}

wysota
15th December 2014, 21:28
Yes, call the function.

And you shouldn't access any of the window's properties from the rendering thread. Better initialize that scene before you start drawing.

sajis997
22nd December 2014, 17:38
Thanks,

I have managed to render an opengl scene under the qt quick scene. I largely followed the tutorial titled - "Scene Graph - OpenGL Under QML"


Now i want to animate the opengl scene that contains a teapot. I usually rotate the opengl scene using the Qt' s timer event and timer function as follows:



QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(updateSc ene()));
timer->start();


And inside the updateScene() slot I have the following :



void GLWindow::updateScene()
{
float t = mTime.elapsed() * 0.001;

mScene->update(t);

paintGL();
}


I used the same mechanism while integrating qt quick with opengl underlay, but the teapot only rotates for a while with the mouse click and it stops. I want the teapot to rotate continuously untill the application closes.

Any hint to achieve this ?

Thanks

wysota
22nd December 2014, 17:58
You have to tell QtQuick scene to update itself. It will call your GL code with the beforeRendering signal.

sajis997
22nd December 2014, 18:22
Thanks !

Any concrete example to what you have just mentioned ?

wysota
22nd December 2014, 18:46
QQuickWindow::update().