VAR -- aligned pointers / striding?

Started by
4 comments, last by Kurioes 21 years, 4 months ago
I just read Spearhawk's post about something about the GL_NV_vertex_array_range extension. He gives a link to an NVidia article about the vertex array range extension. I read the article but two things confus me: 1) Vertex arrays' pointers should be 4-byte aligned 2) Strides must be multiples of four I know what the first one means, so I made up a define to turn a pointer into a 4-byte aligned pointer. Because Windows programs probably have a virtual addres space or something like that, this trick may not work, so the question is: Would this work (assuming you allocate 4 bytes extra for the vertex array) #define align4(x) ((x & 0x03) ? (ptr + (4 - (x & 0x03))) : (x)) You can then align4(ptr) the pointer to make it aligned. As for the strides: what are strides? I took a look at the GL_NV_vertex_array_range extension spec but it's still unclear to me... Thanks in advance /Tristan Edit: typo [edited by - Kurioes on December 14, 2002 11:54:11 AM]
Advertisement
stride defines the memory spacing between two vertices. It means that the size of one vertex in memory (including all it's attributes like position, colour, normals, etc, and optional padding) must be a multiple of 4 bytes.


[edited by - Yann L on December 14, 2002 11:57:34 AM]
Thanks for the info...

But floats are 4 bytes... Assuming all the data about the vertices is floats you don''t have anything to worry about (as opposed to bytes) if I understand correctly.

As for the aligned byte question... I''ll ask in the general programming forum.
quote:
But floats are 4 bytes... Assuming all the data about the vertices is floats you don't have anything to worry about (as opposed to bytes) if I understand correctly.

Yep. If you only use floats, then you don't have to worry about 4 byte strides.

quote:
As for the aligned byte question... I'll ask in the general programming forum.

Well, you can simply align a pointer like this: p = (p+3)&(~3)
Make sure to keep a copy of the original pointer, in order to free it later on. But you shouldn't really worry about alignment, as modern 32bit OS's will always return a 4 byte aligned pointer when allocating memory.

[Edit: typo]

[edited by - Yann L on December 14, 2002 5:47:55 PM]
Accualy you do have to take care of aligning yourself.
When using VAR (and i suppose VAO too) you should only alloc
one big block of memory which you are responsible for and
have to splitup amoung your vertex arrays yourself (and
manage "freeing" of memory too). Be sure to do it properly

Myself i''m having a little problem with this in my current
engine, so if someone know a good solution you''r welcome.
Right now i use a buddy-allocator to keep track of my memory
blocks.

BR
Marten Svanfeldt
Aren''t you confusing system memory and AGP memory? You don''t have to take care of the aligning in AGP memory as far as I understand... your video driver handles that for you. However, for fast transfer rates between system and AGP memory you''d need the data to be aligned on system mem (driver aligns on AGP mem).

I know you should only allocate one big block of AGP memory... that''s no problem... at least not yet. Maybe somthing like this could be used to create an AGP memory manager.

This topic is closed to new replies.

Advertisement