PageRenderTime 33ms CodeModel.GetById 23ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/GUI/Win32/GLContexts_arb.py

https://bitbucket.org/alsh/pygui-mirror
Python | 52 lines | 38 code | 6 blank | 8 comment | 9 complexity | e5fd35d3255369916236e6aa817778b3 MD5 | raw file
 1#------------------------------------------------------------------------------
 2#
 3#   PyGUI - GLContext - Win32
 4#
 5#------------------------------------------------------------------------------
 6
 7import OpenGL as gl
 8from OpenGL import WGL as wgl
 9import WGL
10from GGLContexts import GLContext as GGLContext
11
12class GLContext(GGLContext):
13    #  _win_context  WGL context
14    #  _win_dblbuf   Is double buffered
15    
16    def __init__(self, share_group, config, hdc, mode):
17        print "GLContext: mode =", mode ###
18        GGLContext.__init__(self, share_group)
19        shared_context = self._get_shared_context()
20        if shared_context:
21            share_ctx = shared_context._win_context
22        else:
23            share_ctx = None
24        ipf, act_attrs = config._win_supported_pixelformat(hdc, mode)
25        if ipf is None:
26            raise GLConfigError
27        #config._check_win_pixelattrs(act_attrs, mode)
28        print "GLContext: Setting pixel format", ipf, "for hdc", hdc ###
29        WGL.SetPixelFormat(hdc, ipfs)
30        ctx = wgl.wglCreateContext(hdc)
31        if share_ctx:
32            wgl.wglShareLists(share_ctx, ctx)
33        self._win_context = ctx
34        self._win_dblbuf = actpf.dwFlags & wgl.PFD_DOUBLEBUFFER != 0
35    
36    def destroy(self):
37        wgl.wglDeleteContext(self._win_context)
38    
39    def _with_context(self, hdc, proc, flush = False):
40        old_hdc = wgl.wglGetCurrentDC()
41        old_ctx = wgl.wglGetCurrentContext()
42        result = wgl.wglMakeCurrent(hdc, self._win_context)
43        try:
44            self._with_share_group(proc)
45            if flush:
46                if self._win_dblbuf:
47                    wgl.SwapBuffers(hdc)
48                else:
49                    gl.glFlush()
50        finally:
51            wgl.wglMakeCurrent(old_hdc, old_ctx)
52