Problems with glVertexPointer

Hi

Because of performance reasons i wanted to align my vertices to 32 bit. Therefore i did this:

glVertexPointer (4, GL_FLOAT, 0, (GLvoid*) (pointer));

But i only get a black screen. So i tried this:

glVertexPointer (3, GL_FLOAT, sizeof (GL_FLOAT), (GLvoid*) (pointer));

However now i get very interessting objects, but not those i intended to get. I even tried this:

glVertexPointer (3, GL_FLOAT, 1, (GLvoid*) (pointer));

Because i thought the stride might be in units of “type” (GL_FLOAT), instead of bytes, but the results are equally confusing.

Has anyone ever had the same problems? Does glVertexPointer not support the stride parameter, or do i have to do something different?

I know i loaded my data correctly into the memory. If i don´t align my data to 32 bit but only use 3 elements, the results are correct.
I have a Geforce 2 with the latest drivers.

And another interessting thing: If i use system-memory i get around 300 FPS (of course with not-aligned vertices). If i use VRAM without VAR, i get 100 FPS, if i use VRAM with VAR, i get 300 FPS. So using VRAM is terribly slow without VAR, but with VAR, it is only equally fast?? (I draw around 1000 triangles, at the moment, so will there be a difference, if i draw more?).

Jan.

VRAM without VAR. What is that? Do you mean you dont call glVertexArrayRangeNV on the pointer? VRAM == VAR.

And why do you cast the pointer to (void*).
float* pVRAM = (float*)wglAllocateMemoryNV(numfloats * sizeof(float), 0.0f, 0.0f, 1.0f);
glVertexPointer(4, GL_FLOAT, 0, pVRAM);

The reason you get same performance with and w/o VAR is probably beacuse you are not vertex limited == ýou have overperformance with too little work to do. In this case you might even get the same fps using glVertex();

fritzlang

[This message has been edited by fritzlang (edited 12-12-2002).]

Originally posted by fritzlang:
[b]VRAM without VAR. What is that? Do you mean you dont call glVertexArrayRangeNV on the pointer? VRAM == VAR.

And why do you cast the pointer to (void*).
float* pVRAM = wglAllocateVRAM…bla…bla
glVertexPointer(4, GL_FLOAT, 0, pVRAM);

The reason you get same performance with and w/o VAR is probably beacuse you are not vertex limited == ýou have overperformance with too little work to do. In this case you might even get the same fps using glVertex();

fritzlang[/b]

Yes, i was not so sure, if VRAM and VAR HAVE to be use together, therefore i asked about it.

The casting of the pointer doesn´t matter. I only casted it to (GLvoid*) because the function itself uses this type.

I think you are right, 1000 triangles is not much work, good to see that my pc is so fast, that there is no difference at all.

However i still don´t know how to use vertices that are aligned to 32 bit.

Jan.

glVertexPointer(3, GL_FLOAT, 4 * sizeof(GLfloat), (GLvoid*)pointer);

Is there any point in aligning to 32bit?

This is from the Nvidia Geforce3 faq:

[quote]
>In general, the smallest vertex size >possible should be used, as this helps AGP
>bandwidth and your memory footprint. >Padding vertices to the next multiple of
>32-bytes (so, a 40 byte vertex gets padded >to 64 bytes) can slightly improve
>performance in the case of scattered memory >accesses, but roughly sequential
<access will provide better performance and >eliminate the need to pad. In general,
>padding is not recommended.

Any experience on this? What’s the most common case among you guys here?

fritzlang

Both 3 floats, and 4 floats, are equally aligned on 32 bits.

VAR has alignment restrictions that are, at a minimum, 32 bit aligned.

If you’re doing software processing, aligning so you can fit an even number of vertices in a cache line is beneficial.

The argument for “stride” to glVertexPointer is the number of BYTES between each first element.

Originally posted by Coriolis:
glVertexPointer(3, GL_FLOAT, 4 * sizeof(GLfloat), (GLvoid*)pointer);

This works, at last. I always interpreted the stride value to be the number of bytes between the end of one vertex and the beginning of the next, not as the complete size of one vertex (does anyone understand this sentence?).

I tested it and there was no difference in speed, although my 1000 triangle app is no good benchmark, of course :wink:

Thanks, to all of you.

Jan.

The documentation is a bit misleading when it says that “0 means tightly packed”.

When it says that vertex data should be aligned on a 32-bit boundary, that means the first vertex of the array, not every vertex in the array.