Hi,

I'm having a problem in my custom shader while updating my texture2D using 
image->dirty() function. Following there is the relevant code snippet. 


Code:

osg::StateSet* stateset = geom1->getOrCreateStateSet();

osg::ref_ptr<osg::Program> program = new osg::Program;
osg::ref_ptr<osg::Shader> vertexSource = new osg::Shader(osg::Shader::VERTEX);
osg::ref_ptr<osg::Shader> fragmentSource = new 
osg::Shader(osg::Shader::FRAGMENT);

vertexSource->setShaderSource(vert);
fragmentSource->setShaderSource(frag);

program->addShader(vertexSource);
program->addShader(fragmentSource);

stateset->setAttributeAndModes(program.get());
stateset->setDataVariance(osg::Object::DYNAMIC);

////
osg::ref_ptr<osg::Image> diffuseImage = osgDB::readImageFile(".\\img0.png");
std::cout << " File " << diffuseImage->getFileName() << " " << std::endl; // it 
prints img0

osg::ref_ptr<osg::Texture2D> diffuseTex = new osg::Texture2D;
diffuseTex->setDataVariance(osg::Object::DYNAMIC);
diffuseTex->setImage(diffuseImage.get());

stateset->setTextureAttributeAndModes(0, diffuseTex.get(), 
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

osg::ref_ptr<osg::Uniform> cDiffTex = new 
osg::Uniform(osg::Uniform::SAMPLER_2D, "cDiffTex");
cDiffTex->set(0);
stateset->addUniform(cDiffTex.get());

diffuseImage = osgDB::readImageFile(".\\img1.jpg");
diffuseImage->dirty();
std::cout << " File " << diffuseImage->getFileName() << " " << std::endl; // it 
prints img1->GOOD the diffuseImage is updated
std::cout << " Tex " << diffuseTex->getImage()->getFileName() << " " << 
std::endl; // it prints img0->BAD the image object of texture is not updated
// NEED TO TELL TEXTURE TO SET THE IMAGE TO HAVE IT UPDATED
//diffuseTex->setImage(diffuseImage);
//std::cout << " Tex " << diffuseTex->getImage()->getFileName() << " " << 
std::endl;




I simply set an image (img0) to a texture2D (diffuseTex) and what I would  like 
to do is updating the image\texture. Unfortunately what I get is that the 
diffuseTex->getImage() function is pointing to the original image while the 
object diffuseImage is correctly updated.
If I'm putting the setImage again on texture it is correctly updated.
Am I doing something wrong in passing the image to a texture? Because I've read 
that using dirty() function is possible to update all textures that are sharing 
the image object with no further actions.
Sorry I'm a newbie in OSG.

Thank you!

Cheers,
Fabrizio[/i]

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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to