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 <title>WebGL texture mips conformance test.</title> | |
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
12 <script src="../../resources/js-test-pre.js"></script> | |
13 <script src="../resources/webgl-test.js"> </script> | |
14 <script src="../resources/webgl-test-utils.js"></script> | |
15 </head> | |
16 <body> | |
17 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></c
anvas> | |
18 <div id="description"></div> | |
19 <div id="console"></div> | |
20 <script id="vshader" type="x-shader/x-vertex"> | |
21 uniform vec4 uOffset; | |
22 uniform vec4 uMult; | |
23 attribute vec4 vPosition; | |
24 attribute vec2 texCoord0; | |
25 varying vec2 texCoord; | |
26 void main() | |
27 { | |
28 gl_Position = vPosition * uMult + uOffset; | |
29 texCoord = texCoord0; | |
30 } | |
31 </script> | |
32 | |
33 <script id="fshader" type="x-shader/x-fragment"> | |
34 precision mediump float; | |
35 uniform sampler2D tex; | |
36 varying vec2 texCoord; | |
37 void main() | |
38 { | |
39 gl_FragColor = texture2D(tex, texCoord); | |
40 } | |
41 </script> | |
42 <script> | |
43 var canvas; | |
44 function init() | |
45 { | |
46 if (window.initNonKhronosFramework) { | |
47 window.initNonKhronosFramework(false); | |
48 } | |
49 | |
50 debug("Checks mip issues"); | |
51 debug(""); | |
52 | |
53 var wtu = WebGLTestUtils; | |
54 canvas = document.getElementById("example"); | |
55 shouldBe("canvas.width", "2"); | |
56 shouldBe("canvas.height", "2"); | |
57 | |
58 gl = wtu.create3DContext(canvas); | |
59 wtu.setupUnitQuad(gl, 0, 1); | |
60 var program = wtu.setupProgram( | |
61 gl, | |
62 [wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER), | |
63 wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER)], | |
64 ['vPosition', 'texCoord0'], [0, 1]); | |
65 | |
66 gl.disable(gl.DEPTH_TEST); | |
67 gl.disable(gl.BLEND); | |
68 | |
69 var blue = [0, 0, 255, 255]; | |
70 var red = [255, 0, 0, 255]; | |
71 var green = [0, 255, 0, 255]; | |
72 var lightGreen = [128, 255, 192, 255]; | |
73 var black = [0, 0, 0, 255]; | |
74 | |
75 var tex = gl.createTexture(); | |
76 gl.bindTexture(gl.TEXTURE_2D, tex); | |
77 // 16x16 texture no mips | |
78 fillLevel(0, 16, lightGreen); | |
79 debug("mips: lightGreen(16x16), undef, undef, undef, undef"); | |
80 | |
81 var texLoc = gl.getUniformLocation(program, "tex"); | |
82 gl.uniform1i(texLoc, 0); | |
83 var offLoc = gl.getUniformLocation(program, "uOffset"); | |
84 var multLoc = gl.getUniformLocation(program, "uMult"); | |
85 | |
86 gl.uniform4f(offLoc, 0, 0, 0, 0); | |
87 gl.uniform4f(multLoc, 1, 1, 1, 1); | |
88 | |
89 wtu.drawQuad(gl); | |
90 wtu.checkCanvas(gl, black, | |
91 "texture that is missing mips when " + | |
92 "TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with black"); | |
93 | |
94 gl.generateMipmap(gl.TEXTURE_2D); | |
95 debug("mips: lightGreen(16x16), lightGreen(8x8), lightGreen(4x4), lightGreen(2
x2), lightGreen(1x1)"); | |
96 | |
97 wtu.drawQuad(gl); | |
98 wtu.checkCanvas(gl, lightGreen, | |
99 "texture that has all mips when should draw with light green"); | |
100 | |
101 // Fill in the bottom 2 mips with a different color. | |
102 fillLevel(4, 1, green); | |
103 fillLevel(3, 2, green); | |
104 debug("mips: lightGreen(16x16), lightGreen(8x8), lightGreen(4x4), green(2x2),
green(1x1)"); | |
105 | |
106 // Choose the nearest mip | |
107 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEARES
T); | |
108 | |
109 wtu.drawQuad(gl); | |
110 wtu.checkCanvas(gl, green, | |
111 "texture that is only using the smallest 2 mips should draw with green"); | |
112 | |
113 gl.uniform4f(multLoc, 16, 16, 1, 1); | |
114 | |
115 wtu.drawQuad(gl); | |
116 wtu.checkCanvas(gl, lightGreen, | |
117 "texture that is using only the largest 2 mips should draw with light gree
n"); | |
118 | |
119 // Set the top level | |
120 fillLevel(0, 1, red); | |
121 debug("mips: red(1x1), lightGreen(8x8-unused), lightGreen(4x4-unused), lightGr
een(2x2-unused), lightGreen(1x1-unused)"); | |
122 wtu.drawQuad(gl); | |
123 wtu.checkCanvas(gl, red, | |
124 "texture that is only using the top level even though other levels are def
ined " + | |
125 "should draw with red"); | |
126 | |
127 // Set the top 2 levels using generateMipmap | |
128 fillLevel(0, 2, blue); | |
129 debug("mips: blue(2x2), lightGreen(8x8-unused), lightGreen(4x4-unused), lightG
reen(2x2-unused), lightGreen(1x1-unused)"); | |
130 gl.generateMipmap(gl.TEXTURE_2D); | |
131 debug("mips: blue(2x2), blue(1x1), lightGreen(4x4-unused), lightGreen(2x2-unus
ed), lightGreen(1x1-unused)"); | |
132 | |
133 wtu.drawQuad(gl); | |
134 wtu.checkCanvas(gl, blue, | |
135 "texture that is only using the top 2 levels even though other levels are
defined " + | |
136 "should draw with blue"); | |
137 | |
138 | |
139 // Set the top 2 levels back to sizes that end up using levels 2, 3, and 4 aga
in. | |
140 fillLevel(0, 16, blue); | |
141 debug("mips: blue(16x16), blue(1x1), lightGreen(4x4-unused), lightGreen(2x2-un
used), lightGreen(1x1-unused)"); | |
142 fillLevel(1, 8, blue); | |
143 debug("mips: blue(16x16), blue(8x8), lightGreen(4x4), lightGreen(2x2), lightGr
een(1x1)"); | |
144 wtu.drawQuad(gl); | |
145 wtu.checkCanvas(gl, blue, | |
146 "texture that is only using the largest 2 mips should draw with blue"); | |
147 gl.uniform4f(multLoc, 1, 1, 1, 1); | |
148 wtu.drawQuad(gl); | |
149 wtu.checkCanvas(gl, green, | |
150 "texture that is only using the smalles 2 mips should draw with green"); | |
151 | |
152 | |
153 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors."); | |
154 } | |
155 | |
156 function fillLevel(level, size, color) { | |
157 var numPixels = size * size; | |
158 var pixels = new Uint8Array(numPixels * 4); | |
159 for (var jj = 0; jj < numPixels; ++jj) { | |
160 var off = jj * 4; | |
161 pixels[off + 0] = color[0]; | |
162 pixels[off + 1] = color[1]; | |
163 pixels[off + 2] = color[2]; | |
164 pixels[off + 3] = color[3]; | |
165 } | |
166 gl.texImage2D( | |
167 gl.TEXTURE_2D, level, gl.RGBA, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, | |
168 pixels); | |
169 } | |
170 | |
171 init(); | |
172 successfullyParsed = true; | |
173 </script> | |
174 | |
175 <script src="../../resources/js-test-post.js"></script> | |
176 | |
177 </body> | |
178 </html> | |
179 | |
OLD | NEW |