OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Qt5 integration first try

Goto page 1, 2  Next
 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Martin Scheffler (Martin Scheffler)
Appreciator


Joined: 29 Mar 2009
Posts: 138

PostPosted: Thu Nov 29, 2012 7:03 am    Post subject:
Qt5 integration first try
Reply with quote

Hi all,

here is a rough first version of Qt5 running together with OSG.


It works fine on linux with Qt5 beta 2. On windows I get compile errors, a conflict between the OpenGL defines in OSG and those in Qt. Maybe it may become necessary to separate qt and osg even more so that their headers don't collide.

OSG is now rendered to an opengl context created by Qt. The context object renders to a QWindow. Unfortunately there is not yet an easy way to add a QWindow as a child to QWidget (this will come in Qt 5.1 I have heard). But it is possible to add a QWindow to a QWidget by using the window handle.

What's next:
* Render in a different thread - I just didn't come around to try it, I don't expect that many problems
* Try to render Qt Quick over the OSG scene. Qt could then be used to make HUDs. Maybe it is even possible to still keep OSG and Qt in different threads?

Thanks to Sean from KDAB!

Cheers,
Martin[/img]
Back to top
View user's profile Send private message
Wang Rui
Guest





PostPosted: Thu Nov 29, 2012 7:25 am    Post subject:
Qt5 integration first try
Reply with quote

Hi Martin,

Oh, good news! I'm working on Qt5, too. You may see something in the osgRecipes project. In just provided a simple example integrating OSG and Qt5 and draw Qt widgets in the scene graph. It is tested under Windows, but can't work in multithreaded mode.


Unfortunately this seems not an OSG related problem, but an issue in QGLContext that can't work under different threads even doneCurrent() is executed in time. In the following link I found that Qt expects have already noticed it:

https://codereview.qt-project.org/#change,40644



I'd like to then use moveToThread() to move QGLContext to the rendering thread so that it could work (at present it will fail and say it can't make a context current on another thread). Maybe these information will help you, too.


Cheers,


Wang Rui




2012/11/29 Martin Scheffler < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
Hi all,

here is a rough first version of Qt5 running together with OSG.


It works fine on linux with Qt5 beta 2. On windows I get compile errors, a conflict between the OpenGL defines in OSG and those in Qt. Maybe it may become necessary to separate qt and osg even more so that their headers don't collide.

OSG is now rendered to an opengl context created by Qt. The context object renders to a QWindow. Unfortunately there is not yet an easy way to add a QWindow as a child to QWidget (this will come in Qt 5.1 I have heard). But it is possible to add a QWindow to a QWidget by using the window handle.

What's next:
* Render in a different thread - I just didn't come around to try it, I don't expect that many problems
* Try to render Qt Quick over the OSG scene. Qt could then be used to make HUDs. Maybe it is even possible to still keep OSG and Qt in different threads?

Thank you!

Cheers,
Martin[/img]

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




_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
Kristofer Tingdahl
Guest





PostPosted: Thu Nov 29, 2012 11:05 am    Post subject:
Qt5 integration first try
Reply with quote

Hi,

I did, FYI, submit a patch to adapt the cmake-system to compile with qt5 to osg-submissions a couple of days ago, but I have not heard anything. If you did not subscribe to that list, you can get my changes at

https://docs.google.com/open?id=0B_4ZHt6ZZHE9Q2RBLUxac1hZQ2M

I was, as you describe as well, not able to get multi-threaded rendering working.

Sincerely,


Kristofer Tingdahl
--
Kristofer Tingdahl, Ph. D.
CEO
dGB Earth Sciences

------------------
Post generated by Mail2Forum
Back to top
Wang Rui
Guest





PostPosted: Thu Nov 29, 2012 1:23 pm    Post subject:
Qt5 integration first try
Reply with quote

Hi Kristofer,

Yes, I've noticed your submission but haven't had time to try it. I'd like to have a look at your code this weekend after my client work. Smile


Thanks,


Wang Rui




2012/11/29 Kristofer Tingdahl < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
Hi,

I did, FYI, submit a patch to adapt the cmake-system to compile with qt5 to osg-submissions a couple of days ago, but I have not heard anything. If you did not subscribe to that list, you can get my changes at

https://docs.google.com/open?id=0B_4ZHt6ZZHE9Q2RBLUxac1hZQ2M

I was, as you describe as well, not able to get multi-threaded rendering working.

Sincerely,


Kristofer Tingdahl
--
Kristofer Tingdahl, Ph. D.
CEO
dGB Earth Sciences



_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
NitishPuri (Nitish Puri)
Newbie


Joined: 17 Jan 2013
Posts: 1

PostPosted: Mon Jan 21, 2013 10:00 am    Post subject:
Reply with quote

Hi Martin,

I looked at your osgWindowWidget example, it worked great, but now if i want to add qml on top of the osgViewer i get an opaque window. What i did was in your example i added a QQuickView, formed a windowHolderWidget from it with parent as the osgWidget. Here is the code.
Code:

QApplication a(argc, argv);
Window w;
w.viewer()->setSceneData(osgDB::readNodeFile("cow.osg"));
w.viewer()->setCameraManipulator(new osgGA::TrackballManipulator);

QQuickView view;
view.setSurface(QSurface::OpenGLSurface);
view.setSource(QUrl::fromLocalFile("example.qml"));

QSurfaceFormat surfaceFormat;
surfaceFormat.setAlphaBufferSize(8);
surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL);

view.setFormat(surfaceFormat);
view.setColor(QColor(Qt::transparent));
view.setClearBeforeRendering(true);

//view.setParent(&w);
//view.show();

WindowHolderWidget myWidget, menuWidget;
myWidget.setEmbeddedWindow(&w);
menuWidget.setEmbeddedWindow(&view);
menuWidget.setStyleSheet("background:transparent;");
menuWidget.setAttribute(Qt::WA_TranslucentBackground);
menuWidget.setWindowFlags(Qt::FramelessWindowHint);
menuWidget.setParent(&mywidget);
QWidget mainwidget;   

mainwidget.resize(600,600);
mainwidget.setLayout(new QVBoxLayout());
QSlider slider(Qt::Horizontal);
slider.setRange(0, 255);
mainwidget.layout()->addWidget(&slider);
mainwidget.layout()->addWidget(&mywidget);
QObject::connect(&slider, SIGNAL(valueChanged(int)), &w, SLOT(setBackgroundColorRed(int)));
mainwidget.showMaximized();
return a.exec();


Would it be possible to render a transparent qquickview.

Thank you!

Cheers,
Nitish
Back to top
View user's profile Send private message Send e-mail
Vitezslav
Newbie


Joined: 18 Jan 2013
Posts: 3

PostPosted: Mon Jan 28, 2013 12:06 pm    Post subject:
Reply with quote

Hi Wang,
I've patched OSG to get multithreaded rendering working. I've used QGLContext::moveToThread, as you suggested, before the thread starts and the same function when the thread ends.

I'm sharing the patch. Maybe it will save a little of your time. Please note that I'm not sure this is the best way to do it, take it just as a hint what has to be done.

Cheers,
Vitezslav
Back to top
View user's profile Send private message
Vitezslav
Newbie


Joined: 18 Jan 2013
Posts: 3

PostPosted: Mon Feb 11, 2013 6:07 pm    Post subject:
Qt5 integration first try
Reply with quote

Hi Wang,
I've patched OSG to get multithreaded rendering working. I've used QGLContext::moveToThread, as you suggested, before the thread starts and the same function when the thread ends.

I'm sharing the patch. Maybe it will save a little of your time. Please note that I'm not sure this is the best way to do it, take it just as a hint what has to be done.

Cheers,
Vitezslav

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




Attachments:
http://forum.openscenegraph.org//files/osg_qt5_multithreading_564.txt




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Wang Rui
Guest





PostPosted: Tue Feb 12, 2013 12:44 am    Post subject:
Qt5 integration first try
Reply with quote

Hi Vitezslav,

That's good to hear that Qt5 integration can work now. Could you please send your patches (complete source files are recommended) to the osg-submissions so Robert can review and merge them?


Cheers,


Wang Rui





2013/1/28 Vitezslav Zajic < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
Quote:
Hi Wang,
I've patched OSG to get multithreaded rendering working. I've used QGLContext::moveToThread, as you suggested, before the thread starts and the same function when the thread ends.

I'm sharing the patch. Maybe it will save a little of your time. Please note that I'm not sure this is the best way to do it, take it just as a hint what has to be done.

Cheers,
Vitezslav

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




Attachments:
http://forum.openscenegraph.org//files/osg_qt5_multithreading_564.txt


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
Martin Scheffler (Martin Scheffler)
Appreciator


Joined: 29 Mar 2009
Posts: 138

PostPosted: Wed Jun 12, 2013 12:22 pm    Post subject:
Reply with quote

Hi,

in reference to my submission here:
http://forum.openscenegraph.org/viewtopic.php?p=54555#54555

as I said, I simply submitted Vitezslavs patch. I can certainly try to remove the extra hooks from the osg main classes.
The moveToThread command must be called with the Qt widget and the Qt graphics thread before makeCurrent is called the first time.

Another thing I just realized: The code will only work when CMake option BUILD_OPENTHREADS_WITH_QT is set! Otherwise the static_cast in GraphicsWindowQt::moveToThread will fail.
How can I solve this? For multithreading to work with Qt5 it seems we need the render threads to be QThreads. Maybe add a flag to OpenThreads/Config and #ifdef against that?

Thank you!

Cheers,
Martin
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 8828

PostPosted: Wed Jun 12, 2013 1:10 pm    Post subject:
Qt5 integration first try
Reply with quote

Hi Martin,

On 12 June 2013 13:22, Martin Scheffler <> wrote:
Quote:
in reference to my submission here:
http://forum.openscenegraph.org/viewtopic.php?p=54555#54555

as I said, I simply submitted Vitezslavs patch. I can certainly try to remove the extra hooks from the osg main classes.
The moveToThread command must be called with the Qt widget and the Qt graphics thread before makeCurrent is called the first time.

What does moveToThread do? Is it a form of release context?

Under Windows the GraphicsWindowWin32::releaseContext() is implemented
with a wglMakeCurrent(_hdc, NULL) while X11 has glXMakeCurrent(
_display, None, NULL ). The release context is used to make sure that
a thread no longer retain a context as being current, allowing it to
be made current in another thread.



Quote:
Another thing I just realized: The code will only work when CMake option BUILD_OPENTHREADS_WITH_QT is set! Otherwise the static_cast in GraphicsWindowQt::moveToThread will fail.
How can I solve this? For multithreading to work with Qt5 it seems we need the render threads to be QThreads. Maybe add a flag to OpenThreads/Config and #ifdef against that?

Oh the joy of a windowing toolkit trying to do everything... It rather
does seem like a lot of hoops to jump through, and that we'd need to
compile the OSG against Qt, not just osgQt to get things to work.
Perhaps one way round would be for osgQt to provide it's own
OpenThreads integration, or perhaps for osgViewer to allow the
osg::GraphicThread threads to be provided in an more user definable
way.

Where I'd like to get to is have the core OSG usable directly and
independently from Qt, and only osgQt and the Qt examples requiring Qt
or a specific version of Qt.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
rmilh
User


Joined: 26 Feb 2009
Posts: 51

PostPosted: Wed Jun 12, 2013 8:07 pm    Post subject:
Qt5 integration first try
Reply with quote

Hi Martin,

Quote:
in reference to my submission here:
http://forum.openscenegraph.org/viewtopic.php?p=54555#54555

as I said, I simply submitted Vitezslavs patch. I can certainly try to remove the extra hooks from the osg main classes.
The moveToThread command must be called with the Qt widget and the Qt graphics thread before makeCurrent is called the first time.
Maybe there is a way to achieve multithreaded rendering in a
non-intrusive way by simply calling both new members (moveToThread and
moveBack) from GraphicsWindowQt itself. We could overload
GraphicsContext::setGraphicsThread and
GraphicsContext::releaseContextImplementation with something like this:

void GraphicsWindowQt::setGraphicsThread(osg::GraphicsThread* gt)
{
if (gt)
{
moveToThread(gt);
}

osgViewer::GraphicsWindow::setGraphicsThread(gt);
}

bool GraphicsWindowQt::releaseContextImplementation()
{
existing stuff here ...

// move context back to main thread
if (_widget->context()->thread() != qApp->thread())
{
moveBack();
}

return result;
}

Of course, setGraphicsThread should be made virtual if not already.

Quote:
Another thing I just realized: The code will only work when CMake option BUILD_OPENTHREADS_WITH_QT is set! Otherwise the static_cast in GraphicsWindowQt::moveToThread will fail.
How can I solve this? For multithreading to work with Qt5 it seems we need the render threads to be QThreads. Maybe add a flag to OpenThreads/Config and #ifdef against that?

Flag is ok ... or maybe we could add new api to OT, an api that can
return string like "qt", "win32", "pthreads", "sproc", "c++11"... ,
benign but useful ...

Robert Milharcic


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
EliteTUM
Newbie


Joined: 18 Aug 2013
Posts: 3

PostPosted: Sun Aug 18, 2013 4:01 pm    Post subject:
Assertion Error
Reply with quote

Hello Martin,

I tried your example using Qt5 x64 in MS VS 2012. It compiles and works nicely, but when the application is closed I get an Debug Assertion error (see attached Pic) in dbgdel.cpp, Line 51
Expression: _BLOCK_TYPE_IS_VALID( pHead->nBlockUse )

This is the Call Stack when the error is thrown:

Quote:

ntdll.dll!000000007793f0b1() Unknown
ntdll.dll!0000000077929351() Unknown
ntdll.dll!00000000778afae1() Unknown
KernelBase.dll!000007fefda53aca() Unknown
> msvcr110d.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036 C++
msvcr110d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322 C++
msvcr110d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 C++
msvcr110d.dll!operator delete(void * pUserData) Line 54 C++
qtOSGdefault.exe!Window::`scalar deleting destructor'(unsigned int) C++
Qt5Cored.dll!000000005729ff96() Unknown
Qt5Cored.dll!000000005729a165() Unknown
Qt5Guid.dll!000007fee829fe5b() Unknown
Qt5Widgetsd.dll!000000005651ad66() Unknown
Qt5Widgetsd.dll!000000005651aed7() Unknown
Qt5Widgetsd.dll!0000000056513151() Unknown
Qt5Widgetsd.dll!00000000565128fb() Unknown
Qt5Widgetsd.dll!00000000564c06a6() Unknown
qtOSGdefault.exe!WindowHolderWidget::~WindowHolderWidget() Line 15 C++
qtOSGdefault.exe!WindowHolderWidget::`scalar deleting destructor'(unsigned int) C++
Qt5Cored.dll!000000005729ff96() Unknown
Qt5Widgetsd.dll!00000000564c067d() Unknown
qtOSGdefault.exe!main(int argc, char * * argv) Line 49 C++
qtOSGdefault.exe!WinMain(HINSTANCE__ * instance, HINSTANCE__ * prevInstance, char * __formal, int cmdShow) Line 131 C++
qtOSGdefault.exe!__tmainCRTStartup() Line 528 C
qtOSGdefault.exe!WinMainCRTStartup() Line 377 C
kernel32.dll!000000007768652d() Unknown
ntdll.dll!00000000778bc521() Unknown


I somehow don't get the error. Any ideas?


Thank you!

Cheers,
Jonathan
Back to top
View user's profile Send private message
CLST755
Newbie


Joined: 17 Sep 2012
Posts: 9

PostPosted: Fri Jul 11, 2014 11:18 am    Post subject:
Qt5 integration
Reply with quote

Hi,
i found another way to fix the threading problem without changing osg.
However its quite more complex and still requires openthreads to be build with qt.

My solution uses a custom osgViewer::GraphicsWindow that derives from osgQt::GraphicsWindowQt.

The makeCurrentImplementation method now first checks if the calling thread is the one that owns the OpenGL context. If not the main thread (which owns the context at this point) is instructed to move the context to the calling thread (usually the GraphicsThread) using a blocking connection.
When moving the context to another thread the finished method of that thread is connected with a slot that moves the context back to the main thread using a direct connection this time.

It is important that the main thread does not wait for the GraphicsThread before the context is moved, otherwise both threads deadlock. Hence osgViewer::realize() must be called before calling osgViewer::frame().

Cheers,
Claus
Back to top
View user's profile Send private message
John D
Newbie


Joined: 29 Aug 2014
Posts: 2

PostPosted: Thu Sep 18, 2014 12:05 am    Post subject:
Reply with quote

Hi,

Claus. Are you willing to share the source code.

Thank you!

Cheers,
John
Back to top
View user's profile Send private message
CLST755
Newbie


Joined: 17 Sep 2012
Posts: 9

PostPosted: Thu Sep 18, 2014 9:19 am    Post subject:
Reply with quote

Sure,
http://pastebin.com/W2QJj8bQ

You might need to expose some more methods from the viewer that is capsuled (e.g. osgViewer::getCamera). I have not included that in the snippet to keep it short.

Cheers,
Claus
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts OSG CEGUI integration updated for ceg... cbuchner1 General 1 Tue Sep 16, 2014 1:52 pm View latest post
No new posts create a OSG wiki: (it was OpenSceneG... Jordi Torres General 30 Wed Aug 27, 2014 3:36 pm View latest post
No new posts osgLeap Leap Motion Integration Mathieu General 2 Mon Mar 24, 2014 2:30 pm View latest post
No new posts Qt Form integration oelmas General [3rdparty] 1 Mon Mar 24, 2014 9:19 am View latest post
No new posts State of Qt5 integration? Martin Scheffler General 4 Fri Mar 21, 2014 11:49 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP