Context manager that makes this Renderer's OpenGL context current. Yields: An object that exposes a `call` method that can be used to call a function on the dedicated rendering thread. Raises: RuntimeError: If this context is already current on another thread.
(self)
| 121 | |
| 122 | @contextlib.contextmanager |
| 123 | def make_current(self): |
| 124 | """Context manager that makes this Renderer's OpenGL context current. |
| 125 | |
| 126 | Yields: |
| 127 | An object that exposes a `call` method that can be used to call a |
| 128 | function on the dedicated rendering thread. |
| 129 | |
| 130 | Raises: |
| 131 | RuntimeError: If this context is already current on another thread. |
| 132 | """ |
| 133 | |
| 134 | with self._render_executor.execution_context() as ctx: |
| 135 | if _CURRENT_CONTEXT_FOR_THREAD[self._render_executor.thread] != id(self): |
| 136 | if _CURRENT_THREAD_FOR_CONTEXT[id(self)]: |
| 137 | raise RuntimeError( |
| 138 | 'Cannot make context {!r} current on thread {!r}: ' |
| 139 | 'this context is already current on another thread {!r}.' |
| 140 | .format(self, self._render_executor.thread, |
| 141 | _CURRENT_THREAD_FOR_CONTEXT[id(self)])) |
| 142 | else: |
| 143 | current_context = ( |
| 144 | _CURRENT_CONTEXT_FOR_THREAD[self._render_executor.thread]) |
| 145 | if current_context: |
| 146 | del _CURRENT_THREAD_FOR_CONTEXT[current_context] |
| 147 | _CURRENT_THREAD_FOR_CONTEXT[id(self)] = self._render_executor.thread |
| 148 | _CURRENT_CONTEXT_FOR_THREAD[self._render_executor.thread] = id(self) |
| 149 | ctx.call(self._platform_make_current) |
| 150 | yield ctx |
| 151 | |
| 152 | def to_pixels(self, buffer): |
| 153 | """Converts the buffer to pixels.""" |