gl-shader-test.html (2482B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL ShaderL Conformance Tests</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 13 <script src="../../js/desktop-gl-constants.js"></script> 14 <script src="../../js/js-test-pre.js"></script> 15 <script src="../../js/webgl-test-utils.js"></script> 16 </head> 17 <body> 18 <script id="vs" type="x-shader/x-fragment"> 19 attribute vec4 vPosition; 20 varying vec2 texCoord; 21 void main() { 22 gl_Position = vPosition; 23 texCoord = vPosition.xy * 0.5 + 0.5; 24 } 25 </script> 26 <script id="fs-green" type="x-shader/x-fragment"> 27 precision mediump float; 28 void main() { 29 gl_FragData[0] = vec4(0, 1, 0, 1); 30 } 31 </script> 32 <script id="fs-red" type="x-shader/x-fragment"> 33 precision mediump float; 34 void main() { 35 gl_FragData[0] = vec4(1, 0, 0, 1); 36 } 37 </script> 38 <div id="description"></div> 39 <div id="console"></div> 40 <canvas id="canvas" width="2" height="2"> </canvas> 41 <script> 42 "use strict"; 43 description("This test checks a few things about WebGL Shaders."); 44 45 debug(""); 46 debug("Canvas.getContext"); 47 48 var wtu = WebGLTestUtils; 49 var gl = wtu.create3DContext("canvas"); 50 if (!gl) { 51 testFailed("context does not exist"); 52 } else { 53 testPassed("context exists"); 54 55 debug(""); 56 debug("Checking shaders."); 57 58 // Create the shader object 59 var shader = gl.createShader(desktopGL['GEOMETRY_SHADER_ARB']); 60 assertMsg(shader == null, 61 "should not be able to create GEOMETRY shader"); 62 63 checkDeferredCompliation() 64 } 65 66 function checkDeferredCompliation() { 67 var vs = gl.createShader(gl.VERTEX_SHADER); 68 gl.shaderSource(vs, document.getElementById("vs").text); 69 gl.compileShader(vs); 70 var fs = gl.createShader(gl.FRAGMENT_SHADER); 71 // Compile the green shader 72 gl.shaderSource(fs, document.getElementById("fs-green").text); 73 gl.compileShader(fs); 74 // Load the red shader source but do NOT compile it 75 gl.shaderSource(fs, document.getElementById("fs-red").text); 76 var p = gl.createProgram(); 77 gl.attachShader(p, vs); 78 gl.attachShader(p, fs); 79 gl.bindAttribLocation(p, 0, "vPosition"); 80 gl.linkProgram(p); 81 gl.useProgram(p); 82 wtu.setupUnitQuad(gl, 0, 1); 83 wtu.clearAndDrawUnitQuad(gl); 84 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); 85 } 86 87 debug(""); 88 var successfullyParsed = true; 89 90 </script> 91 <script src="../../js/js-test-post.js"></script> 92 93 </body> 94 </html>