commit ff948a089ca61a60d8aabf225ae70993e65ba852
Author: Timo Korvola <tkorvola@iki.fi>
Date:   Tue Feb 21 23:11:48 2012 +0200

    Record the minimum and maximum indices when creating index buffers.
    
    The bounds can then be used in glDrawRangeElements, which appears
    somewhat faster than glDrawElements.
    
    Conflicts:
    
    	code/graphics/gropengltnl.cpp

diff --git a/code/graphics/2d.h b/code/graphics/2d.h
index e55f65e..92eebbf 100644
--- a/code/graphics/2d.h
+++ b/code/graphics/2d.h
@@ -109,7 +109,12 @@ struct buffer_data {
 
 	size_t index_offset;
 
-	uint *index;
+	const uint *get_index() const
+	{
+		return index;
+	}
+	
+        uint i_first, i_last;
 
 	void release()
 	{
@@ -119,10 +124,26 @@ struct buffer_data {
 		}
 	}
 
-	buffer_data() :
-		flags(0), texture(-1), n_verts(0), index_offset(0), index(NULL)
+	void assign(int i, uint j)
+	{
+		const_cast<uint *>(index)[i] = j;
+		if (i_first > i_last)
+			i_first = i_last = j;
+		else if (i_first > j)
+			i_first = j;
+		else if (i_last < j)
+			i_last = j;
+	}
+
+	buffer_data(int n_vrts) :
+		flags(0), texture(-1), n_verts(n_vrts), index_offset(0),
+		i_first(1), i_last(0)
 	{
+		index = new(std::nothrow) uint[n_verts];
 	}
+
+private:
+	uint *index;
 };
 
 struct vertex_buffer {
diff --git a/code/graphics/gropengltnl.cpp b/code/graphics/gropengltnl.cpp
index 6a07156..eeed02c 100644
--- a/code/graphics/gropengltnl.cpp
+++ b/code/graphics/gropengltnl.cpp
@@ -357,7 +357,7 @@ bool gr_opengl_pack_buffer(const int buffer_id, vertex_buffer *vb)
 	for (j = 0; j < vb->tex_buf.size(); j++) {
 		n_verts = vb->tex_buf[j].n_verts;
 		uint offset = vb->tex_buf[j].index_offset;
-		uint *index = vb->tex_buf[j].index;
+		const uint *index = vb->tex_buf[j].get_index();
 
 		// bump to our spot in the buffer
 		GLubyte *ibuf = m_vbp->index_list + offset;
@@ -494,7 +494,7 @@ static void opengl_init_arrays(opengl_vertex_buffer *vbp, const vertex_buffer *b
 	if (Cmdline_drawelements) \
 		glDrawElements(GL_TRIANGLES, count, element_type, ibuffer + (datap->index_offset + start)); \
 	else \
-		vglDrawRangeElements(GL_TRIANGLES, start, end, count, element_type, ibuffer + (datap->index_offset + start));
+		vglDrawRangeElements(GL_TRIANGLES, datap->i_first, datap->i_last, count, element_type, ibuffer + (datap->index_offset + start));
 
 int GL_last_shader_flags = -1;
 int GL_last_shader_index = -1;
diff --git a/code/model/modelinterp.cpp b/code/model/modelinterp.cpp
index 92c073f..d9aa672 100644
--- a/code/model/modelinterp.cpp
+++ b/code/model/modelinterp.cpp
@@ -4245,22 +4245,21 @@ void interp_configure_vertex_buffers(polymodel *pm, int mn)
 		if ( !polygon_list[i].n_verts )
 			continue;
 
-		buffer_data new_buffer;
+		buffer_data new_buffer(polygon_list[i].n_verts);
 
-		new_buffer.index = new(std::nothrow) uint[polygon_list[i].n_verts];
-		Verify( new_buffer.index != NULL );
+		Verify( new_buffer.get_index() != NULL );
 
 		for (j = 0; j < polygon_list[i].n_verts; j++) {
 			if (ibuffer_info.read != NULL) {
 				first_index = cfread_int(ibuffer_info.read);
 				Assert( first_index >= 0 );
 
-				new_buffer.index[j] = (uint)first_index;
+				new_buffer.assign(j, first_index);
 			} else {
 				first_index = model_list->find_index(&polygon_list[i], j);
 				Assert(first_index != -1);
 
-				new_buffer.index[j] = (uint)first_index;
+				new_buffer.assign(j, first_index);
 
 				if (ibuffer_info.write != NULL) {
 					cfwrite_int(first_index, ibuffer_info.write);
@@ -4268,7 +4267,6 @@ void interp_configure_vertex_buffers(polymodel *pm, int mn)
 			}
 		}
 
-		new_buffer.n_verts = polygon_list[i].n_verts;
 		new_buffer.texture = i;
 
 		new_buffer.flags = 0;
