pyglet 2.1.12__py3-none-any.whl → 3.0.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. pyglet/__init__.py +67 -61
  2. pyglet/__init__.pyi +15 -8
  3. pyglet/app/__init__.py +22 -13
  4. pyglet/app/async_app.py +212 -0
  5. pyglet/app/base.py +2 -1
  6. pyglet/app/{xlib.py → linux.py} +3 -3
  7. pyglet/config/__init__.py +101 -0
  8. pyglet/config/gl/__init__.py +30 -0
  9. pyglet/config/gl/egl.py +120 -0
  10. pyglet/config/gl/macos.py +262 -0
  11. pyglet/config/gl/windows.py +267 -0
  12. pyglet/config/gl/x11.py +142 -0
  13. pyglet/customtypes.py +43 -2
  14. pyglet/display/__init__.py +8 -6
  15. pyglet/display/base.py +3 -63
  16. pyglet/display/cocoa.py +12 -17
  17. pyglet/display/emscripten.py +39 -0
  18. pyglet/display/headless.py +23 -30
  19. pyglet/display/wayland.py +157 -0
  20. pyglet/display/win32.py +4 -17
  21. pyglet/display/xlib.py +19 -27
  22. pyglet/display/xlib_vidmoderestore.py +2 -2
  23. pyglet/enums.py +183 -0
  24. pyglet/event.py +0 -1
  25. pyglet/experimental/geoshader_sprite.py +15 -13
  26. pyglet/experimental/hidraw.py +6 -15
  27. pyglet/experimental/multitexture_sprite.py +31 -19
  28. pyglet/experimental/particles.py +13 -35
  29. pyglet/font/__init__.py +251 -85
  30. pyglet/font/base.py +116 -61
  31. pyglet/font/dwrite/__init__.py +349 -204
  32. pyglet/font/dwrite/dwrite_lib.py +27 -5
  33. pyglet/font/fontconfig.py +14 -6
  34. pyglet/font/freetype.py +138 -87
  35. pyglet/font/freetype_lib.py +19 -0
  36. pyglet/font/group.py +179 -0
  37. pyglet/font/harfbuzz/__init__.py +3 -3
  38. pyglet/font/pyodide_js.py +310 -0
  39. pyglet/font/quartz.py +319 -126
  40. pyglet/font/ttf.py +45 -3
  41. pyglet/font/user.py +14 -19
  42. pyglet/font/win32.py +45 -21
  43. pyglet/graphics/__init__.py +8 -787
  44. pyglet/graphics/allocation.py +115 -1
  45. pyglet/graphics/api/__init__.py +77 -0
  46. pyglet/graphics/api/base.py +299 -0
  47. pyglet/graphics/api/gl/__init__.py +58 -0
  48. pyglet/graphics/api/gl/base.py +24 -0
  49. pyglet/graphics/{vertexbuffer.py → api/gl/buffer.py} +104 -159
  50. pyglet/graphics/api/gl/cocoa/context.py +76 -0
  51. pyglet/graphics/api/gl/context.py +391 -0
  52. pyglet/graphics/api/gl/default_shaders.py +0 -0
  53. pyglet/graphics/api/gl/draw.py +627 -0
  54. pyglet/graphics/api/gl/egl/__init__.py +0 -0
  55. pyglet/graphics/api/gl/egl/context.py +92 -0
  56. pyglet/graphics/api/gl/enums.py +76 -0
  57. pyglet/graphics/api/gl/framebuffer.py +315 -0
  58. pyglet/graphics/api/gl/gl.py +5463 -0
  59. pyglet/graphics/api/gl/gl_info.py +188 -0
  60. pyglet/graphics/api/gl/global_opengl.py +226 -0
  61. pyglet/{gl → graphics/api/gl}/lib.py +34 -18
  62. pyglet/graphics/api/gl/shader.py +1476 -0
  63. pyglet/graphics/api/gl/shapes.py +55 -0
  64. pyglet/graphics/api/gl/sprite.py +102 -0
  65. pyglet/graphics/api/gl/state.py +219 -0
  66. pyglet/graphics/api/gl/text.py +190 -0
  67. pyglet/graphics/api/gl/texture.py +1526 -0
  68. pyglet/graphics/{vertexarray.py → api/gl/vertexarray.py} +11 -13
  69. pyglet/graphics/api/gl/vertexdomain.py +751 -0
  70. pyglet/graphics/api/gl/win32/__init__.py +0 -0
  71. pyglet/graphics/api/gl/win32/context.py +108 -0
  72. pyglet/graphics/api/gl/win32/wgl_info.py +24 -0
  73. pyglet/graphics/api/gl/xlib/__init__.py +0 -0
  74. pyglet/graphics/api/gl/xlib/context.py +174 -0
  75. pyglet/{gl → graphics/api/gl/xlib}/glx_info.py +26 -31
  76. pyglet/graphics/api/gl1/__init__.py +0 -0
  77. pyglet/{gl → graphics/api/gl1}/gl_compat.py +3 -2
  78. pyglet/graphics/api/gl2/__init__.py +0 -0
  79. pyglet/graphics/api/gl2/buffer.py +320 -0
  80. pyglet/graphics/api/gl2/draw.py +600 -0
  81. pyglet/graphics/api/gl2/global_opengl.py +122 -0
  82. pyglet/graphics/api/gl2/shader.py +200 -0
  83. pyglet/graphics/api/gl2/shapes.py +51 -0
  84. pyglet/graphics/api/gl2/sprite.py +79 -0
  85. pyglet/graphics/api/gl2/text.py +175 -0
  86. pyglet/graphics/api/gl2/vertexdomain.py +364 -0
  87. pyglet/graphics/api/webgl/__init__.py +233 -0
  88. pyglet/graphics/api/webgl/buffer.py +302 -0
  89. pyglet/graphics/api/webgl/context.py +234 -0
  90. pyglet/graphics/api/webgl/draw.py +590 -0
  91. pyglet/graphics/api/webgl/enums.py +76 -0
  92. pyglet/graphics/api/webgl/framebuffer.py +360 -0
  93. pyglet/graphics/api/webgl/gl.py +1537 -0
  94. pyglet/graphics/api/webgl/gl_info.py +130 -0
  95. pyglet/graphics/api/webgl/shader.py +1346 -0
  96. pyglet/graphics/api/webgl/shapes.py +92 -0
  97. pyglet/graphics/api/webgl/sprite.py +102 -0
  98. pyglet/graphics/api/webgl/state.py +227 -0
  99. pyglet/graphics/api/webgl/text.py +187 -0
  100. pyglet/graphics/api/webgl/texture.py +1227 -0
  101. pyglet/graphics/api/webgl/vertexarray.py +54 -0
  102. pyglet/graphics/api/webgl/vertexdomain.py +616 -0
  103. pyglet/graphics/api/webgl/webgl_js.pyi +307 -0
  104. pyglet/{image → graphics}/atlas.py +33 -32
  105. pyglet/graphics/base.py +10 -0
  106. pyglet/graphics/buffer.py +245 -0
  107. pyglet/graphics/draw.py +578 -0
  108. pyglet/graphics/framebuffer.py +26 -0
  109. pyglet/graphics/instance.py +178 -69
  110. pyglet/graphics/shader.py +267 -1553
  111. pyglet/graphics/state.py +83 -0
  112. pyglet/graphics/texture.py +703 -0
  113. pyglet/graphics/vertexdomain.py +695 -538
  114. pyglet/gui/ninepatch.py +10 -10
  115. pyglet/gui/widgets.py +120 -10
  116. pyglet/image/__init__.py +20 -1973
  117. pyglet/image/animation.py +12 -12
  118. pyglet/image/base.py +730 -0
  119. pyglet/image/codecs/__init__.py +9 -0
  120. pyglet/image/codecs/bmp.py +53 -30
  121. pyglet/image/codecs/dds.py +53 -31
  122. pyglet/image/codecs/gdiplus.py +38 -14
  123. pyglet/image/codecs/gdkpixbuf2.py +0 -2
  124. pyglet/image/codecs/js_image.py +99 -0
  125. pyglet/image/codecs/ktx2.py +161 -0
  126. pyglet/image/codecs/pil.py +1 -1
  127. pyglet/image/codecs/png.py +1 -1
  128. pyglet/image/codecs/wic.py +11 -2
  129. pyglet/info.py +26 -24
  130. pyglet/input/__init__.py +8 -0
  131. pyglet/input/base.py +163 -105
  132. pyglet/input/controller.py +13 -19
  133. pyglet/input/controller_db.py +39 -24
  134. pyglet/input/emscripten/__init__.py +18 -0
  135. pyglet/input/emscripten/gamepad_js.py +397 -0
  136. pyglet/input/linux/__init__.py +11 -5
  137. pyglet/input/linux/evdev.py +10 -11
  138. pyglet/input/linux/x11_xinput.py +2 -2
  139. pyglet/input/linux/x11_xinput_tablet.py +1 -1
  140. pyglet/input/macos/__init__.py +7 -2
  141. pyglet/input/macos/darwin_gc.py +559 -0
  142. pyglet/input/win32/__init__.py +1 -1
  143. pyglet/input/win32/directinput.py +34 -29
  144. pyglet/input/win32/xinput.py +11 -61
  145. pyglet/lib.py +3 -3
  146. pyglet/libs/__init__.py +1 -1
  147. pyglet/{gl → libs/darwin}/agl.py +1 -1
  148. pyglet/libs/darwin/cocoapy/__init__.py +2 -2
  149. pyglet/libs/darwin/cocoapy/cocoahelpers.py +181 -0
  150. pyglet/libs/darwin/cocoapy/cocoalibs.py +31 -0
  151. pyglet/libs/darwin/cocoapy/cocoatypes.py +27 -0
  152. pyglet/libs/darwin/cocoapy/runtime.py +81 -45
  153. pyglet/libs/darwin/coreaudio.py +4 -4
  154. pyglet/{gl → libs/darwin}/lib_agl.py +9 -8
  155. pyglet/libs/darwin/quartzkey.py +1 -3
  156. pyglet/libs/egl/__init__.py +2 -0
  157. pyglet/libs/egl/egl_lib.py +576 -0
  158. pyglet/libs/egl/eglext.py +51 -5
  159. pyglet/libs/linux/__init__.py +0 -0
  160. pyglet/libs/linux/egl/__init__.py +0 -0
  161. pyglet/libs/linux/egl/eglext.py +22 -0
  162. pyglet/libs/linux/glx/__init__.py +0 -0
  163. pyglet/{gl → libs/linux/glx}/glx.py +13 -14
  164. pyglet/{gl → libs/linux/glx}/glxext_arb.py +408 -192
  165. pyglet/{gl → libs/linux/glx}/glxext_mesa.py +1 -1
  166. pyglet/{gl → libs/linux/glx}/glxext_nv.py +345 -164
  167. pyglet/{gl → libs/linux/glx}/lib_glx.py +3 -2
  168. pyglet/libs/linux/wayland/__init__.py +0 -0
  169. pyglet/libs/linux/wayland/client.py +1068 -0
  170. pyglet/libs/linux/wayland/lib_wayland.py +207 -0
  171. pyglet/libs/linux/wayland/wayland_egl.py +38 -0
  172. pyglet/libs/{wayland → linux/wayland}/xkbcommon.py +26 -0
  173. pyglet/libs/{x11 → linux/x11}/xf86vmode.py +4 -4
  174. pyglet/libs/{x11 → linux/x11}/xinerama.py +2 -2
  175. pyglet/libs/{x11 → linux/x11}/xinput.py +10 -10
  176. pyglet/libs/linux/x11/xrandr.py +0 -0
  177. pyglet/libs/{x11 → linux/x11}/xrender.py +1 -1
  178. pyglet/libs/shared/__init__.py +0 -0
  179. pyglet/libs/shared/spirv/__init__.py +0 -0
  180. pyglet/libs/shared/spirv/lib_shaderc.py +85 -0
  181. pyglet/libs/shared/spirv/lib_spirv_cross.py +126 -0
  182. pyglet/libs/win32/__init__.py +27 -5
  183. pyglet/libs/win32/constants.py +59 -48
  184. pyglet/libs/win32/context_managers.py +20 -3
  185. pyglet/libs/win32/dinput.py +105 -88
  186. pyglet/{gl → libs/win32}/lib_wgl.py +52 -26
  187. pyglet/libs/win32/types.py +58 -23
  188. pyglet/{gl → libs/win32}/wgl.py +32 -25
  189. pyglet/{gl → libs/win32}/wglext_arb.py +364 -2
  190. pyglet/media/__init__.py +9 -10
  191. pyglet/media/codecs/__init__.py +12 -1
  192. pyglet/media/codecs/base.py +99 -96
  193. pyglet/media/codecs/ffmpeg.py +2 -2
  194. pyglet/media/codecs/ffmpeg_lib/libavformat.py +3 -8
  195. pyglet/media/codecs/webaudio_pyodide.py +111 -0
  196. pyglet/media/drivers/__init__.py +9 -4
  197. pyglet/media/drivers/base.py +4 -4
  198. pyglet/media/drivers/openal/__init__.py +1 -1
  199. pyglet/media/drivers/openal/adaptation.py +3 -3
  200. pyglet/media/drivers/pulse/__init__.py +1 -1
  201. pyglet/media/drivers/pulse/adaptation.py +3 -3
  202. pyglet/media/drivers/pyodide_js/__init__.py +8 -0
  203. pyglet/media/drivers/pyodide_js/adaptation.py +288 -0
  204. pyglet/media/drivers/xaudio2/adaptation.py +3 -3
  205. pyglet/media/player.py +276 -193
  206. pyglet/media/player_worker_thread.py +1 -1
  207. pyglet/model/__init__.py +39 -29
  208. pyglet/model/codecs/base.py +4 -4
  209. pyglet/model/codecs/gltf.py +3 -3
  210. pyglet/model/codecs/obj.py +71 -43
  211. pyglet/resource.py +129 -78
  212. pyglet/shapes.py +147 -177
  213. pyglet/sprite.py +47 -164
  214. pyglet/text/__init__.py +44 -54
  215. pyglet/text/caret.py +12 -7
  216. pyglet/text/document.py +19 -17
  217. pyglet/text/formats/html.py +2 -2
  218. pyglet/text/formats/structured.py +10 -40
  219. pyglet/text/layout/__init__.py +20 -13
  220. pyglet/text/layout/base.py +176 -287
  221. pyglet/text/layout/incremental.py +9 -10
  222. pyglet/text/layout/scrolling.py +7 -95
  223. pyglet/window/__init__.py +183 -172
  224. pyglet/window/cocoa/__init__.py +62 -51
  225. pyglet/window/cocoa/pyglet_delegate.py +2 -25
  226. pyglet/window/cocoa/pyglet_view.py +9 -8
  227. pyglet/window/dialog/__init__.py +184 -0
  228. pyglet/window/dialog/base.py +99 -0
  229. pyglet/window/dialog/darwin.py +121 -0
  230. pyglet/window/dialog/linux.py +72 -0
  231. pyglet/window/dialog/windows.py +194 -0
  232. pyglet/window/emscripten/__init__.py +779 -0
  233. pyglet/window/headless/__init__.py +44 -28
  234. pyglet/window/key.py +2 -0
  235. pyglet/window/mouse.py +2 -2
  236. pyglet/window/wayland/__init__.py +377 -0
  237. pyglet/window/win32/__init__.py +101 -46
  238. pyglet/window/xlib/__init__.py +104 -66
  239. {pyglet-2.1.12.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
  240. pyglet-3.0.dev1.dist-info/RECORD +322 -0
  241. {pyglet-2.1.12.dist-info → pyglet-3.0.dev1.dist-info}/WHEEL +1 -1
  242. pyglet/gl/__init__.py +0 -208
  243. pyglet/gl/base.py +0 -499
  244. pyglet/gl/cocoa.py +0 -309
  245. pyglet/gl/gl.py +0 -4625
  246. pyglet/gl/gl.pyi +0 -2320
  247. pyglet/gl/gl_compat.pyi +0 -3097
  248. pyglet/gl/gl_info.py +0 -190
  249. pyglet/gl/headless.py +0 -166
  250. pyglet/gl/wgl_info.py +0 -36
  251. pyglet/gl/wglext_nv.py +0 -1096
  252. pyglet/gl/win32.py +0 -268
  253. pyglet/gl/xlib.py +0 -295
  254. pyglet/image/buffer.py +0 -274
  255. pyglet/image/codecs/s3tc.py +0 -354
  256. pyglet/libs/x11/xrandr.py +0 -166
  257. pyglet-2.1.12.dist-info/RECORD +0 -234
  258. /pyglet/{libs/wayland → graphics/api/gl/cocoa}/__init__.py +0 -0
  259. /pyglet/libs/{egl → linux/egl}/egl.py +0 -0
  260. /pyglet/libs/{egl → linux/egl}/lib.py +0 -0
  261. /pyglet/libs/{ioctl.py → linux/ioctl.py} +0 -0
  262. /pyglet/libs/{wayland → linux/wayland}/gbm.py +0 -0
  263. /pyglet/libs/{x11 → linux/x11}/__init__.py +0 -0
  264. /pyglet/libs/{x11 → linux/x11}/cursorfont.py +0 -0
  265. /pyglet/libs/{x11 → linux/x11}/xlib.py +0 -0
  266. /pyglet/libs/{x11 → linux/x11}/xsync.py +0 -0
  267. {pyglet-2.1.12.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
pyglet/image/buffer.py DELETED
@@ -1,274 +0,0 @@
1
- """OpenGL Framebuffer abstractions.
2
-
3
- This module provides classes for working with Framebuffers & Renderbuffers
4
- and their attachments. Attachments can be pyglet Texture objects, which allows
5
- easily accessing their data, saving to disk, etc. Renderbuffers can be used
6
- if you don't need to access their data at a later time. For example::
7
-
8
- # Create two objects to use as attachments for our Framebuffer.
9
- color_buffer = pyglet.image.Texture.create(width, height, min_filter=GL_NEAREST, mag_filter=GL_NEAREST)
10
- depth_buffer = pyglet.image.buffer.Renderbuffer(width, height, GL_DEPTH_COMPONENT)
11
-
12
- # Create a framebuffer object, and attach the two buffers:
13
- framebuffer = pyglet.image.Framebuffer()
14
- framebuffer.attach_texture(color_buffer, attachment=GL_COLOR_ATTACHMENT0)
15
- framebuffer.attach_renderbuffer(depth_buffer, attachment=GL_DEPTH_ATTACHMENT)
16
-
17
- # Bind the Framebuffer, which sets it as the active render target:
18
- framebuffer.bind()
19
-
20
- See the OpenGL documentation for more information on valid attachment types and targets.
21
- """
22
- from __future__ import annotations
23
-
24
- import pyglet
25
-
26
- from pyglet.gl import GLint, GLuint, glBindFramebuffer, glBindRenderbuffer, glCheckFramebufferStatus, glClear
27
- from pyglet.gl import glDeleteFramebuffers, glDeleteRenderbuffers, glFramebufferRenderbuffer, glFramebufferTexture
28
- from pyglet.gl import glFramebufferTextureLayer, glGenFramebuffers, glGenRenderbuffers, glGetIntegerv
29
- from pyglet.gl import glRenderbufferStorage, glRenderbufferStorageMultisample
30
- from pyglet.gl import GL_COLOR_ATTACHMENT0, GL_MAX_COLOR_ATTACHMENTS, GL_RENDERBUFFER
31
- from pyglet.gl import GL_FRAMEBUFFER, GL_FRAMEBUFFER_COMPLETE, GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
32
- from pyglet.gl import GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT, GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
33
- from pyglet.gl import GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT, GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
34
- from pyglet.gl import GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER, GL_FRAMEBUFFER_UNSUPPORTED
35
-
36
- from typing import TYPE_CHECKING
37
-
38
- if TYPE_CHECKING:
39
- from pyglet.image import Texture
40
-
41
-
42
- def get_max_color_attachments() -> int:
43
- """Get the maximum allow Framebuffer Color attachments."""
44
- number = GLint()
45
- glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, number)
46
- return number.value
47
-
48
-
49
- class Renderbuffer:
50
- """OpenGL Renderbuffer Object."""
51
-
52
- def __init__(self, width: int, height: int, internal_format: int, samples: int = 1) -> None:
53
- """Create a RenderBuffer instance."""
54
- self._context = pyglet.gl.current_context
55
- self._id = GLuint()
56
- self._width = width
57
- self._height = height
58
- self._internal_format = internal_format
59
-
60
- glGenRenderbuffers(1, self._id)
61
- glBindRenderbuffer(GL_RENDERBUFFER, self._id)
62
-
63
- if samples > 1:
64
- glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, internal_format, width, height)
65
- else:
66
- glRenderbufferStorage(GL_RENDERBUFFER, internal_format, width, height)
67
-
68
- glBindRenderbuffer(GL_RENDERBUFFER, 0)
69
-
70
- @property
71
- def id(self) -> int:
72
- return self._id.value
73
-
74
- @property
75
- def width(self) -> int:
76
- return self._width
77
-
78
- @property
79
- def height(self) -> int:
80
- return self._height
81
-
82
- def bind(self) -> None:
83
- glBindRenderbuffer(GL_RENDERBUFFER, self._id)
84
-
85
- @staticmethod
86
- def unbind() -> None:
87
- glBindRenderbuffer(GL_RENDERBUFFER, 0)
88
-
89
- def delete(self) -> None:
90
- glDeleteRenderbuffers(1, self._id)
91
- self._id = None
92
-
93
- def __del__(self) -> None:
94
- if self._id is not None:
95
- try:
96
- self._context.delete_renderbuffer(self._id.value)
97
- self._id = None
98
- except (AttributeError, ImportError):
99
- pass # Interpreter is shutting down
100
-
101
- def __repr__(self) -> str:
102
- return f"{self.__class__.__name__}(id={self._id.value})"
103
-
104
-
105
- class Framebuffer:
106
- """OpenGL Framebuffer Object.
107
-
108
- .. versionadded:: 2.0
109
- """
110
- def __init__(self, target: int = GL_FRAMEBUFFER) -> None:
111
- """Create a Framebuffer Instance."""
112
- self._context = pyglet.gl.current_context
113
- self._id = GLuint()
114
- glGenFramebuffers(1, self._id)
115
- self._attachment_types = 0
116
- self._width = 0
117
- self._height = 0
118
- self.target = target
119
-
120
- @property
121
- def id(self) -> int:
122
- """The Framebuffer id."""
123
- return self._id.value
124
-
125
- @property
126
- def width(self) -> int:
127
- """The width of the widest attachment."""
128
- return self._width
129
-
130
- @property
131
- def height(self) -> int:
132
- """The height of the tallest attachment."""
133
- return self._height
134
-
135
- def bind(self) -> None:
136
- """Bind the Framebuffer.
137
-
138
- This ctivates it as the current drawing target.
139
- """
140
- glBindFramebuffer(self.target, self._id)
141
-
142
- def unbind(self) -> None:
143
- """Unbind the Framebuffer.
144
-
145
- Unbind should be called to prevent further rendering
146
- to the framebuffer, or if you wish to access data
147
- from its Texture attachments.
148
- """
149
- glBindFramebuffer(self.target, 0)
150
-
151
- def clear(self) -> None:
152
- """Clear the attachments."""
153
- if self._attachment_types:
154
- self.bind()
155
- glClear(self._attachment_types)
156
- self.unbind()
157
-
158
- def delete(self) -> None:
159
- """Explicitly delete the Framebuffer."""
160
- glDeleteFramebuffers(1, self._id)
161
- self._id = None
162
-
163
- def __del__(self) -> None:
164
- if self._id is not None:
165
- try:
166
- self._context.delete_framebuffer(self._id.value)
167
- self._id = None
168
- except (AttributeError, ImportError):
169
- pass # Interpreter is shutting down
170
-
171
- @property
172
- def is_complete(self) -> bool:
173
- """True if the framebuffer is 'complete', else False."""
174
- return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE
175
-
176
- @staticmethod
177
- def get_status() -> str:
178
- """Get the current Framebuffer status, as a string.
179
-
180
- If ``Framebuffer.is_complete`` is ``False``, this method
181
- can be used for more information. It will return a
182
- string with the OpenGL reported status.
183
- """
184
- states = {GL_FRAMEBUFFER_UNSUPPORTED: "Framebuffer unsupported. Try another format.",
185
- GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: "Framebuffer incomplete attachment.",
186
- GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: "Framebuffer missing attachment.",
187
- GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: "Framebuffer unsupported dimension.",
188
- GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: "Framebuffer incomplete formats.",
189
- GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: "Framebuffer incomplete draw buffer.",
190
- GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: "Framebuffer incomplete read buffer.",
191
- GL_FRAMEBUFFER_COMPLETE: "Framebuffer is complete."}
192
-
193
- gl_status = glCheckFramebufferStatus(GL_FRAMEBUFFER)
194
-
195
- return states.get(gl_status, "Unknown error")
196
-
197
- def attach_texture(self, texture: Texture,
198
- target: int = GL_FRAMEBUFFER, attachment: int = GL_COLOR_ATTACHMENT0) -> None:
199
- """Attach a Texture to the Framebuffer.
200
-
201
- Args:
202
- texture:
203
- Specifies the texture object to attach to the framebuffer attachment
204
- point named by attachment.
205
- target:
206
- Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER,
207
- GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent
208
- to GL_DRAW_FRAMEBUFFER.
209
- attachment:
210
- Specifies the attachment point of the framebuffer. attachment must be
211
- GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or
212
- GL_DEPTH_STENCIL_ATTACHMENT.
213
- """
214
- self.bind()
215
- glFramebufferTexture(target, attachment, texture.id, texture.level)
216
- self._attachment_types |= attachment
217
- self._width = max(texture.width, self._width)
218
- self._height = max(texture.height, self._height)
219
- self.unbind()
220
-
221
- def attach_texture_layer(self, texture: Texture, layer: int, level: int,
222
- target: int = GL_FRAMEBUFFER, attachment: int = GL_COLOR_ATTACHMENT0) -> None:
223
- """Attach a Texture layer to the Framebuffer.
224
-
225
- Args:
226
- texture:
227
- Specifies the texture object to attach to the framebuffer attachment
228
- point named by attachment.
229
- layer:
230
- Specifies the layer of texture to attach.
231
- level:
232
- Specifies the mipmap level of texture to attach.
233
- target:
234
- Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER,
235
- GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent
236
- to GL_DRAW_FRAMEBUFFER.
237
- attachment:
238
- Specifies the attachment point of the framebuffer. attachment must be
239
- GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or
240
- GL_DEPTH_STENCIL_ATTACHMENT.
241
- """
242
- self.bind()
243
- glFramebufferTextureLayer(target, attachment, texture.id, level, layer)
244
- self._attachment_types |= attachment
245
- self._width = max(texture.width, self._width)
246
- self._height = max(texture.height, self._height)
247
- self.unbind()
248
-
249
- def attach_renderbuffer(self, renderbuffer: Renderbuffer,
250
- target: int = GL_FRAMEBUFFER, attachment: int = GL_COLOR_ATTACHMENT0) -> None:
251
- """Attach a Renderbuffer to the Framebuffer.
252
-
253
- Args:
254
- renderbuffer:
255
- Specifies the Renderbuffer to attach to the framebuffer attachment
256
- point named by attachment.
257
- target:
258
- Specifies the framebuffer target. target must be GL_DRAW_FRAMEBUFFER,
259
- GL_READ_FRAMEBUFFER, or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent
260
- to GL_DRAW_FRAMEBUFFER.
261
- attachment:
262
- Specifies the attachment point of the framebuffer. attachment must be
263
- GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or
264
- GL_DEPTH_STENCIL_ATTACHMENT.
265
- """
266
- self.bind()
267
- glFramebufferRenderbuffer(target, attachment, GL_RENDERBUFFER, renderbuffer.id)
268
- self._attachment_types |= attachment
269
- self._width = max(renderbuffer.width, self._width)
270
- self._height = max(renderbuffer.height, self._height)
271
- self.unbind()
272
-
273
- def __repr__(self) -> str:
274
- return f"{self.__class__.__name__}(id={self._id.value})"
@@ -1,354 +0,0 @@
1
- """Software decoder for S3TC compressed texture (i.e., DDS).
2
-
3
- http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_compression_s3tc.txt
4
- """
5
-
6
- import re
7
- import ctypes
8
-
9
- from pyglet.gl import *
10
- from pyglet.gl import gl_info
11
- from pyglet.image import AbstractImage, Texture
12
-
13
- split_8byte = re.compile('.' * 8, flags=re.DOTALL)
14
- split_16byte = re.compile('.' * 16, flags=re.DOTALL)
15
-
16
-
17
- class PackedImageData(AbstractImage):
18
- _current_texture = None
19
-
20
- def __init__(self, width, height, fmt, packed_format, data):
21
- super().__init__(width, height)
22
- self.format = fmt
23
- self.packed_format = packed_format
24
- self.data = data
25
-
26
- def unpack(self):
27
- if self.packed_format == GL_UNSIGNED_SHORT_5_6_5:
28
- # Unpack to GL_RGB. Assume self.data is already 16-bit
29
- i = 0
30
- out = (ctypes.c_ubyte * (self.width * self.height * 3))()
31
- for c in self.data:
32
- out[i + 2] = (c & 0x1f) << 3
33
- out[i + 1] = (c & 0x7e0) >> 3
34
- out[i] = (c & 0xf800) >> 8
35
- i += 3
36
- self.data = out
37
- self.packed_format = GL_UNSIGNED_BYTE
38
-
39
- def _get_texture(self):
40
- if self._current_texture:
41
- return self._current_texture
42
-
43
- texture = Texture.create(self.width, self.height, GL_TEXTURE_2D, None)
44
- glBindTexture(texture.target, texture.id)
45
- glTexParameteri(texture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
46
-
47
- if not gl_info.have_version(1, 2) or True:
48
- self.unpack()
49
-
50
- glTexImage2D(texture.target, texture.level,
51
- self.format, self.width, self.height, 0,
52
- self.format, self.packed_format, self.data)
53
-
54
- self._current_texture = texture
55
- return texture
56
-
57
- texture = property(_get_texture)
58
-
59
- def get_texture(self, rectangle=False, force_rectangle=False):
60
- """The parameters 'rectangle' and 'force_rectangle' are ignored.
61
- See the documentation of the method 'AbstractImage.get_texture' for
62
- a more detailed documentation of the method. """
63
- return self._get_texture()
64
-
65
-
66
- def decode_dxt1_rgb(data, width, height):
67
- # Decode to 16-bit RGB UNSIGNED_SHORT_5_6_5
68
- out = (ctypes.c_uint16 * (width * height))()
69
-
70
- # Read 8 bytes at a time
71
- image_offset = 0
72
- for c0_lo, c0_hi, c1_lo, c1_hi, b0, b1, b2, b3 in split_8byte.findall(data):
73
- color0 = ord(c0_lo) | ord(c0_hi) << 8
74
- color1 = ord(c1_lo) | ord(c1_hi) << 8
75
- bits = ord(b0) | ord(b1) << 8 | ord(b2) << 16 | ord(b3) << 24
76
-
77
- r0 = color0 & 0x1f
78
- g0 = (color0 & 0x7e0) >> 5
79
- b0 = (color0 & 0xf800) >> 11
80
- r1 = color1 & 0x1f
81
- g1 = (color1 & 0x7e0) >> 5
82
- b1 = (color1 & 0xf800) >> 11
83
-
84
- # i is the dest ptr for this block
85
- i = image_offset
86
- for y in range(4):
87
- for x in range(4):
88
- code = bits & 0x3
89
-
90
- if code == 0:
91
- out[i] = color0
92
- elif code == 1:
93
- out[i] = color1
94
- elif code == 3 and color0 <= color1:
95
- out[i] = 0
96
- else:
97
- if code == 2 and color0 > color1:
98
- r = (2 * r0 + r1) // 3
99
- g = (2 * g0 + g1) // 3
100
- b = (2 * b0 + b1) // 3
101
- elif code == 3 and color0 > color1:
102
- r = (r0 + 2 * r1) // 3
103
- g = (g0 + 2 * g1) // 3
104
- b = (b0 + 2 * b1) // 3
105
- else:
106
- assert code == 2 and color0 <= color1
107
- r = (r0 + r1) // 2
108
- g = (g0 + g1) // 2
109
- b = (b0 + b1) // 2
110
- out[i] = r | g << 5 | b << 11
111
-
112
- bits >>= 2
113
- i += 1
114
- i += width - 4
115
-
116
- # Move dest ptr to next 4x4 block
117
- advance_row = (image_offset + 4) % width == 0
118
- image_offset += width * 3 * advance_row + 4
119
-
120
- return PackedImageData(width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, out)
121
-
122
-
123
- def decode_dxt1_rgba(data, width, height):
124
- # Decode to GL_RGBA
125
- out = (ctypes.c_ubyte * (width * height * 4))()
126
- pitch = width << 2
127
-
128
- # Read 8 bytes at a time
129
- image_offset = 0
130
- for c0_lo, c0_hi, c1_lo, c1_hi, b0, b1, b2, b3 in split_8byte.findall(data):
131
- color0 = ord(c0_lo) | ord(c0_hi) << 8
132
- color1 = ord(c1_lo) | ord(c1_hi) << 8
133
- bits = ord(b0) | ord(b1) << 8 | ord(b2) << 16 | ord(b3) << 24
134
-
135
- r0 = color0 & 0x1f
136
- g0 = (color0 & 0x7e0) >> 5
137
- b0 = (color0 & 0xf800) >> 11
138
- r1 = color1 & 0x1f
139
- g1 = (color1 & 0x7e0) >> 5
140
- b1 = (color1 & 0xf800) >> 11
141
-
142
- # i is the dest ptr for this block
143
- i = image_offset
144
- for y in range(4):
145
- for x in range(4):
146
- code = bits & 0x3
147
- a = 255
148
-
149
- if code == 0:
150
- r, g, b = r0, g0, b0
151
- elif code == 1:
152
- r, g, b = r1, g1, b1
153
- elif code == 3 and color0 <= color1:
154
- r = g = b = a = 0
155
- else:
156
- if code == 2 and color0 > color1:
157
- r = (2 * r0 + r1) // 3
158
- g = (2 * g0 + g1) // 3
159
- b = (2 * b0 + b1) // 3
160
- elif code == 3 and color0 > color1:
161
- r = (r0 + 2 * r1) // 3
162
- g = (g0 + 2 * g1) // 3
163
- b = (b0 + 2 * b1) // 3
164
- else:
165
- assert code == 2 and color0 <= color1
166
- r = (r0 + r1) // 2
167
- g = (g0 + g1) // 2
168
- b = (b0 + b1) // 2
169
-
170
- out[i] = b << 3
171
- out[i + 1] = g << 2
172
- out[i + 2] = r << 3
173
- out[i + 3] = a << 4
174
-
175
- bits >>= 2
176
- i += 4
177
- i += pitch - 16
178
-
179
- # Move dest ptr to next 4x4 block
180
- advance_row = (image_offset + 16) % pitch == 0
181
- image_offset += pitch * 3 * advance_row + 16
182
-
183
- return PackedImageData(width, height, GL_RGBA, GL_UNSIGNED_BYTE, out)
184
-
185
-
186
- def decode_dxt3(data, width, height):
187
- # Decode to GL_RGBA
188
- out = (ctypes.c_ubyte * (width * height * 4))()
189
- pitch = width << 2
190
-
191
- # Read 16 bytes at a time
192
- image_offset = 0
193
- for (a0, a1, a2, a3, a4, a5, a6, a7,
194
- c0_lo, c0_hi, c1_lo, c1_hi,
195
- b0, b1, b2, b3) in split_16byte.findall(data):
196
- color0 = ord(c0_lo) | ord(c0_hi) << 8
197
- color1 = ord(c1_lo) | ord(c1_hi) << 8
198
- bits = ord(b0) | ord(b1) << 8 | ord(b2) << 16 | ord(b3) << 24
199
- alpha = ord(a0) | ord(a1) << 8 | ord(a2) << 16 | ord(a3) << 24 | \
200
- ord(a4) << 32 | ord(a5) << 40 | ord(a6) << 48 | ord(a7) << 56
201
-
202
- r0 = color0 & 0x1f
203
- g0 = (color0 & 0x7e0) >> 5
204
- b0 = (color0 & 0xf800) >> 11
205
- r1 = color1 & 0x1f
206
- g1 = (color1 & 0x7e0) >> 5
207
- b1 = (color1 & 0xf800) >> 11
208
-
209
- # i is the dest ptr for this block
210
- i = image_offset
211
- for y in range(4):
212
- for x in range(4):
213
- code = bits & 0x3
214
- a = alpha & 0xf
215
-
216
- if code == 0:
217
- r, g, b = r0, g0, b0
218
- elif code == 1:
219
- r, g, b = r1, g1, b1
220
- elif code == 3 and color0 <= color1:
221
- r = g = b = 0
222
- else:
223
- if code == 2 and color0 > color1:
224
- r = (2 * r0 + r1) // 3
225
- g = (2 * g0 + g1) // 3
226
- b = (2 * b0 + b1) // 3
227
- elif code == 3 and color0 > color1:
228
- r = (r0 + 2 * r1) // 3
229
- g = (g0 + 2 * g1) // 3
230
- b = (b0 + 2 * b1) // 3
231
- else:
232
- assert code == 2 and color0 <= color1
233
- r = (r0 + r1) // 2
234
- g = (g0 + g1) // 2
235
- b = (b0 + b1) // 2
236
-
237
- out[i] = b << 3
238
- out[i + 1] = g << 2
239
- out[i + 2] = r << 3
240
- out[i + 3] = a << 4
241
-
242
- bits >>= 2
243
- alpha >>= 4
244
- i += 4
245
- i += pitch - 16
246
-
247
- # Move dest ptr to next 4x4 block
248
- advance_row = (image_offset + 16) % pitch == 0
249
- image_offset += pitch * 3 * advance_row + 16
250
-
251
- return PackedImageData(width, height, GL_RGBA, GL_UNSIGNED_BYTE, out)
252
-
253
-
254
- def decode_dxt5(data, width, height):
255
- # Decode to GL_RGBA
256
- out = (ctypes.c_ubyte * (width * height * 4))()
257
- pitch = width << 2
258
-
259
- # Read 16 bytes at a time
260
- image_offset = 0
261
- for (alpha0, alpha1, ab0, ab1, ab2, ab3, ab4, ab5,
262
- c0_lo, c0_hi, c1_lo, c1_hi,
263
- b0, b1, b2, b3) in split_16byte.findall(data):
264
- color0 = ord(c0_lo) | ord(c0_hi) << 8
265
- color1 = ord(c1_lo) | ord(c1_hi) << 8
266
- alpha0 = ord(alpha0)
267
- alpha1 = ord(alpha1)
268
- bits = ord(b0) | ord(b1) << 8 | ord(b2) << 16 | ord(b3) << 24
269
- abits = ord(ab0) | ord(ab1) << 8 | ord(ab2) << 16 | ord(ab3) << 24 | \
270
- ord(ab4) << 32 | ord(ab5) << 40
271
-
272
- r0 = color0 & 0x1f
273
- g0 = (color0 & 0x7e0) >> 5
274
- b0 = (color0 & 0xf800) >> 11
275
- r1 = color1 & 0x1f
276
- g1 = (color1 & 0x7e0) >> 5
277
- b1 = (color1 & 0xf800) >> 11
278
-
279
- # i is the dest ptr for this block
280
- i = image_offset
281
- for y in range(4):
282
- for x in range(4):
283
- code = bits & 0x3
284
- acode = abits & 0x7
285
-
286
- if code == 0:
287
- r, g, b = r0, g0, b0
288
- elif code == 1:
289
- r, g, b = r1, g1, b1
290
- elif code == 3 and color0 <= color1:
291
- r = g = b = 0
292
- else:
293
- if code == 2 and color0 > color1:
294
- r = (2 * r0 + r1) // 3
295
- g = (2 * g0 + g1) // 3
296
- b = (2 * b0 + b1) // 3
297
- elif code == 3 and color0 > color1:
298
- r = (r0 + 2 * r1) // 3
299
- g = (g0 + 2 * g1) // 3
300
- b = (b0 + 2 * b1) // 3
301
- else:
302
- assert code == 2 and color0 <= color1
303
- r = (r0 + r1) / 2
304
- g = (g0 + g1) / 2
305
- b = (b0 + b1) / 2
306
-
307
- if acode == 0:
308
- a = alpha0
309
- elif acode == 1:
310
- a = alpha1
311
- elif alpha0 > alpha1:
312
- if acode == 2:
313
- a = (6 * alpha0 + 1 * alpha1) // 7
314
- elif acode == 3:
315
- a = (5 * alpha0 + 2 * alpha1) // 7
316
- elif acode == 4:
317
- a = (4 * alpha0 + 3 * alpha1) // 7
318
- elif acode == 5:
319
- a = (3 * alpha0 + 4 * alpha1) // 7
320
- elif acode == 6:
321
- a = (2 * alpha0 + 5 * alpha1) // 7
322
- else:
323
- assert acode == 7
324
- a = (1 * alpha0 + 6 * alpha1) // 7
325
- else:
326
- if acode == 2:
327
- a = (4 * alpha0 + 1 * alpha1) // 5
328
- elif acode == 3:
329
- a = (3 * alpha0 + 2 * alpha1) // 5
330
- elif acode == 4:
331
- a = (2 * alpha0 + 3 * alpha1) // 5
332
- elif acode == 5:
333
- a = (1 * alpha0 + 4 * alpha1) // 5
334
- elif acode == 6:
335
- a = 0
336
- else:
337
- assert acode == 7
338
- a = 255
339
-
340
- out[i] = b << 3
341
- out[i + 1] = g << 2
342
- out[i + 2] = r << 3
343
- out[i + 3] = a
344
-
345
- bits >>= 2
346
- abits >>= 3
347
- i += 4
348
- i += pitch - 16
349
-
350
- # Move dest ptr to next 4x4 block
351
- advance_row = (image_offset + 16) % pitch == 0
352
- image_offset += pitch * 3 * advance_row + 16
353
-
354
- return PackedImageData(width, height, GL_RGBA, GL_UNSIGNED_BYTE, out)