2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL Vertex Texture Fetch.
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"> </script>
17 <canvas id=
"example" width=
"1" height=
"1" style=
"width: 40px; height: 40px;"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
20 <script id=
"vs" type=
"text/something-not-javascript">
21 attribute vec4 a_position;
22 attribute vec2 a_texCoord;
23 uniform sampler2D u_texture;
26 gl_Position = a_position;
27 color = texture2D(u_texture, a_texCoord);
30 <script id=
"fs" type=
"text/something-not-javascript">
31 precision mediump float;
39 description("checks that vertex texture fetch, if supported, operates correctly.");
40 var wtu
= WebGLTestUtils
;
41 var gl
= wtu
.create3DContext("example");
42 if (!gl
.getParameter(gl
.MAX_VERTEX_TEXTURE_IMAGE_UNITS
)) {
43 testPassed("No vertex texture image units (vertex texture fetch not supported) -- this is legal");
45 var texture
= gl
.createTexture();
46 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
47 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, 2, 2, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
,
53 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
54 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
55 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
56 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
57 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after creating texture");
59 var program
= wtu
.setupProgram(gl
, ["vs", "fs"], ["vPosition", "vTexCoord"]);
60 gl
.uniform1i(gl
.getUniformLocation(program
, "u_texture"), 0);
62 gl
.disable(gl
.DEPTH_TEST
);
63 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after initWebGL");
64 var bufferObjects
= wtu
.setupUnitQuad(gl
, 0);
65 gl
.disableVertexAttribArray(1);
67 gl
.vertexAttrib2f(1, 0, 0);
68 wtu
.clearAndDrawUnitQuad(gl
);
69 wtu
.checkCanvas(gl
, [255, 0, 0, 255], "Should be red.");
71 gl
.vertexAttrib2f(1, 1, 0);
72 wtu
.clearAndDrawUnitQuad(gl
);
73 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "Should be green.");
75 gl
.vertexAttrib2f(1, 0, 1);
76 wtu
.clearAndDrawUnitQuad(gl
);
77 wtu
.checkCanvas(gl
, [0, 0, 255, 255], "Should be blue.");
79 gl
.vertexAttrib2f(1, 1, 1);
80 wtu
.clearAndDrawUnitQuad(gl
);
81 wtu
.checkCanvas(gl
, [255, 255, 0, 255], "Should be yellow.");
83 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after drawing");
86 var successfullyParsed
= true;
88 <script src=
"../../js/js-test-post.js"></script>