add SDL_GL wrappers
commit also removes quit() calls from video tests, they were causing weird X errors
This commit is contained in:
parent
5ef4e0f078
commit
7eae042d05
@ -1,6 +1,7 @@
|
|||||||
from csdl import init, InitFlags, quit
|
from csdl import init, InitFlags
|
||||||
from csdl import video
|
from csdl import video
|
||||||
from nose.tools import with_setup
|
from nose.tools import with_setup
|
||||||
|
import time
|
||||||
|
|
||||||
def video_setup():
|
def video_setup():
|
||||||
init(InitFlags.VIDEO)
|
init(InitFlags.VIDEO)
|
||||||
@ -37,7 +38,7 @@ def test_rect_basics():
|
|||||||
assert repr(r1) == 'Rect(0, 0, 10, 10)'
|
assert repr(r1) == 'Rect(0, 0, 10, 10)'
|
||||||
|
|
||||||
|
|
||||||
@with_setup(video_setup, quit)
|
@with_setup(video_setup)
|
||||||
def test_window_title():
|
def test_window_title():
|
||||||
w = video.Window("window_title_test", 10, 10, 50, 50)
|
w = video.Window("window_title_test", 10, 10, 50, 50)
|
||||||
assert w.title == "window_title_test"
|
assert w.title == "window_title_test"
|
||||||
@ -45,7 +46,7 @@ def test_window_title():
|
|||||||
assert w.title == "something completely different"
|
assert w.title == "something completely different"
|
||||||
w.destroy()
|
w.destroy()
|
||||||
|
|
||||||
@with_setup(video_setup, quit)
|
@with_setup(video_setup)
|
||||||
def test_window_size():
|
def test_window_size():
|
||||||
w = video.Window("window_size_test", 10, 10, 50, 50)
|
w = video.Window("window_size_test", 10, 10, 50, 50)
|
||||||
assert w.size == (50, 50)
|
assert w.size == (50, 50)
|
||||||
@ -53,7 +54,7 @@ def test_window_size():
|
|||||||
assert w.size == (100, 120)
|
assert w.size == (100, 120)
|
||||||
w.destroy()
|
w.destroy()
|
||||||
|
|
||||||
@with_setup(video_setup, quit)
|
@with_setup(video_setup)
|
||||||
def test_window_position():
|
def test_window_position():
|
||||||
w = video.Window('window_position_test', 10, 10, 50, 50)
|
w = video.Window('window_position_test', 10, 10, 50, 50)
|
||||||
assert w.position == (10, 10)
|
assert w.position == (10, 10)
|
||||||
@ -61,7 +62,7 @@ def test_window_position():
|
|||||||
assert w.position == (100, 110)
|
assert w.position == (100, 110)
|
||||||
w.destroy()
|
w.destroy()
|
||||||
|
|
||||||
@with_setup(video_setup, quit)
|
@with_setup(video_setup)
|
||||||
def test_screensaver():
|
def test_screensaver():
|
||||||
enabled = video.is_screensaver_enabled()
|
enabled = video.is_screensaver_enabled()
|
||||||
|
|
||||||
@ -77,8 +78,19 @@ def test_screensaver():
|
|||||||
assert not video.is_screensaver_enabled()
|
assert not video.is_screensaver_enabled()
|
||||||
|
|
||||||
|
|
||||||
@with_setup(video_setup, quit)
|
@with_setup(video_setup)
|
||||||
def test_video_info():
|
def test_video_info():
|
||||||
# make sure both aren't blank
|
# make sure both aren't blank
|
||||||
assert video.get_num_video_displays()
|
assert video.get_num_video_displays()
|
||||||
assert video.get_current_video_driver()
|
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()
|
||||||
|
|
||||||
|
@ -144,8 +144,23 @@ class Window(object):
|
|||||||
self.renderer = Renderer(self._handle)
|
self.renderer = Renderer(self._handle)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
|
_glcontext = getattr(self, '_glcontext', None)
|
||||||
|
if _glcontext:
|
||||||
|
_SDL.SDL_GL_DeleteContext(_glcontext)
|
||||||
_SDL.SDL_DestroyWindow(self._handle)
|
_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
|
@property
|
||||||
def display(self):
|
def display(self):
|
||||||
return errcheck(_SDL.SDL_GetWindowDisplay(self._handle))
|
return errcheck(_SDL.SDL_GetWindowDisplay(self._handle))
|
||||||
@ -342,3 +357,44 @@ def get_display_bounds(display_index):
|
|||||||
rect = Rect()
|
rect = Rect()
|
||||||
errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect)))
|
errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect)))
|
||||||
return rect.value
|
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))
|
||||||
|
@ -13,7 +13,7 @@ http://wiki.libsdl.org/moin.cgi/CategoryVideo
|
|||||||
SDL_SetWindowFullscreen -- later
|
SDL_SetWindowFullscreen -- later
|
||||||
SDL_VideoInit -- later
|
SDL_VideoInit -- later
|
||||||
SDL_VideoQuit -- later
|
SDL_VideoQuit -- later
|
||||||
SDL_GL_* -- later?
|
SDL_GL_GetProcAddress, SDL_GL_LoadLibrary, SDL_GL_UnloadLibrary
|
||||||
|
|
||||||
CategoryRender
|
CategoryRender
|
||||||
SDL_CreateSoftwareRenderer
|
SDL_CreateSoftwareRenderer
|
||||||
|
@ -1 +1 @@
|
|||||||
nosetests --cover-html --with-coverage --cover-package=csdl --cover-inclusive
|
nosetests --cover-html --with-coverage --cover-package=csdl --cover-inclusive -v -s
|
||||||
|
Loading…
Reference in New Issue
Block a user