Skip to content

Commit 795a749

Browse files
fix: Some broken unit tests, and move statics to more appropriate location
1 parent f5139a2 commit 795a749

File tree

5 files changed

+71
-69
lines changed

5 files changed

+71
-69
lines changed

src/javascript/extensions/webgl-draw-buffers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class WebGLDrawBuffers {
88
if (exts && exts.indexOf('WEBGL_draw_buffers') >= 0) {
99
Object.assign(this, ctx.extWEBGL_draw_buffers())
1010
this._buffersState = [ctx.BACK]
11-
this._maxDrawBuffers = ctx.getParameter(this.MAX_DRAW_BUFFERS_WEBGL)
11+
this._maxDrawBuffers = ctx._getParameterDirect(this.MAX_DRAW_BUFFERS_WEBGL)
1212
this._ALL_ATTACHMENTS = []
1313
this._ALL_COLOR_ATTACHMENTS = []
1414
const allColorAttachments = [

src/javascript/native-gl.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ const gl = NativeWebGLRenderingContext.prototype
66

77
// from binding.gyp
88
delete gl['1.0.0']
9-
gl.VERSION = 0x1F02
10-
gl.IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A
11-
gl.IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B
129

1310
// from binding.gyp
1411
delete NativeWebGLRenderingContext['1.0.0']

src/javascript/utils.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,35 +153,6 @@ function formatSize (internalFormat) {
153153
return 0
154154
}
155155

156-
function computePixelSize (type, internalFormat) {
157-
const pixelSize = formatSize(internalFormat)
158-
if (pixelSize === 0) {
159-
this.setError(gl.INVALID_ENUM)
160-
return 0
161-
}
162-
switch (type) {
163-
case gl.UNSIGNED_BYTE:
164-
return pixelSize
165-
case gl.UNSIGNED_SHORT_5_6_5:
166-
if (internalFormat !== gl.RGB) {
167-
this.setError(gl.INVALID_OPERATION)
168-
break
169-
}
170-
return 2
171-
case gl.UNSIGNED_SHORT_4_4_4_4:
172-
case gl.UNSIGNED_SHORT_5_5_5_1:
173-
if (internalFormat !== gl.RGBA) {
174-
this.setError(gl.INVALID_OPERATION)
175-
break
176-
}
177-
return 2
178-
case gl.FLOAT:
179-
return 1
180-
}
181-
this.setError(gl.INVALID_ENUM)
182-
return 0
183-
}
184-
185156
function convertPixels (pixels) {
186157
if (typeof pixels === 'object' && pixels !== null) {
187158
if (pixels instanceof ArrayBuffer) {
@@ -228,7 +199,6 @@ module.exports = {
228199
formatSize,
229200
checkFormat,
230201
checkUniform,
231-
computePixelSize,
232202
convertPixels,
233203
validCubeTarget
234204
}

src/javascript/webgl-rendering-context.js

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { getWebGLDrawBuffers } = require('./extensions/webgl-draw-buffers')
1111
const {
1212
checkObject,
1313
checkUniform,
14-
computePixelSize,
14+
formatSize,
1515
isValidString,
1616
typeSize,
1717
uniformTypeSize,
@@ -255,6 +255,35 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
255255
return true
256256
}
257257

258+
_computePixelSize (type, internalFormat) {
259+
const pixelSize = formatSize(internalFormat)
260+
if (pixelSize === 0) {
261+
this.setError(gl.INVALID_ENUM)
262+
return 0
263+
}
264+
switch (type) {
265+
case gl.UNSIGNED_BYTE:
266+
return pixelSize
267+
case gl.UNSIGNED_SHORT_5_6_5:
268+
if (internalFormat !== gl.RGB) {
269+
this.setError(gl.INVALID_OPERATION)
270+
break
271+
}
272+
return 2
273+
case gl.UNSIGNED_SHORT_4_4_4_4:
274+
case gl.UNSIGNED_SHORT_5_5_5_1:
275+
if (internalFormat !== gl.RGBA) {
276+
this.setError(gl.INVALID_OPERATION)
277+
break
278+
}
279+
return 2
280+
case gl.FLOAT:
281+
return 1
282+
}
283+
this.setError(gl.INVALID_ENUM)
284+
return 0
285+
}
286+
258287
_computeRowStride (width, pixelSize) {
259288
let rowStride = width * pixelSize
260289
if (rowStride % this._unpackAlignment) {
@@ -347,11 +376,15 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
347376
}
348377

349378
_getAttachments () {
350-
return this._extensions.webgl_draw_buffers ? this._extensions.webgl_draw_buffers._WEBGL_DRAW_BUFFERS_ATTACHMENTS : DEFAULT_ATTACHMENTS
379+
return this._extensions.webgl_draw_buffers ? this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS : DEFAULT_ATTACHMENTS
351380
}
352381

353382
_getColorAttachments () {
354-
return this._extensions.webgl_draw_buffers ? this._extensions.webgl_draw_buffers._WEBGL_DRAW_BUFFERS_COLOR_ATTACHMENTS : DEFAULT_COLOR_ATTACHMENTS
383+
return this._extensions.webgl_draw_buffers ? this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS : DEFAULT_COLOR_ATTACHMENTS
384+
}
385+
386+
_getParameterDirect (pname) {
387+
return super.getParameter(pname)
355388
}
356389

357390
_getTexImage (target) {
@@ -3052,7 +3085,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
30523085
return
30533086
}
30543087

3055-
const pixelSize = computePixelSize(type, format)
3088+
const pixelSize = this._computePixelSize(type, format)
30563089
if (pixelSize === 0) {
30573090
return
30583091
}
@@ -3169,7 +3202,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
31693202
return
31703203
}
31713204

3172-
const pixelSize = computePixelSize(type, format)
3205+
const pixelSize = this._computePixelSize(type, format)
31733206
if (pixelSize === 0) {
31743207
return
31753208
}
@@ -3440,9 +3473,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34403473
if (!this._checkUniformValueValid(location, value, 'uniform1fv', 1, 'f')) return
34413474
if (location._array) {
34423475
const locs = location._array
3443-
for (let j = 0; j < locs.length && (j + 1) * 1 <= value.length; ++j) {
3444-
const loc = locs[j]
3445-
super.uniform1fv(loc, value[1 * j])
3476+
for (let i = 0; i < locs.length && i < value.length; ++i) {
3477+
const loc = locs[i]
3478+
super.uniform1f(loc, value[i])
34463479
}
34473480
return
34483481
}
@@ -3456,9 +3489,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34563489
if (!this._checkUniformValueValid(location, value, 'uniform1iv', 1, 'i')) return
34573490
if (location._array) {
34583491
const locs = location._array
3459-
for (let j = 0; j < locs.length && (j + 1) * 1 <= value.length; ++j) {
3460-
const loc = locs[j]
3461-
super.uniform1iv(loc, value[1 * j])
3492+
for (let i = 0; i < locs.length && i < value.length; ++i) {
3493+
const loc = locs[i]
3494+
super.uniform1i(loc, value[i])
34623495
}
34633496
return
34643497
}
@@ -3473,9 +3506,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34733506
if (!this._checkUniformValueValid(location, value, 'uniform2fv', 2, 'f')) return
34743507
if (location._array) {
34753508
const locs = location._array
3476-
for (let j = 0; j < locs.length && (j + 2) * 1 <= value.length; ++j) {
3477-
const loc = locs[j]
3478-
super.uniform2fv(loc, value[2 * j])
3509+
for (let i = 0; i < locs.length && 2 * i < value.length; ++i) {
3510+
const loc = locs[i]
3511+
super.uniform2f(loc, value[2 * i], value[(2 * i) + 1])
34793512
}
34803513
return
34813514
}
@@ -3489,9 +3522,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34893522
if (!this._checkUniformValueValid(location, value, 'uniform2iv', 2, 'i')) return
34903523
if (location._array) {
34913524
const locs = location._array
3492-
for (let j = 0; j < locs.length && (j + 2) * 1 <= value.length; ++j) {
3493-
const loc = locs[j]
3494-
super.uniform2iv(loc, value[2 * j])
3525+
for (let i = 0; i < locs.length && 2 * i < value.length; ++i) {
3526+
const loc = locs[i]
3527+
super.uniform2i(loc, value[2 * i], value[2 * i + 1])
34953528
}
34963529
return
34973530
}
@@ -3506,9 +3539,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
35063539
if (!this._checkUniformValueValid(location, value, 'uniform3fv', 3, 'f')) return
35073540
if (location._array) {
35083541
const locs = location._array
3509-
for (let j = 0; j < locs.length && (j + 3) * 1 <= value.length; ++j) {
3510-
const loc = locs[j]
3511-
super.uniform3fv(loc, value[3 * j])
3542+
for (let i = 0; i < locs.length && 3 * i < value.length; ++i) {
3543+
const loc = locs[i]
3544+
super.uniform3f(loc, value[3 * i], value[3 * i + 1], value[3 * i + 2])
35123545
}
35133546
return
35143547
}
@@ -3522,9 +3555,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
35223555
if (!this._checkUniformValueValid(location, value, 'uniform3iv', 3, 'i')) return
35233556
if (location._array) {
35243557
const locs = location._array
3525-
for (let j = 0; j < locs.length && (j + 3) * 1 <= value.length; ++j) {
3526-
const loc = locs[j]
3527-
super.uniform3iv(loc, value[3 * j])
3558+
for (let i = 0; i < locs.length && 3 * i < value.length; ++i) {
3559+
const loc = locs[i]
3560+
super.uniform3i(loc, value[3 * i], value[3 * i + 1], value[3 * i + 2])
35283561
}
35293562
return
35303563
}
@@ -3539,25 +3572,25 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
35393572
if (!this._checkUniformValueValid(location, value, 'uniform4fv', 4, 'f')) return
35403573
if (location._array) {
35413574
const locs = location._array
3542-
for (let j = 0; j < locs.length && (j + 4) * 1 <= value.length; ++j) {
3543-
const loc = locs[j]
3544-
super.uniform4fv(loc, value[4 * j])
3575+
for (let i = 0; i < locs.length && 4 * i < value.length; ++i) {
3576+
const loc = locs[i]
3577+
super.uniform4f(loc, value[4 * i], value[4 * i + 1], value[4 * i + 2], value[4 * i + 3])
35453578
}
35463579
return
35473580
}
35483581
super.uniform4f(location._ | 0, value[0], value[1], value[2], value[3])
35493582
}
35503583
uniform4i (location, v0, v1, v2, v3) {
35513584
if (!this._checkUniformValid(location, v0, 'uniform4i', 4, 'i')) return
3552-
super.uniform3i(location._ | 0, v0, v1, v2, v3)
3585+
super.uniform4i(location._ | 0, v0, v1, v2, v3)
35533586
}
35543587
uniform4iv (location, value) {
35553588
if (!this._checkUniformValueValid(location, value, 'uniform4iv', 4, 'i')) return
35563589
if (location._array) {
35573590
const locs = location._array
3558-
for (let j = 0; j < locs.length && (j + 4) * 1 <= value.length; ++j) {
3559-
const loc = locs[j]
3560-
super.uniform4iv(loc, value[4 * j])
3591+
for (let i = 0; i < locs.length && 4 * i < value.length; ++i) {
3592+
const loc = locs[i]
3593+
super.uniform4i(loc, value[4 * i], value[4 * i + 1], value[4 * i + 2], value[4 * i + 3])
35613594
}
35623595
return
35633596
}
@@ -3657,7 +3690,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36573690
}
36583691

36593692
vertexAttrib1fv (index, value) {
3660-
if (typeof value !== 'object' || value === null || value.length !== 1) {
3693+
if (typeof value !== 'object' || value === null || value.length < 1) {
36613694
this.setError(gl.INVALID_OPERATION)
36623695
return
36633696
}
@@ -3669,7 +3702,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36693702
return super.vertexAttrib1f(index | 0, +value[0])
36703703
}
36713704
vertexAttrib2fv (index, value) {
3672-
if (typeof value !== 'object' || value === null || value.length !== 2) {
3705+
if (typeof value !== 'object' || value === null || value.length < 2) {
36733706
this.setError(gl.INVALID_OPERATION)
36743707
return
36753708
}
@@ -3681,7 +3714,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36813714
return super.vertexAttrib2f(index | 0, +value[0], +value[1])
36823715
}
36833716
vertexAttrib3fv (index, value) {
3684-
if (typeof value !== 'object' || value === null || value.length !== 3) {
3717+
if (typeof value !== 'object' || value === null || value.length < 3) {
36853718
this.setError(gl.INVALID_OPERATION)
36863719
return
36873720
}
@@ -3693,7 +3726,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36933726
return super.vertexAttrib3f(index | 0, +value[0], +value[1], +value[2])
36943727
}
36953728
vertexAttrib4fv (index, value) {
3696-
if (typeof value !== 'object' || value === null || value.length !== 4) {
3729+
if (typeof value !== 'object' || value === null || value.length < 4) {
36973730
this.setError(gl.INVALID_OPERATION)
36983731
return
36993732
}

src/native/bindings.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ NAN_MODULE_INIT(Init) {
349349
JS_GL_CONSTANT(DECR_WRAP);
350350
JS_GL_CONSTANT(VENDOR);
351351
JS_GL_CONSTANT(RENDERER);
352-
JS_GL_CONSTANT(VERSION);
353352
JS_GL_CONSTANT(NEAREST);
354353
JS_GL_CONSTANT(LINEAR);
355354
JS_GL_CONSTANT(NEAREST_MIPMAP_NEAREST);
@@ -473,6 +472,9 @@ NAN_MODULE_INIT(Init) {
473472
JS_CONSTANT(CONTEXT_LOST_WEBGL, 0x9242);
474473
JS_CONSTANT(UNPACK_COLORSPACE_CONVERSION_WEBGL, 0x9243);
475474
JS_CONSTANT(BROWSER_DEFAULT_WEBGL, 0x9244);
475+
JS_CONSTANT(VERSION, 0x1F02);
476+
JS_CONSTANT(IMPLEMENTATION_COLOR_READ_TYPE, 0x8B9A);
477+
JS_CONSTANT(IMPLEMENTATION_COLOR_READ_FORMAT, 0x8B9B);
476478

477479
//Export template
478480
WEBGL_TEMPLATE.Reset(webgl_template);

0 commit comments

Comments
 (0)