1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/textures/tex-sub-image-2d.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.14 +<script src="../../resources/js-test-pre.js"></script> 1.15 +<script src="../resources/webgl-test.js"></script> 1.16 +<script src="../resources/webgl-test-utils.js"></script> 1.17 +<script id="fshader" type="x-shader/x-fragment"> 1.18 +precision mediump float; 1.19 + 1.20 +uniform sampler2D tex; 1.21 +varying vec2 texCoord; 1.22 + 1.23 +void main() 1.24 +{ 1.25 + float intensity = texture2D(tex, texCoord).a; 1.26 + gl_FragColor = vec4(intensity, intensity, intensity, 1.0); 1.27 +} 1.28 +</script> 1.29 + 1.30 +</head> 1.31 +<body> 1.32 +<canvas id="example" width="256px" height="1px"></canvas> 1.33 +<div id="description"></div> 1.34 +<div id="console"></div> 1.35 +<script> 1.36 +description('Tests texSubImage2D upload path from Uint8Array'); 1.37 + 1.38 +var wtu = WebGLTestUtils; 1.39 +var canvas = document.getElementById("example"); 1.40 +var gl = wtu.create3DContext(canvas); 1.41 +gl.disable(gl.DITHER); 1.42 +var program = wtu.setupProgram( 1.43 + gl, 1.44 + [wtu.setupSimpleTextureVertexShader(gl), "fshader"], 1.45 + ['vPosition', 'texCoord0']); 1.46 +wtu.setupUnitQuad(gl); 1.47 +var textureWidth = 256; 1.48 +var textureHeight = 1; 1.49 + 1.50 +textureLoc = gl.getUniformLocation(program, "tex"); 1.51 + 1.52 +var texture = gl.createTexture(); 1.53 +gl.bindTexture(gl.TEXTURE_2D, texture); 1.54 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1.55 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1.56 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1.57 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1.58 +// Allocate the texture object 1.59 +gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, textureWidth, textureHeight, 0, gl.ALPHA, gl.UNSIGNED_BYTE, null); 1.60 +// Prepare the image data 1.61 +var array = new Uint8Array(textureWidth); 1.62 +for (var i = 0; i < textureWidth; i++) 1.63 + array[i] = i; 1.64 +// Fill the texture object with data -- this is actually the code path being tested 1.65 +gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, gl.ALPHA, gl.UNSIGNED_BYTE, array); 1.66 + 1.67 +// Clear and set up 1.68 +gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 1.69 +gl.bindTexture(gl.TEXTURE_2D, texture); 1.70 +gl.useProgram(program); 1.71 +gl.uniform1i(textureLoc, 0); 1.72 +// Draw the texture to the frame buffer 1.73 +gl.drawArrays(gl.TRIANGLES, 0, 6); 1.74 + 1.75 +// Read back the frame buffer 1.76 +var buf = new Uint8Array(textureWidth * textureHeight * 4); 1.77 +gl.readPixels(0, 0, textureWidth, textureHeight, gl.RGBA, gl.UNSIGNED_BYTE, buf); 1.78 + 1.79 +// Verify the frame buffer's contents 1.80 +var passed = true; 1.81 +for (var i = 0; i < textureWidth; i++) { 1.82 + var val = i; 1.83 + if (buf[4 * i + 0] != val || 1.84 + buf[4 * i + 1] != val || 1.85 + buf[4 * i + 2] != val) { 1.86 + testFailed("pixel at (" + i + ", 0) was (" + 1.87 + buf[4 * i + 0] + ", " + 1.88 + buf[4 * i + 1] + ", " + 1.89 + buf[4 * i + 2] + "), should be (" + 1.90 + val + ", " + val + ", " + val + ")"); 1.91 + passed = false; 1.92 + break; 1.93 + } 1.94 +} 1.95 + 1.96 +if (passed) 1.97 + testPassed(""); 1.98 + 1.99 +successfullyParsed = true; 1.100 +</script> 1.101 +<script>finishTest();</script> 1.102 +</body> 1.103 +</html>