MCPcopy
hub / github.com/regl-project/regl / gpuReduceCreate

Function gpuReduceCreate

example/reduction.js:60–163  ·  view source on GitHub ↗
(data, op)

Source from the content-addressed store, hash-verified

58 1x1, 2x2, 4x4, 8x8, 16x16,...
59*/
60function gpuReduceCreate (data, op) {
61 // a single reduce pass
62 var reducePass = regl({
63 frag: `
64 precision mediump float;
65 uniform sampler2D tex;
66 varying vec2 uv;
67 uniform float rcpDim;
68
69 float op(float a, float b) {
70 return ${op};
71 }
72
73 void main () {
74 float a = texture2D(tex, uv - vec2(0.0, 0.0) * rcpDim).x;
75 float b = texture2D(tex, uv - vec2(1.0, 0.0) * rcpDim).x;
76 float c = texture2D(tex, uv - vec2(0.0, 1.0) * rcpDim).x;
77 float d = texture2D(tex, uv - vec2(1.0, 1.0) * rcpDim).x;
78
79 float result = op(op(a, b), op(c, d));
80 gl_FragColor = vec4(result);
81 }`,
82
83 vert: `
84 precision mediump float;
85 attribute vec2 position;
86 varying vec2 uv;
87 void main () {
88 uv = position;
89 gl_Position = vec4(1.0 - 2.0 * position, 0, 1);
90 }`,
91
92 attributes: {
93 position: [-2, 0, 0, -2, 2, 2]
94 },
95
96 uniforms: {
97 tex: regl.prop('inTex'),
98 rcpDim: regl.prop('rcpDim') // reciprocal texture dimensions.
99 },
100
101 framebuffer: regl.prop('outFbo'),
102
103 count: 3
104 })
105
106 // We must use a texture format of type RGBA. Because you cannot create a single channel FBO of type
107 // ALPHA in WebGL.
108 var textureData = []
109 var i
110 for (i = 0; i < data.length; i++) {
111 var g = data[i]
112 textureData.push(g, g, g, g)
113 }
114
115 // dimensions of the first texture is (dim)X(dim).
116 var DIM = Math.sqrt(data.length)
117 var dim = DIM

Callers 1

profileFunction · 0.85

Calls 4

propMethod · 0.80
textureMethod · 0.80
framebufferMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…