PDA

View Full Version : Text in Multithreading OpenGL



bahbah30
9th December 2010, 22:11
Hello,

first sorry for my English!


I have an App that shows Videos in OpenGL-Textur. One Video->One Thread.

It is something like that:
http://doc.trolltech.com/qq/qq06-glimpsing.html

But additional I need to write a text in my OpenGL window.I tried following(line 23):



void GLThread::run()
{
srand(QTime::currentTime().msec());
rotAngle = rand() % 360;

glw->makeCurrent();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0, 5.0, -5.0, 5.0, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0, 0, 200, 200);
glClearColor(0.0, 0.0, 0.0, 1.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);

while (doRendering) {
if (doResize) {
glViewport(0, 0, w, h);
doResize = false;
}
// Rendering code goes here

glw->renderText(0.5,0.5.1.0,QString("TEST"));

glw->swapBuffers();
msleep(40);
}
}


Reesult was, that my App crashed with:
ASSERT: "qApp && qApp->thread() == QThread::currentThread()" in file kernel\qapplication_win.cpp, line 929

I know what does it mean. But I don't know, hwo can I realase my issue.
I tried to do the same in GLWidget:



void GLWidget ::paintEvent(QPaintEvent*)
{
mOpenGLWidget->renderText(0.5,0.5,2,QString("TEST"));
}


But here I got:
"QGLContext::makeCurrent() : wglMakeCurrent failed:"

My Sytem is:
WinXP 32, QT4.7 ( MinGW ) and CMake

Any suggestions?


Thanks!

wysota
9th December 2010, 22:33
It seems that you can't render text in OpenGL from worker threads. At least that's what the assertion says.

bahbah30
9th December 2010, 23:04
thankt you for the answer!



It seems that you can't render text in OpenGL from worker threads. At least that's what the assertion says.

I know but I search for workaround!

wysota
9th December 2010, 23:23
There is no workaround.

bahbah30
10th December 2010, 08:44
There is always an workaround!
My issue is to show a Text in OpenGL Widget.

But I can't do it becouse QPainter that privided renderText() have to be initilized in main thread or OpenGL must run in main thread. But I can't run OpenGL in main thread, becouse I have to show 9 videos (about 40*9 images in HD format per second) at the same time. If I will do this my main windows will freez.

Do I have other optionts?

thanks!

wysota
10th December 2010, 09:00
There is always an workaround!
My issue is to show a Text in OpenGL Widget.
So don't use threads, that's your workaround.

bahbah30
10th December 2010, 09:47
So don't use threads, that's your workaround.

than will my main tread freez! How woud you show 9 vidoes without freezing main thread?

tbscope
10th December 2010, 10:24
Use techniques that do not block the eventloop.
This works up to a certain point. If loading and displaying of a single frame is as fast as possible and it still isn't fast enough for the computer, you'll need to look into special techniques. Threading will not help here.

I can't imagine any need for 40 fps with 9 (full) HD frames on a single computer monitor. That is one area you can greatly improve the speed.
If it is necessary, you do not want a simple computer with a single monitor, you want a computer with multiple monitors that has a single GPU for every monitor. In your example 9 monitors and 9 GPU's. And then you can redirect the painting, decoding, etc... to each GPU

bahbah30
10th December 2010, 11:04
As I wrote you I had an idea:



QPainter painter(&sourceImg);
QRectF rect(0,0,100,100);
painter.drawText(rect, Qt::AlignCenter, tr("Test"));
painter.end();
glGenTextures(1, &mTexture);
t = QGLWidget::convertToGLFormat(sourceImg);

And it works!

I wirte not in OpenGL widget, I display my text in my image. Very simple!

Thank all for your answer!

wysota
10th December 2010, 23:23
I'm just wondering why aren't you using solutions that are more efficient than OpenGL for displaying the videos. It seems all you need the GL widget for is to display a texture on it. I don't really see why you would need nine threads just to do that unless you are doing it really inefficiently.

bahbah30
11th December 2010, 01:56
I'm just wondering why aren't you using solutions that are more efficient than OpenGL for displaying the videos.

What do you think about? Phonon? (on linux it works fine with vlc-backend on windows it doesn't work with 4.7. I have to compile my own backend dll and it is very creule on windows)

I hate threads they makes always trouble, but i didn't saw any other way. Do you know some other way?

thanks!

wysota
11th December 2010, 02:59
What do you think about?
Usually each platform has a couple of optimizations for showing videos, like using the GPU for decoding/blitting (like vdpau on Linux and equivalent on WIndows) or XVideo extension on X11.


I hate threads they makes always trouble, but i didn't saw any other way. Do you know some other way?
I don't really see how threads help you. You'd have to have a many-core system to fully support it anyway as any multi-core system will not have enough threads to spare so if everything works with say... 4 cores then it means the concurrency (or lack of it) is not an issue and doing the same within 4 threads (as opposed to 10) would be sufficient. I also completely agree you don't need nine separate video streams at 40fps because nobody is able to register that amount of dispersed movement in their brains.

bahbah30
19th January 2011, 13:38
Finally I taked your advice and make my QGLWidget back to the main thread. I use now PBO to copy Images to graphic card and it works fine. Now I have some other problems. i am going to post it in other thread.

thx