Shared vertex data


I was wondering if vertex data stored in i.e.

PT(GeomVertexData) mVData;
can be shared… i.e.

I have a polygons class which I want to render
the triangles that make up the polygon, so I store the data like this

GeomVertexRewriter mVertices;
GeomVertexRewriter mNormals; 
GeomVertexRewriter mColors;

PT(Geom) mPolyGeom;

in each polygon. I initialise the Geom like this

	LVector4f debugColor(1.0f, 0, 0, 0.3f);

	PT(Geom) meshGeom;
	meshGeom = new Geom(mVData);

	for (unsigned int i = 0; i < mPolyVerts.size(); ++i)
		LVector3f& vertex = mPolyVerts[i]->GetPosition();
		mNormals.add_data3f(0, 1, 0);

	PT(GeomTriangles) prim = new GeomTriangles(Geom::UH_dynamic);

	unsigned int zeroVert = mPolyVerts[0]->VertexID();

	unsigned int maxIndex = mPolyVerts.size() - 1;
	for (unsigned int i = maxIndex; i > 1; --i)

		unsigned int indexA = mPolyVerts[i]->VertexID();

		unsigned int next = i - 1;
		unsigned int indexB = mPolyVerts[next]->VertexID();


	mPolyGeom = meshGeom;

	mPolygonNode = new GeomNode("DebugPolygonNode");

I want this geometry to be normal triangles.

Now I want to render somewhere else the wireframe of the polygons , hence I thought all I need to do is store another

PT(Geom) mWireframeGeom;

GeomVertexRewriter mWireframeVertices;
GeomVertexRewriter mWireframeNormals; 
GeomVertexRewriter mWireframeColors;

and I initialise this as well with mVData.
And then as GeomLines

PT(GeomLines) prim;
prim = new GeomLines(Geom::UH_dynamic);

I get weird results… The lines geom is set to render in black while the trianglGeom is set to render in red . Yet what I get is a mix of black and red colored meshes. If I remove either of the geoms then the result looks as expected and all is fine.

So can I initialise 2 different geoms from the same vertex data ?

here a screenshot

I solved it by using 2 different

PT(GeomVertexData) mWireframeVData;
PT(GeomVertexData) mPolygonVData;

I still wonder if it is possible to share the vertex data and have the color column different for the 2 geom lists.

Wait, I don’t understand. You want to share the same vertex data, but have different values in the vertex columns? That doesn’t make sense. You can certainly share one GeomVertexData object between many different primitives, but since the purpose of GeomVertexData is to hold the values for the vertices, it follows that all of your primitives will then have the same values for all of their vertices. Including color. You can’t rewrite the data with a new GeomVertexRewriter object, because that will just rewrite the data for all of the primitives that share the same GeomVertexData.

(Actually, if you really want to maximize sharing, you can share the vertex data while having a different value for the color array, by storing the color array in its own GeomVertexArrayData object. But this is a more advanced topic, and there’s not a lot of point to doing it anyway unless you’re talking about a lot of vertices. It doesn’t appear to be what you are doing, anyway.)