PDA

View Full Version : glInterleavedArrays() + VBO?



grunt123
12-09-2003, 06:57 PM
how do i do this?

can i do the following?

glGenBuffer(1, &interwined);
glBindBuffer(..., interwined);
glBufferData(...,NULL,...);
void *m = glMapbuffer(...)

... // copying data into interwined

glUnmapbuffer(...)

glInterleavedArrays(...,0,(char*)NULL);
glDrawArrays(...);

... if it's possible to use glInterleaveArrays() with VBO, is there any performance gain?

Jan
12-10-2003, 01:51 AM
Instead of using the glInterleaved.. function, simply use the glVertexPointer, ect. functions with a stride value.

That does the same.

Jan.

grunt123
12-10-2003, 02:56 AM
if i use glvertexpointer AND gltexcoordpointer (when i use VBO), then how do i set up the pointer parameter of each function? do i just use (char*)NULL? ...

grunt123
12-10-2003, 03:06 AM
i just tested my codes using (char*)NULL as pointer value in glvertexpointer and gltexcoordpointer ... didn't work. However, when i used glinterleavedarrays, it worked fine, but the frame rates dropped slightly. (comparing with non-VBO rendering code)

any idea?

thanks

Zengar
12-10-2003, 03:19 AM
I tried to use glInterleavedArrays with VBO on my FX5600(53.03) and it worked just fine -the same framerate as usual glxxPointer&stride approach.

zeckensack
12-10-2003, 09:17 AM
Originally posted by grunt123:
if i use glvertexpointer AND gltexcoordpointer (when i use VBO), then how do i set up the pointer parameter of each function? do i just use (char*)NULL? ... No, not NULL. You need to find the offsets to the right components. That depends on your vertex layout.
Eg

struct Vertex
{
float x,y,z; //position
float tx,ty; //tex coord
ubyte r,g,b,a; //color
};

Tex coords start at offset 12 (3*sizeof(float)), color starts at offset 20 (3*sizeof(float)+2*sizeof(float)).



glVertexPointer(3,GL_FLOAT,sizeof(Vertex),(void*)0 );
glTexCoordPointer(2,GL_FLOAT,sizeof(Vertex),(void* )12);
glColorPointer(4,GL_UNSIGNED_BYTE,sizeof(Vertex),( void*)20);

grunt123
12-10-2003, 01:17 PM
thx for the reply.

by the way, I read from somewhere on this board that glInterleaveArrays() can actually slow down the performance. can anyone confirm this?

zeckensack
12-10-2003, 01:59 PM
Originally posted by grunt123:
thx for the reply.

by the way, I read from somewhere on this board that glInterleaveArrays() can actually slow down the performance. can anyone confirm this? Interleaved arrays should be a win in the majority of cases. That's the general recommendation and you shouldn't do anything else unless you have a good reason.

You may get better performance with disjoint arrays only if you *frequently* change *some parts* of your vertices (eg position, but not texture coords, color etc).

ABCABCACBABC
vs
AAAA
BBBB
CCCC

It's simpler to respecify the As when they're not intermixed with the Bs and Cs. But then you should benchmark your particular case. It may very well be completely irrelevant.

PS: glInterleavedArrays is simply an 'emulation' layer put on top of the gl*Pointer calls.

grunt123
12-11-2003, 07:52 AM
if i want to use multitexturing with glInterleavedArrays(), how do i do it?

suppose that i have tex1 and tex2. how do i set up tex coord for these two textures when using glInterleavedArrays?

thanks

zeckensack
12-11-2003, 09:19 AM
Originally posted by grunt123:
if i want to use multitexturing with glInterleavedArrays(), how do i do it?

suppose that i have tex1 and tex2. how do i set up tex coord for these two textures when using glInterleavedArrays?

thanksglClientActiveTextureARB selects which pointer is modified by glTexCoordPointer and enabled by glEnableClientState(GL_TEXTURE_COORD_ARRAY);.

VBO case:

struct Vertex
{
float x,y,z; //position
float t0x,t0y; //tex coord set 0
float t1x,t1y; //tex coord set 1
};

glBindBufferARB(<...> );
glBufferDataARB(<...> );

glVertexPointer(3,GL_FLOAT,sizeof(Vertex),(void*)0 );
glEnableClientState(GL_VERTEX_ARRAY);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2,GL_FLOAT,sizeof(Vertex),(void* )12);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2,GL_FLOAT,sizeof(Vertex),(void* )20);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

//optional, for safety
glClientActiveTextureARB(GL_TEXTURE0_ARB);

And no, you can't do that with glInterleavedArrays. That function only 'knows' a few specific vertex layouts, and those don't include multitexture support.

grunt123
12-11-2003, 02:32 PM
why do we have to call glEnableClientState(...) in the rendering codes? I just tested your codes without glEnableClientState(GL_TEX_ARRAY) (i thought it was ok since i called glEnableClientState(GL_TEX_ARRAY) in the initialization codes) and the multi-texturing failed. any explanation? (until now, i only called glEnableClientState(...) in the initialization codes)

zeckensack
12-11-2003, 02:47 PM
That's most likely because you've called glEnableClientState(GL_TEXTURE_COORD_ARRAY) only once (or you did call it multiple times but you didn't switch arrays). Not all of your texture coordinate sets were properly set up.

glEnbableClientState(GL_TEXTURE_COORD_ARRAY) and glTexCoordPointer only work for the coordinate set that has been selected with glClientActiveTexture (the default state is GL_TEXTURE0_ARB).

Of course you can enable the arrays in your init code just as well.