Re: [osg-users] Offscreen rendering of large scenes

2019-12-10 Thread Werner Modenbach
Hi Philipp,

I'm not sure, if I really understand what you intend to do.

In my case my scene is very complex and I get timeouts on my graphic card.
So I do a rendering into many tiles, each holding a small portion of the scene.
Thus culling avoids transfer of the complete data onto the graphic card.
The tiles are assigned to a quadtree and rendered with paged LOD.

Would that also be a solution for you?

- Werner -

Am 10.12.2019 um 16:42 schrieb Philipp Wagner:
> Hi,
>
> I want to perform an offscreen rendering of a scene that is too large to fit 
> into the GPU memory at once (lots of big textures).
> My idea was to render parts of the scene each in its own frame, and disable 
> the clearing of the depth and color buffer.
> This does work for the color buffer, but the depth buffer seems to be cleared 
> after each frame, which leads to incorrect results (The later parts are drawn 
> over the previous
> ones, even though they are behind the other parts).
>
> The algorithm:
> 1. Create camera/context/...
> 2. Clear the buffers (i.e. Render an empty scene with a clear mask of 
> (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)
> 3. Disable buffer clearing
> 4. Render each part in its own frame
>  a. Add part to the scene
>  b. Render
>  c. Remove part from the scene
> 5. Read back color buffer
>
>
> osg::ref_ptr<::osg::Camera> camera = new osg::Camera();
>
> //Here we set the camera orientation/projection matrix
>
> camera->setClearColor(...);
> camera->setGraphicsContext(context);
>
> osg::ref_ptr img = new osg::Image;
> img->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);
> camera->attach(osg::Camera::COLOR_BUFFER0, img, numSamples);
> camera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT32);
> camera->setRenderOrder(osg::Camera::PRE_RENDER);
> camera->setRenderTargetImplementation(osg::Camera::RenderTargetImplementation::FRAME_BUFFER_OBJECT);
> camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
> camera->setProjectionResizePolicy(osg::Camera::FIXED);
> camera->setViewport(0, 0, img->s(), img->t());
> viewer->addSlave(camera);
>
> camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
> viewer->frame();
> camera->setClearMask(0);
> for (auto& item : parts)
> {
>    //Here we create and add the item to the scene...
>    viewer->frame();
>    //Here we remove item from the scene and delete it
> }
>
> Thanks in advance
> Phil
> -- 
> You received this message because you are subscribed to the Google Groups 
> "OpenSceneGraph Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to osg-users+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/osg-users/c6f7907d-6c89-4c00-973c-f9dc0585ae32%40googlegroups.com
> .
>
> ___
> 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] Offscreen rendering of large scenes

2019-12-10 Thread Philipp Wagner
Hi,

I want to perform an offscreen rendering of a scene that is too large to 
fit into the GPU memory at once (lots of big textures).
My idea was to render parts of the scene each in its own frame, and disable 
the clearing of the depth and color buffer.
This does work for the color buffer, but the depth buffer seems to be 
cleared after each frame, which leads to incorrect results (The later parts 
are drawn over the previous ones, even though they are behind the other 
parts).

The algorithm:
1. Create camera/context/...
2. Clear the buffers (i.e. Render an empty scene with a clear mask of 
(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)
3. Disable buffer clearing
4. Render each part in its own frame
 a. Add part to the scene
 b. Render
 c. Remove part from the scene
5. Read back color buffer


osg::ref_ptr<::osg::Camera> camera = new osg::Camera();

//Here we set the camera orientation/projection matrix

camera->setClearColor(...);
camera->setGraphicsContext(context);

osg::ref_ptr img = new osg::Image;
img->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, 
GL_UNSIGNED_BYTE);
camera->attach(osg::Camera::COLOR_BUFFER0, img, numSamples);
camera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT32);
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setRenderTargetImplementation(osg::Camera::RenderTargetImplementation::FRAME_BUFFER_OBJECT);
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
camera->setProjectionResizePolicy(osg::Camera::FIXED);
camera->setViewport(0, 0, img->s(), img->t());
viewer->addSlave(camera);

camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
viewer->frame();
camera->setClearMask(0);
for (auto& item : parts)
{
   //Here we create and add the item to the scene...
   viewer->frame();
   //Here we remove item from the scene and delete it
}

Thanks in advance
Phil

-- 
You received this message because you are subscribed to the Google Groups 
"OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osg-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osg-users/c6f7907d-6c89-4c00-973c-f9dc0585ae32%40googlegroups.com.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Texture Caching Problem with 3.6.3/4

2019-12-10 Thread Robert Osfield


On Monday, 9 December 2019 19:57:27 UTC, Greg D wrote:
>
> My quick fix is to clear the cache on the first render (and call clear 
> thereafter).  OpenFlight files open and render fine now.  Is this a safe 
> fix?
>
> void ViewerBase::frame(double simulationTime)
> {
> 
> osgDB::Registry::instance()->clearObjectCache();  // ADDED TO CLEAR CACHE 
> AFTER RENDER SINCE IT BECOMES CORRUPTED
> }
>
>
Adding this line to ViewerBase is a point of information about the problem 
rather than a fix.  FYI, you can override Viewer::frame() by just 
subclassing Viewer there is no need to modify the OSG itself.  You can also 
call the clear after the frame() in your own frame loop.  However, all of 
these clearObjectCache() changes are hacks around a different problem.

>From your previous post that the change to OpenFlight's use of local cache 
vs ObjectCache indicates to me that the memory optimization of unrefering 
the osg::Image after the image data has been applied to the Textures 
texture object.  If an Texture is in the cache and could be reused *and* 
the texture object data is released between the first use but before that 
Texture is later reused.

The potential fixes are :

Nt enable Texture::UnrefImageAfterApply  - this is set to true by the 
osgUtil::Optimizer's TextureVisitor.  Is you app call the Optimizer on 
loaded databases?
Don't delete the graphics contexts, instead just close the window and 
reopen it when you need it.
Don't enable the object cache usage.

A fix at the OSG would be for the OjbectCache to automatically detect the 
usage case where a Texture is in the case, it's been compiled and the image 
unreferred, the context deleted, then the Texture requested from the 
cache.   The place to do this would probably be 
ObjectCache::releaseGLObjects(osg::State* state).  It'd need to 
dynamic_cast the Objects in the cache to find the textures then 
remove the Texture from the cache if it's got UnrefImageAfter enabled and 
no osg::Image still attached to it.

Robert.




-- 
You received this message because you are subscribed to the Google Groups 
"OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osg-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osg-users/d726cd31-ce28-43ce-814c-1e293da836b8%40googlegroups.com.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org