Пример #1
0
 def getDisplay(self):
     """Retrieve the currently-bound, or the default, display"""
     from OpenGL.EGL import (
         eglGetCurrentDisplay,
         eglGetDisplay,
         EGL_DEFAULT_DISPLAY,
     )
     return eglGetCurrentDisplay() or eglGetDisplay(EGL_DEFAULT_DISPLAY)
Пример #2
0
    def _init_egl(self):
        from OpenGL.EGL import EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE,    \
                               EGL_RED_SIZE, EGL_GREEN_SIZE, EGL_DEPTH_SIZE,        \
                               EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, EGL_HEIGHT,   \
                               EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_CONFORMANT, \
                               EGL_OPENGL_BIT, EGL_CONFIG_CAVEAT, EGL_NONE,         \
                               EGL_DEFAULT_DISPLAY, EGL_NO_CONTEXT, EGL_WIDTH,      \
                               EGL_OPENGL_API,                                      \
                               eglGetDisplay, eglInitialize, eglChooseConfig,       \
                               eglBindAPI, eglCreatePbufferSurface,                 \
                               eglCreateContext, eglMakeCurrent, EGLConfig

        self._egl_display = None
        self._egl_surface = None
        self._egl_context = None

        config_attributes = arrays.GLintArray.asArray([
            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE, 8, EGL_RED_SIZE,
            8, EGL_GREEN_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_COLOR_BUFFER_TYPE,
            EGL_RGB_BUFFER, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
            EGL_CONFORMANT, EGL_OPENGL_BIT, EGL_NONE
        ])
        major, minor = ctypes.c_long(), ctypes.c_long()
        num_configs = ctypes.c_long()
        configs = (EGLConfig * 1)()

        # Cache DISPLAY if necessary and get an off-screen EGL display
        orig_dpy = None
        if 'DISPLAY' in os.environ:
            orig_dpy = os.environ['DISPLAY']
            del os.environ['DISPLAY']
        self._egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY)
        if orig_dpy is not None:
            os.environ['DISPLAY'] = orig_dpy

        # Initialize EGL
        eglInitialize(self._egl_display, major, minor)
        eglChooseConfig(self._egl_display, config_attributes, configs, 1,
                        num_configs)

        # Bind EGL to the OpenGL API
        eglBindAPI(EGL_OPENGL_API)

        # Create an EGL pbuffer
        self._egl_surface = eglCreatePbufferSurface(
            self._egl_display, configs[0],
            [EGL_WIDTH, self._width, EGL_HEIGHT, self._height, EGL_NONE])

        # Create an EGL context
        self._egl_context = eglCreateContext(self._egl_display, configs[0],
                                             EGL_NO_CONTEXT, None)

        # Make the EGL context current
        eglMakeCurrent(self._egl_display, self._egl_surface, self._egl_surface,
                       self._egl_context)
Пример #3
0
    def init_context(self):
        from OpenGL.EGL import (
            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE, EGL_RED_SIZE,
            EGL_GREEN_SIZE, EGL_DEPTH_SIZE, EGL_COLOR_BUFFER_TYPE,
            EGL_RGB_BUFFER, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
            EGL_CONFORMANT, EGL_NONE, EGL_DEFAULT_DISPLAY, EGL_NO_CONTEXT,
            EGL_OPENGL_API, EGL_CONTEXT_MAJOR_VERSION,
            EGL_CONTEXT_MINOR_VERSION, EGL_CONTEXT_OPENGL_PROFILE_MASK,
            EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, eglGetDisplay, eglInitialize,
            eglChooseConfig, eglBindAPI, eglCreateContext, EGLConfig)
        from OpenGL import arrays

        config_attributes = arrays.GLintArray.asArray([
            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE, 8, EGL_RED_SIZE,
            8, EGL_GREEN_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_COLOR_BUFFER_TYPE,
            EGL_RGB_BUFFER, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
            EGL_CONFORMANT, EGL_OPENGL_BIT, EGL_NONE
        ])
        context_attributes = arrays.GLintArray.asArray([
            EGL_CONTEXT_MAJOR_VERSION, 4, EGL_CONTEXT_MINOR_VERSION, 1,
            EGL_CONTEXT_OPENGL_PROFILE_MASK,
            EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, EGL_NONE
        ])
        major, minor = ctypes.c_long(), ctypes.c_long()
        num_configs = ctypes.c_long()
        configs = (EGLConfig * 1)()

        # Cache DISPLAY if necessary and get an off-screen EGL display
        orig_dpy = None
        if 'DISPLAY' in os.environ:
            orig_dpy = os.environ['DISPLAY']
            del os.environ['DISPLAY']
        self._egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY)
        if orig_dpy is not None:
            os.environ['DISPLAY'] = orig_dpy

        # Initialize EGL
        print(self._egl_display, major, minor)
        assert eglInitialize(self._egl_display, major, minor)
        assert eglChooseConfig(self._egl_display, config_attributes, configs,
                               1, num_configs)

        # Bind EGL to the OpenGL API
        assert eglBindAPI(EGL_OPENGL_API)

        # Create an EGL context
        self._egl_context = eglCreateContext(self._egl_display, configs[0],
                                             EGL_NO_CONTEXT,
                                             context_attributes)

        # Make it current
        self.make_current()
Пример #4
0
    def __init__(self):
        config_attributes = arrays.GLintArray.asArray([
            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE, 8, EGL_RED_SIZE,
            8, EGL_GREEN_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_COLOR_BUFFER_TYPE,
            EGL_RGB_BUFFER, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
            EGL_CONFORMANT, EGL_OPENGL_BIT, EGL_NONE
        ])

        context_attributes = arrays.GLintArray.asArray([
            EGL_CONTEXT_MAJOR_VERSION, 4, EGL_CONTEXT_MINOR_VERSION, 1,
            EGL_CONTEXT_OPENGL_PROFILE_MASK,
            EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, EGL_NONE
        ])
        major, minor = ctypes.c_long(), ctypes.c_long()
        num_configs = ctypes.c_long()
        configs = (EGLConfig * 1)()

        # Cache DISPLAY if necessary and get an off-screen EGL display
        orig_dpy = None
        if 'DISPLAY' in os.environ:
            orig_dpy = os.environ['DISPLAY']
            del os.environ['DISPLAY']
        self._egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY)
        if orig_dpy is not None:
            os.environ['DISPLAY'] = orig_dpy

        # Initialize EGL
        assert eglInitialize(self._egl_display, major, minor)
        assert eglChooseConfig(self._egl_display, config_attributes,
                               pointer(configs), 1, pointer(num_configs))

        # Bind EGL to the OpenGL API
        assert eglBindAPI(EGL_OPENGL_API)

        # Create an EGL context
        self._egl_context = eglCreateContext(self._egl_display, configs[0],
                                             EGL_NO_CONTEXT,
                                             context_attributes)
        if self._egl_context == EGL_NO_CONTEXT:
            raise RuntimeError('Unable to create context')

        # Make it current
        self.make_current()

        if not glInitBindlessTextureNV():
            raise RuntimeError("Bindless Textures not supported")
        self.__display = self._egl_display
Пример #5
0
 def getDisplay( self ):
     """Retrieve the currently-bound, or the default, display"""
     from OpenGL.EGL import (
         eglGetCurrentDisplay, eglGetDisplay, EGL_DEFAULT_DISPLAY,
     )
     return eglGetCurrentDisplay() or eglGetDisplay(EGL_DEFAULT_DISPLAY)