Skip to content

Commit 7f8d36e

Browse files
feat: Initial working creation
1 parent 620d96b commit 7f8d36e

9 files changed

Lines changed: 26188 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p8
6+
*.p12
7+
*.key
8+
*.mobileprovision
9+
*.orig.*
10+
web-build/
11+
web-report/
12+
13+
# macOS
14+
.DS_Store

‎App.tsx‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { Component, Fragment } from 'react';
2+
import { Button, StyleSheet, Text, View } from 'react-native';
3+
import { GLView } from 'expo-gl';
4+
import { GPU, IKernelRunShortcut } from '@gpujs/expo-gl';
5+
6+
async function createVanillaKernel() {
7+
const context = await GLView.createContextAsync();
8+
const gpu = new GPU({ context });
9+
return gpu.createKernel(function () {
10+
return Math.random();
11+
}, {
12+
output: [2048, 2048],
13+
});
14+
}
15+
16+
interface IAppState {
17+
error: any,
18+
kernel: IKernelRunShortcut,
19+
milliseconds: number,
20+
kernelResult: number[][],
21+
kernelRunning: boolean,
22+
}
23+
24+
export default class App extends Component<any, IAppState> {
25+
setError = error => {
26+
this.setState({ error });
27+
};
28+
29+
setKernel = async kernel => {
30+
this.setState({ kernel });
31+
};
32+
33+
runKernel = () => {
34+
this.setState({
35+
kernelRunning: true,
36+
});
37+
const start = Date.now();
38+
const result = this.state.kernel();
39+
const milliseconds = Date.now() - start;
40+
this.setState({
41+
kernelResult: result as number[][],
42+
milliseconds,
43+
kernelRunning: false,
44+
});
45+
};
46+
47+
constructor(props) {
48+
super(props);
49+
this.state = {
50+
error: null,
51+
kernel: null,
52+
kernelResult: null,
53+
milliseconds: null,
54+
kernelRunning: false,
55+
};
56+
}
57+
58+
componentDidMount(): void {
59+
createVanillaKernel()
60+
.catch(this.setError)
61+
.then(this.setKernel);
62+
}
63+
64+
render() {
65+
const {
66+
error,
67+
kernel,
68+
kernelResult,
69+
milliseconds,
70+
kernelRunning,
71+
} = this.state;
72+
73+
let children;
74+
75+
if (error) {
76+
children = <Text>There was an error { error.toString() }</Text>;
77+
} else if (!kernel) {
78+
children = <Text>Loading context</Text>;
79+
} else {
80+
children = <Fragment>
81+
<Button
82+
disabled={kernelRunning}
83+
onPress={this.runKernel}
84+
title="Tap to run Kernel"
85+
/>
86+
{
87+
kernelResult
88+
? <Text>Kernel calculated with length of { kernelResult.length * kernelResult[0].length } and took { milliseconds } milliseconds</Text>
89+
: null
90+
}
91+
</Fragment>
92+
}
93+
return (<View style={styles.container}>{children}</View>);
94+
}
95+
}
96+
97+
const styles = StyleSheet.create({
98+
container: {
99+
flex: 1,
100+
backgroundColor: '#fff',
101+
alignItems: 'center',
102+
justifyContent: 'center',
103+
},
104+
});

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# expo-gl-example
22
A GPU.js native example used with https://github.com/gpujs/expo-gl
3+
Created using `expo init` with minimal working example.

‎app.json‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "A GPU.js native example",
4+
"slug": "gpujs_example",
5+
"privacy": "public",
6+
"sdkVersion": "36.0.0",
7+
"platforms": [
8+
"ios",
9+
"android",
10+
"web"
11+
],
12+
"version": "1.0.0",
13+
"orientation": "portrait",
14+
"icon": "./assets/icon.png",
15+
"splash": {
16+
"image": "./assets/splash.png",
17+
"resizeMode": "contain",
18+
"backgroundColor": "#ffffff"
19+
},
20+
"updates": {
21+
"fallbackToCacheTimeout": 0
22+
},
23+
"assetBundlePatterns": [
24+
"**/*"
25+
],
26+
"ios": {
27+
"supportsTablet": true
28+
}
29+
}
30+
}

‎babel.config.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

0 commit comments

Comments
 (0)