diff --git a/csdl/tests/test_video.py b/csdl/tests/test_video.py index f837722..714f10c 100644 --- a/csdl/tests/test_video.py +++ b/csdl/tests/test_video.py @@ -1,6 +1,7 @@ -from csdl import init, InitFlags, quit +from csdl import init, InitFlags from csdl import video from nose.tools import with_setup +import time def video_setup(): init(InitFlags.VIDEO) @@ -37,7 +38,7 @@ def test_rect_basics(): assert repr(r1) == 'Rect(0, 0, 10, 10)' -@with_setup(video_setup, quit) +@with_setup(video_setup) def test_window_title(): w = video.Window("window_title_test", 10, 10, 50, 50) assert w.title == "window_title_test" @@ -45,7 +46,7 @@ def test_window_title(): assert w.title == "something completely different" w.destroy() -@with_setup(video_setup, quit) +@with_setup(video_setup) def test_window_size(): w = video.Window("window_size_test", 10, 10, 50, 50) assert w.size == (50, 50) @@ -53,7 +54,7 @@ def test_window_size(): assert w.size == (100, 120) w.destroy() -@with_setup(video_setup, quit) +@with_setup(video_setup) def test_window_position(): w = video.Window('window_position_test', 10, 10, 50, 50) assert w.position == (10, 10) @@ -61,7 +62,7 @@ def test_window_position(): assert w.position == (100, 110) w.destroy() -@with_setup(video_setup, quit) +@with_setup(video_setup) def test_screensaver(): enabled = video.is_screensaver_enabled() @@ -77,8 +78,19 @@ def test_screensaver(): assert not video.is_screensaver_enabled() -@with_setup(video_setup, quit) +@with_setup(video_setup) def test_video_info(): # make sure both aren't blank assert video.get_num_video_displays() assert video.get_current_video_driver() + +@with_setup(video_setup) +def test_gl_info(): + w = video.Window('window_position_test', 10, 10, 50, 50, + video.WindowFlags.OPENGL) + + for attr in video.GL_Attr: + print('{0}: {1}'.format(repr(attr)[1:-1], + video.gl_get_attribute(attr))) + print 'GL Swap Interval:', video.gl_get_swap_interval() + diff --git a/csdl/video.py b/csdl/video.py index 1ed1b3e..672dc7b 100644 --- a/csdl/video.py +++ b/csdl/video.py @@ -144,8 +144,23 @@ class Window(object): self.renderer = Renderer(self._handle) def destroy(self): + _glcontext = getattr(self, '_glcontext', None) + if _glcontext: + _SDL.SDL_GL_DeleteContext(_glcontext) _SDL.SDL_DestroyWindow(self._handle) + @property + def gl_context(self): + if not hasattr(self, '_glcontext'): + self._glcontext = _SDL.SDL_GL_CreateContext(self._handle) + return self._glcontext + + def swap(): + _SDL.SDL_GL_SwapWindow(self._handle) + + def make_context_current(): + errcheck(_SDL.SDL_GL_MakeCurrent(self._handle, self._glcontext)) + @property def display(self): return errcheck(_SDL.SDL_GetWindowDisplay(self._handle)) @@ -342,3 +357,44 @@ def get_display_bounds(display_index): rect = Rect() errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect))) return rect.value + + +def gl_extension_supported(extension): + return _SDL.SDL_GL_ExtensionSupported(extension) == 1 + +class GL_Attr(CEnum): + SDL_GL_RED_SIZE = 0 + SDL_GL_GREEN_SIZE = 1 + SDL_GL_BLUE_SIZE = 2 + SDL_GL_ALPHA_SIZE = 3 + SDL_GL_BUFFER_SIZE = 4 + SDL_GL_DOUBLEBUFFER = 5 + SDL_GL_DEPTH_SIZE = 6 + SDL_GL_STENCIL_SIZE = 7 + SDL_GL_ACCUM_RED_SIZE = 8 + SDL_GL_ACCUM_GREEN_SIZE = 9 + SDL_GL_ACCUM_BLUE_SIZE = 10 + SDL_GL_ACCUM_ALPHA_SIZE = 11 + SDL_GL_STEREO = 12 + SDL_GL_MULTISAMPLEBUFFERS = 13 + SDL_GL_MULTISAMPLESAMPLES = 14 + SDL_GL_ACCELERATED_VISUAL = 15 + SDL_GL_RETAINED_BACKING = 16 + SDL_GL_CONTEXT_MAJOR_VERSION = 17 + SDL_GL_CONTEXT_MINOR_VERSION = 18 + +def gl_get_attribute(attr): + attrvalue = ctypes.c_int() + errcheck(_SDL.SDL_GL_GetAttribute(attr, ctypes.byref(attrvalue))) + return attrvalue.value + +def gl_set_attribute(attr, value): + errcheck(_SDL.SDL_GL_SetAttribute(attr, value)) + +def gl_get_swap_interval(): + return errcheck(_SDL.SDL_GL_GetSwapInterval()) + +def gl_set_swap_interval(interval): + # 0: immediate + # 1: sync w/ vtrace + return errcheck(_SDL.SDL_GL_SetSwapInterval(interval)) diff --git a/not_supported.txt b/not_supported.txt index c183bce..ff297d3 100644 --- a/not_supported.txt +++ b/not_supported.txt @@ -13,7 +13,7 @@ http://wiki.libsdl.org/moin.cgi/CategoryVideo SDL_SetWindowFullscreen -- later SDL_VideoInit -- later SDL_VideoQuit -- later - SDL_GL_* -- later? + SDL_GL_GetProcAddress, SDL_GL_LoadLibrary, SDL_GL_UnloadLibrary CategoryRender SDL_CreateSoftwareRenderer diff --git a/run_tests.sh b/run_tests.sh index 829e6f7..3f7ba0e 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1 +1 @@ -nosetests --cover-html --with-coverage --cover-package=csdl --cover-inclusive +nosetests --cover-html --with-coverage --cover-package=csdl --cover-inclusive -v -s