OpenGL lots of textures for one mesh

Recommended Posts

Hello community,

I know this question has been asked a lot of times before everywhere in the internet but i can't come up with a good solution. My problem is if i run into the situation of having a mesh which should have different textures on different surfaces how do i switch the textures intelligent?

I don't want to use texture atlases because textures arent always the same size and i have to rework everything if i ever go over the max number of textures my atlas can contain. btw im using opengl.

I have read something about sorting meshes by textures, does that mean creating vbos for every texture? that would mean to create a lot of small vbos and it would uhm suck hard in my opinion.

So if i have a mesh like a house or something which uses like 10 different textures. How do i gonna do it? Do i really have to splitt the vbos?

Thanks
Ichi

Share this post

Share on other sites

There are a million ways to do this and what you end up doing depends entirely on your performance/quality requirements. Let's take your house example, say there are three different types of textures: shingles on the roof, the siding of the house, and brick for the chimney.

Option 1: use one texture, with different portions of the texture mapping to different things: part of the texture is shingles, part is siding, part is brick. The vertex UVs make sure the correct image is mapped to the correct vertex position. This is an extremely common option.

Option 2: Split the shingles, siding and brick portions of the house into separate surfaces, and each surfaces has its own texture. The shingle surface uses the shingle texture, siding surface uses the siding texture, etc. This is also an extremely common technique, and is useful if you can't fix enough texture resolution for option 1 to be useful. This option does not "suck hard".

Option 3: Use three separate textures, but have some vertex attribute control the blending of each texture. This makes sense for terrain or something where blending between multiple textures is useful for the look of the material. It wouldn't make much sense for your house.

I would choose option 1 or option 2 unless I had a specific reason not to.

Share this post

Share on other sites

I have read something about sorting meshes by textures

This is unrelated to the current task. This is for improved performance and while you should always do it it can be ignored in this discussion.

does that mean creating vbos for every texture?

If you need to change a render state between surfaces (such as a texture, a shader, a blend mode, etc.) then you logically need to make more than 1 draw call to do this.
This does not mean you have to make more than what VBO, with bark-textured surfaces in 1 and leaf-textured surfaces in another, but this is the simplest and most common way.

If you want a faster approach but a more complicated set-up, you can still use a single VBO, but then you need to keep a table for the 2 draw calls so you know which portions of the VBO to draw for each draw call.

In either case, if you need to switch textures from one surface to another, those surfaces will be drawn via more than 1 draw call, whether the surfaces are in separate VBO’s or not.

L. Spiro Edited by L. Spiro

Share this post

Share on other sites

How important is it to use textures of different sizes?

If you're prepared to rework them to be equal in size, texture arrays could be an ideal solution. Essentially you multidraw using the same vbo (but different offsets/lengths) and pass in the texture array slice number to be used as per instance data in the shader. This means no state changes, and is probably the fastest way to do this without going down the bindless route.

Edited by mark ds

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

• Partner Spotlight

• Forum Statistics

• Total Topics
627677
• Total Posts
2978591
• Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
Thank you in advance!
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 11
• 12
• 10
• 12
• 22