def __init__(self, data): self.data = data self.vbo_id = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo_id) rawGlBufferData(gl.GL_ARRAY_BUFFER, ADT.arrayByteCount(data), ADT.voidDataPointer(data), gl.GL_DYNAMIC_DRAW) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
def initialize(): plats = cl.get_platforms() ctx_props = cl.context_properties props = [(ctx_props.PLATFORM, plats[0]), (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())] import sys if sys.platform == "linux2": props.append( (ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) elif sys.platform == "win32": props.append( (ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC())) ctx = cl.Context(properties=props) glClearColor(1, 1, 1, 1) glColor(0, 0, 1) vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) rawGlBufferData(GL_ARRAY_BUFFER, n_vertices * 2 * 4, None, GL_STATIC_DRAW) glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, None) coords_dev = cl.GLBuffer(ctx, cl.mem_flags.READ_WRITE, int(vbo)) prog = cl.Program(ctx, src).build() queue = cl.CommandQueue(ctx) cl.enqueue_acquire_gl_objects(queue, [coords_dev]) prog.generate_sin(queue, (n_vertices,), None, coords_dev) cl.enqueue_release_gl_objects(queue, [coords_dev]) queue.finish() glFlush()
def initialize(): plats = cl.get_platforms() ctx_props = cl.context_properties props = [(ctx_props.PLATFORM, plats[0]), (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())] import sys if sys.platform == "linux2": props.append((ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay())) elif sys.platform == "win32": props.append((ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC())) ctx = cl.Context(properties=props) glClearColor(1, 1, 1, 1) glColor(0, 0, 1) vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) rawGlBufferData(GL_ARRAY_BUFFER, n_vertices * 2 * 4, None, GL_STATIC_DRAW) glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, None) coords_dev = cl.GLBuffer(ctx, cl.mem_flags.READ_WRITE, int(vbo)) prog = cl.Program(ctx, src).build() queue = cl.CommandQueue(ctx) cl.enqueue_acquire_gl_objects(queue, [coords_dev]) prog.generate_sin(queue, (n_vertices, ), None, coords_dev) cl.enqueue_release_gl_objects(queue, [coords_dev]) queue.finish() glFlush()
def initial_buffers(): data = numpy.ndarray((num_points, 2), dtype=numpy.float32) data[:,:] = [0.,1.] cl_buffer = cl.Buffer(context, cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=data) gl_buffer = vbo.VBO(data=data, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) # gl_buffer.bind() buffer_name = glGenBuffers(1) # Generate the OpenGL Buffer name glBindBuffer(GL_ARRAY_BUFFER, buffer_name) # Bind the vertex buffer to a target rawGlBufferData(GL_ARRAY_BUFFER, num_points * 2 * 4, None, GL_DYNAMIC_DRAW) # Allocate memory for the buffer glEnableClientState(GL_VERTEX_ARRAY) # The vertex array is enabled for client writing and used for rendering glVertexPointer(2, GL_FLOAT, 0, None) # Define an array of vertex data (size xyz, type, stride, pointer) cl_gl_buffer = cl.GLBuffer(context, cl.mem_flags.READ_WRITE, int(buffer_name)) return (cl_buffer, gl_buffer, cl_gl_buffer)
def __init__(self, gl_context, cl_context, size, scale=None, color=(0, 0, 0)): super(LinePlot, self).__init__() self.scale = scale self._size = size self.color = color self.gl_context = gl_context self.cl_context = cl_context vbo = GL.glGenBuffers(1) GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo) rawGlBufferData(GL.GL_ARRAY_BUFFER, self.size * 2 * 4, None, GL.GL_STATIC_DRAW) self.vtx_array = VertexArray(self.cl_context, vbo) self.queue = cl.CommandQueue(self.cl_context) self._pipe_segments = []
def initialize(): platform = cl.get_platforms()[0] from pyopencl.tools import get_gl_sharing_context_properties import sys if sys.platform == "darwin": ctx = cl.Context(properties=get_gl_sharing_context_properties(), devices=[]) else: # Some OSs prefer clCreateContextFromType, some prefer # clCreateContext. Try both. try: ctx = cl.Context(properties=[ (cl.context_properties.PLATFORM, platform)] + get_gl_sharing_context_properties()) except: ctx = cl.Context(properties=[ (cl.context_properties.PLATFORM, platform)] + get_gl_sharing_context_properties(), devices = [platform.get_devices()[0]]) glClearColor(1, 1, 1, 1) glColor(0, 0, 1) vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) rawGlBufferData(GL_ARRAY_BUFFER, n_vertices * 2 * 4, None, GL_STATIC_DRAW) glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, None) coords_dev = cl.GLBuffer(ctx, cl.mem_flags.READ_WRITE, int(vbo)) prog = cl.Program(ctx, src).build() queue = cl.CommandQueue(ctx) cl.enqueue_acquire_gl_objects(queue, [coords_dev]) prog.generate_sin(queue, (n_vertices,), None, coords_dev) cl.enqueue_release_gl_objects(queue, [coords_dev]) queue.finish() glFlush()
def initialize(): platform = cl.get_platforms()[0] from pyopencl.tools import get_gl_sharing_context_properties import sys if sys.platform == "darwin": ctx = cl.Context(properties=get_gl_sharing_context_properties(), devices=[]) else: # Some OSs prefer clCreateContextFromType, some prefer # clCreateContext. Try both. try: ctx = cl.Context( properties=[(cl.context_properties.PLATFORM, platform)] + get_gl_sharing_context_properties()) except: ctx = cl.Context( properties=[(cl.context_properties.PLATFORM, platform)] + get_gl_sharing_context_properties(), devices=[platform.get_devices()[0]]) glClearColor(1, 1, 1, 1) glColor(0, 0, 1) vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) rawGlBufferData(GL_ARRAY_BUFFER, n_vertices * 2 * 4, None, GL_STATIC_DRAW) glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(2, GL_FLOAT, 0, None) coords_dev = cl.GLBuffer(ctx, cl.mem_flags.READ_WRITE, int(vbo)) prog = cl.Program(ctx, src).build() queue = cl.CommandQueue(ctx) cl.enqueue_acquire_gl_objects(queue, [coords_dev]) prog.generate_sin(queue, (n_vertices, ), None, coords_dev) cl.enqueue_release_gl_objects(queue, [coords_dev]) queue.finish() glFlush()
glutInitWindowSize(800, 200) glutInitWindowPosition(0, 0) glutCreateWindow('OpenCL/OpenGL Interop') glutDisplayFunc(on_draw) glutReshapeFunc(on_reshape) glClearColor(1, 1, 1, 1) # Set the background color to white glColor(0, 0, 0) # Set the foreground color to black platform = cl.get_platforms()[0] context = cl.Context(properties=[(cl.context_properties.PLATFORM, platform)] + get_gl_sharing_context_properties()) vertex_buffer = glGenBuffers(1) # Generate the OpenGL Buffer name glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer) # Bind the vertex buffer to a target rawGlBufferData(GL_ARRAY_BUFFER, num_points * 2 * 4, None, GL_DYNAMIC_DRAW) # Allocate memory for the buffer glEnableClientState( GL_VERTEX_ARRAY ) # The vertex array is enabled for client writing and used for rendering glVertexPointer( 2, GL_FLOAT, 0, None) # Define an array of vertex data (size xyz, type, stride, pointer) cl_buffer = cl.GLBuffer(context, cl.mem_flags.READ_WRITE, int(vertex_buffer)) program = cl.Program(context, kernel).build() queue = cl.CommandQueue(context) cl.enqueue_acquire_gl_objects(queue, [cl_buffer]) program.generate_sin(queue, (num_points, ), None, cl_buffer) cl.enqueue_release_gl_objects(queue, [cl_buffer]) queue.finish() glFlush()