(reader: Rgba8Readback)
| 97 | // Get a program and THREE.RawShaderMaterial for a given Rgba8Readback, |
| 98 | // generating it if necessary and caching the result. |
| 99 | prepareProgramMaterial(reader: Rgba8Readback): { |
| 100 | program: DynoProgram; |
| 101 | material: THREE.RawShaderMaterial; |
| 102 | } { |
| 103 | let program = Readback.readbackProgram.get(reader); |
| 104 | if (!program) { |
| 105 | const graph = dynoBlock( |
| 106 | { index: "int" }, |
| 107 | { rgba8: "vec4" }, |
| 108 | ({ index }) => { |
| 109 | reader.inputs.index = index; |
| 110 | const rgba8 = new OutputRgba8({ rgba8: reader.outputs.rgba8 }); |
| 111 | return { rgba8 }; |
| 112 | }, |
| 113 | ); |
| 114 | if (!Readback.programTemplate) { |
| 115 | Readback.programTemplate = new DynoProgramTemplate( |
| 116 | getShaders().computeVec4Template, |
| 117 | ); |
| 118 | } |
| 119 | // Create a program from the template and graph |
| 120 | program = new DynoProgram({ |
| 121 | graph, |
| 122 | inputs: { index: "_index" }, |
| 123 | outputs: { rgba8: "target" }, |
| 124 | template: Readback.programTemplate, |
| 125 | }); |
| 126 | Object.assign(program.uniforms, { |
| 127 | targetLayer: { value: 0 }, |
| 128 | targetBase: { value: 0 }, |
| 129 | targetCount: { value: 0 }, |
| 130 | }); |
| 131 | Readback.readbackProgram.set(reader, program); |
| 132 | } |
| 133 | |
| 134 | const material = program.prepareMaterial(); |
| 135 | Readback.fullScreenQuad.material = material; |
| 136 | return { program, material }; |
| 137 | } |
| 138 | |
| 139 | private saveRenderState(renderer: THREE.WebGLRenderer) { |
| 140 | return { |
no test coverage detected