summaryrefslogtreecommitdiffstats
path: root/devtools/client/shadereditor/test/doc_simple-canvas.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/shadereditor/test/doc_simple-canvas.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/shadereditor/test/doc_simple-canvas.html')
-rw-r--r--devtools/client/shadereditor/test/doc_simple-canvas.html125
1 files changed, 125 insertions, 0 deletions
diff --git a/devtools/client/shadereditor/test/doc_simple-canvas.html b/devtools/client/shadereditor/test/doc_simple-canvas.html
new file mode 100644
index 000000000..2a709ad8e
--- /dev/null
+++ b/devtools/client/shadereditor/test/doc_simple-canvas.html
@@ -0,0 +1,125 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <title>WebGL editor test page</title>
+
+ <script id="shader-vs" type="x-shader/x-vertex">
+ precision lowp float;
+ attribute vec3 aVertexPosition;
+ attribute vec3 aVertexColor;
+ varying vec3 vFragmentColor;
+
+ void main(void) {
+ gl_Position = vec4(aVertexPosition, 1.0);
+ vFragmentColor = aVertexColor; // I'm special!
+ }
+ </script>
+
+ <script id="shader-fs" type="x-shader/x-fragment">
+ precision lowp float;
+ varying vec3 vFragmentColor;
+
+ void main(void) {
+ gl_FragColor = vec4(vFragmentColor, 1.0); // I'm also special!
+ }
+ </script>
+ </head>
+
+ <body>
+ <canvas width="512" height="512"></canvas>
+
+ <script type="text/javascript;version=1.8">
+ "use strict";
+
+ let canvas, gl;
+ let program;
+ let squareVerticesPositionBuffer;
+ let squareVerticesColorBuffer;
+ let vertexPositionAttribute;
+ let vertexColorAttribute;
+
+ window.onload = function() {
+ canvas = document.querySelector("canvas");
+ gl = canvas.getContext("webgl", { preserveDrawingBuffer: true });
+ gl.clearColor(0.0, 0.0, 0.0, 1.0);
+
+ initProgram();
+ initBuffers();
+ drawScene();
+ }
+
+ function initProgram() {
+ let vertexShader = getShader(gl, "shader-vs");
+ let fragmentShader = getShader(gl, "shader-fs");
+
+ program = gl.createProgram();
+ gl.attachShader(program, vertexShader);
+ gl.attachShader(program, fragmentShader);
+ gl.linkProgram(program);
+
+ vertexPositionAttribute = gl.getAttribLocation(program, "aVertexPosition");
+ gl.enableVertexAttribArray(vertexPositionAttribute);
+
+ vertexColorAttribute = gl.getAttribLocation(program, "aVertexColor");
+ gl.enableVertexAttribArray(vertexColorAttribute);
+ }
+
+ function getShader(gl, id) {
+ let script = document.getElementById(id);
+ let source = script.textContent;
+ let shader;
+
+ if (script.type == "x-shader/x-fragment") {
+ shader = gl.createShader(gl.FRAGMENT_SHADER);
+ } else if (script.type == "x-shader/x-vertex") {
+ shader = gl.createShader(gl.VERTEX_SHADER);
+ }
+
+ gl.shaderSource(shader, source);
+ gl.compileShader(shader);
+
+ return shader;
+ }
+
+ function initBuffers() {
+ squareVerticesPositionBuffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesPositionBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+ 1.0, 1.0, 0.0,
+ -1.0, 1.0, 0.0,
+ 1.0, -1.0, 0.0,
+ -1.0, -1.0, 0.0
+ ]), gl.STATIC_DRAW);
+
+ squareVerticesColorBuffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesColorBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+ 1.0, 1.0, 1.0, 1.0,
+ 1.0, 0.0, 0.0, 1.0,
+ 0.0, 1.0, 0.0, 1.0,
+ 0.0, 0.0, 1.0, 1.0
+ ]), gl.STATIC_DRAW);
+ }
+
+ function drawScene() {
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesPositionBuffer);
+ gl.vertexAttribPointer(vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesColorBuffer);
+ gl.vertexAttribPointer(vertexColorAttribute, 4, gl.FLOAT, false, 0, 0);
+
+ gl.useProgram(program);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+
+ window.requestAnimationFrame(drawScene);
+ }
+ </script>
+ </body>
+
+</html>