NVidia's Vertex Array Range

Aka "How to store the triangles in the graphic card memory in order not to send them again and again to the graphic card".

First you have to know how to use VA (Vertex Arrays) as VAR is based on VAs.

The only difference is the way you allocate the memory: instead of using malloc or new, you ask the card for some AGP memory. You're going to allocate only ONCE these AGP memory, and you'll put all your VA inside it. Big chunk of AGP memory allocation:

//First, if you're under Windows, get the pointer to the needed functions using wglGetProcAddress

//Allocate memory
char var = strstr(extensions,"GL_NV_vertex_array_range")!=NULL;
if (!var) {
	printf("No VAR extension found\n");
char var2 = strstr(extensions,"GL_NV_vertex_array_range2")!=NULL;
	printf("VAR2 extension was found\n");

unsigned char *var_memory = AllocateMemoryNV( s, 0.0f,0.0f,0.5f );

if (var_memory==NULL)
	printf("AGP memory allocation failure\n");
else {
	size_var_free = s;
	VertexArrayRangeNV( s,var_memory );
	if (var2) {
		var_version = 2;
	else {
		glEnableClientState( GL_VERTEX_ARRAY_RANGE_NV );
		var_version = 1;
	printf("Memoire AGP allouee\n");
next_va_available = var_memory;

Array allocation:

//If no VAR is available, standard allocation method. CARE: don't forget to free that later
if (var==0 || var_memory==NULL || size>size_var_free )
	return malloc(size);

size_var_free -= size;
void *res = next_va_available;
next_va_available += size;
return res;
When you shut down your engine:
glDisableClientState( GL_VERTEX_ARRAY_RANGE_NV );
FreeMemoryNV( var_memory );

Main page

email : Sly