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 id="vshader" type="x-shader/x-vertex"> |
| 14 attribute vec3 pos; |
| 15 attribute vec4 colorIn; |
| 16 uniform float pointSize; |
| 17 varying vec4 color; |
| 18 |
| 19 void main() |
| 20 { |
| 21 gl_PointSize = pointSize; |
| 22 color = colorIn; |
| 23 gl_Position = vec4(pos, 1.0); |
| 24 } |
| 25 </script> |
| 26 |
| 27 <script id="fshader" type="x-shader/x-fragment"> |
| 28 precision mediump float; |
| 29 varying vec4 color; |
| 30 |
| 31 void main() |
| 32 { |
| 33 gl_FragColor = color; |
| 34 } |
| 35 </script> |
| 36 </head> |
| 37 <body> |
| 38 <canvas id="testbed" width="2px" height="2px"></canvas> |
| 39 <div id="description"></div> |
| 40 <div id="console"></div> |
| 41 <script> |
| 42 description('Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled in WebGL'); |
| 43 |
| 44 var gl = initWebGL('testbed', 'vshader', 'fshader', ['pos', 'colorIn'], [0,
0, 0, 1], 1, { antialias: false }); |
| 45 shouldBeNonNull("gl"); |
| 46 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 47 |
| 48 gl.disable(gl.BLEND); |
| 49 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 50 |
| 51 // The choice of (0.4, 0.4) ensures that the centers of the surrounding |
| 52 // pixels are not contained within the point when it is of size 1, but |
| 53 // that they definitely are when it is of size 2. |
| 54 var vertices = new Float32Array([ |
| 55 0.4, 0.4, 0.0]); |
| 56 var colors = new Uint8Array([ |
| 57 255, 0, 0, 255]); |
| 58 |
| 59 var colorOffset = vertices.byteLength; |
| 60 |
| 61 var vbo = gl.createBuffer(); |
| 62 gl.bindBuffer(gl.ARRAY_BUFFER, vbo); |
| 63 gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DR
AW); |
| 64 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices); |
| 65 gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors); |
| 66 |
| 67 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 68 gl.enableVertexAttribArray(0); |
| 69 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, colorOffset); |
| 70 gl.enableVertexAttribArray(1); |
| 71 |
| 72 var locPointSize = gl.getUniformLocation(gl.program, 'pointSize'); |
| 73 |
| 74 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 75 |
| 76 debug('Draw a point of size 1 and verify it does not touch any other pixels.
'); |
| 77 |
| 78 gl.uniform1f(locPointSize, 1.0); |
| 79 gl.drawArrays(gl.POINTS, 0, vertices.length / 3); |
| 80 var buf = new Uint8Array(2 * 2 * 4); |
| 81 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 82 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 83 |
| 84 var index = 0; |
| 85 var correctColor; |
| 86 for (var y = 0; y < 2; ++y) { |
| 87 for (var x = 0; x < 2; ++x) { |
| 88 correctColor = [0, 0, 0]; |
| 89 if (x == 1 && y == 1) |
| 90 shouldBe('buf[index]', '255'); |
| 91 else |
| 92 shouldBe('buf[index]', '0'); |
| 93 shouldBe('buf[index + 1]', '0'); |
| 94 shouldBe('buf[index + 2]', '0'); |
| 95 index += 4; |
| 96 } |
| 97 } |
| 98 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 99 |
| 100 debug('Draw a point of size 2 and verify it fills the appropriate region.'); |
| 101 |
| 102 var pointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE); |
| 103 if (pointSizeRange[1] >= 2.0) { |
| 104 gl.uniform1f(locPointSize, 2.0); |
| 105 gl.drawArrays(gl.POINTS, 0, vertices.length / 3); |
| 106 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 107 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 108 index = 0; |
| 109 for (var y = 0; y < 2; ++y) { |
| 110 for (var x = 0; x < 2; ++x) { |
| 111 shouldBe('buf[index]', '255'); |
| 112 shouldBe('buf[index + 1]', '0'); |
| 113 shouldBe('buf[index + 2]', '0'); |
| 114 index += 4; |
| 115 } |
| 116 } |
| 117 } |
| 118 |
| 119 successfullyParsed = true; |
| 120 </script> |
| 121 |
| 122 <script src="../../resources/js-test-post.js"></script> |
| 123 |
| 124 </body> |
| 125 </html> |
OLD | NEW |