PDA

View Full Version : Problems with glVertexPointer



Jan
12-12-2002, 10:36 AM
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.

fritzlang
12-12-2002, 11:00 AM
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).]

Jan
12-12-2002, 11:13 AM
Originally posted by fritzlang:
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


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.

Coriolis
12-12-2002, 11:29 AM
glVertexPointer(3, GL_FLOAT, 4 * sizeof(GLfloat), (GLvoid*)pointer);

fritzlang
12-12-2002, 11:41 AM
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

jwatte
12-12-2002, 12:14 PM
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.

Jan
12-12-2002, 12:30 PM
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 ;-)

Thanks, to all of you.

Jan.

Coriolis
12-12-2002, 01:33 PM
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.