| Total Complexity | 6 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| 1 | import sdl2 as sdl |
||
| 3 | class Context(object): |
||
| 4 | ''' An OpenGL rendering context ''' |
||
| 5 | def __init__(self, major, minor, msaa): |
||
| 6 | self.major = major |
||
| 7 | self.minor = minor |
||
| 8 | self.msaa = msaa |
||
| 9 | |||
| 10 | self.profile = sdl.SDL_GL_CONTEXT_PROFILE_CORE |
||
| 11 | |||
| 12 | self.context = None |
||
| 13 | self._window = None |
||
| 14 | |||
| 15 | sdl.SDL_GL_SetAttribute(sdl.SDL_GL_DOUBLEBUFFER, 1) |
||
| 16 | |||
| 17 | sdl.SDL_GL_SetAttribute(sdl.SDL_GL_CONTEXT_MAJOR_VERSION, self.major) |
||
| 18 | sdl.SDL_GL_SetAttribute(sdl.SDL_GL_CONTEXT_MINOR_VERSION, self.minor) |
||
| 19 | |||
| 20 | sdl.SDL_GL_SetAttribute(sdl.SDL_GL_CONTEXT_PROFILE_MASK, self.profile) |
||
| 21 | |||
| 22 | if self.msaa < 0: |
||
| 23 | sdl.SDL_GL_SetAttribute(sdl.SDL_GL_MULTISAMPLEBUFFERS, 1) |
||
| 24 | sdl.SDL_GL_SetAttribute(sdl.SDL_GL_MULTISAMPLESAMPLES, self.msaa) |
||
| 25 | |||
| 26 | def destroy(self): |
||
| 27 | ''' Destroy the rendering context ''' |
||
| 28 | sdl.SDL_GL_DeleteContext(self.context) |
||
| 29 | |||
| 30 | @property |
||
| 31 | def window(self): |
||
| 32 | return self._window |
||
| 33 | @window.setter |
||
| 34 | def window(self, window): |
||
| 35 | # this mainly exists because we need the sdl window object |
||
| 36 | # to be able to create a context |
||
| 37 | self._window = window |
||
| 38 | if self.context == None: |
||
| 39 | # Create context |
||
| 40 | self.context = sdl.SDL_GL_CreateContext(self._window.window) |
||
| 41 | |||
| 43 |