MCPcopy Create free account
hub / github.com/anvaka/fieldplay / updatePositionProgram

Function updatePositionProgram

src/lib/programs/updatePositionProgram.js:12–199  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

10const particlePositionShaderCodeBuilder = new UpdatePositionGraph();
11
12export default function updatePositionProgram(ctx) {
13 var gl = ctx.gl;
14 var readTextures, writeTextures;
15 var particleStateResolution;
16 var updateProgram;
17 var readVelocity = makeReadProgram(ctx);
18
19 // If someone needs to get vectors out from the GPU, they send a `vector-lines-request`
20 // over the bus. This request is delayed until next compute frame. Once it is handled,
21 // we send them back response with calculated vectors.
22 var pendingVectorLines;
23
24 // TODO: need to make sure we are not leaking.
25 bus.on('vector-lines-request', putVectorLinesRequestIntoQueue);
26
27 return {
28 updateCode,
29 updateParticlesPositions,
30 updateParticlesCount,
31 prepareToDraw,
32 };
33
34 function updateCode(vectorField) {
35 particlePositionShaderCodeBuilder.setCustomVectorField(vectorField);
36 let fragment = particlePositionShaderCodeBuilder.getFragmentShader();
37 let vertex = particlePositionShaderCodeBuilder.getVertexShader();
38
39 let newProgram = util.createProgram(gl, vertex, fragment);
40
41 if (updateProgram) updateProgram.unload();
42 updateProgram = newProgram;
43
44 if (ctx.colorMode === ColorMode.VELOCITY) readVelocity.requestSpeedUpdate();
45 }
46
47 function updateParticlesCount(x, y) {
48 particleStateResolution = ctx.particleStateResolution;
49
50 var dimensions = [{
51 name: 'x',
52 particleState: x
53 }, {
54 name: 'y',
55 particleState: y
56 }];
57
58 if (readTextures) readTextures.dispose();
59 readTextures = textureCollection(gl, dimensions, particleStateResolution);
60
61 if (writeTextures) writeTextures.dispose();
62 writeTextures = textureCollection(gl, dimensions, particleStateResolution);
63
64 readVelocity.updateParticlesCount();
65 }
66
67 function prepareToDraw(program) {
68 var colorMode = ctx.colorMode;
69 if (colorMode === ColorMode.VELOCITY) readVelocity.setColorMinMax(program);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected