<s> import sys <EOL> import numpy <EOL> from OpenGL . GL import * <EOL> from OpenGL . GLU import * <EOL> from OpenGL import GLX <EOL> import pyopencl as cl <EOL> class raycl ( object ) : <EOL> def __init__ ( self , texture , tex_dim , world ) : <EOL> self . tex_dim = tex_dim <EOL> self . world = world <EOL> self . clinit ( ) <EOL> self . loadProgram ( "<STR_LIT>" ) <EOL> world . init_cldata ( self . ctx ) <EOL> self . tex = cl . GLTexture ( <EOL> self . ctx , cl . mem_flags . READ_WRITE , <EOL> GL_TEXTURE_2D , <NUM_LIT:0> , <EOL> texture , <NUM_LIT:2> ) <EOL> self . gl_objects = [ self . tex ] <EOL> def clinit ( self ) : <EOL> plats = cl . get_platforms ( ) <EOL> ctx_props = cl . context_properties <EOL> props = [ ( ctx_props . PLATFORM , plats [ <NUM_LIT:0> ] ) , <EOL> ( ctx_props . GL_CONTEXT_KHR , platform . GetCurrentContext ( ) ) ] <EOL> import sys <EOL> if sys . platform == "<STR_LIT>" : <EOL> props . append ( ( ctx_props . GLX_DISPLAY_KHR , <EOL> GLX . glXGetCurrentDisplay ( ) ) ) <EOL> elif sys . platform == "<STR_LIT:win32>" : <EOL> props . append ( ( ctx_props . WGL_HDC_KHR , <EOL> WGL . wglGetCurrentDC ( ) ) ) <EOL> self . ctx = cl . Context ( properties = props ) <EOL> self . queue = cl . CommandQueue ( self . ctx ) <EOL> def loadProgram ( self , fname ) : <EOL> f = open ( fname , "<STR_LIT:r>" ) <EOL> code = "<STR_LIT>" . join ( f . readlines ( ) ) <EOL> self . program = cl . Program ( self . ctx , code ) . build ( ) <EOL> def execute ( self ) : <EOL> glFinish ( ) <EOL> cl . enqueue_acquire_gl_objects ( self . queue , self . gl_objects ) <EOL> global_size = self . tex_dim <EOL> local_size = None <EOL> world = self . world <EOL> kernelargs = ( self . tex , <EOL> numpy . float32 ( world . camera . rot_x ) , <EOL> numpy . float32 ( world . camera . rot_y ) , <EOL> numpy . float32 ( world . camera . x ) , <EOL> numpy . float32 ( world . camera . y ) , <EOL> numpy . float32 ( world . camera . z ) , <EOL> numpy . float32 ( world . camera . fov_x ( ) ) , <EOL> numpy . float32 ( world . camera . fov_y ( ) ) , <EOL> world . mapdat_clbuf ) <EOL> self . program . raytrace ( self . queue , global_size , local_size , <EOL> * kernelargs ) <EOL> cl . enqueue_release_gl_objects ( self . queue , self . gl_objects ) <EOL> self . queue . flush ( ) <EOL> self . queue . finish ( ) </s>
