| <!-- |
| /* |
| ** Copyright (c) 2012 The Khronos Group Inc. |
| ** |
| ** Permission is hereby granted, free of charge, to any person obtaining a |
| ** copy of this software and/or associated documentation files (the |
| ** "Materials"), to deal in the Materials without restriction, including |
| ** without limitation the rights to use, copy, modify, merge, publish, |
| ** distribute, sublicense, and/or sell copies of the Materials, and to |
| ** permit persons to whom the Materials are furnished to do so, subject to |
| ** the following conditions: |
| ** |
| ** The above copyright notice and this permission notice shall be included |
| ** in all copies or substantial portions of the Materials. |
| ** |
| ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| */ |
| --> |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| <script src="../../resources/js-test-pre.js"></script> |
| <script src="../resources/webgl-test.js"></script> |
| <script src="../resources/webgl-test-utils.js"></script> |
| <script> |
| "use strict"; |
| var wtu = WebGLTestUtils; |
| var gl = null; |
| var texture; |
| var textureLoc = null; |
| var successfullyParsed = false; |
| |
| function init() |
| { |
| initTestingHarnessWaitUntilDone(); |
| |
| description('Tests there is no garbage in transparent regions of images uploaded as textures'); |
| |
| wtu = WebGLTestUtils; |
| gl = wtu.create3DContext("example"); |
| var program = wtu.setupTexturedQuad(gl); |
| gl.clearColor(0.5,0.5,0.5,1); |
| gl.clearDepth(1); |
| |
| textureLoc = gl.getUniformLocation(program, "tex"); |
| |
| // The input texture has 8 characters; take the leftmost one |
| var coeff = 1.0 / 8.0; |
| var texCoords = new Float32Array([ |
| coeff, 1.0, |
| 0.0, 1.0, |
| 0.0, 0.0, |
| coeff, 1.0, |
| 0.0, 0.0, |
| coeff, 0.0]); |
| |
| var vbo = gl.createBuffer(); |
| gl.bindBuffer(gl.ARRAY_BUFFER, vbo); |
| gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW); |
| gl.enableVertexAttribArray(1); |
| gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); |
| |
| texture = wtu.loadTexture(gl, "../resources/bug-32888-texture.png", runTest); |
| } |
| |
| // These two declarations need to be global for "shouldBe" to see them |
| var buf = null; |
| var idx = 0; |
| |
| function runTest() |
| { |
| gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| gl.enable(gl.BLEND); |
| gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); |
| // Bind the texture to texture unit 0 |
| gl.bindTexture(gl.TEXTURE_2D, texture); |
| // Point the uniform sampler to texture unit 0 |
| gl.uniform1i(textureLoc, 0); |
| // Draw the triangles |
| wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]); |
| |
| // Spot check a couple of 2x2 regions in the upper and lower left |
| // corners; they should be the rgb values in the texture. |
| var color = [0, 0, 0]; |
| debug("Checking lower left corner"); |
| wtu.checkCanvasRect(gl, 1, gl.canvas.height - 3, 2, 2, color, |
| "shouldBe " + color); |
| debug("Checking upper left corner"); |
| wtu.checkCanvasRect(gl, 1, 1, 2, 2, color, |
| "shouldBe " + color); |
| |
| finishTest(); |
| } |
| </script> |
| </head> |
| <body onload="init()"> |
| <canvas id="example" width="32" height="32"></canvas> |
| <div id="description"></div> |
| <div id="console"></div> |
| </body> |
| </html> |