Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #10224 - emilio:shader-type-validations, r=jdm
webgl: Add attribute validations and other nits Fixes #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 -->
- Loading branch information
Showing
9 changed files
with
144 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/wpt/mozilla/tests/mozilla/webgl/invalid_vertex_attributes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |