def test_gl_load_unload_library(self): # Try the default library self.assertTrue(video.gl_load_library()) video.gl_unload_library() if has_opengl_lib(): self.assertTrue(video.gl_load_library(get_opengl_path())) video.gl_unload_library() self.assertRaises(sdl.SDLError, video.gl_load_library, "Test") self.assertRaises(sdl.SDLError, video.gl_load_library, False) self.assertRaises(sdl.SDLError, video.gl_load_library, 0)
def test_gl_get_set_swap_interval(self): self.assertRaises(ValueError, video.gl_set_swap_interval, None) self.assertRaises(ValueError, video.gl_set_swap_interval, "Test") self.assertRaises(ValueError, video.gl_set_swap_interval, 1234) # No current OpenGL context yet. # Might crash on certain platforms, since the internal state of # SDL2 does not support calling GL functions without having a # GL library loaded. # self.assertRaises(sdl.SDLError, video.gl_set_swap_interval, 1) # self.assertRaises(sdl.SDLError, video.gl_set_swap_interval, 0) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) video.gl_make_current(window, ctx) video.gl_set_swap_interval(0) self.assertEqual(video.gl_get_swap_interval(), 0) video.gl_set_swap_interval(1) self.assertEqual(video.gl_get_swap_interval(), 1) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library()
def test_gl_create_delete_context(self): self.assertRaises((AttributeError, TypeError), video.gl_create_context, None) self.assertRaises((AttributeError, TypeError), video.gl_create_context, "Test") self.assertRaises((AttributeError, TypeError), video.gl_create_context, 1234) window = video.create_window("No OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_BORDERLESS) self.assertRaises(sdl.SDLError, video.gl_create_context, window) video.destroy_window(window) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) video.gl_delete_context(ctx) video.destroy_window(window) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) video.destroy_window(window) video.gl_delete_context(ctx) video.gl_unload_library()
def test_gl_make_current(self): self.assertTrue(video.gl_load_library()) self.assertRaises((AttributeError, TypeError), video.gl_make_current, None, None) window = video.create_window("No OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_BORDERLESS) self.assertRaises(sdl.SDLError, video.gl_create_context, window) video.destroy_window(window) self.assertRaises((AttributeError, TypeError), video.gl_make_current, None, None) video.gl_unload_library()
def test_gl_extension_supported(self): self.assertFalse(video.gl_extension_supported("GL_EXT_bgra")) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) self.assertTrue(video.gl_extension_supported("GL_EXT_bgra")) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library() self.assertFalse(video.gl_extension_supported("GL_EXT_bgra"))
def test_gl_get_proc_address(self): procaddr = video.gl_get_proc_address("glGetString") self.assertIsNone(procaddr) self.assertTrue(video.gl_load_library()) # Behaviour is undefined as long as there is no window and context. window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) procaddr = video.gl_get_proc_address("glGetString") self.assertTrue(procaddr is not None and int(procaddr) != 0) procaddr = video.gl_get_proc_address("glForWhackoPeople") self.assertIsNone(procaddr) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library() procaddr = video.gl_get_proc_address("glGetString") self.assertIsNone(procaddr)
def test_gl_get_set_attribute(self): self.assertRaises(sdl.SDLError, video.gl_get_attribute, video.SDL_GL_DEPTH_SIZE) self.assertRaises(sdl.SDLError, video.gl_set_attribute, 1455, 24) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) depth = video.gl_get_attribute(video.SDL_GL_DEPTH_SIZE) video.gl_delete_context(ctx) video.destroy_window(window) newdepth = 24 if depth == 8: newdepth = 16 elif depth == 16: newdepth = 24 elif depth == 24: newdepth = 16 video.gl_set_attribute(video.SDL_GL_DEPTH_SIZE, newdepth) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) val = video.gl_get_attribute(video.SDL_GL_DEPTH_SIZE) self.assertNotEqual(depth, val) self.assertEqual(val, newdepth) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library()