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

Function drawParticlesProgram

src/lib/programs/drawParticlesProgram.js:14–122  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

12 * @param {Object} ctx rendering context. Holds WebGL state
13 */
14export default function drawParticlesProgram(ctx) {
15 var gl = ctx.gl;
16
17 var particleStateResolution, particleIndexBuffer;
18 var numParticles;
19
20 var currentVectorField = '';
21 var updatePositionProgram = makeUpdatePositionProgram(ctx);
22 var audioProgram;
23
24 var drawProgram;
25 initPrograms();
26
27 return {
28 updateParticlesCount,
29 updateParticlesPositions,
30 drawParticles,
31 updateCode,
32 updateColorMode
33 }
34
35 function initPrograms() {
36 // need to update the draw graph because color mode shader has changed.
37 initDrawProgram();
38
39 if (config.isAudioEnabled) {
40 if (audioProgram) audioProgram.dispose();
41 audioProgram = createAudioProgram(ctx);
42 }
43 }
44
45 function initDrawProgram() {
46 if (drawProgram) drawProgram.unload();
47
48 const drawGraph = new DrawParticleGraph(ctx);
49 const vertexShaderCode = drawGraph.getVertexShader(currentVectorField);
50 drawProgram = util.createProgram(gl, vertexShaderCode, drawGraph.getFragmentShader());
51 }
52
53 function updateParticlesPositions() {
54 if (!currentVectorField) return;
55
56 ctx.frame += 1
57 ctx.frameSeed = Math.random();
58
59 // TODO: Remove this.
60 if (audioProgram) audioProgram.updateTextures();
61
62 updatePositionProgram.updateParticlesPositions();
63 }
64
65 function updateColorMode() {
66 initDrawProgram();
67 }
68
69 function updateCode(vfCode) {
70 ctx.frame = 0;
71 currentVectorField = vfCode;

Callers

nothing calls this directly

Calls 1

initProgramsFunction · 0.85

Tested by

no test coverage detected