MCPcopy
hub / github.com/tensorflow/tfjs / detectGLCapabilities

Function detectGLCapabilities

tfjs-react-native/src/camera/camera.ts:54–97  ·  view source on GitHub ↗
(gl: WebGL2RenderingContext)

Source from the content-addressed store, hash-verified

52 * @doc {heading: 'Media', subheading: 'Camera'}
53 */
54export async function detectGLCapabilities(gl: WebGL2RenderingContext) {
55 if (glCapabilities.glCapabilitiesTested.get(gl)) {
56 return;
57 }
58 // Test whether we can successfully download from an RGB texture.
59 // Notably this isn't supported on iOS, but we use this test rather than a
60 // platform check to be more robust on android devices we may not have
61 // directly tested.
62
63 // Set this to true temporarily so that fromTexture does not
64 // use its workaround.
65 glCapabilities.canDownloadFromRGBTexture.set(gl, true);
66
67 try {
68 const height = 2;
69 const width = 4; // This must be a multiple of 4.
70 const data = new Uint8Array(height * width * 4);
71 for (let i = 0; i < data.length; i++) {
72 data[i] = i;
73 }
74 const sourceDims = {height, width, depth: 4};
75 const tex = uploadTextureData(data, gl, sourceDims);
76
77 const targetDims = {height, width, depth: 3};
78 const downloaded = fromTexture(gl, tex, sourceDims, targetDims);
79 const downloadedData = await downloaded.data();
80 tf.dispose(downloaded);
81
82 const matches = tf.util.arraysEqual(downloadedData, [
83 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14,
84 16, 17, 18, 20, 21, 22, 24, 25, 26, 28, 29, 30
85 ]);
86
87 if (matches) {
88 glCapabilities.canDownloadFromRGBTexture.set(gl, true);
89 } else {
90 glCapabilities.canDownloadFromRGBTexture.set(gl, false);
91 }
92 } catch (e) {
93 glCapabilities.canDownloadFromRGBTexture.set(gl, false);
94 } finally {
95 glCapabilities.glCapabilitiesTested.set(gl, true);
96 }
97}
98
99/**
100 * Transfers tensor data to an RGB(A) texture.

Callers 2

onGLContextCreateMethod · 0.90
camera_test.tsFile · 0.90

Calls 6

uploadTextureDataFunction · 0.90
fromTextureFunction · 0.85
dataMethod · 0.65
getMethod · 0.45
setMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…