Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / compositing / webgl / webgl-reflection.html
blob610a9bb2fbcca3e24474af682366342e6f4fa5e8
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <style type="text/css" media="screen">
5 canvas {
6 margin: 20px;
7 width: 200px;
8 height: 200px;
9 padding: 0 20px;
10 border: 2px solid black;
11 -webkit-box-reflect: below 20px;
12 outline: 10px solid transparent; /* affects layer sizes */
15 </style>
16 <script id="vertexShader" type="x-shader/x-vertex">
17 attribute vec4 vPosition;
19 void main() {
20 gl_Position = vPosition;
22 </script>
24 <script id="fragmentShader" type="x-shader/x-fragment">
25 void main() {
26 gl_FragColor = vec4(0.0, 0.5, 0.0, 1.0);
28 </script>
29 <script>
30 if (window.testRunner)
31 testRunner.overridePreference("WebKitWebGLEnabled", "1");
33 var gl = null;
35 function draw()
37 var vertices = [ 0.0, 0.8, 0.0,
38 -0.8, -0.8, 0.0,
39 0.8, -0.8, 0.0 ];
40 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
42 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); // Load the vertex data
43 gl.enableVertexAttribArray(0);
44 gl.drawArrays(gl.TRIANGLES, 0, 3);
45 gl.flush();
48 function getFragmentShader()
50 var shaderNode = document.getElementById("fragmentShader"); // fragmentShader has been defined at the top
51 var shaderSource = getShaderSource(shaderNode);
53 var shader = gl.createShader(gl.FRAGMENT_SHADER);
54 gl.shaderSource(shader, shaderSource);
55 gl.compileShader(shader);
57 return shader;
60 function getShaderSource(shaderNode)
62 var shaderSource = "";
63 var node = shaderNode.firstChild;
64 while (node) {
65 if (node.nodeType == 3) // Node.TEXT_NODE
66 shaderSource += node.textContent;
67 node = node.nextSibling;
70 return shaderSource;
73 function getVertexShader()
75 var shaderNode = document.getElementById("vertexShader");
76 var shaderSource = getShaderSource(shaderNode);
78 var shader = gl.createShader(gl.VERTEX_SHADER);
79 gl.shaderSource(shader, shaderSource);
80 gl.compileShader(shader);
82 return shader;
85 function initialize()
87 var theCanvas = document.getElementById("canvas");
88 gl = theCanvas.getContext("webgl");
90 var vertexShader = getVertexShader();
91 var fragmentShader = getFragmentShader();
93 var shaderProgram = gl.createProgram();
94 gl.attachShader(shaderProgram, vertexShader);
95 gl.attachShader(shaderProgram, fragmentShader);
96 gl.bindAttribLocation(shaderProgram, 0, "vPosition"); // vPosition has been defined at the top
97 gl.linkProgram(shaderProgram);
99 gl.useProgram(shaderProgram);
101 var buffer = gl.createBuffer();
102 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
105 function drawCanvas()
107 initialize();
108 draw();
110 </script>
111 </head>
112 <body onload="drawCanvas()">
114 <p>You should see a green triangle and its reflection.</p>
115 <canvas id="canvas" style="left: 20px" width="200" height="200"></canvas>
117 </body>
118 </html>