Completed
Push — master ( 6cf062...43f138 )
by Matthew
01:00
created

ed2d.platforms.Context.destroy()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
import sdl2 as sdl
2
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
42
__all__ = ['Context']
43