Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Hi Chris, thanks for pointing me to the right direction. Unfortunately, it didn't work as expected, probably because I still don't get things right in my head ;) However, I found a workaround that works quite well: I simply destroy my viewer before I get a context loss. I can still keep my scene so everything looks as before leaving the app. When going back into the application, I simply create a new viewer and everything works smooth :) Best regards, Martin Am Mi., 24. Juli 2019 um 03:28 Uhr schrieb Chris Djali : > > Hi, > > You can't release objects that belong to a destroyed context, so you > definitely need to call all the releaseGLObjects methods before the context > is destroyed. You shouldn't need to call it on the root node provided the > root node is still attached to the viewer when the viewer and context are > destroyed, as the normal viewer does this for you. > > You need to give the state associated with the context that's being destroyed > if you just want to clear GL objects for that context. If you're fine > deleting things from every context (e.g. because you've only got one context > or destroy them all at once) you can just pass a null pointer, and it'll do > it for all contexts. > > flushAllDeletedGLObjects gets called automatically unless you're using a > weird viewer (which is possible given that you're using Android, but I'd > guess it isn't happening). > > > > If I were in your situation, if you're loading fonts from files, I'd try > calling releaseGLObjects on the object cache > (osgDB::Registry::instance()->getObjectCache()->releaseGLObjects();) right > before the context is closed, and if you're letting OSG use its default font, > I'd do the default font instead > (osgText::Font::getDefaultFont()->releaseGLObjects();). If either of these > helps, then the problem is what I think it is. I've not looked at the Android > examples, so I don't know where you'd put the call, though. > > > Cheers, > Chris > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=76475#76475 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Hi, You can't release objects that belong to a destroyed context, so you definitely need to call all the releaseGLObjects methods before the context is destroyed. You shouldn't need to call it on the root node provided the root node is still attached to the viewer when the viewer and context are destroyed, as the normal viewer does this for you. You need to give the state associated with the context that's being destroyed if you just want to clear GL objects for that context. If you're fine deleting things from every context (e.g. because you've only got one context or destroy them all at once) you can just pass a null pointer, and it'll do it for all contexts. flushAllDeletedGLObjects gets called automatically unless you're using a weird viewer (which is possible given that you're using Android, but I'd guess it isn't happening). If I were in your situation, if you're loading fonts from files, I'd try calling releaseGLObjects on the object cache (osgDB::Registry::instance()->getObjectCache()->releaseGLObjects();) right before the context is closed, and if you're letting OSG use its default font, I'd do the default font instead (osgText::Font::getDefaultFont()->releaseGLObjects();). If either of these helps, then the problem is what I think it is. I've not looked at the Android examples, so I don't know where you'd put the call, though. Cheers, Chris -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=76475#76475 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Dear Robert, what is the correct order of the calls I have to made? : a) Context detroyed b) call releaseGLObjects. This required a state argument. Which state do I have to put in here? Is it sufficient to call this on the root node of my scene graph? c) what about osg::flushAllDeletedGLObjects? Is this called automatically? Or do I have to call releaseGlObjects BEFORE the context is destroyed? Sorry for asking these probably stupid questions. What would be a more standard way of doing things (on android)? Is a context loss so exotic? Regarding VSG: I'd really love playing around with Vulkan. Unfortunately, two things are making me to stick to OpenGL: 1) Vulkan requires Android 8. Therefore, many phones would not be supported. 2) Not enough time to get into Vulkan at the moment :( I actually don't need much features, so VSG might be nice in future: - Geometry creation from own tesselations - Edge/Line rendering - Picking / Intersections - Custom Shaders - Text Nodes Martin ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Hi, This is almost certainly due to one of the issues I've outlined here: http://forum.openscenegraph.org/viewtopic.php?p=76471#76471 The standard viewer definitely doesn't clean everything up that it's supposed to, as demonstrated by the examples I gave in that thread. Specifically, this example shows that the static default font isn't released: http://forum.openscenegraph.org/viewtopic.php?p=76365#76365, and this example shows that loaded fonts living in the object cache aren't released: http://forum.openscenegraph.org/viewtopic.php?p=76345#76345. You'll need to run these examples through an OpenGL debugger like CodeXL that tells you when things aren't released. Cheers, Chris -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=76472#76472 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Hi Martin, The osg::Node's have releaseGLObjects() that help disconnect the GLObjects from the scene graph, these get put in several backend containers for the GLObjects, that get cleaned up by a call to osg::flushAllDeletedGLObjects. The standard viewer should be doing all this for you, but in your case you'll be using a non standard route thanks to the constraints of Android windowing. I'm not the author of the the Android windowing example so can't comment on the specifics. I guess there is chance there is an error at the viewer level somewhere. As general comment, the VSG project is probably a better fit for Android than the OSG, thanks to both the Vulkan and the lightweight design/implementation of the VSG. Under Vulkan you create most graphics objects tied to the Vulkan Instance, when a window is resized or closed/opened you have to recreate the window related objects, but other objects can be shared. This recreation of objects happens for all platforms so it's not a Android special issue like it is for OpenGL, so it's more likely we'll be able to spot issues and debug them prior to a port to Android. The VSG still early it's life though, so feature wise it's a long way behind the OSG right now. It's still a moving target too, but if you don't need a wide range of OSG features then you might be able to get by with the VSG. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Dear Robert, I am now on master. The problems still exist. > Those shaders are related to the shader pipeline that is only part of master, > they don't exist in 3.6. You are right. Lets forget the inbuilt shaders. The problems occur also with my own shaders. The only place I use the inbuilt ones are for text nodes. Those also existed in rc3. > Or are you using osgUtil::ShaderGen? No. > What hardware/software Android platform are you testing with? I am testing it in the android emulator that comes with the Android SDK. Additionally I also have a One Plus 3 around, which show the same problems. Is there any way I can help you setting up an Android Dev environment? I am thinking of a virtual machine that I could create for testing. Or step by step instructions, how to build OSG and the example. But maybe lets not focus too much on android. It seems, that similar issues also occurred with qt, when a gl context was recreated. My question is, how to properly notify to OSG, that all shaders + uniforms are invalid such that it recompiles them. Actually, OSG already recompiles the shader after creating a new embedded window and therefore increasing the context id. Maybe the old shader objects are not disposed properly and are still attached to the stateset (just guessing). Unfortunately, I don't know OSG much that I can find out, what is actually going wrong. Martin Am Di., 23. Juli 2019 um 11:03 Uhr schrieb Robert Osfield : > > Hi Martin, > > On Mon, 22 Jul 2019 at 19:33, Martin Siggel > wrote: > > I am using OSG 3.6.4-rc3. > > That's from back in January so it would be worth updating to 3.6.4-rc8. > > I've done a diff between rc3 and rc8 and overall there are quite a few fixes, > I couldn't see a change that would affect things for you with osgText. > > > The only built-in shaders I am using right now are the osgText shaders: > https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osgText/shaders > > These are automatically bound, when no other shaders are added to a text node. > > > When I don't add shaders to a geometry node, other built-in shaders seem to > > get active as well. I guess these are the ones from > > https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osg/shaders. > > Those shaders are related to the shader pipeline that is only part of master, > they don't exist in 3.6. If you are aren't creating your own shaders do they > come with your data? Or are you using osgUtil::ShaderGen? > > > When I e.g. use osgText, the text will appear after starting the > > application. When I go to the android main screen and then go back to the > > app, the text nodes will become black rectangles. Somehow, osg seems to > > reference still the "old" objects from the context before. > > > Still, from the log I can verify, that shaders are compiled again after > > resuming to the app. > > What hardware/software Android platform are you testing with? > > > I could provide a "minimal" example if anyone is interested. > > I don't personally have a Android dev environment setup, so I can't test. I > was hoping that other Android users would chip in here, unfortunately the > forum has been a bit unreliable of late so perhaps this is contributing. > > Cheers, > Robert. > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Hi Martin, On Mon, 22 Jul 2019 at 19:33, Martin Siggel wrote: > I am using OSG 3.6.4-rc3. That's from back in January so it would be worth updating to 3.6.4-rc8. I've done a diff between rc3 and rc8 and overall there are quite a few fixes, I couldn't see a change that would affect things for you with osgText. > The only built-in shaders I am using right now are the osgText shaders: https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osgText/shaders These are automatically bound, when no other shaders are added to a text node. > When I don't add shaders to a geometry node, other built-in shaders seem to get active as well. I guess these are the ones from https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osg/shaders . Those shaders are related to the shader pipeline that is only part of master, they don't exist in 3.6. If you are aren't creating your own shaders do they come with your data? Or are you using osgUtil::ShaderGen? > When I e.g. use osgText, the text will appear after starting the application. When I go to the android main screen and then go back to the app, the text nodes will become black rectangles. Somehow, osg seems to reference still the "old" objects from the context before. > Still, from the log I can verify, that shaders are compiled again after resuming to the app. What hardware/software Android platform are you testing with? > I could provide a "minimal" example if anyone is interested. I don't personally have a Android dev environment setup, so I can't test. I was hoping that other Android users would chip in here, unfortunately the forum has been a bit unreliable of late so perhaps this is contributing. Cheers, Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
Dear Robert, I am using OSG 3.6.4-rc3. The only built-in shaders I am using right now are the osgText shaders: https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osgText/shaders These are automatically bound, when no other shaders are added to a text node. When I don't add shaders to a geometry node, other built-in shaders seem to get active as well. I guess these are the ones from https://github.com/openscenegraph/OpenSceneGraph/tree/master/src/osg/shaders . When I e.g. use osgText, the text will appear after starting the application. When I go to the android main screen and then go back to the app, the text nodes will become black rectangles. Somehow, osg seems to reference still the "old" objects from the context before. Still, from the log I can verify, that shaders are compiled again after resuming to the app. I could provide a "minimal" example if anyone is interested. Martin. Am Mo., 22. Juli 2019 um 17:24 Uhr schrieb Robert Osfield < robert.osfi...@gmail.com>: > HI Martin, > > I don't have any Android experience so will defer to others on the > specifics, but one question everyone will probably have is what version of > the OSG are you using? When you say the OSG's "built in" shaders, which > ones do you actually mean as there isn't any single set of "built in" > shaders - various NodeKits provide their own shaders, and there is a > osgUtil::ShaderGenVisitor that can create shaders for basic fixed function > scene graph, but it's written for desktop rather that GLES2. For GLES2 > applications one normally has to write your own shaders. > > Robert. > > On Mon, 22 Jul 2019 at 13:17, Martin Siggel > wrote: > >> Hi @all, >> >> I built a prototypical Android application based on your OSG GLES 2.0 >> example. As also users in the OSG forum pointed out, the problem with >> this example application is, that is reinitialized everything, when >> e.g. leaving the app, changing the screen orientation and so on. >> >> I worked around this by just calling again >> 'setUpViewerAsEmbeddedInWindow' instead of creating everything from >> scratch. >> >> This seems to work pretty well, but sometimes - after a EGL context >> loss - the shader programs are somehow lost or invalid, resulting in a >> wrong rendering. This even happens, when using OSG's default shaders. >> >> When debugging OSG, it seems to me, that OSG tries to clean up all GL >> objects - including the shaders and reinitialize everything (also >> compiling the shader objects). >> >> Still, it happens, that the shaders get invalid sometimes and I'll get >> the error: >> >>s_glUseProgram:2041 GL error 0x501 >> >> Which basically means invalid program. Are the shader handled somehow >> differently? What do I have to do, in order to properly cleanup >> everything? >> >> Does anyone of you have any example surviving correctly a context loss >> e.g. due to application switch? >> >> Here are forum entries that describe a similar problem: >> >> http://forum.openscenegraph.org/viewtopic.php?t=11270 >> http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number >> 4.) >> >> >> Best regards, >> Martin >> ___ >> osg-users mailing list >> osg-users@lists.openscenegraph.org >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- Dr. Martin Siggel Neusser Straße 257 50733 Köln Phone: 0178 6729772 martinsig...@googlemail.com ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Android: Survive Context Loss without complete reinitialization
HI Martin, I don't have any Android experience so will defer to others on the specifics, but one question everyone will probably have is what version of the OSG are you using? When you say the OSG's "built in" shaders, which ones do you actually mean as there isn't any single set of "built in" shaders - various NodeKits provide their own shaders, and there is a osgUtil::ShaderGenVisitor that can create shaders for basic fixed function scene graph, but it's written for desktop rather that GLES2. For GLES2 applications one normally has to write your own shaders. Robert. On Mon, 22 Jul 2019 at 13:17, Martin Siggel wrote: > Hi @all, > > I built a prototypical Android application based on your OSG GLES 2.0 > example. As also users in the OSG forum pointed out, the problem with > this example application is, that is reinitialized everything, when > e.g. leaving the app, changing the screen orientation and so on. > > I worked around this by just calling again > 'setUpViewerAsEmbeddedInWindow' instead of creating everything from > scratch. > > This seems to work pretty well, but sometimes - after a EGL context > loss - the shader programs are somehow lost or invalid, resulting in a > wrong rendering. This even happens, when using OSG's default shaders. > > When debugging OSG, it seems to me, that OSG tries to clean up all GL > objects - including the shaders and reinitialize everything (also > compiling the shader objects). > > Still, it happens, that the shaders get invalid sometimes and I'll get > the error: > >s_glUseProgram:2041 GL error 0x501 > > Which basically means invalid program. Are the shader handled somehow > differently? What do I have to do, in order to properly cleanup > everything? > > Does anyone of you have any example surviving correctly a context loss > e.g. due to application switch? > > Here are forum entries that describe a similar problem: > > http://forum.openscenegraph.org/viewtopic.php?t=11270 > http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number > 4.) > > > Best regards, > Martin > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Android: Survive Context Loss without complete reinitialization
Hi @all, I built a prototypical Android application based on your OSG GLES 2.0 example. As also users in the OSG forum pointed out, the problem with this example application is, that is reinitialized everything, when e.g. leaving the app, changing the screen orientation and so on. I worked around this by just calling again 'setUpViewerAsEmbeddedInWindow' instead of creating everything from scratch. This seems to work pretty well, but sometimes - after a EGL context loss - the shader programs are somehow lost or invalid, resulting in a wrong rendering. This even happens, when using OSG's default shaders. When debugging OSG, it seems to me, that OSG tries to clean up all GL objects - including the shaders and reinitialize everything (also compiling the shader objects). Still, it happens, that the shaders get invalid sometimes and I'll get the error: s_glUseProgram:2041 GL error 0x501 Which basically means invalid program. Are the shader handled somehow differently? What do I have to do, in order to properly cleanup everything? Does anyone of you have any example surviving correctly a context loss e.g. due to application switch? Here are forum entries that describe a similar problem: http://forum.openscenegraph.org/viewtopic.php?t=11270 http://forum.openscenegraph.org/viewtopic.php?t=14549 (see point number 4.) Best regards, Martin ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org