| OLD | NEW |
| 1 function checkCanvasRect(buf, x, y, width, height, color, tolerance, bufWidth, r
etVal) | 1 function checkCanvasRect(buf, x, y, width, height, color, tolerance, bufWidth, r
etVal) |
| 2 { | 2 { |
| 3 for (var px = x; px < x + width; px++) { | 3 for (var px = x; px < x + width; px++) { |
| 4 for (var py = y; py < y + height; py++) { | 4 for (var py = y; py < y + height; py++) { |
| 5 var offset = (py * bufWidth + px) * 4; | 5 var offset = (py * bufWidth + px) * 4; |
| 6 for (var j = 0; j < color.length; j++) { | 6 for (var j = 0; j < color.length; j++) { |
| 7 if (Math.abs(buf[offset + j] - color[j]) > tolerance) { | 7 if (Math.abs(buf[offset + j] - color[j]) > tolerance) { |
| 8 retVal.testPassed = false; | 8 retVal.testPassed = false; |
| 9 return; | 9 return; |
| 10 } | 10 } |
| 11 } | 11 } |
| 12 } | 12 } |
| 13 } | 13 } |
| 14 } | 14 } |
| 15 | 15 |
| 16 function runOneIteration(useTexSubImage2D, bindingTarget, program, bitmap, flipY
, premultiplyAlpha, retVal) | 16 function runOneIteration(useTexSubImage2D, bindingTarget, program, bitmap, flipY
, premultiplyAlpha, retVal, colorspace = 'empty') |
| 17 { | 17 { |
| 18 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | 18 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 19 // Enable writes to the RGBA channels | 19 // Enable writes to the RGBA channels |
| 20 gl.colorMask(1, 1, 1, 0); | 20 gl.colorMask(1, 1, 1, 0); |
| 21 var texture = gl.createTexture(); | 21 var texture = gl.createTexture(); |
| 22 // Bind the texture to texture unit 0 | 22 // Bind the texture to texture unit 0 |
| 23 gl.bindTexture(bindingTarget, texture); | 23 gl.bindTexture(bindingTarget, texture); |
| 24 // Set up texture parameters | 24 // Set up texture parameters |
| 25 gl.texParameteri(bindingTarget, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | 25 gl.texParameteri(bindingTarget, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 26 gl.texParameteri(bindingTarget, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | 26 gl.texParameteri(bindingTarget, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 54 var quaterHeight = Math.floor(halfHeight / 2); | 54 var quaterHeight = Math.floor(halfHeight / 2); |
| 55 | 55 |
| 56 var top = flipY ? quaterHeight : (height - halfHeight + quaterHeight); | 56 var top = flipY ? quaterHeight : (height - halfHeight + quaterHeight); |
| 57 var bottom = flipY ? (height - halfHeight + quaterHeight) : quaterHeight; | 57 var bottom = flipY ? (height - halfHeight + quaterHeight) : quaterHeight; |
| 58 | 58 |
| 59 var tl = redColor; | 59 var tl = redColor; |
| 60 var tr = premultiplyAlpha ? ((retVal.alpha == 0.5) ? halfRed : (retVal.alpha
== 1) ? redColor : blackColor) : redColor; | 60 var tr = premultiplyAlpha ? ((retVal.alpha == 0.5) ? halfRed : (retVal.alpha
== 1) ? redColor : blackColor) : redColor; |
| 61 var bl = greenColor; | 61 var bl = greenColor; |
| 62 var br = premultiplyAlpha ? ((retVal.alpha == 0.5) ? halfGreen : (retVal.alp
ha == 1) ? greenColor : blackColor) : greenColor; | 62 var br = premultiplyAlpha ? ((retVal.alpha == 0.5) ? halfGreen : (retVal.alp
ha == 1) ? greenColor : blackColor) : greenColor; |
| 63 | 63 |
| 64 var blueColor = [0, 0, 255]; |
| 65 if (colorspace == 'none') { |
| 66 tl = tr = bl = br = blueColor; |
| 67 } else if (colorspace == 'default' || colorspace == 'notprovided') { |
| 68 tl = tr = bl = br = redColor; |
| 69 } |
| 70 |
| 64 var loc; | 71 var loc; |
| 65 if (bindingTarget == gl.TEXTURE_CUBE_MAP) { | 72 if (bindingTarget == gl.TEXTURE_CUBE_MAP) { |
| 66 loc = gl.getUniformLocation(program, "face"); | 73 loc = gl.getUniformLocation(program, "face"); |
| 67 } | 74 } |
| 68 | 75 |
| 69 var tolerance = (retVal.alpha == 0) ? 0 : 3; | 76 var tolerance = (retVal.alpha == 0) ? 0 : 3; |
| 77 if (colorspace == 'default' || colorspace == 'none' || colorspace == 'notpro
vided') |
| 78 tolerance = 13; // For linux and win, the tolerance can be 8. |
| 70 for (var tt = 0; tt < targets.length; ++tt) { | 79 for (var tt = 0; tt < targets.length; ++tt) { |
| 71 if (bindingTarget == gl.TEXTURE_CUBE_MAP) { | 80 if (bindingTarget == gl.TEXTURE_CUBE_MAP) { |
| 72 gl.uniform1i(loc, targets[tt]); | 81 gl.uniform1i(loc, targets[tt]); |
| 73 } | 82 } |
| 74 // Draw the triangles | 83 // Draw the triangles |
| 75 gl.clearColor(0, 0, 0, 1); | 84 gl.clearColor(0, 0, 0, 1); |
| 76 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | 85 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 77 gl.drawArrays(gl.TRIANGLES, 0, 6); | 86 gl.drawArrays(gl.TRIANGLES, 0, 6); |
| 78 | 87 |
| 79 // Check the top pixel and bottom pixel and make sure they have | 88 // Check the top pixel and bottom pixel and make sure they have |
| 80 // the right color. | 89 // the right color. |
| 81 var buf = new Uint8Array(width * height * 4); | 90 var buf = new Uint8Array(width * height * 4); |
| 82 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf); | 91 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 83 checkCanvasRect(buf, quaterWidth, bottom, 2, 2, tl, tolerance, width, re
tVal); | 92 checkCanvasRect(buf, quaterWidth, bottom, 2, 2, tl, tolerance, width, re
tVal); |
| 84 checkCanvasRect(buf, halfWidth + quaterWidth, bottom, 2, 2, tr, toleranc
e, width, retVal); | 93 checkCanvasRect(buf, halfWidth + quaterWidth, bottom, 2, 2, tr, toleranc
e, width, retVal); |
| 85 checkCanvasRect(buf, quaterWidth, top, 2, 2, bl, tolerance, width, retVa
l); | 94 checkCanvasRect(buf, quaterWidth, top, 2, 2, bl, tolerance, width, retVa
l); |
| 86 checkCanvasRect(buf, halfWidth + quaterWidth, top, 2, 2, br, tolerance,
width, retVal); | 95 checkCanvasRect(buf, halfWidth + quaterWidth, top, 2, 2, br, tolerance,
width, retVal); |
| 87 } | 96 } |
| 88 } | 97 } |
| 89 | 98 |
| 90 function runTestOnBindingTarget(bindingTarget, program, bitmaps, retVal) { | 99 function runTestOnBindingTarget(bindingTarget, program, bitmaps, retVal) { |
| 91 var cases = [ | 100 var cases = [ |
| 92 { sub: false }, | 101 { sub: false, bitmap: bitmaps.defaultOption, flipY: false, premultiply:
true, colorspace: 'empty' }, |
| 93 { sub: true }, | 102 { sub: true, bitmap: bitmaps.defaultOption, flipY: false, premultiply: t
rue, colorspace: 'empty' }, |
| 103 { sub: false, bitmap: bitmaps.noFlipYPremul, flipY: false, premultiply:
true, colorspace: 'empty' }, |
| 104 { sub: true, bitmap: bitmaps.noFlipYPremul, flipY: false, premultiply: t
rue, colorspace: 'empty' }, |
| 105 { sub: false, bitmap: bitmaps.noFlipYDefault, flipY: false, premultiply:
true, colorspace: 'empty' }, |
| 106 { sub: true, bitmap: bitmaps.noFlipYDefault, flipY: false, premultiply:
true, colorspace: 'empty' }, |
| 107 { sub: false, bitmap: bitmaps.noFlipYUnpremul, flipY: false, premultiply
: false, colorspace: 'empty' }, |
| 108 { sub: true, bitmap: bitmaps.noFlipYUnpremul, flipY: false, premultiply:
false, colorspace: 'empty' }, |
| 109 { sub: false, bitmap: bitmaps.flipYPremul, flipY: true, premultiply: tru
e, colorspace: 'empty' }, |
| 110 { sub: true, bitmap: bitmaps.flipYPremul, flipY: true, premultiply: true
, colorspace: 'empty' }, |
| 111 { sub: false, bitmap: bitmaps.flipYDefault, flipY: true, premultiply: tr
ue, colorspace: 'empty' }, |
| 112 { sub: true, bitmap: bitmaps.flipYDefault, flipY: true, premultiply: tru
e, colorspace: 'empty' }, |
| 113 { sub: false, bitmap: bitmaps.flipYUnpremul, flipY: true, premultiply: f
alse, colorspace: 'empty' }, |
| 114 { sub: true, bitmap: bitmaps.flipYUnpremul, flipY: true, premultiply: fa
lse, colorspace: 'empty' }, |
| 115 { sub: false, bitmap: bitmaps.colorspaceDef, flipY: false, premultiply:
true, colorspace: retVal.colorspaceEffect ? 'notprovided' : 'empty' }, |
| 116 { sub: true, bitmap: bitmaps.colorspaceDef, flipY: false, premultiply: t
rue, colorspace: retVal.colorspaceEffect ? 'notprovided' : 'empty' }, |
| 117 { sub: false, bitmap: bitmaps.colorspaceNone, flipY: false, premultiply:
true, colorspace: retVal.colorspaceEffect ? 'none' : 'empty' }, |
| 118 { sub: true, bitmap: bitmaps.colorspaceNone, flipY: false, premultiply:
true, colorspace: retVal.colorspaceEffect ? 'none' : 'empty' }, |
| 119 { sub: false, bitmap: bitmaps.colorspaceDefault, flipY: false, premultip
ly: true, colorspace: retVal.colorspaceEffect ? 'default' : 'empty' }, |
| 120 { sub: true, bitmap: bitmaps.colorspaceDefault, flipY: false, premultipl
y: true, colorspace: retVal.colorspaceEffect ? 'default' : 'empty' }, |
| 94 ]; | 121 ]; |
| 95 | 122 |
| 96 for (var i in cases) { | 123 for (var i in cases) { |
| 97 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.defaultOpt
ion, false, true, retVal); | 124 runOneIteration(cases[i].sub, bindingTarget, program, cases[i].bitmap, c
ases[i].flipY, |
| 98 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.noFlipYPre
mul, false, true, retVal); | 125 cases[i].premultiply, retVal, cases[i].colorspace); |
| 99 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.noFlipYDef
ault, false, true, retVal); | |
| 100 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.noFlipYUnp
remul, false, false, retVal); | |
| 101 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.flipYPremu
l, true, true, retVal); | |
| 102 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.flipYDefau
lt, true, true, retVal); | |
| 103 runOneIteration(cases[i].sub, bindingTarget, program, bitmaps.flipYUnpre
mul, true, false, retVal); | |
| 104 } | 126 } |
| 105 } | 127 } |
| 106 | 128 |
| 107 function runTest(bitmaps, alphaVal) | 129 function runTest(bitmaps, alphaVal, colorspaceEffective) |
| 108 { | 130 { |
| 109 var retVal = {testPassed: true, alpha: alphaVal}; | 131 var retVal = {testPassed: true, alpha: alphaVal, colorspaceEffect: colorspac
eEffective}; |
| 110 var program = tiu.setupTexturedQuad(gl, internalFormat); | 132 var program = tiu.setupTexturedQuad(gl, internalFormat); |
| 111 runTestOnBindingTarget(gl.TEXTURE_2D, program, bitmaps, retVal); | 133 runTestOnBindingTarget(gl.TEXTURE_2D, program, bitmaps, retVal); |
| 112 // program = tiu.setupTexturedQuadWithCubeMap(gl, internalFormat); | 134 program = tiu.setupTexturedQuadWithCubeMap(gl, internalFormat); |
| 113 // runTestOnBindingTarget(gl.TEXTURE_CUBE_MAP, program, bitmaps, retVal); | 135 runTestOnBindingTarget(gl.TEXTURE_CUBE_MAP, program, bitmaps, retVal); |
| 114 return retVal.testPassed; | 136 return retVal.testPassed; |
| 115 } | 137 } |
| OLD | NEW |