Browse Source

Don't do unnecessary vertex buffer orphaning when calling SpriteBatch:unbind() on a SpriteBatch with the static usage hint

Alex Szpakowski 11 years ago
parent
commit
6a491ed0f0
1 changed files with 12 additions and 4 deletions
  1. 12 4
      src/modules/graphics/opengl/VertexBuffer.cpp

+ 12 - 4
src/modules/graphics/opengl/VertexBuffer.cpp

@@ -182,10 +182,18 @@ void VBO::unmap()
 		is_bound = true;
 		is_bound = true;
 	}
 	}
 
 
-	// "orphan" current buffer to avoid implicit synchronisation on the GPU:
-	// http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf
-	glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), NULL,       getUsage());
-	glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage());
+	if (getUsage() == GL_STATIC_DRAW)
+	{
+		// Upload the mapped data to the buffer.
+		glBufferSubDataARB(getTarget(), 0, (GLsizeiptr) getSize(), memory_map);
+	}
+	else
+	{
+		// "orphan" current buffer to avoid implicit synchronisation on the GPU:
+		// http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf
+		glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), NULL,       getUsage());
+		glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage());
+	}
 
 
 	is_mapped = false;
 	is_mapped = false;
 }
 }