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 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
11 <script src="../../resources/js-test-pre.js"></script> | |
12 <script src="../resources/webgl-test.js"></script> | |
13 <script src="../resources/webgl-test-utils.js"></script> | |
14 <script id="fshader" type="x-shader/x-fragment"> | |
15 precision mediump float; | |
16 | |
17 uniform sampler2D tex; | |
18 varying vec2 texCoord; | |
19 | |
20 void main() | |
21 { | |
22 float intensity = texture2D(tex, texCoord).a; | |
23 gl_FragColor = vec4(intensity, intensity, intensity, 1.0); | |
24 } | |
25 </script> | |
26 | |
27 </head> | |
28 <body> | |
29 <canvas id="example" width="256px" height="1px"></canvas> | |
30 <div id="description"></div> | |
31 <div id="console"></div> | |
32 <script> | |
33 description('Tests texSubImage2D upload path from Uint8Array'); | |
34 | |
35 var wtu = WebGLTestUtils; | |
36 var canvas = document.getElementById("example"); | |
37 var gl = wtu.create3DContext(canvas); | |
38 var program = wtu.setupProgram( | |
39 gl, | |
40 [wtu.setupSimpleTextureVertexShader(gl), | |
41 wtu.loadShaderFromScript(gl, "fshader")], | |
42 ['vPosition', 'texCoord0']); | |
43 wtu.setupUnitQuad(gl); | |
44 var textureWidth = 256; | |
45 var textureHeight = 1; | |
46 | |
47 textureLoc = gl.getUniformLocation(program, "tex"); | |
48 | |
49 var texture = gl.createTexture(); | |
50 gl.bindTexture(gl.TEXTURE_2D, texture); | |
51 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
52 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
53 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
54 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
55 // Allocate the texture object | |
56 gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, textureWidth, textureHeight, 0, gl.ALP
HA, gl.UNSIGNED_BYTE, null); | |
57 // Prepare the image data | |
58 var array = new Uint8Array(textureWidth); | |
59 for (var i = 0; i < textureWidth; i++) | |
60 array[i] = i; | |
61 // Fill the texture object with data -- this is actually the code path being tes
ted | |
62 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, gl.ALPHA,
gl.UNSIGNED_BYTE, array); | |
63 | |
64 // Clear and set up | |
65 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
66 gl.bindTexture(gl.TEXTURE_2D, texture); | |
67 gl.useProgram(program); | |
68 gl.uniform1i(textureLoc, 0); | |
69 // Draw the texture to the frame buffer | |
70 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
71 | |
72 // Read back the frame buffer | |
73 var buf = new Uint8Array(textureWidth * textureHeight * 4); | |
74 gl.readPixels(0, 0, textureWidth, textureHeight, gl.RGBA, gl.UNSIGNED_BYTE, buf)
; | |
75 | |
76 // Verify the frame buffer's contents | |
77 var passed = true; | |
78 for (var i = 0; i < textureWidth; i++) { | |
79 var val = i; | |
80 if (buf[4 * i + 0] != val || | |
81 buf[4 * i + 1] != val || | |
82 buf[4 * i + 2] != val) { | |
83 testFailed("pixel at (" + i + ", 0) was (" + | |
84 buf[4 * i + 0] + ", " + | |
85 buf[4 * i + 1] + ", " + | |
86 buf[4 * i + 2] + "), should be (" + | |
87 val + ", " + val + ", " + val + ")"); | |
88 passed = false; | |
89 break; | |
90 } | |
91 } | |
92 | |
93 if (passed) | |
94 testPassed(""); | |
95 | |
96 successfullyParsed = true; | |
97 </script> | |
98 <script src="../../resources/js-test-post.js"></script> | |
99 </body> | |
100 </html> | |
OLD | NEW |