3 <!-- READ BEFORE UPDATING:
4 If this test is updated make sure to increment the "revision" value of the
5 associated test in content/test/gpu/page_sets/pixel_tests.py. This will ensure
6 that the baseline images are regenerated on the next run.
11 <title>WebGL Test: Green Triangle over Black Background
</title>
12 <style type=
"text/css">
18 <script id=
"shader-vs" type=
"x-shader/x-vertex">
22 gl_Position = vec4(pos,
1.0);
26 <script id=
"shader-fs" type=
"x-shader/x-fragment">
27 precision mediump float;
30 gl_FragColor = vec4(
0.0,
1.0,
0.0,
1.0);
35 var g_swapsBeforeAck
= 15;
40 var canvas
= document
.getElementById("c");
42 if (gl
&& setup(gl
)) {
45 domAutomationController
.setAutomationId(1);
46 domAutomationController
.send("FAILURE");
50 function drawSomeFrames()
52 if (g_swapsBeforeAck
== 0) {
53 domAutomationController
.setAutomationId(1);
54 domAutomationController
.send("SUCCESS");
58 window
.webkitRequestAnimationFrame(drawSomeFrames
);
62 function initGL(canvas
)
66 gl
= canvas
.getContext("experimental-webgl");
70 gl
= canvas
.getContext("webgl");
76 function setupShader(gl
, source
, type
) {
77 var shader
= gl
.createShader(type
);
78 gl
.shaderSource(shader
, source
);
79 gl
.compileShader(shader
);
80 if (!gl
.getShaderParameter(shader
, gl
.COMPILE_STATUS
))
85 function setupProgram(gl
, vs_id
, fs_id
) {
86 var vs_node
= document
.getElementById(vs_id
);
87 var fs_node
= document
.getElementById(fs_id
);
88 if (!vs_node
|| !fs_node
)
90 var vs
= setupShader(gl
, vs_node
.text
, gl
.VERTEX_SHADER
);
91 var fs
= setupShader(gl
, fs_node
.text
, gl
.FRAGMENT_SHADER
);
94 var program
= gl
.createProgram();
95 gl
.attachShader(program
, vs
);
96 gl
.attachShader(program
, fs
);
97 gl
.linkProgram(program
);
98 if (!gl
.getProgramParameter(program
, gl
.LINK_STATUS
))
100 gl
.useProgram(program
);
104 function setupBuffer(gl
) {
105 var buffer
= gl
.createBuffer();
106 gl
.bindBuffer(gl
.ARRAY_BUFFER
, buffer
);
108 0.0, 0.6, 0.0, // Vertex 1 position
109 -0.6, -0.6, 0.0, // Vertex 2 position
110 0.6, -0.6, 0.0, // Vertex 3 position
112 gl
.bufferData(gl
.ARRAY_BUFFER
, new Float32Array(vertexData
), gl
.STATIC_DRAW
);
116 var program
= setupProgram(gl
, "shader-vs", "shader-fs");
119 var posAttr
= gl
.getAttribLocation(program
, "pos");
120 gl
.enableVertexAttribArray(posAttr
);
122 var stride
= 3 * Float32Array
.BYTES_PER_ELEMENT
;
123 gl
.vertexAttribPointer(posAttr
, 3, gl
.FLOAT
, false, stride
, 0);
124 gl
.clearColor(0.0, 0.0, 0.0, 0.0);
125 gl
.viewport(0, 0, 200, 200);
126 gl
.disable(gl
.DEPTH_TEST
);
127 if (gl
.getError() != gl
.NO_ERROR
)
133 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
134 gl
.drawArrays(gl
.TRIANGLES
, 0, 3);
138 <body onload=
"main()">
139 <div style=
"position:relative; width:200px; height:200px; background-color:black"></div>
140 <div style=
"position:absolute; top:0px; left:0px">
141 <canvas id=
"c" width=
"200" height=
"200" class=
"nomargin"></canvas>