expo-gl 13.1.0 → 13.3.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/CHANGELOG.md +14 -0
- package/android/build.gradle +11 -8
- package/android/src/main/java/expo/modules/gl/GLContext.java +22 -23
- package/android/src/main/java/expo/modules/gl/GLObjectManagerModule.kt +92 -0
- package/android/src/main/java/expo/modules/gl/GLView.kt +2 -2
- package/build/GLView.d.ts.map +1 -1
- package/build/GLView.js +3 -2
- package/build/GLView.js.map +1 -1
- package/build/GLView.types.d.ts +1 -1
- package/build/GLView.types.js.map +1 -1
- package/expo-module.config.json +1 -1
- package/package.json +2 -2
- package/src/GLView.tsx +3 -1
- package/src/GLView.types.ts +1 -1
- package/android/src/main/java/expo/modules/gl/GLObjectManagerModule.java +0 -144
- package/android/src/main/java/expo/modules/gl/GLPackage.java +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 13.3.0 — 2023-09-15
|
|
14
|
+
|
|
15
|
+
_This version does not introduce any user-facing changes._
|
|
16
|
+
|
|
17
|
+
## 13.2.0 — 2023-09-04
|
|
18
|
+
|
|
19
|
+
### 🎉 New features
|
|
20
|
+
|
|
21
|
+
- Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
|
|
22
|
+
|
|
23
|
+
### 💡 Others
|
|
24
|
+
|
|
25
|
+
- Migrated `GLObjectManagerModule` to use Expo Modules API. ([#24017](https://github.com/expo/expo/pull/24017) by [@lukmccall](https://github.com/lukmccall))
|
|
26
|
+
|
|
13
27
|
## 13.1.0 — 2023-07-28
|
|
14
28
|
|
|
15
29
|
_This version does not introduce any user-facing changes._
|
package/android/build.gradle
CHANGED
|
@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
|
|
|
6
6
|
apply plugin: "de.undercouch.download"
|
|
7
7
|
|
|
8
8
|
group = 'host.exp.exponent'
|
|
9
|
-
version = '13.
|
|
9
|
+
version = '13.3.0'
|
|
10
10
|
|
|
11
11
|
def REACT_NATIVE_BUILD_FROM_SOURCE = findProject(":ReactAndroid") != null
|
|
12
12
|
def REACT_NATIVE_DIR = REACT_NATIVE_BUILD_FROM_SOURCE
|
|
@@ -82,13 +82,16 @@ android {
|
|
|
82
82
|
ndkVersion rootProject.ext.ndkVersion
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
86
|
+
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
87
|
+
compileOptions {
|
|
88
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
89
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
90
|
+
}
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
kotlinOptions {
|
|
93
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
namespace "expo.modules.gl"
|
|
@@ -96,7 +99,7 @@ android {
|
|
|
96
99
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
97
100
|
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
98
101
|
versionCode 31
|
|
99
|
-
versionName "13.
|
|
102
|
+
versionName "13.3.0"
|
|
100
103
|
|
|
101
104
|
externalNativeBuild {
|
|
102
105
|
cmake {
|
|
@@ -28,12 +28,11 @@ import javax.microedition.khronos.egl.EGLDisplay;
|
|
|
28
28
|
import javax.microedition.khronos.egl.EGLSurface;
|
|
29
29
|
|
|
30
30
|
import expo.modules.core.ModuleRegistry;
|
|
31
|
-
import expo.modules.core.Promise;
|
|
32
31
|
import expo.modules.core.interfaces.JavaScriptContextProvider;
|
|
33
32
|
import expo.modules.core.interfaces.RuntimeEnvironmentInterface;
|
|
34
33
|
import expo.modules.core.interfaces.services.UIManager;
|
|
35
|
-
import expo.modules.gl.cpp.EXGL;
|
|
36
34
|
import expo.modules.gl.utils.FileSystemUtils;
|
|
35
|
+
import expo.modules.kotlin.Promise;
|
|
37
36
|
|
|
38
37
|
import static android.opengl.GLES30.*;
|
|
39
38
|
import static expo.modules.gl.cpp.EXGL.*;
|
|
@@ -72,9 +71,9 @@ public class GLContext {
|
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
public void initialize(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
SurfaceTexture surfaceTexture,
|
|
75
|
+
Boolean enableExperimentalWorkletSupport,
|
|
76
|
+
final Runnable completionCallback) {
|
|
78
77
|
if (mGLThread != null) {
|
|
79
78
|
return;
|
|
80
79
|
}
|
|
@@ -85,7 +84,7 @@ public class GLContext {
|
|
|
85
84
|
|
|
86
85
|
// On JS thread, get JavaScriptCore context, create EXGL context, call JS callback
|
|
87
86
|
final GLContext glContext = this;
|
|
88
|
-
ModuleRegistry moduleRegistry = mManager.
|
|
87
|
+
ModuleRegistry moduleRegistry = mManager.getAppContext().getLegacyModuleRegistry();
|
|
89
88
|
final UIManager uiManager = moduleRegistry.getModule(UIManager.class);
|
|
90
89
|
final JavaScriptContextProvider jsContextProvider = moduleRegistry.getModule(JavaScriptContextProvider.class);
|
|
91
90
|
final RuntimeEnvironmentInterface environment = moduleRegistry.getModule(RuntimeEnvironmentInterface.class);
|
|
@@ -103,14 +102,14 @@ public class GLContext {
|
|
|
103
102
|
uiManager.runOnUiQueueThread(new Runnable() {
|
|
104
103
|
@Override
|
|
105
104
|
public void run() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
EXGLContextPrepareWorklet(mEXGLCtxId);
|
|
106
|
+
mManager.saveContext(glContext);
|
|
107
|
+
completionCallback.run();
|
|
109
108
|
}
|
|
110
109
|
});
|
|
111
110
|
} else {
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
mManager.saveContext(glContext);
|
|
112
|
+
completionCallback.run();
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
115
|
});
|
|
@@ -150,9 +149,9 @@ public class GLContext {
|
|
|
150
149
|
if (surfaceTexture == null) {
|
|
151
150
|
// Some devices are crashing when pbuffer surface doesn't have EGL_WIDTH and EGL_HEIGHT attributes set
|
|
152
151
|
int[] surfaceAttribs = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
EGL10.EGL_WIDTH, 1,
|
|
153
|
+
EGL10.EGL_HEIGHT, 1,
|
|
154
|
+
EGL10.EGL_NONE
|
|
156
155
|
};
|
|
157
156
|
return mEGL.eglCreatePbufferSurface(mEGLDisplay, eglConfig, surfaceAttribs);
|
|
158
157
|
} else {
|
|
@@ -239,7 +238,7 @@ public class GLContext {
|
|
|
239
238
|
glBindFramebuffer(GL_FRAMEBUFFER, prevFramebuffer[0]);
|
|
240
239
|
|
|
241
240
|
new TakeSnapshot(context, width, height, flip, format, compressionQuality, dataArray, promise)
|
|
242
|
-
|
|
241
|
+
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
243
242
|
}
|
|
244
243
|
});
|
|
245
244
|
}
|
|
@@ -308,7 +307,7 @@ public class GLContext {
|
|
|
308
307
|
Context context = mContext.get();
|
|
309
308
|
|
|
310
309
|
if (context == null) {
|
|
311
|
-
mPromise.reject("E_GL_CONTEXT_DESTROYED", "Context has been garbage collected.");
|
|
310
|
+
mPromise.reject("E_GL_CONTEXT_DESTROYED", "Context has been garbage collected.", null);
|
|
312
311
|
return null;
|
|
313
312
|
}
|
|
314
313
|
|
|
@@ -322,7 +321,7 @@ public class GLContext {
|
|
|
322
321
|
|
|
323
322
|
} catch (Exception e) {
|
|
324
323
|
e.printStackTrace();
|
|
325
|
-
mPromise.reject("E_GL_CANT_SAVE_SNAPSHOT", e.getMessage());
|
|
324
|
+
mPromise.reject("E_GL_CANT_SAVE_SNAPSHOT", e.getMessage(), null);
|
|
326
325
|
}
|
|
327
326
|
|
|
328
327
|
if (output == null) {
|
|
@@ -392,10 +391,10 @@ public class GLContext {
|
|
|
392
391
|
int[] configsCount = new int[1];
|
|
393
392
|
EGLConfig[] configs = new EGLConfig[1];
|
|
394
393
|
int[] configSpec = {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
394
|
+
EGL10.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
|
|
395
|
+
EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8, EGL10.EGL_BLUE_SIZE, 8,
|
|
396
|
+
EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_STENCIL_SIZE, 8,
|
|
397
|
+
EGL10.EGL_NONE,
|
|
399
398
|
};
|
|
400
399
|
if (!mEGL.eglChooseConfig(mEGLDisplay, configSpec, configs, 1, configsCount)) {
|
|
401
400
|
throw new IllegalArgumentException("eglChooseConfig failed " + GLUtils.getEGLErrorString(mEGL.eglGetError()));
|
|
@@ -425,7 +424,7 @@ public class GLContext {
|
|
|
425
424
|
|
|
426
425
|
// Enable buffer preservation -- allows app to draw over previous frames without clearing
|
|
427
426
|
EGL14.eglSurfaceAttrib(EGL14.eglGetCurrentDisplay(), EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW),
|
|
428
|
-
|
|
427
|
+
EGL14.EGL_SWAP_BEHAVIOR, EGL14.EGL_BUFFER_PRESERVED);
|
|
429
428
|
checkEGLError();
|
|
430
429
|
}
|
|
431
430
|
|
|
@@ -441,7 +440,7 @@ public class GLContext {
|
|
|
441
440
|
|
|
442
441
|
private void makeEGLContextCurrent() {
|
|
443
442
|
if (!mEGLContext.equals(mEGL.eglGetCurrentContext()) ||
|
|
444
|
-
|
|
443
|
+
!mEGLSurface.equals(mEGL.eglGetCurrentSurface(EGL10.EGL_DRAW))) {
|
|
445
444
|
checkEGLError();
|
|
446
445
|
if (!makeCurrent(mEGLSurface)) {
|
|
447
446
|
throw new RuntimeException("eglMakeCurrent failed " + GLUtils.getEGLErrorString(mEGL.eglGetError()));
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright 2017-present 650 Industries. All rights reserved.
|
|
2
|
+
package expo.modules.gl
|
|
3
|
+
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import android.util.SparseArray
|
|
6
|
+
import android.view.View
|
|
7
|
+
import expo.modules.interfaces.camera.CameraViewInterface
|
|
8
|
+
import expo.modules.kotlin.Promise
|
|
9
|
+
import expo.modules.kotlin.exception.CodedException
|
|
10
|
+
import expo.modules.kotlin.exception.Exceptions
|
|
11
|
+
import expo.modules.kotlin.functions.Queues
|
|
12
|
+
import expo.modules.kotlin.modules.Module
|
|
13
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
14
|
+
|
|
15
|
+
private class InvalidCameraViewException :
|
|
16
|
+
CodedException("Provided view tag don't point to valid instance of the camera view")
|
|
17
|
+
|
|
18
|
+
private class InvalidGLContextException :
|
|
19
|
+
CodedException("GLContext not found for given context id")
|
|
20
|
+
|
|
21
|
+
class GLObjectManagerModule : Module() {
|
|
22
|
+
private val mGLObjects = SparseArray<GLObject>()
|
|
23
|
+
private val mGLContextMap = SparseArray<GLContext>()
|
|
24
|
+
override fun definition() = ModuleDefinition {
|
|
25
|
+
Name("ExponentGLObjectManager")
|
|
26
|
+
|
|
27
|
+
AsyncFunction("destroyObjectAsync") { exglObjId: Int ->
|
|
28
|
+
val glObject = mGLObjects[exglObjId]
|
|
29
|
+
?: return@AsyncFunction false
|
|
30
|
+
|
|
31
|
+
mGLObjects.remove(exglObjId)
|
|
32
|
+
glObject.destroy()
|
|
33
|
+
true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
AsyncFunction("createCameraTextureAsync") { exglCtxId: Int, cameraViewTag: Int, promise: Promise ->
|
|
37
|
+
val cameraView = appContext.findView<View>(cameraViewTag) as? CameraViewInterface
|
|
38
|
+
?: throw InvalidCameraViewException()
|
|
39
|
+
|
|
40
|
+
val glContext = getContextWithId(exglCtxId)
|
|
41
|
+
?: throw InvalidGLContextException()
|
|
42
|
+
|
|
43
|
+
glContext.runAsync {
|
|
44
|
+
val cameraTexture = GLCameraObject(glContext, cameraView)
|
|
45
|
+
val exglObjId = cameraTexture.getEXGLObjId()
|
|
46
|
+
mGLObjects.put(exglObjId, cameraTexture)
|
|
47
|
+
val response = Bundle()
|
|
48
|
+
response.putInt("exglObjId", exglObjId)
|
|
49
|
+
promise.resolve(response)
|
|
50
|
+
}
|
|
51
|
+
}.runOnQueue(Queues.MAIN)
|
|
52
|
+
|
|
53
|
+
AsyncFunction("takeSnapshotAsync") { exglCtxId: Int, options: Map<String, Any?>, promise: Promise ->
|
|
54
|
+
val context = appContext.reactContext
|
|
55
|
+
?: throw Exceptions.ReactContextLost()
|
|
56
|
+
|
|
57
|
+
val glContext = getContextWithId(exglCtxId)
|
|
58
|
+
?: throw InvalidGLContextException()
|
|
59
|
+
|
|
60
|
+
glContext.takeSnapshot(options, context, promise)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
AsyncFunction("createContextAsync") { promise: Promise ->
|
|
64
|
+
val glContext = GLContext(this@GLObjectManagerModule)
|
|
65
|
+
glContext.initialize(null, false) {
|
|
66
|
+
val results = Bundle()
|
|
67
|
+
results.putInt("exglCtxId", glContext.contextId)
|
|
68
|
+
promise.resolve(results)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
AsyncFunction("destroyContextAsync") { exglCtxId: Int ->
|
|
73
|
+
val glContext = getContextWithId(exglCtxId)
|
|
74
|
+
?: return@AsyncFunction false
|
|
75
|
+
|
|
76
|
+
glContext.destroy()
|
|
77
|
+
true
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private fun getContextWithId(exglCtxId: Int): GLContext? {
|
|
82
|
+
return mGLContextMap[exglCtxId]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fun saveContext(glContext: GLContext) {
|
|
86
|
+
mGLContextMap.put(glContext.contextId, glContext)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fun deleteContextWithId(exglCtxId: Int) {
|
|
90
|
+
mGLContextMap.delete(exglCtxId)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -20,8 +20,8 @@ class GLView(context: Context, appContext: AppContext) : TextureView(context), S
|
|
|
20
20
|
private var onSurfaceTextureWasCalledWithZeroSize = false
|
|
21
21
|
private var glContext = GLContext(
|
|
22
22
|
appContext
|
|
23
|
-
.
|
|
24
|
-
.
|
|
23
|
+
.registry
|
|
24
|
+
.getModule<GLObjectManagerModule>()
|
|
25
25
|
)
|
|
26
26
|
|
|
27
27
|
private val exglContextId: Int
|
package/build/GLView.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.d.ts","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GLView.d.ts","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAIxB,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAWF;;;GAGG;AACH,qBAAa,MAAO,SAAQ,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC;IACtD,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC;IAEvB,MAAM,CAAC,YAAY;;;MAGjB;IAEF;;;;;;;OAOG;WACU,kBAAkB,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAKrE;;;;OAIG;WACU,mBAAmB,CAAC,IAAI,CAAC,EAAE,yBAAyB,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM7F;;;;;OAKG;WACU,iBAAiB,CAC5B,IAAI,CAAC,EAAE,yBAAyB,GAAG,MAAM,EACzC,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,UAAU,CAAC;IAKtB,MAAM,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,yBAAyB,GAAG,SAAS,CACnD;IAEnC,SAAS,EAAE,iBAAiB,CAAQ;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,MAAM;IA4BN,aAAa,cAAe,iBAAiB,KAAG,IAAI,CAKlD;IAEF,gBAAgB,mCAAoC,kBAAkB,KAAG,IAAI,CAQ3E;IAEF,oBAAoB,IAAI,IAAI;IAM5B,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;IAS1C,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC;IAQnC,wBAAwB,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBrF,kBAAkB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAOjE;;;;OAIG;IACG,iBAAiB,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;CAO5E"}
|
package/build/GLView.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { NativeModulesProxy, UnavailabilityError, requireNativeViewManager, CodedError, } from 'expo-modules-core';
|
|
1
|
+
import { NativeModulesProxy, UnavailabilityError, requireNativeModule, requireNativeViewManager, CodedError, } from 'expo-modules-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { Platform, View, findNodeHandle } from 'react-native';
|
|
4
4
|
import { configureLogging } from './GLUtils';
|
|
5
5
|
import { createWorkletContextManager } from './GLWorkletContextManager';
|
|
6
|
-
const
|
|
6
|
+
const ExponentGLObjectManager = requireNativeModule('ExponentGLObjectManager');
|
|
7
|
+
const { ExponentGLViewManager } = NativeModulesProxy;
|
|
7
8
|
const NativeView = requireNativeViewManager('ExponentGLView');
|
|
8
9
|
const workletContextManager = createWorkletContextManager();
|
|
9
10
|
// @needsAudit
|
package/build/GLView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.js","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAS7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AASxE,MAAM,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,GAAG,kBAAkB,CAAC;AAE9E,MAAM,UAAU,GAAG,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;AAC9D,MAAM,qBAAqB,GAAG,2BAA2B,EAAE,CAAC;AAE5D,cAAc;AACd;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,KAAK,CAAC,SAAsB;IACtD,MAAM,CAAC,UAAU,CAAM;IAEvB,MAAM,CAAC,YAAY,GAAG;QACpB,WAAW,EAAE,CAAC;QACd,gCAAgC,EAAE,KAAK;KACxC,CAAC;IAEF;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB;QAC7B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,uBAAuB,CAAC,kBAAkB,EAAE,CAAC;QACzE,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAyC;QACxE,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACrC,mBAAmB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AC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAEpD,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAErB,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAAyC,EAAU,EAAE;IACzE,MAAM,SAAS,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3E,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QAC/C,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;KACjE;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import {\n NativeModulesProxy,\n UnavailabilityError,\n requireNativeViewManager,\n CodedError,\n} from 'expo-modules-core';\nimport * as React from 'react';\nimport { Platform, View, findNodeHandle } from 'react-native';\n\nimport { configureLogging } from './GLUtils';\nimport {\n ComponentOrHandle,\n SurfaceCreateEvent,\n GLSnapshot,\n ExpoWebGLRenderingContext,\n SnapshotOptions,\n GLViewProps,\n} from './GLView.types';\nimport { createWorkletContextManager } from './GLWorkletContextManager';\n\n// @docsMissing\nexport type WebGLObject = {\n id: number;\n};\n\ndeclare let global: any;\n\nconst { ExponentGLObjectManager, ExponentGLViewManager } = NativeModulesProxy;\n\nconst NativeView = requireNativeViewManager('ExponentGLView');\nconst workletContextManager = createWorkletContextManager();\n\n// @needsAudit\n/**\n * A View that acts as an OpenGL ES render target. On mounting, an OpenGL ES context is created.\n * Its drawing buffer is presented as the contents of the View every frame.\n */\nexport class GLView extends React.Component<GLViewProps> {\n static NativeView: any;\n\n static defaultProps = {\n msaaSamples: 4,\n enableExperimentalWorkletSupport: false,\n };\n\n /**\n * Imperative API that creates headless context which is devoid of underlying view.\n * It's useful for headless rendering or in case you want to keep just one context per application and share it between multiple components.\n * It is slightly faster than usual context as it doesn't swap framebuffers and doesn't present them on the canvas,\n * however it may require you to take a snapshot in order to present its results.\n * Also, keep in mind that you need to set up a viewport and create your own framebuffer and texture that you will be drawing to, before you take a snapshot.\n * @return A promise that resolves to WebGL context object. See [WebGL API](#webgl-api) for more details.\n */\n static async createContextAsync(): Promise<ExpoWebGLRenderingContext> {\n const { exglCtxId } = await ExponentGLObjectManager.createContextAsync();\n return getGl(exglCtxId);\n }\n\n /**\n * Destroys given context.\n * @param exgl WebGL context to destroy.\n * @return A promise that resolves to boolean value that is `true` if given context existed and has been destroyed successfully.\n */\n static async destroyContextAsync(exgl?: ExpoWebGLRenderingContext | number): Promise<boolean> {\n const exglCtxId = getContextId(exgl);\n unregisterGLContext(exglCtxId);\n return ExponentGLObjectManager.destroyContextAsync(exglCtxId);\n }\n\n /**\n * Takes a snapshot of the framebuffer and saves it as a file to app's cache directory.\n * @param exgl WebGL context to take a snapshot from.\n * @param options\n * @return A promise that resolves to `GLSnapshot` object.\n */\n static async takeSnapshotAsync(\n exgl?: ExpoWebGLRenderingContext | number,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const exglCtxId = getContextId(exgl);\n return ExponentGLObjectManager.takeSnapshotAsync(exglCtxId, options);\n }\n\n static getWorkletContext: (contextId: number) => ExpoWebGLRenderingContext | undefined =\n workletContextManager.getContext;\n\n nativeRef: ComponentOrHandle = null;\n exglCtxId?: number;\n\n render() {\n const {\n onContextCreate, // eslint-disable-line no-unused-vars\n msaaSamples,\n enableExperimentalWorkletSupport,\n ...viewProps\n } = this.props;\n\n return (\n <View {...viewProps}>\n <NativeView\n ref={this._setNativeRef}\n style={{\n flex: 1,\n ...(Platform.OS === 'ios'\n ? {\n backgroundColor: 'transparent',\n }\n : {}),\n }}\n onSurfaceCreate={this._onSurfaceCreate}\n enableExperimentalWorkletSupport={enableExperimentalWorkletSupport}\n msaaSamples={Platform.OS === 'ios' ? msaaSamples : undefined}\n />\n </View>\n );\n }\n\n _setNativeRef = (nativeRef: ComponentOrHandle): void => {\n if (this.props.nativeRef_EXPERIMENTAL) {\n this.props.nativeRef_EXPERIMENTAL(nativeRef);\n }\n this.nativeRef = nativeRef;\n };\n\n _onSurfaceCreate = ({ nativeEvent: { exglCtxId } }: SurfaceCreateEvent): void => {\n const gl = getGl(exglCtxId);\n\n this.exglCtxId = exglCtxId;\n\n if (this.props.onContextCreate) {\n this.props.onContextCreate(gl);\n }\n };\n\n componentWillUnmount(): void {\n if (this.exglCtxId) {\n unregisterGLContext(this.exglCtxId);\n }\n }\n\n componentDidUpdate(prevProps: GLViewProps): void {\n if (\n this.props.enableExperimentalWorkletSupport !== prevProps.enableExperimentalWorkletSupport\n ) {\n console.warn('Updating prop enableExperimentalWorkletSupport is not supported');\n }\n }\n\n // @docsMissing\n async startARSessionAsync(): Promise<any> {\n if (!ExponentGLViewManager.startARSessionAsync) {\n throw new UnavailabilityError('expo-gl', 'startARSessionAsync');\n }\n return await ExponentGLViewManager.startARSessionAsync(findNodeHandle(this.nativeRef));\n }\n\n // @docsMissing\n async createCameraTextureAsync(cameraRefOrHandle: ComponentOrHandle): Promise<WebGLTexture> {\n if (!ExponentGLObjectManager.createCameraTextureAsync) {\n throw new UnavailabilityError('expo-gl', 'createCameraTextureAsync');\n }\n\n const { exglCtxId } = this;\n\n if (!exglCtxId) {\n throw new Error(\"GLView's surface is not created yet!\");\n }\n\n const cameraTag = findNodeHandle(cameraRefOrHandle);\n const { exglObjId } = await ExponentGLObjectManager.createCameraTextureAsync(\n exglCtxId,\n cameraTag\n );\n return { id: exglObjId } as WebGLTexture;\n }\n\n // @docsMissing\n async destroyObjectAsync(glObject: WebGLObject): Promise<boolean> {\n if (!ExponentGLObjectManager.destroyObjectAsync) {\n throw new UnavailabilityError('expo-gl', 'destroyObjectAsync');\n }\n return await ExponentGLObjectManager.destroyObjectAsync(glObject.id);\n }\n\n /**\n * Same as static [`takeSnapshotAsync()`](#glviewtakesnapshotasyncgl-options),\n * but uses WebGL context that is associated with the view on which the method is called.\n * @param options\n */\n async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n const { exglCtxId } = this;\n return await GLView.takeSnapshotAsync(exglCtxId, options);\n }\n}\n\nGLView.NativeView = NativeView;\n\nfunction unregisterGLContext(exglCtxId: number) {\n if (global.__EXGLContexts) {\n delete global.__EXGLContexts[String(exglCtxId)];\n }\n workletContextManager.unregister?.(exglCtxId);\n}\n\n// Get the GL interface from an EXGLContextId\nconst getGl = (exglCtxId: number): ExpoWebGLRenderingContext => {\n if (!global.__EXGLContexts) {\n throw new CodedError(\n 'ERR_GL_NOT_AVAILABLE',\n 'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)'\n );\n }\n const gl = global.__EXGLContexts[String(exglCtxId)];\n\n configureLogging(gl);\n\n return gl;\n};\n\nconst getContextId = (exgl?: ExpoWebGLRenderingContext | number): number => {\n const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;\n\n if (!exglCtxId || typeof exglCtxId !== 'number') {\n throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);\n }\n return exglCtxId;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"GLView.js","sourceRoot":"","sources":["../src/GLView.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAS7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AASxE,MAAM,uBAAuB,GAAG,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;AA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Manager,\n CodedError,\n} from 'expo-modules-core';\nimport * as React from 'react';\nimport { Platform, View, findNodeHandle } from 'react-native';\n\nimport { configureLogging } from './GLUtils';\nimport {\n ComponentOrHandle,\n SurfaceCreateEvent,\n GLSnapshot,\n ExpoWebGLRenderingContext,\n SnapshotOptions,\n GLViewProps,\n} from './GLView.types';\nimport { createWorkletContextManager } from './GLWorkletContextManager';\n\n// @docsMissing\nexport type WebGLObject = {\n id: number;\n};\n\ndeclare let global: any;\n\nconst ExponentGLObjectManager = requireNativeModule('ExponentGLObjectManager');\nconst { ExponentGLViewManager } = NativeModulesProxy;\n\nconst NativeView = requireNativeViewManager('ExponentGLView');\nconst workletContextManager = createWorkletContextManager();\n\n// @needsAudit\n/**\n * A View that acts as an OpenGL ES render target. On mounting, an OpenGL ES context is created.\n * Its drawing buffer is presented as the contents of the View every frame.\n */\nexport class GLView extends React.Component<GLViewProps> {\n static NativeView: any;\n\n static defaultProps = {\n msaaSamples: 4,\n enableExperimentalWorkletSupport: false,\n };\n\n /**\n * Imperative API that creates headless context which is devoid of underlying view.\n * It's useful for headless rendering or in case you want to keep just one context per application and share it between multiple components.\n * It is slightly faster than usual context as it doesn't swap framebuffers and doesn't present them on the canvas,\n * however it may require you to take a snapshot in order to present its results.\n * Also, keep in mind that you need to set up a viewport and create your own framebuffer and texture that you will be drawing to, before you take a snapshot.\n * @return A promise that resolves to WebGL context object. See [WebGL API](#webgl-api) for more details.\n */\n static async createContextAsync(): Promise<ExpoWebGLRenderingContext> {\n const { exglCtxId } = await ExponentGLObjectManager.createContextAsync();\n return getGl(exglCtxId);\n }\n\n /**\n * Destroys given context.\n * @param exgl WebGL context to destroy.\n * @return A promise that resolves to boolean value that is `true` if given context existed and has been destroyed successfully.\n */\n static async destroyContextAsync(exgl?: ExpoWebGLRenderingContext | number): Promise<boolean> {\n const exglCtxId = getContextId(exgl);\n unregisterGLContext(exglCtxId);\n return ExponentGLObjectManager.destroyContextAsync(exglCtxId);\n }\n\n /**\n * Takes a snapshot of the framebuffer and saves it as a file to app's cache directory.\n * @param exgl WebGL context to take a snapshot from.\n * @param options\n * @return A promise that resolves to `GLSnapshot` object.\n */\n static async takeSnapshotAsync(\n exgl?: ExpoWebGLRenderingContext | number,\n options: SnapshotOptions = {}\n ): Promise<GLSnapshot> {\n const exglCtxId = getContextId(exgl);\n return ExponentGLObjectManager.takeSnapshotAsync(exglCtxId, options);\n }\n\n static getWorkletContext: (contextId: number) => ExpoWebGLRenderingContext | undefined =\n workletContextManager.getContext;\n\n nativeRef: ComponentOrHandle = null;\n exglCtxId?: number;\n\n render() {\n const {\n onContextCreate, // eslint-disable-line no-unused-vars\n msaaSamples,\n enableExperimentalWorkletSupport,\n ...viewProps\n } = this.props;\n\n return (\n <View {...viewProps}>\n <NativeView\n ref={this._setNativeRef}\n style={{\n flex: 1,\n ...(Platform.OS === 'ios'\n ? {\n backgroundColor: 'transparent',\n }\n : {}),\n }}\n onSurfaceCreate={this._onSurfaceCreate}\n enableExperimentalWorkletSupport={enableExperimentalWorkletSupport}\n msaaSamples={Platform.OS === 'ios' ? msaaSamples : undefined}\n />\n </View>\n );\n }\n\n _setNativeRef = (nativeRef: ComponentOrHandle): void => {\n if (this.props.nativeRef_EXPERIMENTAL) {\n this.props.nativeRef_EXPERIMENTAL(nativeRef);\n }\n this.nativeRef = nativeRef;\n };\n\n _onSurfaceCreate = ({ nativeEvent: { exglCtxId } }: SurfaceCreateEvent): void => {\n const gl = getGl(exglCtxId);\n\n this.exglCtxId = exglCtxId;\n\n if (this.props.onContextCreate) {\n this.props.onContextCreate(gl);\n }\n };\n\n componentWillUnmount(): void {\n if (this.exglCtxId) {\n unregisterGLContext(this.exglCtxId);\n }\n }\n\n componentDidUpdate(prevProps: GLViewProps): void {\n if (\n this.props.enableExperimentalWorkletSupport !== prevProps.enableExperimentalWorkletSupport\n ) {\n console.warn('Updating prop enableExperimentalWorkletSupport is not supported');\n }\n }\n\n // @docsMissing\n async startARSessionAsync(): Promise<any> {\n if (!ExponentGLViewManager.startARSessionAsync) {\n throw new UnavailabilityError('expo-gl', 'startARSessionAsync');\n }\n return await ExponentGLViewManager.startARSessionAsync(findNodeHandle(this.nativeRef));\n }\n\n // @docsMissing\n async createCameraTextureAsync(cameraRefOrHandle: ComponentOrHandle): Promise<WebGLTexture> {\n if (!ExponentGLObjectManager.createCameraTextureAsync) {\n throw new UnavailabilityError('expo-gl', 'createCameraTextureAsync');\n }\n\n const { exglCtxId } = this;\n\n if (!exglCtxId) {\n throw new Error(\"GLView's surface is not created yet!\");\n }\n\n const cameraTag = findNodeHandle(cameraRefOrHandle);\n const { exglObjId } = await ExponentGLObjectManager.createCameraTextureAsync(\n exglCtxId,\n cameraTag\n );\n return { id: exglObjId } as WebGLTexture;\n }\n\n // @docsMissing\n async destroyObjectAsync(glObject: WebGLObject): Promise<boolean> {\n if (!ExponentGLObjectManager.destroyObjectAsync) {\n throw new UnavailabilityError('expo-gl', 'destroyObjectAsync');\n }\n return await ExponentGLObjectManager.destroyObjectAsync(glObject.id);\n }\n\n /**\n * Same as static [`takeSnapshotAsync()`](#glviewtakesnapshotasyncgl-options),\n * but uses WebGL context that is associated with the view on which the method is called.\n * @param options\n */\n async takeSnapshotAsync(options: SnapshotOptions = {}): Promise<GLSnapshot> {\n if (!GLView.takeSnapshotAsync) {\n throw new UnavailabilityError('expo-gl', 'takeSnapshotAsync');\n }\n const { exglCtxId } = this;\n return await GLView.takeSnapshotAsync(exglCtxId, options);\n }\n}\n\nGLView.NativeView = NativeView;\n\nfunction unregisterGLContext(exglCtxId: number) {\n if (global.__EXGLContexts) {\n delete global.__EXGLContexts[String(exglCtxId)];\n }\n workletContextManager.unregister?.(exglCtxId);\n}\n\n// Get the GL interface from an EXGLContextId\nconst getGl = (exglCtxId: number): ExpoWebGLRenderingContext => {\n if (!global.__EXGLContexts) {\n throw new CodedError(\n 'ERR_GL_NOT_AVAILABLE',\n 'GL is currently not available. (Have you enabled remote debugging? GL is not available while debugging remotely.)'\n );\n }\n const gl = global.__EXGLContexts[String(exglCtxId)];\n\n configureLogging(gl);\n\n return gl;\n};\n\nconst getContextId = (exgl?: ExpoWebGLRenderingContext | number): number => {\n const exglCtxId = exgl && typeof exgl === 'object' ? exgl.contextId : exgl;\n\n if (!exglCtxId || typeof exglCtxId !== 'number') {\n throw new Error(`Invalid EXGLContext id: ${String(exglCtxId)}`);\n }\n return exglCtxId;\n};\n"]}
|
package/build/GLView.types.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type SnapshotOptions = {
|
|
|
29
29
|
* Specifies what type of compression should be used and what is the result file extension.
|
|
30
30
|
* PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.
|
|
31
31
|
* > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.
|
|
32
|
-
* > It is
|
|
32
|
+
* > It is recommended to use [platform-specific](https://reactnative.dev/docs/platform-specific-code) code in this case.
|
|
33
33
|
* @default 'jpeg'
|
|
34
34
|
*/
|
|
35
35
|
format?: 'jpeg' | 'png' | 'webp';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLView.types.js","sourceRoot":"","sources":["../src/GLView.types.ts"],"names":[],"mappings":"AAwGA,cAAc;AACd,MAAM,CAAN,IAAY,eA2BX;AA3BD,WAAY,eAAe;IACzB;;OAEG;IACH,6DAAY,CAAA;IACZ;;OAEG;IACH,qEAAgB,CAAA;IAChB;;;OAGG;IACH,iEAAc,CAAA;IACd;;OAEG;IACH,+EAAqB,CAAA;IACrB;;;OAGG;IACH,6EAAoB,CAAA;IACpB;;OAEG;IACH,oDAAsE,CAAA;AACxE,CAAC,EA3BW,eAAe,KAAf,eAAe,QA2B1B","sourcesContent":["import { Component, ComponentClass } from 'react';\nimport { ViewProps } from 'react-native';\n\n// @docsMissing\nexport type SurfaceCreateEvent = {\n nativeEvent: {\n exglCtxId: number;\n };\n};\n\n// @needsAudit\nexport type SnapshotOptions = {\n /**\n * Whether to flip the snapshot vertically.\n * @default false\n */\n flip?: boolean;\n /**\n * Specify the framebuffer that we will be reading from.\n * Defaults to underlying framebuffer that is presented in the view or the current framebuffer if context is headless.\n */\n framebuffer?: WebGLFramebuffer;\n /**\n * Rect to crop the snapshot. It's passed directly to `glReadPixels`.\n */\n rect?: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n /**\n * Specifies what type of compression should be used and what is the result file extension.\n * PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.\n * > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.\n * > It is
|
|
1
|
+
{"version":3,"file":"GLView.types.js","sourceRoot":"","sources":["../src/GLView.types.ts"],"names":[],"mappings":"AAwGA,cAAc;AACd,MAAM,CAAN,IAAY,eA2BX;AA3BD,WAAY,eAAe;IACzB;;OAEG;IACH,6DAAY,CAAA;IACZ;;OAEG;IACH,qEAAgB,CAAA;IAChB;;;OAGG;IACH,iEAAc,CAAA;IACd;;OAEG;IACH,+EAAqB,CAAA;IACrB;;;OAGG;IACH,6EAAoB,CAAA;IACpB;;OAEG;IACH,oDAAsE,CAAA;AACxE,CAAC,EA3BW,eAAe,KAAf,eAAe,QA2B1B","sourcesContent":["import { Component, ComponentClass } from 'react';\nimport { ViewProps } from 'react-native';\n\n// @docsMissing\nexport type SurfaceCreateEvent = {\n nativeEvent: {\n exglCtxId: number;\n };\n};\n\n// @needsAudit\nexport type SnapshotOptions = {\n /**\n * Whether to flip the snapshot vertically.\n * @default false\n */\n flip?: boolean;\n /**\n * Specify the framebuffer that we will be reading from.\n * Defaults to underlying framebuffer that is presented in the view or the current framebuffer if context is headless.\n */\n framebuffer?: WebGLFramebuffer;\n /**\n * Rect to crop the snapshot. It's passed directly to `glReadPixels`.\n */\n rect?: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n /**\n * Specifies what type of compression should be used and what is the result file extension.\n * PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.\n * > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.\n * > It is recommended to use [platform-specific](https://reactnative.dev/docs/platform-specific-code) code in this case.\n * @default 'jpeg'\n */\n format?: 'jpeg' | 'png' | 'webp';\n /**\n * A value in range `0` to `1.0` specifying compression level of the result image.\n * `1.0` means no compression and `0` the highest compression.\n * @default 1.0\n */\n compress?: number;\n};\n\n// @needsAudit\nexport type GLSnapshot = {\n /**\n * URI to the snapshot.\n */\n uri: string | Blob | null;\n /**\n * Synonym for `uri`. Makes snapshot object compatible with `texImage2D`.\n */\n localUri: string;\n /**\n * Width of the snapshot.\n */\n width: number;\n /**\n * Height of the snapshot.\n */\n height: number;\n};\n\n// @docsMissing\nexport interface ExpoWebGLRenderingContext extends WebGL2RenderingContext {\n contextId: number;\n endFrameEXP(): void;\n flushEXP(): void;\n __expoSetLogging(option: GLLoggingOption): void;\n}\n\n// @docsMissing\nexport type ComponentOrHandle = null | number | Component<any, any> | ComponentClass<any>;\n\n// @needsAudit\nexport type GLViewProps = {\n /**\n * A function that will be called when the OpenGL ES context is created.\n * The function is passed a single argument `gl` that extends a [WebGLRenderingContext](https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14) interface.\n */\n onContextCreate(gl: ExpoWebGLRenderingContext): void;\n /**\n * `GLView` can enable iOS's built-in [multisampling](https://www.khronos.org/registry/OpenGL/extensions/APPLE/APPLE_framebuffer_multisample.txt).\n * This prop specifies the number of samples to use. Setting this to `0` turns off multisampling.\n * @platform ios\n * @default 4\n */\n msaaSamples: number;\n /**\n * Enables support for interacting with a `gl` object from code running on the Reanimated worklet thread.\n * @default false\n */\n enableExperimentalWorkletSupport: boolean;\n /**\n * @hidden\n * A ref callback for the native GLView\n */\n nativeRef_EXPERIMENTAL?(callback: ComponentOrHandle | null);\n} & ViewProps;\n\n// @needsAudit\nexport enum GLLoggingOption {\n /**\n * Disables logging entirely.\n */\n DISABLED = 0,\n /**\n * Logs method calls, their parameters and results.\n */\n METHOD_CALLS = 1,\n /**\n * Calls `gl.getError()` after each other method call and prints an error if any is returned.\n * This option has a significant impact on the performance as this method is blocking.\n */\n GET_ERRORS = 2,\n /**\n * Resolves parameters of type `number` to their constant names.\n */\n RESOLVE_CONSTANTS = 4,\n /**\n * When this option is enabled, long strings will be truncated.\n * It's useful if your shaders are really big and logging them significantly reduces performance.\n */\n TRUNCATE_STRINGS = 8,\n /**\n * Enables all other options. It implies `GET_ERRORS` so be aware of the slowdown.\n */\n ALL = METHOD_CALLS | GET_ERRORS | RESOLVE_CONSTANTS | TRUNCATE_STRINGS,\n}\n"]}
|
package/expo-module.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gl",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.0",
|
|
4
4
|
"description": "Provides GLView that acts as OpenGL ES render target and gives GL context object implementing WebGL 2.0 specification.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"expo": "*"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "ee2c866ba3c7fbc35ff2a3e896041cf15d3bd7c5"
|
|
53
53
|
}
|
package/src/GLView.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NativeModulesProxy,
|
|
3
3
|
UnavailabilityError,
|
|
4
|
+
requireNativeModule,
|
|
4
5
|
requireNativeViewManager,
|
|
5
6
|
CodedError,
|
|
6
7
|
} from 'expo-modules-core';
|
|
@@ -25,7 +26,8 @@ export type WebGLObject = {
|
|
|
25
26
|
|
|
26
27
|
declare let global: any;
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
+
const ExponentGLObjectManager = requireNativeModule('ExponentGLObjectManager');
|
|
30
|
+
const { ExponentGLViewManager } = NativeModulesProxy;
|
|
29
31
|
|
|
30
32
|
const NativeView = requireNativeViewManager('ExponentGLView');
|
|
31
33
|
const workletContextManager = createWorkletContextManager();
|
package/src/GLView.types.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type SnapshotOptions = {
|
|
|
33
33
|
* Specifies what type of compression should be used and what is the result file extension.
|
|
34
34
|
* PNG compression is lossless but slower, JPEG is faster but the image has visible artifacts.
|
|
35
35
|
* > **Note:** When using WebP format, the iOS version will print a warning, and generate a `'png'` file instead.
|
|
36
|
-
* > It is
|
|
36
|
+
* > It is recommended to use [platform-specific](https://reactnative.dev/docs/platform-specific-code) code in this case.
|
|
37
37
|
* @default 'jpeg'
|
|
38
38
|
*/
|
|
39
39
|
format?: 'jpeg' | 'png' | 'webp';
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-present 650 Industries. All rights reserved.
|
|
2
|
-
|
|
3
|
-
package expo.modules.gl;
|
|
4
|
-
|
|
5
|
-
import android.content.Context;
|
|
6
|
-
import android.os.Bundle;
|
|
7
|
-
import android.util.SparseArray;
|
|
8
|
-
|
|
9
|
-
import java.util.Map;
|
|
10
|
-
|
|
11
|
-
import expo.modules.core.ExportedModule;
|
|
12
|
-
import expo.modules.core.ModuleRegistry;
|
|
13
|
-
import expo.modules.core.Promise;
|
|
14
|
-
import expo.modules.core.interfaces.ExpoMethod;
|
|
15
|
-
import expo.modules.core.interfaces.services.UIManager;
|
|
16
|
-
|
|
17
|
-
import expo.modules.interfaces.camera.CameraViewInterface;
|
|
18
|
-
|
|
19
|
-
public class GLObjectManagerModule extends ExportedModule {
|
|
20
|
-
private SparseArray<GLObject> mGLObjects = new SparseArray<>();
|
|
21
|
-
private SparseArray<GLContext> mGLContextMap = new SparseArray<>();
|
|
22
|
-
|
|
23
|
-
private ModuleRegistry mModuleRegistry;
|
|
24
|
-
|
|
25
|
-
public GLObjectManagerModule(Context context) {
|
|
26
|
-
super(context);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Override
|
|
30
|
-
public String getName() {
|
|
31
|
-
return "ExponentGLObjectManager";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Override
|
|
35
|
-
public void onCreate(ModuleRegistry moduleRegistry) {
|
|
36
|
-
mModuleRegistry = moduleRegistry;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public ModuleRegistry getModuleRegistry() {
|
|
40
|
-
return mModuleRegistry;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public GLContext getContextWithId(int exglCtxId) {
|
|
44
|
-
return mGLContextMap.get(exglCtxId);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public void saveContext(final GLContext glContext) {
|
|
48
|
-
mGLContextMap.put(glContext.getContextId(), glContext);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public void deleteContextWithId(final int exglCtxId) {
|
|
52
|
-
mGLContextMap.delete(exglCtxId);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@ExpoMethod
|
|
56
|
-
public void destroyObjectAsync(final int exglObjId, final Promise promise) {
|
|
57
|
-
GLObject glObject = mGLObjects.get(exglObjId);
|
|
58
|
-
if (glObject != null) {
|
|
59
|
-
mGLObjects.remove(exglObjId);
|
|
60
|
-
glObject.destroy();
|
|
61
|
-
promise.resolve(true);
|
|
62
|
-
} else {
|
|
63
|
-
promise.resolve(false);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@ExpoMethod
|
|
68
|
-
public void createCameraTextureAsync(final int exglCtxId, final int cameraViewTag, final Promise promise) {
|
|
69
|
-
UIManager uiManager = mModuleRegistry.getModule(UIManager.class);
|
|
70
|
-
|
|
71
|
-
if (uiManager == null) {
|
|
72
|
-
promise.reject("E_UI_MANAGER_NOT_FOUND", "UIManager not found in module registry.");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
uiManager.addUIBlock(cameraViewTag, new UIManager.UIBlock<CameraViewInterface>() {
|
|
77
|
-
@Override
|
|
78
|
-
public void resolve(final CameraViewInterface cameraView) {
|
|
79
|
-
final GLContext glContext = getContextWithId(exglCtxId);
|
|
80
|
-
|
|
81
|
-
if (glContext == null) {
|
|
82
|
-
promise.reject("E_GL_NO_CONTEXT", "ExponentGLObjectManager.createCameraTextureAsync: GLContext not found for given context id.");
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
glContext.runAsync(new Runnable() {
|
|
87
|
-
@Override
|
|
88
|
-
public void run() {
|
|
89
|
-
GLCameraObject cameraTexture = new GLCameraObject(glContext, cameraView);
|
|
90
|
-
|
|
91
|
-
int exglObjId = cameraTexture.getEXGLObjId();
|
|
92
|
-
mGLObjects.put(exglObjId, cameraTexture);
|
|
93
|
-
|
|
94
|
-
Bundle response = new Bundle();
|
|
95
|
-
response.putInt("exglObjId", exglObjId);
|
|
96
|
-
promise.resolve(response);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@Override
|
|
102
|
-
public void reject(Throwable throwable) {
|
|
103
|
-
promise.reject("E_GL_BAD_CAMERA_VIEW_TAG", "ExponentGLObjectManager.createCameraTextureAsync: Expected a CameraView", throwable);
|
|
104
|
-
}
|
|
105
|
-
}, CameraViewInterface.class);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
@ExpoMethod
|
|
109
|
-
public void takeSnapshotAsync(final int exglCtxId, final Map<String, Object> options, final Promise promise) {
|
|
110
|
-
GLContext glContext = getContextWithId(exglCtxId);
|
|
111
|
-
|
|
112
|
-
if (glContext == null) {
|
|
113
|
-
promise.reject("E_GL_NO_CONTEXT", "ExponentGLObjectManager.takeSnapshotAsync: GLContext not found for given context id.");
|
|
114
|
-
} else {
|
|
115
|
-
glContext.takeSnapshot(options, getContext(), promise);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@ExpoMethod
|
|
120
|
-
public void createContextAsync(final Promise promise) {
|
|
121
|
-
final GLContext glContext = new GLContext(this);
|
|
122
|
-
|
|
123
|
-
glContext.initialize(null, false, new Runnable() {
|
|
124
|
-
@Override
|
|
125
|
-
public void run() {
|
|
126
|
-
Bundle results = new Bundle();
|
|
127
|
-
results.putInt("exglCtxId", glContext.getContextId());
|
|
128
|
-
promise.resolve(results);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
@ExpoMethod
|
|
134
|
-
public void destroyContextAsync(final int exglCtxId, final Promise promise) {
|
|
135
|
-
GLContext glContext = getContextWithId(exglCtxId);
|
|
136
|
-
|
|
137
|
-
if (glContext != null) {
|
|
138
|
-
glContext.destroy();
|
|
139
|
-
promise.resolve(true);
|
|
140
|
-
} else {
|
|
141
|
-
promise.resolve(false);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
package expo.modules.gl;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
|
|
5
|
-
import java.util.Collections;
|
|
6
|
-
import java.util.List;
|
|
7
|
-
|
|
8
|
-
import expo.modules.core.ExportedModule;
|
|
9
|
-
import expo.modules.core.BasePackage;
|
|
10
|
-
|
|
11
|
-
public class GLPackage extends BasePackage {
|
|
12
|
-
@Override
|
|
13
|
-
public List<ExportedModule> createExportedModules(Context context) {
|
|
14
|
-
return Collections.singletonList((ExportedModule) new GLObjectManagerModule(context));
|
|
15
|
-
}
|
|
16
|
-
}
|