expo-gl 11.0.2 → 11.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,10 +10,23 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
- ## 11.0.2 — 2021-10-15
13
+ ## 11.1.2 — 2022-02-01
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fix segfault in iOS draw loop. ([#15653](https://github.com/expo/expo/pull/15653) by [@wkozyra95](https://github.com/wkozyra95))
18
+ - Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
19
+
20
+ ## 11.1.1 — 2021-12-08
14
21
 
15
22
  _This version does not introduce any user-facing changes._
16
23
 
24
+ ## 11.1.0 — 2021-12-03
25
+
26
+ ### 🎉 New features
27
+
28
+ - Add support for reanimated worklets. ([#15296](https://github.com/expo/expo/pull/15296) by [@wkozyra95](https://github.com/wkozyra95))
29
+
17
30
  ## 11.0.1 — 2021-10-01
18
31
 
19
32
  _This version does not introduce any user-facing changes._
package/README.md CHANGED
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Install expo-gl-cpp
19
19
 
@@ -1,9 +1,9 @@
1
1
  apply plugin: 'com.android.library'
2
2
  apply plugin: 'kotlin-android'
3
- apply plugin: 'maven'
3
+ apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '11.0.2'
6
+ version = '11.1.2'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -20,27 +20,25 @@ buildscript {
20
20
  }
21
21
  }
22
22
 
23
- //Upload android library to maven with javadoc and android sources
24
- configurations {
25
- deployerJars
26
- }
27
-
28
- //Creating sources with comments
23
+ // Creating sources with comments
29
24
  task androidSourcesJar(type: Jar) {
30
25
  classifier = 'sources'
31
26
  from android.sourceSets.main.java.srcDirs
32
27
  }
33
28
 
34
- //Put the androidSources and javadoc to the artifacts
35
- artifacts {
36
- archives androidSourcesJar
37
- }
38
-
39
- uploadArchives {
40
- repositories {
41
- mavenDeployer {
42
- configuration = configurations.deployerJars
43
- repository(url: mavenLocal().url)
29
+ afterEvaluate {
30
+ publishing {
31
+ publications {
32
+ release(MavenPublication) {
33
+ from components.release
34
+ // Add additional sourcesJar to artifacts
35
+ artifact(androidSourcesJar)
36
+ }
37
+ }
38
+ repositories {
39
+ maven {
40
+ url = mavenLocal().url
41
+ }
44
42
  }
45
43
  }
46
44
  }
@@ -57,7 +55,7 @@ android {
57
55
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
56
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
57
  versionCode 31
60
- versionName "11.0.2"
58
+ versionName "11.1.2"
61
59
  }
62
60
 
63
61
  sourceSets.main {
@@ -85,16 +85,18 @@ public class GLContext {
85
85
  final JavaScriptContextProvider jsContextProvider = moduleRegistry.getModule(JavaScriptContextProvider.class);
86
86
  final RuntimeEnvironmentInterface environment = moduleRegistry.getModule(RuntimeEnvironmentInterface.class);
87
87
 
88
+ EXGLRegisterThread();
88
89
  uiManager.runOnClientCodeQueueThread(new Runnable() {
89
90
  @Override
90
91
  public void run() {
91
92
  long jsContextRef = jsContextProvider.getJavaScriptContextRef();
92
93
  synchronized (uiManager) {
93
94
  if (jsContextRef != 0) {
94
- mEXGLCtxId = EXGLContextCreate(jsContextRef);
95
+ mEXGLCtxId = EXGLContextCreate();
96
+ EXGLRegisterThread();
97
+ EXGLContextPrepare(jsContextRef, mEXGLCtxId, glContext);
95
98
  }
96
99
  }
97
- EXGLContextSetFlushMethod(mEXGLCtxId, glContext);
98
100
  mManager.saveContext(glContext);
99
101
  completionCallback.run();
100
102
  }
package/build/Canvas.js CHANGED
@@ -50,7 +50,7 @@ const CanvasWrapper = ({ pointerEvents, children, ...props }) => {
50
50
  const { offsetWidth: width = 0, offsetHeight: height = 0 } = element;
51
51
  return { width, height };
52
52
  }
53
- function onLayout(event) {
53
+ const onLayout = (event) => {
54
54
  const { nativeEvent: { layout: { width, height }, }, } = event;
55
55
  if (width !== size?.width || height !== size.height) {
56
56
  setSize({ width, height });
@@ -58,7 +58,7 @@ const CanvasWrapper = ({ pointerEvents, children, ...props }) => {
58
58
  props.onLayout(event);
59
59
  }
60
60
  }
61
- }
61
+ };
62
62
  React.useEffect(() => {
63
63
  if (ref.current != null) {
64
64
  setSize(getSize());
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAqB,UAAU,EAAE,UAAU,EAAE,IAAI,EAAa,MAAM,cAAc,CAAC;AAC1F,OAAO,aAAa,MAAM,6CAA6C,CAAC;AAExE,SAAS,UAAU,CAAC,SAAS;IAC3B,IAAI;QACF,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC;KAC/B;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,SAAS,MAAM,CAAI,OAAqB,EAAE,GAAa;IACrD,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;QACjC,OAAO,CAAC,GAAG,CAAC,CAAC;KACd;SAAM,IAAI,SAAS,IAAI,OAAO,EAAE;QAC/B,aAAa;QACb,OAAO,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,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CACL,oBAAC,IAAI,OAAK,KAAK,EAAE,aAAa,EAAC,UAAU,EAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;QACpE,oBAAC,MAAM,IAAC,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,GAAI;QACxF,QAAQ,CACJ,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport * as React from 'react';\nimport { findDOMNode } from 'react-dom';\nimport { LayoutChangeEvent, PixelRatio, StyleSheet, View, ViewProps } from 'react-native';\nimport createElement from 'react-native-web/dist/exports/createElement';\n\nfunction getElement(component) {\n try {\n return findDOMNode(component);\n } catch (e) {\n return component;\n }\n}\n\nfunction setRef<T>(refProp: React.Ref<T>, ref: T | null) {\n if (!refProp) return;\n\n if (typeof refProp === 'function') {\n refProp(ref);\n } else if ('current' in refProp) {\n // @ts-ignore\n refProp.current = ref;\n }\n}\n\nconst Canvas = React.forwardRef(\n (props: React.ComponentProps<typeof View>, ref: React.Ref<HTMLCanvasElement>) =>\n createElement('canvas', { ...props, ref })\n);\n\nconst CanvasWrapper: React.FunctionComponent<\n ViewProps & {\n canvasRef: React.Ref<HTMLCanvasElement>;\n }\n> = ({ pointerEvents, children, ...props }) => {\n const [size, setSize] = React.useState<{ width: number; height: number } | null>(null);\n\n const ref = React.useRef<View>(null);\n const _canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n function updateCanvasSize(): void {\n const canvas = _canvasRef.current;\n // eslint-disable-next-line no-undef\n if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {\n const size = getSize();\n const scale = PixelRatio.get();\n\n canvas.style.width = `${size.width}px`;\n canvas.style.height = `${size.height}px`;\n\n canvas.width = size.width * scale;\n canvas.height = size.height * scale;\n }\n }\n\n function getSize(): { width: number; height: number } {\n if (size) {\n return size;\n } else if (!ref.current || !Platform.isDOMAvailable) {\n return { width: 0, height: 0 };\n }\n const element = getElement(ref.current);\n const { offsetWidth: width = 0, offsetHeight: height = 0 } = element;\n return { width, height };\n }\n\n function onLayout(event: LayoutChangeEvent): void {\n const {\n nativeEvent: {\n layout: { width, height },\n },\n } = event;\n\n if (width !== size?.width || height !== size.height) {\n setSize({ width, height });\n\n if (props.onLayout) {\n props.onLayout(event);\n }\n }\n }\n\n React.useEffect(() => {\n if (ref.current != null) {\n setSize(getSize());\n }\n }, [ref]);\n\n React.useEffect(() => {\n updateCanvasSize();\n }, [size]);\n\n React.useEffect(() => {\n const canvas = _canvasRef.current;\n if (canvas) {\n updateCanvasSize();\n }\n setRef(props.canvasRef, canvas);\n }, [_canvasRef]);\n\n return (\n <View {...props} pointerEvents=\"box-none\" ref={ref} onLayout={onLayout}>\n <Canvas ref={_canvasRef} pointerEvents={pointerEvents} style={StyleSheet.absoluteFill} />\n {children}\n </View>\n );\n};\n\nexport default CanvasWrapper;\n"]}
1
+ {"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAqB,UAAU,EAAE,UAAU,EAAE,IAAI,EAAa,MAAM,cAAc,CAAC;AAC1F,OAAO,aAAa,MAAM,6CAA6C,CAAC;AAExE,SAAS,UAAU,CAAC,SAAS;IAC3B,IAAI;QACF,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC;KAC/B;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,SAAS,MAAM,CAAI,OAAqB,EAAE,GAAa;IACrD,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,IA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MAAM,GAAG,UAAU,CAAC,OAAO,CAAC;QAClC,IAAI,MAAM,EAAE;YACV,gBAAgB,EAAE,CAAC;SACpB;QACD,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CACL,oBAAC,IAAI,OAAK,KAAK,EAAE,aAAa,EAAC,UAAU,EAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;QACpE,oBAAC,MAAM,IAAC,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,GAAI;QACxF,QAAQ,CACJ,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\nimport * as React from 'react';\nimport { findDOMNode } from 'react-dom';\nimport { LayoutChangeEvent, PixelRatio, StyleSheet, View, ViewProps } from 'react-native';\nimport createElement from 'react-native-web/dist/exports/createElement';\n\nfunction getElement(component) {\n try {\n return findDOMNode(component);\n } catch (e) {\n return component;\n }\n}\n\nfunction setRef<T>(refProp: React.Ref<T>, ref: T | null) {\n if (!refProp) return;\n\n if (typeof refProp === 'function') {\n refProp(ref);\n } else if ('current' in refProp) {\n // @ts-ignore\n refProp.current = ref;\n }\n}\n\nconst Canvas = React.forwardRef(\n (props: React.ComponentProps<typeof View>, ref: React.Ref<HTMLCanvasElement>) =>\n createElement('canvas', { ...props, ref })\n);\n\nconst CanvasWrapper: React.FunctionComponent<\n ViewProps & {\n canvasRef: React.Ref<HTMLCanvasElement>;\n }\n> = ({ pointerEvents, children, ...props }) => {\n const [size, setSize] = React.useState<{ width: number; height: number } | null>(null);\n\n const ref = React.useRef<View>(null);\n const _canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n function updateCanvasSize(): void {\n const canvas = _canvasRef.current;\n // eslint-disable-next-line no-undef\n if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {\n const size = getSize();\n const scale = PixelRatio.get();\n\n canvas.style.width = `${size.width}px`;\n canvas.style.height = `${size.height}px`;\n\n canvas.width = size.width * scale;\n canvas.height = size.height * scale;\n }\n }\n\n function getSize(): { width: number; height: number } {\n if (size) {\n return size;\n } else if (!ref.current || !Platform.isDOMAvailable) {\n return { width: 0, height: 0 };\n }\n const element = getElement(ref.current);\n const { offsetWidth: width = 0, offsetHeight: height = 0 } = element;\n return { width, height };\n }\n\n const onLayout = (event: LayoutChangeEvent) => {\n const {\n nativeEvent: {\n layout: { width, height },\n },\n } = event;\n\n if (width !== size?.width || height !== size.height) {\n setSize({ width, height });\n\n if (props.onLayout) {\n props.onLayout(event);\n }\n }\n };\n\n React.useEffect(() => {\n if (ref.current != null) {\n setSize(getSize());\n }\n }, [ref]);\n\n React.useEffect(() => {\n updateCanvasSize();\n }, [size]);\n\n React.useEffect(() => {\n const canvas = _canvasRef.current;\n if (canvas) {\n updateCanvasSize();\n }\n setRef(props.canvasRef, canvas);\n }, [_canvasRef]);\n\n return (\n <View {...props} pointerEvents=\"box-none\" ref={ref} onLayout={onLayout}>\n <Canvas ref={_canvasRef} pointerEvents={pointerEvents} style={StyleSheet.absoluteFill} />\n {children}\n </View>\n );\n};\n\nexport default CanvasWrapper;\n"]}
package/build/GLUtils.js CHANGED
@@ -20,15 +20,15 @@ export function configureLogging(gl) {
20
20
  // Turn off logging.
21
21
  if (!option || option === GLLoggingOption.DISABLED) {
22
22
  Object.entries(gl).forEach(([key, value]) => {
23
- if (typeof value === 'function' && value.original) {
24
- gl[key] = value.original;
23
+ if (typeof value === 'function' && value.__logWrapper) {
24
+ delete gl[key];
25
25
  }
26
26
  });
27
27
  loggingOption = option;
28
28
  return;
29
29
  }
30
30
  // Turn on logging.
31
- Object.entries(gl).forEach(([key, originalValue]) => {
31
+ Object.entries(Object.getPrototypeOf(gl)).forEach(([key, originalValue]) => {
32
32
  if (typeof originalValue !== 'function' || key === '__expoSetLogging') {
33
33
  return;
34
34
  }
@@ -64,15 +64,16 @@ export function configureLogging(gl) {
64
64
  }
65
65
  if (loggingOption & GLLoggingOption.GET_ERRORS && key !== 'getError') {
66
66
  // @ts-ignore We need to call into the original `getError`.
67
- const error = gl.getError.original.call(gl);
67
+ // eslint-disable-next-line no-proto
68
+ const error = gl.__proto__.getError.call(gl);
68
69
  if (error && error !== gl.NO_ERROR) {
69
70
  // `console.error` would cause a red screen, so let's just log with red color.
70
71
  console.log(`\x1b[31mExpoGL: Error ${GLErrors[error]}\x1b[0m`);
71
72
  }
72
73
  }
74
+ gl[key].__logWrapper = true;
73
75
  return result;
74
76
  };
75
- gl[key].original = originalValue;
76
77
  });
77
78
  loggingOption = option;
78
79
  };
@@ -1 +1 @@
1
- {"version":3,"file":"GLUtils.js","sourceRoot":"","sources":["../src/GLUtils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAA6B,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE5E;;GAEG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAA6B;IAC5D,kDAAkD;IAClD,IAAI,aAAa,GAAG,eAAe,CAAC,QAAQ,CAAC;IAE7C,EAAE,CAAC,gBAAgB,GAAG,CAAC,MAAuB,EAAQ,EAAE;QACtD,kEAAkE;QAClE,0DAA0D;QAC1D,IAAI,CAAC,aAAa,KAAK,CAAC,MAAM,EAAE;YAC9B,aAAa,GAAG,MAAM,CAAC;YACvB,OAAO;SACR;QAED,oBAAoB;QACpB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,eAAe,CAAC,QAAQ,EAAE;YAClD,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC1C,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,K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C,GAAG,KAAK,CAAC;6BAC9E;yBACF;wBAED,yCAAyC;wBACzC,OAAO,EAAE,GAAG,GAAG,CAAC;oBAClB,CAAC,CAAC,CAAC;oBACH,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBACrD;gBAED,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBAE7C,IAAI,aAAa,GAAG,eAAe,CAAC,YAAY,EAAE;oBAChD,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,EAAE,CAAC,CAAC;iBACtC;gBACD,IAAI,aAAa,GAAG,eAAe,CAAC,UAAU,IAAI,GAAG,KAAK,UAAU,EAAE;oBACpE,2DAA2D;oBAC3D,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBAE5C,IAAI,KAAK,IAAI,KAAK,KAAK,EAAE,CAAC,QAAQ,EAAE;wBAClC,8EAA8E;wBAC9E,OAAO,CAAC,GAAG,CAAC,yBAAyB,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;qBAChE;iBACF;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;YACF,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,aAAa,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,aAAa,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import GLErrors from './GLErrors';\nimport { ExpoWebGLRenderingContext, GLLoggingOption } from './GLView.types';\n\n/**\n * Maximum length of the strings printed to the console.\n */\nconst MAX_STRING_LENGTH = 20;\n\n/**\n * Sets up `__expoSetLogging` method providing some logging options useful when debugging GL calls.\n */\nexport function configureLogging(gl: ExpoWebGLRenderingContext): void {\n // Enable/disable logging of all GL function calls\n let loggingOption = GLLoggingOption.DISABLED;\n\n gl.__expoSetLogging = (option: GLLoggingOption): void => {\n // If boolean values are the same, just change the internal value,\n // there is no need to wrap/unwrap functions in this case.\n if (!loggingOption === !option) {\n loggingOption = option;\n return;\n }\n\n // Turn off logging.\n if (!option || option === GLLoggingOption.DISABLED) {\n Object.entries(gl).forEach(([key, value]) => {\n if (typeof value === 'function' && value.original) {\n gl[key] = value.original;\n }\n });\n loggingOption = option;\n return;\n }\n\n // Turn on logging.\n Object.entries(gl).forEach(([key, originalValue]) => {\n if (typeof originalValue !== 'function' || key === '__expoSetLogging') {\n return;\n }\n\n gl[key] = (...args) => {\n if (loggingOption & GLLoggingOption.METHOD_CALLS) {\n const params = args.map((arg) => {\n // If the type is `number`, then try to find name of the constant that has such value,\n // so it's easier to read these logs. In some cases it might be misleading\n // if the parameter is for example a width or height, so the number is still logged.\n if (loggingOption & GLLoggingOption.RESOLVE_CONSTANTS && typeof arg === 'number') {\n for (const prop in gl) {\n if (gl[prop] === arg) {\n return `${arg} (${prop})`;\n }\n }\n }\n\n // Truncate strings so they don't produce too much output and don't block the bridge.\n // It mostly applies to shaders which might be very long...\n if (loggingOption & GLLoggingOption.TRUNCATE_STRINGS && typeof arg === 'string') {\n if (arg.length > MAX_STRING_LENGTH) {\n const lastIndex = arg.lastIndexOf(' ', MAX_STRING_LENGTH);\n return arg.substr(0, lastIndex >= 0 ? lastIndex : MAX_STRING_LENGTH) + '...';\n }\n }\n\n // Just return the parameter as a string.\n return '' + arg;\n });\n console.log(`ExpoGL: ${key}(${params.join(', ')})`);\n }\n\n const result = originalValue.apply(gl, args);\n\n if (loggingOption & GLLoggingOption.METHOD_CALLS) {\n console.log(`ExpoGL: = ${result}`);\n }\n if (loggingOption & GLLoggingOption.GET_ERRORS && key !== 'getError') {\n // @ts-ignore We need to call into the original `getError`.\n const error = gl.getError.original.call(gl);\n\n if (error && error !== gl.NO_ERROR) {\n // `console.error` would cause a red screen, so let's just log with red color.\n console.log(`\\x1b[31mExpoGL: Error ${GLErrors[error]}\\x1b[0m`);\n }\n }\n return result;\n };\n gl[key].original = originalValue;\n });\n\n loggingOption = option;\n };\n}\n"]}
1
+ {"version":3,"file":"GLUtils.js","sourceRoot":"","sources":["../src/GLUtils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAA6B,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE5E;;GAEG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAA6B;IAC5D,kDAAkD;IAClD,IAAI,aAAa,GAAG,eAAe,CAAC,QAAQ,CAAC;IAE7C,EAAE,CAAC,gBAAgB,GAAG,CAAC,MAAuB,EAAQ,EAAE;QACtD,kEAAkE;QAClE,0DAA0D;QAC1D,IAAI,CAAC,aAAa,KAAK,CAAC,MAAM,EAAE;YAC9B,aAAa,GAAG,MAAM,CAAC;YACvB,OAAO;SACR;QAED,oBAAoB;QACpB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,eAAe,CAAC,QAAQ,EAAE;YAClD,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC1C,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,KAAK,CAAC,YAAY,EAAE;oBACrD,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;iBAChB;YACH,CAAC,CAAC,CAAC;YACH,aAAa,GAAG,MAAM,CAAC;YACvB,OAAO;SACR;QAED,mBAAmB;QACnB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,EAAE;YACzE,IAAI,OAAO,aAAa,KAAK,UAAU,IAAI,GAAG,KAAK,kBAAkB,EAAE;gBACrE,OAAO;aACR;YAED,EAAE,CAAC,GA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M,EAAE,CAAC,CAAC;iBACtC;gBACD,IAAI,aAAa,GAAG,eAAe,CAAC,UAAU,IAAI,GAAG,KAAK,UAAU,EAAE;oBACpE,2DAA2D;oBAC3D,oCAAoC;oBACpC,MAAM,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBAE7C,IAAI,KAAK,IAAI,KAAK,KAAK,EAAE,CAAC,QAAQ,EAAE;wBAClC,8EAA8E;wBAC9E,OAAO,CAAC,GAAG,CAAC,yBAAyB,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;qBAChE;iBACF;gBACD,EAAE,CAAC,GAAG,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC;gBAC5B,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,aAAa,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import GLErrors from './GLErrors';\nimport { ExpoWebGLRenderingContext, GLLoggingOption } from './GLView.types';\n\n/**\n * Maximum length of the strings printed to the console.\n */\nconst MAX_STRING_LENGTH = 20;\n\n/**\n * Sets up `__expoSetLogging` method providing some logging options useful when debugging GL calls.\n */\nexport function configureLogging(gl: ExpoWebGLRenderingContext): void {\n // Enable/disable logging of all GL function calls\n let loggingOption = GLLoggingOption.DISABLED;\n\n gl.__expoSetLogging = (option: GLLoggingOption): void => {\n // If boolean values are the same, just change the internal value,\n // there is no need to wrap/unwrap functions in this case.\n if (!loggingOption === !option) {\n loggingOption = option;\n return;\n }\n\n // Turn off logging.\n if (!option || option === GLLoggingOption.DISABLED) {\n Object.entries(gl).forEach(([key, value]) => {\n if (typeof value === 'function' && value.__logWrapper) {\n delete gl[key];\n }\n });\n loggingOption = option;\n return;\n }\n\n // Turn on logging.\n Object.entries(Object.getPrototypeOf(gl)).forEach(([key, originalValue]) => {\n if (typeof originalValue !== 'function' || key === '__expoSetLogging') {\n return;\n }\n\n gl[key] = (...args) => {\n if (loggingOption & GLLoggingOption.METHOD_CALLS) {\n const params = args.map((arg) => {\n // If the type is `number`, then try to find name of the constant that has such value,\n // so it's easier to read these logs. In some cases it might be misleading\n // if the parameter is for example a width or height, so the number is still logged.\n if (loggingOption & GLLoggingOption.RESOLVE_CONSTANTS && typeof arg === 'number') {\n for (const prop in gl) {\n if (gl[prop] === arg) {\n return `${arg} (${prop})`;\n }\n }\n }\n\n // Truncate strings so they don't produce too much output and don't block the bridge.\n // It mostly applies to shaders which might be very long...\n if (loggingOption & GLLoggingOption.TRUNCATE_STRINGS && typeof arg === 'string') {\n if (arg.length > MAX_STRING_LENGTH) {\n const lastIndex = arg.lastIndexOf(' ', MAX_STRING_LENGTH);\n return arg.substr(0, lastIndex >= 0 ? lastIndex : MAX_STRING_LENGTH) + '...';\n }\n }\n\n // Just return the parameter as a string.\n return '' + arg;\n });\n console.log(`ExpoGL: ${key}(${params.join(', ')})`);\n }\n\n const result = originalValue.apply(gl, args);\n\n if (loggingOption & GLLoggingOption.METHOD_CALLS) {\n console.log(`ExpoGL: = ${result}`);\n }\n if (loggingOption & GLLoggingOption.GET_ERRORS && key !== 'getError') {\n // @ts-ignore We need to call into the original `getError`.\n // eslint-disable-next-line no-proto\n const error = gl.__proto__.getError.call(gl);\n\n if (error && error !== gl.NO_ERROR) {\n // `console.error` would cause a red screen, so let's just log with red color.\n console.log(`\\x1b[31mExpoGL: Error ${GLErrors[error]}\\x1b[0m`);\n }\n }\n gl[key].__logWrapper = true;\n return result;\n };\n });\n\n loggingOption = option;\n };\n}\n"]}
package/build/GLView.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentOrHandle, SurfaceCreateEvent, GLSnapshot, ExpoWebGLRenderingContext, SnapshotOptions, BaseGLViewProps } from './GLView.types';
3
+ export interface WebGLObject {
4
+ id: number;
5
+ }
3
6
  export declare type GLViewProps = {
4
7
  /**
5
8
  * Called when the OpenGL context is created, with the context object as a parameter. The context
@@ -26,6 +29,7 @@ export declare class GLView extends React.Component<GLViewProps> {
26
29
  static createContextAsync(): Promise<ExpoWebGLRenderingContext>;
27
30
  static destroyContextAsync(exgl?: ExpoWebGLRenderingContext | number): Promise<boolean>;
28
31
  static takeSnapshotAsync(exgl?: ExpoWebGLRenderingContext | number, options?: SnapshotOptions): Promise<GLSnapshot>;
32
+ static getWorkletContext: (contextId: number) => ExpoWebGLRenderingContext | undefined;
29
33
  nativeRef: ComponentOrHandle;
30
34
  exglCtxId?: number;
31
35
  render(): JSX.Element;
@@ -36,12 +40,3 @@ export declare class GLView extends React.Component<GLViewProps> {
36
40
  destroyObjectAsync(glObject: WebGLObject): Promise<boolean>;
37
41
  takeSnapshotAsync(options?: SnapshotOptions): Promise<GLSnapshot>;
38
42
  }
39
- declare type WebGLObjectId = any;
40
- export declare class WebGLObject {
41
- id: WebGLObjectId;
42
- constructor(id: WebGLObjectId);
43
- toString(): string;
44
- }
45
- declare class WebGLTexture extends WebGLObject {
46
- }
47
- export {};
package/build/GLView.js CHANGED
@@ -2,7 +2,6 @@ import { NativeModulesProxy, UnavailabilityError, requireNativeViewManager, Code
2
2
  import * as React from 'react';
3
3
  import { Platform, View, findNodeHandle } from 'react-native';
4
4
  import { configureLogging } from './GLUtils';
5
- const packageJSON = require('../package.json');
6
5
  const { ExponentGLObjectManager, ExponentGLViewManager } = NativeModulesProxy;
7
6
  const NativeView = requireNativeViewManager('ExponentGLView');
8
7
  /**
@@ -25,6 +24,22 @@ export class GLView extends React.Component {
25
24
  const exglCtxId = getContextId(exgl);
26
25
  return ExponentGLObjectManager.takeSnapshotAsync(exglCtxId, options);
27
26
  }
27
+ static getWorkletContext = (function () {
28
+ try {
29
+ // reanimated needs to be imported before any workletized code
30
+ // is created, but we don't want to make it dependency on expo-gl.
31
+ require('react-native-reanimated');
32
+ return (contextId) => {
33
+ 'worklet';
34
+ return global.__EXGLContexts?.[String(contextId)];
35
+ };
36
+ }
37
+ catch {
38
+ return () => {
39
+ throw new Error('Worklet runtime is not available');
40
+ };
41
+ }
42
+ })();
28
43
  nativeRef = null;
29
44
  exglCtxId;
30
45
  render() {
@@ -69,7 +84,7 @@ export class GLView extends React.Component {
69
84
  }
70
85
  const cameraTag = findNodeHandle(cameraRefOrHandle);
71
86
  const { exglObjId } = await ExponentGLObjectManager.createCameraTextureAsync(exglCtxId, cameraTag);
72
- return new WebGLTexture(exglObjId);
87
+ return { id: exglObjId };
73
88
  }
74
89
  async destroyObjectAsync(glObject) {
75
90
  if (!ExponentGLObjectManager.destroyObjectAsync) {
@@ -86,311 +101,20 @@ export class GLView extends React.Component {
86
101
  }
87
102
  }
88
103
  GLView.NativeView = NativeView;
89
- // JavaScript WebGL types to wrap around native objects
90
- class WebGLRenderingContext {
91
- __exglCtxId;
92
- }
93
- class WebGL2RenderingContext extends WebGLRenderingContext {
94
- }
95
- const idToObject = {};
96
- export class WebGLObject {
97
- id;
98
- constructor(id) {
99
- if (idToObject[id]) {
100
- throw new Error(`WebGL object with underlying EXGLObjectId '${id}' already exists!`);
101
- }
102
- this.id = id; // Native GL object id
103
- }
104
- toString() {
105
- return `[${this.constructor.name} ${this.id}]`;
106
- }
107
- }
108
- const wrapObject = (type, id) => {
109
- const found = idToObject[id];
110
- if (found) {
111
- return found;
112
- }
113
- return (idToObject[id] = new type(id));
114
- };
115
- const objectId = (obj) => obj && obj.id;
116
- class WebGLBuffer extends WebGLObject {
117
- }
118
- class WebGLFramebuffer extends WebGLObject {
119
- }
120
- class WebGLProgram extends WebGLObject {
121
- }
122
- class WebGLRenderbuffer extends WebGLObject {
123
- }
124
- class WebGLShader extends WebGLObject {
125
- }
126
- class WebGLTexture extends WebGLObject {
127
- }
128
- class WebGLUniformLocation {
129
- id;
130
- constructor(id) {
131
- this.id = id; // Native GL object id
132
- }
133
- toString() {
134
- return `[${this.constructor.name} ${this.id}]`;
135
- }
136
- }
137
- class WebGLActiveInfo {
138
- name;
139
- size;
140
- type;
141
- constructor(obj) {
142
- Object.assign(this, obj);
143
- }
144
- toString() {
145
- return `[${this.constructor.name} ${JSON.stringify(this)}]`;
146
- }
147
- }
148
- class WebGLShaderPrecisionFormat {
149
- rangeMin;
150
- rangeMax;
151
- precision;
152
- constructor(obj) {
153
- Object.assign(this, obj);
154
- }
155
- toString() {
156
- return `[${this.constructor.name} ${JSON.stringify(this)}]`;
157
- }
158
- }
159
- // WebGL2 classes
160
- class WebGLQuery extends WebGLObject {
161
- }
162
- class WebGLSampler extends WebGLObject {
163
- }
164
- class WebGLSync extends WebGLObject {
165
- }
166
- class WebGLTransformFeedback extends WebGLObject {
167
- }
168
- class WebGLVertexArrayObject extends WebGLObject {
169
- }
170
- // Many functions need wrapping/unwrapping of arguments and return value. We handle each case
171
- // specifically so we can write the tightest code for better performance.
172
- const wrapMethods = (gl) => {
173
- const wrap = (methodNames, wrapper) => (Array.isArray(methodNames) ? methodNames : [methodNames]).forEach((methodName) => (gl[methodName] = wrapper(gl[methodName])));
174
- // We can be slow in `gl.getParameter(...)` since it's a blocking call anyways
175
- const getParameterTypes = {
176
- [gl.ARRAY_BUFFER_BINDING]: WebGLBuffer,
177
- [gl.COPY_READ_BUFFER_BINDING]: WebGLBuffer,
178
- [gl.COPY_WRITE_BUFFER_BINDING]: WebGLBuffer,
179
- [gl.CURRENT_PROGRAM]: WebGLProgram,
180
- [gl.DRAW_FRAMEBUFFER_BINDING]: WebGLFramebuffer,
181
- [gl.ELEMENT_ARRAY_BUFFER_BINDING]: WebGLBuffer,
182
- [gl.READ_FRAMEBUFFER_BINDING]: WebGLFramebuffer,
183
- [gl.RENDERBUFFER_BINDING]: WebGLRenderbuffer,
184
- [gl.SAMPLER_BINDING]: WebGLSampler,
185
- [gl.TEXTURE_BINDING_2D_ARRAY]: WebGLTexture,
186
- [gl.TEXTURE_BINDING_2D]: WebGLTexture,
187
- [gl.TEXTURE_BINDING_3D]: WebGLTexture,
188
- [gl.TEXTURE_BINDING_CUBE_MAP]: WebGLTexture,
189
- [gl.TRANSFORM_FEEDBACK_BINDING]: WebGLTransformFeedback,
190
- [gl.TRANSFORM_FEEDBACK_BUFFER_BINDING]: WebGLBuffer,
191
- [gl.UNIFORM_BUFFER_BINDING]: WebGLBuffer,
192
- [gl.VERTEX_ARRAY_BINDING]: WebGLVertexArrayObject,
193
- };
194
- wrap('getParameter', (orig) => (pname) => {
195
- let ret = orig.call(gl, pname);
196
- if (pname === gl.VERSION) {
197
- // Wrap native version name
198
- ret = `WebGL 2.0 (Expo-${Platform.OS}-${packageJSON.version}) (${ret})`;
199
- }
200
- const type = getParameterTypes[pname];
201
- return type ? wrapObject(type, ret) : ret;
202
- });
203
- // Buffers
204
- wrap('bindBuffer', (orig) => (target, buffer) => orig.call(gl, target, buffer && buffer.id));
205
- wrap('createBuffer', (orig) => () => wrapObject(WebGLBuffer, orig.call(gl)));
206
- wrap('deleteBuffer', (orig) => (buffer) => orig.call(gl, buffer && buffer.id));
207
- wrap('isBuffer', (orig) => (buffer) => buffer instanceof WebGLBuffer && orig.call(gl, buffer.id));
208
- // Framebuffers
209
- wrap('bindFramebuffer', (orig) => (target, framebuffer) => orig.call(gl, target, framebuffer && framebuffer.id));
210
- wrap('createFramebuffer', (orig) => () => wrapObject(WebGLFramebuffer, orig.call(gl)));
211
- wrap('deleteFramebuffer', (orig) => (framebuffer) => orig.call(gl, framebuffer && framebuffer.id));
212
- wrap('framebufferRenderbuffer', (orig) => (target, attachment, rbtarget, rb) => orig.call(gl, target, attachment, rbtarget, rb && rb.id));
213
- wrap('framebufferTexture2D', (orig) => (target, attachment, textarget, tex, level) => orig.call(gl, target, attachment, textarget, tex && tex.id, level));
214
- wrap('isFramebuffer', (orig) => (framebuffer) => framebuffer instanceof WebGLFramebuffer && orig.call(gl, framebuffer.id));
215
- wrap('framebufferTextureLayer', (orig) => (target, attachment, texture, level, layer) => {
216
- return orig.call(gl, target, attachment, objectId(texture), level, layer);
217
- });
218
- // Renderbuffers
219
- wrap('bindRenderbuffer', (orig) => (target, renderbuffer) => orig.call(gl, target, renderbuffer && renderbuffer.id));
220
- wrap('createRenderbuffer', (orig) => () => wrapObject(WebGLRenderbuffer, orig.call(gl)));
221
- wrap('deleteRenderbuffer', (orig) => (renderbuffer) => orig.call(gl, renderbuffer && renderbuffer.id));
222
- wrap('isRenderbuffer', (orig) => (renderbuffer) => renderbuffer instanceof WebGLRenderbuffer && orig.call(gl, renderbuffer.id));
223
- // Textures
224
- wrap('bindTexture', (orig) => (target, texture) => orig.call(gl, target, texture && texture.id));
225
- wrap('createTexture', (orig) => () => wrapObject(WebGLTexture, orig.call(gl)));
226
- wrap('deleteTexture', (orig) => (texture) => orig.call(gl, texture && texture.id));
227
- wrap('isTexture', (orig) => (texture) => texture instanceof WebGLTexture && orig.call(gl, texture.id));
228
- // Programs and shaders
229
- wrap('attachShader', (orig) => (program, shader) => orig.call(gl, program && program.id, shader && shader.id));
230
- wrap('bindAttribLocation', (orig) => (program, index, name) => orig.call(gl, program && program.id, index, name));
231
- wrap('compileShader', (orig) => (shader) => orig.call(gl, shader && shader.id));
232
- wrap('createProgram', (orig) => () => wrapObject(WebGLProgram, orig.call(gl)));
233
- wrap('createShader', (orig) => (type) => wrapObject(WebGLShader, orig.call(gl, type)));
234
- wrap('deleteProgram', (orig) => (program) => orig.call(gl, program && program.id));
235
- wrap('deleteShader', (orig) => (shader) => orig.call(gl, shader && shader.id));
236
- wrap('detachShader', (orig) => (program, shader) => orig.call(gl, program && program.id, shader && shader.id));
237
- wrap('getAttachedShaders', (orig) => (program) => orig.call(gl, program && program.id).map((id) => wrapObject(WebGLShader, id)));
238
- wrap('getProgramParameter', (orig) => (program, pname) => orig.call(gl, program && program.id, pname));
239
- wrap('getProgramInfoLog', (orig) => (program) => orig.call(gl, program && program.id));
240
- wrap('getShaderParameter', (orig) => (shader, pname) => orig.call(gl, shader && shader.id, pname));
241
- wrap('getShaderPrecisionFormat', (orig) => (shadertype, precisiontype) => new WebGLShaderPrecisionFormat(orig.call(gl, shadertype, precisiontype)));
242
- wrap('getShaderInfoLog', (orig) => (shader) => orig.call(gl, shader && shader.id));
243
- wrap('getShaderSource', (orig) => (shader) => orig.call(gl, shader && shader.id));
244
- wrap('linkProgram', (orig) => (program) => orig.call(gl, program && program.id));
245
- wrap('shaderSource', (orig) => (shader, source) => orig.call(gl, shader && shader.id, source));
246
- wrap('useProgram', (orig) => (program) => orig.call(gl, program && program.id));
247
- wrap('validateProgram', (orig) => (program) => orig.call(gl, program && program.id));
248
- wrap('isShader', (orig) => (shader) => shader instanceof WebGLShader && orig.call(gl, shader.id));
249
- wrap('isProgram', (orig) => (program) => program instanceof WebGLProgram && orig.call(gl, program.id));
250
- wrap('getFragDataLocation', (orig) => (program) => orig.call(gl, objectId(program)));
251
- // Uniforms and attributes
252
- wrap('getActiveAttrib', (orig) => (program, index) => new WebGLActiveInfo(orig.call(gl, program && program.id, index)));
253
- wrap('getActiveUniform', (orig) => (program, index) => new WebGLActiveInfo(orig.call(gl, program && program.id, index)));
254
- wrap('getAttribLocation', (orig) => (program, name) => orig.call(gl, program && program.id, name));
255
- wrap('getUniform', (orig) => (program, location) => orig.call(gl, program && program.id, location && location.id));
256
- wrap('getUniformLocation', (orig) => (program, name) => new WebGLUniformLocation(orig.call(gl, program && program.id, name)));
257
- wrap(['uniform1f', 'uniform1i', 'uniform1ui'], (orig) => (loc, x) => orig.call(gl, objectId(loc), x));
258
- wrap(['uniform2f', 'uniform2i', 'uniform2ui'], (orig) => (loc, x, y) => orig.call(gl, objectId(loc), x, y));
259
- wrap(['uniform3f', 'uniform3i', 'uniform3ui'], (orig) => (loc, x, y, z) => orig.call(gl, objectId(loc), x, y, z));
260
- wrap(['uniform4f', 'uniform4i', 'uniform4ui'], (orig) => (loc, x, y, z, w) => orig.call(gl, objectId(loc), x, y, z, w));
261
- wrap(['uniform1fv', 'uniform2fv', 'uniform3fv', 'uniform4fv'], (orig) => (loc, val) => orig.call(gl, objectId(loc), new Float32Array(val)));
262
- wrap(['uniform1iv', 'uniform2iv', 'uniform3iv', 'uniform4iv'], (orig) => (loc, val) => orig.call(gl, objectId(loc), new Int32Array(val)));
263
- wrap(['uniform1uiv', 'uniform2uiv', 'uniform3uiv', 'uniform4uiv'], (orig) => (loc, val) => orig.call(gl, objectId(loc), new Uint32Array(val)));
264
- wrap([
265
- 'uniformMatrix2fv',
266
- 'uniformMatrix3fv',
267
- 'uniformMatrix4fv',
268
- 'uniformMatrix3x2fv',
269
- 'uniformMatrix4x2fv',
270
- 'uniformMatrix2x3fv',
271
- 'uniformMatrix4x3fv',
272
- 'uniformMatrix2x4fv',
273
- 'uniformMatrix3x4fv',
274
- ], (orig) => (loc, transpose, val) => orig.call(gl, loc && loc.id, transpose, new Float32Array(val)));
275
- wrap(['vertexAttrib1fv', 'vertexAttrib2fv', 'vertexAttrib3fv', 'vertexAttrib4fv'], (orig) => (index, val) => orig.call(gl, index, new Float32Array(val)));
276
- wrap('vertexAttribI4iv', (orig) => (index, val) => orig.call(gl, index, new Int32Array(val)));
277
- wrap('vertexAttribI4uiv', (orig) => (index, val) => orig.call(gl, index, new Uint32Array(val)));
278
- // Query objects
279
- wrap('createQuery', (orig) => () => wrapObject(WebGLQuery, orig.call(gl)));
280
- wrap('deleteQuery', (orig) => (query) => orig.call(gl, objectId(query)));
281
- wrap('beginQuery', (orig) => (target, query) => orig.call(gl, target, objectId(query)));
282
- wrap('getQuery', (orig) => (target, pname) => {
283
- const id = orig.call(gl, target, pname);
284
- return id ? wrapObject(WebGLQuery, id) : id;
285
- });
286
- wrap('getQueryParameter', (orig) => (query, pname) => orig.call(gl, objectId(query), pname));
287
- // Samplers
288
- wrap('bindSampler', (orig) => (unit, sampler) => orig.call(gl, unit, objectId(sampler)));
289
- wrap('createSampler', (orig) => () => wrapObject(WebGLSampler, orig.call(gl)));
290
- wrap('deleteSampler', (orig) => (sampler) => orig.call(gl, objectId(sampler)));
291
- wrap('isSampler', (orig) => (sampler) => sampler instanceof WebGLSampler && orig.call(gl, sampler.id));
292
- wrap(['samplerParameteri', 'samplerParameterf'], (orig) => (sampler, pname, param) => {
293
- return orig.call(gl, objectId(sampler), pname, param);
294
- });
295
- wrap('getSamplerParameter', (orig) => (sampler, pname) => {
296
- return orig.call(gl, objectId(sampler), pname);
297
- });
298
- // Transform feedback
299
- wrap('bindTransformFeedback', (orig) => (target, transformFeedback) => {
300
- return orig.call(gl, target, objectId(transformFeedback));
301
- });
302
- wrap('createTransformFeedback', (orig) => () => wrapObject(WebGLTransformFeedback, orig.call(gl)));
303
- wrap('deleteTransformFeedback', (orig) => (transformFeedback) => {
304
- return orig.call(gl, objectId(transformFeedback));
305
- });
306
- wrap('transformFeedbackVaryings', (orig) => (program, varyings, bufferMode) => {
307
- return orig.call(gl, objectId(program), varyings, bufferMode);
308
- });
309
- wrap('getTransformFeedbackVarying', (orig) => (program, index) => {
310
- return new WebGLActiveInfo(orig.call(gl, objectId(program), index));
311
- });
312
- // Uniforms and attributes
313
- wrap(['bindBufferBase', 'bindBufferRange'], (orig) => (target, index, buffer, ...rest) => {
314
- return orig.call(gl, target, index, objectId(buffer), ...rest);
315
- });
316
- wrap('getUniformIndices', (orig) => (program, uniformNames) => {
317
- // according to WebGL2 specs, it returns Array instead of Uint32Array
318
- const uintArray = orig.call(gl, objectId(program), uniformNames);
319
- return Array.from(uintArray);
320
- });
321
- wrap('getActiveUniforms', (orig) => (program, uniformIndices, pname) => {
322
- // according to WebGL2 specs, it returns Array instead of Int32Array
323
- const intArray = orig.call(gl, objectId(program), new Uint32Array(uniformIndices), pname);
324
- const boolResult = pname === gl.UNIFORM_IS_ROW_MAJOR;
325
- const arr = Array.from(intArray);
326
- return boolResult ? arr.map((val) => !!val) : arr;
327
- });
328
- wrap('getUniformBlockIndex', (orig) => (program, uniformBlockName) => orig.call(gl, objectId(program), uniformBlockName));
329
- wrap('getActiveUniformBlockName', (orig) => (program, uniformBlockIndex) => orig.call(gl, objectId(program), uniformBlockIndex));
330
- wrap('uniformBlockBinding', (orig) => (program, uniformBlockIndex, uniformBlockBinding) => {
331
- return orig.call(gl, objectId(program), uniformBlockIndex, uniformBlockBinding);
332
- });
333
- // Vertex array objects
334
- wrap('bindVertexArray', (orig) => (vertexArray) => orig.call(gl, vertexArray && vertexArray.id));
335
- wrap('createVertexArray', (orig) => () => wrapObject(WebGLVertexArrayObject, orig.call(gl)));
336
- wrap('deleteVertexArray', (orig) => (vertexArray) => orig.call(gl, vertexArray && vertexArray.id));
337
- wrap('isVertexArray', (orig) => (vertexArray) => vertexArray instanceof WebGLVertexArrayObject && orig.call(gl, vertexArray.id));
338
- };
339
- // Get the GL interface from an EXGLContextID and do JS-side setup
104
+ // Get the GL interface from an EXGLContextId
340
105
  const getGl = (exglCtxId) => {
341
106
  if (!global.__EXGLContexts) {
342
107
  throw new CodedError('ERR_GL_NOT_AVAILABLE', 'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)');
343
108
  }
344
- const gl = global.__EXGLContexts[exglCtxId];
345
- gl.__exglCtxId = exglCtxId;
346
- delete global.__EXGLContexts[exglCtxId];
347
- // determine the prototype to use, depending on OpenGL ES version
348
- const glesVersion = gl.getParameter(gl.VERSION);
349
- const supportsWebGL2 = parseFloat(glesVersion.split(/[^\d.]+/g).join(' ')) >= 3.0;
350
- const prototype = supportsWebGL2
351
- ? global.WebGL2RenderingContext.prototype
352
- : global.WebGLRenderingContext.prototype;
353
- if (Object.setPrototypeOf) {
354
- Object.setPrototypeOf(gl, prototype);
355
- }
356
- else {
357
- // Delete this path when we are competely sure we're using modern JSC on Android. iOS 9+
358
- // supports Object.setPrototypeOf.
359
- gl.__proto__ = prototype; // eslint-disable-line no-proto
360
- }
361
- wrapMethods(gl);
362
- // No canvas yet...
363
- gl.canvas = null;
364
- // Drawing buffer width/height
365
- // TODO(nikki): Make this dynamic
366
- const viewport = gl.getParameter(gl.VIEWPORT);
367
- gl.drawingBufferWidth = viewport[2];
368
- gl.drawingBufferHeight = viewport[3];
109
+ const gl = global.__EXGLContexts[String(exglCtxId)];
369
110
  configureLogging(gl);
370
111
  return gl;
371
112
  };
372
113
  const getContextId = (exgl) => {
373
- const exglCtxId = exgl && typeof exgl === 'object' ? exgl.__exglCtxId : exgl;
114
+ const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;
374
115
  if (!exglCtxId || typeof exglCtxId !== 'number') {
375
116
  throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);
376
117
  }
377
118
  return exglCtxId;
378
119
  };
379
- global.WebGLRenderingContext = WebGLRenderingContext;
380
- global.WebGL2RenderingContext = WebGL2RenderingContext;
381
- global.WebGLObject = WebGLObject;
382
- global.WebGLBuffer = WebGLBuffer;
383
- global.WebGLFramebuffer = WebGLFramebuffer;
384
- global.WebGLProgram = WebGLProgram;
385
- global.WebGLRenderbuffer = WebGLRenderbuffer;
386
- global.WebGLShader = WebGLShader;
387
- global.WebGLTexture = WebGLTexture;
388
- global.WebGLUniformLocation = WebGLUniformLocation;
389
- global.WebGLActiveInfo = WebGLActiveInfo;
390
- global.WebGLShaderPrecisionFormat = WebGLShaderPrecisionFormat;
391
- global.WebGLQuery = WebGLQuery;
392
- global.WebGLSampler = WebGLSampler;
393
- global.WebGLSync = WebGLSync;
394
- global.WebGLTransformFeedback = WebGLTransformFeedback;
395
- global.WebGLVertexArrayObject = WebGLVertexArrayObject;
396
120
  //# sourceMappingURL=GLView.js.map