mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
177 lines
6.7 KiB
HTML
177 lines
6.7 KiB
HTML
<!--
|
|
Copyright (c) 2010 Mozilla Foundation. All rights reserved.
|
|
Use of this source code is governed by a BSD-style license that can be
|
|
found in the LICENSE file.
|
|
-->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
"http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
<title>WebGL Program Compiling/Linking Conformance Test</title>
|
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
|
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
|
|
<script src="../resources/js-test-pre.js" type="text/javascript"></script>
|
|
<script src="resources/webgl-test.js" type="text/javascript"></script>
|
|
</head>
|
|
<body>
|
|
<div id="description"></div>
|
|
<div id="console"></div>
|
|
<canvas id="canvas" width="2" height="2"> </canvas>
|
|
<script type="text/javascript">
|
|
function go() {
|
|
description("Tests that program compiling/linking/using works correctly.");
|
|
|
|
debug("");
|
|
debug("Canvas.getContext");
|
|
|
|
var gl = create3DContext(document.getElementById("canvas"));
|
|
if (!gl) {
|
|
testFailed("context does not exist");
|
|
return;
|
|
}
|
|
|
|
testPassed("context exists");
|
|
|
|
gl.clearColor(0.0, 0.0, 0.0, 0.0);
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
|
|
var vs = gl.createShader(gl.VERTEX_SHADER);
|
|
gl.shaderSource(vs, "attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }");
|
|
gl.compileShader(vs);
|
|
|
|
assertMsg(gl.getShaderParameter(vs, gl.COMPILE_STATUS) == true,
|
|
"good vertex shader should compiled");
|
|
|
|
var vsBad = gl.createShader(gl.VERTEX_SHADER);
|
|
gl.shaderSource(vsBad, "WILL NOT COMPILE;");
|
|
gl.compileShader(vsBad);
|
|
|
|
assertMsg(gl.getShaderParameter(vsBad, gl.COMPILE_STATUS) == false,
|
|
"bad vertex shader should failed to compile");
|
|
|
|
var fs = gl.createShader(gl.FRAGMENT_SHADER);
|
|
gl.shaderSource(fs, "#ifdef GL_ES\nprecision mediump float;\n#endif\n varying vec4 vColor; void main() { gl_FragColor = vColor; }");
|
|
gl.compileShader(fs);
|
|
|
|
assertMsg(gl.getShaderParameter(fs, gl.COMPILE_STATUS) == true,
|
|
"good fragment shader should compile");
|
|
|
|
var fs2 = gl.createShader(gl.FRAGMENT_SHADER);
|
|
gl.shaderSource(fs2, "#ifdef GL_ES\nprecision mediump float;\n#endif\n varying vec4 vColor; void main() { gl_FragColor = vColor * 0.5; }");
|
|
gl.compileShader(fs2);
|
|
|
|
assertMsg(gl.getShaderParameter(fs2, gl.COMPILE_STATUS) == true,
|
|
"good fragment shader #2 should compile");
|
|
|
|
var fsBad = gl.createShader(gl.FRAGMENT_SHADER);
|
|
gl.shaderSource(fsBad, "WILL NOT COMPILE;");
|
|
gl.compileShader(fsBad);
|
|
|
|
assertMsg(gl.getShaderParameter(fsBad, gl.COMPILE_STATUS) == false,
|
|
"bad fragment shader should fail to compile");
|
|
|
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
|
"should be no errors at this point");
|
|
|
|
// Now create some programs.
|
|
|
|
function createAndCheckLinkStatus(shaders, expected_status, errmsg) {
|
|
var prog = gl.createProgram();
|
|
for (var i = 0; i < shaders.length; ++i)
|
|
gl.attachShader(prog, shaders[i]);
|
|
gl.bindAttribLocation(prog, 0, "aVertex");
|
|
gl.bindAttribLocation(prog, 1, "aColor");
|
|
gl.linkProgram(prog);
|
|
assertMsg(gl.getProgramParameter(prog, gl.LINK_STATUS) == expected_status,
|
|
errmsg);
|
|
if (expected_status == true && gl.getProgramParameter(prog, gl.LINK_STATUS) == false)
|
|
debug(gl.getProgramInfoLog(prog));
|
|
return prog;
|
|
}
|
|
|
|
var progGood1 = createAndCheckLinkStatus([vs, fs], true,
|
|
"valid program should link");
|
|
|
|
var progGood2 = createAndCheckLinkStatus([vs, fs2], true,
|
|
"valid program #2 should link");
|
|
|
|
var progBad1 = createAndCheckLinkStatus([vs], false,
|
|
"program with no fragment shader should fail to link");
|
|
|
|
var progBad2 = createAndCheckLinkStatus([fs], false,
|
|
"program with no vertex shader should fail to link");
|
|
|
|
var progBad3 = createAndCheckLinkStatus([vsBad, fs], false,
|
|
"program with bad vertex shader should fail to link");
|
|
|
|
var progBad4 = createAndCheckLinkStatus([vs, fsBad], false,
|
|
"program with bad fragment shader should fail to link");
|
|
|
|
var progBad5 = createAndCheckLinkStatus([vsBad, fsBad], false,
|
|
"program with bad shaders should fail to link");
|
|
|
|
gl.detachShader(progBad3, vs);
|
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
|
"detaching a shader not attached to a program should generate INVALID_OPERATION");
|
|
|
|
gl.useProgram(progBad1);
|
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
|
"using a program which failed to link should generate INVALID_OPERATION");
|
|
|
|
gl.useProgram(progBad5);
|
|
assertMsg(gl.getError() == gl.INVALID_OPERATION,
|
|
"using a program which failed to link should generate INVALID_OPERATION (#2)");
|
|
|
|
gl.useProgram(progGood1);
|
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
|
"using a valid program shouldn't generate a GL error");
|
|
|
|
var vbuf = gl.createBuffer();
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbuf);
|
|
gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([0.0, 0.0, 0.0, 1.0,
|
|
1.0, 0.0, 0.0, 1.0,
|
|
1.0, 1.0, 0.0, 1.0,
|
|
0.0, 1.0, 0.0, 1.0]), gl.STATIC_DRAW);
|
|
gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
|
|
gl.enableVertexAttribArray(0);
|
|
gl.vertexAttrib3f(1, 1.0, 0.0, 0.0);
|
|
|
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
|
"should be no errors at this point #2");
|
|
|
|
gl.useProgram(progGood1);
|
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
|
"drawing with a valid program shouldn't generate a GL error");
|
|
|
|
gl.useProgram(progBad1);
|
|
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
assertMsg(gl.getError() != gl.NO_ERROR,
|
|
"drawing with an invalid program should generate some GL error XXX");
|
|
|
|
gl.useProgram(progGood2);
|
|
gl.attachShader(progGood2, fsBad);
|
|
gl.linkProgram(progGood2);
|
|
assertMsg(gl.getProgramParameter(progGood2, gl.LINK_STATUS) == false,
|
|
"linking should fail with in-use formerly good program, with new bad shader attached");
|
|
|
|
gl.useProgram(progGood1);
|
|
gl.drawArrays(gl.TRIANGLES, 0, 4);
|
|
assertMsg(gl.getError() == gl.NO_ERROR,
|
|
"drawing with a valid when last used program shouldn't generate a GL error");
|
|
}
|
|
|
|
debug("");
|
|
successfullyParsed = true;
|
|
|
|
go();
|
|
</script>
|
|
<script src="../resources/js-test-post.js"></script>
|
|
|
|
<script>
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|