def __init__(self, *args, **kwargs): BaseCanvasBackend.__init__(self, *args) p = self._process_backend_kwargs(kwargs) self._initialized = False # Deal with config _set_config(p.context.config) # Deal with context p.context.shared.add_ref('sdl2', self) if p.context.shared.ref is self: share = None else: other = p.context.shared.ref share = other._id.window, other._native_context sdl2.SDL_GL_MakeCurrent(*share) sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1) sdl2.SDL_GL_SetSwapInterval(1 if p.vsync else 0) flags = sdl2.SDL_WINDOW_OPENGL flags |= sdl2.SDL_WINDOW_SHOWN # start out shown flags |= sdl2.SDL_WINDOW_ALLOW_HIGHDPI flags |= sdl2.SDL_WINDOW_RESIZABLE if p.resizable else 0 flags |= sdl2.SDL_WINDOW_BORDERLESS if not p.decorate else 0 if p.fullscreen is not False: self._fullscreen = True if p.fullscreen is not True: logger.warning('Cannot specify monitor number for SDL2 ' 'fullscreen, using default') flags |= sdl2.SDL_WINDOW_FULLSCREEN_DESKTOP else: self._fullscreen = False self._mods = list() if p.position is None: position = [sdl2.SDL_WINDOWPOS_UNDEFINED] * 2 else: position = None self._id = sdl2.ext.Window(p.title, p.size, position, flags) if not self._id.window: raise RuntimeError('Could not create window') if share is None: self._native_context = sdl2.SDL_GL_CreateContext(self._id.window) else: self._native_context = sdl2.SDL_GL_CreateContext(share[0]) self._sdl_id = sdl2.SDL_GetWindowID(self._id.window) _VP_SDL2_ALL_WINDOWS[self._sdl_id] = self # Init self._initialized = True self._needs_draw = False self._vispy_canvas.set_current() self._vispy_canvas.events.initialize() if not p.show: self._vispy_set_visible(False)
def __init__(self, *args, **kwargs): BaseCanvasBackend.__init__(self, *args) title, size, position, show, vsync, resize, dec, fs, parent, context, \ = self._process_backend_kwargs(kwargs) self._initialized = False # Deal with context if not context.istaken: context.take('sdl2', self) _set_config(context.config) share = None elif context.istaken == 'sdl2': other = context.backend_canvas share = other._id.window, other._native_context sdl2.SDL_GL_MakeCurrent(*share) sdl2.SDL_GL_SetAttribute(sdl2.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1) else: raise RuntimeError('Different backends cannot share a context.') sdl2.SDL_GL_SetSwapInterval(1 if vsync else 0) flags = sdl2.SDL_WINDOW_OPENGL flags |= sdl2.SDL_WINDOW_SHOWN # start out shown flags |= sdl2.SDL_WINDOW_ALLOW_HIGHDPI flags |= sdl2.SDL_WINDOW_RESIZABLE if resize else 0 flags |= sdl2.SDL_WINDOW_BORDERLESS if not dec else 0 if fs is not False: self._fullscreen = True if fs is not True: logger.warning('Cannot specify monitor number for SDL2 ' 'fullscreen, using default') flags |= sdl2.SDL_WINDOW_FULLSCREEN_DESKTOP else: self._fullscreen = False self._mods = list() if position is None: position = [sdl2.SDL_WINDOWPOS_UNDEFINED] * 2 self._id = sdl2.ext.Window(title, size, position, flags) if not self._id.window: raise RuntimeError('Could not create window') if share is None: self._native_context = sdl2.SDL_GL_CreateContext(self._id.window) else: self._native_context = sdl2.SDL_GL_CreateContext(share[0]) self._sdl_id = sdl2.SDL_GetWindowID(self._id.window) _VP_SDL2_ALL_WINDOWS[self._sdl_id] = self # Init self._initialized = True self._needs_draw = False self._vispy_set_current() self._vispy_canvas.events.initialize() if not show: self._vispy_set_visible(False)
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))
def _vispy_set_current(self): if self._id is None: return # Make this the current context self._vispy_canvas.set_current() # Mark as current sdl2.SDL_GL_MakeCurrent(self._id.window, self._native_context)
def activate(self): sdl2.SDL_GL_MakeCurrent(self._native_window, self._native_context)