Auto merge of #10224 - emilio:shader-type-validations, r=jdm

webgl: Add attribute validations and other nits

Fixes https://github.com/servo/servo/issues/9958

Depends on a bunch of prs, and needs a test.

r? @jdm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10224)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-12 05:18:49 +05:30
commit f0014bd9cd
9 changed files with 144 additions and 44 deletions

View file

@ -9,23 +9,25 @@
<canvas id="canvas" width="512" height="512"></canvas>
</div>
<script id="vertexshader" type="x-shader">
attribute vec2 aVertexPosition;
attribute vec4 aColour;
varying vec4 aVertexColor;
precision mediump float;
void main() {
aVertexColor = aColour;
gl_Position = vec4(aVertexPosition, 0.0, 1.0);
}
attribute vec2 aVertexPosition;
attribute vec4 aColour;
varying vec4 aVertexColor;
void main() {
aVertexColor = aColour;
gl_Position = vec4(aVertexPosition, 0.0, 1.0);
}
</script>
<script id="fragmentshader" type="x-shader">
precision mediump float;
precision mediump float;
varying vec4 aVertexColor;
varying vec4 aVertexColor;
void main() {
gl_FragColor = aVertexColor;
}
void main() {
gl_FragColor = aVertexColor;
}
</script>
<script type="text/javascript">
@ -44,6 +46,9 @@
var v = document.getElementById("vertexshader").firstChild.nodeValue;
var f = document.getElementById("fragmentshader").firstChild.nodeValue;
console.log("vertex source: ", v);
console.log("fragment source: ", f);
var vs = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vs, v);
gl.compileShader(vs);
@ -96,6 +101,7 @@
gl.vertexAttribPointer(program.aVertexPosition, itemSize, gl.FLOAT, false, 0, 0);
program.aColour = gl.getAttribLocation(program, "aColour");
console.log("aColour: " + program.aColour);
gl.enableVertexAttribArray(program.aColour);
gl.vertexAttribPointer(program.aColour, 4, gl.FLOAT, false, 0, 24);

View file

@ -6477,6 +6477,12 @@
"url": "/_mozilla/mozilla/webgl/get_supported_extensions.html"
}
],
"mozilla/webgl/invalid_vertex_attributes.html": [
{
"path": "mozilla/webgl/invalid_vertex_attributes.html",
"url": "/_mozilla/mozilla/webgl/invalid_vertex_attributes.html"
}
],
"mozilla/websocket_connection_fail.html": [
{
"path": "mozilla/websocket_connection_fail.html",

View file

@ -0,0 +1,60 @@
<!doctype html>
<meta charset="utf-8">
<title>Validation of out-of-bounds vertex attributes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
void main() {
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
void main() {
}
</script>
<script type="application/x-javascript">
function getShader(gl, id) {
var shaderScript = document.getElementById(id);
if (!shaderScript)
return null;
var type = (shaderScript.getAttribute('type') == "x-shader/x-fragment") ?
gl.FRAGMENT_SHADER : gl.VERTEX_SHADER;
var shader = gl.createShader(type);
gl.shaderSource(shader, shaderScript.textContent);
gl.compileShader(shader);
assert_true(!!gl.getShaderParameter(shader, gl.COMPILE_STATUS), shaderScript.textContent + '\n' + gl.getShaderInfoLog(shader));
return shader;
}
</script>
<canvas id="canvas"></canvas>
<script>
test(function() {
var canvas = document.getElementById("canvas");
var gl = canvas.getContext("experimental-webgl");
assert_true(!!gl);
var shaderProgram = gl.createProgram();
var vertexShader = getShader(gl, "shader-vs");
gl.attachShader(shaderProgram, vertexShader);
var fragmentShader = getShader(gl, "shader-fs");
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
assert_true(gl.getError() == gl.NO_ERROR);
// -1 is what it's returned from a not found attribute.
gl.enableVertexAttribArray(-1);
assert_true(gl.getError() == gl.INVALID_VALUE);
assert_true(gl.getError() == gl.NO_ERROR);
gl.vertexAttribPointer(-1, 2, gl.FLOAT, false, 0, 0);
assert_true(gl.getError() == gl.INVALID_VALUE);
assert_true(gl.getError() == gl.NO_ERROR);
gl.vertexAttrib1f(-1, 3.0);
assert_true(gl.getError() == gl.INVALID_VALUE);
});
</script>
</html>