|
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 <title>WebGL texture2D GLSL conformance test.</title> |
|
11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
|
12 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> |
|
13 <script src="../../../resources/js-test-pre.js"></script> |
|
14 <script src="../../resources/webgl-test.js"> </script> |
|
15 <script src="../../resources/webgl-test-utils.js"> </script> |
|
16 </head> |
|
17 <body> |
|
18 <canvas id="example" width="256" height="256" style="width: 16px; height: 16px;"></canvas> |
|
19 <div id="description"></div> |
|
20 <div id="console"></div> |
|
21 <script id="vshader2d" type="x-shader/x-vertex"> |
|
22 attribute vec4 vPosition; |
|
23 attribute vec2 texCoord0; |
|
24 varying vec2 texCoord; |
|
25 void main() { |
|
26 gl_Position = vPosition; |
|
27 texCoord = texCoord0; |
|
28 } |
|
29 </script> |
|
30 <script id="fshader2d" type="x-shader/x-fragment"> |
|
31 precision mediump float; |
|
32 uniform sampler2D tex; |
|
33 uniform float bias; |
|
34 varying vec2 texCoord; |
|
35 void main() { |
|
36 gl_FragData[0] = texture2D(tex, texCoord, bias); |
|
37 } |
|
38 </script> |
|
39 <script> |
|
40 description("tests GLSL texture2D function with bias"); |
|
41 |
|
42 var wtu = WebGLTestUtils; |
|
43 var canvas = document.getElementById("example"); |
|
44 |
|
45 shouldBe("canvas.width", "256"); |
|
46 shouldBe("canvas.height", "256"); |
|
47 |
|
48 var gl = wtu.create3DContext(canvas); |
|
49 var program = wtu.setupProgram( |
|
50 gl, ['vshader2d', 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]); |
|
51 wtu.setupUnitQuad(gl, 0, 1); |
|
52 |
|
53 var colors = [ |
|
54 {name: 'red', color:[255, 0, 0, 255]}, |
|
55 {name: 'green', color:[0, 255, 0, 255]}, |
|
56 {name: 'blue', color:[0, 0, 255, 255]}, |
|
57 {name: 'yellow', color:[255, 255, 0, 255]}, |
|
58 {name: 'magenta', color:[255, 0, 255, 255]}, |
|
59 {name: 'cyan', color:[0, 255, 255, 255]}, |
|
60 {name: 'pink', color:[255, 128, 128, 255]}, |
|
61 {name: 'gray', color:[128, 128, 128, 255]}, |
|
62 {name: 'light green', color:[128, 255, 128, 255]}, |
|
63 ]; |
|
64 |
|
65 shouldBe("colors.length", "9"); |
|
66 |
|
67 var tex = gl.createTexture(); |
|
68 gl.bindTexture(gl.TEXTURE_2D, tex); |
|
69 gl.texParameteri( |
|
70 gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST); |
|
71 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
|
72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
|
73 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
|
74 |
|
75 for (var ii = 0; ii < colors.length; ++ii) { |
|
76 var color = colors[ii]; |
|
77 var size = Math.pow(2, colors.length - ii - 1); |
|
78 wtu.fillTexture(gl, tex, size, size, color.color, ii); |
|
79 } |
|
80 |
|
81 var loc = gl.getUniformLocation(program, "bias"); |
|
82 |
|
83 for (var ii = 0; ii < colors.length; ++ii) { |
|
84 gl.uniform1f(loc, ii); |
|
85 var color = colors[ii]; |
|
86 wtu.drawQuad(gl); |
|
87 wtu.checkCanvas( |
|
88 gl, color.color, |
|
89 "256x256 texture drawn to 256x256 dest with bias = " + ii + |
|
90 " should be " + color.name); |
|
91 } |
|
92 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors."); |
|
93 |
|
94 successfullyParsed = true; |
|
95 |
|
96 </script> |
|
97 <script>finishTest();</script> |
|
98 |
|
99 </body> |
|
100 </html> |
|
101 |
|
102 |