[opensource-dev] Mesh rendering: What does indicesp provide?

Aidan Thornton makosoft at googlemail.com
Thu Jun 3 02:50:36 PDT 2010


Hi,

On Thu, Jun 3, 2010 at 12:35 AM, Rob Nelson
<nexisentertainment at gmail.com> wrote:
> I am working on the rendering code in the SL viewer at the moment,
> having completed the server-side code and some of the client-side
> packet-handling classes.  However, I have zero familiarity with OpenGL,
> so bear with me.
>
> My viewer needs to construct a terrain surface (a mesh) for display.  I
> have completed an LLViewerObject to this end, except for:
>
> ::getGeometry(LLStrider<LLVector3> &verticesp,
>        LLStrider<LLVector3> &normalsp,
>        LLStrider<LLColor4U> &colorsp,
>        LLStrider<LLVector2> &texCoords0p,
>        LLStrider<LLVector2> &texCoords1p,
>        LLStrider<U16> &indicesp)
>
> What is confusing me is indicesp.  I think it has something to do with
> connecting vertices, but I'm not sure how.

I think you should find it's a list of indexes into the vertex,
normal, etc arrays that's later passed to glDrawElements, but I'm not
100% sure.

> The example code I am
> working with uses a mess of lookup tables in the following loop for each
> voxel:
>
>        //Draw the triangles that were found.  There can be up to five per cube
>        for(iTriangle = 0; iTriangle < 5; iTriangle++)
>        {
>            if(a2iTriangleConnectionTable[iFlagIndex][3*iTriangle] < 0)
> break;
>
>            for(iCorner = 0; iCorner < 3; iCorner++)
>            {
>                iVertex =
> a2iTriangleConnectionTable[iFlagIndex][3*iTriangle+iCorner];
>
>                vGetColor(sColor, asEdgeVertex[iVertex],
> asEdgeNorm[iVertex]);
>                glColor4f(sColor.fX, sColor.fY, sColor.fZ, 0.6);
>                glNormal3f(asEdgeNorm[iVertex].fX,
> asEdgeNorm[iVertex].fY,   asEdgeNorm[iVertex].fZ);
>                glVertex3f(asEdgeVertex[iVertex].fX,
> asEdgeVertex[iVertex].fY, asEdgeVertex[iVertex].fZ);
>            }
>        }

So, for example, you would convert this code by appending each iVertex
used to indicesp in turn rather than rendering the corresponding
vertex immediately. It appears there's a slight complication in that
all the arrays could contain items that have already been added
previously and these may affect your indices, but you should be able
to figure this out from the existing code.

Aidan


More information about the opensource-dev mailing list