(-400, -200, 100), (-250, -350, 100), (0, -300, 100), (250, -350, 100), (400, -200, 100), ] circles_ubo = GL.NewUniformBuffer(struct.pack('i4x', len(circles)) + b''.join(struct.pack('2f1f4x', *c) for c in circles)) GL.UseUniformBuffer(circles_ubo, circles_prog['Circles']) particles_prog = GL.NewProgram([particles_vert, particles_frag]) GL.SetUniform(particles_prog['scale'], 0.002 * height / width, 0.002) particle_vbo = GL.NewVertexBuffer(b''.join(struct.pack('2f', cos(i * 2 * pi / 16), sin(i * 2 * pi / 16)) for i in range(16))) particle_vao = GL.NewVertexArray(particles_prog, particle_vbo, '2f', ['vert']) sbo = GL.NewStorageBuffer(b''.join(struct.pack('ffffff', -10000, 0, -10000, 0, 0, 0) for i in range(10240))) GL.UseUniformBuffer(circles_ubo, circles_prog['Circles']) GL.UseStorageBuffer(sbo) k = 0 while WND.Update(): k = (k + 32) % 10240 GL.UpdateStorageBuffer(sbo, k * 24, b''.join(struct.pack('ffffff', -400, 200, -400 + uniform(3, 5), 200 + uniform(2, 5), 0, -0.1) for i in range(32))) GL.Clear(240, 240, 240) GL.RunComputeShader(physics, 40) GL.RenderTriangleFan(circle_vao, 128, instances = len(circles)) GL.RenderTriangleFan(particle_vao, 16, instances = 10240)
B[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y][gl_GlobalInvocationID.z] = A[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y][gl_GlobalInvocationID.z]; } ''') A = GL.NewStorageBuffer(struct.pack('64i', *[1 + i for i in range(64)])) B = GL.NewStorageBuffer(b'\x00' * 256) C = GL.NewStorageBuffer(b'\x00' * 256) BX = GL.NewStorageBuffer(b'\x00' * 256) BY = GL.NewStorageBuffer(b'\x00' * 256) BZ = GL.NewStorageBuffer(b'\x00' * 256) GL.UseStorageBuffer(A) GL.UseStorageBuffer(B, 1) GL.RunComputeShader(cs) GL.UseStorageBuffer(BX, 1) GL.RunComputeShader(cs, x = 2) GL.UseStorageBuffer(BY, 1) GL.RunComputeShader(cs, y = 2) GL.UseStorageBuffer(BZ, 1) GL.RunComputeShader(cs, z = 2) GL.UpdateStorageBuffer(C, 0, struct.pack('64i', *[4 for i in range(64)])) GL.UpdateStorageBuffer(C, 64, struct.pack('32i', *[9 for i in range(32)])) print(struct.unpack('64i', GL.ReadStorageBuffer(B))) print(struct.unpack('64i', GL.ReadStorageBuffer(BX))) print(struct.unpack('64i', GL.ReadStorageBuffer(BY))) print(struct.unpack('64i', GL.ReadStorageBuffer(BZ)))