I’m diving into vertex array range stuff and have a few questions:

the specs say one should’nt call (glX/wgl)AllocateMemoryNV more than once. Why? I have following problem: I have a collection of objects, and each obejct has it’s own vertex array, normal array, texcoord array and indices array. When rendering multiply objects I must call glVertexPointer… and glDrawRangeElements for each object. How can this be arranged with vertex array range extension?

Can I use plain system memory for a vertex array range? I mean memory allocated with malloc/calloc/realloc and c++'s new?

Thanks in advance

You can use VAR with system memory, but performance will be terrible.

The reason you shouldn’t call AllocateMemoryNV more than once, is because the driver does not have any memory management code managing this memory. You should attempt to allocate the most memory you can and manage it yourself.


During your program startup, figure out how much memory you need for geometry for all your objects, and then try to allocate a buffer this big in video memory (allowing enough for textures, framebuffer of course). If it won’t all fit, then put as much as possible in video memory (keep reducing the buffer size until you get a valid pointer back from wglallocateMemoryNV) and put the rest in AGP or system memory.

Then just copy your mesh data one after the other into the buffer, keeping a pointer to the beginning of each mesh. This way you can use one large buffer, which is good for efficiency on the card.

would it be ok to do following:

allocate AGP memory
do stuff
free AGP memory

allocate AGP memory
do other stuff
free AGP memory



I write a portal engine and I have got a vertex array for each room of the world. I can’t load all arrays into the same memory block because they are too big.

If I hadn’t noticed this thread i would have coded it this way:

  • allocate some blocks of memory
  • load some sectors (from a file)
  • leave sectors that are far away unloaded

I would have been deallocating memory for old sectors and allocating memory and loading new sectors from time to time as the camera moves through the world.

Whats the best way to do this without many calls to alloc/deallocNV?

from what i’ve understood the solution is to use fences extension (although I understand 0% of what fences are and how the work )


with the NV_fence extension i can find out if the hardware has already read the data out of the var and if it is save to overwrite/deallocate it

when i deallocate an array i know that it isn’t needed anymore because the sector using this data is far away (i determine this with some sort of paging algorithm)

my problem is not to find out when i can deallocate the memory, the problem is that it is not recommended to call allocateNV more than once, wich is required when i want to dynamically load/unload parts of my world

Basically, what you will have to do is allocate one large block of memory. Then, you copy into this memory all of the vertex arrays you will need for that frame. After doing that, you do the setup (ie gl*pointer operations) for each array and do your rendering.

The trick is to use efficient memory management. You should do your best to keep memory from becoming fragmented (if you use a complex memory management scheme). A quick way to do it is to keep your vertex arrays in “blocks” of a fixed size. Then, wglAllocate a bank of memory equal to the number of array blocks you will need. When it is time to render, you will need to load up array blocks for things you need to render (that aren’t already loaded).

I would do my best not to try to render more than you allocate memory for. For instance, if you can guarentee that the renderer will not try to render more than 8MB of information, just allocate 8MB of AGP memory and use as much as you can. Playing with fences to reuse memory in the middle of a frame isn’t the easiest thing in the world.