示例#1
0
    def detach(self):
        if not self.canvas:
            return

        self.set_current()
        gl.glFlush()  # needs to be in try/except?

        super(HeadlessContext, self).detach()

        egl.eglMakeCurrent(self.display_connection, 0, 0, None)
        self.egl_surface = None
示例#2
0
 def set_current(self):
     egl.eglMakeCurrent(self.display_connection, self.egl_surface,
                        self.egl_surface, self.egl_context)
     super(HeadlessContext, self).set_current()
示例#3
0
                                         pbuffer_attrib_array)
print("Surface id: ", surface)

# Bind the API:
result = libegl.eglBindAPI(libegl.EGL_OPENGL_API)
assert result == 1, "Failed to bind EGL_OPENGL_API"

# Create a context:
context_attribs = (EGL_CONTEXT_MAJOR_VERSION, 2, EGL_NONE)
context_attrib_array = (libegl.EGLint * len(context_attribs))(*context_attribs)
context = libegl.eglCreateContext(display_connection, egl_config, None,
                                  context_attrib_array)
print("Context id: ", context)

# Make context current:
result = libegl.eglMakeCurrent(display_connection, surface, surface, context)
assert result == 1, "Failed to make context current"

error_code = libegl.eglGetError()
assert error_code == EGL_SUCCESS, "EGL Error code {} returned".format(
    error_code)

# Print some context details:
buffer_type = libegl.EGLint()
libegl.eglQueryContext(display_connection, context, EGL_RENDER_BUFFER,
                       buffer_type)
print("Buffer type: ", _buffer_types.get(buffer_type.value, "Unknown"))
print("API type: ", _api_types.get(libegl.eglQueryAPI(), "Unknown"))

# Terminate EGL:
libegl.eglTerminate(display_connection)