2 <body onload=
"runRepaintTest()">
3 <span id=
"description" style=
"color: white">
4 This test is only useful as a pixel test. You should see two rows with
4 canvases in each. The top row of canvases should have a black background, the bottom row should have a dark blue background.
5 The canvases in the first two rows should have a single triangle. The canvases on the left should have two triangles superimposed on top of each other.
6 If multisampling is supported, the odd columns should have smooth edges instead of jagged stair-stepping.
11 outline:
1px solid blue;
14 background-color: darkblue;
17 <script id=
"2d-fragment-shader" type=
"x-shader/x-fragment">
18 precision mediump float;
23 gl_FragColor = u_color;
26 <script id=
"2d-vertex-shader" type=
"x-shader/x-vertex">
27 attribute vec2 a_position;
29 uniform vec2 u_resolution;
32 // convert the rectangle from pixels to
0.0 to
1.0
33 vec2 zeroToOne = a_position / u_resolution;
35 // convert from
0-
>1 to
0-
>2
36 vec2 zeroToTwo = zeroToOne *
2.0;
38 // convert from
0-
>2 to -
1-
>+
1 (clipspace)
39 vec2 clipSpace = zeroToTwo -
1.0;
41 gl_Position = vec4(clipSpace * vec2(
1, -
1),
0,
1);
44 <script src=
"resources/webgl-test-utils.js"></script>
49 if (window
.testRunner
) {
50 testRunner
.overridePreference("WebKitWebGLEnabled", "1");
51 testRunner
.dumpAsTextWithPixelResults();
52 document
.getElementById("description").style
.position
= "absolute";
53 document
.getElementById("description").style
.top
= "-5000px";
56 for (var i
=0; i
<8; ++i
) {
59 'preserveDrawingBuffer': (i
% 4) >= 2,
60 'antialias': (i
% 2) == 1
62 var can
= document
.createElement('canvas');
63 can
.width
= can
.height
= 100;
64 can
.style
.position
= "absolute";
65 can
.style
.left
= 10 + (i
% 4) * 120 + "px";
66 can
.style
.top
= (i
< 4 ? 40 : 150) + "px";
67 document
.body
.appendChild(can
);
69 document
.body
.appendChild(document
.createElement('br'));
70 ctxs
[i
] = can
.getContext("webgl", attrs
);
75 // setup a GLSL program
76 var wtu
= WebGLTestUtils
;
77 var vertexShader
= WebGLTestUtils
.loadShaderFromScript(gl
, "2d-vertex-shader");
78 var fragmentShader
= WebGLTestUtils
.loadShaderFromScript(gl
, "2d-fragment-shader");
79 var program
= gl
.createProgram();
80 gl
.attachShader(program
, vertexShader
, gl
.VERTEX_SHADER
);
81 gl
.attachShader(program
, fragmentShader
, gl
.FRAGMENT_SHADER
);
82 gl
.linkProgram(program
);
83 gl
.useProgram(program
);
85 // look up where the vertex data needs to go.
86 gl
.myPositionLocation
= gl
.getAttribLocation(program
, "a_position");
89 var resolutionLocation
= gl
.getUniformLocation(program
, "u_resolution");
90 gl
.uniform2f(resolutionLocation
, 100, 100);
92 var colorLocation
= gl
.getUniformLocation(program
, "u_color");
93 gl
.uniform4f(colorLocation
, 0, 1, 0, 1);
96 function draw(gl
, offset
) {
97 var buffer
= gl
.createBuffer();
98 gl
.bindBuffer(gl
.ARRAY_BUFFER
, buffer
);
99 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array([
102 10 + offset
, 80]), gl
.STATIC_DRAW
);
104 gl
.enableVertexAttribArray(gl
.myPositionLocation
);
105 gl
.vertexAttribPointer(gl
.myPositionLocation
, 2, gl
.FLOAT
, false, 0, 0);
108 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
111 function drawAll(offset
) {
112 for (var i
=0; i
<8; ++i
)
113 draw(ctxs
[i
], offset
);
118 function repaintTest() {
120 if (window
.testRunner
) {
121 testRunner
.notifyDone();
125 function runRepaintTest() {
126 if (window
.testRunner
) {
127 testRunner
.waitUntilDone();
128 testRunner
.layoutAndPaintAsyncThen(repaintTest
);
130 setTimeout(repaintTest
, 100);