tex-image-webgl.html (2656B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL texImage2D from WebGL conformance test.</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/webgl-test-utils.js"> </script> 15 </head> 16 <body> 17 <canvas id="example" width="256" height="16" style="width: 256px; height: 48px;"></canvas> 18 <canvas id="source" width="256" height="16" style="width: 256px; height: 48px;"></canvas> 19 <div id="description"></div> 20 <div id="console"></div> 21 <script> 22 "use strict"; 23 description("Test texImage2D from a webgl canvas."); 24 var wtu = WebGLTestUtils; 25 var gl = wtu.create3DContext("example"); 26 gl.disable(gl.DITHER); 27 var program = wtu.setupTexturedQuad(gl); 28 var gl1 = wtu.create3DContext("source"); 29 gl1.disable(gl.DITHER); 30 gl1.disable(gl.BLEND); 31 gl1.disable(gl.DEPTH_TEST); 32 33 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 34 wtu.glErrorShouldBe(gl1, gl1.NO_ERROR, "Should be no errors from setup."); 35 36 gl.disable(gl.BLEND); 37 gl.disable(gl.DEPTH_TEST); 38 39 gl1.clearColor(1.0, 0.0, 0.0, 1.0); 40 gl1.clear(gl1.COLOR_BUFFER_BIT); 41 42 var tex = gl.createTexture(); 43 gl.bindTexture(gl.TEXTURE_2D, tex); 44 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, gl1.canvas); 45 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 46 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 47 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 48 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 49 wtu.clearAndDrawUnitQuad(gl); 50 51 wtu.checkCanvas(gl, [255, 0, 0, 255], "Canvas should be red"); 52 53 gl1.clearColor(0.0, 1.0, 0.0, 1.0); 54 gl1.clear(gl1.COLOR_BUFFER_BIT); 55 56 var program1 = wtu.setupTexturedQuad(gl1); 57 var tex1 = gl1.createTexture(); 58 gl1.bindTexture(gl.TEXTURE_2D, tex1); 59 gl1.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 255])); 60 61 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, gl1.canvas); 62 wtu.clearAndDrawUnitQuad(gl); 63 64 wtu.checkCanvas(gl, [0, 255, 0, 255], "Canvas should be green"); 65 66 // Test a scenario from Chrome where a WebGL context would lose its active texture binding when its 67 // canvas was used as the texture source for another WebGL context. 68 wtu.clearAndDrawUnitQuad(gl1); 69 70 wtu.checkCanvas(gl1, [0, 0, 255, 255], "Canvas should be blue"); 71 72 debug(""); 73 var successfullyParsed = true; 74 </script> 75 <script src="../../../js/js-test-post.js"></script> 76 </body> 77 </html>