mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
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:
commit
f0014bd9cd
9 changed files with 144 additions and 44 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue