-
Notifications
You must be signed in to change notification settings - Fork 2
/
kernel.js
73 lines (61 loc) · 1.69 KB
/
kernel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { WebGL2Kernel } = require('gpu.js/src/backend/web-gl2/kernel');
const { GLView } = require('expo-gl');
let isSupported = null;
let testContext = null;
let testCanvas = {}; // not yet supported
let testExtensions = null;
let features = null;
GLView.createContextAsync()
.then(context => testContext = context);
class ExpoGLKernel extends WebGL2Kernel {
static get isSupported() {
if (isSupported !== null) {
return isSupported;
}
this.setupFeatureChecks();
isSupported = this.isContextMatch(testContext);
return isSupported;
}
static get testContext() {
return testContext;
}
static get testCanvas() {
return testCanvas;
}
static setupFeatureChecks() {
if (!testContext || !testContext.getExtension) return;
testExtensions = {
EXT_color_buffer_float: testContext.getExtension('EXT_color_buffer_float'),
OES_texture_float_linear: testContext.getExtension('OES_texture_float_linear'),
};
features = this.getFeatures();
}
static getFeatures() {
return Object.freeze({
isFloatRead: this.getIsFloatRead(),
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
kernelMap: true,
isTextureFloat: true,
channelCount: this.getChannelCount(),
});
}
static getChannelCount() {
return testContext.getParameter(testContext.MAX_DRAW_BUFFERS);
}
static get features() {
return features;
}
constructor(source, settings) {
super(source, settings);
this.warnVarUsage = false;
}
initContext() {
throw new Error('No context defined and ExpoGL instantiates them asynchronously');
}
initCanvas() {
return testCanvas;
}
}
module.exports = {
ExpoGLKernel
};