PDA

View Full Version : Textures with vertex arrays



drakar
06-20-2004, 11:34 AM
Am I imagining things, or is it impossible to use vertex arrays with index arrays (as opposed to just calling glArrayElement() over and over) AND specify a different texture for each polygon? It looks like OpenGL's vertex array implementation provides no equivalent for glBindTexture() that can be nestled in along with vertex indices, other than with the method of repeated calls to glArrayElement(). And I'd rather avoid the latter idea because it does very little to eliminate the overhead time that plagues immediate-mode.

Am I missing something?

CrazyButcher
06-20-2004, 12:25 PM
nope you gotta do the binds yourself
and better sort things in such a fashion that you minimize texbinds/glDrawElements..

drakar
06-20-2004, 01:00 PM
Ah... okay then. Thanks.

So in other words, index arrays are almost never appropriate because of this. It makes me wonder why OpenGL even bothers to throw them in.

harsman
06-20-2004, 02:05 PM
It certainly doesn't make index arrays useless. To get any kind of performance from modern graphics hardware you need to send large batches in each rendering call. Changing texture per polygon will have abysmal performance, it will require a separate glBegin/glEnd pair per polygon even in immediate mode, so if that is what you want to do performance obviously isn't a concern. Then not using index arrays shouldn't be a problem really since they mostly offer a performance increase.

If you're interested in how to write efficient graphics code for modern graphics hardware, check out the programming guides and SDKs on the various IHVs' web sites, nvidia.com/developer and ati.com/developer for example, there's lots of info available.

drakar
06-20-2004, 05:07 PM
Hang on. You say that having a different texture for each polygon is always inefficient? That doesn't make any sense. It's almost always the case that you have lots of different textures for lots of different polygons. Why would all (or most) of them have the same texture? That'd be boring. :-P

ClearMind
06-20-2004, 06:08 PM
i have an idea that u can put all ur textures together. But the problem is how to achieve the mapping problem. maybe we have to do a complicate pre-calculation for different problems. it is easier said than done

plasmonster
06-20-2004, 07:03 PM
Originally posted by drakar:
Hang on. You say that having a different texture for each polygon is always inefficient? That doesn't make any sense. It's almost always the case that you have lots of different textures for lots of different polygons. Why would all (or most) of them have the same texture? That'd be boring. :-PThere's nothing wrong with changing texture binds willy-nilly, nothing at all, as long as you realize that these state changes cost something. Experienced OpenGL programmers will simply point out that this is something you will want to avoid where you can, by batching geometry with the same texture together. That's all, simply a matter of optimization. This is not only true for texturing, but many other state changes as well.

zeckensack
06-20-2004, 09:05 PM
You can't bind different textures in between ArrayElement calls ... BindTexture is not allowed inside a Begin/End block.

drakar
06-21-2004, 11:37 AM
Yeah yeah yeah, I already know about optimization philosophy and stuff like that. I just tend to become a little disconcerted when someone tells me I should bind each texture "ONCE AND ONLY ONCE!!!!!!!!!!" or give up all hope of an efficient program.


BindTexture is not allowed inside a Begin/End block.I know. ;)

Aeluned
06-22-2004, 05:29 AM
What Q is saying is that you should pack your arrays in a sorted fashion, attempting to group them by most shared states.

bind a texture, draw all geometry using that texture,
bind next texture, draw all that geometry etc...

you can use glDrawArrays and use the offset and num_elements params to pick and choose which group of geometry you'll render next.