Re: [osg-users] How to force reloading the texture in the shader

2011-08-30 Thread Robert Osfield
HI Fred,

What is probably happening is the update to the texture is happening
just fine, but the previous frames draw traversal is still running so
sees the update to the image and downloads and uses it right away.
Setting the threading to SingleThreaded will prevent the osgViewer
from running the update in parallel to the previous draw traversal so
avoid this issue of texture being applied a frame early.

However, a better solution is to set the DataVariance on the StateSet
that the Texture is associated with to DYNAMIC stateset so that the
draw traversal knows to hold back the next frame till all the elements
that are changing have been dispatched first.  The checked for
DataVariance is only done at Drawable and StateSet level so setting
this directly on the Texture won't help.

A a general note, make sure your a using an osg::ImageStream for
continuously updating data as this subclass from osg::Image adds the
use of PixelBufferObject automatically, this provides a much more
efficient means for downloading the data to OpenGL.

Robert.

On Mon, Aug 29, 2011 at 10:32 PM, Fred Maulir wallys...@live.com wrote:
 Hello to All,

 I'm having a very specific issue using OpenSceneGraph. While using a texture 
 shader I developped, I need to attach a texture to my object. But my texture 
 need to be changed at each frame. However, I noticed that my texture is not 
 updated in the next viewer.update() if my computer is very fast. If I slow 
 down my computer it is correctly synchronized.

 In other word, I'm looking for a way to way for a texture object to be 
 propagated in the gpu buffer before rendering the frame.

 As I'm using OpenSceneGraph for simulation purpose even 1 frame offset is not 
 acceptable for me.


 Basically the code can be summed up this way:

 Code:

 osg::Image IMAGE;
 IMAGE-setImage(..., imageData, osg::Image::AllocationMode::NO_DELETE);

 osg::StateSet *mystate = new osg::StateSet();
 osg::Texture2D *texture = new osg::Texture2D();
 texture-setImage(IMAGE);

 (...)

 for(int i=0;i!viewer-done();++i)
 {
 IMAGE-setImage(..., ImageData[i], osg::Image::AllocationMode::NO_DELETE);


 viewer-frame(ctime);
 }



 In this example when rendering the scene OSG sometimes uses the ImageData of 
 index i-1 instead of index i


 If anyone can help me I would be very happy.
 Regards.

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





 ___
 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] How to force reloading the texture in the shader

2011-08-29 Thread Fred Maulir
Hello to All,

I'm having a very specific issue using OpenSceneGraph. While using a texture 
shader I developped, I need to attach a texture to my object. But my texture 
need to be changed at each frame. However, I noticed that my texture is not 
updated in the next viewer.update() if my computer is very fast. If I slow down 
my computer it is correctly synchronized.

In other word, I'm looking for a way to way for a texture object to be 
propagated in the gpu buffer before rendering the frame.

As I'm using OpenSceneGraph for simulation purpose even 1 frame offset is not 
acceptable for me.


Basically the code can be summed up this way:

Code:

osg::Image IMAGE;
IMAGE-setImage(..., imageData, osg::Image::AllocationMode::NO_DELETE);

osg::StateSet *mystate = new osg::StateSet();
osg::Texture2D *texture = new osg::Texture2D();
texture-setImage(IMAGE);

(...)

for(int i=0;i!viewer-done();++i)
{
IMAGE-setImage(..., ImageData[i], osg::Image::AllocationMode::NO_DELETE);


viewer-frame(ctime);
}



In this example when rendering the scene OSG sometimes uses the ImageData of 
index i-1 instead of index i


If anyone can help me I would be very happy.
Regards.

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





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


Re: [osg-users] How to force reloading the texture in the shader

2011-08-29 Thread Sergey Polischuk
Hi, Fred

Try setting singlethreaded threading model to viewer 
(viewer-setThreadingModel(osgViewer::ViewerBase::SingleThreaded)) or setting 
texture data variance to dynamic 
(texture-setDataVariance(osg::Object::DYNAMIC))

Cheers,
Sergey.

30.08.2011, 01:32, Fred Maulir wallys...@live.com:
 Hello to All,

 I'm having a very specific issue using OpenSceneGraph. While using a texture 
 shader I developped, I need to attach a texture to my object. But my texture 
 need to be changed at each frame. However, I noticed that my texture is not 
 updated in the next viewer.update() if my computer is very fast. If I slow 
 down my computer it is correctly synchronized.

 In other word, I'm looking for a way to way for a texture object to be 
 propagated in the gpu buffer before rendering the frame.

 As I'm using OpenSceneGraph for simulation purpose even 1 frame offset is not 
 acceptable for me.

 Basically the code can be summed up this way:

 Code:

 osg::Image IMAGE;
 IMAGE-setImage(..., imageData, osg::Image::AllocationMode::NO_DELETE);

 osg::StateSet *mystate = new osg::StateSet();
 osg::Texture2D *texture = new osg::Texture2D();
 texture-setImage(IMAGE);

 (...)

 for(int i=0;i!viewer-done();++i)
 {
 IMAGE-setImage(..., ImageData[i], osg::Image::AllocationMode::NO_DELETE);

 viewer-frame(ctime);
 }

 In this example when rendering the scene OSG sometimes uses the ImageData of 
 index i-1 instead of index i

 If anyone can help me I would be very happy.
 Regards.

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

 ___
 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] How to force reloading the texture in the shader

2011-08-29 Thread Fred Maulir
Sergey.

Thanks really A LOT for your fast and VERY EFFICIENT help. This problem drove 
me crazy for a while.

The setting texture-setDataVariance(osg::Object::DYNAMIC) did not help but the 
viewer-setThreadingModel(osgViewer::ViewerBase::SingleThreaded) worked very 
well.

Thanks again for your help.
Regards.

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





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