summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dproj.html
blob: c9e042f9a9a0af3a4ea3956ec39331ac8851c04c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL texture2D GLSL conformance test.</title>
<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="32" height="32"></canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader0" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec2 texCoord0;
varying vec2 texCoord;
void main() {
    gl_Position = vPosition;
    texCoord = texCoord0;
}
</script>
<script id="fshader0" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D tex;
uniform float divisor;
varying vec2 texCoord;
void main() {
    gl_FragData[0] = texture2DProj(tex, vec3(texCoord, divisor));
}
</script>
<script id="vshader1" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec2 texCoord0;
varying vec2 texCoord;
void main() {
    gl_Position = vPosition;
    texCoord = texCoord0;
}
</script>
<script id="fshader1" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D tex;
uniform float divisor;
varying vec2 texCoord;
void main() {
    gl_FragData[0] = texture2DProj(tex, vec4(texCoord, 123.0, divisor));
}
</script>
<script>
"use strict";
description("tests GLSL texture2DProj function with");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example", {antialias: false});

wtu.setupUnitQuad(gl, 0, 1);
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);

var c = document.createElement("canvas");
c.width = 16;
c.height = 16;
var ctx = c.getContext("2d");
ctx.fillStyle = "rgb(0,255,0)";
ctx.fillRect(0, 0, 16, 16);
ctx.fillStyle = "rgb(0,0,255)";
ctx.fillRect(0, 0, 8, 8);
ctx.fillRect(8, 8, 8, 8);

gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);

for (var ss = 0; ss < 2; ++ss) {
  debug("");
  debug(ss ? "testing vec4 version" : "testing vec3 version");
  var program = wtu.setupProgram(
      gl, ['vshader' + ss, 'fshader' + ss],
      ['vPosition', 'texCoord0'], [0, 1]);
  gl.useProgram(program);
  var loc = gl.getUniformLocation(program, "divisor");

  for (var ii = 0; ii < 3; ++ii) {
    var denominator = Math.pow(2, ii);
    gl.uniform1f(loc, 1 / denominator);
    wtu.clearAndDrawUnitQuad(gl);
    var size = 16 / denominator;
    for (var yy = 0; yy < 32; yy += size) {
      for (var xx = 0; xx < 32; xx += size) {
        var odd = (xx / size + yy / size) % 2;
        var color = odd ? [0, 255, 0, 255] : [0, 0, 255, 255];
        var msg = "" + xx + ", " + yy + ", " + size + ", " + size + " should be " + (odd ? "green" : "blue");
        wtu.checkCanvasRect(gl, xx, yy, size, size, color, msg);
      }
    }
  }
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");

var successfullyParsed = true;

</script>
<script src="../../../js/js-test-post.js"></script>

</body>
</html>