|
1 <!-- |
|
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
3 |
|
4 Redistribution and use in source and binary forms, with or without |
|
5 modification, are permitted provided that the following conditions are |
|
6 met: |
|
7 |
|
8 * Redistributions of source code must retain the above copyright |
|
9 notice, this list of conditions and the following disclaimer. |
|
10 * Redistributions in binary form must reproduce the above |
|
11 copyright notice, this list of conditions and the following disclaimer |
|
12 in the documentation and/or other materials provided with the |
|
13 distribution. |
|
14 * Neither the name of Google Inc. nor the names of its |
|
15 contributors may be used to endorse or promote products derived from |
|
16 this software without specific prior written permission. |
|
17 |
|
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 --> |
|
30 <!DOCTYPE html> |
|
31 <html> |
|
32 <head> |
|
33 <meta charset="utf-8"> |
|
34 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
|
35 <script src="../../resources/js-test-pre.js"></script> |
|
36 <script src="../resources/webgl-test.js"></script> |
|
37 <script src="../resources/webgl-test-utils.js"></script> |
|
38 <script> |
|
39 var wtu = WebGLTestUtils; |
|
40 var gl = null; |
|
41 var textureLoc = null; |
|
42 var successfullyParsed = false; |
|
43 |
|
44 function init() |
|
45 { |
|
46 if (window.initNonKhronosFramework) { |
|
47 window.initNonKhronosFramework(true); |
|
48 } |
|
49 |
|
50 description('Tests there is no garbage in transparent regions of images uploaded as textures'); |
|
51 |
|
52 wtu = WebGLTestUtils; |
|
53 gl = wtu.create3DContext("example"); |
|
54 var program = wtu.setupTexturedQuad(gl); |
|
55 gl.clearColor(0.5,0.5,0.5,1); |
|
56 gl.clearDepth(1); |
|
57 |
|
58 textureLoc = gl.getUniformLocation(program, "tex"); |
|
59 |
|
60 // The input texture has 8 characters; take the leftmost one |
|
61 var coeff = 1.0 / 8.0; |
|
62 var texCoords = new Float32Array([ |
|
63 coeff, 1.0, |
|
64 0.0, 1.0, |
|
65 0.0, 0.0, |
|
66 coeff, 1.0, |
|
67 0.0, 0.0, |
|
68 coeff, 0.0]); |
|
69 |
|
70 var vbo = gl.createBuffer(); |
|
71 gl.bindBuffer(gl.ARRAY_BUFFER, vbo); |
|
72 gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW); |
|
73 gl.enableVertexAttribArray(1); |
|
74 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); |
|
75 |
|
76 texture = wtu.loadTexture(gl, "../resources/bug-32888-texture.png", runTest); |
|
77 } |
|
78 |
|
79 // These two declarations need to be global for "shouldBe" to see them |
|
80 var buf = null; |
|
81 var idx = 0; |
|
82 |
|
83 function runTest() |
|
84 { |
|
85 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
86 gl.enable(gl.BLEND); |
|
87 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); |
|
88 // Bind the texture to texture unit 0 |
|
89 gl.bindTexture(gl.TEXTURE_2D, texture); |
|
90 // Point the uniform sampler to texture unit 0 |
|
91 gl.uniform1i(textureLoc, 0); |
|
92 // Draw the triangles |
|
93 wtu.drawQuad(gl, [0, 0, 0, 255]); |
|
94 |
|
95 // Spot check a couple of 2x2 regions in the upper and lower left |
|
96 // corners; they should be the rgb values in the texture. |
|
97 color = [0, 0, 0]; |
|
98 debug("Checking lower left corner"); |
|
99 wtu.checkCanvasRect(gl, 1, gl.canvas.height - 3, 2, 2, color, |
|
100 "shouldBe " + color); |
|
101 debug("Checking upper left corner"); |
|
102 wtu.checkCanvasRect(gl, 1, 1, 2, 2, color, |
|
103 "shouldBe " + color); |
|
104 |
|
105 finishTest(); |
|
106 } |
|
107 </script> |
|
108 </head> |
|
109 <body onload="init()"> |
|
110 <canvas id="example" width="32px" height="32px"></canvas> |
|
111 <div id="description"></div> |
|
112 <div id="console"></div> |
|
113 </body> |
|
114 </html> |