Beispiel #1
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)
 def make_current(self):
     from OpenGL.EGL import eglMakeCurrent, EGL_NO_SURFACE
     assert eglMakeCurrent(self._egl_display, EGL_NO_SURFACE,
                           EGL_NO_SURFACE, self._egl_context)