Hello,
thanks for the answer of my last post, it doesn't crash anymore. But I have
another problem now :
I use a SHLChunk to display an object. I have called setVertexProgram and
setFragmentProgram and the shader executes, no problem. I also set some
constant parameters with some floats, etc., and that's OK. Now, I want to use a
sampler3D. So I call :
_shl->setUniformParameter("samplerName", 0)
where samplerName is the name of the sampler3D declared in my fragment program
and 0 is - I believe, tell me if I'm wrong - the slot of the texture.
Then, I do :
beginEditCP(tChunk); tChunk->setImage(img);
endEditCP(tChunk);
where tChunk is a TextureChunk which has just been created before but there's
nothing inside right now.
Then :
beginEditCP(cmat);
cmat->addChunk(texChunk);
endEditCP(cmat);
where cmat is the ChunkMaterial I use.
And then, in an other function, I set my image and tell the texture chunk it has
changed (imageContentChanged()).
For a reason I can't explain here, when I want to set this image, I have to get
this image from the ChunkMaterial and the number of the texture slot in it
(slotNumber). Here's how i'm doing this (which is probably not the best way to
do it, but it seems to work ) :
StateChunkPtr stateChunk = NullFC;
// get the chunks associated to this chunkmaterial :
MFStateChunkPtr lesChunks = pM->getChunks();
Int32 numeroSlotTexture = -1;
for(MFStateChunkPtr::iterator it = lesChunks.begin(); it != lesChunks.end() &&
stateChunk == NullFC; ++it)
{
const StateChunkClass * classe = (*it)->getClass();
// we choose only the chunks of type : Texture
std::string nomClasseChunk(classe->getName());
if(nomClasseChunk == "Texture")
{
// we found a texture slot, so we increment the corresponding number :
numeroSlotTexture++;
// if the number equals the one we want to set
if(numeroSlotTexture == slotNumber)
{
stateChunk = (*it);
}
}
}
if(stateChunk == NullFC)
{
// ... ERROR
}
else
{
TextureChunkPtr tChunk = TextureChunkPtr::dcast(stateChunk);
if(tChunk == NullFC)
{
// ... ERROR :
}
// now, we're sure we've got a texture chunk corresponding to the given slot
number :
else
{
beginEditCP(tChunk);
tChunk->setImage(img);
endEditCP(tChunk);
}
}
Are you still with me? Ok. Now, all of this seems to work given that I manage to
do the setImage, which means it succeeds when looking for a given texture slot
in a given material chunk. But when I render it, the texture used in my shader
is the last texture used in the scene, for another object. I mean : I have 2
objects in my scene : a textured box and my object, which is the only one which
has the chunk material with the shl chunk, the texture chunk, etc. (all that I
just explained here). And the shader executes well BUT it uses the wrong
texture : it uses the one of the box (and not the one I set with setImage,
which is an image calculated by myself).
So what's wrong? Have I misunderstood something about the texture slots? I think
I understood that the number 0 in :
_shl->setUniformParameter("samplerName", 0)
means the number of the texture slot to be used. And so when I call once
addChunk(tChunk) on my material, I think I add the texture chunk on the first
free texture chunk slot (which corresponds to the previous 0). So when I'm
looking for a texture chunk with the slotNumber = 0, I think I get the texture
chunk on the slot 0. So I think it's OK. But it's not, so I must be wrong
somewhere. Can you help me?
Sorry for this long mail but I just wanted to explain well what I've done.
Thanks!
Jo
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users