Multitexturing and vertex arrays

Started by
5 comments, last by BladeWise 18 years, 10 months ago
I found this, looking for informations about multitexturing: -------------------------------------------------------------------------------- The multitexture extension supports vertex arrays for multiple texture coordinate sets. Because vertex arrays are considered client state, the glClientActiveTextureARB() command controls which vertex array texture coordinate set that the glTexCoordPointer(), glEnableClientState(), glDisableClientState(), and glGetPointerv() commands affect or query. For example: glClientActiveTextureARB(GL_TEXTURE0_ARB); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTextureARB(GL_TEXTURE1_ARB); glTexCoordPointer(2, GL_FLOAT, 0, tex_array_ptr); glEnableClientState(GL_TEXTURE_COORD_ARRAY); The current raster position has been extended to maintain a distinct texture coordinate set for each supported texture unit. To simplify the multitexture extension, OpenGL's evaluator and feedback functionality are not extended to support multiple texture coordinate sets. Evaluators and feedback utilize only texture coordinate set 0. -------------------------------------------------------------------------------- Taken from: http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node61.html So, I can define multiple texture coordinates... my question is, the example above... uses the same coordinates (tex_array_ptr) for both textures? Doing this: glClientActiveTextureARB(GL_TEXTURE0_ARB); glTexCoordPointer(2, GL_FLOAT, 0, tex_array_ptr1); glClientActiveTextureARB(GL_TEXTURE1_ARB); glTexCoordPointer(2, GL_FLOAT, 0, tex_array_ptr2); glEnableClientState(GL_TEXTURE_COORD_ARRAY); I'm linking different tex coords to these two textures?
Advertisement
Quote:Original post by BladeWise
I'm linking different tex coords to these two textures?


Yes you can have different texture coords for each TMU.
Thanks, now multitexturing works, even if a problem occurs... my scene is composed by textured and not textured objects, so I suppose I need to enable/disable texturing if needed... now, to enable/disable texturing I use this code (this is in the object render function, and is called for each object to render):
if(this.m_TextureCount>0 && texturing){	for(int i=0; i<this.m_TextureCount; i++)	{		Gl.glActiveTexture(Gl.GL_TEXTURE0+i);		Gl.glBindTexture(Gl.GL_TEXTURE_2D,this.m_Textures.ID);		Gl.glEnable(Gl.GL_TEXTURE_2D); 		Gl.glClientActiveTexture(Gl.GL_TEXTURE0+i);		Gl.glTexCoordPointer(2,Gl.GL_FLOAT,0,this.m_TexCoords.Raw);		Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);	}}else{	for(int i=0; i<Texture.MAX_TEXTURES; i++)	{		Gl.glActiveTexture(Gl.GL_TEXTURE0+i);		Gl.glDisable(Gl.GL_TEXTURE_2D);		Gl.glClientActiveTexture(Gl.GL_TEXTURE0+i);		Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY);	}	Gl.glDisable(Gl.GL_TEXTURE_2D);}

Where Texture.MAX_TEXTURES is 32, the maximum number of textures available in
the OpenGL context... I suppose every card support less texture units, though...
is there a way to know how many?...
The problem with this code is that I have a "invalid enum" error (I suppose the
problem lies in the else statement, since my 9600 doesn't have 32 texture
units... I suppose...), moreover I think it's not a good idea to disable units
in this way, for each element... is there another way? How could I fix this
problem? Would be a good idea to sort objets (first textured ones, than
not-textured) to disable render units only one time?

Just to give more infos, removing the else statement, the same texture is applied to every object in my scene (I use only cubes at this time for testing
purpose, so I have always the same vertices number... I suppose otherwise the program could crash...), as expected...

Thanks in advance! :P
No gfx card that I know of supports 32 texture units. You only have 4 texture units on Nvidia cards under FFP and 8 units with ATI and both have 16 with programable shader code. If you want 32 textures on the screen at once you either need to do...
1.Multipass not a good idea
2.Multipass with Multi-texturing better
3.Reduced total # of textures by combining them into 4 larger textures
e.g. 512x512 textures in a 2048x2048 texture = 16 textures in one texture unit
Now you access each texture by offseting the texture coordinates, this is by far the best way if you want speed and support of most hardware so two texture units will give you 32 high quality textures...
HTH...
Thanks for your suggestion... and what about retrieving hardware texture units? Does OpenGL provides a method to accomplish such a task? :P

About enabling/disabling texturing, is it too expansive doing that may times for each frame, or it's a common solution? Is it better to sort objects by texture (Not textured will be drawn last, in such a case)?
glGetIntegerv() with GL_MAX_TEXTURE_UNITS as the value to look up.
Many many thanks! :D It's exactly what I was seaching for... :P

This topic is closed to new replies.

Advertisement