Sign in to follow this  
waZim

How to Use glDrawElement() using Indexed data

Recommended Posts

waZim    100
hi All, I am saving my 3D model data in 3 seperate Indexed Lists which i exported from a Collada file, in the following format..
	VertexList = // N Number of Vertices
	{ 
		x1,y1,z1,
		x2,y2,z2,
		x3,y3,z3,
		.....
	};
	NormalsList = // M Number of Normals
	{ 
		x1,y1,z1,
		x2,y2,z2,
		x3,y3,z3,
		.....
	};
	TexCoordsList = // O Number of TexCoords
	{ 
		s1,t1,
		s2,t2,
		s3,t3,
		.....
	};

	IndexList = // (NumberOfTriangles * 3 * 3) Number of Indices 
	{
		t1.v1.V, t1.v1.N, t1.v1.T, // Triangle 1 Vertix 1 Indices
		t1.v2.V, t1.v2.N, t1.v2.T, // Triangle 1 Vertix 2 Indices
		t1.v3.V, t1.v3.N, t1.v3.T, // Triangle 1 Vertix 3 Indices

		t2.v1.V, t2.v1.N, t2.v1.T, // Triangle 2 Vertix 1 Indices
		t2.v2.V, t2.v2.N, t2.v2.T, // Triangle 2 Vertix 2 Indices
		t2.v3.V, t2.v3.N, t2.v3.T, // Triangle 2 Vertix 3 Indices

		.......................... // And so on
	};



Now How collada Compresses those Lists is, that the Size of all those 3 Lists are different, Note "N", "M" and "O" Number of Vertices, Normals and TexCoords respectively... How can i render this data using VBO and glDrawElements() or anything else. except duplicating the vertices which have different set of (Normals,TexCoord) from the vertices List... In Other Words, re-Creating the Vertex Lists and so on.. If i put the Data "As it is" in VBOs each for Vertex, Normals and TexCoords and then Put the Indices in an IBO. glDrawElements only considers the count Number of Indices from the List of Indices and Fetches the Same Index Data from all the 3 VBOs (Vertex, Normals, TexCoords)..

Share this post


Link to post
Share on other sites
Brother Bob    10344
You cannot have multiple index arrays. So if duplicating attributes to ensure that the arrays are of the same length and use the same index array, immediate mode is your only option.

Share this post


Link to post
Share on other sites
waZim    100
Well actually i know the limitation. but i am waiting if some one have a better approach of handeling this. some Extension etc.....

And i actually can still do better then Immidiate Mode. i can atleast use glDrawArrays(). which takes each triangle data seperately.. i don't know you mean that as "immidiate" mode..?

Share this post


Link to post
Share on other sites
Brother Bob    10344
Immediate mode is the manual specification of all vertex data using glBegin(), glVertex(), glEnd() and those functions. About the slowest approach you can take, but unless you are willing to recreate the vertex arrays, it is also your only choice. Vertex arrays of any kind won't help you if you have non-matching arrays of vertex and attributes arrays.

Share this post


Link to post
Share on other sites
waZim    100
thanks for your reply... i know what is immidiate mode but since you mentioned Immidiate Mode is my ONLY solution i thought you are calling glDrawArrays() immidiate mode as well. since thats still a better solution then immidiate mode.

I have found another solution.
I found the unique sets of (PositionIndex,NormalIndex,texCoordsIndex) from the triangles list and created seperate buffers for those "Unique" sets of (PositionIndex,NormalIndex,texCoordsIndex), and put all the unique sets of (PositionIndex,NormalIndex,texCoordsIndex) at the same indix in all the 3 Buffers, i also updated the IndexList for all the triangles according to the new Indices and NOW i can use glDrawElements() and Indexed Data... which i hope is faster then glDrawArrays() :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this