@symbiote-native/gl 0.0.0-stage → 0.1.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 +219 -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 +107 -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 +35 -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 +108 -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 +36 -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 +51 -0
- package/src/angular/index.ts +4 -0
- package/src/core/constants.ts +6 -0
- package/src/core/gl-context.ts +79 -0
- package/src/core/gl-errors.ts +8 -0
- package/src/core/gl-utils.ts +106 -0
- package/src/core/gl-view.ts +160 -0
- package/src/core/index.ts +26 -0
- package/src/core/native-module.ts +22 -0
- package/src/core/types.ts +95 -0
- package/src/core/worklet-context-manager.ts +52 -0
- package/src/react/gl-view.ts +17 -0
- package/src/react/index.ts +5 -0
- package/src/solid/gl-view.ts +8 -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,107 @@
|
|
|
1
|
+
import { Platform, UnavailabilityError, requireNativeViewManager, } from 'expo-modules-core';
|
|
2
|
+
import { el } from '@symbiote-native/components';
|
|
3
|
+
import { defineExpoNativeView, getNativeTag, isDevBuild, isSymbioteNode, } from '@symbiote-native/engine';
|
|
4
|
+
import { GL_MODULE_NAME, GL_PACKAGE_NAME } from './constants.js';
|
|
5
|
+
import { getGl, takeSnapshotAsync, unregisterGLContext } from './gl-context.js';
|
|
6
|
+
import { glNativeModule } from './native-module.js';
|
|
7
|
+
// Registered on render: a barrel side effect is lost in a release build
|
|
8
|
+
const glView = defineExpoNativeView(requireNativeViewManager, GL_MODULE_NAME);
|
|
9
|
+
export const glViewName = glView.name;
|
|
10
|
+
export const ensureGLViewRegistered = glView.ensureRegistered;
|
|
11
|
+
const DEFAULT_MSAA_SAMPLES = 4;
|
|
12
|
+
function isSurfaceCreated(value) {
|
|
13
|
+
return typeof Reflect.get(Object(value), 'exglCtxId') === 'number';
|
|
14
|
+
}
|
|
15
|
+
function isContextCallback(value) {
|
|
16
|
+
return typeof value === 'function';
|
|
17
|
+
}
|
|
18
|
+
// Adapters hand over the props they hold, a missing callback is a view nobody listens to
|
|
19
|
+
function toViewProps(props) {
|
|
20
|
+
const onContextCreate = Reflect.get(props, 'onContextCreate');
|
|
21
|
+
return {
|
|
22
|
+
...props,
|
|
23
|
+
onContextCreate: isContextCallback(onContextCreate)
|
|
24
|
+
? onContextCreate
|
|
25
|
+
: () => undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function nativeTagOf(camera) {
|
|
29
|
+
const tag = isSymbioteNode(camera) ? getNativeTag(camera) : camera;
|
|
30
|
+
if (typeof tag !== 'number')
|
|
31
|
+
throw new Error('The camera view has no native tag yet');
|
|
32
|
+
return tag;
|
|
33
|
+
}
|
|
34
|
+
/** One per mounted view, `getNode` is kept for the shape the adapters share */
|
|
35
|
+
export function createGLView(_getNode) {
|
|
36
|
+
let exglCtxId;
|
|
37
|
+
let latestProps;
|
|
38
|
+
let hasWorkletSupport;
|
|
39
|
+
const onSurfaceCreate = (event) => {
|
|
40
|
+
if (!isSurfaceCreated(event.nativeEvent))
|
|
41
|
+
return;
|
|
42
|
+
exglCtxId = event.nativeEvent.exglCtxId;
|
|
43
|
+
latestProps?.onContextCreate(getGl(exglCtxId));
|
|
44
|
+
};
|
|
45
|
+
function warnOnWorkletChange(enabled) {
|
|
46
|
+
if (hasWorkletSupport !== undefined && hasWorkletSupport !== enabled) {
|
|
47
|
+
console.warn('Updating prop enableExperimentalWorkletSupport is not supported');
|
|
48
|
+
}
|
|
49
|
+
hasWorkletSupport = enabled;
|
|
50
|
+
}
|
|
51
|
+
const handle = {
|
|
52
|
+
get exglCtxId() {
|
|
53
|
+
return exglCtxId;
|
|
54
|
+
},
|
|
55
|
+
async createCameraTextureAsync(camera) {
|
|
56
|
+
if (!glNativeModule.createCameraTextureAsync) {
|
|
57
|
+
throw new UnavailabilityError(GL_PACKAGE_NAME, 'createCameraTextureAsync');
|
|
58
|
+
}
|
|
59
|
+
if (!exglCtxId)
|
|
60
|
+
throw new Error("GLView's surface is not created yet!");
|
|
61
|
+
const { exglObjId } = await glNativeModule.createCameraTextureAsync(exglCtxId, nativeTagOf(camera));
|
|
62
|
+
const texture = { id: exglObjId };
|
|
63
|
+
return texture;
|
|
64
|
+
},
|
|
65
|
+
async destroyObjectAsync(glObject) {
|
|
66
|
+
if (!glNativeModule.destroyObjectAsync) {
|
|
67
|
+
throw new UnavailabilityError(GL_PACKAGE_NAME, 'destroyObjectAsync');
|
|
68
|
+
}
|
|
69
|
+
return glNativeModule.destroyObjectAsync(glObject.id);
|
|
70
|
+
},
|
|
71
|
+
takeSnapshotAsync: (options) => takeSnapshotAsync(exglCtxId, options),
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
handle,
|
|
75
|
+
dispose: () => {
|
|
76
|
+
if (exglCtxId)
|
|
77
|
+
unregisterGLContext(exglCtxId);
|
|
78
|
+
},
|
|
79
|
+
render: props => {
|
|
80
|
+
if (!ensureGLViewRegistered()) {
|
|
81
|
+
if (isDevBuild())
|
|
82
|
+
console.warn("'GLView' is not available.");
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
latestProps = toViewProps(props);
|
|
86
|
+
const { onContextCreate, msaaSamples = DEFAULT_MSAA_SAMPLES, enableExperimentalWorkletSupport = false, ...viewProps } = latestProps;
|
|
87
|
+
warnOnWorkletChange(enableExperimentalWorkletSupport);
|
|
88
|
+
return el('view', viewProps, [
|
|
89
|
+
el(glViewName(), {
|
|
90
|
+
style: {
|
|
91
|
+
flex: 1,
|
|
92
|
+
...Platform.select({
|
|
93
|
+
ios: { backgroundColor: 'transparent' },
|
|
94
|
+
default: {},
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
onSurfaceCreate,
|
|
98
|
+
enableExperimentalWorkletSupport,
|
|
99
|
+
msaaSamples: Platform.select({
|
|
100
|
+
ios: msaaSamples,
|
|
101
|
+
default: undefined,
|
|
102
|
+
}),
|
|
103
|
+
}),
|
|
104
|
+
]);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { GL_MODULE_NAME } from './constants';
|
|
2
|
+
export { createContextAsync, destroyContextAsync, getGl, getWorkletContext, takeSnapshotAsync, } from './gl-context';
|
|
3
|
+
export { configureLogging } from './gl-utils';
|
|
4
|
+
export { createGLView, ensureGLViewRegistered, glViewName, type IGLView, } from './gl-view';
|
|
5
|
+
export { GLLoggingOption } from './types';
|
|
6
|
+
export type { IExpoWebGLRenderingContext, IGLNodeOrTag, IGLObject, IGLSnapshot, IGLSnapshotOptions, IGLSurfaceCreateEvent, IGLViewHandle, IGLViewProps, } from './types';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GL_MODULE_NAME } from './constants.js';
|
|
2
|
+
export { createContextAsync, destroyContextAsync, getGl, getWorkletContext, takeSnapshotAsync, } from './gl-context.js';
|
|
3
|
+
export { configureLogging } from './gl-utils.js';
|
|
4
|
+
export { createGLView, ensureGLViewRegistered, glViewName, } from './gl-view.js';
|
|
5
|
+
export { GLLoggingOption } from './types.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IGLSnapshot, IGLSnapshotOptions } from './types';
|
|
2
|
+
export type INativeGLModule = {
|
|
3
|
+
createContextAsync(): Promise<{
|
|
4
|
+
exglCtxId: number;
|
|
5
|
+
}>;
|
|
6
|
+
destroyContextAsync(exglCtxId: number): Promise<boolean>;
|
|
7
|
+
takeSnapshotAsync(exglCtxId: number, options: IGLSnapshotOptions): Promise<IGLSnapshot>;
|
|
8
|
+
/** Absent where there is no camera texture support */
|
|
9
|
+
createCameraTextureAsync?(exglCtxId: number, cameraTag: number): Promise<{
|
|
10
|
+
exglObjId: number;
|
|
11
|
+
}>;
|
|
12
|
+
/** Absent where objects cannot be destroyed one by one */
|
|
13
|
+
destroyObjectAsync?(exglObjId: number): Promise<boolean>;
|
|
14
|
+
};
|
|
15
|
+
export declare const glNativeModule: INativeGLModule;
|
|
@@ -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,13 @@
|
|
|
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 = {}));
|
|
@@ -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.js';
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- optional dependency, see above
|
|
11
|
+
const reanimated = require('react-native-reanimated');
|
|
12
|
+
const runOnUI = Reflect.get(Object(reanimated), 'runOnUI');
|
|
13
|
+
if (!isRunOnUI(runOnUI))
|
|
14
|
+
throw new Error('react-native-reanimated has no runOnUI');
|
|
15
|
+
return {
|
|
16
|
+
getContext: contextId => {
|
|
17
|
+
'worklet';
|
|
18
|
+
return Reflect.get(Object(Reflect.get(globalThis, GL_CONTEXTS_GLOBAL)), String(contextId));
|
|
19
|
+
},
|
|
20
|
+
unregister: contextId => {
|
|
21
|
+
runOnUI(id => {
|
|
22
|
+
'worklet';
|
|
23
|
+
Reflect.deleteProperty(Object(Reflect.get(globalThis, GL_CONTEXTS_GLOBAL)), String(id));
|
|
24
|
+
})(contextId);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return {
|
|
30
|
+
getContext: () => {
|
|
31
|
+
throw new Error('Worklet runtime is not available');
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactElement, Ref } from 'react';
|
|
2
|
+
import type { IGLViewHandle, IGLViewProps } from '../core';
|
|
3
|
+
export type IGLViewReactProps = IGLViewProps & {
|
|
4
|
+
ref?: Ref<IGLViewHandle>;
|
|
5
|
+
className?: string;
|
|
6
|
+
};
|
|
7
|
+
/** React twin of `expo-gl`'s `GLView` */
|
|
8
|
+
export declare function GLView({ ref, ...props }: IGLViewReactProps): ReactElement | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useNativeViewController } from '@symbiote-native/react';
|
|
2
|
+
import { createGLView } from '../core/index.js';
|
|
3
|
+
/** React twin of `expo-gl`'s `GLView` */
|
|
4
|
+
export function GLView({ ref, ...props }) {
|
|
5
|
+
return useNativeViewController(ref, createGLView, props);
|
|
6
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IGLViewHandle } from '../core';
|
|
2
|
+
/** Solid twin of `expo-gl`'s `GLView`, `ref` gets the handle of the view */
|
|
3
|
+
export declare const GLView: (props: import("@symbiote-native/components").IAccessibilityProps & import("@symbiote-native/components").IAriaProps & import("@symbiote-native/components").IResponderProps & {
|
|
4
|
+
style?: import("@symbiote-native/engine").IStyleProp<import("@symbiote-native/engine").IViewStyle>;
|
|
5
|
+
testID?: string;
|
|
6
|
+
nativeID?: string;
|
|
7
|
+
onLayout?: (event: import("@symbiote-native/engine").ISymbioteEvent) => void;
|
|
8
|
+
onContextCreate(gl: import(".").IExpoWebGLRenderingContext): void;
|
|
9
|
+
msaaSamples?: number;
|
|
10
|
+
enableExperimentalWorkletSupport?: boolean;
|
|
11
|
+
} & {
|
|
12
|
+
ref?: ((handle: IGLViewHandle) => void) | undefined;
|
|
13
|
+
}) => import("@symbiote-native/engine").ISymbioteNode | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import DescriptorHost from '@symbiote-native/svelte/descriptor-host';
|
|
3
|
+
import { useNativeViewController } from '@symbiote-native/svelte/runes/use-native-view-controller';
|
|
4
|
+
import { createGLView } from '../core';
|
|
5
|
+
import type { IGLViewProps } from '../core';
|
|
6
|
+
|
|
7
|
+
const props: IGLViewProps = $props();
|
|
8
|
+
const view = useNativeViewController(createGLView, () => ({ ...props }));
|
|
9
|
+
|
|
10
|
+
// The functions of the view are instance members, `bind:this` reaches them
|
|
11
|
+
export const createCameraTextureAsync = view.handle.createCameraTextureAsync;
|
|
12
|
+
export const destroyObjectAsync = view.handle.destroyObjectAsync;
|
|
13
|
+
export const takeSnapshotAsync = view.handle.takeSnapshotAsync;
|
|
14
|
+
export const getContextId = (): number | undefined => view.handle.exglCtxId;
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
{#if view.descriptor}
|
|
18
|
+
<DescriptorHost descriptor={view.descriptor} />
|
|
19
|
+
{/if}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IGLViewProps } from '../core';
|
|
2
|
+
declare const GlView: import("svelte").Component<IGLViewProps, {
|
|
3
|
+
createCameraTextureAsync: (camera: import(".").IGLNodeOrTag) => Promise<WebGLTexture>;
|
|
4
|
+
destroyObjectAsync: (glObject: import(".").IGLObject) => Promise<boolean>;
|
|
5
|
+
takeSnapshotAsync: (options?: import(".").IGLSnapshotOptions) => Promise<import(".").IGLSnapshot>;
|
|
6
|
+
getContextId: () => number | undefined;
|
|
7
|
+
}, "">;
|
|
8
|
+
type GlView = ReturnType<typeof GlView>;
|
|
9
|
+
export default GlView;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Vue twin of `expo-gl`'s `GLView`, `ref` gets the handle of the view */
|
|
2
|
+
export declare const GLView: import("vue").DefineComponent<{}, () => import("vue").VNode | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NativeViewBase } from '@symbiote-native/angular';
|
|
2
|
+
import type { IDescriptor } from '@symbiote-native/components';
|
|
3
|
+
import type { IGLViewProps } from '../../core';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
declare const GL_VIEW_INPUTS: readonly ["onContextCreate", "msaaSamples", "enableExperimentalWorkletSupport"];
|
|
6
|
+
export interface GLView extends Partial<Pick<IGLViewProps, (typeof GL_VIEW_INPUTS)[number]>> {
|
|
7
|
+
}
|
|
8
|
+
/** Angular twin of `expo-gl`'s `GLView` */
|
|
9
|
+
export declare class GLView extends NativeViewBase {
|
|
10
|
+
private readonly view;
|
|
11
|
+
readonly createCameraTextureAsync: (camera: import("..").IGLNodeOrTag) => Promise<WebGLTexture>;
|
|
12
|
+
readonly destroyObjectAsync: (glObject: import("..").IGLObject) => Promise<boolean>;
|
|
13
|
+
readonly takeSnapshotAsync: (options?: import("..").IGLSnapshotOptions) => Promise<import("..").IGLSnapshot>;
|
|
14
|
+
get exglCtxId(): number | undefined;
|
|
15
|
+
protected readonly propNames: readonly ["onContextCreate", "msaaSamples", "enableExperimentalWorkletSupport"];
|
|
16
|
+
protected renderView(props: object): IDescriptor | null;
|
|
17
|
+
protected disposeView(): void;
|
|
18
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<GLView, never>;
|
|
19
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<GLView, "GLView", never, { "onContextCreate": { "alias": "onContextCreate"; "required": false; }; "msaaSamples": { "alias": "msaaSamples"; "required": false; }; "enableExperimentalWorkletSupport": { "alias": "enableExperimentalWorkletSupport"; "required": false; }; }, {}, never, never, true, never>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
|
2
|
+
import { DescriptorOutlet, NativeViewBase } from '@symbiote-native/angular';
|
|
3
|
+
import { createGLView } from '../../core';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
// One list is the inputs of the component and the props it hands to the native view
|
|
6
|
+
const GL_VIEW_INPUTS = [
|
|
7
|
+
'onContextCreate',
|
|
8
|
+
'msaaSamples',
|
|
9
|
+
'enableExperimentalWorkletSupport',
|
|
10
|
+
];
|
|
11
|
+
/** Angular twin of `expo-gl`'s `GLView` */
|
|
12
|
+
export class GLView extends NativeViewBase {
|
|
13
|
+
view = createGLView(() => this.hostNode());
|
|
14
|
+
// The functions of the view are members of the component, a `@ViewChild` reaches them
|
|
15
|
+
createCameraTextureAsync = this.view.handle.createCameraTextureAsync;
|
|
16
|
+
destroyObjectAsync = this.view.handle.destroyObjectAsync;
|
|
17
|
+
takeSnapshotAsync = this.view.handle.takeSnapshotAsync;
|
|
18
|
+
get exglCtxId() {
|
|
19
|
+
return this.view.handle.exglCtxId;
|
|
20
|
+
}
|
|
21
|
+
propNames = GL_VIEW_INPUTS;
|
|
22
|
+
renderView(props) {
|
|
23
|
+
return this.view.render(props);
|
|
24
|
+
}
|
|
25
|
+
disposeView() {
|
|
26
|
+
this.view.dispose();
|
|
27
|
+
}
|
|
28
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: GLView, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
29
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.8", type: GLView, isStandalone: true, selector: "GLView", inputs: { onContextCreate: "onContextCreate", msaaSamples: "msaaSamples", enableExperimentalWorkletSupport: "enableExperimentalWorkletSupport" }, usesInheritance: true, ngImport: i0, template: `@if (descriptor; as node) {
|
|
30
|
+
<symbiote-descriptor-outlet [node]="node" />
|
|
31
|
+
}`, isInline: true, dependencies: [{ kind: "component", type: DescriptorOutlet, selector: "symbiote-descriptor-outlet", inputs: ["node"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
32
|
+
}
|
|
33
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: GLView, decorators: [{
|
|
34
|
+
type: Component,
|
|
35
|
+
args: [{
|
|
36
|
+
selector: 'GLView',
|
|
37
|
+
standalone: true,
|
|
38
|
+
imports: [DescriptorOutlet],
|
|
39
|
+
inputs: [...GL_VIEW_INPUTS],
|
|
40
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
41
|
+
template: `@if (descriptor; as node) {
|
|
42
|
+
<symbiote-descriptor-outlet [node]="node" />
|
|
43
|
+
}`,
|
|
44
|
+
}]
|
|
45
|
+
}] });
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/angular/gl-view/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;;AAG1C,oFAAoF;AACpF,MAAM,cAAc,GAAG;IACrB,iBAAiB;IACjB,aAAa;IACb,kCAAkC;CAC1B,CAAC;AAOX,2CAA2C;AAW3C,MAAM,OAAO,MAAO,SAAQ,cAAc;IACvB,IAAI,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE5D,sFAAsF;IAC7E,wBAAwB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;IACrE,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;IACzD,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;IAEhE,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IACpC,CAAC;IAE2B,SAAS,GAAG,cAAc,CAAC;IAEpC,UAAU,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAEkB,WAAW;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;uGApBU,MAAM;2FAAN,MAAM,2OAJP;;IAER,4DALQ,gBAAgB;;2FAOf,MAAM;kBAVlB,SAAS;mBAAC;oBACT,QAAQ,EAAE,QAAQ;oBAClB,UAAU,EAAE,IAAI;oBAChB,OAAO,EAAE,CAAC,gBAAgB,CAAC;oBAC3B,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC;oBAC3B,eAAe,EAAE,uBAAuB,CAAC,MAAM;oBAC/C,QAAQ,EAAE;;IAER;iBACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/angular/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAElG,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEvC,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC;AAEzC,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IExpoWebGLRenderingContext, IGLSnapshot, IGLSnapshotOptions } from './types';
|
|
2
|
+
/** The context of a worklet, `exgl` has to be created with worklet support */
|
|
3
|
+
export declare function getWorkletContext(contextId: number): IExpoWebGLRenderingContext | undefined;
|
|
4
|
+
export declare function unregisterGLContext(exglCtxId: number): void;
|
|
5
|
+
/** The GL interface of a context id the native side created */
|
|
6
|
+
export declare function getGl(exglCtxId: number): IExpoWebGLRenderingContext;
|
|
7
|
+
export declare function getContextId(exgl?: IExpoWebGLRenderingContext | number): number;
|
|
8
|
+
/** A context with no view, which does not present its framebuffer, take a snapshot to see it */
|
|
9
|
+
export declare function createContextAsync(): Promise<IExpoWebGLRenderingContext>;
|
|
10
|
+
/** For a headless context made by `createContextAsync` */
|
|
11
|
+
export declare function destroyContextAsync(exgl?: IExpoWebGLRenderingContext | number): Promise<boolean>;
|
|
12
|
+
/** Saves the framebuffer as a file in the cache directory of the app */
|
|
13
|
+
export declare function takeSnapshotAsync(exgl?: IExpoWebGLRenderingContext | number, options?: IGLSnapshotOptions): Promise<IGLSnapshot>;
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { createWorkletContextManager } from './worklet-context-manager';
|
|
6
|
+
const workletContextManager = createWorkletContextManager();
|
|
7
|
+
function isContext(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null;
|
|
9
|
+
}
|
|
10
|
+
/** The context of a worklet, `exgl` has to be created with worklet support */
|
|
11
|
+
export function getWorkletContext(contextId) {
|
|
12
|
+
'worklet';
|
|
13
|
+
return workletContextManager.getContext(contextId);
|
|
14
|
+
}
|
|
15
|
+
export function unregisterGLContext(exglCtxId) {
|
|
16
|
+
const contexts = Reflect.get(globalThis, GL_CONTEXTS_GLOBAL);
|
|
17
|
+
if (contexts)
|
|
18
|
+
Reflect.deleteProperty(Object(contexts), String(exglCtxId));
|
|
19
|
+
workletContextManager.unregister?.(exglCtxId);
|
|
20
|
+
}
|
|
21
|
+
/** The GL interface of a context id the native side created */
|
|
22
|
+
export function getGl(exglCtxId) {
|
|
23
|
+
const contexts = Reflect.get(globalThis, GL_CONTEXTS_GLOBAL);
|
|
24
|
+
if (!contexts) {
|
|
25
|
+
throw new CodedError('ERR_GL_NOT_AVAILABLE', 'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)');
|
|
26
|
+
}
|
|
27
|
+
const gl = Reflect.get(Object(contexts), String(exglCtxId));
|
|
28
|
+
if (!isContext(gl))
|
|
29
|
+
throw new Error(`There is no EXGLContext with id ${exglCtxId}`);
|
|
30
|
+
configureLogging(gl);
|
|
31
|
+
return gl;
|
|
32
|
+
}
|
|
33
|
+
export function getContextId(exgl) {
|
|
34
|
+
const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;
|
|
35
|
+
if (!exglCtxId || typeof exglCtxId !== 'number') {
|
|
36
|
+
throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);
|
|
37
|
+
}
|
|
38
|
+
return exglCtxId;
|
|
39
|
+
}
|
|
40
|
+
/** A context with no view, which does not present its framebuffer, take a snapshot to see it */
|
|
41
|
+
export async function createContextAsync() {
|
|
42
|
+
const { exglCtxId } = await glNativeModule.createContextAsync();
|
|
43
|
+
return getGl(exglCtxId);
|
|
44
|
+
}
|
|
45
|
+
/** For a headless context made by `createContextAsync` */
|
|
46
|
+
export async function destroyContextAsync(exgl) {
|
|
47
|
+
const exglCtxId = getContextId(exgl);
|
|
48
|
+
unregisterGLContext(exglCtxId);
|
|
49
|
+
return glNativeModule.destroyContextAsync(exglCtxId);
|
|
50
|
+
}
|
|
51
|
+
/** Saves the framebuffer as a file in the cache directory of the app */
|
|
52
|
+
export async function takeSnapshotAsync(exgl, options = {}) {
|
|
53
|
+
return glNativeModule.takeSnapshotAsync(getContextId(exgl), options);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=gl-context.js.map
|
|
@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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GL_ERRORS: Readonly<Record<number, string>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const GL_ERRORS = {
|
|
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
|
+
};
|
|
9
|
+
//# sourceMappingURL=gl-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gl-errors.js","sourceRoot":"","sources":["../../src/core/gl-errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAqC;IACzD,IAAI,EAAE,oFAAoF;IAC1F,IAAI,EAAE,oDAAoD;IAC1D,IAAI,EAAE,gFAAgF;IACtF,IAAI,EAAE,kEAAkE;IACxE,IAAI,EAAE,6HAA6H;IACnI,KAAK,EAAE,gDAAgD;CACxD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExpoWebGLRenderingContext } from './types';
|
|
2
|
+
type ILoggableGL = Pick<IExpoWebGLRenderingContext, '__expoSetLogging'>;
|
|
3
|
+
/** Adds `__expoSetLogging` to the context, for the logging options useful in debugging GL calls */
|
|
4
|
+
export declare function configureLogging(gl: ILoggableGL): void;
|
|
5
|
+
export {};
|