[solved] - Embed OpenGl rendering
-
Hi.
I try to had a "WebGl-OpenGl api to qml throw a plugin":http://www.youtube.com/user/QExtend#p/c/1FD514E2B24011DB/1/bxcbolOuFeY and i try to find the best method to embed OpenGl rendering .
I test 3 methods :
1- render to a QGLPixelBuffer and get image with toImage(). Good performance but slow for big image (Edit: depend on hardware used)
2- use QGlCOntext to a Pixmap. Bad performance.
3- use OPenGl graphics system, render scene to a QGLPixelBuffer. I try to draw a rectangle with texture from QGLPixelBuffer in QDeclarativeItem::paint but it's doesn't work :(
Do you know other solution ? I think method 3 could be better but i don't find how use correctly QDeclarativeItem::paint with Opengl call.
-
I think your best option is to make sure the QDeclarativeView is using a GLWidget as its viewport (if using qmlviewer, pass -opengl). Then you can rely on OpenGL calls simply working in your paint implementation. It will also allow you to make use of primitives provided by the Qt 3D project ("http://qt.gitorious.org/qt-labs/qt3d":http://qt.gitorious.org/qt-labs/qt3d).
Embedding an OpenGL view inside a non-OpenGL QDeclarativeView is just getting messy and would indeed be hard to make perform well I think. Especially if you want to be able to perform transformations on it.
-
[quote author="Thorbjørn Lindeijer" date="1285697279"]I think your best option is to make sure the QDeclarativeView is using a GLWidget as its viewport (if using qmlviewer, pass -opengl). Then you can rely on OpenGL calls simply working in your paint implementation. It will also allow you to make use of primitives provided by the Qt 3D project ("http://qt.gitorious.org/qt-labs/qt3d":http://qt.gitorious.org/qt-labs/qt3d).[/quote]
I try draw a rectangle in paint method when opengl is activate.@void Canvas::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
static QTime t(QTime::currentTime());
static double mean(0.);
static int nb = 0;
++nb;
if(t.elapsed()>1000 )
{
mean = 1000.*nb/t.elapsed();
t.restart();
nb = 0;
}
p->setBrush(m_background);
p->setPen(Qt::NoPen);
p->drawRect(boundingRect().toRect());
p->drawPixmap(0,0,m_cache);glBegin(GL_QUADS); glVertex3d(0, 0, 0); glVertex3d(0, 100, 0); glVertex3d( 100, 100, 0); glVertex3d( 100, 0, 0); glEnd(); p->setPen(Qt::red); p->setFont(QFont("Tahoma",20,QFont::Bold)); p->drawText(10,25,QString::number(mean,'g',4));
}@
A corresponding rectangle appear like a translucent quads.If i try to use a color or a texture, the quad display bug.
I don't understand why.
I'll see qt3d code.
[quote author="Thorbjørn Lindeijer" date="1285697279"]
Embedding an OpenGL view inside a non-OpenGL QDeclarativeView is just getting messy and would indeed be hard to make perform well I think. Especially if you want to be able to perform transformations on it.[/quote]
QGlPixelBuffer with toImage work fine with good pc... It's a first solution. But a full OpenGl solution will certainly better. -
Have you tried using "beginNativePainting()":http://doc.trolltech.com/4.7/qpainter.html#beginNativePainting and endNativePainting() to wrap your raw GL code?
-
[quote author="mbrasser" date="1285721884"]Have you tried using "beginNativePainting()":http://doc.trolltech.com/4.7/qpainter.html#beginNativePainting and endNativePainting() to wrap your raw GL code? [/quote]
Cool. I don't see these functions. I'll test tonight.In my last test, use OpenGl works very fine if i d'ont use QPainter in the paint method and if my item is alone. So beginNativePainting seem to be what i want.