コード例 #1
0
ファイル: tools.py プロジェクト: inducer/pyopencl
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, GLX.glXGetCurrentContext()))
        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
コード例 #2
0
 def __exit__(self, *_args):
     self.valid = False
     if self.context:
         context_type = type(self.context)
         null_context = cast(0, context_type)
         log("glXMakeCurrent: NULL for xid=%#x", self.xid)
         GLX.glXMakeCurrent(self.xdisplay, 0, null_context)
コード例 #3
0
def get_gl_sharing_context_properties():
    import pyopencl as cl

    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, GLX.glXGetCurrentContext()))
        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
コード例 #4
0
 def __init__(self, wid):
     """Constructor for OpenGLRenderingArea"""
     xlib = cdll.LoadLibrary('libX11.so')
     xlib.XOpenDisplay.argtypes = [c_char_p]
     xlib.XOpenDisplay.restype = POINTER(struct__XDisplay)
     self.xdisplay = xlib.XOpenDisplay((ctypes.c_char * 1)(*[0]))
     display = Display()
     attrs = [
         GLX.GLX_RGBA, True,
         GLX.GLX_RED_SIZE, 1,
         GLX.GLX_GREEN_SIZE, 1,
         GLX.GLX_BLUE_SIZE, 1,
         GLX.GLX_DOUBLEBUFFER, 0,
         0, 0
     ]
     width = 200
     height = 200
     cattrs = (c_int * len(attrs))(*attrs)
     xvinfo = GLX.glXChooseVisual(self.xdisplay, display.get_default_screen(), cattrs)
     configs = GLX.glXChooseFBConfig(self.xdisplay, 0, None, byref(c_int()))
     self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True)
     self.x_window_id = GdkX11.X11Window.get_xid(wid)
     if not GLX.glXMakeCurrent(self.xdisplay, self.x_window_id, self.context):
         print("failed")
     GL.glViewport(0, 0, width, height)  # todo
     self.app = None
     GL.glClearColor(0.24, 0.24, 0.24, 0.0)
     self.profiler_window = None
コード例 #5
0
ファイル: gl_interop_demo.py プロジェクト: initcrash/pyopencl
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()
コード例 #6
0
ファイル: Main.py プロジェクト: favilo/4space-nbody
    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()
コード例 #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()
コード例 #8
0
ファイル: gremlin.py プロジェクト: zym1rm/linuxcnc
 def reshape(self, widget, event):
     self.width = event.width
     self.height = event.height
     self.xwindow_id = GdkX11.X11Window.get_xid(widget.get_window())
     if(not GLX.glXMakeCurrent(self.xdisplay, self.xwindow_id, self.context)):
         print('failed binding opengl context')
     glViewport(0, 0, self.width, self.height)
コード例 #9
0
 def set_size(self, width, height):
     """Change size of rendering area
     :param height:
     :param width:
     """
     if not GLX.glXMakeCurrent(self.xdisplay, self.x_window_id, self.context):
         print("failed")
     GL.glViewport(0, 0, width, height)  # todo
コード例 #10
0
ファイル: gl_context.py プロジェクト: chewi/xpra
 def __exit__(self, *_args):
     self.valid = False
     if self.context:
         context_type = type(self.context)
         null_context = cast(0, context_type)
         log("glXMakeCurrent: NULL for xid=%#x", self.xid)
         if not GLX.glXMakeCurrent(self.xdisplay, 0, null_context):
             log.error("Error: glXMakeCurrent NULL failed")
コード例 #11
0
ファイル: gremlin.py プロジェクト: zym1rm/linuxcnc
    def activate(self):
        """make cairo context current for drawing"""
        if(not GLX.glXMakeCurrent(self.xdisplay, self.xwindow_id, self.context)):
            print("failed binding opengl context")
        #glcontext = gtk.gtkgl.widget_get_gl_context(self)
        #gldrawable = gtk.gtkgl.widget_get_gl_drawable(self)

        #return gldrawable and glcontext and gldrawable.gl_begin(glcontext)
        return True
コード例 #12
0
    def _async_init(self):
        # Create an SDL2 window
        sdl2.ext.init()
        if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
            raise RuntimeError(sdl2.SDL_GetError())
        self._window = sdl2.SDL_CreateWindow(
            self._window_title.encode(),
            sdl2.SDL_WINDOWPOS_UNDEFINED,
            sdl2.SDL_WINDOWPOS_UNDEFINED,
            self.width,
            self.height,
            sdl2.SDL_WINDOW_OPENGL
            | sdl2.SDL_WINDOW_RESIZABLE
            | sdl2.SDL_WINDOW_UTILITY,
        )

        # Create an OpenGL context
        sdl2.video.SDL_GL_SetAttribute(sdl2.video.SDL_GL_CONTEXT_MAJOR_VERSION,
                                       self.OPENGL_VERSION[0])
        sdl2.video.SDL_GL_SetAttribute(sdl2.video.SDL_GL_CONTEXT_MINOR_VERSION,
                                       self.OPENGL_VERSION[1])
        sdl2.video.SDL_GL_SetAttribute(
            sdl2.video.SDL_GL_CONTEXT_PROFILE_MASK,
            sdl2.video.SDL_GL_CONTEXT_PROFILE_CORE,
        )
        self._glcontext = sdl2.SDL_GL_CreateContext(self._window)
        sdl2.SDL_GL_MakeCurrent(self._window, self._glcontext)

        # Activate vertical synchronization
        sdl2.SDL_GL_SetSwapInterval(1)

        # Set the GLX context
        GLX.glXMakeCurrent(self.x11display, self.x11window, self.glx_context)

        # Call subclass custom initialization
        self.init(**self._init_kwds)

        # Start rendering
        sdl2.SDL_ShowWindow(self._window)
        self._timer = self._loop.create_timer(self._on_update)
        self._loop.set_timer(self._timer, 1, int(1000.0 / 60.0))
コード例 #13
0
 def render(self):
     """Must be called each frame"""
     if not GLX.glXMakeCurrent(self.xdisplay, self.x_window_id, self.context):
         print("failed")
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     #todo
     GL.glBegin(GL.GL_TRIANGLES)
     GL.glIndexi(0)
     GL.glColor3f(1.0, 0.0, 0.0)
     GL.glVertex2i(0, 1)
     GL.glIndexi(0)
     GL.glColor3f(0.0, 1.0, 0.0)
     GL.glVertex2i(-1, -1)
     GL.glIndexi(0)
     GL.glColor3f(0.0, 0.0, 1.0)
     GL.glVertex2i(1, -1)
     GL.glEnd()
     self.app.render_loop()
     GLX.glXSwapBuffers(self.xdisplay, self.x_window_id)
     self.profiler_window.one_frame_passed()
     return True
コード例 #14
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
コード例 #15
0
ファイル: raycl.py プロジェクト: deepbound/fishpye
    def clinit(self):
        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()))

        self.ctx = cl.Context(properties=props)
        self.queue = cl.CommandQueue(self.ctx)
コード例 #16
0
ファイル: raycl.py プロジェクト: albertmena/fishpye
    def clinit(self):
        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()))
        
        self.ctx = cl.Context(properties=props)
        self.queue = cl.CommandQueue(self.ctx)
コード例 #17
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
コード例 #18
0
ファイル: gl_context.py プロジェクト: rudresh2319/Xpra
 def __enter__(self):
     if not GLX.glXMakeCurrent(self.xdisplay, self.xid, self.context):
         raise Exception("glXMakeCurrent failed")
     self.valid = True
コード例 #19
0
ファイル: interop.py プロジェクト: tejeswinisundaram/pycl
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from OpenGL import platform as gl_platform
from OpenGL import GLX

from pycl import *
import numpy as np

glutInit()
gl_window = glutCreateWindow("window")
gl_ctx = gl_platform.GetCurrentContext()
glx_display = GLX.glXGetCurrentDisplay()

cl_ctx_props = {
    CL_GL_CONTEXT_KHR:  gl_ctx,
    CL_GLX_DISPLAY_KHR: glx_display,
}
cl_ctx = clCreateContext(other_props=cl_ctx_props)
cl_queue = clCreateCommandQueue(cl_ctx)

def idle():
    input_data = np.arange(20, dtype=np.float32)

    gl_buf = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, gl_buf)
    glBufferData(GL_ARRAY_BUFFER, input_data, GL_STATIC_DRAW)
    glFinish()

    cl_buf = clCreateFromGLBuffer(cl_ctx, gl_buf)
    clEnqueueAcquireGLObjects(cl_queue, [cl_buf])
コード例 #20
0
 def tkSwapBuffers(self):
     if self.winfo_ismapped():
         GLX.glXSwapBuffers(self.__window, self._wid)
コード例 #21
0
 def tkMakeCurrent(self):
     if self.winfo_ismapped():
         GLX.glXMakeCurrent(self.__window, self._wid, self.__context)
コード例 #22
0
        def tkCreateContext(self):
            self.__window = XOpenDisplay(self.winfo_screen().encode('utf-8'))
            # Check glx version:
            major = c_int(0)
            minor = c_int(0)
            GLX.glXQueryVersion(self.__window, major, minor)
            print("GLX version: %d.%d" % (major.value, minor.value))
            if major.value == 1 and minor.value < 3:  # e.g. 1.2 and down
                visual = GLX.glXChooseVisual(self.__window, 0,
                                             (GL.GLint * len(att))(*att))
                if not visual:
                    _log.error("glXChooseVisual call failed")
                self.__context = GLX.glXCreateContext(self.__window, visual,
                                                      None, GL.GL_TRUE)
                GLX.glXMakeCurrent(self.__window, self._wid, self.__context)
                return  # OUT HERE FOR 1.2 and less
            else:
                # 1.3 or higher
                # which screen - should it be winfo_screen instead ??
                XDefaultScreen = _x11lib.XDefaultScreen
                XDefaultScreen.argtypes = [POINTER(Display)]
                XDefaultScreen.restype = c_int
                screen = XDefaultScreen(self.__window)
                print("Screen is ", screen)
                # Look at framebuffer configs
                ncfg = GL.GLint(0)
                cfgs = GLX.glXChooseFBConfig(self.__window, screen,
                                             (GL.GLint * len(fbatt))(*fbatt),
                                             ncfg)
                print("Number of FBconfigs", ncfg.value)
                #
                # Try to match to the current window
                # ... might also be possible to set this for the frame
                # ... but for now we just take what Tk gave us
                ideal = int(self.winfo_visualid(), 16)  # convert from hex
                best = -1
                for i in range(ncfg.value):
                    vis = GLX.glXGetVisualFromFBConfig(self.__window, cfgs[i])
                    if ideal == vis.contents.visualid:
                        best = i
                        print("Got a matching visual: index %d %d xid %s" %
                              (best, vis.contents.visualid, hex(ideal)))
                if best < 0:
                    print("oh dear - visual does not match")
                    # Take the first in the list (should be another I guess)
                    best = 0
                # Here we insist on RGBA - but didn't check earlier
                self.__context = GLX.glXCreateNewContext(
                    self.__window,
                    cfgs[best],
                    GLX.GLX_RGBA_TYPE,
                    None,  # share list
                    GL.GL_TRUE)  # direct
                print("Is Direct?: ",
                      GLX.glXIsDirect(self.__window, self.__context))
                # Not creating another window ... some tutorials do
                #                print("wid: ",self._wid)
                #                self._wid = GLX.glXCreateWindow( self.__window, cfgs[best], self._wid, None)
                #                print("wid: ",self._wid)
                GLX.glXMakeContextCurrent(self.__window, self._wid, self._wid,
                                          self.__context)
                print("Done making a first context")
                extensions = GLX.glXQueryExtensionsString(
                    self.__window, screen)
                # Here we quit - getting a modern context needs further work below
                return
                if "GLX_ARB_create_context" in extensions:
                    # We can try to upgrade it ??
                    print("Trying to upgrade context")
                    s = "glXCreateContextAttribsARB"
                    p = GLX.glXGetProcAddress(c_char_p(s))

                    print(p)
                    if not p:
                        p = GLX.glXGetProcAddressARB(
                            (GL.GLubyte * len(s)).from_buffer_copy(s))
                    print(p)
                    if p:
                        print(" p is true")
                    p.restype = GLX.GLXContext
                    p.argtypes = [
                        POINTER(Display), GLX.GLXFBConfig, GLX.GLXContext,
                        c_bool,
                        POINTER(c_int)
                    ]
                    arb_attrs = fbatt[:-1] + []

                    #    GLX.GLX_CONTEXT_MAJOR_VERSION_ARB , 3
                    #    GLX.GLX_CONTEXT_MINOR_VERSION_ARB , 1,
                    #    0 ]
                    #
                    #    GLX.GLX_CONTEXT_FLAGS_ARB
                    #    GLX.GLX_CONTEXT_PROFILE_MASK_ARB
                    #]
                    #                    import pdb
                    #                    pdb.set_trace()
                    self.__context = p(self.__window, cfgs[best], None,
                                       GL.GL_TRUE,
                                       (GL.GLint * len(arb_attrs))(*arb_attrs))
コード例 #23
0
ファイル: gremlin.py プロジェクト: zym1rm/linuxcnc
    def __init__(self, inifile):
    
        self.xwindow_id = None

        #self.set_has_alpha(True)
        #'set_has_stencil_buffer',
        glutInit()
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH )


        self.add_attribute(GLX.GLX_RGBA, True)
        self.add_attribute(GLX.GLX_RED_SIZE, 1)
        self.add_attribute(GLX.GLX_GREEN_SIZE, 1)
        self.add_attribute(GLX.GLX_BLUE_SIZE, 1)
        self.add_attribute(GLX.GLX_DOUBLEBUFFER, 1)

        xvinfo = GLX.glXChooseVisual(self.xdisplay, self.display.get_default_screen(), self.get_attributes())
        configs = GLX.glXChooseFBConfig(self.xdisplay, 0, None, byref(c_int()))
        self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True)


#class Gremlin(gtk.gtkgl.widget.DrawingArea, glnav.GlNavBase,
#              rs274.glcanon.GlCanonDraw):
#    rotation_vectors = [(1.,0.,0.), (0., 0., 1.)]

#    def __init__(self, inifile):
#
#        display_mode = ( gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH |
#                         gtk.gdkgl.MODE_DOUBLE )
#        glconfig = gtk.gdkgl.Config(mode=display_mode)

#        gtk.gtkgl.widget.DrawingArea.__init__(self, glconfig)
        glnav.GlNavBase.__init__(self)
        def C(s):
            a = self.colors[s + "_alpha"]
            s = self.colors[s]
            return [int(x * 255) for x in s + (a,)]
        self.inifile = inifile
        self.logger = linuxcnc.positionlogger(linuxcnc.stat(),
            C('backplotjog'),
            C('backplottraverse'),
            C('backplotfeed'),
            C('backplotarc'),
            C('backplottoolchange'),
            C('backplotprobing'),
            self.get_geometry()
        )
        _thread.start_new_thread(self.logger.start, (.01,))

        rs274.glcanon.GlCanonDraw.__init__(self, linuxcnc.stat(), self.logger)

        self.current_view = 'z'

        self.select_primed = None

        self.connect_after('realize', self.realize)
        self.connect('configure_event', self.reshape)
        self.connect('map_event', self.map)
        self.connect('draw', self.expose) # expose_event was deprecated
        self.connect('motion-notify-event', self.motion)
        self.connect('button-press-event', self.pressed)
        self.connect('button-release-event', self.select_fire)
        self.connect('scroll-event', self.scroll)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
        self.add_events(Gdk.EventMask.POINTER_MOTION_HINT_MASK)
        #self.add_events(gdk.BUTTON_MOTION_MASK)
        #self.add_events(gdk.EventMask.BUTTON_PRESS_MASK)
        #self.add_events(gdk.BUTTON_RELEASE_MASK)
        self.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
        self.add_events(Gdk.EventMask.SCROLL_MASK)
 

        self.fingerprint = ()

        self.lat = 0
        self.minlat = -90
        self.maxlat = 90

        self.highlight_line = None
        self.program_alpha = False
        self.use_joints_mode = False
        self.use_commanded = True
        self.show_limits = True
        self.show_extents_option = True
        self.show_live_plot = True
        self.show_velocity = True
        self.metric_units = True
        self.show_program = True
        self.show_rapids = True
        self.use_relative = True
        self.show_tool = True
        self.show_dtg = True
        self.grid_size = 0.0
        temp = inifile.find("DISPLAY", "LATHE")
        self.lathe_option = bool(temp == "1" or temp == "True" or temp == "true" )
        self.foam_option = bool(inifile.find("DISPLAY", "FOAM"))
        self.show_offsets = False
        self.use_default_controls = True
        self.mouse_btn_mode = 0

        self.a_axis_wrapped = inifile.find("AXIS_A", "WRAPPED_ROTARY")
        self.b_axis_wrapped = inifile.find("AXIS_B", "WRAPPED_ROTARY")
        self.c_axis_wrapped = inifile.find("AXIS_C", "WRAPPED_ROTARY")

        live_axis_count = 0
        for i,j in enumerate("XYZABCUVW"):
            if self.stat.axis_mask & (1<<i) == 0: continue
            live_axis_count += 1
        self.num_joints = int(inifile.find("KINS", "JOINTS") or live_axis_count)
        glDrawBuffer(GL_BACK)
        glDisable(GL_CULL_FACE)
        glLineStipple(2, 0x5555)
        glDisable(GL_LIGHTING)
        glClearColor(0,0,0,0)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
コード例 #24
0
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from OpenGL import platform as gl_platform
from OpenGL import GLX

from pycl import *
import numpy as np

glutInit()
gl_window = glutCreateWindow("window")
gl_ctx = gl_platform.GetCurrentContext()
glx_display = GLX.glXGetCurrentDisplay()

cl_ctx_props = {
    CL_GL_CONTEXT_KHR: gl_ctx,
    CL_GLX_DISPLAY_KHR: glx_display,
}
cl_ctx = clCreateContext(other_props=cl_ctx_props)
cl_queue = clCreateCommandQueue(cl_ctx)


def idle():
    input_data = np.arange(20, dtype=np.float32)

    gl_buf = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, gl_buf)
    glBufferData(GL_ARRAY_BUFFER, input_data, GL_STATIC_DRAW)
    glFinish()

    cl_buf = clCreateFromGLBuffer(cl_ctx, gl_buf)
コード例 #25
0
ファイル: gl_context.py プロジェクト: rudresh2319/Xpra
 def __exit__(self, *_args):
     self.valid = False
     if self.context:
         context_type = type(self.context)
         null_context = cast(0, context_type)
         GLX.glXMakeCurrent(self.xdisplay, 0, null_context)
コード例 #26
0
 def __enter__(self):
     log("glXMakeCurrent: xid=%#x, context=%s", self.xid, self.context)
     with xsync:
         if not GLX.glXMakeCurrent(self.xdisplay, self.xid, self.context):
             raise Exception("glXMakeCurrent failed")
     self.valid = True
コード例 #27
0
 def destroy(self):
     c = self.context
     if c:
         self.context = None
         GLX.glXDestroyContext(self.xdisplay, c)
コード例 #28
0
 def getconfig(attrib):
     value = c_int()
     r = GLX.glXGetConfig(self.xdisplay, xvinfo, attrib, byref(value))
     assert r == 0, "glXGetConfig returned %i" % r
     return value.value
コード例 #29
0
def get_process_address(name):
    address = GLX.glXGetProcAddress(name.decode("utf-8"))
    return ctypes.cast(address, ctypes.c_void_p).value
コード例 #30
0
ファイル: gl_context.py プロジェクト: rudresh2319/Xpra
    def __init__(self, alpha=False):
        display = display_get_default()
        screen = display.get_default_screen()
        bpc = 8
        attrs = c_attrs({
            GLX.GLX_RGBA: True,
            GLX.GLX_RED_SIZE: bpc,
            GLX.GLX_GREEN_SIZE: bpc,
            GLX.GLX_BLUE_SIZE: bpc,
            GLX.GLX_ALPHA_SIZE: int(alpha) * bpc,
            GLX.GLX_DOUBLEBUFFER: int(DOUBLE_BUFFERED),
        })
        self.props = {}
        self.xdisplay = get_xdisplay()
        xvinfo = GLX.glXChooseVisual(self.xdisplay, screen.get_number(), attrs)

        def getconfig(attrib):
            value = c_int()
            r = GLX.glXGetConfig(self.xdisplay, xvinfo, attrib, byref(value))
            assert r == 0, "glXGetConfig returned %i" % r
            return value.value

        assert getconfig(
            GLX.GLX_USE_GL), "OpenGL is not supported by this visual!"
        major = c_int()
        minor = c_int()
        assert GLX.glXQueryVersion(self.xdisplay, byref(major), byref(minor))
        log("found GLX version %i.%i", major.value, minor.value)
        self.props["GLX"] = (major.value, minor.value)
        self.bit_depth = getconfig(GLX.GLX_RED_SIZE) + getconfig(
            GLX.GLX_GREEN_SIZE) + getconfig(GLX.GLX_BLUE_SIZE) + getconfig(
                GLX.GLX_ALPHA_SIZE)
        self.props["depth"] = self.bit_depth
        self.props["has-depth-buffer"] = getconfig(GLX.GLX_DEPTH_SIZE) > 0
        self.props["has-stencil-buffer"] = getconfig(GLX.GLX_STENCIL_SIZE) > 0
        self.props["has-alpha"] = getconfig(GLX.GLX_ALPHA_SIZE) > 0
        for attrib, name in {
                GLX.GLX_ACCUM_RED_SIZE: "accum-red-size",
                GLX.GLX_ACCUM_GREEN_SIZE: "accum-green-size",
                GLX.GLX_ACCUM_BLUE_SIZE: "accum-blue-size",
                GLX.GLX_ACCUM_ALPHA_SIZE: "accum-alpha-size",
                GLX.GLX_RED_SIZE: "red-size",
                GLX.GLX_GREEN_SIZE: "green-size",
                GLX.GLX_BLUE_SIZE: "blue-size",
                GLX.GLX_ALPHA_SIZE: "alpha-size",
                GLX.GLX_DEPTH_SIZE: "depth-size",
                GLX.GLX_STENCIL_SIZE: "stencil-size",
                GLX.GLX_BUFFER_SIZE: "buffer-size",
                GLX.GLX_AUX_BUFFERS: "aux-buffers",
                GLX.GLX_DOUBLEBUFFER: "double-buffered",
                GLX.GLX_LEVEL: "level",
                GLX.GLX_STEREO: "stereo",
                GLX.GLX_RGBA: "rgba",
        }.items():
            v = getconfig(attrib)
            if name in ("stereo", "double-buffered", "rgba"):
                v = bool(v)
            self.props[name] = v
        #attribute names matching gtkgl:
        display_mode = []
        if getconfig(GLX.GLX_RGBA):
            #this particular context may not have alpha channel support...
            #but if we have RGBA then it's almost guaranteed that we can do ALPHA
            display_mode.append("ALPHA")
        if getconfig(GLX.GLX_DOUBLEBUFFER):
            display_mode.append("DOUBLE")
        else:
            display_mode.append("SINGLE")
        self.props["display_mode"] = display_mode
        self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True)
        self.props["direct"] = bool(
            GLX.glXIsDirect(self.xdisplay, self.context))
        self.props["vendor"] = glGetString(GL_VENDOR)
        self.props["renderer"] = glGetString(GL_RENDERER)
        log("GLXContext(%s) context=%s, props=%s", alpha, self.context,
            self.props)
コード例 #31
0
ファイル: gl_context.py プロジェクト: DiGuoZhiMeng/Xpra
    def __init__(self, alpha=False):
        display = display_get_default()
        screen = display.get_default_screen()
        bpc = 8
        attrs = c_attrs({
            GLX.GLX_RGBA: True,
            GLX.GLX_RED_SIZE: bpc,
            GLX.GLX_GREEN_SIZE: bpc,
            GLX.GLX_BLUE_SIZE: bpc,
            GLX.GLX_ALPHA_SIZE: int(alpha) * bpc,
            GLX.GLX_DOUBLEBUFFER: int(DOUBLE_BUFFERED),
        })
        self.props = {}
        self.xdisplay = get_xdisplay()
        xvinfo = GLX.glXChooseVisual(self.xdisplay, screen.get_number(), attrs)

        def getconfig(attrib):
            value = c_int()
            r = GLX.glXGetConfig(self.xdisplay, xvinfo, attrib, byref(value))
            assert r == 0, "glXGetConfig returned %i" % r
            return value.value

        assert getconfig(
            GLX.GLX_USE_GL), "OpenGL is not supported by this visual!"
        major = c_int()
        minor = c_int()
        assert GLX.glXQueryVersion(self.xdisplay, byref(major), byref(minor))
        log("found GLX version %i.%i", major.value, minor.value)
        self.props["GLX"] = (major.value, minor.value)
        self.bit_depth = sum(
            getconfig(x) for x in (GLX.GLX_RED_SIZE, GLX.GLX_GREEN_SIZE,
                                   GLX.GLX_BLUE_SIZE, GLX.GLX_ALPHA_SIZE))
        self.props["depth"] = self.bit_depth
        self.props["has-depth-buffer"] = getconfig(GLX.GLX_DEPTH_SIZE) > 0
        self.props["has-stencil-buffer"] = getconfig(GLX.GLX_STENCIL_SIZE) > 0
        self.props["has-alpha"] = getconfig(GLX.GLX_ALPHA_SIZE) > 0
        for attrib, name in GLX_ATTRIBUTES.items():
            v = getconfig(attrib)
            if name in ("stereo", "double-buffered", "rgba"):
                v = bool(v)
            self.props[name] = v
        #attribute names matching gtkgl:
        display_mode = []
        if getconfig(GLX.GLX_RGBA):
            #this particular context may not have alpha channel support...
            #but if we have RGBA then it's almost guaranteed that we can do ALPHA
            display_mode.append("ALPHA")
        if getconfig(GLX.GLX_DOUBLEBUFFER):
            display_mode.append("DOUBLE")
        else:
            display_mode.append("SINGLE")
        self.props["display_mode"] = display_mode
        self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True)
        self.props["direct"] = bool(
            GLX.glXIsDirect(self.xdisplay, self.context))

        def getstr(k):
            try:
                return glGetString(k)
            except Exception as e:
                self.props["safe"] = False
                result = getattr(e, "result", None)
                if result and isinstance(result, str):
                    return result
                raise

        self.props["vendor"] = getstr(GL_VENDOR)
        self.props["renderer"] = getstr(GL_RENDERER)
        log("GLXContext(%s) context=%s, props=%s", alpha, self.context,
            self.props)
コード例 #32
0
 def swap_buffers(self):
     assert self.valid, "GLX window context is no longer valid"
     GLX.glXSwapBuffers(self.xdisplay, self.xid)
コード例 #33
0
    def __init__(self, alpha=False):
        self.props = {}
        self.xdisplay = None
        self.context = None
        self.bit_depth = 0
        from gi.repository import Gdk
        display = Gdk.Display.get_default()
        if not display:
            log.warn("Warning: GLXContext: no default display")
            return
        screen = display.get_default_screen()
        bpc = 8
        pyattrs = {
            GLX.GLX_RGBA: None,
            GLX.GLX_RED_SIZE: bpc,
            GLX.GLX_GREEN_SIZE: bpc,
            GLX.GLX_BLUE_SIZE: bpc,
        }
        if alpha:
            pyattrs[GLX.GLX_ALPHA_SIZE] = int(alpha) * bpc
        if DOUBLE_BUFFERED:
            pyattrs[GLX.GLX_DOUBLEBUFFER] = None
        attrs = c_attrs(pyattrs)
        self.xdisplay = get_xdisplay()
        xvinfo = GLX.glXChooseVisual(self.xdisplay, screen.get_number(), attrs)

        def getconfig(attrib):
            value = c_int()
            r = GLX.glXGetConfig(self.xdisplay, xvinfo, attrib, byref(value))
            assert r == 0, "glXGetConfig returned %i" % r
            return value.value

        assert getconfig(
            GLX.GLX_USE_GL), "OpenGL is not supported by this visual!"
        major = c_int()
        minor = c_int()
        assert GLX.glXQueryVersion(self.xdisplay, byref(major), byref(minor))
        log("found GLX version %i.%i", major.value, minor.value)
        self.props["GLX"] = (major.value, minor.value)
        self.bit_depth = sum(
            getconfig(x) for x in (GLX.GLX_RED_SIZE, GLX.GLX_GREEN_SIZE,
                                   GLX.GLX_BLUE_SIZE, GLX.GLX_ALPHA_SIZE))
        self.props["depth"] = self.bit_depth
        #hide those because we don't use them
        #and because they're misleading: 'has-alpha' may be False
        #even when we have RGBA support (and therefore very likely to have alpha..)
        #self.props["has-depth-buffer"] = getconfig(GLX.GLX_DEPTH_SIZE)>0
        #self.props["has-stencil-buffer"] = getconfig(GLX.GLX_STENCIL_SIZE)>0
        #self.props["has-alpha"] = getconfig(GLX.GLX_ALPHA_SIZE)>0
        for attrib, name in GLX_ATTRIBUTES.items():
            v = getconfig(attrib)
            if name in ("stereo", "double-buffered", "rgba"):
                v = bool(v)
            self.props[name] = v
        #attribute names matching gtkgl:
        display_mode = []
        if getconfig(GLX.GLX_RGBA):
            #this particular context may not have alpha channel support...
            #but if we have RGBA then it's almost guaranteed that we can do ALPHA
            display_mode.append("ALPHA")
        if getconfig(GLX.GLX_DOUBLEBUFFER):
            display_mode.append("DOUBLE")
        else:  # pragma: no cover
            display_mode.append("SINGLE")
        self.props["display_mode"] = display_mode
        self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True)
        self.props["direct"] = bool(
            GLX.glXIsDirect(self.xdisplay, self.context))

        def getstr(k):
            try:
                return glGetString(k)
            except Exception as e:  # pragma: no cover
                self.props["safe"] = False
                result = getattr(e, "result", None)
                if result and isinstance(result, str):
                    return result
                raise

        self.props["vendor"] = getstr(GL_VENDOR)
        self.props["renderer"] = getstr(GL_RENDERER)
        log("GLXContext(%s) context=%s, props=%s", alpha, self.context,
            self.props)
コード例 #34
0
ファイル: gl_context.py プロジェクト: DiGuoZhiMeng/Xpra
 def swap_buffers(self):
     assert self.valid
     GLX.glXSwapBuffers(self.xdisplay, self.xid)
コード例 #35
0
ファイル: gremlin.py プロジェクト: zym1rm/linuxcnc
 def swapbuffers(self):
     GLX.glXSwapBuffers(self.xdisplay, self.xwindow_id)
     #gldrawable = gtk.gtkgl.widget_get_gl_drawable(self)
     #gldrawable.swap_buffers()
     return