Skip to content

Commit ff46e51

Browse files
committed
Update to current pyglet dev branch
1 parent 1821e87 commit ff46e51

File tree

12 files changed

+94
-30
lines changed

12 files changed

+94
-30
lines changed

arcade/context.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@ def __init__(
9090
)
9191
self.sprite_list_program_no_cull["sprite_texture"] = 0
9292
self.sprite_list_program_no_cull["uv_texture"] = 1
93+
94+
self.sprite_list_program_cull: Program = self.load_program(
95+
vertex_shader=":system:shaders/sprites/sprite_list_geometry_vs.glsl",
96+
geometry_shader=":system:shaders/sprites/sprite_list_geometry_cull_geo.glsl",
97+
fragment_shader=":system:shaders/sprites/sprite_list_geometry_fs.glsl",
98+
)
99+
self.sprite_list_program_cull["sprite_texture"] = 0
100+
self.sprite_list_program_cull["uv_texture"] = 1
93101
else:
94102
self.sprite_list_program_no_cull = None # type: ignore
103+
self.sprite_list_program_cull = None # type: ignore
95104

96105
self.sprite_list_program_no_geo = self.load_program(
97106
vertex_shader=":system:shaders/sprites/sprite_list_simple_vs.glsl",
@@ -244,7 +253,10 @@ def __init__(
244253
["in_vert"],
245254
),
246255
BufferDescription(
247-
self.shape_line_buffer_pos, "4f", ["in_instance_pos"], instanced=True
256+
self.shape_line_buffer_pos,
257+
"4f",
258+
["in_instance_pos"],
259+
instanced=True,
248260
),
249261
],
250262
mode=self.TRIANGLE_STRIP,
@@ -320,12 +332,8 @@ def bind_window_block(self) -> None:
320332
This should always be bound to index 0 so all shaders
321333
have access to them.
322334
"""
323-
gl.glBindBufferRange(
324-
gl.GL_UNIFORM_BUFFER,
325-
0,
326-
self._window_block.buffer.id,
327-
0, # type: ignore
328-
128, # 32 x 32bit floats (two mat4) # type: ignore
335+
raise NotImplementedError(
336+
"The currently selected GL backend does not implement ArcadeContext.bind_window_block"
329337
)
330338

331339
@property

arcade/gl/backends/opengl/buffer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ctypes import byref, string_at
55
from typing import TYPE_CHECKING
66

7+
from pyglet.graphics import core
78
from pyglet.graphics.api import gl
89

910
from arcade.gl.buffer import Buffer, _usages
@@ -114,7 +115,7 @@ def delete_glo(ctx: Context, glo: gl.GLuint):
114115
The OpenGL buffer id
115116
"""
116117
# If we have no context, then we are shutting down, so skip this
117-
if gl.current_context is None:
118+
if core.current_context is None:
118119
return
119120

120121
if glo.value != 0:

arcade/gl/backends/opengl/compute_shader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from typing import TYPE_CHECKING
1616

17+
from pyglet.graphics import core
1718
from pyglet.graphics.api import gl
1819

1920
from arcade.gl.compute_shader import ComputeShader
@@ -188,7 +189,7 @@ def delete_glo(ctx, prog_id):
188189
"""
189190
# Check to see if the context was already cleaned up from program
190191
# shut down. If so, we don't need to delete the shaders.
191-
if gl.current_context is None:
192+
if core.current_context is None:
192193
return
193194

194195
gl.glDeleteProgram(prog_id)

arcade/gl/backends/opengl/context.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class OpenGLContext(Context):
2929
_valid_apis = ("opengl", "opengles")
3030

3131
def __init__(
32-
self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "opengl"
32+
self,
33+
window: pyglet.window.Window,
34+
gc_mode: str = "context_gc",
35+
gl_api: str = "opengl",
3336
):
3437
super().__init__(window, gc_mode)
3538

@@ -221,7 +224,11 @@ def _create_default_framebuffer(self) -> OpenGLDefaultFrameBuffer:
221224
return OpenGLDefaultFrameBuffer(self)
222225

223226
def buffer(
224-
self, *, data: BufferProtocol | None = None, reserve: int = 0, usage: str = "static"
227+
self,
228+
*,
229+
data: BufferProtocol | None = None,
230+
reserve: int = 0,
231+
usage: str = "static",
225232
) -> OpenGLBuffer:
226233
return OpenGLBuffer(self, data, reserve=reserve, usage=usage)
227234

@@ -272,10 +279,10 @@ def program(
272279
return OpenGLProgram(
273280
self,
274281
vertex_shader=source_vs.get_source(defines=defines),
275-
fragment_shader=source_fs.get_source(defines=defines) if source_fs else None,
276-
geometry_shader=source_geo.get_source(defines=defines) if source_geo else None,
277-
tess_control_shader=source_tc.get_source(defines=defines) if source_tc else None,
278-
tess_evaluation_shader=source_te.get_source(defines=defines) if source_te else None,
282+
fragment_shader=(source_fs.get_source(defines=defines) if source_fs else None),
283+
geometry_shader=(source_geo.get_source(defines=defines) if source_geo else None),
284+
tess_control_shader=(source_tc.get_source(defines=defines) if source_tc else None),
285+
tess_evaluation_shader=(source_te.get_source(defines=defines) if source_te else None),
279286
varyings=out_attributes,
280287
varyings_capture_mode=varyings_capture_mode,
281288
)
@@ -345,7 +352,9 @@ def framebuffer(
345352
depth_attachment: OpenGLTexture2D | None = None,
346353
) -> OpenGLFramebuffer:
347354
return OpenGLFramebuffer(
348-
self, color_attachments=color_attachments or [], depth_attachment=depth_attachment
355+
self,
356+
color_attachments=color_attachments or [],
357+
depth_attachment=depth_attachment,
349358
)
350359

351360
def copy_framebuffer(
@@ -424,6 +433,15 @@ def __init__(self, *args, **kwargs):
424433
OpenGLContext.__init__(self, *args, **kwargs)
425434
ArcadeContext.__init__(self, *args, **kwargs)
426435

436+
def bind_window_block(self):
437+
gl.glBindBufferRange(
438+
gl.GL_UNIFORM_BUFFER,
439+
0,
440+
self._window_block.buffer.id,
441+
0, # type: ignore
442+
128, # 32 x 32bit floats (two mat4) # type: ignore
443+
)
444+
427445

428446
class OpenGLInfo(Info):
429447
"""OpenGL info and capabilities"""

arcade/gl/backends/opengl/framebuffer.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ctypes import Array, c_int, c_uint, string_at
55
from typing import TYPE_CHECKING
66

7+
from pyglet.graphics import core
78
from pyglet.graphics.api import gl
89

910
from arcade.gl.framebuffer import DefaultFrameBuffer, Framebuffer
@@ -208,12 +209,22 @@ def clear(
208209
if len(color) == 3:
209210
clear_color = color[0] / 255, color[1] / 255, color[2] / 255, 1.0
210211
elif len(color) == 4:
211-
clear_color = color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255
212+
clear_color = (
213+
color[0] / 255,
214+
color[1] / 255,
215+
color[2] / 255,
216+
color[3] / 255,
217+
)
212218
else:
213219
raise ValueError("Color should be a 3 or 4 component tuple")
214220
elif color_normalized is not None:
215221
if len(color_normalized) == 3:
216-
clear_color = color_normalized[0], color_normalized[1], color_normalized[2], 1.0
222+
clear_color = (
223+
color_normalized[0],
224+
color_normalized[1],
225+
color_normalized[2],
226+
1.0,
227+
)
217228
elif len(color_normalized) == 4:
218229
clear_color = color_normalized
219230
else:
@@ -304,7 +315,7 @@ def delete_glo(ctx, framebuffer_id):
304315
framebuffer_id:
305316
Framebuffer id destroy (glo)
306317
"""
307-
if gl.current_context is None:
318+
if core.current_context is None:
308319
return
309320

310321
gl.glDeleteFramebuffers(1, framebuffer_id)

arcade/gl/backends/opengl/program.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from typing import TYPE_CHECKING, Any, Iterable
1717

18+
from pyglet.graphics import core
1819
from pyglet.graphics.api import gl
1920

2021
from arcade.gl.exceptions import ShaderException
@@ -256,7 +257,7 @@ def delete_glo(ctx, prog_id):
256257
"""
257258
# Check to see if the context was already cleaned up from program
258259
# shut down. If so, we don't need to delete the shaders.
259-
if gl.current_context is None:
260+
if core.current_context is None:
260261
return
261262

262263
gl.glDeleteProgram(prog_id)

arcade/gl/backends/opengl/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import weakref
44
from typing import TYPE_CHECKING
55

6+
from pyglet.graphics import core
67
from pyglet.graphics.api import gl
78

89
from arcade.gl.query import Query
@@ -118,7 +119,7 @@ def delete_glo(ctx, glos) -> None:
118119
119120
This is automatically called when the object is garbage collected.
120121
"""
121-
if gl.current_context is None:
122+
if core.current_context is None:
122123
return
123124

124125
for glo in glos:

arcade/gl/backends/opengl/texture.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ctypes import byref, string_at
55
from typing import TYPE_CHECKING
66

7+
from pyglet.graphics import core
78
from pyglet.graphics.api import gl
89

910
from arcade.gl.texture import Texture2D
@@ -658,7 +659,7 @@ def delete_glo(ctx: "Context", glo: gl.GLuint):
658659
glo: The OpenGL texture id
659660
"""
660661
# If we have no context, then we are shutting down, so skip this
661-
if gl.current_context is None:
662+
if core.current_context is None:
662663
return
663664

664665
if glo.value != 0:

arcade/gl/backends/opengl/texture_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ctypes import byref, string_at
55
from typing import TYPE_CHECKING
66

7+
from pyglet.graphics import core
78
from pyglet.graphics.api import gl
89

910
from arcade.gl.texture_array import TextureArray
@@ -602,7 +603,7 @@ def delete_glo(ctx: "Context", glo: gl.GLuint):
602603
glo: The OpenGL texture id
603604
"""
604605
# If we have no context, then we are shutting down, so skip this
605-
if gl.current_context is None:
606+
if core.current_context is None:
606607
return
607608

608609
if glo.value != 0:

arcade/gl/backends/opengl/vertex_array.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from ctypes import byref, c_void_p
55
from typing import TYPE_CHECKING, Sequence
66

7+
from pyglet.graphics import core
78
from pyglet.graphics.api import gl
89

910
from arcade.gl.types import BufferDescription, GLenumLike, GLuintLike, gl_name
@@ -97,7 +98,7 @@ def delete_glo(ctx: Context, glo: gl.GLuint) -> None:
9798
This is automatically called when this object is garbage collected.
9899
"""
99100
# If we have no context, then we are shutting down, so skip this
100-
if gl.current_context is None:
101+
if core.current_context is None:
101102
return
102103

103104
if glo.value != 0:
@@ -107,7 +108,10 @@ def delete_glo(ctx: Context, glo: gl.GLuint) -> None:
107108
ctx.stats.decr("vertex_array")
108109

109110
def _build(
110-
self, program: Program, content: Sequence[BufferDescription], index_buffer: Buffer | None
111+
self,
112+
program: Program,
113+
content: Sequence[BufferDescription],
114+
index_buffer: Buffer | None,
111115
) -> None:
112116
"""
113117
Build a vertex array compatible with the program passed in.

0 commit comments

Comments
 (0)