Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-08 Thread Florian Castellane
Hi Robert,

Yes, I am indeed changing the texcoord array at the indices relevant to the 
part of the geometry I am texturing.  :o 

You can indeed see in the code that I am accessing the texArray using
(*texArray)[idx] ... which is actually short for 
Code:
(*texArray)[ (*indices)[id] ]

  8) 

I'll try to produce a minimal compileable code to further showcase the issue as 
you are advising. Let me get back on that.

For dynamic texture coordinates, I thought you had to pass them to the shader 
through the texCoord array in the geometry for texturing unit N (aka) 
settexcoords(N, texCoord) in order for the shader to get this texCoord array as 
attribute vec2 osg_MultiTexCoordN in the shader. Can you detail what you are 
suggesting instead?

Thank you!

Cheers,
Florian

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





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


Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Robert Osfield
Hi Florian,

On 7 July 2016 at 15:02, Florian Castellane
 wrote:
> I am modifying some indices of a texture coordinate array that correspond to 
> a subset of my floor that is divided into several parts (here, we are working 
> on the center part. Other parts have already had their parameters set up).
> This array has been initialized before (hence the getTexCoordArray() call) 
> and already filled with some data. I access it to give texture coordinates 
> for all the indices of the floor center, which are yet unset (they are set to 
> (-1,-1)). This lets me apply my texture to the floor center.

Your use of the word indices in this context is a bit confusing as I
don't think you mean indices, but perhaps you do  A texcoord array
doesn't normally contain indices, but texture coordinates.  A
DrawElementsUShort contains indices.  You could possible use a
texcoord array as a float or int array and use these as indices to
look up textures or uniform arrays in shaders but I'm guessing you
aren't doing this.

As for the reason why things aren't working for you.  At this stage
nothing we've suggested has fixed the problem, it could well be that
you are doing something wrong that we are witness to.  For this the
only way to make sure others know what you mean would be to create a
small example that others can compile and run and witness first hand
what is going wrong.

As a general note. for dynamic texture coord data consider not using
display lists or VBO's, just let the array data be passed to OpenGL as
a vertex/tex coordinate array on each frame.

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


Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Florian Castellane
Hi everyone, thanks for the tips.

@Sebastian:

Code:
geometry->getPrimitiveSet(0)->setDataVariance(DataVariance::DYNAMIC) ;


did not solve the problem unfortunately. As Robert points out, I'm not sure 
that is the problem here.

@Trajce: 

Code:
texArray->getVertexBufferObject()->dirty();


didn't solve it either, and I'm not sure why since setTexCoords does update the 
VBO so it should be calling that method itself.

@Robert:
Let me explain a bit more then. :) 

I am modifying some indices of a texture coordinate array that correspond to a 
subset of my floor that is divided into several parts (here, we are working on 
the center part. Other parts have already had their parameters set up). 
This array has been initialized before (hence the getTexCoordArray() call) and 
already filled with some data. I access it to give texture coordinates for all 
the indices of the floor center, which are yet unset (they are set to (-1,-1)). 
This lets me apply my texture to the floor center.

Thanks again.

Best regards,
Florian

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





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


Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Robert Osfield
Hi Florian,

I read your post but came away confused about what your are doing/how
you are going about things.

As a general note, DataVariance is not used in compile or uploading of
OpenGL data, just in giving hints to the operations like in
osgUtil::Optimizer or in the draw traversal for holding back the next
frame till all DYNAMIC objects have been dispatched.

Second general note, if you are using VBO's and have modified the
array data so that copy in the VBO is now out of date then you will
need call dirty on the VBO to force it re-upload the vertex data.
Perhaps this is what is missing in your code.

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


Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Trajce Nikolov NICK
I think it was something like tcoords->getVertexBufferObject()->dirty();

On Thu, Jul 7, 2016 at 2:15 PM, Sebastian Messerschmidt <
sebastian.messerschm...@gmx.de> wrote:

> Hi Florian,
>
>> Hi Sebastian, thanks for the answer.
>>
>> Calling texArray->dirty() does not seem to be enough, since my texture is
>> not displayed. I can confirm that my shader is being applied though - it
>> just doesn't seem to get the texture coordinates.
>>
>> My custom geometry class (MyNameSpace::MyGeometry) does indeed
>>
>> Code:
>> setDataVariance(osg::Object::DYNAMIC);
>> setUseDisplayList(false);
>> setUseVertexBufferObjects(true);
>>
> Try the setDataVariance on the PrimitiveSet.
>
>
>> in its constructor.
>>
>> Best regards,
>> Florian
>>
>> --
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=68038#68038
>>
>>
>>
>>
>>
>> ___
>> 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
>



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


Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Sebastian Messerschmidt

Hi Florian,

Hi Sebastian, thanks for the answer.

Calling texArray->dirty() does not seem to be enough, since my texture is not 
displayed. I can confirm that my shader is being applied though - it just doesn't 
seem to get the texture coordinates.

My custom geometry class (MyNameSpace::MyGeometry) does indeed

Code:
setDataVariance(osg::Object::DYNAMIC);
setUseDisplayList(false);
setUseVertexBufferObjects(true);

Try the setDataVariance on the PrimitiveSet.


in its constructor.

Best regards,
Florian

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





___
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] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Florian Castellane
Hi Sebastian, thanks for the answer.

Calling texArray->dirty() does not seem to be enough, since my texture is not 
displayed. I can confirm that my shader is being applied though - it just 
doesn't seem to get the texture coordinates.

My custom geometry class (MyNameSpace::MyGeometry) does indeed

Code:
setDataVariance(osg::Object::DYNAMIC);
setUseDisplayList(false);
setUseVertexBufferObjects(true);


in its constructor.

Best regards,
Florian

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





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


Re: [osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place

2016-07-07 Thread Sebastian Messerschmidt

Hi Florian

Calling dirty on the modified array should be enough. Are you sure you 
set the useDisplayList to false and the useVertexBufferObject to true?
You don't need to call setTexCoordArray unless you want to assign a 
different array.
I don't quite recall if you need to set the datavariance of the geometry 
to dynamic however, so it might be worth a shot.


Cheers
Sebastian


Greetings fellow OSG users :)

There is a detail in my code that I found disturbing:


Code:

void applyTextureToCenter( MyNameSpace::SpecificNode* floor )
{
   MyNameSpace::MyGeode* center = floor->getCenterGeode() ;
   osg::StateSet* stateSet = center->getOrCreateStateSet() ;
   MyNameSpace::MyGeometry* geometry = center -> getGeometry() ;
   const osg::DrawElementsUShort* indices = geometry -> getIndexArray() ;
   const osg::Vec3Array* vtxArray = static_cast( 
geometry->getVertexArray() ) ;
   osg::Vec2Array* texArray = floor ->getTexCoordArray() ;
   const unsigned numVertex = geometry->getVertexArray()->getNumElements() ;
   const unsigned numIndices = geometry->getIndexArray() ->getNumIndices() ;

   for ( unsigned id = 0 ; id < numIndices ; ++id )
   {
 const unsigned idx = (*indices)[id] ;
 osg::Vec2 uv ;

 /* *snip*
  * some texture coordinates computation
  */
   
 (*texArray)[idx].set( uv.x(), uv.y() ) ;

   }

   geometry->setTexCoordArray( 0, texArray ) ; //Why is this needed ?

 /* *snip*
  * Code setting the stateSet parameters (shader program, uniforms...)
  */
   return ;
}




I don't understand why the line
Code:
geometry->setTexCoordArray( 0, texArray ) ;

  is needed. AFAIK since texArray points to the value given by 
getTexCoordArray(), we are not actually changing anything...  :?
I was thinking that maybe it was because setTexCoordArray() caused dirty() to 
be called, causing re-evaluation of the texture coordinates, but calling

Code:
geometry->getTexCoordArray(0)->dirty() ;


is not enough for my texture to be displayed.

So I went on and looked at the code for setTexCoordArray:

Code:
openscenegraph/OpenSceneGraph/blob/master/src/osg/Geometry.cpp


I see that it is calling
Code:
geometry->dirtyDisplayList() ;

  but since we are using VBOs (Vertex Buffer Objects) and not display lists 
that should not do anything.
The code is also calling
Code:
geometry->addVertexBufferObjectIfRequired()

, which should itself call

Code:
texArray->setVertexBufferObject(geometry->getOrCreateVertexBufferObject());


, which AFAIK should not be changing anything here either, since it is setting 
the array to use the existing VBOs (which should already be the case).

What is your take on this? There must be something I'm missing.

Thank you!

Best regards,
Florian.

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





___
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