[osg-users] getColorIndices usage

Robert Osfield robert.osfield at gmail.com
Wed Jul 2 00:45:31 PDT 2008


Hi Thomas,

I can only guess the tutorial your are copying has rather awkward
usage of the OSG, in normal OSG usage you would never reference the
TemplateIndexArray<> template directly, rather just use the typedef
UIntArray.

As for color indices, please don't use them unless you really really
need to.  The vertex array indices exist because in the early days of
the OSG I was working with a client porting from Performer to OSG and
in this case adding per vertex array indices support helped them.  I
have however regretted this addition ever since, as the feature end up
being used when it really shouldn't be.   My plan is to move the array
indices out of osg::Geometry to prevent for inappropriate use.

Why is it inappropriate?  Well OpenGL doesn't itself support separate
index arrays for the different vertex arrays, it only supports
glDrawElements that provide index access to all active vertex arrays
in a parallel, to support the separate index arrays you have to
simulate it by dropping down to OpenGL slow path i.e. glBegin/glEnd,
this is really slow unless you hide the cost by wrapping it all in a
display list and even then it still won't be as fast as using .

It far far more efficient to repeat colours to get the effect than to
use per array indices, it might be more data you are managing but it
used OpenGL fast paths.

Robert.

On Wed, Jul 2, 2008 at 8:20 AM, Tomas Hnilica <tomas.hnilica at webstep.net> wrote:
> Hello all OSG users,
>
> does anyone know how to use the Geometry::getColorIndices() method? I do not
> know how to work with the returned IndexArray - how to access and change the
> values.
>
> My situation: Geometry uses generally one color and sometimes it's necessary
> to draw some primitiveSets by another color.
> So, I use BIND_PER_PRIMITIVE_SET, colorArray has one element and
> colorIndices is:
>
>   /*copied from OSG pyramid example, I do not know what last 2 params
> DataSize and DataType 4,4 mean :( */
>   osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>
> *colorIndices;
>   colorIndices = new osg::TemplateIndexArray<unsigned int,
> osg::Array::UIntArrayType,4,4>;
>
> ....
> (for every primitiveset) colorIndices.push_back(0);
> ...
> .
>
> This works fine, but now I want to change index in colorIndices array, but I
> do not know how to access the data in IndexArray* that is returned by
> Geometry::getColorIndices().
> I tried to dynamic_cast  to osg::UIntArray*, but such cast does not work.
> (like Vec4Array* works for getColorArray())
>
> Any ideas how to access and work with the colorIndices array? Or is it
> necessary to remember the array as osg::TemplateIndexArray and use only
> setColorIndices - but if so, then why getColorIndices() exists?
>
> Many thanks,
> Tomas
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list