blob: 742df958d6113f1458e083d4ad88eed2c699feca [file] [log] [blame]
gman@chromium.org8c33d152013-02-07 13:05:32 +00001<!--
2
3/*
4** Copyright (c) 2012 The Khronos Group Inc.
5**
6** Permission is hereby granted, free of charge, to any person obtaining a
7** copy of this software and/or associated documentation files (the
8** "Materials"), to deal in the Materials without restriction, including
9** without limitation the rights to use, copy, modify, merge, publish,
10** distribute, sublicense, and/or sell copies of the Materials, and to
11** permit persons to whom the Materials are furnished to do so, subject to
12** the following conditions:
13**
14** The above copyright notice and this permission notice shall be included
15** in all copies or substantial portions of the Materials.
16**
17** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24*/
25
26-->
27
28<!DOCTYPE html>
29<html>
30<head>
31<meta charset="utf-8">
32<title>WebGL ShaderL Conformance Tests</title>
33<link rel="stylesheet" href="../../resources/js-test-style.css"/>
34<script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script>
35<script src="../../resources/js-test-pre.js"></script>
36<script src="../resources/webgl-test.js"></script>
37<script src="../resources/webgl-test-utils.js"></script>
38</head>
39<body>
40<script id="vs" type="x-shader/x-fragment">
41attribute vec4 vPosition;
42varying vec2 texCoord;
43void main() {
44 gl_Position = vPosition;
45 texCoord = vPosition.xy * 0.5 + 0.5;
46}
47</script>
48<script id="fs-green" type="x-shader/x-fragment">
49precision mediump float;
50void main() {
51 gl_FragData[0] = vec4(0, 1, 0, 1);
52}
53</script>
54<script id="fs-red" type="x-shader/x-fragment">
55precision mediump float;
56void main() {
57 gl_FragData[0] = vec4(1, 0, 0, 1);
58}
59</script>
60<div id="description"></div>
61<div id="console"></div>
62<canvas id="canvas" width="2" height="2"> </canvas>
63<script>
64"use strict";
65description("This test checks a few things about WebGL Shaders.");
66
67debug("");
68debug("Canvas.getContext");
69
70var wtu = WebGLTestUtils;
71var gl = wtu.create3DContext("canvas");
72if (!gl) {
73 testFailed("context does not exist");
74} else {
75 testPassed("context exists");
76
77 debug("");
78 debug("Checking shaders.");
79
80 // Create the shader object
81 var shader = gl.createShader(desktopGL['GEOMETRY_SHADER_ARB']);
82 assertMsg(shader == null,
83 "should not be able to create GEOMETRY shader");
84
85 checkDeferredCompliation()
86}
87
88function checkDeferredCompliation() {
89 var vs = gl.createShader(gl.VERTEX_SHADER);
90 gl.shaderSource(vs, document.getElementById("vs").text);
91 gl.compileShader(vs);
92 var fs = gl.createShader(gl.FRAGMENT_SHADER);
93 // Compile the green shader
94 gl.shaderSource(fs, document.getElementById("fs-green").text);
95 gl.compileShader(fs);
96 // Load the red shader source but do NOT compile it
97 gl.shaderSource(fs, document.getElementById("fs-red").text);
98 var p = gl.createProgram();
99 gl.attachShader(p, vs);
100 gl.attachShader(p, fs);
101 gl.bindAttribLocation(p, 0, "vPosition");
102 gl.linkProgram(p);
103 gl.useProgram(p);
104 wtu.setupUnitQuad(gl, 0, 1);
105 wtu.drawQuad(gl);
106 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
107}
108
109debug("");
110var successfullyParsed = true;
111
112</script>
113<script src="../../resources/js-test-post.js"></script>
114
115</body>
116</html>