| 1 | """Test that multiple windows share objects by default. |
| 2 | """ |
| 3 | |
| 4 | from ctypes import * |
| 5 | |
| 6 | import pyglet |
| 7 | |
| 8 | from pyglet import window |
| 9 | from pyglet.gl import * |
| 10 | |
| 11 | |
| 12 | def create_context(share): |
| 13 | display = pyglet.display.get_display() |
| 14 | screen = display.get_default_screen() |
| 15 | config = screen.get_best_config() |
| 16 | return config.create_context(share) |
| 17 | |
| 18 | |
| 19 | def test_context_share_texture(): |
| 20 | w1 = window.Window(200, 200) |
| 21 | w1.switch_to() |
| 22 | textures = c_uint() |
| 23 | glGenTextures(1, byref(textures)) |
| 24 | texture = textures.value |
| 25 | |
| 26 | glBindTexture(GL_TEXTURE_2D, texture) |
| 27 | data = (c_ubyte * 4)() |
| 28 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data) |
| 29 | assert glIsTexture(texture) |
| 30 | |
| 31 | w2 = window.Window(200, 200) |
| 32 | w2.switch_to() |
| 33 | assert glIsTexture(texture) |
| 34 | |
| 35 | glDeleteTextures(1, byref(textures)) |
| 36 | assert not glIsTexture(texture) |
| 37 | |
| 38 | w1.switch_to() |
| 39 | assert not glIsTexture(texture) |
| 40 | |
| 41 | w1.close() |
| 42 | w2.close() |
| 43 | |
| 44 | |
| 45 | def test_context_noshare_texture(): |
| 46 | w1 = window.Window(200, 200) |
| 47 | w1.switch_to() |
| 48 | textures = c_uint() |
| 49 | glGenTextures(1, byref(textures)) |
| 50 | texture = textures.value |
| 51 | |
| 52 | glBindTexture(GL_TEXTURE_2D, texture) |
| 53 | data = (c_ubyte * 4)() |
| 54 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data) |
| 55 | assert glIsTexture(texture) |
| 56 | |
| 57 | w2 = window.Window(200, 200, context=create_context(None)) |
| 58 | w2.switch_to() |
| 59 | assert not glIsTexture(texture) |
| 60 | |
| 61 | w1.close() |
| 62 | w2.close() |