Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / Texture coords in shared vertices (OGL) Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 06, 2005, 01:45 PM

I'm having some trouble using an index array to share vertices. In order to save memory, I'm referring to vertices that are repeated in a model with a common index (using glDrawElements).

However, my understanding is that each one of these indices refers to the same point in the arrays passed to glVertexPointer, glNormalPointer and glTexCoordPointer: so index 2, say, refers to the third element in each of the vertices, normals and texcoords arrays.

This shouldn't be a problem where normals are concerned, but texture coords are another matter. For example, in a tiled terrain, where each tile has to be mapped with a different texture, the uv-coordinates will come out wrong if the touching corners of each tile are referenced by a common index.

Sharing vertices on a quad-tiled terrain seemed to be a good way of saving memory, since it reduces array size by 75%. But the texture coord issue has thrown a spanner in the works. Is it only possible, then, to share vertices whose texture coordinates are the same, or have I missed something? Any help would be very appreciated.


March 06, 2005, 01:53 PM

If you need one vertex with 2 sets of vertex coordinates, you'll have to split the vertex into two, only way.


March 06, 2005, 06:40 PM

Yeah, looks like I'm going to have to give up on sharing vertices, but I'm still, perhaps foolishly, looking for ways to save memory on the texture coordinates.

In the terrain, if the texture coordinates are the same for every quad (0,0, 1,0, 1,1, 0,1), do I really have to fill a big array with these values for every single quad? Is there a way to set standard texture coords for each quad without an array containing these four values repeated over and over? It seems an awful lot of memory to expend on something so simplistic.


March 06, 2005, 06:46 PM

An appropriate texture matrix and texture coordinate generation perhaps?


March 06, 2005, 08:11 PM

I considered that, but thought doing coordinate generation on the fly might slow things down too much. If it's negligible, though, I'll give it a shot.


March 07, 2005, 02:10 AM

It's a negligible speed-hit, but you're very limited in what you can achieve. You're basically stuck with planar or spherical mapping.


March 07, 2005, 02:32 AM

Slightly off-topic, but just a thought, perhaps you could render the final result of your texture blends into one texture, and then map it across the whole mesh (works specially well for the terrain case, but should work for any other mesh aswell), that way you won't have any tex-co problems when wielding your vertices


March 07, 2005, 04:08 AM

If your terrain is a regular n*m grid then you could store each texture coordinate as (n,m) then use GL_REPEAT wrap mode in both S and T so that this is mapped back to (0,0)-(1,1) for each tile.


March 08, 2005, 03:03 AM

You could cache the part of the terrain which is not currently visible or may be generate your texture coords in a vertex buffer.

Christian Sigg

March 08, 2005, 05:02 PM

Hey guys,

Maybe I'm too tired to completely understand the problem but the solutions seems pretty obvious:

Use integer values for the vertex positions (xy) of the grid and use one single texcoord (or env parameter, no vbo) to pass the inverse tile size to a vertex program. There, you compute the mapping by multiplying with the inverse tile size and take the fraction as your map coordinate.

Or do you try to avoid vertex shaders?


This thread contains 10 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.