[Bf-blender-cvs] [adbbcefe] blender2.8: Gawain: fewer glEnable/DisableVertexAttribArray calls

Mike Erwin noreply at git.blender.org
Wed Aug 10 22:09:14 CEST 2016


Commit: adbbcefe57223813f9dd5dd8c764a07602bb6bd7
Author: Mike Erwin
Date:   Wed Aug 10 16:08:32 2016 -0400
Branches: blender2.8
https://developer.blender.org/rBadbbcefe57223813f9dd5dd8c764a07602bb6bd7

Gawain:  fewer glEnable/DisableVertexAttribArray calls

Track previously enabled attrib locations so we can call OpenGL only
when needed.

Same result, fewer GL calls.

===================================================================

M	source/blender/gpu/intern/gpu_immediate.c

===================================================================

diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index 11e609c..57f1cc5 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -250,6 +250,7 @@ typedef struct {
 	
 	GLuint bound_program;
 	AttribBinding attrib_binding;
+	uint16_t prev_enabled_attrib_bits;
 } Immediate;
 
 // size of internal buffer -- make this adjustable?
@@ -421,6 +422,29 @@ void immEnd()
 	// set up VAO -- can be done during Begin or End really
 	glBindVertexArray(imm.vao_id);
 
+	// enable/disable vertex attribs as needed
+	if (imm.attrib_binding.enabled_bits != imm.prev_enabled_attrib_bits)
+		{
+		for (unsigned loc = 0; loc < MAX_VERTEX_ATTRIBS; ++loc)
+			{
+			bool is_enabled = imm.attrib_binding.enabled_bits & (1 << loc);
+			bool was_enabled = imm.prev_enabled_attrib_bits & (1 << loc);
+
+			if (is_enabled && !was_enabled)
+				{
+//				printf("enabling attrib %u\n", loc);
+				glEnableVertexAttribArray(loc);
+				}
+			else if (was_enabled && !is_enabled)
+				{
+//				printf("disabling attrib %u\n", loc);
+				glDisableVertexAttribArray(loc);
+				}
+			}
+
+		imm.prev_enabled_attrib_bits = imm.attrib_binding.enabled_bits;
+		}
+
 	const unsigned stride = immVertexFormat.stride;
 
 	for (unsigned a_idx = 0; a_idx < immVertexFormat.attrib_ct; ++a_idx)
@@ -432,8 +456,7 @@ void immEnd()
 
 		const unsigned loc = read_attrib_location(&imm.attrib_binding, a_idx);
 
-//		printf("enabling attrib %u '%s' at offset %u, stride %u\n", loc, a->name, offset, stride);
-		glEnableVertexAttribArray(loc);
+//		printf("specifying attrib %u '%s' with offset %u, stride %u\n", loc, a->name, offset, stride);
 
 		switch (a->fetch_mode)
 			{
@@ -449,21 +472,6 @@ void immEnd()
 			}
 		}
 
-	for (unsigned loc = 0; loc < MAX_VERTEX_ATTRIBS; ++loc)
-		{
-		if (imm.attrib_binding.enabled_bits & (1 << loc))
-			{
-			}
-		else
-			{
-//			printf("disabling attrib %u\n", loc);
-			glDisableVertexAttribArray(loc);
-			}
-
-		// TODO: compare with previous draw's attrib binding
-		// will always need to update pointers, but can reduce Enable/Disable calls
-		}
-
 	glDrawArrays(imm.primitive, 0, imm.vertex_ct);
 
 	glBindBuffer(GL_ARRAY_BUFFER, 0);




More information about the Bf-blender-cvs mailing list