@symbiote-native/gl 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +38 -2
- package/build/angular/gl-view/index.d.ts +18 -0
- package/build/angular/gl-view/index.js +87 -0
- package/build/angular/index.d.ts +2 -0
- package/build/angular/index.js +3 -0
- package/build/core/constants.d.ts +4 -0
- package/build/core/constants.js +4 -0
- package/build/core/gl-context.d.ts +13 -0
- package/build/core/gl-context.js +54 -0
- package/build/core/gl-errors.d.ts +1 -0
- package/build/core/gl-errors.js +8 -0
- package/build/core/gl-utils.d.ts +5 -0
- package/build/core/gl-utils.js +84 -0
- package/build/core/gl-view.d.ts +16 -0
- package/build/core/gl-view.js +99 -0
- package/build/core/index.d.ts +6 -0
- package/build/core/index.js +5 -0
- package/build/core/native-module.d.ts +15 -0
- package/build/core/native-module.js +3 -0
- package/build/core/types.d.ts +75 -0
- package/build/core/types.js +13 -0
- package/build/core/worklet-context-manager.d.ts +6 -0
- package/build/core/worklet-context-manager.js +34 -0
- package/build/react/gl-view.d.ts +8 -0
- package/build/react/gl-view.js +6 -0
- package/build/react/index.d.ts +3 -0
- package/build/react/index.js +3 -0
- package/build/solid/gl-view.d.ts +13 -0
- package/build/solid/gl-view.js +4 -0
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +3 -0
- package/build/svelte/gl-view.svelte +19 -0
- package/build/svelte/gl-view.svelte.d.ts +9 -0
- package/build/svelte/index.d.ts +2 -0
- package/build/svelte/index.js +3 -0
- package/build/vue/gl-view.d.ts +2 -0
- package/build/vue/gl-view.js +4 -0
- package/build/vue/index.d.ts +2 -0
- package/build/vue/index.js +3 -0
- package/build-ngc/angular/gl-view/index.d.ts +21 -0
- package/build-ngc/angular/gl-view/index.js +46 -0
- package/build-ngc/angular/gl-view/index.js.map +1 -0
- package/build-ngc/angular/index.d.ts +2 -0
- package/build-ngc/angular/index.js +4 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/core/constants.d.ts +4 -0
- package/build-ngc/core/constants.js +5 -0
- package/build-ngc/core/constants.js.map +1 -0
- package/build-ngc/core/gl-context.d.ts +13 -0
- package/build-ngc/core/gl-context.js +55 -0
- package/build-ngc/core/gl-context.js.map +1 -0
- package/build-ngc/core/gl-errors.d.ts +1 -0
- package/build-ngc/core/gl-errors.js +9 -0
- package/build-ngc/core/gl-errors.js.map +1 -0
- package/build-ngc/core/gl-utils.d.ts +5 -0
- package/build-ngc/core/gl-utils.js +85 -0
- package/build-ngc/core/gl-utils.js.map +1 -0
- package/build-ngc/core/gl-view.d.ts +16 -0
- package/build-ngc/core/gl-view.js +100 -0
- package/build-ngc/core/gl-view.js.map +1 -0
- package/build-ngc/core/index.d.ts +6 -0
- package/build-ngc/core/index.js +6 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/native-module.d.ts +15 -0
- package/build-ngc/core/native-module.js +4 -0
- package/build-ngc/core/native-module.js.map +1 -0
- package/build-ngc/core/types.d.ts +75 -0
- package/build-ngc/core/types.js +14 -0
- package/build-ngc/core/types.js.map +1 -0
- package/build-ngc/core/worklet-context-manager.d.ts +6 -0
- package/build-ngc/core/worklet-context-manager.js +35 -0
- package/build-ngc/core/worklet-context-manager.js.map +1 -0
- package/native-link.json +12 -0
- package/package.json +145 -3
- package/src/angular/gl-view/index.ts +50 -0
- package/src/angular/index.ts +4 -0
- package/src/core/constants.ts +6 -0
- package/src/core/gl-context.ts +74 -0
- package/src/core/gl-errors.ts +8 -0
- package/src/core/gl-utils.ts +97 -0
- package/src/core/gl-view.ts +143 -0
- package/src/core/index.ts +21 -0
- package/src/core/native-module.ts +18 -0
- package/src/core/types.ts +95 -0
- package/src/core/worklet-context-manager.ts +42 -0
- package/src/react/gl-view.ts +14 -0
- package/src/react/index.ts +5 -0
- package/src/solid/gl-view.ts +6 -0
- package/src/solid/index.ts +4 -0
- package/src/svelte/gl-view.svelte +19 -0
- package/src/svelte/index.ts +4 -0
- package/src/svelte/svelte-ambient.d.ts +3 -0
- package/src/svelte/svelte-compile.test-helper.ts +6 -0
- package/src/vue/gl-view.ts +5 -0
- package/src/vue/index.ts +4 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { IAccessibilityProps, IAriaProps, IResponderProps } from '@symbiote-native/components';
|
|
2
|
+
import type { IStyleProp, ISymbioteEvent, ISymbioteNode, IViewStyle } from '@symbiote-native/engine';
|
|
3
|
+
export type IGLObject = {
|
|
4
|
+
id: number;
|
|
5
|
+
};
|
|
6
|
+
export type IGLSurfaceCreateEvent = {
|
|
7
|
+
nativeEvent: {
|
|
8
|
+
exglCtxId: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type IGLSnapshotOptions = {
|
|
12
|
+
/** @default false */
|
|
13
|
+
flip?: boolean;
|
|
14
|
+
/** Defaults to the framebuffer shown in the view, or the current one of a headless context */
|
|
15
|
+
framebuffer?: WebGLFramebuffer;
|
|
16
|
+
/** Passed to `glReadPixels` */
|
|
17
|
+
rect?: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
/** PNG is lossless but slower, iOS writes a PNG instead of WebP. @default 'jpeg' */
|
|
24
|
+
format?: 'jpeg' | 'png' | 'webp';
|
|
25
|
+
/** From `0` (most compressed) to `1.0` (none). @default 1.0 */
|
|
26
|
+
compress?: number;
|
|
27
|
+
};
|
|
28
|
+
export type IGLSnapshot = {
|
|
29
|
+
uri: string | Blob | null;
|
|
30
|
+
/** Same as `uri`, which makes a snapshot usable in `texImage2D` */
|
|
31
|
+
localUri: string;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
};
|
|
35
|
+
export type IExpoWebGLRenderingContext = WebGL2RenderingContext & {
|
|
36
|
+
contextId: number;
|
|
37
|
+
endFrameEXP(): void;
|
|
38
|
+
flushEXP(): void;
|
|
39
|
+
__expoSetLogging(option: GLLoggingOption): void;
|
|
40
|
+
};
|
|
41
|
+
/** A native tag, or the host node of a view such as a camera */
|
|
42
|
+
export type IGLNodeOrTag = number | ISymbioteNode | null;
|
|
43
|
+
export type IGLViewProps = IAccessibilityProps & IAriaProps & IResponderProps & {
|
|
44
|
+
style?: IStyleProp<IViewStyle>;
|
|
45
|
+
testID?: string;
|
|
46
|
+
nativeID?: string;
|
|
47
|
+
onLayout?: (event: ISymbioteEvent) => void;
|
|
48
|
+
/** Called with the context once the surface exists */
|
|
49
|
+
onContextCreate(gl: IExpoWebGLRenderingContext): void;
|
|
50
|
+
/** Multisampling, `0` turns it off. @default 4 @platform ios */
|
|
51
|
+
msaaSamples?: number;
|
|
52
|
+
/** Lets the Reanimated worklet thread use the `gl` object. @default false */
|
|
53
|
+
enableExperimentalWorkletSupport?: boolean;
|
|
54
|
+
};
|
|
55
|
+
export declare enum GLLoggingOption {
|
|
56
|
+
DISABLED = 0,
|
|
57
|
+
/** Logs calls, their parameters and results */
|
|
58
|
+
METHOD_CALLS = 1,
|
|
59
|
+
/** Calls `getError` after each call, which blocks and slows drawing down */
|
|
60
|
+
GET_ERRORS = 2,
|
|
61
|
+
/** Prints the name of the constant a numeric parameter holds */
|
|
62
|
+
RESOLVE_CONSTANTS = 4,
|
|
63
|
+
/** Cuts long strings such as shaders */
|
|
64
|
+
TRUNCATE_STRINGS = 8,
|
|
65
|
+
ALL = 15
|
|
66
|
+
}
|
|
67
|
+
/** What a ref to the view hands out */
|
|
68
|
+
export type IGLViewHandle = {
|
|
69
|
+
/** The id of the context of the view, `undefined` until the surface exists */
|
|
70
|
+
readonly exglCtxId: number | undefined;
|
|
71
|
+
createCameraTextureAsync(camera: IGLNodeOrTag): Promise<WebGLTexture>;
|
|
72
|
+
destroyObjectAsync(glObject: IGLObject): Promise<boolean>;
|
|
73
|
+
/** A snapshot of the context of this view */
|
|
74
|
+
takeSnapshotAsync(options?: IGLSnapshotOptions): Promise<IGLSnapshot>;
|
|
75
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export var GLLoggingOption;
|
|
2
|
+
(function (GLLoggingOption) {
|
|
3
|
+
GLLoggingOption[GLLoggingOption["DISABLED"] = 0] = "DISABLED";
|
|
4
|
+
/** Logs calls, their parameters and results */
|
|
5
|
+
GLLoggingOption[GLLoggingOption["METHOD_CALLS"] = 1] = "METHOD_CALLS";
|
|
6
|
+
/** Calls `getError` after each call, which blocks and slows drawing down */
|
|
7
|
+
GLLoggingOption[GLLoggingOption["GET_ERRORS"] = 2] = "GET_ERRORS";
|
|
8
|
+
/** Prints the name of the constant a numeric parameter holds */
|
|
9
|
+
GLLoggingOption[GLLoggingOption["RESOLVE_CONSTANTS"] = 4] = "RESOLVE_CONSTANTS";
|
|
10
|
+
/** Cuts long strings such as shaders */
|
|
11
|
+
GLLoggingOption[GLLoggingOption["TRUNCATE_STRINGS"] = 8] = "TRUNCATE_STRINGS";
|
|
12
|
+
GLLoggingOption[GLLoggingOption["ALL"] = 15] = "ALL";
|
|
13
|
+
})(GLLoggingOption || (GLLoggingOption = {}));
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAyEA,MAAM,CAAN,IAAY,eAWX;AAXD,WAAY,eAAe;IACzB,6DAAY,CAAA;IACZ,+CAA+C;IAC/C,qEAAgB,CAAA;IAChB,4EAA4E;IAC5E,iEAAc,CAAA;IACd,gEAAgE;IAChE,+EAAqB,CAAA;IACrB,wCAAwC;IACxC,6EAAoB,CAAA;IACpB,oDAAsE,CAAA;AACxE,CAAC,EAXW,eAAe,KAAf,eAAe,QAW1B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IExpoWebGLRenderingContext } from './types';
|
|
2
|
+
export type IWorkletContextManager = {
|
|
3
|
+
getContext(contextId: number): IExpoWebGLRenderingContext | undefined;
|
|
4
|
+
unregister?(contextId: number): void;
|
|
5
|
+
};
|
|
6
|
+
export declare function createWorkletContextManager(): IWorkletContextManager;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GL_CONTEXTS_GLOBAL } from './constants';
|
|
2
|
+
function isRunOnUI(value) {
|
|
3
|
+
return typeof value === 'function';
|
|
4
|
+
}
|
|
5
|
+
// Reanimated stays optional, and an import of it in a try block in the module that also holds the
|
|
6
|
+
// view breaks with `inlineRequires`, so the manager lives in its own file
|
|
7
|
+
export function createWorkletContextManager() {
|
|
8
|
+
try {
|
|
9
|
+
// Reanimated has to load before any workletized code is created
|
|
10
|
+
const reanimated = require('react-native-reanimated');
|
|
11
|
+
const runOnUI = Reflect.get(Object(reanimated), 'runOnUI');
|
|
12
|
+
if (!isRunOnUI(runOnUI))
|
|
13
|
+
throw new Error('react-native-reanimated has no runOnUI');
|
|
14
|
+
return {
|
|
15
|
+
getContext: contextId => {
|
|
16
|
+
'worklet';
|
|
17
|
+
return Reflect.get(Object(Reflect.get(globalThis, GL_CONTEXTS_GLOBAL)), String(contextId));
|
|
18
|
+
},
|
|
19
|
+
unregister: contextId => {
|
|
20
|
+
runOnUI(id => {
|
|
21
|
+
'worklet';
|
|
22
|
+
Reflect.deleteProperty(Object(Reflect.get(globalThis, GL_CONTEXTS_GLOBAL)), String(id));
|
|
23
|
+
})(contextId);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return {
|
|
29
|
+
getContext: () => {
|
|
30
|
+
throw new Error('Worklet runtime is not available');
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=worklet-context-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worklet-context-manager.js","sourceRoot":"","sources":["../../src/core/worklet-context-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAUjD,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED,kGAAkG;AAClG,0EAA0E;AAC1E,MAAM,UAAU,2BAA2B;IACzC,IAAI,CAAC;QACH,gEAAgE;QAChE,MAAM,UAAU,GAAY,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QACnF,OAAO;YACL,UAAU,EAAE,SAAS,CAAC,EAAE;gBACtB,SAAS,CAAC;gBACV,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YAC7F,CAAC;YACD,UAAU,EAAE,SAAS,CAAC,EAAE;gBACtB,OAAO,CAAC,EAAE,CAAC,EAAE;oBACX,SAAS,CAAC;oBACV,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC1F,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,UAAU,EAAE,GAAG,EAAE;gBACf,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACtD,CAAC;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/native-link.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,148 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiote-native/gl",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "expo-gl wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, Svelte, Solid, and Angular adapters. A GLView that gives a WebGL context to draw into, headless contexts and snapshots.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/OneEyed1366/symbiote-native.git",
|
|
9
|
+
"directory": "packages/gl"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/OneEyed1366/symbiote-native/tree/master/packages/gl#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/OneEyed1366/symbiote-native/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": "Andrey Prokopenko <psevdoproger@gmail.com>",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react-native",
|
|
18
|
+
"symbiote-native",
|
|
19
|
+
"expo-gl",
|
|
20
|
+
"react",
|
|
21
|
+
"vue",
|
|
22
|
+
"svelte",
|
|
23
|
+
"solid",
|
|
24
|
+
"angular",
|
|
25
|
+
"webgl",
|
|
26
|
+
"opengl"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./build/core/index.js",
|
|
30
|
+
"module": "./build/core/index.js",
|
|
31
|
+
"types": "./build/core/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./build/core/index.d.ts",
|
|
35
|
+
"default": "./build/core/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./vue": {
|
|
38
|
+
"types": "./build/vue/index.d.ts",
|
|
39
|
+
"default": "./build/vue/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./react": {
|
|
42
|
+
"types": "./build/react/index.d.ts",
|
|
43
|
+
"default": "./build/react/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./svelte": "./src/svelte/index.ts",
|
|
46
|
+
"./solid": {
|
|
47
|
+
"types": "./build/solid/index.d.ts",
|
|
48
|
+
"default": "./build/solid/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./angular": {
|
|
51
|
+
"types": "./build-ngc/angular/index.d.ts",
|
|
52
|
+
"react-native": "./build-ngc/angular/index.js",
|
|
53
|
+
"default": "./src/angular/index.ts"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"src",
|
|
58
|
+
"build",
|
|
59
|
+
"build-ngc",
|
|
60
|
+
"native-link.json",
|
|
61
|
+
"!src/**/*.test.*",
|
|
62
|
+
"!src/**/*.spec.*",
|
|
63
|
+
"!src/**/*.detox.*"
|
|
64
|
+
],
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"expo-gl": "57.0.2",
|
|
70
|
+
"expo-modules-core": "57.0.20",
|
|
71
|
+
"@symbiote-native/components": "3.1.4"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"@angular/core": ">=20",
|
|
75
|
+
"@vue/runtime-core": "^3.5.13",
|
|
76
|
+
"react": ">=19.0.0",
|
|
77
|
+
"react-native": ">=0.86",
|
|
78
|
+
"solid-js": ">=1.9.0",
|
|
79
|
+
"svelte": ">=5.56.0",
|
|
80
|
+
"vue": ">=3.5.0",
|
|
81
|
+
"@symbiote-native/engine": "^1.5.0",
|
|
82
|
+
"@symbiote-native/angular": "^3.2.0",
|
|
83
|
+
"@symbiote-native/react": "^3.2.0",
|
|
84
|
+
"@symbiote-native/solid": "^3.1.0",
|
|
85
|
+
"@symbiote-native/svelte": "^3.1.0",
|
|
86
|
+
"@symbiote-native/vue": "^3.2.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependenciesMeta": {
|
|
89
|
+
"@symbiote-native/angular": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"@symbiote-native/react": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@symbiote-native/solid": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@symbiote-native/svelte": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@symbiote-native/vue": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"@angular/core": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"@vue/runtime-core": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"react": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"solid-js": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"svelte": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"vue": {
|
|
120
|
+
"optional": true
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"devDependencies": {
|
|
124
|
+
"@angular/compiler": "~22.0.8",
|
|
125
|
+
"@angular/compiler-cli": "~22.0.8",
|
|
126
|
+
"@angular/core": "~22.0.8",
|
|
127
|
+
"@types/node": "^26.0.0",
|
|
128
|
+
"@types/react": "^19.2.0",
|
|
129
|
+
"@vue/runtime-core": "^3.5.13",
|
|
130
|
+
"react": "19.2.3",
|
|
131
|
+
"solid-js": "^1.9.14",
|
|
132
|
+
"svelte": "^5.56.0",
|
|
133
|
+
"typescript": "~6.0.0",
|
|
134
|
+
"@symbiote-native/angular": "3.2.0",
|
|
135
|
+
"@symbiote-native/engine": "1.5.0",
|
|
136
|
+
"@symbiote-native/react": "3.2.0",
|
|
137
|
+
"@symbiote-native/test-utils": "0.4.6",
|
|
138
|
+
"@symbiote-native/svelte": "3.1.0",
|
|
139
|
+
"@symbiote-native/vue": "3.2.0",
|
|
140
|
+
"@symbiote-native/solid": "3.1.0"
|
|
141
|
+
},
|
|
142
|
+
"scripts": {
|
|
143
|
+
"typecheck": "tsc --build",
|
|
144
|
+
"clean": "rm -rf build-ngc",
|
|
145
|
+
"ng:build": "pnpm run clean && ngc -p tsconfig.angular.json",
|
|
146
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
147
|
+
}
|
|
6
148
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
|
2
|
+
import { DescriptorOutlet, NativeViewBase } from '@symbiote-native/angular';
|
|
3
|
+
import type { IDescriptor } from '@symbiote-native/components';
|
|
4
|
+
import { createGLView } from '../../core';
|
|
5
|
+
import type { IGLViewProps } from '../../core';
|
|
6
|
+
|
|
7
|
+
// One list is the inputs of the component and the props it hands to the native view
|
|
8
|
+
const GL_VIEW_INPUTS = [
|
|
9
|
+
'onContextCreate',
|
|
10
|
+
'msaaSamples',
|
|
11
|
+
'enableExperimentalWorkletSupport',
|
|
12
|
+
] as const;
|
|
13
|
+
|
|
14
|
+
// Types the inputs for the template, the decorators that would do it are replaced by `inputs`
|
|
15
|
+
export interface GLView
|
|
16
|
+
extends Partial<Pick<IGLViewProps, (typeof GL_VIEW_INPUTS)[number]>> {}
|
|
17
|
+
|
|
18
|
+
/** Angular twin of `expo-gl`'s `GLView` */
|
|
19
|
+
@Component({
|
|
20
|
+
selector: 'GLView',
|
|
21
|
+
standalone: true,
|
|
22
|
+
imports: [DescriptorOutlet],
|
|
23
|
+
inputs: [...GL_VIEW_INPUTS],
|
|
24
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
25
|
+
template: `@if (descriptor; as node) {
|
|
26
|
+
<symbiote-descriptor-outlet [node]="node" />
|
|
27
|
+
}`,
|
|
28
|
+
})
|
|
29
|
+
export class GLView extends NativeViewBase {
|
|
30
|
+
private readonly view = createGLView(() => this.hostNode());
|
|
31
|
+
|
|
32
|
+
// The functions of the view are members of the component, a `@ViewChild` reaches them
|
|
33
|
+
readonly createCameraTextureAsync = this.view.handle.createCameraTextureAsync;
|
|
34
|
+
readonly destroyObjectAsync = this.view.handle.destroyObjectAsync;
|
|
35
|
+
readonly takeSnapshotAsync = this.view.handle.takeSnapshotAsync;
|
|
36
|
+
|
|
37
|
+
get exglCtxId(): number | undefined {
|
|
38
|
+
return this.view.handle.exglCtxId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected override readonly propNames = GL_VIEW_INPUTS;
|
|
42
|
+
|
|
43
|
+
protected override renderView(props: object): IDescriptor | null {
|
|
44
|
+
return this.view.render(props);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected override disposeView(): void {
|
|
48
|
+
this.view.dispose();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CodedError } from 'expo-modules-core';
|
|
2
|
+
import { GL_CONTEXTS_GLOBAL } from './constants';
|
|
3
|
+
import { configureLogging } from './gl-utils';
|
|
4
|
+
import { glNativeModule } from './native-module';
|
|
5
|
+
import type {
|
|
6
|
+
IExpoWebGLRenderingContext,
|
|
7
|
+
IGLSnapshot,
|
|
8
|
+
IGLSnapshotOptions,
|
|
9
|
+
} from './types';
|
|
10
|
+
import { createWorkletContextManager } from './worklet-context-manager';
|
|
11
|
+
|
|
12
|
+
const workletContextManager = createWorkletContextManager();
|
|
13
|
+
|
|
14
|
+
function isContext(value: unknown): value is IExpoWebGLRenderingContext {
|
|
15
|
+
return typeof value === 'object' && value !== null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The context of a worklet, `exgl` has to be created with worklet support */
|
|
19
|
+
export function getWorkletContext(contextId: number): IExpoWebGLRenderingContext | undefined {
|
|
20
|
+
'worklet';
|
|
21
|
+
return workletContextManager.getContext(contextId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function unregisterGLContext(exglCtxId: number): void {
|
|
25
|
+
const contexts: unknown = Reflect.get(globalThis, GL_CONTEXTS_GLOBAL);
|
|
26
|
+
if (contexts) Reflect.deleteProperty(Object(contexts), String(exglCtxId));
|
|
27
|
+
workletContextManager.unregister?.(exglCtxId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The GL interface of a context id the native side created */
|
|
31
|
+
export function getGl(exglCtxId: number): IExpoWebGLRenderingContext {
|
|
32
|
+
const contexts: unknown = Reflect.get(globalThis, GL_CONTEXTS_GLOBAL);
|
|
33
|
+
if (!contexts) {
|
|
34
|
+
throw new CodedError(
|
|
35
|
+
'ERR_GL_NOT_AVAILABLE',
|
|
36
|
+
'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const gl: unknown = Reflect.get(Object(contexts), String(exglCtxId));
|
|
40
|
+
if (!isContext(gl)) throw new Error(`There is no EXGLContext with id ${exglCtxId}`);
|
|
41
|
+
configureLogging(gl);
|
|
42
|
+
return gl;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getContextId(exgl?: IExpoWebGLRenderingContext | number): number {
|
|
46
|
+
const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;
|
|
47
|
+
if (!exglCtxId || typeof exglCtxId !== 'number') {
|
|
48
|
+
throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);
|
|
49
|
+
}
|
|
50
|
+
return exglCtxId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A context with no view, which does not present its framebuffer, take a snapshot to see it */
|
|
54
|
+
export async function createContextAsync(): Promise<IExpoWebGLRenderingContext> {
|
|
55
|
+
const { exglCtxId } = await glNativeModule.createContextAsync();
|
|
56
|
+
return getGl(exglCtxId);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** For a headless context made by `createContextAsync` */
|
|
60
|
+
export async function destroyContextAsync(
|
|
61
|
+
exgl?: IExpoWebGLRenderingContext | number,
|
|
62
|
+
): Promise<boolean> {
|
|
63
|
+
const exglCtxId = getContextId(exgl);
|
|
64
|
+
unregisterGLContext(exglCtxId);
|
|
65
|
+
return glNativeModule.destroyContextAsync(exglCtxId);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Saves the framebuffer as a file in the cache directory of the app */
|
|
69
|
+
export async function takeSnapshotAsync(
|
|
70
|
+
exgl?: IExpoWebGLRenderingContext | number,
|
|
71
|
+
options: IGLSnapshotOptions = {},
|
|
72
|
+
): Promise<IGLSnapshot> {
|
|
73
|
+
return glNativeModule.takeSnapshotAsync(getContextId(exgl), options);
|
|
74
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const GL_ERRORS: Readonly<Record<number, string>> = {
|
|
2
|
+
1280: 'INVALID ENUM: An unacceptable value has been specified for an enumerated argument.',
|
|
3
|
+
1281: 'INVALID_VALUE: A numeric argument is out of range.',
|
|
4
|
+
1282: 'INVALID_OPERATION: The specified command is not allowed for the current state.',
|
|
5
|
+
1285: 'OUT_OF_MEMORY: Not enough memory is left to execute the command.',
|
|
6
|
+
1286: 'INVALID_FRAMEBUFFER_OPERATION: The currently bound framebuffer is not complete when trying to render to or to read from it.',
|
|
7
|
+
37442: 'CONTEXT_LOST_WEBGL: The WebGL context is lost.',
|
|
8
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { GL_ERRORS } from './gl-errors';
|
|
2
|
+
import { GLLoggingOption } from './types';
|
|
3
|
+
import type { IExpoWebGLRenderingContext } from './types';
|
|
4
|
+
|
|
5
|
+
type ILoggableGL = Pick<IExpoWebGLRenderingContext, '__expoSetLogging'>;
|
|
6
|
+
|
|
7
|
+
type IGLFunction = (...args: unknown[]) => unknown;
|
|
8
|
+
|
|
9
|
+
const MAX_STRING_LENGTH = 20;
|
|
10
|
+
|
|
11
|
+
const SET_LOGGING_KEY = '__expoSetLogging';
|
|
12
|
+
|
|
13
|
+
const wrappers = new WeakSet<IGLFunction>();
|
|
14
|
+
|
|
15
|
+
function isGLFunction(value: unknown): value is IGLFunction {
|
|
16
|
+
return typeof value === 'function';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function constantNameOf(gl: object, value: number): string | undefined {
|
|
20
|
+
for (const name in gl) {
|
|
21
|
+
if (Reflect.get(gl, name) === value) return name;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Numbers get the name of a constant that holds them, which can mislead for a size, so the
|
|
27
|
+
// number stays. Strings are cut because a shader is long and logging it blocks the bridge
|
|
28
|
+
function describeArg(gl: object, option: number, arg: unknown): string {
|
|
29
|
+
if (option & GLLoggingOption.RESOLVE_CONSTANTS && typeof arg === 'number') {
|
|
30
|
+
const name = constantNameOf(gl, arg);
|
|
31
|
+
if (name) return `${arg} (${name})`;
|
|
32
|
+
}
|
|
33
|
+
const isLong = typeof arg === 'string' && arg.length > MAX_STRING_LENGTH;
|
|
34
|
+
if (option & GLLoggingOption.TRUNCATE_STRINGS && isLong) {
|
|
35
|
+
const lastSpace = arg.lastIndexOf(' ', MAX_STRING_LENGTH);
|
|
36
|
+
return `${arg.slice(0, lastSpace >= 0 ? lastSpace : MAX_STRING_LENGTH)}...`;
|
|
37
|
+
}
|
|
38
|
+
return String(arg);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The original `getError`, a wrapped one would log itself
|
|
42
|
+
function reportError(gl: object): void {
|
|
43
|
+
const getError: unknown = Reflect.get(Reflect.getPrototypeOf(gl) ?? {}, 'getError');
|
|
44
|
+
if (!isGLFunction(getError)) return;
|
|
45
|
+
const error = getError.call(gl);
|
|
46
|
+
if (typeof error !== 'number' || error === Reflect.get(gl, 'NO_ERROR')) return;
|
|
47
|
+
console.warn(`\x1b[31mExpoGL: Error ${GL_ERRORS[error]}\x1b[0m`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function wrapMethod(
|
|
51
|
+
gl: object,
|
|
52
|
+
key: string,
|
|
53
|
+
original: IGLFunction,
|
|
54
|
+
getOption: () => number,
|
|
55
|
+
): void {
|
|
56
|
+
const wrapper: IGLFunction = (...args) => {
|
|
57
|
+
const option = getOption();
|
|
58
|
+
if (option & GLLoggingOption.METHOD_CALLS) {
|
|
59
|
+
const params = args.map(arg => describeArg(gl, option, arg));
|
|
60
|
+
console.warn(`ExpoGL: ${key}(${params.join(', ')})`);
|
|
61
|
+
}
|
|
62
|
+
const result = original.apply(gl, args);
|
|
63
|
+
if (option & GLLoggingOption.METHOD_CALLS) console.warn(`ExpoGL: = ${String(result)}`);
|
|
64
|
+
if (option & GLLoggingOption.GET_ERRORS && key !== 'getError') reportError(gl);
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
wrappers.add(wrapper);
|
|
68
|
+
Reflect.set(gl, key, wrapper);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function wrapMethods(gl: object, getOption: () => number): void {
|
|
72
|
+
for (const [key, original] of Object.entries(Reflect.getPrototypeOf(gl) ?? {})) {
|
|
73
|
+
if (isGLFunction(original) && key !== SET_LOGGING_KEY) {
|
|
74
|
+
wrapMethod(gl, key, original, getOption);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function unwrapMethods(gl: object): void {
|
|
80
|
+
for (const [key, value] of Object.entries(gl)) {
|
|
81
|
+
if (isGLFunction(value) && wrappers.has(value)) Reflect.deleteProperty(gl, key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Adds `__expoSetLogging` to the context, for the logging options useful in debugging GL calls */
|
|
86
|
+
export function configureLogging(gl: ILoggableGL): void {
|
|
87
|
+
let loggingOption: number = GLLoggingOption.DISABLED;
|
|
88
|
+
|
|
89
|
+
gl.__expoSetLogging = (option: GLLoggingOption): void => {
|
|
90
|
+
// Both on or both off needs no wrapping or unwrapping, only the new option
|
|
91
|
+
if (!loggingOption !== !option) {
|
|
92
|
+
if (option) wrapMethods(gl, () => loggingOption);
|
|
93
|
+
else unwrapMethods(gl);
|
|
94
|
+
}
|
|
95
|
+
loggingOption = option;
|
|
96
|
+
};
|
|
97
|
+
}
|