Re: [osg-users] OSG + Qt + threading.

2012-03-26 Thread Aitor Ardanza
Hi Aurelien,

It seems that already works! I attached code...

Code:

_qtViewer = new osgGenerals::ViewerQT(this);
ui.OSGRenderLayout-addWidget(_qtViewer);
_qtViewer-updateCamera(center,eye,up);
_qtViewer-setSceneData(_mainLogic-getRootGroup());
_qtViewer-startRendering();




Thank you!

Cheers,
Aitor

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46582#46582



#ifndef _OSG_QT_RENDER_H_
#define _OSG_QT_RENDER_H_

#include osgViewer/Viewer
#include osgViewer/GraphicsWindow
#include osgViewer/CompositeViewer
#include osgViewer/ViewerEventHandlers
#include osgGA/TrackballManipulator
#include osg/Notify

#define USE_QT4 1

#if USE_QT4

#include QtCore/QString
#include QtCore/QTimer
#include QtGui/QKeyEvent
#include QtOpenGL/QGLWidget
#include QtCore/QThread
#include QtCore/QMutex

using Qt::WindowFlags;

#else

class QWidget;
#include qtimer.h
#include qgl.h
#include qapplication.h

#define WindowFlags WFlags

#endif

#include iostream

namespace osgGenerals{

class LogFileHandler : public osg::NotifyHandler
{
public:
LogFileHandler( const std::string file )
{ _log.open( file.c_str() ); }
virtual ~LogFileHandler() { _log.close(); }
virtual void notify(osg::NotifySeverity severity,
const char* msg)
{ _log  msg; }
protected:
std::ofstream _log;
};

class ViewerQT;
class GLPainter : public QObject
 {
 Q_OBJECT
 public:
 GLPainter(ViewerQT *widget);
 void stop();
 void resizeViewport(const QSize size);
 void updateCamera(osg::Vec3f center, osg::Vec3f eye, osg::Vec3f up);

 public slots:
 void start();

 protected:
 void timerEvent(QTimerEvent *event);

 private:
 QMutex mutex;
 ViewerQT *glWidget;
 bool doRendering;
 };
class AdapterWidget : public QGLWidget
{
public:

AdapterWidget( QWidget * parent = 0, const char * name = 0, const 
QGLWidget * shareWidget = 0, WindowFlags f = 0 );

virtual ~AdapterWidget() {}

osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); }
const osgViewer::GraphicsWindow* getGraphicsWindow() const { return 
_gw.get(); }

protected:

void init();

virtual void resizeGL( int width, int height );
virtual void keyPressEvent( QKeyEvent* event );
virtual void keyReleaseEvent( QKeyEvent* event );
virtual void mousePressEvent( QMouseEvent* event );
virtual void mouseReleaseEvent( QMouseEvent* event );
virtual void mouseMoveEvent( QMouseEvent* event );
virtual void wheelEvent(QWheelEvent *event);
osg::ref_ptrosgViewer::GraphicsWindowEmbedded _gw;
};

class ViewerQT : public osgViewer::Viewer, public AdapterWidget
{
public:

ViewerQT(QWidget * parent = 0, const char * name = 0, const QGLWidget * 
shareWidget = 0, WindowFlags f = 0);
~ViewerQT();

void startRendering();
void stopRendering();
virtual void paintGL();
void updateCamera(osg::Vec3f center, osg::Vec3f eye, osg::Vec3f 
up);

protected:
void resizeEvent(QResizeEvent *evt);
void paintEvent(QPaintEvent *);
void closeEvent(QCloseEvent *evt);

GLPainter glPainter;
QThread glThread;
};

}
#endifÿþ#include OSGQtRender.h





using namespace osgGenerals;



GLPainter::GLPainter(ViewerQT *widget)

     : glWidget(widget)

     , doRendering(true)

 {

 }



 void GLPainter::start()

 {

	 glWidget-AdapterWidget::makeCurrent();

     startTimer(10);

 }



 void GLPainter::stop()

 {

     QMutexLocker locker(mutex);

     doRendering = false;

 }



void GLPainter::resizeViewport(const QSize size)

{

	QMutexLocker locker(mutex);

	glWidget-getCamera()-setViewport(new osg::Viewport(0,0,size.width(),size.height()));

}



void GLPainter::timerEvent(QTimerEvent *event)

{

	QMutexLocker locker(mutex);

	if (!doRendering) {

		killTimer(event-timerId());

		QThread::currentThread()-quit();

		return;

	}

	glWidget-updateGL();

}

void 

Re: [osg-users] OSG + Qt + threading.

2012-03-24 Thread Aurelien Albert
Hi,


 when I call glWidget-frame() dont refresh the osg


May be the OSG OpenGL context is not the current one. And maybe the OSG OpenGL 
context is not the same as created by Qt.

Have a look at makeCurrent methods in Qt and in OSG :

http://qt-project.org/doc/qt-4.8/qglcontext.html#makeCurrent
http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00275.html#f9570786bab5518aab85737498af3a30

You can also check a lot of OpenGL context related stuff with gDebugger. 


 if I put a connection between timer and updateGL() fails to call paintGL(). 


It's probably because in this case, paintGL is called within another thread 
than main thread, which is not alowed by Qt.

Could you post a minimal complete source code ?

Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46575#46575





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-23 Thread Aitor Ardanza
Hi,

I'm following this example: 
http://doc-snapshot.qt-project.org/4.8/demos-glhypnotizer-main-cpp.html
but I fail to refresh the window... is blank.

This is my code on glPainter:

Code:

GLPainter::GLPainter(ViewerQT *widget)
 : glWidget(widget)
 , doRendering(true)
 {
 }

 void GLPainter::start()
 {
 glWidget-AdapterWidget::makeCurrent();
 QTimer timer;
 connect(timer, SIGNAL(timeout()), glWidget, SLOT(updateGL()));
 timer.start(10);
 startTimer(20);
 }

 void GLPainter::stop()
 {
 QMutexLocker locker(mutex);
 doRendering = false;
 }

 void GLPainter::resizeViewport(const QSize size)
 {
 QMutexLocker locker(mutex);
 viewportWidth = size.width();
 viewportHeight = size.height();

 }

 void GLPainter::timerEvent(QTimerEvent *event)
 {
 QMutexLocker locker(mutex);
 if (!doRendering) {
 killTimer(event-timerId());
 QThread::currentThread()-quit();
 return;
 }
// glWidget-updateFrame();
 }




I initialize the GLWidget like the example and the thread go well but when I 
call glWidget-frame() dont refresh the osg and if I put a connection between 
timer and updateGL() fails to call paintGL().

What am I doing wrong?

Thank you!

Cheers,
Aitor

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46554#46554





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-22 Thread Aitor Ardanza
Hi,

I've had to change several things to works it...
OSGQtRenderThreadManager: public QThread, and the render thread loop is:


Code:

void OSGQtRenderThreadManager::run() 
{
_done = false;

osg::notify(osg::INFO)  Start OSGRender Thread!std::endl;
while(!_done)
{
emit updateFrame();
msleep(10);
}
osg::notify(osg::INFO)  End OSGRender Thread!std::endl;

}


In the constructor of OSGQtTRenderThreadManager I have defined the connection 
between these object and void ViewerQT::paintGL():

Code:

connect(this,SIGNAL(updateFrame()),_qtViewer,SLOT(updateGL()));




Now I can update render frame in another frame than GUI main frame!

Thank you!

Cheers,
Aitor

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46519#46519





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-22 Thread Aurelien Albert
Hi,


 Now I can update render frame in another frame than GUI main frame! 


I don't think so. Because when you do that :


Code:
connect(this,SIGNAL(updateFrame()),_qtViewer,SLOT(updateGL())); 



If the this object and _qtViewer belongs to different thread, the 
connection will be established as a Qt::QueuedConnection and so the 
updateGL() slot will be executed in the _qtViewer owner thread which is the 
main thread.

I think you can check that by settings breakpoints in updateGL() and check 
which thread is the current thread within the debugger.


Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46520#46520





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-22 Thread Aitor Ardanza
Hi Aurelien,

You are right! I am emiting a signal to execute painGL() fuction on main 
thread...
I've been looking but I haven't found anything clear... How would I refresh a 
QGLWidget embedded in a main gui layout from another thread? is possible?

Thank you!

Cheers,
Aitor

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46522#46522





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-22 Thread Aurelien Albert
Have a look to this article : 
http://labs.qt.nokia.com/2011/06/03/threaded-opengl-in-4-8/

I think it's maybe not possible with qt previous 4.8 version, but maybe under 
some conditions.

Basically, you need to call the updateGL() method from the worker thread.

Have also a look to this article about threading in Qt : 
http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/

Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46523#46523





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-22 Thread Aitor Ardanza
Ok, so I need to update qt...

Thank you!

Cheers,
Aitor

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46524#46524





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2012-03-21 Thread Aitor Ardanza
Hi,

I'm trying to do the same... but I only get errors... The steps that I follow 
are the next:
I create a class OSGQtRenderThreadManager: public OpenThreads::Thread which 
contains a variable class ViewerQT : public osgViewer::Viewer, public 
AdapterWidget (class AdapterWidget : public QGLWidget). 
In the qt application thread I initialize the renderThreadManager and I insert 
the QGLWidget variable in a layout:

Code:

_viewerThreadManager = new osgGenerals::OSGQtRenderThreadManager(center, eye, 
up, false);
_viewerThreadManager-startThread();
ui.OSGRenderLayout-addWidget(_viewerThreadManager-getQtViewerWidget());




This is de run() of the renderThread:

Code:

void OSGQtRenderThreadManager::run() 
{
 _done = false;

 osg::notify(osg::INFO)  Start OSGRender Thread!std::endl;
 while(!_done)
 {
 YieldCurrentThread();
OpenThreads::ScopedLockOpenThreads::Mutex lock(_mutex);
   _qtViewer-frame();
 }
 osg::notify(osg::INFO)  End OSGRender Thread!std::endl;

}




I suppose that the problem is in the _qtViewer variable acces from the 
application main thread and renderThread... But I dont know how can I fix it.

Can someone help me?! Thank you!

Cheers,
Aitor

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46490#46490





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2011-11-09 Thread Nico Kruithof
Yes, I'm using one thread per context, which works fine. Although I must
admit that I run a single context most of the time. On the other hand, it
seems to be the default setting for the example in the OSG source.

Nico

On Tue, Nov 1, 2011 at 10:02 AM, Aurelien Albert 
aurelien.alb...@alyotech.fr wrote:

 Hi Nico,

 I'm also working with Qt as UI framework with OSG as a 3d renderer.

 Have you successed to use another threading model than SingleThreaded ?

 Thank you!

 Cheers,
 Aurelien

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=43664#43664





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




-- 
Nico Kruithof
nghk.nl
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2011-11-01 Thread Aurelien Albert
Hi Nico,

I'm also working with Qt as UI framework with OSG as a 3d renderer.

Have you successed to use another threading model than SingleThreaded ?

Thank you!

Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43664#43664





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt + threading.

2011-10-31 Thread Nico Kruithof
Hi,

I was incorrecly assuming that the QTimer that initiates the rendering of a
frame was started from the thread doing the event handling. The solution is
very elegant indeed.

Best regards,
Nico

On Sat, Oct 29, 2011 at 2:07 PM, Nico Kruithof n...@nghk.nl wrote:

 Hello,

 I'm trying to develop a Qt user interface around OpenSceneGraph Views
 (using the CompoundViewer). I've seen the OsgViewerQt but was wondering
 whether the OpenGL rendering could be done in an independent thread. Having
 rendering and the user interface in the same thread makes the user
 interface irresponsive when rendering becomes really slow (a few seconds
 per frame).

 My thought was to create a osg-window from a separate render thread and
 forward all events from Qt to the render thread where they are handled. I
 could block from the Qt thread on an event if necessary. Now if I create an
 independent view using createGraphicsContext() it creates the window as
 expected, however it shows up in the task bar as a separate window. Is it
 possible attach the graphics context to the Qt widget that is the
 placeholder in the Qt interface?

 --
 Nico Kruithof
 nghk.nl




-- 
Nico Kruithof
nghk.nl
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] OSG + Qt + threading.

2011-10-29 Thread Nico Kruithof
Hello,

I'm trying to develop a Qt user interface around OpenSceneGraph Views
(using the CompoundViewer). I've seen the OsgViewerQt but was wondering
whether the OpenGL rendering could be done in an independent thread. Having
rendering and the user interface in the same thread makes the user
interface irresponsive when rendering becomes really slow (a few seconds
per frame).

My thought was to create a osg-window from a separate render thread and
forward all events from Qt to the render thread where they are handled. I
could block from the Qt thread on an event if necessary. Now if I create an
independent view using createGraphicsContext() it creates the window as
expected, however it shows up in the task bar as a separate window. Is it
possible attach the graphics context to the Qt widget that is the
placeholder in the Qt interface?

-- 
Nico Kruithof
nghk.nl
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org