gl: enable use of buffer objects for TexSubImage2D by nil

This CL enables use of a bound buffer at TexSubImage2D by allowing
nil (0) data, which indicates the head of the bound buffer.

In the long run, we need to be able to pass non-0 integer to not
only TexSubImage2D but also other functions like TexImage2D. As we
might change the API, let's revisit this issue later.

Fixes golang/go#36355

Change-Id: I66f6650b10fca9a346cfa6eba246ea9286ed3a85
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/213077
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/gl/gl.go b/gl/gl.go
index 95f7468..41dfef7 100644
--- a/gl/gl.go
+++ b/gl/gl.go
@@ -1284,6 +1284,14 @@
 }
 
 func (ctx *context) TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) {
+	// It is common to pass TexSubImage2D a nil data, indicating that a
+	// bound GL buffer is being used as the source. In that case, it
+	// is not necessary to block.
+	parg := unsafe.Pointer(nil)
+	if len(data) > 0 {
+		parg = unsafe.Pointer(&data[0])
+	}
+
 	ctx.enqueue(call{
 		args: fnargs{
 			fn: glfnTexSubImage2D,
@@ -1297,8 +1305,8 @@
 			a6: format.c(),
 			a7: ty.c(),
 		},
-		parg:     unsafe.Pointer(&data[0]),
-		blocking: true,
+		parg:     parg,
+		blocking: parg != nil,
 	})
 }