Ejemplo n.º 1
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.º 2
0
def get_gl_sharing_context_properties():
    ctx_props = cl.context_properties

    from OpenGL import platform as gl_platform

    props = []

    import sys
    if sys.platform in ["linux", "linux2"]:
        from OpenGL import GLX
        props.append(
            (ctx_props.GL_CONTEXT_KHR, gl_platform.GetCurrentContext()))
        props.append((ctx_props.GLX_DISPLAY_KHR, GLX.glXGetCurrentDisplay()))
    elif sys.platform == "win32":
        from OpenGL import WGL
        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 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.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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.º 9
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)
    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.º 11
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
 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 as err:
             failures.append((item,err))
         else:
             print '%20s\t%r'%( item[0], result.value)
     if failures:
         print 'FAILURES'
         for ((name,value),err) in failures:
             print name, value, '->' as err
     items = [ getattr(module,name) for name in names ]
     try:
         method(
             hdc,
             WGL.GetPixelFormat(hdc),
             0,
             1,
             WGL.INT32(item[1]),
             result
         )
     except WindowsError as err:
         print method, 'failed on getting full set'
     else:
         print method, result
Ejemplo n.º 13
0
    def BuildFont(self):

        wgldc = WGL.wglGetCurrentDC()
        hDC = win32ui.CreateDCFromHandle(wgldc)

        self.base = glGenLists(32 + 96)
        # // Storage For 96 Characters, plus 32 at the start...

        # CreateFont () takes a python dictionary to specify the requested font properties.
        font_properties = {
            "name": "Courier New",
            "width": 0,
            "height": -24,
            "weight": 800
        }
        font = win32ui.CreateFont(font_properties)
        # // Selects The Font We Want
        oldfont = hDC.SelectObject(font)
        # // Builds 96 Characters Starting At Character 32
        WGL.wglUseFontBitmaps(wgldc, 32, 96, self.base + 32)
        # // reset the font
        hDC.SelectObject(oldfont)