gecko/content/canvas/test/webgl/conformance/glsl-conformance.html

377 lines
10 KiB
HTML
Raw Normal View History

<!--
Copyright (c) 2009 The Chromium Authors. 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 GLSL Conformance Tests</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"></script>
<script src="resources/webgl-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
</script>
<script id="fshader" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithPrecision" type="text/something-not-javascript">
void main()
{
gl_FragColor = mediump vec4(1.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithDefaultPrecision" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithOutPrecision" type="text/something-not-javascript">
uniform vec4 color;
void main()
{
gl_FragColor = color;
}
</script>
<script id="fshaderWithInvalidIdentifier" type="text/something-not-javascript">
precision mediump float;
uniform float gl_foo;
void main()
{
gl_FragColor = vec4(gl_foo,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithGLSLPreprocessorSymbol" type="text/something-not-javascript">
#if defined(GL_ES)
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,1.0);
}
#else
foo
#endif
</script>
<script id="fshaderWithVERSION100PreprocessorSymbol" type="text/something-not-javascript">
#if __VERSION__ == 100
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
#else
foo
#endif
</script>
<script id="fshaderWithFragDepth" type="text/something-not-javascript">
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
gl_FragDepth = 1.0;
}
</script>
<script id="vshaderWithClipVertex" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
gl_ClipVertex = vPosition;
}
</script>
<script id="fshaderWith__Define" type="text/something-not-javascript">
#define __foo 1
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithGL_Define" type="text/something-not-javascript">
#define GL_FOO 1
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
</script>
<script id="fshaderWithDefineLineContinuation" type="text/something-not-javascript">
#define foo this \
is a test
precision mediump float;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
}
</script>
<script id="vshaderWithgl_Color" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = gl_Color;
}
</script>
<script id="vshaderWithgl_ProjectionMatrix" type="text/something-not-javascript">
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition * gl_ProjectionMatrix;
}
</script>
<script id="vshaderWithAttributeArray" type="text/something-not-javascript">
attribute vec4 vPosition[2];
void main()
{
gl_Position = vPosition[0] + vPosition[1];
}
</script>
<script id="vshaderWithwebgl_" type="text/something-not-javascript">
attribute vec4 webgl_vPosition;
void main()
{
gl_Position = webgl_vPosition;
}
</script>
<script id="vshaderWith_webgl_" type="text/something-not-javascript">
attribute vec4 _webgl_vPosition;
void main()
{
gl_Position = _webgl_vPosition;
}
</script>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
description("This test ensures WebGL implementations allow proper GLES2 shaders compile and improper ones fail.");
debug("");
debug("Canvas.getContext");
var gl = create3DContext(document.getElementById("canvas"));
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking various GLSL programs.");
function log(msg) {
if (window.console && window.console.log) {
window.console.log(msg);
}
}
function loadShader(shaderType, shaderId) {
// Get the shader source.
var shaderSource = document.getElementById(shaderId).text;
// Create the shader object
var shader = gl.createShader(shaderType);
if (shader == null) {
debug("*** Error: unable to create shader '"+shaderId+"'");
return null;
}
// Load the shader source
gl.shaderSource(shader, shaderSource);
// Compile the shader
gl.compileShader(shader);
// Check the compile status
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
if (!compiled) {
// Something went wrong during compilation; get the error
var error = gl.getShaderInfoLog(shader);
log("*** Error compiling shader '"+shader+"':"+error);
gl.deleteShader(shader);
return null;
}
return shader;
}
var shaderInfo = [
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithPrecision',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'frament shader with precision compiled and linked'
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithDefaultPrecision',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader with default precision compiled and linked'
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithOutPrecision',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader without precision should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithInvalidIdentifier',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader with gl_ identifier should fail',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithGLSLPreprocessorSymbol',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader that uses GL_ES preprocessor symbol should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithVERSION100PreprocessorSymbol',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'fragment shader that uses __VERSION__==100 should succeed',
},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithFragDepth',
fShaderSuccess: false,
linkSuccess: true,
passMsg: 'fragment shader that uses gl_FragDepth should fail',
},
{ vShaderId: 'vshaderWithClipVertex',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses gl_ClipVertex should fail',
},
//{ vShaderId: 'vshader',
// vShaderSuccess: true,
// fShaderId: 'fshaderWith__Define',
// fShaderSuccess: false,
// linkSuccess: false,
// passMsg: 'fragment shader that uses __ define should fail',
//},
//{ vShaderId: 'vshader',
// vShaderSuccess: true,
// fShaderId: 'fshaderWithGL_Define',
// fShaderSuccess: false,
// linkSuccess: false,
// passMsg: 'fragment shader that uses GL_ define should fail',
//},
{ vShaderId: 'vshader',
vShaderSuccess: true,
fShaderId: 'fshaderWithDefineLineContinuation',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'fragment shader that uses has line continuation macro should fail',
},
{ vShaderId: 'vshaderWithgl_Color',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses gl_Color should fail',
},
{ vShaderId: 'vshaderWithgl_ProjectionMatrix',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses gl_ProjectionMatrix should fail',
},
{ vShaderId: 'vshaderWithAttributeArray',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses attribute array should fail as per GLSL page 110, appendix A, section 5',
},
{ vShaderId: 'vshaderWithwebgl_',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses _webgl identifier should fail',
},
{ vShaderId: 'vshaderWith_webgl_',
vShaderSuccess: false,
fShaderId: 'fshader',
fShaderSuccess: true,
linkSuccess: false,
passMsg: 'vertex shader that uses _webgl_ identifier should fail',
}
];
for (var ii = 0; ii < shaderInfo.length; ++ii) {
var info = shaderInfo[ii];
log("vs = " + info.vShaderId + ", fs = " + info.fShaderId);
//debug(info.fShaderId);
var vShader = loadShader(gl.VERTEX_SHADER, info.vShaderId);
if ((vShader != null) != info.vShaderSuccess) {
testFailed(info.passMsg);
continue;
}
var fShader = loadShader(gl.FRAGMENT_SHADER, info.fShaderId);
//debug(fShader == null ? "fail" : "succeed");
if ((fShader != null) != info.fShaderSuccess) {
testFailed(info.passMsg);
continue;
}
if (vShader && fShader) {
var program = gl.createProgram();
gl.attachShader(program, vShader);
gl.attachShader(program, fShader);
gl.linkProgram(program);
var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
if (!linked) {
var error = gl.getProgramInfoLog(shader);
log("*** Error linking program '"+program+"':"+error);
}
if (linked != info.linkSuccess) {
testFailed(info.passMsg);
continue;
}
} else {
if (info.linkSuccess) {
testFailed(info.passMsg);
continue;
}
}
testPassed(info.passMsg);
}
}
debug("");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
<script>
</script>
</body>
</html>