Browse Source

Bind texture id 0 (no texture) instead of disabling/re-enabling texturing entirely, when drawing graphics primitives. This both allows shaders to potentially use their own textures when drawing textureless primitives, and reduces overhead caused by constant GL state changes when drawing many graphics primitives.

Alexander Szpakowski 12 years ago
parent
commit
da661e8e2f
1 changed files with 4 additions and 8 deletions
  1. 4 8
      src/modules/graphics/opengl/Graphics.cpp

+ 4 - 8
src/modules/graphics/opengl/Graphics.cpp

@@ -742,11 +742,10 @@ void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode a
 
 
 void Graphics::point(float x, float y)
 void Graphics::point(float x, float y)
 {
 {
-	glDisable(GL_TEXTURE_2D);
+	bindTexture(0);
 	glBegin(GL_POINTS);
 	glBegin(GL_POINTS);
 	glVertex2f(x, y);
 	glVertex2f(x, y);
 	glEnd();
 	glEnd();
-	glEnable(GL_TEXTURE_2D);
 }
 }
 
 
 // Calculate line boundary points u1 and u2. Sketch:
 // Calculate line boundary points u1 and u2. Sketch:
@@ -940,7 +939,7 @@ void Graphics::polyline(const float *coords, size_t count)
 	// end get line vertex boundaries
 	// end get line vertex boundaries
 
 
 	// draw the core line
 	// draw the core line
-	glDisable(GL_TEXTURE_2D);
+	bindTexture(0);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)vertices);
 	glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)vertices);
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
@@ -950,7 +949,6 @@ void Graphics::polyline(const float *coords, size_t count)
 		draw_overdraw(overdraw, count, pixel_size, looping);
 		draw_overdraw(overdraw, count, pixel_size, looping);
 
 
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
-	glEnable(GL_TEXTURE_2D);
 
 
 	// cleanup
 	// cleanup
 	delete[] vertices;
 	delete[] vertices;
@@ -1034,12 +1032,11 @@ void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1,
 	}
 	}
 	else
 	else
 	{
 	{
-		glDisable(GL_TEXTURE_2D);
+		bindTexture(0);
 		glEnableClientState(GL_VERTEX_ARRAY);
 		glEnableClientState(GL_VERTEX_ARRAY);
 		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *) coords);
 		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *) coords);
 		glDrawArrays(GL_TRIANGLE_FAN, 0, points + 2);
 		glDrawArrays(GL_TRIANGLE_FAN, 0, points + 2);
 		glDisableClientState(GL_VERTEX_ARRAY);
 		glDisableClientState(GL_VERTEX_ARRAY);
-		glEnable(GL_TEXTURE_2D);
 	}
 	}
 
 
 	delete[] coords;
 	delete[] coords;
@@ -1058,12 +1055,11 @@ void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
 	}
 	}
 	else
 	else
 	{
 	{
-		glDisable(GL_TEXTURE_2D);
+		bindTexture(0);
 		glEnableClientState(GL_VERTEX_ARRAY);
 		glEnableClientState(GL_VERTEX_ARRAY);
 		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)coords);
 		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)coords);
 		glDrawArrays(GL_POLYGON, 0, count/2-1); // opengl will close the polygon for us
 		glDrawArrays(GL_POLYGON, 0, count/2-1); // opengl will close the polygon for us
 		glDisableClientState(GL_VERTEX_ARRAY);
 		glDisableClientState(GL_VERTEX_ARRAY);
-		glEnable(GL_TEXTURE_2D);
 	}
 	}
 }
 }