PDA

View Full Version : Textures with VBO



Atul Agarwal
10-20-2008, 05:41 AM
Hi, i am Atul
I am developing an application in which I am rendering multiple objects(meshes).These objects have different faces with different textures. To speed up the application, I am using VBO for each object. But I don't know, how to use multiple texures files with one VBO as an object has many faces each with different texture.
At a time I can give the name of only one texture file with the object in my render(display) function.
Please help me.

_NK47
10-20-2008, 06:45 AM
You can bind as many textures as supported and reuse (in your example) one texture coord set for all textures. in case you need different texture coordinates for each stage you need to provide them in the vbo or generate them in a shader/fixed function.

Y-tension
10-20-2008, 06:49 AM
There are many ways to do this. You can either sort the faces according to texture at load time and use a separate draw call for each texture or you can even load every texture at once and use a pixel shader to zero out unused textures or even select one if the texture array extension is available.
To load multiple textures, first call glActiveTexture to select a texture unit as active, then glTextureImage*D will apply your texture to that unit. When calling glTexCoordPointer it will apply the texture coordinates to your active texture unit. Of course you must enable texture coordinate arrays for each unit seperately.

zeoverlord
10-20-2008, 06:53 AM
there are a few ways

1. if you have the hardware then you could use a texture array to store all textures in.

2. try to put all sub textures in one large texture if possible.
Then if needed you sort the polygons beforehand by texture, that way you could just draw all the polygons that is covered by a specific texture before you switch to the next, that would reduce unnecessary work

Atul Agarwal
10-20-2008, 10:40 PM
Thanks everyone for your replies.
But my problem has not been solved.I cannot give glBindTexture function in the display function because of multiple textures one for each face.Is there anyway through which I can use glBindTexture in the function in which I am assigning the texture & vertices coordinates to the VBO.

Ilian Dinev
10-21-2008, 01:04 AM
Atul, re-read the above replies, as they show the only existing solutions.
1) with texture-arrays (GeForce8x00+) you specify a third texture-coordinate - it specifies which texture to use from the array. You must code a pixel-shader for it.
2) without texture-arrays, you're limited to 8 or 16 textures max, and you have to do a lot of slow branching in the shader.
3) with a single large texture-atlas, you just fix-up the ST coordinates, and get each face to have a different "texture".

So really, your unrealistic requirements either need a a GeForce 8x00 or be made realistic via a texture-atlas.

theguy126
07-30-2010, 03:59 PM
I'm stuck, bleh, same problem as agarwal.

Atlas is not a good choice for me; hardware limits max texture resolution to barely above 8000x8000 (whatever that power of 2 is). This is bad because my atlas is supposed to be a lot bigger, like possibly 8x that in both dimensions (is this feasible on a mid- to high-end modern computer?).

texture arrays would be a great solution if they were easy to use with glDrawElements; sadly they are not very well documented and they are confusing. And it doesn't look like you can use them effectively with glDrawElements, because glDrawElements only has a limited number of pointer-setting options, like glTexCoordPointer which would only work in an atlas context.

If anyone has any solutions please let me know.

http://www.maxloh.com

kyle_
07-30-2010, 04:31 PM
Atlas is not a good choice for me; hardware limits max texture resolution to barely above 8000x8000 (whatever that power of 2 is). This is bad because my atlas is supposed to be a lot bigger, like possibly 8x that in both dimensions (is this feasible on a mid- to high-end modern computer?).
If you need 8x that then you are doing something seriously wrong.
8kx8k for RGBA texture (8b per component) is 250MB.
If you need more, you will need to stream data into your atlas.

Alfonse Reinheart
07-31-2010, 03:32 PM
texture arrays would be a great solution if they were easy to use with glDrawElements; sadly they are not very well documented and they are confusing.

There's nothing confusing about them. They're exactly like 3D textures, except there's no filtering in the Z coordinate.


glDrawElements only has a limited number of pointer-setting options, like glTexCoordPointer which would only work in an atlas context.

Um, no. This would be a good introduction (http://www.opengl.org/wiki/Vertex_Specification) to vertex attributes.


8kx8k for RGBA texture (8b per component) is 250MB.

People still use uncompressed textures?

Dark Photon
07-31-2010, 06:21 PM
8kx8k for RGBA texture (8b per component) is 250MB.
People still use uncompressed textures?
Sure thing. Dynamically rendered impostors. Shadow maps. Sometimes HDR on pre-GL4 HW (no BPTC). FBO render targets used in subsequent passes.

But of course when possible prefer compressed for pregenerated content.

Rosario Leonardi
08-01-2010, 11:16 AM
If you have very high texture resolution you can use virtual texturing.
http://silverspaceship.com/src/svt/
And everything return to be a very big atlas. :)

Before try to implement that technique think it twice. Explain your problem a little better and maybe we can find a easier solution.

http://www.maxloh.com -> OMG!! You rock on the piano!!