Ejemplo n.º 1
0
 def _with_context(self, hdc, proc, flush=False):
     old_hdc = wgl.wglGetCurrentDC()
     old_ctx = wgl.wglGetCurrentContext()
     result = wgl.wglMakeCurrent(hdc, self._win_context)
     try:
         self._with_share_group(proc)
         if flush:
             if self._win_dblbuf:
                 wgl.SwapBuffers(hdc)
             else:
                 gl.glFlush()
     finally:
         wgl.wglMakeCurrent(old_hdc, old_ctx)
Ejemplo n.º 2
0
def get_gl_sharing_context_properties():
    ctx_props = cl.context_properties

    from OpenGL import platform as gl_platform, GLX, WGL

    props = []

    import sys
    if sys.platform in ["linux", "linux2"]:
        props.append(
            (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext()))
        props.append(
                (ctx_props.GLX_DISPLAY_KHR,
                    GLX.glXGetCurrentDisplay()))
    elif sys.platform == "win32":
        props.append(
            (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext()))
        props.append(
                (ctx_props.WGL_HDC_KHR,
                    WGL.wglGetCurrentDC()))
    elif sys.platform == "darwin":
        props.append(
            (ctx_props.CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
                cl.get_apple_cgl_share_group()))
    else:
        raise NotImplementedError("platform '%s' not yet supported"
                % sys.platform)

    return props
Ejemplo n.º 3
0
    def __init__(self):
        plats = cl.get_platforms()
        ctx_props = cl.context_properties

        self.props = [(ctx_props.PLATFORM, plats[0]),
                      (ctx_props.GL_CONTEXT_KHR, platform.GetCurrentContext())]

        if sys.platform == "linux2":
            self.props.append((ctx_props.GLX_DISPLAY_KHR,
                               GLX.glXGetCurrentDisplay()))
        elif sys.platform == "win32":
            self.props.append((ctx_props.WGL_HDC_KHR, WGL.wglGetCurrentDC()))
        self.ctx = cl.Context(properties=self.props)

        self.cross4 = ElementwiseKernel(
            self.ctx, "__global const float4 *u, "
            "__global const float4 *v, "
            "__global const float4 *w, "
            "__global       float4 *r",
            "r[i] = cross4(u[i],v[i],w[i])",
            "cross4_final",
            preamble=cross4_preamble)

        self.distance2 = ElementwiseKernel(
            self.ctx, "__global const float4 *a, "
            "__global const float4 *b, "
            "__global       float4 *d",
            "d[i] = distance2(a[i],b[i])",
            "distance_final",
            preamble=distance_preamble)
        self.place_hyperspheres()
Ejemplo n.º 4
0
 def TestMethod( self, method ):
     print 'Starting method', method
     module = pixel_format
     hdc = WGL.wglGetCurrentDC()
     items = [(name,getattr( module, name)) for name in names ]
     failures = []
     if method == pixel_format.wglGetPixelFormatAttribivARB:
         result = WGL.INT32( )
     else:
         result = WGL.FLOAT( )
     for item in items:
         try:
             pf = WGL.GetPixelFormat(hdc)
             method(
                 hdc,
                 pf,
                 0,
                 1,
                 WGL.INT32(item[1]),
                 result,
             )
         except WindowsError, err:
             failures.append((item,err))
         else:
             print '%20s\t%r'%( item[0], result.value)
Ejemplo n.º 5
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 __init__(self, share_group, config, hdc, mode):
     print "GLContext: mode =", mode ###
     GGLContext.__init__(self, share_group)
     shared_context = self._get_shared_context()
     if shared_context:
         share_ctx = shared_context._win_context
     else:
         share_ctx = None
     ipf, actpf = config._win_supported_pixelformat(hdc, mode)
     config._check_win_pixelformat(actpf, mode)
     print "GLContext: Setting pixel format", ipf, "for hdc", hdc ###
     wgl.SetPixelFormat(hdc, ipf, actpf)
     print "GLContext: Creating context for hdc", hdc ###
     ctx = wgl.wglCreateContext(hdc)
     if share_ctx:
         wgl.wglShareLists(share_ctx, ctx)
     self._win_context = ctx
     self._win_dblbuf = actpf.dwFlags & wgl.PFD_DOUBLEBUFFER != 0
    def get_context_properties(self, plat):
        #reference context properties enumeration
        out = []

        #link OpenCL context platform
        out.append((context_properties.PLATFORM, plat))
        #link OpenGL context
        out.append((context_properties.GL_CONTEXT_KHR, platform.GetCurrentContext()))
        #link platform specific window contexts
        if "GLX" in globals():
            out.append((context_properties.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay()))
        if "WGL" in globals():
            out.append((context_properties.WGL_HDC_KHR, WGL.wglGetCurrentDC()))

        #return context properties
        return out
Ejemplo n.º 8
0
 def destroy(self):
     wgl.wglDeleteContext(self._win_context)