[SOLVED] When exactly is the getMeshBufferCount() > 1

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

[SOLVED] When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

To get all the vertices in a mesh, I'm using

Code: Select all

S3DVertex* vertexArr = (S3DVertex*)mesh->getMeshBuffer(0)->getVertices();
I couldn't guess the scenario of

Code: Select all

mesh->getMeshBufferCount() > 1
When does this happen?
Last edited by cegprakash on Fri Jul 11, 2014 2:38 pm, edited 1 time in total.
luthyr
Posts: 69
Joined: Wed Dec 30, 2009 5:47 pm

Re: When exactly is the getMeshBufferCount() > 1

Post by luthyr »

If you were to import an mesh (such as OBJ) with multiple materials/textures, it will come in as separate meshbuffers because it would need to be drawn in 2 or more separate draw calls.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: When exactly is the getMeshBufferCount() > 1

Post by CuteAlien »

Yeah - it's 1 meshbuffer per material.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

Re: When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

what do you mean by a "material" and why is texture called as a material. Texture does not come along with OBJ.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: When exactly is the getMeshBufferCount() > 1

Post by CuteAlien »

A material describes the way the polygons are rendered. In the simplest case it might be just 1 color or even a wireframe. A typical case is for example a single texture. But can be several textures, light-setttings or even a shader. Check SMaterial for some of the settings you can use to describe a material.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

Re: When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

I have to get all the vertices in the mesh. I don't care about texture details or shader details.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: When exactly is the getMeshBufferCount() > 1

Post by hybrid »

Still, your mesh could have more than one meshbuffer. For example if you have more than 65k polys and a loader supporting this. Or if your mesh type (and obj does) support groups. These are usually kept in Irrlicht as well, as they might be intended for further use. Say, if you store multiple parts of a mesh in separate groups. Or multiple objects.
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

Re: When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

I wrote this function to merge all the meshBuffers in a mesh. Hope it'll help someone someday :)

Code: Select all

updated code available below
Last edited by cegprakash on Fri Jul 11, 2014 5:56 pm, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by hendu »

Your function has no check for the 16-bit limit. If you have over USHRT_MAX verts your mesh will be corrupted. The index offset of subsequent buffers is also wrong.
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

I've fixed the indices part.. No idea how to fix the u16 part. :( My code will fail if total no. of vertices exceed 2^16-1

Code: Select all

updated code available below
Last edited by cegprakash on Sat Jul 12, 2014 8:10 am, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by hendu »

It's still wrong if you have more than two meshbuffers.
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

why is it wrong?
I've added code to skip meshBuffers when the number of vertices/indices crosses u16 limit.

Code: Select all

updated code available below
Last edited by cegprakash on Sat Jul 12, 2014 1:32 pm, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by hendu »

Oh, my mistake, numVertices is not zeroed. Nevermind.
cegprakash
Posts: 41
Joined: Thu Feb 27, 2014 10:55 am

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by cegprakash »

is it looking okay now?
Why isn't irrlicht allowing more than 2^16 indices/vertices in a mesh buffer? Will the rendering be too slow?

Even if it's slow, irrlicht is capable to draw lot of meshBuffers simultaneously. Why won't it allow u32?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] When exactly is the getMeshBufferCount() > 1

Post by hendu »

Yes, it looks ok.

Irr does allow 32-bit indices, it's merely the default SMeshBuffer that does not. 16-bit indices should be used because they are faster and save VRAM, this is basic advice that all industry agrees on, and can be found in both AMD and Nvidia guides.

In other words, you are merely discouraged from using 32-bit indices, and indirectly meshes over 65k verts, because using them is against best practices.
Post Reply