示例#1
0
    def render(self):
        if not self.dancer.render_multithreaded:
            new_pixel_matrix = [[self.new_pixel() for j in range(self.ray_length)] for i in range(self.dancer.num_rays)]
            # print '******new render'
            for name, data in self.shaders.items():
                shad = Shader(data)
                new_pixel_matrix = shad.effect(new_pixel_matrix)
                # print name, data.pixel_component, data.generate_parameters

            self.pixel_matrix = new_pixel_matrix
            # display_pixel_matrix(self.pixel_matrix)

        else:

            # send shaders
            # print 'sending data to shaders', self.shaders
            for wi in range(self.dancer.num_rays):
                self.render_pipes[wi][0].send(self.shaders)

            # receive pixels
            new_pixel_matrix = [None] * self.dancer.num_rays
            for wi in range(self.dancer.num_rays):
                # print 'rx from worker', wi
                new_pixel_ray = self.render_pipes[wi][0].recv()

                # assemble pixels into full matrix
                # print 'rays by worker',wi,self.render_workers_rays
                new_pixel_matrix[wi] = new_pixel_ray

            self.pixel_matrix = new_pixel_matrix
示例#2
0
    def render_worker(self, conn, ray_index):

        while True:
            msg = conn.recv()
            # print 'worker received', msg
            if msg == 'end':
                break
            else:
                new_pixel_ray = [self.new_pixel() for j in range(self.ray_length)]
                for name, data in msg.items():
                    # print 'shader', name
                    shad = Shader(data)
                    new_pixel_ray = shad.effect(new_pixel_ray, ray_index)
                # print 'worker sending'
                conn.send(new_pixel_ray)

        conn.close()