Beispiel #1
0
 def setup_kernels(self):
     self.cl_program = build_program(self.ctx, "kernels")
     self.raytrace = self.cl_program.raytrace
     self.init_chunk_array = self.cl_program.init_chunk_array
Beispiel #2
0
 def __init__(self, clctx, queue):
     '''
     Constructor
     '''
     self.clctx = clctx
     self.queue = queue
     
     # stores the objects of the scene. (data and ref)
     self.objects = set() 
     self.lights = set()
     
     # stores the (byte)data of the objects
     self._obj_buffer     = RenderBuffer(clctx, queue, 2**16, 2**15)
     
     # stores the references on the (byte)data. 
     # these will be raytraced in the render process.
     self._obj_references = RenderBuffer(clctx, queue, 2**15, 2**14)
     
     # couldn't help myself but put this in a buffer... maybe sometimes we need multiple cameras.
     self._cam_buffer     = RenderBuffer(clctx, queue, Camera.dtype.itemsize, Camera.dtype.itemsize)
     
     # The lights in the scene. These are referenced by _light_references
     self._light_buffer     = RenderBuffer(clctx, queue, 2**9, 2**7)
     self._light_references = RenderBuffer(clctx, queue, 2**8, 2**6)
     
     # This camera will be passed to the render process
     self.camera = self.create_camera(position=(-2,-2,30), orientation=(1,0,0,0), bounds=(-2,2,1.5,-1.5), warp=4)
     
     self.raytrace_pgrm = build_program(clctx, "raytrace")
     self.raytrace = self.raytrace_pgrm.raytrace
     self.raytrace.set_scalar_arg_dtypes([None, None, None, numpy.uint32, None, None, None, None])
     self._chunk_array = ChunkArray(self.clctx, self.queue, (0, 1) , self.raytrace_pgrm.init_chunk_array)
     
     """self._chunk_array.allocate_layer(0, x_bounds=(0, 2), y_bounds=(0, 2))
     self._chunk_array.allocate_layer(1, x_bounds=(0, 2), y_bounds=(0, 2))
     self._chunk_array.allocate_chunk(0, 0, 0, level=0)
     self._chunk_array.allocate_chunk(1, 0, 0, level=1)
     self._chunk_array.allocate_chunk(0, 0, 1, level=0)
     self._chunk_array.allocate_chunk(1, 0, 1, level=0)
     self._chunk_array.allocate_chunk(0, 1, 0, level=0)
     self._chunk_array.allocate_chunk(1, 1, 0, level=0)
     self._chunk_array.allocate_chunk(0, 1, 1, level=0)
     self._chunk_array.allocate_chunk(1, 1, 1, level=0)
     
     self._chunk_array.get_layer(0).chunk_offset = 0
     chunk = self._chunk_array.get_chunk(0, 0, 0)
     chunk.voxel_data[:] = numpy.array([(random.randint(0,2), (0,0,0), (-1,-1,-1)) for i in range(32**3)], dtype=VoxelData.test_dtype)
     
     chunk = self._chunk_array.get_chunk(1, 0, 0)
     chunk.voxel_data[:] = numpy.array([(i % 2, (0,0,0), (-1,-1,-1)) for i in range(16**3)], dtype=VoxelData.test_dtype)
     
     chunk = self._chunk_array.get_chunk(0, 0, 1)
     chunk.voxel_data[:] = numpy.array([(random.randint(0,2), (0,0,0), (-1,-1,-1)) for i in range(32**3)], dtype=VoxelData.test_dtype)
     
     self._chunk_array.get_chunk(1, 0, 1).voxel_data[:] = chunk.voxel_data
     
     
     self._chunk_array.get_chunk(0, 1, 0).voxel_data[:] = chunk.voxel_data
     self._chunk_array.get_chunk(1, 1, 0).voxel_data[:] = chunk.voxel_data
     self._chunk_array.get_chunk(0, 1, 1).voxel_data[:] = chunk.voxel_data
     self._chunk_array.get_chunk(1, 1, 1).voxel_data[:] = chunk.voxel_data"""
     
     self.h_test_buffer = numpy.zeros((32,32,32), dtype=numpy.uint32)
     self.d_test_buffer = pyopencl.Buffer(clctx, pyopencl.mem_flags.READ_WRITE | pyopencl.mem_flags.COPY_HOST_PTR, hostbuf=self.h_test_buffer)