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 

[SOLVED] How to force reloading the texture in the shader


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
wallysx
Newbie


Joined: 22 Jul 2011
Posts: 13

PostPosted: Mon Aug 29, 2011 9:32 pm    Post subject:
[SOLVED] How to force reloading the texture in the shader
Reply with quote

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.


Last edited by wallysx on Tue Aug 30, 2011 1:16 am; edited 1 time in total
Back to top
View user's profile Send private message
hybr
Appreciator


Joined: 26 Jun 2009
Posts: 454

PostPosted: Mon Aug 29, 2011 9:59 pm    Post subject:
How to force reloading the texture in the shader
Reply with quote

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" <>:
Quote:
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




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


Joined: 22 Jul 2011
Posts: 13

PostPosted: Tue Aug 30, 2011 1:16 am    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12348

PostPosted: Tue Aug 30, 2011 7:59 am    Post subject:
How to force reloading the texture in the shader
Reply with quote

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 <> wrote:
Quote:
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









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


Joined: 31 May 2012
Posts: 26

PostPosted: Mon Jul 09, 2012 3:41 pm    Post subject:
Help first frame
Reply with quote

Hi,
I've code something like the snippet you have posted...but i'me able to see just first frame...could you help me to solve this problem?

Thank you!

Cheers,
Antonio
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
Page 1 of 1

 
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 Wrapping Text around object as texture johansson_gbg General 0 Tue Oct 15, 2019 7:45 am View latest post
No new posts Image from shader lucasamparo General 14 Thu Oct 03, 2019 5:46 pm View latest post
No new posts How do I move a Texture in an model ... newlife958 General 10 Tue Sep 17, 2019 1:16 am View latest post
No new posts Render to Texture and osgQt (osgQOpenGL) wroos General 3 Mon Sep 16, 2019 5:47 pm View latest post
No new posts [OSG 3.6.3 Core Profile GL 3+] Weird ... johansson_gbg General 2 Thu Sep 12, 2019 1:17 pm 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