# Program and program generator ctx.program = cell("json") ctx.program.resource.save_policy = 4 #always save the program ctx.gen_program = transformer({"program_template": {"pin": "input", "dtype": "json"}, "program": {"pin": "output", "dtype": "json"}}) ctx.registrar.silk.connect("VertexData", ctx.gen_program) ctx.link_gen_program = link(ctx.gen_program.code.cell(), ".", "cell-gen-program.py", file_dominant=file_dominant) ctx.program_template.connect(ctx.gen_program.program_template) ctx.gen_program.program.connect(ctx.program) #GL program ctx.equilibrate() #ctx.program has to be generated first p = ctx.glprogram = glprogram(ctx.program, window_title="Seamless fireworks demo") ctx.frag_shader.connect(p.fragment_shader) ctx.vert_shader.connect(p.vertex_shader) # Vertexdata generator ctx.N = cell("int").set(10000) ctx.params_gen_vertexdata = cell(("json", "seamless", "transformer_params")) ctx.link_params_gen_vertexdata = link( ctx.params_gen_vertexdata, ".", "params_gen_vertexdata.json", file_dominant=file_dominant) ctx.equilibrate() ctx.gen_vertexdata = transformer(ctx.params_gen_vertexdata) ctx.N.connect(ctx.gen_vertexdata.N) ctx.registrar.silk.connect("VertexData", ctx.gen_vertexdata) ctx.registrar.silk.connect("VertexDataArray", ctx.gen_vertexdata)
"render": { "command": "points", "glstate": {}, "attributes": {}, }, } ctx.pre_program = cell("json").set(program) ctx.gen_program = transformer({"program": {"pin": "input", "dtype": "json"}, "result": {"pin": "output", "dtype": "json"}}) ctx.pre_program.connect(ctx.gen_program.program) ctx.gen_program.code.cell().set("return program") ctx.program = ctx.gen_program.result.cell() ctx.equilibrate() p = ctx.glprogram = glprogram(ctx.program) p.uniforms.cell().set({}) ctx.vertex_shader.connect(p.vertex_shader) ctx.fragment_shader.connect(p.fragment_shader) p.painted.cell().connect(p.update) #if this connection is broken, no more crash! """ BUG: ctx.program.touch() will always re-create the window ctx.pre_program.touch() will once-in-a-while result in a Qt crash This is much more likely if ctx.program.touch() has not occurred yet, and if the GL window has not been killed beforehand PARTIAL SOLUTION: let Qt flush its event loop whenever work is done This solves the issue for the current program.
""") identity = np.eye(4).tolist() ctx.uniforms = cell("json") ctx.window.camera.connect(ctx.uniforms) ctx.uniforms.connect(ctx.gen_uniforms.input) # Atom shaders ctx.atom_vertexshader = cell(("text", "code", "vertexshader")) ctx.atom_fragmentshader = cell(("text", "code", "fragmentshader")) ctx.links.atom_vertexshader = link(ctx.atom_vertexshader, ".", "atom.vert") ctx.links.atom_fragmentshader = link(ctx.atom_fragmentshader, ".", "atom.frag") # Atom program ctx.params.atom = cell("cson") ctx.links.atom = link(ctx.params.atom, ".", "atom.cson") ctx.atom_program = glprogram(ctx.params.atom, with_window=False) ctx.window.init.cell().connect(ctx.atom_program.init) ctx.window.paint.cell().connect(ctx.atom_program.paint) ctx.atom_program.repaint.cell().connect(ctx.window.update) ctx.coordinates.connect(ctx.atom_program.array_coordinates) ctx.normals.connect(ctx.atom_program.array_normals) ctx.triangle_indices.connect(ctx.atom_program.array_indices) ctx.gen_uniforms.output.cell().connect(ctx.atom_program.uniforms) ctx.atom_vertexshader.connect(ctx.atom_program.vertex_shader) ctx.atom_fragmentshader.connect(ctx.atom_program.fragment_shader) ctx.atoms = cell("array").set_store("GL") ctx.atoms.connect(ctx.atom_program.array_atoms) # PDB loader c = ctx.params.load_pdb = cell(("json", "seamless", "transformer_params"))
"u_modelview_matrix": input["modelview_matrix"], "u_projection_matrix": input["projection_matrix"], "u_normal_matrix": input["normal_matrix"], "u_mvp_matrix": input["mvp_matrix"], } return result """) identity = np.eye(4).tolist() ctx.uniforms = cell("json") ctx.window.camera.connect(ctx.uniforms) ctx.uniforms.connect(ctx.gen_uniforms.input) # Lines program ctx.params.lines = cell("cson") ctx.links.lines = link(ctx.params.lines, ".", "lines.cson", file_dominant=file_dominant) ctx.lines_program = glprogram(ctx.params.lines, with_window=False) ctx.window.init.cell().connect(ctx.lines_program.init) #ctx.window.paint.cell().connect(ctx.lines_program.paint) # taken over by selector ctx.lines_program.repaint.cell().connect(ctx.window.update) #ctx.coordinates.connect(ctx.lines_program.array_coordinates) #ctx.edges.connect(ctx.lines_program.array_edges) ctx.gen_uniforms.output.cell().connect(ctx.lines_program.uniforms) # Lines shaders ctx.lines_vertexshader = cell(("text", "code", "vertexshader")) ctx.lines_fragmentshader = cell(("text", "code", "fragmentshader")) ctx.links.lines_vertexshader = link(ctx.lines_vertexshader, ".", "lines.vert", file_dominant=file_dominant) ctx.links.lines_fragmentshader = link(ctx.lines_fragmentshader, ".", "lines.frag", file_dominant=file_dominant) ctx.lines_vertexshader.connect(ctx.lines_program.vertex_shader) ctx.lines_fragmentshader.connect(ctx.lines_program.fragment_shader)
ctx.gen_program = transformer({ "program": { "pin": "input", "dtype": "json" }, "result": { "pin": "output", "dtype": "json" } }) ctx.pre_program.connect(ctx.gen_program.program) ctx.gen_program.code.cell().set("return program") ctx.program = ctx.gen_program.result.cell() ctx.equilibrate() p = ctx.glprogram = glprogram(ctx.program) p.uniforms.cell().set({}) ctx.vertex_shader.connect(p.vertex_shader) ctx.fragment_shader.connect(p.fragment_shader) p.painted.cell().connect( p.update) #if this connection is broken, no more crash! """ BUG: ctx.program.touch() will always re-create the window ctx.pre_program.touch() will once-in-a-while result in a Qt crash This is much more likely if ctx.program.touch() has not occurred yet, and if the GL window has not been killed beforehand PARTIAL SOLUTION: let Qt flush its event loop whenever work is done This solves the issue for the current program.
from seamless.lib.gui.gl import glprogram ctx.program = cell("cson") link(ctx.program, ".", "program.cson") if not ctx.program.value: ### kludge: to be fixed in seamless 0.2 ctx.program.set("{}") p = ctx.glprogram = glprogram(ctx.program, window_title="Seamless fireworks demo") ctx.glprogram.uniforms.set({}) ctx.vert_shader = cell(("text", "code", "vertexshader")) ctx.frag_shader = cell(("text", "code", "fragmentshader")) link(ctx.vert_shader, ".", "vert_shader.glsl") link(ctx.frag_shader, ".", "frag_shader.glsl") ctx.frag_shader.connect(p.fragment_shader) ctx.vert_shader.connect(p.vertex_shader) ctx.vertexdata.set_store("GL")