| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 Use of this source code is governed by a BSD-style license that can be | |
| 4 found in the LICENSE file. | |
| 5 --> | |
| 6 <!DOCTYPE html> | |
| 7 <html> | |
| 8 <head> | |
| 9 <meta charset="utf-8"> | |
| 10 <title>Test the WebGL premultipledAlpha context creation flag.</title> | |
| 11 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
| 12 <script src="../resources/js-test-pre.js"></script> | |
| 13 <script src="resources/webgl-test.js"> </script> | |
| 14 <script src="resources/webgl-test-utils.js"> </script> | |
| 15 </head> | |
| 16 <body> | |
| 17 <div id="description"></div><div id="console"></div> | |
| 18 <script> | |
| 19 var wtu = WebGLTestUtils; | |
| 20 | |
| 21 var tests = [ | |
| 22 // If premultipledAlpha is true then | |
| 23 // [texture] [canvas] [dataURL] | |
| 24 // 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128 | |
| 25 { creationAttributes: {}, | |
| 26 sentColor: [32, 64, 128, 128], | |
| 27 expectedColor: [64, 128, 255, 128], | |
| 28 errorRange: 2, | |
| 29 useToDataURL: true, | |
| 30 }, | |
| 31 // If premultipledAlpha is true then | |
| 32 // [texture] [canvas] [texture] | |
| 33 // 32, 64, 128, 128 -> 64, 128, 255, 128 -> 64, 128, 255, 128 | |
| 34 { creationAttributes: {}, | |
| 35 sentColor: [32, 64, 128, 128], | |
| 36 expectedColor: [64, 128, 255, 128], | |
| 37 errorRange: 2, | |
| 38 useToDataURL: false, | |
| 39 }, | |
| 40 // If premultipledAlpha is false then | |
| 41 // [texture] [canvas] [dataURL] | |
| 42 // 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1 | |
| 43 { creationAttributes: {premultipliedAlpha: false}, | |
| 44 sentColor: [255, 192, 128, 1], | |
| 45 expectedColor: [255, 192, 128, 1], | |
| 46 errorRange: 0, | |
| 47 useToDataURL: true, | |
| 48 }, | |
| 49 // If premultipledAlpha is false then | |
| 50 // [texture] [canvas] [texture] | |
| 51 // 255, 192, 128, 1 -> 255, 192, 128, 1 -> 255, 192, 128, 1 | |
| 52 { creationAttributes: {premultipliedAlpha: false}, | |
| 53 sentColor: [255, 192, 128, 1], | |
| 54 expectedColor: [255, 192, 128, 1], | |
| 55 errorRange: 0, | |
| 56 useToDataURL: false, | |
| 57 } | |
| 58 ]; | |
| 59 | |
| 60 var g_count = 0; | |
| 61 var gl; | |
| 62 var canvas; | |
| 63 var premultipledAlpha; | |
| 64 | |
| 65 description("Test the WebGL premultipledAlpha context creation flag."); | |
| 66 doNextTest(); | |
| 67 function doNextTest() { | |
| 68 if (g_count < tests.length) { | |
| 69 var test = tests[g_count++]; | |
| 70 canvas = document.createElement("canvas"); | |
| 71 gl = wtu.create3DContext(canvas, test.creationAttributes); | |
| 72 var premultipliedAlpha = test.creationAttributes.premultipliedAlpha != fals
e; | |
| 73 debug("") | |
| 74 debug("testing: premultipliedAlpha: " + premultipliedAlpha + " toDataURL: "
+ test.useToDataURL); | |
| 75 | |
| 76 shouldBe('gl.getContextAttributes().premultipledAlpha', 'premultipledAlpha'
); | |
| 77 | |
| 78 console.log(gl.getContextAttributes()); | |
| 79 var program = wtu.setupTexturedQuad(gl); | |
| 80 | |
| 81 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); | |
| 82 var tex = gl.createTexture(); | |
| 83 wtu.fillTexture(gl, tex, 2, 2, test.sentColor, 0); | |
| 84 var loc = gl.getUniformLocation(program, "tex"); | |
| 85 gl.uniform1i(loc, 0); | |
| 86 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); | |
| 87 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); | |
| 88 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
| 89 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
| 90 | |
| 91 wtu.drawQuad(gl); | |
| 92 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from drawing."); | |
| 93 | |
| 94 function loadTexture() { | |
| 95 var pngTex = gl.createTexture(); | |
| 96 // not needed as it's the default | |
| 97 // gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | |
| 98 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, false); | |
| 99 gl.bindTexture(gl.TEXTURE_2D, pngTex); | |
| 100 if (test.useToDataURL) { | |
| 101 // create texture from image | |
| 102 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, th
is); | |
| 103 } else { | |
| 104 // create texture from canvas | |
| 105 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, ca
nvas); | |
| 106 } | |
| 107 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); | |
| 108 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); | |
| 109 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
| 110 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
| 111 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from creating copy.
"); | |
| 112 wtu.drawQuad(gl); | |
| 113 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from 2nd drawing.")
; | |
| 114 wtu.checkCanvas( | |
| 115 gl, test.expectedColor, | |
| 116 "should draw with " + test.expectedColor, test.errorRange); | |
| 117 | |
| 118 doNextTest(); | |
| 119 } | |
| 120 | |
| 121 if (test.useToDataURL) { | |
| 122 // Load canvas into string using toDataURL | |
| 123 var png = canvas.toDataURL(); | |
| 124 // Load string into the texture | |
| 125 var input = document.createElement("img"); | |
| 126 input.onload = loadTexture; | |
| 127 input.src = png; | |
| 128 } else { | |
| 129 // Load canvas into the texture asynchronously (to prevent unbounded sta
ck consumption) | |
| 130 setTimeout(loadTexture, 0); | |
| 131 } | |
| 132 } else { | |
| 133 successfullyParsed = true; | |
| 134 finishTest(); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 </script> | |
| 139 | |
| 140 </body> | |
| 141 </html> | |
| 142 | |
| 143 | |
| OLD | NEW |