func ImageData(img image.Image) (gl.Sizei, gl.Sizei, gl.Enum, gl.Enum, gl.Pointer) { switch img := img.(type) { case *image.NRGBA: return gl.Sizei(img.Rect.Dx()), gl.Sizei(img.Rect.Dy()), gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&img.Pix[0]) case *image.RGBA: return gl.Sizei(img.Rect.Dx()), gl.Sizei(img.Rect.Dy()), gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&img.Pix[0]) default: panic(reflect.TypeOf(img)) } return 0, 0, gl.RGB, gl.UNSIGNED_BYTE, nil }
func ArrayPtr(data interface{}) (gl.Pointer, gl.Sizeiptr) { var size gl.Sizeiptr var ptr gl.Pointer switch data := data.(type) { case []float64: duplicate := make([]gl.Float, len(data)) for i, v := range data { duplicate[i] = gl.Float(v) } ptr, size = ArrayPtr(duplicate) case []float32: if len(data) == 0 { size = 0 ptr = gl.Pointer(nil) } else { var v float32 size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v))) ptr = gl.Pointer(&data[0]) } case []gl.Float: if len(data) == 0 { size = 0 ptr = gl.Pointer(nil) } else { var v gl.Float size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v))) ptr = gl.Pointer(&data[0]) } case []int16: if len(data) == 0 { size = 0 ptr = gl.Pointer(nil) } else { var v int16 size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v))) ptr = gl.Pointer(&data[0]) } case []gl.Ushort: if len(data) == 0 { size = 0 ptr = gl.Pointer(nil) } else { var v gl.Ushort size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v))) ptr = gl.Pointer(&data[0]) } case []int: duplicate := make([]gl.Ushort, len(data)) for i, v := range data { duplicate[i] = gl.Ushort(v) } ptr, size = ArrayPtr(duplicate) case []gl.Int: if len(data) == 0 { size = 0 ptr = gl.Pointer(nil) } else { var v gl.Int size = gl.Sizeiptr(len(data) * int(unsafe.Sizeof(v))) ptr = gl.Pointer(&data[0]) } default: panic(fmt.Sprintln("unknown data type:", reflect.TypeOf(data))) } return ptr, size }