1
\$\begingroup\$

I need suggestions for the best method of acheiving what I am trying to do:

-Using either OpenGL ES 1.x or 2.x

I need to pass a bunch of vertices to the GPU. Each one has 3 attributes: Position, Color, and Texture coords.

The vertices form quads, which share vertices. The shared vertices have both position and color attributes in common, but texcoords are not shared because each quad is textured with a 'tile' from a texture atlas.

I already know that it is not possible to use separate indices for a glDrawElements() call, so does that mean I can only use indexing for individual quads(specify 4 unique vertices per quad)? .. or is there any better solution?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

If you have a lot of quads (with shared vertices), but each quad needs its own texcoords, you can't use shared vertices, but each quad has to be defined separately.

It's better to use interleaved arrays in each case, because you have stored all attributes for one vertex consecutively in memory. So if you are trying to read for example vertex position, also some surrounding data from memory (in your case color and texcoords) are send to cache. If you have a lot of data, it's more efficient.

And you don't have to use glDrawElements in this case, you can just use glDrawArrays (you don't have to pass indices, if they are just sequence of increasing numbers).

I also hope, you are using VBOs (data are stored in GPU memory instead of system memory).

\$\endgroup\$
2
  • \$\begingroup\$ On Android devices, the GPU does not have dedicated memory.. doesn't that mean that VBOs are useless? And also, I have the use glDrawElements because then I need to specify 6 vertices per quad( There is no such thing as GL_QUADS in OpenGL ES) \$\endgroup\$
    – Jonathan
    Commented Apr 8, 2011 at 10:17
  • \$\begingroup\$ I am sorry, I don't have experience with Opengl ES. \$\endgroup\$
    – zacharmarz
    Commented Apr 8, 2011 at 11:17
0
\$\begingroup\$

Use glDrawElements and pass GL_TRIANGLE_FAN (4 indexes per quad).

You can use an uniform to get to a specific region in the texture, so your quads share the same texcoords but map to a certain area using the uniform variable.

\$\endgroup\$
1
  • \$\begingroup\$ This idea would kill batching. \$\endgroup\$ Commented Mar 13, 2013 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .