@hxa-rn/react-native-gcanvas 6.0.25 → 6.0.26
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 +2 -2
- package/LICENSE +203 -21
- package/README.md +5 -5
- package/harmony/gcanvas/LICENSE +203 -21
- package/harmony/gcanvas/NOTICE +32 -32
- package/harmony/gcanvas/OAT.xml +37 -37
- package/harmony/gcanvas/build-profile.json5 +16 -16
- package/harmony/gcanvas/hvigorfile.ts +1 -1
- package/harmony/gcanvas/index.ets +1 -1
- package/harmony/gcanvas/oh-package.json5 +14 -14
- package/harmony/gcanvas/src/main/cpp/CMakeLists.txt +126 -126
- package/harmony/gcanvas/src/main/cpp/GCanvasNapi.cpp +485 -485
- package/harmony/gcanvas/src/main/cpp/GCanvasXComponent.cpp +106 -106
- package/harmony/gcanvas/src/main/cpp/GcanvasPackage.h +24 -24
- package/harmony/gcanvas/src/main/ets/GCanvasModuleTurboModule.ts +448 -448
- package/harmony/gcanvas/src/main/ets/GCanvasNativeEngine.ts +206 -206
- package/harmony/gcanvas/src/main/ets/components/GCanvasView.ets +64 -64
- package/harmony/gcanvas/src/main/module.json5 +21 -21
- package/harmony/gcanvas/src/main/resources/base/element/string.json +12 -12
- package/harmony/gcanvas/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/gcanvas/src/main/resources/zh_CN/element/string.json +12 -12
- package/harmony/gcanvas.har +0 -0
- package/package.json +4 -4
- package/packages/gcanvas/.babelrc +4 -4
- package/packages/gcanvas/.eslintrc.js +133 -133
- package/packages/gcanvas/package.json +19 -19
- package/packages/gcanvas/rollup.config.js +13 -13
- package/packages/gcanvas/src/bridge/react-native.js +286 -286
- package/packages/gcanvas/src/bridge/weex.js +210 -210
- package/packages/gcanvas/src/context/2d/FillStyleLinearGradient.js +16 -16
- package/packages/gcanvas/src/context/2d/FillStylePattern.js +7 -7
- package/packages/gcanvas/src/context/2d/FillStyleRadialGradient.js +16 -16
- package/packages/gcanvas/src/context/2d/OffScreenRenderingContext.js +48 -48
- package/packages/gcanvas/src/context/2d/RenderingContext.js +787 -787
- package/packages/gcanvas/src/context/webgl/ActiveInfo.js +10 -10
- package/packages/gcanvas/src/context/webgl/Buffer.js +20 -20
- package/packages/gcanvas/src/context/webgl/Framebuffer.js +20 -20
- package/packages/gcanvas/src/context/webgl/GLenum.js +300 -300
- package/packages/gcanvas/src/context/webgl/GLmethod.js +141 -141
- package/packages/gcanvas/src/context/webgl/GLtype.js +22 -22
- package/packages/gcanvas/src/context/webgl/Program.js +20 -20
- package/packages/gcanvas/src/context/webgl/Renderbuffer.js +20 -20
- package/packages/gcanvas/src/context/webgl/RenderingContext.js +1479 -1479
- package/packages/gcanvas/src/context/webgl/Shader.js +21 -21
- package/packages/gcanvas/src/context/webgl/ShaderPrecisionFormat.js +10 -10
- package/packages/gcanvas/src/context/webgl/Texture.js +21 -21
- package/packages/gcanvas/src/context/webgl/UniformLocation.js +21 -21
- package/packages/gcanvas/src/context/webgl/classUtils.js +2 -2
- package/packages/gcanvas/src/env/canvas.js +210 -210
- package/packages/gcanvas/src/env/image.js +76 -76
- package/packages/gcanvas/src/env/off-screen-canvas.js +74 -74
- package/packages/gcanvas/src/index.js +56 -56
- package/src/components/CanvasView.js +20 -20
- package/src/components/GCanvasComponent.js +408 -408
- package/src/index.js +69 -69
- package/src/packages/gcanvas/.babelrc +4 -4
- package/src/packages/gcanvas/.eslintrc.js +133 -133
- package/src/packages/gcanvas/package.json +19 -19
- package/src/packages/gcanvas/rollup.config.js +13 -13
- package/src/packages/gcanvas/src/bridge/react-native.js +288 -288
- package/src/packages/gcanvas/src/bridge/weex.js +210 -210
- package/src/packages/gcanvas/src/context/2d/FillStyleLinearGradient.js +16 -16
- package/src/packages/gcanvas/src/context/2d/FillStylePattern.js +7 -7
- package/src/packages/gcanvas/src/context/2d/FillStyleRadialGradient.js +16 -16
- package/src/packages/gcanvas/src/context/2d/OffScreenRenderingContext.js +48 -48
- package/src/packages/gcanvas/src/context/2d/RenderingContext.js +801 -801
- package/src/packages/gcanvas/src/context/webgl/ActiveInfo.js +10 -10
- package/src/packages/gcanvas/src/context/webgl/Buffer.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/Framebuffer.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/GLenum.js +300 -300
- package/src/packages/gcanvas/src/context/webgl/GLmethod.js +141 -141
- package/src/packages/gcanvas/src/context/webgl/GLtype.js +22 -22
- package/src/packages/gcanvas/src/context/webgl/Program.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/Renderbuffer.js +20 -20
- package/src/packages/gcanvas/src/context/webgl/RenderingContext.js +1479 -1479
- package/src/packages/gcanvas/src/context/webgl/Shader.js +21 -21
- package/src/packages/gcanvas/src/context/webgl/ShaderPrecisionFormat.js +10 -10
- package/src/packages/gcanvas/src/context/webgl/Texture.js +21 -21
- package/src/packages/gcanvas/src/context/webgl/UniformLocation.js +21 -21
- package/src/packages/gcanvas/src/context/webgl/classUtils.js +2 -2
- package/src/packages/gcanvas/src/env/canvas.js +210 -210
- package/src/packages/gcanvas/src/env/image.js +76 -76
- package/src/packages/gcanvas/src/env/off-screen-canvas.js +74 -74
- package/src/packages/gcanvas/src/index.js +56 -56
- package/src/specs/v1/GCanvasViewNativeComponent.ts +42 -42
- package/src/specs/v1/NativeGCanvasModule.ts +140 -140
|
@@ -1,1479 +1,1479 @@
|
|
|
1
|
-
import GLenum from './GLenum';
|
|
2
|
-
import ActiveInfo from './ActiveInfo';
|
|
3
|
-
import Buffer from './Buffer';
|
|
4
|
-
import Framebuffer from './Framebuffer';
|
|
5
|
-
import Renderbuffer from './Renderbuffer';
|
|
6
|
-
import Texture from './Texture';
|
|
7
|
-
import Program from './Program';
|
|
8
|
-
import Shader from './Shader';
|
|
9
|
-
import ShaderPrecisionFormat from './ShaderPrecisionFormat';
|
|
10
|
-
import UniformLocation from './UniformLocation';
|
|
11
|
-
import GLmethod from './GLmethod';
|
|
12
|
-
|
|
13
|
-
const processArray = (array, checkArrayType = false) => {
|
|
14
|
-
function joinArray(arr, sep) {
|
|
15
|
-
let res = '';
|
|
16
|
-
for (let i = 0; i < arr.length; i++) {
|
|
17
|
-
if (i !== 0) {
|
|
18
|
-
res += sep;
|
|
19
|
-
}
|
|
20
|
-
res += arr[i];
|
|
21
|
-
}
|
|
22
|
-
return res;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let type = 'Float32Array';
|
|
26
|
-
if (checkArrayType) {
|
|
27
|
-
if (array instanceof Uint8Array) {
|
|
28
|
-
type = 'Uint8Array';
|
|
29
|
-
} else if (array instanceof Uint16Array) {
|
|
30
|
-
type = 'Uint16Array';
|
|
31
|
-
} else if (array instanceof Uint32Array) {
|
|
32
|
-
type = 'Uint32Array';
|
|
33
|
-
} else if (array instanceof Float32Array) {
|
|
34
|
-
type = 'Float32Array';
|
|
35
|
-
} else if (array instanceof ArrayBuffer) {
|
|
36
|
-
let uint8Array = new Uint8Array(array);
|
|
37
|
-
return 1 + ',' + btoa(joinArray(uint8Array, ','));
|
|
38
|
-
} else {
|
|
39
|
-
throw new Error('Check array type failed. Array type is ' + typeof array);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const ArrayTypes = {
|
|
44
|
-
Uint8Array: 1,
|
|
45
|
-
Uint16Array: 2,
|
|
46
|
-
Uint32Array: 4,
|
|
47
|
-
Float32Array: 14
|
|
48
|
-
};
|
|
49
|
-
return ArrayTypes[type] + ',' + btoa(joinArray(array, ','));
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default class WebGLRenderingContext {
|
|
53
|
-
// static GBridge = null;
|
|
54
|
-
|
|
55
|
-
className = 'WebGLRenderingContext';
|
|
56
|
-
|
|
57
|
-
componentId = null;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_resetContextAttributes({}) {}
|
|
61
|
-
|
|
62
|
-
constructor(canvas, type, attrs) {
|
|
63
|
-
this._canvas = canvas;
|
|
64
|
-
this._type = type;
|
|
65
|
-
this._version = 'WebGL 1.0';
|
|
66
|
-
this._attrs = attrs;
|
|
67
|
-
this._map = new Map();
|
|
68
|
-
this._supportedExtensions = [];
|
|
69
|
-
|
|
70
|
-
Object.keys(GLenum)
|
|
71
|
-
.forEach(name => Object.defineProperty(this, name, {
|
|
72
|
-
value: GLenum[name]
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
this._resetContextAttributes({});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get canvas() {
|
|
79
|
-
return this._canvas;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
activeTexture = function(textureUnit) {
|
|
83
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
84
|
-
this._canvas.id,
|
|
85
|
-
GLmethod.activeTexture + ',' + textureUnit,
|
|
86
|
-
true
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
attachShader = function(progarm, shader) {
|
|
91
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
92
|
-
this._canvas.id,
|
|
93
|
-
GLmethod.attachShader + ',' + progarm.id + ',' + shader.id,
|
|
94
|
-
true
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
bindAttribLocation = function(program, index, name) {
|
|
99
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
100
|
-
this._canvas.id,
|
|
101
|
-
GLmethod.bindAttribLocation + ',' + program.id + ',' + index + ',' + name,
|
|
102
|
-
true
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
bindBuffer = function(target, buffer) {
|
|
107
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
108
|
-
this._canvas.id,
|
|
109
|
-
GLmethod.bindBuffer + ',' + target + ',' + (buffer ? buffer.id : 0),
|
|
110
|
-
true
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
bindFramebuffer = function(target, framebuffer) {
|
|
115
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
116
|
-
this._canvas.id,
|
|
117
|
-
GLmethod.bindFramebuffer + ',' + target + ',' + (framebuffer ? framebuffer.id : 0),
|
|
118
|
-
true
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
bindRenderbuffer = function(target, renderBuffer) {
|
|
123
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
124
|
-
this._canvas.id,
|
|
125
|
-
GLmethod.bindRenderbuffer + ',' + target + ',' + (renderBuffer ? renderBuffer.id : 0),
|
|
126
|
-
true
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
bindTexture = function(target, texture) {
|
|
131
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
132
|
-
this._canvas.id,
|
|
133
|
-
GLmethod.bindTexture + ',' + target + ',' + (texture ? texture.id : 0),
|
|
134
|
-
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
blendColor = function(r, g, b, a) {
|
|
139
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
140
|
-
this._canvas.id,
|
|
141
|
-
GLmethod.blendColor + ',' + r + ',' + g + ',' + b + ',' + a,
|
|
142
|
-
true
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
blendEquation = function(mode) {
|
|
147
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
148
|
-
this._canvas.id,
|
|
149
|
-
GLmethod.blendEquation + ',' + mode,
|
|
150
|
-
true
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
blendEquationSeparate = function(modeRGB, modeAlpha) {
|
|
155
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
156
|
-
this._canvas.id,
|
|
157
|
-
GLmethod.blendEquationSeparate + ',' + modeRGB + ',' + modeAlpha,
|
|
158
|
-
true
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
blendFunc = function(sfactor, dfactor) {
|
|
164
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
165
|
-
this._canvas.id,
|
|
166
|
-
GLmethod.blendFunc + ',' + sfactor + ',' + dfactor,
|
|
167
|
-
true
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
blendFuncSeparate = function(srcRGB, dstRGB, srcAlpha, dstAlpha) {
|
|
172
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
173
|
-
this._canvas.id,
|
|
174
|
-
GLmethod.blendFuncSeparate + ',' + srcRGB + ',' + dstRGB + ',' + srcAlpha + ',' + dstAlpha,
|
|
175
|
-
true
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
bufferData = function(target, data, usage) {
|
|
180
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
181
|
-
this._canvas.id,
|
|
182
|
-
GLmethod.bufferData + ',' + target + ',' + processArray(data, true) + ',' + usage,
|
|
183
|
-
true
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
bufferSubData = function(target, offset, data) {
|
|
188
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
189
|
-
this._canvas.id,
|
|
190
|
-
GLmethod.bufferSubData + ',' + target + ',' + offset + ',' + processArray(data, true),
|
|
191
|
-
true
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
checkFramebufferStatus = function(target) {
|
|
196
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
197
|
-
this._canvas.id,
|
|
198
|
-
GLmethod.checkFramebufferStatus + ',' + target
|
|
199
|
-
);
|
|
200
|
-
return Number(result);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// not a Web webgl API, used by @flyskywhy/react-native-gcanvas
|
|
204
|
-
flushJsCommands2CallNative(
|
|
205
|
-
methodType = 'sync',
|
|
206
|
-
optionType = 'execWithDisplay',
|
|
207
|
-
) {
|
|
208
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
209
|
-
this.componentId,
|
|
210
|
-
'',
|
|
211
|
-
false, // here false will let cmds cache be empty
|
|
212
|
-
'webgl',
|
|
213
|
-
methodType,
|
|
214
|
-
optionType,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
clear = function(mask) {
|
|
219
|
-
if (this._canvas._disableAutoSwap) {
|
|
220
|
-
this.flushJsCommands2CallNative();
|
|
221
|
-
// above exec cached cmds to generate and display graphics
|
|
222
|
-
// below add gl.clear to cmds cache to be exec next time
|
|
223
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
224
|
-
this._canvas.id,
|
|
225
|
-
GLmethod.clear + ',' + mask,
|
|
226
|
-
true,
|
|
227
|
-
);
|
|
228
|
-
} else {
|
|
229
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
230
|
-
this._canvas.id,
|
|
231
|
-
GLmethod.clear + ',' + mask,
|
|
232
|
-
true, // TODO: no matter true or false in https://github.com/flyskywhy/snakeRN can keep 60 JS FPS, maybe need more APP code to test
|
|
233
|
-
);
|
|
234
|
-
this._canvas._needRender = true;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
clearColor = function(r, g, b, a) {
|
|
239
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
240
|
-
this._canvas.id,
|
|
241
|
-
GLmethod.clearColor + ',' + r + ',' + g + ',' + b,
|
|
242
|
-
true
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
clearDepth = function(depth) {
|
|
247
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
248
|
-
this._canvas.id,
|
|
249
|
-
GLmethod.clearDepth + ',' + depth,
|
|
250
|
-
true
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
clearStencil = function(s) {
|
|
255
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
256
|
-
this._canvas.id,
|
|
257
|
-
GLmethod.clearStencil + ',' + s
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
colorMask = function(r, g, b, a) {
|
|
262
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
263
|
-
this._canvas.id,
|
|
264
|
-
GLmethod.colorMask + ',' + Number(r) + ',' + Number(g) + ',' + Number(b) + ',' + Number(a),
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
compileShader = function(shader) {
|
|
269
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
270
|
-
this._canvas.id,
|
|
271
|
-
GLmethod.compileShader + ',' + shader.id,
|
|
272
|
-
true
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
compressedTexImage2D = function(target, level, internalformat, width, height, border, pixels) {
|
|
277
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
278
|
-
this._canvas.id,
|
|
279
|
-
GLmethod.compressedTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' +
|
|
280
|
-
width + ',' + height + ',' + border + ',' + processArray(pixels),
|
|
281
|
-
true
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
compressedTexSubImage2D = function(target, level, xoffset, yoffset, width, height, format, pixels) {
|
|
286
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
287
|
-
this._canvas.id,
|
|
288
|
-
GLmethod.compressedTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' +
|
|
289
|
-
width + ',' + height + ',' + format + ',' + processArray(pixels),
|
|
290
|
-
true
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
copyTexImage2D = function(target, level, internalformat, x, y, width, height, border) {
|
|
296
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
297
|
-
this._canvas.id,
|
|
298
|
-
GLmethod.copyTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' + x + ',' + y + ',' +
|
|
299
|
-
width + ',' + height + ',' + border,
|
|
300
|
-
true
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
copyTexSubImage2D = function(target, level, xoffset, yoffset, x, y, width, height) {
|
|
305
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
306
|
-
this._canvas.id,
|
|
307
|
-
GLmethod.copyTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + x + ',' + y + ',' +
|
|
308
|
-
width + ',' + height,
|
|
309
|
-
true, // TODO: maybe need more APP code to test
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
createBuffer = function() {
|
|
314
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
315
|
-
this._canvas.id,
|
|
316
|
-
GLmethod.createBuffer + ''
|
|
317
|
-
);
|
|
318
|
-
const buffer = new Buffer(result);
|
|
319
|
-
this._map.set(buffer.uuid(), buffer);
|
|
320
|
-
return buffer;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
createFramebuffer = function() {
|
|
324
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
325
|
-
this._canvas.id,
|
|
326
|
-
GLmethod.createFramebuffer + ''
|
|
327
|
-
);
|
|
328
|
-
const framebuffer = new Framebuffer(result);
|
|
329
|
-
this._map.set(framebuffer.uuid(), framebuffer);
|
|
330
|
-
return framebuffer;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
createProgram = function() {
|
|
335
|
-
const id = WebGLRenderingContext.GBridge.callNative(
|
|
336
|
-
this._canvas.id,
|
|
337
|
-
GLmethod.createProgram + ''
|
|
338
|
-
);
|
|
339
|
-
const program = new Program(id);
|
|
340
|
-
this._map.set(program.uuid(), program);
|
|
341
|
-
return program;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
createRenderbuffer = function() {
|
|
345
|
-
const id = WebGLRenderingContext.GBridge.callNative(
|
|
346
|
-
this._canvas.id,
|
|
347
|
-
GLmethod.createRenderbuffer + ''
|
|
348
|
-
);
|
|
349
|
-
const renderBuffer = new Renderbuffer(id);
|
|
350
|
-
this._map.set(renderBuffer.uuid(), renderBuffer);
|
|
351
|
-
return renderBuffer;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
createShader = function(type) {
|
|
355
|
-
const id = WebGLRenderingContext.GBridge.callNative(
|
|
356
|
-
this._canvas.id,
|
|
357
|
-
GLmethod.createShader + ',' + type
|
|
358
|
-
);
|
|
359
|
-
const shader = new Shader(id, type);
|
|
360
|
-
this._map.set(shader.uuid(), shader);
|
|
361
|
-
return shader;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
createTexture = function() {
|
|
365
|
-
const id = WebGLRenderingContext.GBridge.callNative(
|
|
366
|
-
this._canvas.id,
|
|
367
|
-
GLmethod.createTexture + ''
|
|
368
|
-
);
|
|
369
|
-
const texture = new Texture(id);
|
|
370
|
-
this._map.set(texture.uuid(), texture);
|
|
371
|
-
return texture;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
cullFace = function(mode) {
|
|
375
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
376
|
-
this._canvas.id,
|
|
377
|
-
GLmethod.cullFace + ',' + mode,
|
|
378
|
-
true
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
deleteBuffer = function(buffer) {
|
|
384
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
385
|
-
this._canvas.id,
|
|
386
|
-
GLmethod.deleteBuffer + ',' + buffer.id,
|
|
387
|
-
true
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
deleteFramebuffer = function(framebuffer) {
|
|
392
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
393
|
-
this._canvas.id,
|
|
394
|
-
GLmethod.deleteFramebuffer + ',' + framebuffer.id,
|
|
395
|
-
true
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
deleteProgram = function(program) {
|
|
400
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
401
|
-
this._canvas.id,
|
|
402
|
-
GLmethod.deleteProgram + ',' + program.id,
|
|
403
|
-
true
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
deleteRenderbuffer = function(renderbuffer) {
|
|
408
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
409
|
-
this._canvas.id,
|
|
410
|
-
GLmethod.deleteRenderbuffer + ',' + renderbuffer.id,
|
|
411
|
-
true
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
deleteShader = function(shader) {
|
|
416
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
417
|
-
this._canvas.id,
|
|
418
|
-
GLmethod.deleteShader + ',' + shader.id,
|
|
419
|
-
true
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
deleteTexture = function(texture) {
|
|
424
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
425
|
-
this._canvas.id,
|
|
426
|
-
GLmethod.deleteTexture + ',' + texture.id,
|
|
427
|
-
true
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
depthFunc = function(func) {
|
|
432
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
433
|
-
this._canvas.id,
|
|
434
|
-
GLmethod.depthFunc + ',' + func
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
depthMask = function(flag) {
|
|
439
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
440
|
-
this._canvas.id,
|
|
441
|
-
GLmethod.depthMask + ',' + Number(flag),
|
|
442
|
-
true
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
depthRange = function(zNear, zFar) {
|
|
447
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
448
|
-
this._canvas.id,
|
|
449
|
-
GLmethod.depthRange + ',' + zNear + ',' + zFar,
|
|
450
|
-
true
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
detachShader = function(program, shader) {
|
|
455
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
456
|
-
this._canvas.id,
|
|
457
|
-
GLmethod.detachShader + ',' + program.id + ',' + shader.id,
|
|
458
|
-
true
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
disable = function(cap) {
|
|
463
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
464
|
-
this._canvas.id,
|
|
465
|
-
GLmethod.disable + ',' + cap,
|
|
466
|
-
true
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
disableVertexAttribArray = function(index) {
|
|
471
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
472
|
-
this._canvas.id,
|
|
473
|
-
GLmethod.disableVertexAttribArray + ',' + index,
|
|
474
|
-
true
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
drawArrays = function(mode, first, count) {
|
|
479
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
480
|
-
this._canvas.id,
|
|
481
|
-
GLmethod.drawArrays + ',' + mode + ',' + first + ',' + count,
|
|
482
|
-
true,
|
|
483
|
-
);
|
|
484
|
-
this._canvas._needRender = true;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
drawElements = function(mode, count, type, offset) {
|
|
488
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
489
|
-
this._canvas.id,
|
|
490
|
-
GLmethod.drawElements + ',' + mode + ',' + count + ',' + type + ',' + offset,
|
|
491
|
-
true,
|
|
492
|
-
);
|
|
493
|
-
this._canvas._needRender = true;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
enable = function(cap) {
|
|
497
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
498
|
-
this._canvas.id,
|
|
499
|
-
GLmethod.enable + ',' + cap,
|
|
500
|
-
true
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
enableVertexAttribArray = function(index) {
|
|
505
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
506
|
-
this._canvas.id,
|
|
507
|
-
GLmethod.enableVertexAttribArray + ',' + index,
|
|
508
|
-
true
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
flush = function() {
|
|
514
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
515
|
-
this._canvas.id,
|
|
516
|
-
GLmethod.flush + ''
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
framebufferRenderbuffer = function(target, attachment, textarget, texture) {
|
|
521
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
522
|
-
this._canvas.id,
|
|
523
|
-
GLmethod.framebufferRenderbuffer + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0),
|
|
524
|
-
true
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
framebufferTexture2D = function(target, attachment, textarget, texture, level) {
|
|
529
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
530
|
-
this._canvas.id,
|
|
531
|
-
GLmethod.framebufferTexture2D + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0) + ',' + level,
|
|
532
|
-
true
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
frontFace = function(mode) {
|
|
537
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
538
|
-
this._canvas.id,
|
|
539
|
-
GLmethod.frontFace + ',' + mode,
|
|
540
|
-
true
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
generateMipmap = function(target) {
|
|
545
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
546
|
-
this._canvas.id,
|
|
547
|
-
GLmethod.generateMipmap + ',' + target,
|
|
548
|
-
true
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
getActiveAttrib = function(progarm, index) {
|
|
553
|
-
const resultString = WebGLRenderingContext.GBridge.callNative(
|
|
554
|
-
this._canvas.id,
|
|
555
|
-
GLmethod.getActiveAttrib + ',' + progarm.id + ',' + index
|
|
556
|
-
);
|
|
557
|
-
const [type, size, name] = resultString.split(',');
|
|
558
|
-
return new ActiveInfo({
|
|
559
|
-
type: Number(type),
|
|
560
|
-
size: Number(size),
|
|
561
|
-
name
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
getActiveUniform = function(progarm, index) {
|
|
566
|
-
const resultString = WebGLRenderingContext.GBridge.callNative(
|
|
567
|
-
this._canvas.id,
|
|
568
|
-
GLmethod.getActiveUniform + ',' + progarm.id + ',' + index
|
|
569
|
-
);
|
|
570
|
-
const [type, size, name] = resultString.split(',');
|
|
571
|
-
return new ActiveInfo({
|
|
572
|
-
type: Number(type),
|
|
573
|
-
size: Number(size),
|
|
574
|
-
name
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
getAttachedShaders = function(progarm) {
|
|
579
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
580
|
-
this._canvas.id,
|
|
581
|
-
GLmethod.getAttachedShaders + ',' + progarm.id
|
|
582
|
-
);
|
|
583
|
-
const [type, ...ids] = result;
|
|
584
|
-
return ids.map(id => this._map.get(Shader.uuid(id)));
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
getAttribLocation = function(progarm, name) {
|
|
588
|
-
return WebGLRenderingContext.GBridge.callNative(
|
|
589
|
-
this._canvas.id,
|
|
590
|
-
GLmethod.getAttribLocation + ',' + progarm.id + ',' + name
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
getBufferParameter = function(target, pname) {
|
|
595
|
-
const [type, res] = WebGLRenderingContext.GBridge.callNative(
|
|
596
|
-
this._canvas.id,
|
|
597
|
-
GLmethod.getBufferParameter + ',' + target + ',' + pname
|
|
598
|
-
);
|
|
599
|
-
return res;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// http://web-developer-articles.blogspot.com/2015/12/webgl-rendering-context.html
|
|
603
|
-
// A current implementation of WebGL in a flagship browser will produce the following list of attributes and their default values:
|
|
604
|
-
// {
|
|
605
|
-
// antialias: true
|
|
606
|
-
// depth: true
|
|
607
|
-
// premultipliedAlpha: true
|
|
608
|
-
// preserveDrawingBuffer: false
|
|
609
|
-
// stencil: false
|
|
610
|
-
// }
|
|
611
|
-
//
|
|
612
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes
|
|
613
|
-
// the getContextAttributes method returns an object that describes the attributes set on this context, for example:
|
|
614
|
-
// {
|
|
615
|
-
// alpha: true,
|
|
616
|
-
// antialias: true,
|
|
617
|
-
// depth: true,
|
|
618
|
-
// failIfMajorPerformanceCaveat: false,
|
|
619
|
-
// powerPreference: "default",
|
|
620
|
-
// premultipliedAlpha: true,
|
|
621
|
-
// preserveDrawingBuffer: false,
|
|
622
|
-
// stencil: false,
|
|
623
|
-
// desynchronized: false
|
|
624
|
-
// }
|
|
625
|
-
getContextAttributesResult = {
|
|
626
|
-
alpha: true,
|
|
627
|
-
antialias: true,
|
|
628
|
-
depth: true,
|
|
629
|
-
failIfMajorPerformanceCaveat: false,
|
|
630
|
-
powerPreference: "default",
|
|
631
|
-
premultipliedAlpha: false,
|
|
632
|
-
preserveDrawingBuffer: false,
|
|
633
|
-
stencil: true,
|
|
634
|
-
desynchronized: false
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
getContextAttributes = function() {
|
|
638
|
-
return this.getContextAttributesResult;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
getError = function() {
|
|
642
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
643
|
-
this._canvas.id,
|
|
644
|
-
GLmethod.getError + ''
|
|
645
|
-
);
|
|
646
|
-
return result;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
getExtension = function(name) {
|
|
650
|
-
this.getSupportedExtensions();
|
|
651
|
-
|
|
652
|
-
switch (name) {
|
|
653
|
-
// return null to let _initGLContext() in @babylonjs@5.1.0/core/Engines/thinEngine.js works
|
|
654
|
-
case 'EXT_disjoint_timer_query':
|
|
655
|
-
case 'EXT_disjoint_timer_query_webgl2':
|
|
656
|
-
case 'OES_texture_float':
|
|
657
|
-
case 'OES_texture_half_float':
|
|
658
|
-
case 'OES_vertex_array_object':
|
|
659
|
-
case 'KHR_parallel_shader_compile':
|
|
660
|
-
case 'EXT_texture_filter_anisotropic':
|
|
661
|
-
case 'WEBKIT_EXT_texture_filter_anisotropic':
|
|
662
|
-
case 'MOZ_EXT_texture_filter_anisotropic':
|
|
663
|
-
|
|
664
|
-
// maybe some APP need these
|
|
665
|
-
// case 'OES_texture_float_linear':
|
|
666
|
-
// case 'OES_texture_half_float_linear':
|
|
667
|
-
return null;
|
|
668
|
-
default:
|
|
669
|
-
return this._supportedExtensions.includes(name) ? true : null;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
getFramebufferAttachmentParameter = function(target, attachment, pname) {
|
|
674
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
675
|
-
this._canvas.id,
|
|
676
|
-
GLmethod.getFramebufferAttachmentParameter + ',' + target + ',' + attachment + ',' + pname
|
|
677
|
-
);
|
|
678
|
-
switch (pname) {
|
|
679
|
-
case GLenum.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
|
680
|
-
return this._map.get(Renderbuffer.uuid(result)) || this._map.get(Texture.uuid(result)) || null;
|
|
681
|
-
default:
|
|
682
|
-
return result;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
getParameter = function(pname) {
|
|
687
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
688
|
-
this._canvas.id,
|
|
689
|
-
GLmethod.getParameter + ',' + pname
|
|
690
|
-
);
|
|
691
|
-
switch (pname) {
|
|
692
|
-
case GLenum.VERSION:
|
|
693
|
-
return this._version + result.replace(/.,/, ' ');
|
|
694
|
-
case GLenum.ARRAY_BUFFER_BINDING: // buffer
|
|
695
|
-
case GLenum.ELEMENT_ARRAY_BUFFER_BINDING: // buffer
|
|
696
|
-
return this._map.get(Buffer.uuid(result)) || null;
|
|
697
|
-
case GLenum.CURRENT_PROGRAM: // program
|
|
698
|
-
return this._map.get(Program.uuid(result)) || null;
|
|
699
|
-
case GLenum.FRAMEBUFFER_BINDING: // framebuffer
|
|
700
|
-
return this._map.get(Framebuffer.uuid(result)) || null;
|
|
701
|
-
case GLenum.RENDERBUFFER_BINDING: // renderbuffer
|
|
702
|
-
return this._map.get(Renderbuffer.uuid(result)) || null;
|
|
703
|
-
case GLenum.TEXTURE_BINDING_2D: // texture
|
|
704
|
-
case GLenum.TEXTURE_BINDING_CUBE_MAP: // texture
|
|
705
|
-
return this._map.get(Texture.uuid(result)) || null;
|
|
706
|
-
case GLenum.ALIASED_LINE_WIDTH_RANGE: // Float32Array
|
|
707
|
-
case GLenum.ALIASED_POINT_SIZE_RANGE: // Float32Array
|
|
708
|
-
case GLenum.BLEND_COLOR: // Float32Array
|
|
709
|
-
case GLenum.COLOR_CLEAR_VALUE: // Float32Array
|
|
710
|
-
case GLenum.DEPTH_RANGE: // Float32Array
|
|
711
|
-
case GLenum.MAX_VIEWPORT_DIMS: // Int32Array
|
|
712
|
-
case GLenum.SCISSOR_BOX: // Int32Array
|
|
713
|
-
case GLenum.VIEWPORT: // Int32Array
|
|
714
|
-
case GLenum.COMPRESSED_TEXTURE_FORMATS: // Uint32Array
|
|
715
|
-
default:
|
|
716
|
-
const [type, ...res] = result.split(',');
|
|
717
|
-
if (res.length === 1) {
|
|
718
|
-
return Number(res[0]);
|
|
719
|
-
} else {
|
|
720
|
-
return res.map(Number);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
getProgramInfoLog = function(progarm) {
|
|
726
|
-
return WebGLRenderingContext.GBridge.callNative(
|
|
727
|
-
this._canvas.id,
|
|
728
|
-
GLmethod.getProgramInfoLog + ',' + progarm.id
|
|
729
|
-
);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
getProgramParameter = function(program, pname) {
|
|
733
|
-
const res = WebGLRenderingContext.GBridge.callNative(
|
|
734
|
-
this._canvas.id,
|
|
735
|
-
GLmethod.getProgramParameter + ',' + program.id + ',' + pname
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
const [type, result] = res.split(',').map(i => parseInt(i));
|
|
739
|
-
|
|
740
|
-
if (type === 1) {
|
|
741
|
-
return Boolean(result);
|
|
742
|
-
} else if (type === 2) {
|
|
743
|
-
return result;
|
|
744
|
-
} else {
|
|
745
|
-
throw new Error('Unrecongized program paramater ' + res + ', type: ' + typeof res);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
getRenderbufferParameter = function(target, pname) {
|
|
751
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
752
|
-
this._canvas.id,
|
|
753
|
-
GLmethod.getRenderbufferParameter + ',' + target + ',' + pname
|
|
754
|
-
);
|
|
755
|
-
return result;
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
getShaderInfoLog = function(shader) {
|
|
760
|
-
return WebGLRenderingContext.GBridge.callNative(
|
|
761
|
-
this._canvas.id,
|
|
762
|
-
GLmethod.getShaderInfoLog + ',' + shader.id
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
getShaderParameter = function(shader, pname) {
|
|
767
|
-
return WebGLRenderingContext.GBridge.callNative(
|
|
768
|
-
this._canvas.id,
|
|
769
|
-
GLmethod.getShaderParameter + ',' + shader.id + ',' + pname
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
getShaderPrecisionFormat = function(shaderType, precisionType) {
|
|
774
|
-
const [rangeMin, rangeMax, precision] = WebGLRenderingContext.GBridge.callNative(
|
|
775
|
-
this._canvas.id,
|
|
776
|
-
GLmethod.getShaderPrecisionFormat + ',' + shaderType + ',' + precisionType
|
|
777
|
-
);
|
|
778
|
-
const shaderPrecisionFormat = new ShaderPrecisionFormat({
|
|
779
|
-
rangeMin: Number(rangeMin),
|
|
780
|
-
rangeMax: Number(rangeMax),
|
|
781
|
-
precision: Number(precision)
|
|
782
|
-
});
|
|
783
|
-
return shaderPrecisionFormat;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
getShaderSource = function(shader) {
|
|
787
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
788
|
-
this._canvas.id,
|
|
789
|
-
GLmethod.getShaderSource + ',' + shader.id
|
|
790
|
-
);
|
|
791
|
-
return result;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
getSupportedExtensions = function() {
|
|
795
|
-
if (this._supportedExtensions.length === 0) {
|
|
796
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
797
|
-
this._canvas.id,
|
|
798
|
-
GLmethod.getSupportedExtensions + '',
|
|
799
|
-
);
|
|
800
|
-
result.split(' ').map(extension => {
|
|
801
|
-
if (extension !== '') {
|
|
802
|
-
this._supportedExtensions.push(extension.replace(/^GL_/, ''));
|
|
803
|
-
}
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
let supportsWebGL2 = false;
|
|
807
|
-
let version = Number(this.getParameter(GLenum.VERSION).replace(/^.*OpenGL ES /, '').replace(/ .*$/, ''));
|
|
808
|
-
if (version !== NaN && version >= 3.0) {
|
|
809
|
-
supportsWebGL2 = true;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
if (supportsWebGL2) {
|
|
813
|
-
this._supportedExtensions.push('WEBGL_compressed_texture_astc');
|
|
814
|
-
this._supportedExtensions.push('WEBGL_compressed_texture_etc');
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
return this._supportedExtensions;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
getTexParameter = function(target, pname) {
|
|
822
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
823
|
-
this._canvas.id,
|
|
824
|
-
GLmethod.getTexParameter + ',' + target + ',' + pname
|
|
825
|
-
);
|
|
826
|
-
return result;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
getUniformLocation = function(program, name) {
|
|
830
|
-
const id = WebGLRenderingContext.GBridge.callNative(
|
|
831
|
-
this._canvas.id,
|
|
832
|
-
GLmethod.getUniformLocation + ',' + program.id + ',' + name
|
|
833
|
-
);
|
|
834
|
-
if (id === 'null' || id === -1) {
|
|
835
|
-
return null;
|
|
836
|
-
} else {
|
|
837
|
-
return new UniformLocation(Number(id), name);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
getVertexAttrib = function(index, pname) {
|
|
842
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
843
|
-
this._canvas.id,
|
|
844
|
-
GLmethod.getVertexAttrib + ',' + index + ',' + pname
|
|
845
|
-
);
|
|
846
|
-
switch (pname) {
|
|
847
|
-
case GLenum.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
|
|
848
|
-
return this._map.get(Buffer.uuid(result)) || null;
|
|
849
|
-
case GLenum.CURRENT_VERTEX_ATTRIB: // Float32Array
|
|
850
|
-
default:
|
|
851
|
-
return result;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
getVertexAttribOffset = function(index, pname) {
|
|
856
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
857
|
-
this._canvas.id,
|
|
858
|
-
GLmethod.getVertexAttribOffset + ',' + index + ',' + pname
|
|
859
|
-
);
|
|
860
|
-
return Number(result);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
isBuffer = function(buffer) {
|
|
864
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
865
|
-
this._canvas.id,
|
|
866
|
-
GLmethod.isBuffer + ',' + buffer.id
|
|
867
|
-
);
|
|
868
|
-
return Boolean(result);
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
isContextLost = function() {
|
|
872
|
-
return false;
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
isEnabled = function(cap) {
|
|
876
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
877
|
-
this._canvas.id,
|
|
878
|
-
GLmethod.isEnabled + ',' + cap
|
|
879
|
-
);
|
|
880
|
-
return Boolean(result);
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
isFramebuffer = function(framebuffer) {
|
|
884
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
885
|
-
this._canvas.id,
|
|
886
|
-
GLmethod.isFramebuffer + ',' + framebuffer.id
|
|
887
|
-
);
|
|
888
|
-
return Boolean(result);
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
isProgram = function(program) {
|
|
892
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
893
|
-
this._canvas.id,
|
|
894
|
-
GLmethod.isProgram + ',' + program.id
|
|
895
|
-
);
|
|
896
|
-
return Boolean(result);
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
isRenderbuffer = function(renderBuffer) {
|
|
900
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
901
|
-
this._canvas.id,
|
|
902
|
-
GLmethod.isRenderbuffer + ',' + renderBuffer.id
|
|
903
|
-
);
|
|
904
|
-
return Boolean(result);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
isShader = function(shader) {
|
|
908
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
909
|
-
this._canvas.id,
|
|
910
|
-
GLmethod.isShader + ',' + shader.id
|
|
911
|
-
);
|
|
912
|
-
return Boolean(result);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
isTexture = function(texture) {
|
|
916
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
917
|
-
this._canvas.id,
|
|
918
|
-
GLmethod.isTexture + ',' + texture.id
|
|
919
|
-
);
|
|
920
|
-
return Boolean(result);
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
lineWidth = function(width) {
|
|
924
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
925
|
-
this._canvas.id,
|
|
926
|
-
GLmethod.lineWidth + ',' + width,
|
|
927
|
-
true
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
linkProgram = function(program) {
|
|
932
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
933
|
-
this._canvas.id,
|
|
934
|
-
GLmethod.linkProgram + ',' + program.id,
|
|
935
|
-
true
|
|
936
|
-
);
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
pixelStorei = function(pname, param) {
|
|
941
|
-
switch (pname) {
|
|
942
|
-
// OpenGL ES will glGetError()=GL_INVALID_ENUM , so be here
|
|
943
|
-
// TODO: [WebGL和OpenGL的差异 - UNPACK_PREMULTIPLY_ALPHA_WEBGL](https://www.jianshu.com/p/bf21fda9a0b8)
|
|
944
|
-
case GLenum.UNPACK_COLORSPACE_CONVERSION_WEBGL:
|
|
945
|
-
case GLenum.UNPACK_FLIP_Y_WEBGL:
|
|
946
|
-
case GLenum.UNPACK_PREMULTIPLY_ALPHA_WEBGL:
|
|
947
|
-
break;
|
|
948
|
-
default:
|
|
949
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
950
|
-
this._canvas.id,
|
|
951
|
-
GLmethod.pixelStorei + ',' + pname + ',' + Number(param),
|
|
952
|
-
);
|
|
953
|
-
break;
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
polygonOffset = function(factor, units) {
|
|
958
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
959
|
-
this._canvas.id,
|
|
960
|
-
GLmethod.polygonOffset + ',' + factor + ',' + units
|
|
961
|
-
);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
readPixels = function(x, y, width, height, format, type, pixels) {
|
|
965
|
-
const result = WebGLRenderingContext.GBridge.callNative(
|
|
966
|
-
this._canvas.id,
|
|
967
|
-
GLmethod.readPixels + ',' + x + ',' + y + ',' + width + ',' + height + ',' + format + ',' + type
|
|
968
|
-
);
|
|
969
|
-
return result;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
renderbufferStorage = function(target, internalFormat, width, height) {
|
|
973
|
-
// WebGL can `GL_DEPTH_STENCIL` but OpenGL ES will getError so use `GL_DEPTH24_STENCIL8` instead
|
|
974
|
-
const intfmt = internalFormat === GLenum.DEPTH_STENCIL ? GLenum.DEPTH24_STENCIL8 : internalFormat;
|
|
975
|
-
|
|
976
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
977
|
-
this._canvas.id,
|
|
978
|
-
GLmethod.renderbufferStorage + ',' + target + ',' + intfmt + ',' + width + ',' + height,
|
|
979
|
-
true
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
sampleCoverage = function(value, invert) {
|
|
984
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
985
|
-
this._canvas.id,
|
|
986
|
-
GLmethod.sampleCoverage + ',' + value + ',' + Number(invert),
|
|
987
|
-
true
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
scissor = function(x, y, width, height) {
|
|
992
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
993
|
-
this._canvas.id,
|
|
994
|
-
GLmethod.scissor + ',' + x + ',' + y + ',' + width + ',' + height,
|
|
995
|
-
true
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
shaderSource = function(shader, source) {
|
|
1000
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1001
|
-
this._canvas.id,
|
|
1002
|
-
GLmethod.shaderSource + ',' + shader.id + ',' + source,
|
|
1003
|
-
// true, // if true, will cause no display in https://github.com/flyskywhy/snakeRN
|
|
1004
|
-
);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
stencilFunc = function(func, ref, mask) {
|
|
1008
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1009
|
-
this._canvas.id,
|
|
1010
|
-
GLmethod.stencilFunc + ',' + func + ',' + ref + ',' + mask,
|
|
1011
|
-
true
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
stencilFuncSeparate = function(face, func, ref, mask) {
|
|
1016
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1017
|
-
this._canvas.id,
|
|
1018
|
-
GLmethod.stencilFuncSeparate + ',' + face + ',' + func + ',' + ref + ',' + mask,
|
|
1019
|
-
true
|
|
1020
|
-
);
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
stencilMask = function(mask) {
|
|
1024
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1025
|
-
this._canvas.id,
|
|
1026
|
-
GLmethod.stencilMask + ',' + mask,
|
|
1027
|
-
true
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
stencilMaskSeparate = function(face, mask) {
|
|
1032
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1033
|
-
this._canvas.id,
|
|
1034
|
-
GLmethod.stencilMaskSeparate + ',' + face + ',' + mask,
|
|
1035
|
-
true
|
|
1036
|
-
);
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
stencilOp = function(fail, zfail, zpass) {
|
|
1040
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1041
|
-
this._canvas.id,
|
|
1042
|
-
GLmethod.stencilOp + ',' + fail + ',' + zfail + ',' + zpass
|
|
1043
|
-
);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
stencilOpSeparate = function(face, fail, zfail, zpass) {
|
|
1047
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1048
|
-
this._canvas.id,
|
|
1049
|
-
GLmethod.stencilOp + ',' + face + ',' + fail + ',' + zfail + ',' + zpass,
|
|
1050
|
-
true
|
|
1051
|
-
);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
texImage2D = function(...args) {
|
|
1055
|
-
this.flushJsCommands2CallNative();
|
|
1056
|
-
|
|
1057
|
-
if (!args[args.length - 1]) {
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
let isImagePreLoadedInNative = false;
|
|
1062
|
-
if (args.length === 6) {
|
|
1063
|
-
let image = args[5];
|
|
1064
|
-
// TODO: image start with 'data:image'
|
|
1065
|
-
if (image && image.src) {
|
|
1066
|
-
if (image.complete) {
|
|
1067
|
-
// HTMLImageElement
|
|
1068
|
-
isImagePreLoadedInNative = true;
|
|
1069
|
-
} else {
|
|
1070
|
-
// TODO: do we need automatically load Image here then go on?
|
|
1071
|
-
console.warn('HTMLImageElement not loaded!');
|
|
1072
|
-
return;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
if (isImagePreLoadedInNative) {
|
|
1078
|
-
if (WebGLRenderingContext.GBridge.Platform.OS === 'ios') {
|
|
1079
|
-
const [target, level, internalformat, format, type, image] = args;
|
|
1080
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1081
|
-
this._canvas.id,
|
|
1082
|
-
GLmethod.texImage2D + ',' + 6 + ',' + target + ',' + level + ',' + internalformat + ',' + format + ',' + type + ',' + image.src
|
|
1083
|
-
);
|
|
1084
|
-
} else {
|
|
1085
|
-
WebGLRenderingContext.GBridge.texImage2D(this._canvas.id, ...args);
|
|
1086
|
-
}
|
|
1087
|
-
} else {
|
|
1088
|
-
if (args.length === 6) {
|
|
1089
|
-
const [target, level, internalformat, format, type, image] = args;
|
|
1090
|
-
let imageData = {};
|
|
1091
|
-
const imageIsCanvas = image.hasOwnProperty('nodeName') && image.nodeName.toLowerCase() === 'canvas' && image._context;
|
|
1092
|
-
const imageIsImageData = image.data && image.width > 0 && image.height > 0;
|
|
1093
|
-
if (imageIsCanvas) {
|
|
1094
|
-
imageData = image._context.getImageData(0, 0, image.width, image.height);
|
|
1095
|
-
}
|
|
1096
|
-
if (imageIsImageData) {
|
|
1097
|
-
imageData = image;
|
|
1098
|
-
}
|
|
1099
|
-
if (imageData.data && imageData.width > 0 && imageData.height > 0) {
|
|
1100
|
-
// ImageData
|
|
1101
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1102
|
-
this._canvas.id,
|
|
1103
|
-
GLmethod.texImage2D + ',' + 9 + ',' + target + ',' + level + ',' + internalformat + ',' +
|
|
1104
|
-
imageData.width + ',' + imageData.height + ',' + 0 + ',' + format + ',' + type + ',' + processArray(new Uint8Array(imageData.data), true),
|
|
1105
|
-
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1106
|
-
);
|
|
1107
|
-
}
|
|
1108
|
-
} else if (args.length === 9) {
|
|
1109
|
-
const [target, level, internalformat, width, height, border, format, type, image] = args;
|
|
1110
|
-
// usage example 1: gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255]));
|
|
1111
|
-
// usage example 2: gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([187,157,202,255,222,199,255,255,108,75,68,255,139,107,110,255]));
|
|
1112
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1113
|
-
this._canvas.id,
|
|
1114
|
-
GLmethod.texImage2D + ',' + 9 + ',' + target + ',' + level + ',' + internalformat + ',' +
|
|
1115
|
-
width + ',' + height + ',' + border + ',' + format + ',' + type + ',' + processArray(image, true),
|
|
1116
|
-
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1117
|
-
);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
texParameterf = function(target, pname, param) {
|
|
1124
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1125
|
-
this._canvas.id,
|
|
1126
|
-
GLmethod.texParameterf + ',' + target + ',' + pname + ',' + param,
|
|
1127
|
-
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1128
|
-
);
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
texParameteri = function(target, pname, param) {
|
|
1132
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1133
|
-
this._canvas.id,
|
|
1134
|
-
GLmethod.texParameteri + ',' + target + ',' + pname + ',' + param,
|
|
1135
|
-
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1136
|
-
);
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
texSubImage2D = function(...args) {
|
|
1140
|
-
this.flushJsCommands2CallNative();
|
|
1141
|
-
|
|
1142
|
-
if (!args[args.length - 1]) {
|
|
1143
|
-
return;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
let isImagePreLoadedInNative = false;
|
|
1147
|
-
if (args.length === 7) {
|
|
1148
|
-
let image = args[6];
|
|
1149
|
-
// TODO: image start with 'data:image'
|
|
1150
|
-
if (image && image.src) {
|
|
1151
|
-
if (image.complete) {
|
|
1152
|
-
// HTMLImageElement
|
|
1153
|
-
isImagePreLoadedInNative = true;
|
|
1154
|
-
} else {
|
|
1155
|
-
// TODO: do we need automatically load Image here then go on?
|
|
1156
|
-
console.warn('HTMLImageElement not loaded!');
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
if (isImagePreLoadedInNative) {
|
|
1163
|
-
if (WebGLRenderingContext.GBridge.Platform.OS === 'ios') {
|
|
1164
|
-
const [target, level, xoffset, yoffset, format, type, image] = args;
|
|
1165
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1166
|
-
this._canvas.id,
|
|
1167
|
-
GLmethod.texSubImage2D + ',' + 7 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + format + ',' + type + ',' + image.src
|
|
1168
|
-
);
|
|
1169
|
-
} else {
|
|
1170
|
-
WebGLRenderingContext.GBridge.texSubImage2D(this._canvas.id, ...args);
|
|
1171
|
-
}
|
|
1172
|
-
} else {
|
|
1173
|
-
if (args.length === 7) {
|
|
1174
|
-
const [target, level, xoffset, yoffset, format, type, image] = args;
|
|
1175
|
-
let imageData = {};
|
|
1176
|
-
const imageIsCanvas = image.hasOwnProperty('nodeName') && image.nodeName.toLowerCase() === 'canvas' && image._context;
|
|
1177
|
-
const imageIsImageData = image.data && image.width > 0 && image.height > 0;
|
|
1178
|
-
if (imageIsCanvas) {
|
|
1179
|
-
imageData = image._context.getImageData(0, 0, image.width, image.height);
|
|
1180
|
-
}
|
|
1181
|
-
if (imageIsImageData) {
|
|
1182
|
-
imageData = image;
|
|
1183
|
-
}
|
|
1184
|
-
if (imageData.data && imageData.width > 0 && imageData.height > 0) {
|
|
1185
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1186
|
-
this._canvas.id,
|
|
1187
|
-
GLmethod.texSubImage2D + ',' + 9 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' +
|
|
1188
|
-
imageData.width + ',' + imageData.height + ',' + format + ',' + type + ',' + processArray(new Uint8Array(imageData.data), true),
|
|
1189
|
-
// true, // ref to texImage2D above
|
|
1190
|
-
);
|
|
1191
|
-
}
|
|
1192
|
-
} else if (args.length === 9) {
|
|
1193
|
-
const [target, level, xoffset, yoffset, width, height, format, type, image] = args;
|
|
1194
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1195
|
-
this._canvas.id,
|
|
1196
|
-
GLmethod.texSubImage2D + ',' + 9 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' +
|
|
1197
|
-
width + ',' + height + ',' + format + ',' + type + ',' + processArray(image, true),
|
|
1198
|
-
// true, // ref to texImage2D above
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
uniform1f = function(location, v0) {
|
|
1205
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1206
|
-
this._canvas.id,
|
|
1207
|
-
GLmethod.uniform1f + ',' + location.id + ',' + v0,
|
|
1208
|
-
true,
|
|
1209
|
-
);
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
uniform1fv = function(location, value) {
|
|
1213
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1214
|
-
this._canvas.id,
|
|
1215
|
-
GLmethod.uniform1fv + ',' + location.id + ',' + processArray(value),
|
|
1216
|
-
true
|
|
1217
|
-
);
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
uniform1i = function(location, v0) {
|
|
1221
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1222
|
-
this._canvas.id,
|
|
1223
|
-
GLmethod.uniform1i + ',' + location.id + ',' + v0,
|
|
1224
|
-
true, // TODO: maybe need more APP code to test
|
|
1225
|
-
);
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
uniform1iv = function(location, value) {
|
|
1229
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1230
|
-
this._canvas.id,
|
|
1231
|
-
GLmethod.uniform1iv + ',' + location.id + ',' + processArray(value),
|
|
1232
|
-
true
|
|
1233
|
-
);
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
uniform2f = function(location, v0, v1) {
|
|
1237
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1238
|
-
this._canvas.id,
|
|
1239
|
-
GLmethod.uniform2f + ',' + location.id + ',' + v0 + ',' + v1,
|
|
1240
|
-
true
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
uniform2fv = function(location, value) {
|
|
1245
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1246
|
-
this._canvas.id,
|
|
1247
|
-
GLmethod.uniform2fv + ',' + location.id + ',' + processArray(value),
|
|
1248
|
-
true
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
uniform2i = function(location, v0, v1) {
|
|
1253
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1254
|
-
this._canvas.id,
|
|
1255
|
-
GLmethod.uniform2i + ',' + location.id + ',' + v0 + ',' + v1,
|
|
1256
|
-
true
|
|
1257
|
-
);
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
uniform2iv = function(location, value) {
|
|
1261
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1262
|
-
this._canvas.id,
|
|
1263
|
-
GLmethod.uniform2iv + ',' + location.id + ',' + processArray(value),
|
|
1264
|
-
true
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
uniform3f = function(location, v0, v1, v2) {
|
|
1269
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1270
|
-
this._canvas.id,
|
|
1271
|
-
GLmethod.uniform3f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2,
|
|
1272
|
-
true
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
uniform3fv = function(location, value) {
|
|
1277
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1278
|
-
this._canvas.id,
|
|
1279
|
-
GLmethod.uniform3fv + ',' + location.id + ',' + processArray(value),
|
|
1280
|
-
true
|
|
1281
|
-
);
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
uniform3i = function(location, v0, v1, v2) {
|
|
1285
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1286
|
-
this._canvas.id,
|
|
1287
|
-
GLmethod.uniform3i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2,
|
|
1288
|
-
true
|
|
1289
|
-
);
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
uniform3iv = function(location, value) {
|
|
1293
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1294
|
-
this._canvas.id,
|
|
1295
|
-
GLmethod.uniform3iv + ',' + location.id + ',' + processArray(value),
|
|
1296
|
-
true
|
|
1297
|
-
);
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
uniform4f = function(location, v0, v1, v2, v3) {
|
|
1301
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1302
|
-
this._canvas.id,
|
|
1303
|
-
GLmethod.uniform4f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3,
|
|
1304
|
-
true
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
uniform4fv = function(location, value) {
|
|
1309
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1310
|
-
this._canvas.id,
|
|
1311
|
-
GLmethod.uniform4fv + ',' + location.id + ',' + processArray(value),
|
|
1312
|
-
true
|
|
1313
|
-
);
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
uniform4i = function(location, v0, v1, v2, v3) {
|
|
1317
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1318
|
-
this._canvas.id,
|
|
1319
|
-
GLmethod.uniform4i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3,
|
|
1320
|
-
true
|
|
1321
|
-
);
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
uniform4iv = function(location, value) {
|
|
1325
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1326
|
-
this._canvas.id,
|
|
1327
|
-
GLmethod.uniform4iv + ',' + location.id + ',' + processArray(value, true),
|
|
1328
|
-
true
|
|
1329
|
-
);
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
uniformMatrix2fv = function(location, transpose, value) {
|
|
1333
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1334
|
-
this._canvas.id,
|
|
1335
|
-
GLmethod.uniformMatrix2fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value),
|
|
1336
|
-
true
|
|
1337
|
-
);
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
uniformMatrix3fv = function(location, transpose, value) {
|
|
1341
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1342
|
-
this._canvas.id,
|
|
1343
|
-
GLmethod.uniformMatrix3fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value),
|
|
1344
|
-
true
|
|
1345
|
-
);
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
uniformMatrix4fv = function(location, transpose, value) {
|
|
1349
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1350
|
-
this._canvas.id,
|
|
1351
|
-
GLmethod.uniformMatrix4fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value),
|
|
1352
|
-
true
|
|
1353
|
-
);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
useProgram = function(progarm) {
|
|
1357
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1358
|
-
this._canvas.id,
|
|
1359
|
-
GLmethod.useProgram + ',' + progarm.id + '',
|
|
1360
|
-
true
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
validateProgram = function(program) {
|
|
1366
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1367
|
-
this._canvas.id,
|
|
1368
|
-
GLmethod.validateProgram + ',' + program.id,
|
|
1369
|
-
true
|
|
1370
|
-
);
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
vertexAttrib1f = function(index, v0) {
|
|
1374
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1375
|
-
this._canvas.id,
|
|
1376
|
-
GLmethod.vertexAttrib1f + ',' + index + ',' + v0,
|
|
1377
|
-
true
|
|
1378
|
-
);
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
vertexAttrib2f = function(index, v0, v1) {
|
|
1382
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1383
|
-
this._canvas.id,
|
|
1384
|
-
GLmethod.vertexAttrib2f + ',' + index + ',' + v0 + ',' + v1,
|
|
1385
|
-
true
|
|
1386
|
-
);
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
vertexAttrib3f = function(index, v0, v1, v2) {
|
|
1390
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1391
|
-
this._canvas.id,
|
|
1392
|
-
GLmethod.vertexAttrib3f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2,
|
|
1393
|
-
true
|
|
1394
|
-
);
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
vertexAttrib4f = function(index, v0, v1, v2, v3) {
|
|
1398
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1399
|
-
this._canvas.id,
|
|
1400
|
-
GLmethod.vertexAttrib4f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3,
|
|
1401
|
-
true
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
vertexAttrib1fv = function(index, value) {
|
|
1406
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1407
|
-
this._canvas.id,
|
|
1408
|
-
GLmethod.vertexAttrib1fv + ',' + index + ',' + processArray(value),
|
|
1409
|
-
true
|
|
1410
|
-
);
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
vertexAttrib2fv = function(index, value) {
|
|
1414
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1415
|
-
this._canvas.id,
|
|
1416
|
-
GLmethod.vertexAttrib2fv + ',' + index + ',' + processArray(value),
|
|
1417
|
-
true
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
vertexAttrib3fv = function(index, value) {
|
|
1422
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1423
|
-
this._canvas.id,
|
|
1424
|
-
GLmethod.vertexAttrib3fv + ',' + index + ',' + processArray(value),
|
|
1425
|
-
true
|
|
1426
|
-
);
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
vertexAttrib4fv = function(index, value) {
|
|
1430
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1431
|
-
this._canvas.id,
|
|
1432
|
-
GLmethod.vertexAttrib4fv + ',' + index + ',' + processArray(value),
|
|
1433
|
-
true
|
|
1434
|
-
);
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
vertexAttribPointer = function(index, size, type, normalized, stride, offset) {
|
|
1438
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1439
|
-
this._canvas.id,
|
|
1440
|
-
GLmethod.vertexAttribPointer + ',' + index + ',' + size + ',' + type + ',' + Number(normalized) + ',' + stride + ',' + offset,
|
|
1441
|
-
true
|
|
1442
|
-
);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
viewport = function(x, y, width, height) {
|
|
1446
|
-
const cmdArgs = GLmethod.viewport + ',' + x + ',' + y + ',' + width + ',' + height;
|
|
1447
|
-
if (WebGLRenderingContext.GBridge.Platform.OS === 'ios') {
|
|
1448
|
-
// ref to the comment in WebGLRenderingContext.GBridge.callNative()
|
|
1449
|
-
WebGLRenderingContext.GBridge.callViewport(this._canvas.id, cmdArgs);
|
|
1450
|
-
} else {
|
|
1451
|
-
// TODO: need some APP code to test which is better that will not cause low JS FPS if change
|
|
1452
|
-
// viewport() frequently just like comments in getImageData() of `2d/RenderingContext.js`
|
|
1453
|
-
if (this._canvas._disableAutoSwap) {
|
|
1454
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1455
|
-
this._canvas.id,
|
|
1456
|
-
cmdArgs,
|
|
1457
|
-
false,
|
|
1458
|
-
'webgl',
|
|
1459
|
-
'sync',
|
|
1460
|
-
'execWithDisplay',
|
|
1461
|
-
);
|
|
1462
|
-
// TODO: no matter above or below in https://github.com/flyskywhy/snakeRN can keep 30 JS FPS on Huawei Mate 20, maybe need more APP code to test
|
|
1463
|
-
// WebGLRenderingContext.GBridge.callNative(
|
|
1464
|
-
// this._canvas.id,
|
|
1465
|
-
// cmdArgs,
|
|
1466
|
-
// true,
|
|
1467
|
-
// );
|
|
1468
|
-
} else {
|
|
1469
|
-
WebGLRenderingContext.GBridge.callNative(
|
|
1470
|
-
this._canvas.id,
|
|
1471
|
-
cmdArgs,
|
|
1472
|
-
true, // TODO: no matter true or false in https://github.com/flyskywhy/snakeRN can keep 30 JS FPS on Huawei Mate 20, maybe need more APP code to test
|
|
1473
|
-
);
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
this._canvas._needRender = true;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1
|
+
import GLenum from './GLenum';
|
|
2
|
+
import ActiveInfo from './ActiveInfo';
|
|
3
|
+
import Buffer from './Buffer';
|
|
4
|
+
import Framebuffer from './Framebuffer';
|
|
5
|
+
import Renderbuffer from './Renderbuffer';
|
|
6
|
+
import Texture from './Texture';
|
|
7
|
+
import Program from './Program';
|
|
8
|
+
import Shader from './Shader';
|
|
9
|
+
import ShaderPrecisionFormat from './ShaderPrecisionFormat';
|
|
10
|
+
import UniformLocation from './UniformLocation';
|
|
11
|
+
import GLmethod from './GLmethod';
|
|
12
|
+
|
|
13
|
+
const processArray = (array, checkArrayType = false) => {
|
|
14
|
+
function joinArray(arr, sep) {
|
|
15
|
+
let res = '';
|
|
16
|
+
for (let i = 0; i < arr.length; i++) {
|
|
17
|
+
if (i !== 0) {
|
|
18
|
+
res += sep;
|
|
19
|
+
}
|
|
20
|
+
res += arr[i];
|
|
21
|
+
}
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let type = 'Float32Array';
|
|
26
|
+
if (checkArrayType) {
|
|
27
|
+
if (array instanceof Uint8Array) {
|
|
28
|
+
type = 'Uint8Array';
|
|
29
|
+
} else if (array instanceof Uint16Array) {
|
|
30
|
+
type = 'Uint16Array';
|
|
31
|
+
} else if (array instanceof Uint32Array) {
|
|
32
|
+
type = 'Uint32Array';
|
|
33
|
+
} else if (array instanceof Float32Array) {
|
|
34
|
+
type = 'Float32Array';
|
|
35
|
+
} else if (array instanceof ArrayBuffer) {
|
|
36
|
+
let uint8Array = new Uint8Array(array);
|
|
37
|
+
return 1 + ',' + btoa(joinArray(uint8Array, ','));
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error('Check array type failed. Array type is ' + typeof array);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ArrayTypes = {
|
|
44
|
+
Uint8Array: 1,
|
|
45
|
+
Uint16Array: 2,
|
|
46
|
+
Uint32Array: 4,
|
|
47
|
+
Float32Array: 14
|
|
48
|
+
};
|
|
49
|
+
return ArrayTypes[type] + ',' + btoa(joinArray(array, ','));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default class WebGLRenderingContext {
|
|
53
|
+
// static GBridge = null;
|
|
54
|
+
|
|
55
|
+
className = 'WebGLRenderingContext';
|
|
56
|
+
|
|
57
|
+
componentId = null;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_resetContextAttributes({}) {}
|
|
61
|
+
|
|
62
|
+
constructor(canvas, type, attrs) {
|
|
63
|
+
this._canvas = canvas;
|
|
64
|
+
this._type = type;
|
|
65
|
+
this._version = 'WebGL 1.0';
|
|
66
|
+
this._attrs = attrs;
|
|
67
|
+
this._map = new Map();
|
|
68
|
+
this._supportedExtensions = [];
|
|
69
|
+
|
|
70
|
+
Object.keys(GLenum)
|
|
71
|
+
.forEach(name => Object.defineProperty(this, name, {
|
|
72
|
+
value: GLenum[name]
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
this._resetContextAttributes({});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get canvas() {
|
|
79
|
+
return this._canvas;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
activeTexture = function(textureUnit) {
|
|
83
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
84
|
+
this._canvas.id,
|
|
85
|
+
GLmethod.activeTexture + ',' + textureUnit,
|
|
86
|
+
true
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
attachShader = function(progarm, shader) {
|
|
91
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
92
|
+
this._canvas.id,
|
|
93
|
+
GLmethod.attachShader + ',' + progarm.id + ',' + shader.id,
|
|
94
|
+
true
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
bindAttribLocation = function(program, index, name) {
|
|
99
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
100
|
+
this._canvas.id,
|
|
101
|
+
GLmethod.bindAttribLocation + ',' + program.id + ',' + index + ',' + name,
|
|
102
|
+
true
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
bindBuffer = function(target, buffer) {
|
|
107
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
108
|
+
this._canvas.id,
|
|
109
|
+
GLmethod.bindBuffer + ',' + target + ',' + (buffer ? buffer.id : 0),
|
|
110
|
+
true
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
bindFramebuffer = function(target, framebuffer) {
|
|
115
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
116
|
+
this._canvas.id,
|
|
117
|
+
GLmethod.bindFramebuffer + ',' + target + ',' + (framebuffer ? framebuffer.id : 0),
|
|
118
|
+
true
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
bindRenderbuffer = function(target, renderBuffer) {
|
|
123
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
124
|
+
this._canvas.id,
|
|
125
|
+
GLmethod.bindRenderbuffer + ',' + target + ',' + (renderBuffer ? renderBuffer.id : 0),
|
|
126
|
+
true
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
bindTexture = function(target, texture) {
|
|
131
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
132
|
+
this._canvas.id,
|
|
133
|
+
GLmethod.bindTexture + ',' + target + ',' + (texture ? texture.id : 0),
|
|
134
|
+
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
blendColor = function(r, g, b, a) {
|
|
139
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
140
|
+
this._canvas.id,
|
|
141
|
+
GLmethod.blendColor + ',' + r + ',' + g + ',' + b + ',' + a,
|
|
142
|
+
true
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
blendEquation = function(mode) {
|
|
147
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
148
|
+
this._canvas.id,
|
|
149
|
+
GLmethod.blendEquation + ',' + mode,
|
|
150
|
+
true
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
blendEquationSeparate = function(modeRGB, modeAlpha) {
|
|
155
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
156
|
+
this._canvas.id,
|
|
157
|
+
GLmethod.blendEquationSeparate + ',' + modeRGB + ',' + modeAlpha,
|
|
158
|
+
true
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
blendFunc = function(sfactor, dfactor) {
|
|
164
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
165
|
+
this._canvas.id,
|
|
166
|
+
GLmethod.blendFunc + ',' + sfactor + ',' + dfactor,
|
|
167
|
+
true
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
blendFuncSeparate = function(srcRGB, dstRGB, srcAlpha, dstAlpha) {
|
|
172
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
173
|
+
this._canvas.id,
|
|
174
|
+
GLmethod.blendFuncSeparate + ',' + srcRGB + ',' + dstRGB + ',' + srcAlpha + ',' + dstAlpha,
|
|
175
|
+
true
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
bufferData = function(target, data, usage) {
|
|
180
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
181
|
+
this._canvas.id,
|
|
182
|
+
GLmethod.bufferData + ',' + target + ',' + processArray(data, true) + ',' + usage,
|
|
183
|
+
true
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
bufferSubData = function(target, offset, data) {
|
|
188
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
189
|
+
this._canvas.id,
|
|
190
|
+
GLmethod.bufferSubData + ',' + target + ',' + offset + ',' + processArray(data, true),
|
|
191
|
+
true
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
checkFramebufferStatus = function(target) {
|
|
196
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
197
|
+
this._canvas.id,
|
|
198
|
+
GLmethod.checkFramebufferStatus + ',' + target
|
|
199
|
+
);
|
|
200
|
+
return Number(result);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// not a Web webgl API, used by @flyskywhy/react-native-gcanvas
|
|
204
|
+
flushJsCommands2CallNative(
|
|
205
|
+
methodType = 'sync',
|
|
206
|
+
optionType = 'execWithDisplay',
|
|
207
|
+
) {
|
|
208
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
209
|
+
this.componentId,
|
|
210
|
+
'',
|
|
211
|
+
false, // here false will let cmds cache be empty
|
|
212
|
+
'webgl',
|
|
213
|
+
methodType,
|
|
214
|
+
optionType,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
clear = function(mask) {
|
|
219
|
+
if (this._canvas._disableAutoSwap) {
|
|
220
|
+
this.flushJsCommands2CallNative();
|
|
221
|
+
// above exec cached cmds to generate and display graphics
|
|
222
|
+
// below add gl.clear to cmds cache to be exec next time
|
|
223
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
224
|
+
this._canvas.id,
|
|
225
|
+
GLmethod.clear + ',' + mask,
|
|
226
|
+
true,
|
|
227
|
+
);
|
|
228
|
+
} else {
|
|
229
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
230
|
+
this._canvas.id,
|
|
231
|
+
GLmethod.clear + ',' + mask,
|
|
232
|
+
true, // TODO: no matter true or false in https://github.com/flyskywhy/snakeRN can keep 60 JS FPS, maybe need more APP code to test
|
|
233
|
+
);
|
|
234
|
+
this._canvas._needRender = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
clearColor = function(r, g, b, a) {
|
|
239
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
240
|
+
this._canvas.id,
|
|
241
|
+
GLmethod.clearColor + ',' + r + ',' + g + ',' + b,
|
|
242
|
+
true
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
clearDepth = function(depth) {
|
|
247
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
248
|
+
this._canvas.id,
|
|
249
|
+
GLmethod.clearDepth + ',' + depth,
|
|
250
|
+
true
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
clearStencil = function(s) {
|
|
255
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
256
|
+
this._canvas.id,
|
|
257
|
+
GLmethod.clearStencil + ',' + s
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
colorMask = function(r, g, b, a) {
|
|
262
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
263
|
+
this._canvas.id,
|
|
264
|
+
GLmethod.colorMask + ',' + Number(r) + ',' + Number(g) + ',' + Number(b) + ',' + Number(a),
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
compileShader = function(shader) {
|
|
269
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
270
|
+
this._canvas.id,
|
|
271
|
+
GLmethod.compileShader + ',' + shader.id,
|
|
272
|
+
true
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
compressedTexImage2D = function(target, level, internalformat, width, height, border, pixels) {
|
|
277
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
278
|
+
this._canvas.id,
|
|
279
|
+
GLmethod.compressedTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' +
|
|
280
|
+
width + ',' + height + ',' + border + ',' + processArray(pixels),
|
|
281
|
+
true
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
compressedTexSubImage2D = function(target, level, xoffset, yoffset, width, height, format, pixels) {
|
|
286
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
287
|
+
this._canvas.id,
|
|
288
|
+
GLmethod.compressedTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' +
|
|
289
|
+
width + ',' + height + ',' + format + ',' + processArray(pixels),
|
|
290
|
+
true
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
copyTexImage2D = function(target, level, internalformat, x, y, width, height, border) {
|
|
296
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
297
|
+
this._canvas.id,
|
|
298
|
+
GLmethod.copyTexImage2D + ',' + target + ',' + level + ',' + internalformat + ',' + x + ',' + y + ',' +
|
|
299
|
+
width + ',' + height + ',' + border,
|
|
300
|
+
true
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
copyTexSubImage2D = function(target, level, xoffset, yoffset, x, y, width, height) {
|
|
305
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
306
|
+
this._canvas.id,
|
|
307
|
+
GLmethod.copyTexSubImage2D + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + x + ',' + y + ',' +
|
|
308
|
+
width + ',' + height,
|
|
309
|
+
true, // TODO: maybe need more APP code to test
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
createBuffer = function() {
|
|
314
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
315
|
+
this._canvas.id,
|
|
316
|
+
GLmethod.createBuffer + ''
|
|
317
|
+
);
|
|
318
|
+
const buffer = new Buffer(result);
|
|
319
|
+
this._map.set(buffer.uuid(), buffer);
|
|
320
|
+
return buffer;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
createFramebuffer = function() {
|
|
324
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
325
|
+
this._canvas.id,
|
|
326
|
+
GLmethod.createFramebuffer + ''
|
|
327
|
+
);
|
|
328
|
+
const framebuffer = new Framebuffer(result);
|
|
329
|
+
this._map.set(framebuffer.uuid(), framebuffer);
|
|
330
|
+
return framebuffer;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
createProgram = function() {
|
|
335
|
+
const id = WebGLRenderingContext.GBridge.callNative(
|
|
336
|
+
this._canvas.id,
|
|
337
|
+
GLmethod.createProgram + ''
|
|
338
|
+
);
|
|
339
|
+
const program = new Program(id);
|
|
340
|
+
this._map.set(program.uuid(), program);
|
|
341
|
+
return program;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
createRenderbuffer = function() {
|
|
345
|
+
const id = WebGLRenderingContext.GBridge.callNative(
|
|
346
|
+
this._canvas.id,
|
|
347
|
+
GLmethod.createRenderbuffer + ''
|
|
348
|
+
);
|
|
349
|
+
const renderBuffer = new Renderbuffer(id);
|
|
350
|
+
this._map.set(renderBuffer.uuid(), renderBuffer);
|
|
351
|
+
return renderBuffer;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
createShader = function(type) {
|
|
355
|
+
const id = WebGLRenderingContext.GBridge.callNative(
|
|
356
|
+
this._canvas.id,
|
|
357
|
+
GLmethod.createShader + ',' + type
|
|
358
|
+
);
|
|
359
|
+
const shader = new Shader(id, type);
|
|
360
|
+
this._map.set(shader.uuid(), shader);
|
|
361
|
+
return shader;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
createTexture = function() {
|
|
365
|
+
const id = WebGLRenderingContext.GBridge.callNative(
|
|
366
|
+
this._canvas.id,
|
|
367
|
+
GLmethod.createTexture + ''
|
|
368
|
+
);
|
|
369
|
+
const texture = new Texture(id);
|
|
370
|
+
this._map.set(texture.uuid(), texture);
|
|
371
|
+
return texture;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
cullFace = function(mode) {
|
|
375
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
376
|
+
this._canvas.id,
|
|
377
|
+
GLmethod.cullFace + ',' + mode,
|
|
378
|
+
true
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
deleteBuffer = function(buffer) {
|
|
384
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
385
|
+
this._canvas.id,
|
|
386
|
+
GLmethod.deleteBuffer + ',' + buffer.id,
|
|
387
|
+
true
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
deleteFramebuffer = function(framebuffer) {
|
|
392
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
393
|
+
this._canvas.id,
|
|
394
|
+
GLmethod.deleteFramebuffer + ',' + framebuffer.id,
|
|
395
|
+
true
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
deleteProgram = function(program) {
|
|
400
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
401
|
+
this._canvas.id,
|
|
402
|
+
GLmethod.deleteProgram + ',' + program.id,
|
|
403
|
+
true
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
deleteRenderbuffer = function(renderbuffer) {
|
|
408
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
409
|
+
this._canvas.id,
|
|
410
|
+
GLmethod.deleteRenderbuffer + ',' + renderbuffer.id,
|
|
411
|
+
true
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
deleteShader = function(shader) {
|
|
416
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
417
|
+
this._canvas.id,
|
|
418
|
+
GLmethod.deleteShader + ',' + shader.id,
|
|
419
|
+
true
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
deleteTexture = function(texture) {
|
|
424
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
425
|
+
this._canvas.id,
|
|
426
|
+
GLmethod.deleteTexture + ',' + texture.id,
|
|
427
|
+
true
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
depthFunc = function(func) {
|
|
432
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
433
|
+
this._canvas.id,
|
|
434
|
+
GLmethod.depthFunc + ',' + func
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
depthMask = function(flag) {
|
|
439
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
440
|
+
this._canvas.id,
|
|
441
|
+
GLmethod.depthMask + ',' + Number(flag),
|
|
442
|
+
true
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
depthRange = function(zNear, zFar) {
|
|
447
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
448
|
+
this._canvas.id,
|
|
449
|
+
GLmethod.depthRange + ',' + zNear + ',' + zFar,
|
|
450
|
+
true
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
detachShader = function(program, shader) {
|
|
455
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
456
|
+
this._canvas.id,
|
|
457
|
+
GLmethod.detachShader + ',' + program.id + ',' + shader.id,
|
|
458
|
+
true
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
disable = function(cap) {
|
|
463
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
464
|
+
this._canvas.id,
|
|
465
|
+
GLmethod.disable + ',' + cap,
|
|
466
|
+
true
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
disableVertexAttribArray = function(index) {
|
|
471
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
472
|
+
this._canvas.id,
|
|
473
|
+
GLmethod.disableVertexAttribArray + ',' + index,
|
|
474
|
+
true
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
drawArrays = function(mode, first, count) {
|
|
479
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
480
|
+
this._canvas.id,
|
|
481
|
+
GLmethod.drawArrays + ',' + mode + ',' + first + ',' + count,
|
|
482
|
+
true,
|
|
483
|
+
);
|
|
484
|
+
this._canvas._needRender = true;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
drawElements = function(mode, count, type, offset) {
|
|
488
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
489
|
+
this._canvas.id,
|
|
490
|
+
GLmethod.drawElements + ',' + mode + ',' + count + ',' + type + ',' + offset,
|
|
491
|
+
true,
|
|
492
|
+
);
|
|
493
|
+
this._canvas._needRender = true;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
enable = function(cap) {
|
|
497
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
498
|
+
this._canvas.id,
|
|
499
|
+
GLmethod.enable + ',' + cap,
|
|
500
|
+
true
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
enableVertexAttribArray = function(index) {
|
|
505
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
506
|
+
this._canvas.id,
|
|
507
|
+
GLmethod.enableVertexAttribArray + ',' + index,
|
|
508
|
+
true
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
flush = function() {
|
|
514
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
515
|
+
this._canvas.id,
|
|
516
|
+
GLmethod.flush + ''
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
framebufferRenderbuffer = function(target, attachment, textarget, texture) {
|
|
521
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
522
|
+
this._canvas.id,
|
|
523
|
+
GLmethod.framebufferRenderbuffer + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0),
|
|
524
|
+
true
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
framebufferTexture2D = function(target, attachment, textarget, texture, level) {
|
|
529
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
530
|
+
this._canvas.id,
|
|
531
|
+
GLmethod.framebufferTexture2D + ',' + target + ',' + attachment + ',' + textarget + ',' + (texture ? texture.id : 0) + ',' + level,
|
|
532
|
+
true
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
frontFace = function(mode) {
|
|
537
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
538
|
+
this._canvas.id,
|
|
539
|
+
GLmethod.frontFace + ',' + mode,
|
|
540
|
+
true
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
generateMipmap = function(target) {
|
|
545
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
546
|
+
this._canvas.id,
|
|
547
|
+
GLmethod.generateMipmap + ',' + target,
|
|
548
|
+
true
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
getActiveAttrib = function(progarm, index) {
|
|
553
|
+
const resultString = WebGLRenderingContext.GBridge.callNative(
|
|
554
|
+
this._canvas.id,
|
|
555
|
+
GLmethod.getActiveAttrib + ',' + progarm.id + ',' + index
|
|
556
|
+
);
|
|
557
|
+
const [type, size, name] = resultString.split(',');
|
|
558
|
+
return new ActiveInfo({
|
|
559
|
+
type: Number(type),
|
|
560
|
+
size: Number(size),
|
|
561
|
+
name
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
getActiveUniform = function(progarm, index) {
|
|
566
|
+
const resultString = WebGLRenderingContext.GBridge.callNative(
|
|
567
|
+
this._canvas.id,
|
|
568
|
+
GLmethod.getActiveUniform + ',' + progarm.id + ',' + index
|
|
569
|
+
);
|
|
570
|
+
const [type, size, name] = resultString.split(',');
|
|
571
|
+
return new ActiveInfo({
|
|
572
|
+
type: Number(type),
|
|
573
|
+
size: Number(size),
|
|
574
|
+
name
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
getAttachedShaders = function(progarm) {
|
|
579
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
580
|
+
this._canvas.id,
|
|
581
|
+
GLmethod.getAttachedShaders + ',' + progarm.id
|
|
582
|
+
);
|
|
583
|
+
const [type, ...ids] = result;
|
|
584
|
+
return ids.map(id => this._map.get(Shader.uuid(id)));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
getAttribLocation = function(progarm, name) {
|
|
588
|
+
return WebGLRenderingContext.GBridge.callNative(
|
|
589
|
+
this._canvas.id,
|
|
590
|
+
GLmethod.getAttribLocation + ',' + progarm.id + ',' + name
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
getBufferParameter = function(target, pname) {
|
|
595
|
+
const [type, res] = WebGLRenderingContext.GBridge.callNative(
|
|
596
|
+
this._canvas.id,
|
|
597
|
+
GLmethod.getBufferParameter + ',' + target + ',' + pname
|
|
598
|
+
);
|
|
599
|
+
return res;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// http://web-developer-articles.blogspot.com/2015/12/webgl-rendering-context.html
|
|
603
|
+
// A current implementation of WebGL in a flagship browser will produce the following list of attributes and their default values:
|
|
604
|
+
// {
|
|
605
|
+
// antialias: true
|
|
606
|
+
// depth: true
|
|
607
|
+
// premultipliedAlpha: true
|
|
608
|
+
// preserveDrawingBuffer: false
|
|
609
|
+
// stencil: false
|
|
610
|
+
// }
|
|
611
|
+
//
|
|
612
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes
|
|
613
|
+
// the getContextAttributes method returns an object that describes the attributes set on this context, for example:
|
|
614
|
+
// {
|
|
615
|
+
// alpha: true,
|
|
616
|
+
// antialias: true,
|
|
617
|
+
// depth: true,
|
|
618
|
+
// failIfMajorPerformanceCaveat: false,
|
|
619
|
+
// powerPreference: "default",
|
|
620
|
+
// premultipliedAlpha: true,
|
|
621
|
+
// preserveDrawingBuffer: false,
|
|
622
|
+
// stencil: false,
|
|
623
|
+
// desynchronized: false
|
|
624
|
+
// }
|
|
625
|
+
getContextAttributesResult = {
|
|
626
|
+
alpha: true,
|
|
627
|
+
antialias: true,
|
|
628
|
+
depth: true,
|
|
629
|
+
failIfMajorPerformanceCaveat: false,
|
|
630
|
+
powerPreference: "default",
|
|
631
|
+
premultipliedAlpha: false,
|
|
632
|
+
preserveDrawingBuffer: false,
|
|
633
|
+
stencil: true,
|
|
634
|
+
desynchronized: false
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
getContextAttributes = function() {
|
|
638
|
+
return this.getContextAttributesResult;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
getError = function() {
|
|
642
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
643
|
+
this._canvas.id,
|
|
644
|
+
GLmethod.getError + ''
|
|
645
|
+
);
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
getExtension = function(name) {
|
|
650
|
+
this.getSupportedExtensions();
|
|
651
|
+
|
|
652
|
+
switch (name) {
|
|
653
|
+
// return null to let _initGLContext() in @babylonjs@5.1.0/core/Engines/thinEngine.js works
|
|
654
|
+
case 'EXT_disjoint_timer_query':
|
|
655
|
+
case 'EXT_disjoint_timer_query_webgl2':
|
|
656
|
+
case 'OES_texture_float':
|
|
657
|
+
case 'OES_texture_half_float':
|
|
658
|
+
case 'OES_vertex_array_object':
|
|
659
|
+
case 'KHR_parallel_shader_compile':
|
|
660
|
+
case 'EXT_texture_filter_anisotropic':
|
|
661
|
+
case 'WEBKIT_EXT_texture_filter_anisotropic':
|
|
662
|
+
case 'MOZ_EXT_texture_filter_anisotropic':
|
|
663
|
+
|
|
664
|
+
// maybe some APP need these
|
|
665
|
+
// case 'OES_texture_float_linear':
|
|
666
|
+
// case 'OES_texture_half_float_linear':
|
|
667
|
+
return null;
|
|
668
|
+
default:
|
|
669
|
+
return this._supportedExtensions.includes(name) ? true : null;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
getFramebufferAttachmentParameter = function(target, attachment, pname) {
|
|
674
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
675
|
+
this._canvas.id,
|
|
676
|
+
GLmethod.getFramebufferAttachmentParameter + ',' + target + ',' + attachment + ',' + pname
|
|
677
|
+
);
|
|
678
|
+
switch (pname) {
|
|
679
|
+
case GLenum.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
|
680
|
+
return this._map.get(Renderbuffer.uuid(result)) || this._map.get(Texture.uuid(result)) || null;
|
|
681
|
+
default:
|
|
682
|
+
return result;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
getParameter = function(pname) {
|
|
687
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
688
|
+
this._canvas.id,
|
|
689
|
+
GLmethod.getParameter + ',' + pname
|
|
690
|
+
);
|
|
691
|
+
switch (pname) {
|
|
692
|
+
case GLenum.VERSION:
|
|
693
|
+
return this._version + result.replace(/.,/, ' ');
|
|
694
|
+
case GLenum.ARRAY_BUFFER_BINDING: // buffer
|
|
695
|
+
case GLenum.ELEMENT_ARRAY_BUFFER_BINDING: // buffer
|
|
696
|
+
return this._map.get(Buffer.uuid(result)) || null;
|
|
697
|
+
case GLenum.CURRENT_PROGRAM: // program
|
|
698
|
+
return this._map.get(Program.uuid(result)) || null;
|
|
699
|
+
case GLenum.FRAMEBUFFER_BINDING: // framebuffer
|
|
700
|
+
return this._map.get(Framebuffer.uuid(result)) || null;
|
|
701
|
+
case GLenum.RENDERBUFFER_BINDING: // renderbuffer
|
|
702
|
+
return this._map.get(Renderbuffer.uuid(result)) || null;
|
|
703
|
+
case GLenum.TEXTURE_BINDING_2D: // texture
|
|
704
|
+
case GLenum.TEXTURE_BINDING_CUBE_MAP: // texture
|
|
705
|
+
return this._map.get(Texture.uuid(result)) || null;
|
|
706
|
+
case GLenum.ALIASED_LINE_WIDTH_RANGE: // Float32Array
|
|
707
|
+
case GLenum.ALIASED_POINT_SIZE_RANGE: // Float32Array
|
|
708
|
+
case GLenum.BLEND_COLOR: // Float32Array
|
|
709
|
+
case GLenum.COLOR_CLEAR_VALUE: // Float32Array
|
|
710
|
+
case GLenum.DEPTH_RANGE: // Float32Array
|
|
711
|
+
case GLenum.MAX_VIEWPORT_DIMS: // Int32Array
|
|
712
|
+
case GLenum.SCISSOR_BOX: // Int32Array
|
|
713
|
+
case GLenum.VIEWPORT: // Int32Array
|
|
714
|
+
case GLenum.COMPRESSED_TEXTURE_FORMATS: // Uint32Array
|
|
715
|
+
default:
|
|
716
|
+
const [type, ...res] = result.split(',');
|
|
717
|
+
if (res.length === 1) {
|
|
718
|
+
return Number(res[0]);
|
|
719
|
+
} else {
|
|
720
|
+
return res.map(Number);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
getProgramInfoLog = function(progarm) {
|
|
726
|
+
return WebGLRenderingContext.GBridge.callNative(
|
|
727
|
+
this._canvas.id,
|
|
728
|
+
GLmethod.getProgramInfoLog + ',' + progarm.id
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
getProgramParameter = function(program, pname) {
|
|
733
|
+
const res = WebGLRenderingContext.GBridge.callNative(
|
|
734
|
+
this._canvas.id,
|
|
735
|
+
GLmethod.getProgramParameter + ',' + program.id + ',' + pname
|
|
736
|
+
);
|
|
737
|
+
|
|
738
|
+
const [type, result] = res.split(',').map(i => parseInt(i));
|
|
739
|
+
|
|
740
|
+
if (type === 1) {
|
|
741
|
+
return Boolean(result);
|
|
742
|
+
} else if (type === 2) {
|
|
743
|
+
return result;
|
|
744
|
+
} else {
|
|
745
|
+
throw new Error('Unrecongized program paramater ' + res + ', type: ' + typeof res);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
getRenderbufferParameter = function(target, pname) {
|
|
751
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
752
|
+
this._canvas.id,
|
|
753
|
+
GLmethod.getRenderbufferParameter + ',' + target + ',' + pname
|
|
754
|
+
);
|
|
755
|
+
return result;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
getShaderInfoLog = function(shader) {
|
|
760
|
+
return WebGLRenderingContext.GBridge.callNative(
|
|
761
|
+
this._canvas.id,
|
|
762
|
+
GLmethod.getShaderInfoLog + ',' + shader.id
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
getShaderParameter = function(shader, pname) {
|
|
767
|
+
return WebGLRenderingContext.GBridge.callNative(
|
|
768
|
+
this._canvas.id,
|
|
769
|
+
GLmethod.getShaderParameter + ',' + shader.id + ',' + pname
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
getShaderPrecisionFormat = function(shaderType, precisionType) {
|
|
774
|
+
const [rangeMin, rangeMax, precision] = WebGLRenderingContext.GBridge.callNative(
|
|
775
|
+
this._canvas.id,
|
|
776
|
+
GLmethod.getShaderPrecisionFormat + ',' + shaderType + ',' + precisionType
|
|
777
|
+
);
|
|
778
|
+
const shaderPrecisionFormat = new ShaderPrecisionFormat({
|
|
779
|
+
rangeMin: Number(rangeMin),
|
|
780
|
+
rangeMax: Number(rangeMax),
|
|
781
|
+
precision: Number(precision)
|
|
782
|
+
});
|
|
783
|
+
return shaderPrecisionFormat;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
getShaderSource = function(shader) {
|
|
787
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
788
|
+
this._canvas.id,
|
|
789
|
+
GLmethod.getShaderSource + ',' + shader.id
|
|
790
|
+
);
|
|
791
|
+
return result;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
getSupportedExtensions = function() {
|
|
795
|
+
if (this._supportedExtensions.length === 0) {
|
|
796
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
797
|
+
this._canvas.id,
|
|
798
|
+
GLmethod.getSupportedExtensions + '',
|
|
799
|
+
);
|
|
800
|
+
result.split(' ').map(extension => {
|
|
801
|
+
if (extension !== '') {
|
|
802
|
+
this._supportedExtensions.push(extension.replace(/^GL_/, ''));
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
let supportsWebGL2 = false;
|
|
807
|
+
let version = Number(this.getParameter(GLenum.VERSION).replace(/^.*OpenGL ES /, '').replace(/ .*$/, ''));
|
|
808
|
+
if (version !== NaN && version >= 3.0) {
|
|
809
|
+
supportsWebGL2 = true;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (supportsWebGL2) {
|
|
813
|
+
this._supportedExtensions.push('WEBGL_compressed_texture_astc');
|
|
814
|
+
this._supportedExtensions.push('WEBGL_compressed_texture_etc');
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return this._supportedExtensions;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
getTexParameter = function(target, pname) {
|
|
822
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
823
|
+
this._canvas.id,
|
|
824
|
+
GLmethod.getTexParameter + ',' + target + ',' + pname
|
|
825
|
+
);
|
|
826
|
+
return result;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
getUniformLocation = function(program, name) {
|
|
830
|
+
const id = WebGLRenderingContext.GBridge.callNative(
|
|
831
|
+
this._canvas.id,
|
|
832
|
+
GLmethod.getUniformLocation + ',' + program.id + ',' + name
|
|
833
|
+
);
|
|
834
|
+
if (id === 'null' || id === -1) {
|
|
835
|
+
return null;
|
|
836
|
+
} else {
|
|
837
|
+
return new UniformLocation(Number(id), name);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
getVertexAttrib = function(index, pname) {
|
|
842
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
843
|
+
this._canvas.id,
|
|
844
|
+
GLmethod.getVertexAttrib + ',' + index + ',' + pname
|
|
845
|
+
);
|
|
846
|
+
switch (pname) {
|
|
847
|
+
case GLenum.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
|
|
848
|
+
return this._map.get(Buffer.uuid(result)) || null;
|
|
849
|
+
case GLenum.CURRENT_VERTEX_ATTRIB: // Float32Array
|
|
850
|
+
default:
|
|
851
|
+
return result;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
getVertexAttribOffset = function(index, pname) {
|
|
856
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
857
|
+
this._canvas.id,
|
|
858
|
+
GLmethod.getVertexAttribOffset + ',' + index + ',' + pname
|
|
859
|
+
);
|
|
860
|
+
return Number(result);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
isBuffer = function(buffer) {
|
|
864
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
865
|
+
this._canvas.id,
|
|
866
|
+
GLmethod.isBuffer + ',' + buffer.id
|
|
867
|
+
);
|
|
868
|
+
return Boolean(result);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
isContextLost = function() {
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
isEnabled = function(cap) {
|
|
876
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
877
|
+
this._canvas.id,
|
|
878
|
+
GLmethod.isEnabled + ',' + cap
|
|
879
|
+
);
|
|
880
|
+
return Boolean(result);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
isFramebuffer = function(framebuffer) {
|
|
884
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
885
|
+
this._canvas.id,
|
|
886
|
+
GLmethod.isFramebuffer + ',' + framebuffer.id
|
|
887
|
+
);
|
|
888
|
+
return Boolean(result);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
isProgram = function(program) {
|
|
892
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
893
|
+
this._canvas.id,
|
|
894
|
+
GLmethod.isProgram + ',' + program.id
|
|
895
|
+
);
|
|
896
|
+
return Boolean(result);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
isRenderbuffer = function(renderBuffer) {
|
|
900
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
901
|
+
this._canvas.id,
|
|
902
|
+
GLmethod.isRenderbuffer + ',' + renderBuffer.id
|
|
903
|
+
);
|
|
904
|
+
return Boolean(result);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
isShader = function(shader) {
|
|
908
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
909
|
+
this._canvas.id,
|
|
910
|
+
GLmethod.isShader + ',' + shader.id
|
|
911
|
+
);
|
|
912
|
+
return Boolean(result);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
isTexture = function(texture) {
|
|
916
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
917
|
+
this._canvas.id,
|
|
918
|
+
GLmethod.isTexture + ',' + texture.id
|
|
919
|
+
);
|
|
920
|
+
return Boolean(result);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
lineWidth = function(width) {
|
|
924
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
925
|
+
this._canvas.id,
|
|
926
|
+
GLmethod.lineWidth + ',' + width,
|
|
927
|
+
true
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
linkProgram = function(program) {
|
|
932
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
933
|
+
this._canvas.id,
|
|
934
|
+
GLmethod.linkProgram + ',' + program.id,
|
|
935
|
+
true
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
pixelStorei = function(pname, param) {
|
|
941
|
+
switch (pname) {
|
|
942
|
+
// OpenGL ES will glGetError()=GL_INVALID_ENUM , so be here
|
|
943
|
+
// TODO: [WebGL和OpenGL的差异 - UNPACK_PREMULTIPLY_ALPHA_WEBGL](https://www.jianshu.com/p/bf21fda9a0b8)
|
|
944
|
+
case GLenum.UNPACK_COLORSPACE_CONVERSION_WEBGL:
|
|
945
|
+
case GLenum.UNPACK_FLIP_Y_WEBGL:
|
|
946
|
+
case GLenum.UNPACK_PREMULTIPLY_ALPHA_WEBGL:
|
|
947
|
+
break;
|
|
948
|
+
default:
|
|
949
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
950
|
+
this._canvas.id,
|
|
951
|
+
GLmethod.pixelStorei + ',' + pname + ',' + Number(param),
|
|
952
|
+
);
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
polygonOffset = function(factor, units) {
|
|
958
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
959
|
+
this._canvas.id,
|
|
960
|
+
GLmethod.polygonOffset + ',' + factor + ',' + units
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
readPixels = function(x, y, width, height, format, type, pixels) {
|
|
965
|
+
const result = WebGLRenderingContext.GBridge.callNative(
|
|
966
|
+
this._canvas.id,
|
|
967
|
+
GLmethod.readPixels + ',' + x + ',' + y + ',' + width + ',' + height + ',' + format + ',' + type
|
|
968
|
+
);
|
|
969
|
+
return result;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
renderbufferStorage = function(target, internalFormat, width, height) {
|
|
973
|
+
// WebGL can `GL_DEPTH_STENCIL` but OpenGL ES will getError so use `GL_DEPTH24_STENCIL8` instead
|
|
974
|
+
const intfmt = internalFormat === GLenum.DEPTH_STENCIL ? GLenum.DEPTH24_STENCIL8 : internalFormat;
|
|
975
|
+
|
|
976
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
977
|
+
this._canvas.id,
|
|
978
|
+
GLmethod.renderbufferStorage + ',' + target + ',' + intfmt + ',' + width + ',' + height,
|
|
979
|
+
true
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
sampleCoverage = function(value, invert) {
|
|
984
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
985
|
+
this._canvas.id,
|
|
986
|
+
GLmethod.sampleCoverage + ',' + value + ',' + Number(invert),
|
|
987
|
+
true
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
scissor = function(x, y, width, height) {
|
|
992
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
993
|
+
this._canvas.id,
|
|
994
|
+
GLmethod.scissor + ',' + x + ',' + y + ',' + width + ',' + height,
|
|
995
|
+
true
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
shaderSource = function(shader, source) {
|
|
1000
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1001
|
+
this._canvas.id,
|
|
1002
|
+
GLmethod.shaderSource + ',' + shader.id + ',' + source,
|
|
1003
|
+
// true, // if true, will cause no display in https://github.com/flyskywhy/snakeRN
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
stencilFunc = function(func, ref, mask) {
|
|
1008
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1009
|
+
this._canvas.id,
|
|
1010
|
+
GLmethod.stencilFunc + ',' + func + ',' + ref + ',' + mask,
|
|
1011
|
+
true
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
stencilFuncSeparate = function(face, func, ref, mask) {
|
|
1016
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1017
|
+
this._canvas.id,
|
|
1018
|
+
GLmethod.stencilFuncSeparate + ',' + face + ',' + func + ',' + ref + ',' + mask,
|
|
1019
|
+
true
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
stencilMask = function(mask) {
|
|
1024
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1025
|
+
this._canvas.id,
|
|
1026
|
+
GLmethod.stencilMask + ',' + mask,
|
|
1027
|
+
true
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
stencilMaskSeparate = function(face, mask) {
|
|
1032
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1033
|
+
this._canvas.id,
|
|
1034
|
+
GLmethod.stencilMaskSeparate + ',' + face + ',' + mask,
|
|
1035
|
+
true
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
stencilOp = function(fail, zfail, zpass) {
|
|
1040
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1041
|
+
this._canvas.id,
|
|
1042
|
+
GLmethod.stencilOp + ',' + fail + ',' + zfail + ',' + zpass
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
stencilOpSeparate = function(face, fail, zfail, zpass) {
|
|
1047
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1048
|
+
this._canvas.id,
|
|
1049
|
+
GLmethod.stencilOp + ',' + face + ',' + fail + ',' + zfail + ',' + zpass,
|
|
1050
|
+
true
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
texImage2D = function(...args) {
|
|
1055
|
+
this.flushJsCommands2CallNative();
|
|
1056
|
+
|
|
1057
|
+
if (!args[args.length - 1]) {
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
let isImagePreLoadedInNative = false;
|
|
1062
|
+
if (args.length === 6) {
|
|
1063
|
+
let image = args[5];
|
|
1064
|
+
// TODO: image start with 'data:image'
|
|
1065
|
+
if (image && image.src) {
|
|
1066
|
+
if (image.complete) {
|
|
1067
|
+
// HTMLImageElement
|
|
1068
|
+
isImagePreLoadedInNative = true;
|
|
1069
|
+
} else {
|
|
1070
|
+
// TODO: do we need automatically load Image here then go on?
|
|
1071
|
+
console.warn('HTMLImageElement not loaded!');
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
if (isImagePreLoadedInNative) {
|
|
1078
|
+
if (WebGLRenderingContext.GBridge.Platform.OS === 'ios') {
|
|
1079
|
+
const [target, level, internalformat, format, type, image] = args;
|
|
1080
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1081
|
+
this._canvas.id,
|
|
1082
|
+
GLmethod.texImage2D + ',' + 6 + ',' + target + ',' + level + ',' + internalformat + ',' + format + ',' + type + ',' + image.src
|
|
1083
|
+
);
|
|
1084
|
+
} else {
|
|
1085
|
+
WebGLRenderingContext.GBridge.texImage2D(this._canvas.id, ...args);
|
|
1086
|
+
}
|
|
1087
|
+
} else {
|
|
1088
|
+
if (args.length === 6) {
|
|
1089
|
+
const [target, level, internalformat, format, type, image] = args;
|
|
1090
|
+
let imageData = {};
|
|
1091
|
+
const imageIsCanvas = image.hasOwnProperty('nodeName') && image.nodeName.toLowerCase() === 'canvas' && image._context;
|
|
1092
|
+
const imageIsImageData = image.data && image.width > 0 && image.height > 0;
|
|
1093
|
+
if (imageIsCanvas) {
|
|
1094
|
+
imageData = image._context.getImageData(0, 0, image.width, image.height);
|
|
1095
|
+
}
|
|
1096
|
+
if (imageIsImageData) {
|
|
1097
|
+
imageData = image;
|
|
1098
|
+
}
|
|
1099
|
+
if (imageData.data && imageData.width > 0 && imageData.height > 0) {
|
|
1100
|
+
// ImageData
|
|
1101
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1102
|
+
this._canvas.id,
|
|
1103
|
+
GLmethod.texImage2D + ',' + 9 + ',' + target + ',' + level + ',' + internalformat + ',' +
|
|
1104
|
+
imageData.width + ',' + imageData.height + ',' + 0 + ',' + format + ',' + type + ',' + processArray(new Uint8Array(imageData.data), true),
|
|
1105
|
+
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
} else if (args.length === 9) {
|
|
1109
|
+
const [target, level, internalformat, width, height, border, format, type, image] = args;
|
|
1110
|
+
// usage example 1: gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255]));
|
|
1111
|
+
// usage example 2: gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([187,157,202,255,222,199,255,255,108,75,68,255,139,107,110,255]));
|
|
1112
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1113
|
+
this._canvas.id,
|
|
1114
|
+
GLmethod.texImage2D + ',' + 9 + ',' + target + ',' + level + ',' + internalformat + ',' +
|
|
1115
|
+
width + ',' + height + ',' + border + ',' + format + ',' + type + ',' + processArray(image, true),
|
|
1116
|
+
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
texParameterf = function(target, pname, param) {
|
|
1124
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1125
|
+
this._canvas.id,
|
|
1126
|
+
GLmethod.texParameterf + ',' + target + ',' + pname + ',' + param,
|
|
1127
|
+
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
texParameteri = function(target, pname, param) {
|
|
1132
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1133
|
+
this._canvas.id,
|
|
1134
|
+
GLmethod.texParameteri + ',' + target + ',' + pname + ',' + param,
|
|
1135
|
+
// true, // if true, will flick before display all in https://github.com/flyskywhy/GCanvasRNExamples/src/nonDeclarative.js
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
texSubImage2D = function(...args) {
|
|
1140
|
+
this.flushJsCommands2CallNative();
|
|
1141
|
+
|
|
1142
|
+
if (!args[args.length - 1]) {
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
let isImagePreLoadedInNative = false;
|
|
1147
|
+
if (args.length === 7) {
|
|
1148
|
+
let image = args[6];
|
|
1149
|
+
// TODO: image start with 'data:image'
|
|
1150
|
+
if (image && image.src) {
|
|
1151
|
+
if (image.complete) {
|
|
1152
|
+
// HTMLImageElement
|
|
1153
|
+
isImagePreLoadedInNative = true;
|
|
1154
|
+
} else {
|
|
1155
|
+
// TODO: do we need automatically load Image here then go on?
|
|
1156
|
+
console.warn('HTMLImageElement not loaded!');
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
if (isImagePreLoadedInNative) {
|
|
1163
|
+
if (WebGLRenderingContext.GBridge.Platform.OS === 'ios') {
|
|
1164
|
+
const [target, level, xoffset, yoffset, format, type, image] = args;
|
|
1165
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1166
|
+
this._canvas.id,
|
|
1167
|
+
GLmethod.texSubImage2D + ',' + 7 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' + format + ',' + type + ',' + image.src
|
|
1168
|
+
);
|
|
1169
|
+
} else {
|
|
1170
|
+
WebGLRenderingContext.GBridge.texSubImage2D(this._canvas.id, ...args);
|
|
1171
|
+
}
|
|
1172
|
+
} else {
|
|
1173
|
+
if (args.length === 7) {
|
|
1174
|
+
const [target, level, xoffset, yoffset, format, type, image] = args;
|
|
1175
|
+
let imageData = {};
|
|
1176
|
+
const imageIsCanvas = image.hasOwnProperty('nodeName') && image.nodeName.toLowerCase() === 'canvas' && image._context;
|
|
1177
|
+
const imageIsImageData = image.data && image.width > 0 && image.height > 0;
|
|
1178
|
+
if (imageIsCanvas) {
|
|
1179
|
+
imageData = image._context.getImageData(0, 0, image.width, image.height);
|
|
1180
|
+
}
|
|
1181
|
+
if (imageIsImageData) {
|
|
1182
|
+
imageData = image;
|
|
1183
|
+
}
|
|
1184
|
+
if (imageData.data && imageData.width > 0 && imageData.height > 0) {
|
|
1185
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1186
|
+
this._canvas.id,
|
|
1187
|
+
GLmethod.texSubImage2D + ',' + 9 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' +
|
|
1188
|
+
imageData.width + ',' + imageData.height + ',' + format + ',' + type + ',' + processArray(new Uint8Array(imageData.data), true),
|
|
1189
|
+
// true, // ref to texImage2D above
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
} else if (args.length === 9) {
|
|
1193
|
+
const [target, level, xoffset, yoffset, width, height, format, type, image] = args;
|
|
1194
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1195
|
+
this._canvas.id,
|
|
1196
|
+
GLmethod.texSubImage2D + ',' + 9 + ',' + target + ',' + level + ',' + xoffset + ',' + yoffset + ',' +
|
|
1197
|
+
width + ',' + height + ',' + format + ',' + type + ',' + processArray(image, true),
|
|
1198
|
+
// true, // ref to texImage2D above
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
uniform1f = function(location, v0) {
|
|
1205
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1206
|
+
this._canvas.id,
|
|
1207
|
+
GLmethod.uniform1f + ',' + location.id + ',' + v0,
|
|
1208
|
+
true,
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
uniform1fv = function(location, value) {
|
|
1213
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1214
|
+
this._canvas.id,
|
|
1215
|
+
GLmethod.uniform1fv + ',' + location.id + ',' + processArray(value),
|
|
1216
|
+
true
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
uniform1i = function(location, v0) {
|
|
1221
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1222
|
+
this._canvas.id,
|
|
1223
|
+
GLmethod.uniform1i + ',' + location.id + ',' + v0,
|
|
1224
|
+
true, // TODO: maybe need more APP code to test
|
|
1225
|
+
);
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
uniform1iv = function(location, value) {
|
|
1229
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1230
|
+
this._canvas.id,
|
|
1231
|
+
GLmethod.uniform1iv + ',' + location.id + ',' + processArray(value),
|
|
1232
|
+
true
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
uniform2f = function(location, v0, v1) {
|
|
1237
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1238
|
+
this._canvas.id,
|
|
1239
|
+
GLmethod.uniform2f + ',' + location.id + ',' + v0 + ',' + v1,
|
|
1240
|
+
true
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
uniform2fv = function(location, value) {
|
|
1245
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1246
|
+
this._canvas.id,
|
|
1247
|
+
GLmethod.uniform2fv + ',' + location.id + ',' + processArray(value),
|
|
1248
|
+
true
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
uniform2i = function(location, v0, v1) {
|
|
1253
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1254
|
+
this._canvas.id,
|
|
1255
|
+
GLmethod.uniform2i + ',' + location.id + ',' + v0 + ',' + v1,
|
|
1256
|
+
true
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
uniform2iv = function(location, value) {
|
|
1261
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1262
|
+
this._canvas.id,
|
|
1263
|
+
GLmethod.uniform2iv + ',' + location.id + ',' + processArray(value),
|
|
1264
|
+
true
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
uniform3f = function(location, v0, v1, v2) {
|
|
1269
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1270
|
+
this._canvas.id,
|
|
1271
|
+
GLmethod.uniform3f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2,
|
|
1272
|
+
true
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
uniform3fv = function(location, value) {
|
|
1277
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1278
|
+
this._canvas.id,
|
|
1279
|
+
GLmethod.uniform3fv + ',' + location.id + ',' + processArray(value),
|
|
1280
|
+
true
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
uniform3i = function(location, v0, v1, v2) {
|
|
1285
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1286
|
+
this._canvas.id,
|
|
1287
|
+
GLmethod.uniform3i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2,
|
|
1288
|
+
true
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
uniform3iv = function(location, value) {
|
|
1293
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1294
|
+
this._canvas.id,
|
|
1295
|
+
GLmethod.uniform3iv + ',' + location.id + ',' + processArray(value),
|
|
1296
|
+
true
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
uniform4f = function(location, v0, v1, v2, v3) {
|
|
1301
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1302
|
+
this._canvas.id,
|
|
1303
|
+
GLmethod.uniform4f + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3,
|
|
1304
|
+
true
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
uniform4fv = function(location, value) {
|
|
1309
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1310
|
+
this._canvas.id,
|
|
1311
|
+
GLmethod.uniform4fv + ',' + location.id + ',' + processArray(value),
|
|
1312
|
+
true
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
uniform4i = function(location, v0, v1, v2, v3) {
|
|
1317
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1318
|
+
this._canvas.id,
|
|
1319
|
+
GLmethod.uniform4i + ',' + location.id + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3,
|
|
1320
|
+
true
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
uniform4iv = function(location, value) {
|
|
1325
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1326
|
+
this._canvas.id,
|
|
1327
|
+
GLmethod.uniform4iv + ',' + location.id + ',' + processArray(value, true),
|
|
1328
|
+
true
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
uniformMatrix2fv = function(location, transpose, value) {
|
|
1333
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1334
|
+
this._canvas.id,
|
|
1335
|
+
GLmethod.uniformMatrix2fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value),
|
|
1336
|
+
true
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
uniformMatrix3fv = function(location, transpose, value) {
|
|
1341
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1342
|
+
this._canvas.id,
|
|
1343
|
+
GLmethod.uniformMatrix3fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value),
|
|
1344
|
+
true
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
uniformMatrix4fv = function(location, transpose, value) {
|
|
1349
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1350
|
+
this._canvas.id,
|
|
1351
|
+
GLmethod.uniformMatrix4fv + ',' + location.id + ',' + Number(transpose) + ',' + processArray(value),
|
|
1352
|
+
true
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
useProgram = function(progarm) {
|
|
1357
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1358
|
+
this._canvas.id,
|
|
1359
|
+
GLmethod.useProgram + ',' + progarm.id + '',
|
|
1360
|
+
true
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
validateProgram = function(program) {
|
|
1366
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1367
|
+
this._canvas.id,
|
|
1368
|
+
GLmethod.validateProgram + ',' + program.id,
|
|
1369
|
+
true
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
vertexAttrib1f = function(index, v0) {
|
|
1374
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1375
|
+
this._canvas.id,
|
|
1376
|
+
GLmethod.vertexAttrib1f + ',' + index + ',' + v0,
|
|
1377
|
+
true
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
vertexAttrib2f = function(index, v0, v1) {
|
|
1382
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1383
|
+
this._canvas.id,
|
|
1384
|
+
GLmethod.vertexAttrib2f + ',' + index + ',' + v0 + ',' + v1,
|
|
1385
|
+
true
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
vertexAttrib3f = function(index, v0, v1, v2) {
|
|
1390
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1391
|
+
this._canvas.id,
|
|
1392
|
+
GLmethod.vertexAttrib3f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2,
|
|
1393
|
+
true
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
vertexAttrib4f = function(index, v0, v1, v2, v3) {
|
|
1398
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1399
|
+
this._canvas.id,
|
|
1400
|
+
GLmethod.vertexAttrib4f + ',' + index + ',' + v0 + ',' + v1 + ',' + v2 + ',' + v3,
|
|
1401
|
+
true
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
vertexAttrib1fv = function(index, value) {
|
|
1406
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1407
|
+
this._canvas.id,
|
|
1408
|
+
GLmethod.vertexAttrib1fv + ',' + index + ',' + processArray(value),
|
|
1409
|
+
true
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
vertexAttrib2fv = function(index, value) {
|
|
1414
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1415
|
+
this._canvas.id,
|
|
1416
|
+
GLmethod.vertexAttrib2fv + ',' + index + ',' + processArray(value),
|
|
1417
|
+
true
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
vertexAttrib3fv = function(index, value) {
|
|
1422
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1423
|
+
this._canvas.id,
|
|
1424
|
+
GLmethod.vertexAttrib3fv + ',' + index + ',' + processArray(value),
|
|
1425
|
+
true
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
vertexAttrib4fv = function(index, value) {
|
|
1430
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1431
|
+
this._canvas.id,
|
|
1432
|
+
GLmethod.vertexAttrib4fv + ',' + index + ',' + processArray(value),
|
|
1433
|
+
true
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
vertexAttribPointer = function(index, size, type, normalized, stride, offset) {
|
|
1438
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1439
|
+
this._canvas.id,
|
|
1440
|
+
GLmethod.vertexAttribPointer + ',' + index + ',' + size + ',' + type + ',' + Number(normalized) + ',' + stride + ',' + offset,
|
|
1441
|
+
true
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
viewport = function(x, y, width, height) {
|
|
1446
|
+
const cmdArgs = GLmethod.viewport + ',' + x + ',' + y + ',' + width + ',' + height;
|
|
1447
|
+
if (WebGLRenderingContext.GBridge.Platform.OS === 'ios') {
|
|
1448
|
+
// ref to the comment in WebGLRenderingContext.GBridge.callNative()
|
|
1449
|
+
WebGLRenderingContext.GBridge.callViewport(this._canvas.id, cmdArgs);
|
|
1450
|
+
} else {
|
|
1451
|
+
// TODO: need some APP code to test which is better that will not cause low JS FPS if change
|
|
1452
|
+
// viewport() frequently just like comments in getImageData() of `2d/RenderingContext.js`
|
|
1453
|
+
if (this._canvas._disableAutoSwap) {
|
|
1454
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1455
|
+
this._canvas.id,
|
|
1456
|
+
cmdArgs,
|
|
1457
|
+
false,
|
|
1458
|
+
'webgl',
|
|
1459
|
+
'sync',
|
|
1460
|
+
'execWithDisplay',
|
|
1461
|
+
);
|
|
1462
|
+
// TODO: no matter above or below in https://github.com/flyskywhy/snakeRN can keep 30 JS FPS on Huawei Mate 20, maybe need more APP code to test
|
|
1463
|
+
// WebGLRenderingContext.GBridge.callNative(
|
|
1464
|
+
// this._canvas.id,
|
|
1465
|
+
// cmdArgs,
|
|
1466
|
+
// true,
|
|
1467
|
+
// );
|
|
1468
|
+
} else {
|
|
1469
|
+
WebGLRenderingContext.GBridge.callNative(
|
|
1470
|
+
this._canvas.id,
|
|
1471
|
+
cmdArgs,
|
|
1472
|
+
true, // TODO: no matter true or false in https://github.com/flyskywhy/snakeRN can keep 30 JS FPS on Huawei Mate 20, maybe need more APP code to test
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
this._canvas._needRender = true;
|
|
1478
|
+
}
|
|
1479
|
+
}
|