+int R_Mesh_CreateStaticBufferObject(unsigned int target, void *data, size_t size, const char *name)
+{
+ gl_bufferobjectinfo_t *info;
+ GLuint bufferobject;
+
+ if (!gl_vbo.integer)
+ return 0;
+
+ qglGenBuffersARB(1, &bufferobject);
+ switch(target)
+ {
+ case GL_ELEMENT_ARRAY_BUFFER_ARB: GL_BindEBO(bufferobject);break;
+ case GL_ARRAY_BUFFER_ARB: GL_BindVBO(bufferobject);break;
+ default: Sys_Error("R_Mesh_CreateStaticBufferObject: unknown target type %i\n", target);return 0;
+ }
+ qglBufferDataARB(target, size, data, GL_STATIC_DRAW_ARB);
+
+ info = Mem_ExpandableArray_AllocRecord(&gl_bufferobjectinfoarray);
+ memset(info, 0, sizeof(*info));
+ info->target = target;
+ info->object = bufferobject;
+ info->size = size;
+ strlcpy(info->name, name, sizeof(info->name));
+
+ return (int)bufferobject;
+}
+
+void R_Mesh_DestroyBufferObject(int bufferobject)
+{
+ int i, endindex;
+ gl_bufferobjectinfo_t *info;
+
+ qglDeleteBuffersARB(1, (GLuint *)&bufferobject);
+
+ endindex = Mem_ExpandableArray_IndexRange(&gl_bufferobjectinfoarray);
+ for (i = 0;i < endindex;i++)
+ {
+ info = Mem_ExpandableArray_RecordAtIndex(&gl_bufferobjectinfoarray, i);
+ if (!info)
+ continue;
+ if (info->object == bufferobject)
+ {
+ Mem_ExpandableArray_FreeRecord(&gl_bufferobjectinfoarray, (void *)info);
+ break;
+ }
+ }
+}
+
+void GL_Mesh_ListVBOs(qboolean printeach)
+{
+ int i, endindex;
+ size_t ebocount = 0, ebomemory = 0;
+ size_t vbocount = 0, vbomemory = 0;
+ gl_bufferobjectinfo_t *info;
+ endindex = Mem_ExpandableArray_IndexRange(&gl_bufferobjectinfoarray);
+ for (i = 0;i < endindex;i++)
+ {
+ info = Mem_ExpandableArray_RecordAtIndex(&gl_bufferobjectinfoarray, i);
+ if (!info)
+ continue;
+ switch(info->target)
+ {
+ case GL_ELEMENT_ARRAY_BUFFER_ARB: ebocount++;ebomemory += info->size;if (printeach) Con_Printf("EBO #%i %s = %i bytes\n", info->object, info->name, (int)info->size);break;
+ case GL_ARRAY_BUFFER_ARB: vbocount++;vbomemory += info->size;if (printeach) Con_Printf("VBO #%i %s = %i bytes\n", info->object, info->name, (int)info->size);break;
+ default: Con_Printf("gl_vbostats: unknown target type %i\n", info->target);break;
+ }
+ }
+ Con_Printf("vertex buffers: %i element buffers totalling %i bytes (%.3f MB), %i vertex buffers totalling %i bytes (%.3f MB), combined %i bytes (%.3fMB)\n", (int)ebocount, (int)ebomemory, ebomemory / 1048576.0, (int)vbocount, (int)vbomemory, vbomemory / 1048576.0, (int)(ebomemory + vbomemory), (ebomemory + vbomemory) / 1048576.0);
+}
+