forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture-simple.js
61 lines (50 loc) · 1.21 KB
/
texture-simple.js
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
var createContext = require('./util/create-context')
var createREGL = require('../../regl')
var tape = require('tape')
tape('texture', function (t) {
var gl = createContext(2, 2)
var regl = createREGL(gl)
var texture = regl.texture([
[[255, 0, 0], [0, 255, 0]],
[[0, 0, 255], [255, 255, 255]]
])
const drawTexture = regl({
frag: [
'precision mediump float;',
'uniform sampler2D tex;',
'varying vec2 uv;',
'void main() {',
' gl_FragColor = texture2D(tex, uv);',
'}'].join('\n'),
vert: [
'precision mediump float;',
'attribute vec2 p;',
'varying vec2 uv;',
'void main() {',
' uv = 0.5 * (1.0 + p);',
' gl_Position = vec4(p, 0, 1);',
'}'].join('\n'),
attributes: {
p: regl.buffer([
-4, 4,
4, 4,
0, -4
])
},
uniforms: {
tex: texture
},
depth: { enable: false },
count: 3
})
drawTexture()
var pixels = regl.read()
t.same([].slice.call(pixels), [
255, 0, 0, 255, 0, 255, 0, 255,
0, 0, 255, 255, 255, 255, 255, 255
], 'simple texture test')
regl.destroy()
t.equals(gl.getError(), 0, 'error ok')
createContext.destroy(gl)
t.end()
})