Commits

Alex Szpakowski committed 56db65b

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.

Comments (0)

Files changed (1)

src/modules/graphics/opengl/Graphics.cpp

 
 void Graphics::point(float x, float y)
 {
-	glDisable(GL_TEXTURE_2D);
+	bindTexture(0);
 	glBegin(GL_POINTS);
 	glVertex2f(x, y);
 	glEnd();
-	glEnable(GL_TEXTURE_2D);
 }
 
 // Calculate line boundary points u1 and u2. Sketch:
 	// end get line vertex boundaries
 
 	// draw the core line
-	glDisable(GL_TEXTURE_2D);
+	bindTexture(0);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)vertices);
 	glDrawArrays(GL_TRIANGLE_STRIP, 0, count);
 		draw_overdraw(overdraw, count, pixel_size, looping);
 
 	glDisableClientState(GL_VERTEX_ARRAY);
-	glEnable(GL_TEXTURE_2D);
 
 	// cleanup
 	delete[] vertices;
 	}
 	else
 	{
-		glDisable(GL_TEXTURE_2D);
+		bindTexture(0);
 		glEnableClientState(GL_VERTEX_ARRAY);
 		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *) coords);
 		glDrawArrays(GL_TRIANGLE_FAN, 0, points + 2);
 		glDisableClientState(GL_VERTEX_ARRAY);
-		glEnable(GL_TEXTURE_2D);
 	}
 
 	delete[] coords;
 	}
 	else
 	{
-		glDisable(GL_TEXTURE_2D);
+		bindTexture(0);
 		glEnableClientState(GL_VERTEX_ARRAY);
 		glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)coords);
 		glDrawArrays(GL_POLYGON, 0, count/2-1); // opengl will close the polygon for us
 		glDisableClientState(GL_VERTEX_ARRAY);
-		glEnable(GL_TEXTURE_2D);
 	}
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.