/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. import OpenGL as gl
  7. from OpenGL import WGL as wgl
  8. import WGL
  9. from GGLContexts import GLContext as GGLContext
  10. class GLContext(GGLContext):
  11. # _win_context WGL context
  12. # _win_dblbuf Is double buffered
  13. def __init__(self, share_group, config, hdc, mode):
  14. print "GLContext: mode =", mode ###
  15. GGLContext.__init__(self, share_group)
  16. shared_context = self._get_shared_context()
  17. if shared_context:
  18. share_ctx = shared_context._win_context
  19. else:
  20. share_ctx = None
  21. ipf, act_attrs = config._win_supported_pixelformat(hdc, mode)
  22. if ipf is None:
  23. raise GLConfigError
  24. #config._check_win_pixelattrs(act_attrs, mode)
  25. print "GLContext: Setting pixel format", ipf, "for hdc", hdc ###
  26. WGL.SetPixelFormat(hdc, ipfs)
  27. ctx = wgl.wglCreateContext(hdc)
  28. if share_ctx:
  29. wgl.wglShareLists(share_ctx, ctx)
  30. self._win_context = ctx
  31. self._win_dblbuf = actpf.dwFlags & wgl.PFD_DOUBLEBUFFER != 0
  32. def destroy(self):
  33. wgl.wglDeleteContext(self._win_context)
  34. def _with_context(self, hdc, proc, flush = False):
  35. old_hdc = wgl.wglGetCurrentDC()
  36. old_ctx = wgl.wglGetCurrentContext()
  37. result = wgl.wglMakeCurrent(hdc, self._win_context)
  38. try:
  39. self._with_share_group(proc)
  40. if flush:
  41. if self._win_dblbuf:
  42. wgl.SwapBuffers(hdc)
  43. else:
  44. gl.glFlush()
  45. finally:
  46. wgl.wglMakeCurrent(old_hdc, old_ctx)