react-native-wgpu 0.1.5 → 0.1.7
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/README.md +43 -42
- package/android/cpp/AndroidPlatformContext.h +2 -1
- package/cpp/jsi/RNFJSIConverter.h +10 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +1 -2
- package/cpp/rnwgpu/api/Canvas.h +3 -3
- package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
- package/ios/WebGPUView.mm +14 -1
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/utils.js +2 -2
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/utils.js +2 -2
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/lib/commonjs/utils.d.ts +1 -1
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -1
- package/lib/typescript/lib/module/utils.d.ts +1 -1
- package/lib/typescript/lib/module/utils.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +3 -2
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Constants.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Device.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Device.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/GPU.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/Texture.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/DrawingContext.d.ts +12 -0
- package/lib/typescript/src/__tests__/components/DrawingContext.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +3 -0
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +29 -0
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +5 -0
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/cube.d.ts +7 -0
- package/lib/typescript/src/__tests__/components/cube.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +22 -0
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +12 -0
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +7 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +6 -0
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +6 -0
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +10 -0
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/components/triangle.d.ts +3 -0
- package/lib/typescript/src/__tests__/components/triangle.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/config.d.ts +3 -0
- package/lib/typescript/src/__tests__/config.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/globalSetup.d.ts +10 -0
- package/lib/typescript/src/__tests__/globalSetup.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/globalTeardown.d.ts +3 -0
- package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/setup.d.ts +62 -0
- package/lib/typescript/src/__tests__/setup.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +2 -1
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/{ios/libwebgpu_dawn.xcframework/ios-arm64 → apple/arm64_iphoneos}/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn.a +0 -0
- package/libs/{ios/arm64_iphoneos → apple/libwebgpu_dawn.xcframework/ios-arm64}/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn_macosx.xcframework/Info.plist +28 -0
- package/libs/apple/libwebgpu_dawn_macosx.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/libs/{ios/libwebgpu_dawn_visionos.xcframework/xros-arm64_x86_64-simulator → apple}/libwebgpu_dawn_visionos.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn_visionos.xcframework/Info.plist +2 -2
- package/libs/{ios/arm64_xros/libwebgpu_dawn_visionos.a → apple/libwebgpu_dawn_visionos.xcframework/xros-arm64/libwebgpu_dawn.a} +0 -0
- package/libs/{ios → apple/libwebgpu_dawn_visionos.xcframework/xros-arm64_x86_64-simulator}/libwebgpu_dawn_visionos.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/{ios → apple}/x86_64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/package.json +23 -22
- package/react-native-wgpu.podspec +2 -2
- package/src/Canvas.tsx +4 -2
- package/src/__tests__/ArrayBuffer.spec.ts +76 -0
- package/src/__tests__/Buffer.spec.ts +357 -0
- package/src/__tests__/ComputeShader.spec.ts +375 -0
- package/src/__tests__/Constants.spec.ts +91 -0
- package/src/__tests__/Device.spec.ts +35 -0
- package/src/__tests__/ExternalTexture.spec.ts +284 -0
- package/src/__tests__/GPU.spec.ts +229 -0
- package/src/__tests__/ImageData.spec.ts +26 -0
- package/src/__tests__/Shaders.spec.ts +232 -0
- package/src/__tests__/Texture.spec.ts +191 -0
- package/src/__tests__/assets/Di-3d.png +0 -0
- package/src/__tests__/components/DrawingContext.ts +11 -0
- package/src/__tests__/components/Wireframe/Shaders.ts +138 -0
- package/src/__tests__/components/Wireframe/models.ts +113 -0
- package/src/__tests__/components/Wireframe/utils.ts +22 -0
- package/src/__tests__/components/cube.ts +51 -0
- package/src/__tests__/components/meshes/mesh.ts +96 -0
- package/src/__tests__/components/meshes/sphere.ts +103 -0
- package/src/__tests__/components/meshes/stanfordDragon.ts +44 -0
- package/src/__tests__/components/meshes/stanfordDragonData.ts +5 -0
- package/src/__tests__/components/meshes/teapot.ts +13 -0
- package/src/__tests__/components/meshes/utils.ts +235 -0
- package/src/__tests__/components/triangle.ts +17 -0
- package/src/__tests__/config.ts +2 -0
- package/src/__tests__/demos/ABuffer.spec.ts +885 -0
- package/src/__tests__/demos/Blur.spec.ts +397 -0
- package/src/__tests__/demos/Cube.spec.ts +925 -0
- package/src/__tests__/demos/FractalCube.spec.ts +239 -0
- package/src/__tests__/demos/OcclusionQuery.spec.ts +376 -0
- package/src/__tests__/demos/RenderBundles.spec.ts +579 -0
- package/src/__tests__/demos/Triangle.spec.ts +248 -0
- package/src/__tests__/demos/Wireframe.spec.ts +190 -0
- package/src/__tests__/globalSetup.ts +54 -0
- package/src/__tests__/globalTeardown.ts +11 -0
- package/src/__tests__/setup.ts +409 -0
- package/src/__tests__/snapshots/abuffer.png +0 -0
- package/src/__tests__/snapshots/asteroid.png +0 -0
- package/src/__tests__/snapshots/blur.png +0 -0
- package/src/__tests__/snapshots/buffer.png +0 -0
- package/src/__tests__/snapshots/constant-triangle.png +0 -0
- package/src/__tests__/snapshots/cube.png +0 -0
- package/src/__tests__/snapshots/f.png +0 -0
- package/src/__tests__/snapshots/f2.png +0 -0
- package/src/__tests__/snapshots/fractal-cubes.png +0 -0
- package/src/__tests__/snapshots/instanced-cubes.png +0 -0
- package/src/__tests__/snapshots/occlusion-query.png +0 -0
- package/src/__tests__/snapshots/ref.png +0 -0
- package/src/__tests__/snapshots/texture.png +0 -0
- package/src/__tests__/snapshots/textured-cube.png +0 -0
- package/src/__tests__/snapshots/triangle-msaa.png +0 -0
- package/src/__tests__/snapshots/triangle.png +0 -0
- package/src/__tests__/snapshots/two-cube.png +0 -0
- package/src/utils.ts +3 -1
- package/android/gradle.properties +0 -5
- package/libs/ios/libwebgpu_dawn_visionos.xcframework/xros-arm64/libwebgpu_dawn_visionos.a +0 -0
- package/libs/{ios → apple}/libwebgpu_dawn.xcframework/Info.plist +5 -5
package/README.md
CHANGED
|
@@ -11,22 +11,28 @@ Please note that the package name is `react-native-wgpu`.
|
|
|
11
11
|
npm install react-native-wgpu
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
Below are some examples from the [example app](/package/example/).
|
|
15
|
+
|
|
16
|
+
https://github.com/user-attachments/assets/116a41b2-2cf8-49f1-9f16-a5c83637c198
|
|
17
|
+
|
|
18
|
+
Starting from `r168`, Three.js runs out of the box with React Native WebGPU.
|
|
19
|
+
You need to have a slight modification of [the metro config](/package/example/metro.config.js) to resolve Three.js to the WebGPU build.
|
|
20
|
+
|
|
21
|
+
https://github.com/user-attachments/assets/5b49ef63-0a3c-4679-aeb5-e4b4dddfcc1d
|
|
22
|
+
|
|
14
23
|
## Usage
|
|
15
24
|
|
|
16
|
-
|
|
25
|
+
Currently we recommend to use the `useCanvasEffect` to access the WebGPU context.
|
|
17
26
|
|
|
18
27
|
```tsx
|
|
19
|
-
import React
|
|
28
|
+
import React from "react";
|
|
20
29
|
import { StyleSheet, View, PixelRatio } from "react-native";
|
|
21
|
-
import
|
|
22
|
-
import { Canvas } from "react-native-webgpu";
|
|
30
|
+
import { Canvas, useCanvasEffect } from "react-native-wgpu";
|
|
23
31
|
|
|
24
32
|
import { redFragWGSL, triangleVertWGSL } from "./triangle";
|
|
25
33
|
|
|
26
34
|
export function HelloTriangle() {
|
|
27
|
-
const ref =
|
|
28
|
-
|
|
29
|
-
async function demo() {
|
|
35
|
+
const ref = useCanvasEffect(async () => {
|
|
30
36
|
const adapter = await navigator.gpu.requestAdapter();
|
|
31
37
|
if (!adapter) {
|
|
32
38
|
throw new Error("No adapter");
|
|
@@ -35,6 +41,7 @@ export function HelloTriangle() {
|
|
|
35
41
|
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
|
36
42
|
|
|
37
43
|
const context = ref.current!.getContext("webgpu")!;
|
|
44
|
+
const canvas = context.canvas as HTMLCanvasElement;
|
|
38
45
|
canvas.width = canvas.clientWidth * PixelRatio.get();
|
|
39
46
|
canvas.height = canvas.clientHeight * PixelRatio.get();
|
|
40
47
|
|
|
@@ -95,11 +102,7 @@ export function HelloTriangle() {
|
|
|
95
102
|
device.queue.submit([commandEncoder.finish()]);
|
|
96
103
|
|
|
97
104
|
context.present();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
demo();
|
|
102
|
-
}, []);
|
|
105
|
+
});
|
|
103
106
|
|
|
104
107
|
return (
|
|
105
108
|
<View style={style.container}>
|
|
@@ -118,6 +121,18 @@ const style = StyleSheet.create({
|
|
|
118
121
|
});
|
|
119
122
|
```
|
|
120
123
|
|
|
124
|
+
## Example App
|
|
125
|
+
|
|
126
|
+
To run the example app you first need to build Dawn.
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
$ git submodule update --init
|
|
130
|
+
$ cd package && yarn
|
|
131
|
+
$ yarn build-dawn
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
From there you will be able to run the example app properly.
|
|
135
|
+
|
|
121
136
|
## Similarities and Differences with the Web
|
|
122
137
|
|
|
123
138
|
The API has been designed to be completely symmetric with the Web.
|
|
@@ -133,8 +148,6 @@ ctx.canvas.width = ctx.canvas.clientWidth * PixelRatio.get();
|
|
|
133
148
|
ctx.canvas.height = ctx.canvas.clientHeight * PixelRatio.get();
|
|
134
149
|
```
|
|
135
150
|
|
|
136
|
-
However, there are two differences with the Web: frame scheduling and external textures.
|
|
137
|
-
|
|
138
151
|
### Frame Scheduling
|
|
139
152
|
|
|
140
153
|
In React Native, we want to keep frame presentation as a manual operation as we plan to provide more advanced rendering options that are React Native specific.
|
|
@@ -150,35 +163,25 @@ context.present();
|
|
|
150
163
|
|
|
151
164
|
### External Textures
|
|
152
165
|
|
|
153
|
-
|
|
154
|
-
Consider the following Web example:
|
|
166
|
+
This module provides a `createImageBitmap` function that you can use in `copyExternalImageToTexture`.
|
|
155
167
|
|
|
156
168
|
```tsx
|
|
157
|
-
const
|
|
169
|
+
const url = Image.resolveAssetSource(require("./assets/image.png")).uri;
|
|
170
|
+
const response = await fetch(url);
|
|
158
171
|
const imageBitmap = await createImageBitmap(await response.blob());
|
|
159
172
|
|
|
173
|
+
const texture = device.createTexture({
|
|
174
|
+
size: [imageBitmap.width, imageBitmap.height, 1],
|
|
175
|
+
format: "rgba8unorm",
|
|
176
|
+
usage:
|
|
177
|
+
GPUTextureUsage.TEXTURE_BINDING |
|
|
178
|
+
GPUTextureUsage.COPY_DST |
|
|
179
|
+
GPUTextureUsage.RENDER_ATTACHMENT,
|
|
180
|
+
});
|
|
160
181
|
device.queue.copyExternalImageToTexture(
|
|
161
182
|
{ source: imageBitmap },
|
|
162
|
-
{ texture
|
|
163
|
-
[imageBitmap.width, imageBitmap.height]
|
|
164
|
-
);
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
In React Native, you would need to load the texture yourself.
|
|
168
|
-
For instance, we use Skia for image decoding [here](/package/example/src/components/useAssets.ts#L6).
|
|
169
|
-
|
|
170
|
-
```tsx
|
|
171
|
-
const imageBitmap = await decodeImage(require("./assets/Di-3d.png"));
|
|
172
|
-
|
|
173
|
-
device.queue.writeTexture(
|
|
174
|
-
{ texture: cubeTexture, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } },
|
|
175
|
-
imageBitmap.data.buffer,
|
|
176
|
-
{
|
|
177
|
-
offset: 0,
|
|
178
|
-
bytesPerRow: 4 * imageBitmap.width,
|
|
179
|
-
rowsPerImage: imageBitmap.height,
|
|
180
|
-
},
|
|
181
|
-
{ width: imageBitmap.width, height: imageBitmap.height },
|
|
183
|
+
{ texture },
|
|
184
|
+
[imageBitmap.width, imageBitmap.height],
|
|
182
185
|
);
|
|
183
186
|
```
|
|
184
187
|
|
|
@@ -193,9 +196,7 @@ In "Edit Scheme," uncheck "Metal Validation."
|
|
|
193
196
|
|
|
194
197
|
### Android
|
|
195
198
|
|
|
196
|
-
On
|
|
197
|
-
On a simulator, you need Android API level 34 or higher.
|
|
198
|
-
We are currently working on relaxing that rule for Android simulators.
|
|
199
|
+
On an Android simulator, a CPU emulation layer is used which may result in very slow performance.
|
|
199
200
|
|
|
200
201
|
## Library Development
|
|
201
202
|
|
|
@@ -209,7 +210,7 @@ Make sure you have all the tools required for building the Skia libraries (Andro
|
|
|
209
210
|
|
|
210
211
|
### Building
|
|
211
212
|
|
|
212
|
-
* `cd
|
|
213
|
+
* `cd packages/webgpu && yarn`
|
|
213
214
|
* `yarn build-dawn`
|
|
214
215
|
|
|
215
216
|
### Upgrading
|
|
@@ -220,7 +221,7 @@ Make sure you have all the tools required for building the Skia libraries (Andro
|
|
|
220
221
|
|
|
221
222
|
### Codegen
|
|
222
223
|
|
|
223
|
-
* `cd
|
|
224
|
+
* `cd packages/webgpu && yarn codegen`
|
|
224
225
|
|
|
225
226
|
### Testing
|
|
226
227
|
|
|
@@ -22,7 +22,8 @@ private:
|
|
|
22
22
|
jobject _blobModule;
|
|
23
23
|
|
|
24
24
|
public:
|
|
25
|
-
explicit AndroidPlatformContext(jobject blobModule)
|
|
25
|
+
explicit AndroidPlatformContext(jobject blobModule)
|
|
26
|
+
: _blobModule(blobModule) {}
|
|
26
27
|
~AndroidPlatformContext() {
|
|
27
28
|
if (_blobModule) {
|
|
28
29
|
JNIEnv *env = facebook::jni::Environment::current();
|
|
@@ -137,6 +137,16 @@ template <> struct JSIConverter<uint64_t> {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
template <> struct JSIConverter<void *> {
|
|
141
|
+
static void* fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
142
|
+
return reinterpret_cast<void *>(arg.asBigInt(runtime).getUint64(runtime));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, void* arg) {
|
|
146
|
+
return jsi::BigInt::fromUint64(runtime, reinterpret_cast<uint64_t>(arg));
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
140
150
|
// bool <> boolean
|
|
141
151
|
template <> struct JSIConverter<bool> {
|
|
142
152
|
static bool fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
|
|
@@ -15,8 +15,7 @@ class SurfaceRegistry {
|
|
|
15
15
|
public:
|
|
16
16
|
void addSurface(const int contextId, void *surface, float width,
|
|
17
17
|
float height) {
|
|
18
|
-
_registry[contextId] = std::make_shared<Canvas>(
|
|
19
|
-
reinterpret_cast<uint64_t>(surface), width, height);
|
|
18
|
+
_registry[contextId] = std::make_shared<Canvas>(surface, width, height);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
std::shared_ptr<Canvas> getSurface(const int contextId) {
|
package/cpp/rnwgpu/api/Canvas.h
CHANGED
|
@@ -15,7 +15,7 @@ namespace m = margelo;
|
|
|
15
15
|
|
|
16
16
|
class Canvas : public m::HybridObject {
|
|
17
17
|
public:
|
|
18
|
-
explicit Canvas(
|
|
18
|
+
explicit Canvas(void* surface, const float width, const float height)
|
|
19
19
|
: HybridObject("Canvas"), _surface(surface), _width(width),
|
|
20
20
|
_height(height), _clientWidth(width), _clientHeight(height) {}
|
|
21
21
|
|
|
@@ -32,7 +32,7 @@ public:
|
|
|
32
32
|
|
|
33
33
|
void setClientHeight(const float height) { _clientHeight = height; }
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
void* getSurface() { return _surface; }
|
|
36
36
|
|
|
37
37
|
void loadHybridMethods() override {
|
|
38
38
|
registerHybridGetter("surface", &Canvas::getSurface, this);
|
|
@@ -45,7 +45,7 @@ public:
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
private:
|
|
48
|
-
|
|
48
|
+
void* _surface;
|
|
49
49
|
float _width;
|
|
50
50
|
float _height;
|
|
51
51
|
float _clientWidth;
|
package/ios/WebGPUView.mm
CHANGED
|
@@ -49,7 +49,20 @@ static NSMutableDictionary<NSNumber *, MetalView *> *metalViewRegistry =
|
|
|
49
49
|
- (void)prepareForRecycle {
|
|
50
50
|
[super prepareForRecycle];
|
|
51
51
|
self.contentView = nil;
|
|
52
|
-
[metalViewRegistry
|
|
52
|
+
if ([metalViewRegistry objectForKey:_contextId] != nil) {
|
|
53
|
+
[metalViewRegistry removeObjectForKey:_contextId];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps {
|
|
58
|
+
const auto &oldViewProps = *std::static_pointer_cast<const WebGPUViewProps>(_props);
|
|
59
|
+
const auto &newViewProps = *std::static_pointer_cast<const WebGPUViewProps>(props);
|
|
60
|
+
|
|
61
|
+
if (newViewProps.contextId != oldViewProps.contextId) {
|
|
62
|
+
_contextId = [[NSNumber alloc] initWithInt:newViewProps.contextId];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
[super updateProps:props oldProps:oldProps];
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
- (void)updateLayoutMetrics:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_WebGPUViewNativeComponent","_interopRequireDefault","_NativeWebGPUModule","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","CONTEXT_COUNTER","generateContextId","global","__WebGPUContextRegistry","WebGPUContextRegistry","Canvas","exports","forwardRef","props","ref","contextId","_","useState","useImperativeHandle","getNativeSurface","WebGPUNativeModule","createSurfaceContext","getContext","contextName","Error","nativeSurface","ctx","RNWebGPU","MakeWebGPUCanvasContext","useEffect","React","createElement"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,0BAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAsD,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OAAAN,SAAA;AAEtD,IAAIO,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;
|
|
1
|
+
{"version":3,"names":["_react","require","_WebGPUViewNativeComponent","_interopRequireDefault","_NativeWebGPUModule","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","CONTEXT_COUNTER","generateContextId","global","__WebGPUContextRegistry","WebGPUContextRegistry","Canvas","exports","forwardRef","props","ref","contextId","_","useState","useImperativeHandle","getNativeSurface","WebGPUNativeModule","createSurfaceContext","getContext","contextName","Error","nativeSurface","ctx","RNWebGPU","MakeWebGPUCanvasContext","useEffect","React","createElement"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,0BAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAsD,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OAAAN,SAAA;AAEtD,IAAIO,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AAwBAE,MAAM,CAACC,uBAAuB,GAAG,CAAC,CAAC;AACnC,MAAMC,qBAAqB,GAAGF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|
|
13
13
|
exports.warnIfNotHardwareAccelerated = warnIfNotHardwareAccelerated;
|
|
14
|
-
const useCanvasEffect = effect => {
|
|
14
|
+
const useCanvasEffect = (effect, deps = []) => {
|
|
15
15
|
const ref = (0, _react.useRef)(null);
|
|
16
16
|
const unsubscribe = (0, _react.useRef)();
|
|
17
17
|
(0, _react.useEffect)(() => {
|
|
@@ -32,7 +32,7 @@ const useCanvasEffect = effect => {
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
},
|
|
35
|
+
}, deps);
|
|
36
36
|
return ref;
|
|
37
37
|
};
|
|
38
38
|
exports.useCanvasEffect = useCanvasEffect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","warnIfNotHardwareAccelerated","adapter","info","architecture","console","warn","exports","useCanvasEffect","effect","ref","useRef","unsubscribe","useEffect","requestAnimationFrame","unsub","current"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["_react","require","warnIfNotHardwareAccelerated","adapter","info","architecture","console","warn","exports","useCanvasEffect","effect","deps","ref","useRef","unsubscribe","useEffect","requestAnimationFrame","unsub","current"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAMO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAK;EACnE,IAAIA,OAAO,CAACC,IAAI,CAACC,YAAY,KAAK,aAAa,EAAE;IAC/CC,OAAO,CAACC,IAAI,CACV,sGACF,CAAC;EACH;AACF,CAAC;AAACC,OAAA,CAAAN,4BAAA,GAAAA,4BAAA;AAEK,MAAMO,eAAe,GAAGA,CAC7BC,MAA8D,EAC9DC,IAAoB,GAAG,EAAE,KACtB;EACH,MAAMC,GAAG,GAAG,IAAAC,aAAM,EAAY,IAAI,CAAC;EACnC,MAAMC,WAAW,GAAG,IAAAD,aAAM,EAAc,CAAC;EACzC,IAAAE,gBAAS,EAAC,MAAM;IACdC,qBAAqB,CAAC,YAAY;MAChC;MACA;MACA;MACA;MACA;MACA,MAAMC,KAAK,GAAG,MAAMP,MAAM,CAAC,CAAC;MAC5B,IAAIO,KAAK,EAAE;QACTH,WAAW,CAACI,OAAO,GAAGD,KAAK;MAC7B;IACF,CAAC,CAAC;IACF,OAAO,MAAM;MACX,IAAIH,WAAW,CAACI,OAAO,EAAE;QACvBJ,WAAW,CAACI,OAAO,CAAC,CAAC;MACvB;IACF,CAAC;IACD;EACF,CAAC,EAAEP,IAAI,CAAC;EACR,OAAOC,GAAG;AACZ,CAAC;AAACJ,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}
|
package/lib/module/Canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useEffect","useImperativeHandle","useState","WebGPUNativeView","WebGPUNativeModule","CONTEXT_COUNTER","generateContextId","global","__WebGPUContextRegistry","WebGPUContextRegistry","Canvas","props","ref","contextId","_","getNativeSurface","createSurfaceContext","getContext","contextName","Error","nativeSurface","ctx","RNWebGPU","MakeWebGPUCanvasContext","React","createElement","_extends"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AACA,SAASA,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,QAAQ,QAAQ,OAAO;AAE5E,OAAOC,gBAAgB,MAAM,6BAA6B;AAC1D,OAAOC,kBAAkB,MAAM,sBAAsB;AAErD,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;
|
|
1
|
+
{"version":3,"names":["forwardRef","useEffect","useImperativeHandle","useState","WebGPUNativeView","WebGPUNativeModule","CONTEXT_COUNTER","generateContextId","global","__WebGPUContextRegistry","WebGPUContextRegistry","Canvas","props","ref","contextId","_","getNativeSurface","createSurfaceContext","getContext","contextName","Error","nativeSurface","ctx","RNWebGPU","Make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B,CAACI,SAAS,CAAC;IACzC,CAAC;EACH,CAAC,EAAE,CAACA,SAAS,CAAC,CAAC;EAEf,oBAAOW,KAAA,CAAAC,aAAA,CAACtB,gBAAgB,EAAAuB,QAAA,KAAKf,KAAK;IAAEE,SAAS,EAAEA;EAAU,EAAE,CAAC;AAC9D,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ export const warnIfNotHardwareAccelerated = adapter => {
|
|
|
4
4
|
console.warn("GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.");
|
|
5
5
|
}
|
|
6
6
|
};
|
|
7
|
-
export const useCanvasEffect = effect => {
|
|
7
|
+
export const useCanvasEffect = (effect, deps = []) => {
|
|
8
8
|
const ref = useRef(null);
|
|
9
9
|
const unsubscribe = useRef();
|
|
10
10
|
useEffect(() => {
|
|
@@ -25,7 +25,7 @@ export const useCanvasEffect = effect => {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
-
},
|
|
28
|
+
}, deps);
|
|
29
29
|
return ref;
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=utils.js.map
|
package/lib/module/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","warnIfNotHardwareAccelerated","adapter","info","architecture","console","warn","useCanvasEffect","effect","ref","unsubscribe","requestAnimationFrame","unsub","current"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","warnIfNotHardwareAccelerated","adapter","info","architecture","console","warn","useCanvasEffect","effect","deps","ref","unsubscribe","requestAnimationFrame","unsub","current"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAMzC,OAAO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAK;EACnE,IAAIA,OAAO,CAACC,IAAI,CAACC,YAAY,KAAK,aAAa,EAAE;IAC/CC,OAAO,CAACC,IAAI,CACV,sGACF,CAAC;EACH;AACF,CAAC;AAED,OAAO,MAAMC,eAAe,GAAGA,CAC7BC,MAA8D,EAC9DC,IAAoB,GAAG,EAAE,KACtB;EACH,MAAMC,GAAG,GAAGV,MAAM,CAAY,IAAI,CAAC;EACnC,MAAMW,WAAW,GAAGX,MAAM,CAAc,CAAC;EACzCD,SAAS,CAAC,MAAM;IACda,qBAAqB,CAAC,YAAY;MAChC;MACA;MACA;MACA;MACA;MACA,MAAMC,KAAK,GAAG,MAAML,MAAM,CAAC,CAAC;MAC5B,IAAIK,KAAK,EAAE;QACTF,WAAW,CAACG,OAAO,GAAGD,KAAK;MAC7B;IACF,CAAC,CAAC;IACF,OAAO,MAAM;MACX,IAAIF,WAAW,CAACG,OAAO,EAAE;QACvBH,WAAW,CAACG,OAAO,CAAC,CAAC;MACvB;IACF,CAAC;IACD;EACF,CAAC,EAAEL,IAAI,CAAC;EACR,OAAOC,GAAG;AACZ,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const __esModule: boolean;
|
|
2
2
|
export function warnIfNotHardwareAccelerated(adapter: any): void;
|
|
3
|
-
export function useCanvasEffect(effect: any): _react.MutableRefObject<null>;
|
|
3
|
+
export function useCanvasEffect(effect: any, deps?: any[]): _react.MutableRefObject<null>;
|
|
4
4
|
import _react = require("react");
|
|
5
5
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../commonjs/utils.js"],"names":[],"mappings":";AAOA,iEAIC;AAED,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../commonjs/utils.js"],"names":[],"mappings":";AAOA,iEAIC;AAED,0FAuBC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export function warnIfNotHardwareAccelerated(adapter: any): void;
|
|
2
|
-
export function useCanvasEffect(effect: any): import("react").MutableRefObject<null>;
|
|
2
|
+
export function useCanvasEffect(effect: any, deps?: any[]): import("react").MutableRefObject<null>;
|
|
3
3
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../module/utils.js"],"names":[],"mappings":"AACO,iEAIN;AACM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../module/utils.js"],"names":[],"mappings":"AACO,iEAIN;AACM,mGAuBN"}
|
|
@@ -8,8 +8,9 @@ declare global {
|
|
|
8
8
|
createImageBitmap: typeof createImageBitmap;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
type SurfacePointer = bigint;
|
|
11
12
|
export interface NativeCanvas {
|
|
12
|
-
surface:
|
|
13
|
+
surface: SurfacePointer;
|
|
13
14
|
width: number;
|
|
14
15
|
height: number;
|
|
15
16
|
clientWidth: number;
|
|
@@ -17,10 +18,10 @@ export interface NativeCanvas {
|
|
|
17
18
|
}
|
|
18
19
|
type CanvasContext = GPUCanvasContext & {
|
|
19
20
|
present: () => void;
|
|
20
|
-
getNativeSurface: () => NativeCanvas;
|
|
21
21
|
};
|
|
22
22
|
export interface CanvasRef {
|
|
23
23
|
getContext(contextName: "webgpu"): CanvasContext | null;
|
|
24
|
+
getNativeSurface: () => NativeCanvas;
|
|
24
25
|
}
|
|
25
26
|
export declare const Canvas: import("react").ForwardRefExoticComponent<ViewProps & import("react").RefAttributes<CanvasRef>>;
|
|
26
27
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAW9C,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE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AE,MAAM,YAAY,CAAC;CACtC;AAED,eAAO,MAAM,MAAM,iGA6BjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayBuffer.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/ArrayBuffer.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Buffer.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/Buffer.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComputeShader.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/ComputeShader.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/Constants.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Device.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/Device.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExternalTexture.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/ExternalTexture.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GPU.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/GPU.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageData.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/ImageData.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shaders.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/Shaders.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Texture.spec.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/Texture.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface DrawingContext {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
getCurrentTexture(): GPUTexture;
|
|
5
|
+
getImageData(): Promise<{
|
|
6
|
+
data: number[];
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
format: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=DrawingContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DrawingContext.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/components/DrawingContext.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,IAAI,UAAU,CAAC;IAChC,YAAY,IAAI,OAAO,CAAC;QACtB,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const solidColorLitWGSL = "struct Uniforms {\n worldViewProjectionMatrix: mat4x4f,\n worldMatrix: mat4x4f,\n color: vec4f,\n};\n\nstruct Vertex {\n @location(0) position: vec4f,\n @location(1) normal: vec3f,\n};\n\nstruct VSOut {\n @builtin(position) position: vec4f,\n @location(0) normal: vec3f,\n};\n\n@group(0) @binding(0) var<uniform> uni: Uniforms;\n\n@vertex fn vs(vin: Vertex) -> VSOut {\n var vOut: VSOut;\n vOut.position = uni.worldViewProjectionMatrix * vin.position;\n vOut.normal = (uni.worldMatrix * vec4f(vin.normal, 0)).xyz;\n return vOut;\n}\n\n@fragment fn fs(vin: VSOut) -> @location(0) vec4f {\n let lightDirection = normalize(vec3f(4, 10, 6));\n let light = dot(normalize(vin.normal), lightDirection) * 0.5 + 0.5;\n return vec4f(uni.color.rgb * light, uni.color.a);\n}";
|
|
2
|
+
export declare const wireframeWGSL = "struct Uniforms {\n worldViewProjectionMatrix: mat4x4f,\n worldMatrix: mat4x4f,\n color: vec4f,\n};\n\nstruct LineUniforms {\n stride: u32,\n thickness: f32,\n alphaThreshold: f32,\n};\n\nstruct VSOut {\n @builtin(position) position: vec4f,\n};\n\n@group(0) @binding(0) var<uniform> uni: Uniforms;\n@group(0) @binding(1) var<storage, read> positions: array<f32>;\n@group(0) @binding(2) var<storage, read> indices: array<u32>;\n@group(0) @binding(3) var<uniform> line: LineUniforms;\n\n@vertex fn vsIndexedU32(@builtin(vertex_index) vNdx: u32) -> VSOut {\n // indices make a triangle so for every 3 indices we need to output\n // 6 values\n let triNdx = vNdx / 6;\n // 0 1 0 1 0 1 0 1 0 1 0 1 vNdx % 2\n // 0 0 1 1 2 2 3 3 4 4 5 5 vNdx / 2\n // 0 1 1 2 2 3 3 4 4 5 5 6 vNdx % 2 + vNdx / 2\n // 0 1 1 2 2 0 0 1 1 2 2 0 (vNdx % 2 + vNdx / 2) % 3\n let vertNdx = (vNdx % 2 + vNdx / 2) % 3;\n let index = indices[triNdx * 3 + vertNdx];\n\n // note:\n //\n // * if your indices are U16 you could use this\n //\n // let indexNdx = triNdx * 3 + vertNdx;\n // let twoIndices = indices[indexNdx / 2]; // indices is u32 but we want u16\n // let index = (twoIndices >> ((indexNdx & 1) * 16)) & 0xFFFF;\n //\n // * if you're not using indices you could use this\n //\n // let index = triNdx * 3 + vertNdx;\n\n let pNdx = index * line.stride;\n let position = vec4f(positions[pNdx], positions[pNdx + 1], positions[pNdx + 2], 1);\n\n var vOut: VSOut;\n vOut.position = uni.worldViewProjectionMatrix * position;\n return vOut;\n}\n\n@fragment fn fs() -> @location(0) vec4f {\n return uni.color + vec4f(0.5);\n}\n\nstruct BarycentricCoordinateBasedVSOutput {\n @builtin(position) position: vec4f,\n @location(0) barycenticCoord: vec3f,\n};\n\n@vertex fn vsIndexedU32BarycentricCoordinateBasedLines(\n @builtin(vertex_index) vNdx: u32\n) -> BarycentricCoordinateBasedVSOutput {\n let vertNdx = vNdx % 3;\n let index = indices[vNdx];\n\n // note:\n //\n // * if your indices are U16 you could use this\n //\n // let twoIndices = indices[vNdx / 2]; // indices is u32 but we want u16\n // let index = (twoIndices >> ((vNdx & 1) * 16)) & 0xFFFF;\n //\n // * if you're not using indices you could use this\n //\n // let index = vNdx;\n\n let pNdx = index * line.stride;\n let position = vec4f(positions[pNdx], positions[pNdx + 1], positions[pNdx + 2], 1);\n\n var vsOut: BarycentricCoordinateBasedVSOutput;\n vsOut.position = uni.worldViewProjectionMatrix * position;\n\n // emit a barycentric coordinate\n vsOut.barycenticCoord = vec3f(0);\n vsOut.barycenticCoord[vertNdx] = 1.0;\n return vsOut;\n}\n\nfn edgeFactor(bary: vec3f) -> f32 {\n let d = fwidth(bary);\n let a3 = smoothstep(vec3f(0.0), d * line.thickness, bary);\n return min(min(a3.x, a3.y), a3.z);\n}\n\n@fragment fn fsBarycentricCoordinateBasedLines(\n v: BarycentricCoordinateBasedVSOutput\n) -> @location(0) vec4f {\n let a = 1.0 - edgeFactor(v.barycenticCoord);\n if (a < line.alphaThreshold) {\n discard;\n }\n\n return vec4((uni.color.rgb + 0.5) * a, a);\n}\n";
|
|
3
|
+
//# sourceMappingURL=Shaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shaders.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/Wireframe/Shaders.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,6wBA6B5B,CAAC;AAEH,eAAO,MAAM,aAAa,oiGA0GzB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type Mesh = {
|
|
2
|
+
positions: [number, number, number][];
|
|
3
|
+
triangles: [number, number, number][];
|
|
4
|
+
normals: [number, number, number][];
|
|
5
|
+
};
|
|
6
|
+
export declare function convertMeshToTypedArrays(mesh: Mesh, scale: number, offset?: number[]): {
|
|
7
|
+
vertices: Float32Array;
|
|
8
|
+
indices: Uint32Array;
|
|
9
|
+
};
|
|
10
|
+
export declare const modelData: {
|
|
11
|
+
teapot: {
|
|
12
|
+
vertices: Float32Array;
|
|
13
|
+
indices: Uint32Array;
|
|
14
|
+
};
|
|
15
|
+
sphere: {
|
|
16
|
+
vertices: Float32Array;
|
|
17
|
+
indices: Uint32Array;
|
|
18
|
+
};
|
|
19
|
+
jewel: {
|
|
20
|
+
vertices: Float32Array;
|
|
21
|
+
indices: Uint32Array;
|
|
22
|
+
};
|
|
23
|
+
rock: {
|
|
24
|
+
vertices: Float32Array;
|
|
25
|
+
indices: Uint32Array;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/Wireframe/models.ts"],"names":[],"mappings":"AAUA,KAAK,IAAI,GAAG;IACV,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACtC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACtC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,EACb,MAAM,WAAY;;;EAoBnB;AAoED,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;CAKrB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function rand(min?: number, max?: number): number;
|
|
2
|
+
export declare function randInt(min: number, max?: number): number;
|
|
3
|
+
export declare function randColor(): number[];
|
|
4
|
+
export declare function randElement<T>(arr: T[]): T;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/Wireframe/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,UAS9C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,UAEhD;AAED,wBAAgB,SAAS,aAExB;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAE1C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const cubeVertexSize: number;
|
|
2
|
+
export declare const cubePositionOffset = 0;
|
|
3
|
+
export declare const cubeColorOffset: number;
|
|
4
|
+
export declare const cubeUVOffset: number;
|
|
5
|
+
export declare const cubeVertexCount = 36;
|
|
6
|
+
export declare const cubeVertexArray: Float32Array;
|
|
7
|
+
//# sourceMappingURL=cube.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cube.d.ts","sourceRoot":"","sources":["../../../../../src/__tests__/components/cube.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,eAAe,QAAQ,CAAC;AACrC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,KAAK,CAAC;AAGlC,eAAO,MAAM,eAAe,cA2C1B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Renderable {
|
|
2
|
+
vertexBuffer: GPUBuffer;
|
|
3
|
+
indexBuffer: GPUBuffer;
|
|
4
|
+
indexCount: number;
|
|
5
|
+
bindGroup?: GPUBindGroup;
|
|
6
|
+
}
|
|
7
|
+
export interface Mesh {
|
|
8
|
+
vertices: Float32Array;
|
|
9
|
+
indices: Uint16Array | Uint32Array;
|
|
10
|
+
vertexStride: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @param {GPUDevice} device - A valid GPUDevice.
|
|
14
|
+
* @param {Mesh} mesh - An indexed triangle-list mesh, containing its vertices, indices, and vertexStride (number of elements per vertex).
|
|
15
|
+
* @param {boolean} storeVertices - A boolean flag indicating whether the vertexBuffer should be available to use as a storage buffer.
|
|
16
|
+
* @returns {boolean} An object containing an array of bindGroups and the bindGroupLayout they implement.
|
|
17
|
+
*/
|
|
18
|
+
export declare const createMeshRenderable: (device: GPUDevice, mesh: Mesh, storeVertices?: boolean, storeIndices?: boolean) => Renderable;
|
|
19
|
+
export declare const getMeshPosAtIndex: (mesh: Mesh, index: number) => Float32Array;
|
|
20
|
+
export declare const getMeshNormalAtIndex: (mesh: Mesh, index: number) => Float32Array;
|
|
21
|
+
export declare const getMeshUVAtIndex: (mesh: Mesh, index: number) => Float32Array;
|
|
22
|
+
//# sourceMappingURL=mesh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/mesh.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,SAAS,CAAC;IACxB,WAAW,EAAE,SAAS,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,WAAW,GAAG,WAAW,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,WACvB,SAAS,QACX,IAAI,sDAGT,UAyCF,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAU,IAAI,SAAS,MAAM,iBAO1D,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,IAAI,SAAS,MAAM,iBAO7D,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,IAAI,SAAS,MAAM,iBAOzD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SphereMesh {
|
|
2
|
+
vertices: Float32Array;
|
|
3
|
+
indices: Uint16Array;
|
|
4
|
+
}
|
|
5
|
+
export declare const SphereLayout: {
|
|
6
|
+
vertexStride: number;
|
|
7
|
+
positionsOffset: number;
|
|
8
|
+
normalOffset: number;
|
|
9
|
+
uvOffset: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function createSphereMesh(radius: number, widthSegments?: number, heightSegments?: number, randomness?: number): SphereMesh;
|
|
12
|
+
//# sourceMappingURL=sphere.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sphere.d.ts","sourceRoot":"","sources":["../../../../../../src/__tests__/components/meshes/sphere.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,eAAO,MAAM,YAAY;;;;;CAKxB,CAAC;AAGF,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,aAAa,SAAK,EAClB,cAAc,SAAK,EACnB,UAAU,SAAI,GACb,UAAU,CAkFZ"}
|