Skip to content

Commit f2d7d04

Browse files
committed
revert arcade.gl changes to reduce merge issues for gl abstraction PR
1 parent 3d76777 commit f2d7d04

13 files changed

Lines changed: 108 additions & 90 deletions

arcade/gl/buffer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def size(self) -> int:
100100
return self._size
101101

102102
@property
103-
def ctx(self) -> Context:
103+
def ctx(self) -> "Context":
104104
"""The context this resource belongs to."""
105105
return self._ctx
106106

@@ -163,9 +163,11 @@ def read(self, size: int = -1, offset: int = 0) -> bytes:
163163
# Manually detect this so it doesn't raise a confusing INVALID_VALUE error
164164
if size + offset > self._size:
165165
raise ValueError(
166-
"Attempting to read outside the buffer. "
167-
f"Buffer size: {self._size} "
168-
f"Reading from {offset} to {size + offset}"
166+
(
167+
"Attempting to read outside the buffer. "
168+
f"Buffer size: {self._size} "
169+
f"Reading from {offset} to {size + offset}"
170+
)
169171
)
170172

171173
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._glo)

arcade/gl/compute_shader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self, ctx: Context, glsl_source: str) -> None:
8686
gl.glGetProgramiv(self._glo, gl.GL_INFO_LOG_LENGTH, length)
8787
log = c_buffer(length.value)
8888
gl.glGetProgramInfoLog(self._glo, len(log), None, log)
89-
raise ShaderException(f"Program link error: {log.value.decode()}")
89+
raise ShaderException("Program link error: {}".format(log.value.decode()))
9090

9191
self._introspect_uniforms()
9292
self._introspect_uniform_blocks()

arcade/gl/context.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
import logging
44
import weakref
55
from collections import deque
6-
from collections.abc import Iterable, Sequence
76
from contextlib import contextmanager
87
from ctypes import c_char_p, c_float, c_int, cast
98
from typing import (
109
Any,
10+
Deque,
11+
Dict,
12+
Iterable,
13+
List,
1114
Literal,
15+
Sequence,
16+
Set,
17+
Tuple,
1218
overload,
1319
)
1420

@@ -267,9 +273,9 @@ def __init__(
267273
gl.glEnable(gl.GL_SCISSOR_TEST)
268274

269275
# States
270-
self._blend_func: tuple[int, int] | tuple[int, int, int, int] = self.BLEND_DEFAULT
276+
self._blend_func: Tuple[int, int] | Tuple[int, int, int, int] = self.BLEND_DEFAULT
271277
self._point_size = 1.0
272-
self._flags: set[int] = set()
278+
self._flags: Set[int] = set()
273279
self._wireframe = False
274280
# Options for cull_face
275281
self._cull_face_options = {
@@ -288,7 +294,7 @@ def __init__(
288294
self.gc_mode = gc_mode
289295
#: Collected objects to gc when gc_mode is "context_gc".
290296
#: This can be used during debugging.
291-
self.objects: deque[Any] = deque()
297+
self.objects: Deque[Any] = deque()
292298

293299
@property
294300
def info(self) -> GLInfo:
@@ -365,7 +371,7 @@ def fbo(self) -> Framebuffer:
365371
return self.active_framebuffer
366372

367373
@property
368-
def gl_version(self) -> tuple[int, int]:
374+
def gl_version(self) -> Tuple[int, int]:
369375
"""
370376
The OpenGL major and minor version as a tuple.
371377
@@ -578,7 +584,7 @@ def is_enabled(self, flag) -> bool:
578584
return flag in self._flags
579585

580586
@property
581-
def viewport(self) -> tuple[int, int, int, int]:
587+
def viewport(self) -> Tuple[int, int, int, int]:
582588
"""
583589
Get or set the viewport for the currently active framebuffer.
584590
The viewport simply describes what pixels of the screen
@@ -595,11 +601,11 @@ def viewport(self) -> tuple[int, int, int, int]:
595601
return self.active_framebuffer.viewport
596602

597603
@viewport.setter
598-
def viewport(self, value: tuple[int, int, int, int]):
604+
def viewport(self, value: Tuple[int, int, int, int]):
599605
self.active_framebuffer.viewport = value
600606

601607
@property
602-
def scissor(self) -> tuple[int, int, int, int] | None:
608+
def scissor(self) -> Tuple[int, int, int, int] | None:
603609
"""
604610
Get or set the scissor box for the active framebuffer.
605611
This is a shortcut for :py:meth:`~arcade.gl.Framebuffer.scissor`.
@@ -624,7 +630,7 @@ def scissor(self, value):
624630
self.fbo.scissor = value
625631

626632
@property
627-
def blend_func(self) -> tuple[int, int] | tuple[int, int, int, int]:
633+
def blend_func(self) -> Tuple[int, int] | Tuple[int, int, int, int]:
628634
"""
629635
Get or set the blend function.
630636
This is tuple specifying how the color and
@@ -672,7 +678,7 @@ def blend_func(self) -> tuple[int, int] | tuple[int, int, int, int]:
672678
return self._blend_func
673679

674680
@blend_func.setter
675-
def blend_func(self, value: tuple[int, int] | tuple[int, int, int, int]):
681+
def blend_func(self, value: Tuple[int, int] | Tuple[int, int, int, int]):
676682
self._blend_func = value
677683
if len(value) == 2:
678684
gl.glBlendFunc(*value)
@@ -946,7 +952,7 @@ def buffer(
946952
def framebuffer(
947953
self,
948954
*,
949-
color_attachments: Texture2D | list[Texture2D] | None = None,
955+
color_attachments: Texture2D | List[Texture2D] | None = None,
950956
depth_attachment: Texture2D | None = None,
951957
) -> Framebuffer:
952958
"""Create a Framebuffer.
@@ -963,14 +969,14 @@ def framebuffer(
963969

964970
def texture(
965971
self,
966-
size: tuple[int, int],
972+
size: Tuple[int, int],
967973
*,
968974
components: int = 4,
969975
dtype: str = "f1",
970976
data: BufferProtocol | None = None,
971977
wrap_x: PyGLenum | None = None,
972978
wrap_y: PyGLenum | None = None,
973-
filter: tuple[PyGLenum, PyGLenum] | None = None,
979+
filter: Tuple[PyGLenum, PyGLenum] | None = None,
974980
samples: int = 0,
975981
immutable: bool = False,
976982
internal_format: PyGLenum | None = None,
@@ -1066,14 +1072,14 @@ def texture(
10661072

10671073
def texture_array(
10681074
self,
1069-
size: tuple[int, int, int],
1075+
size: Tuple[int, int, int],
10701076
*,
10711077
components: int = 4,
10721078
dtype: str = "f1",
10731079
data: BufferProtocol | None = None,
10741080
wrap_x: PyGLenum | None = None,
10751081
wrap_y: PyGLenum | None = None,
1076-
filter: tuple[PyGLenum, PyGLenum] | None = None,
1082+
filter: Tuple[PyGLenum, PyGLenum] | None = None,
10771083
) -> TextureArray:
10781084
"""
10791085
Create a 2D Texture Array.
@@ -1099,7 +1105,7 @@ def texture_array(
10991105
)
11001106

11011107
def depth_texture(
1102-
self, size: tuple[int, int], *, data: BufferProtocol | None = None
1108+
self, size: Tuple[int, int], *, data: BufferProtocol | None = None
11031109
) -> Texture2D:
11041110
"""
11051111
Create a 2D depth texture. Can be used as a depth attachment
@@ -1223,8 +1229,8 @@ def program(
12231229
geometry_shader: str | None = None,
12241230
tess_control_shader: str | None = None,
12251231
tess_evaluation_shader: str | None = None,
1226-
common: list[str] | None = None,
1227-
defines: dict[str, str] | None = None,
1232+
common: List[str] | None = None,
1233+
defines: Dict[str, str] | None = None,
12281234
varyings: Sequence[str] | None = None,
12291235
varyings_capture_mode: str = "interleaved",
12301236
) -> Program:
@@ -1284,7 +1290,7 @@ def program(
12841290

12851291
# If we don't have a fragment shader we are doing transform feedback.
12861292
# When a geometry shader is present the out attributes will be located there
1287-
out_attributes = list(varyings) if varyings is not None else []
1293+
out_attributes = list(varyings) if varyings is not None else [] # type: List[str]
12881294
if not source_fs and not out_attributes:
12891295
if source_geo:
12901296
out_attributes = source_geo.out_attributes
@@ -1583,7 +1589,7 @@ def __init__(self, ctx):
15831589
self.MAX_TEXTURE_MAX_ANISOTROPY = self.get_float(gl.GL_MAX_TEXTURE_MAX_ANISOTROPY, 1.0)
15841590
"""The highest supported anisotropy value. Usually 8.0 or 16.0."""
15851591

1586-
self.MAX_VIEWPORT_DIMS: tuple[int, int] = self.get_int_tuple(gl.GL_MAX_VIEWPORT_DIMS, 2)
1592+
self.MAX_VIEWPORT_DIMS: Tuple[int, int] = self.get_int_tuple(gl.GL_MAX_VIEWPORT_DIMS, 2)
15871593
"""
15881594
The maximum support window or framebuffer viewport.
15891595
This is usually the same as the maximum texture size
@@ -1607,10 +1613,10 @@ def __init__(self, ctx):
16071613
warn("Error happened while querying of limits. Moving on ..")
16081614

16091615
@overload
1610-
def get_int_tuple(self, enum: GLenumLike, length: Literal[2]) -> tuple[int, int]: ...
1616+
def get_int_tuple(self, enum: GLenumLike, length: Literal[2]) -> Tuple[int, int]: ...
16111617

16121618
@overload
1613-
def get_int_tuple(self, enum: GLenumLike, length: int) -> tuple[int, ...]: ...
1619+
def get_int_tuple(self, enum: GLenumLike, length: int) -> Tuple[int, ...]: ...
16141620

16151621
def get_int_tuple(self, enum: GLenumLike, length: int):
16161622
"""

arcade/gl/framebuffer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from __future__ import annotations
22

33
import weakref
4-
from collections.abc import Generator
54
from contextlib import contextmanager
65
from ctypes import Array, c_int, c_uint, string_at
7-
from typing import TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Generator
87

98
from pyglet import gl
109

@@ -68,7 +67,7 @@ class Framebuffer:
6867

6968
def __init__(
7069
self,
71-
ctx: Context,
70+
ctx: "Context",
7271
*,
7372
color_attachments: Texture2D | list[Texture2D],
7473
depth_attachment: Texture2D | None = None,
@@ -213,7 +212,7 @@ def _set_scissor(self, value):
213212
scissor = property(_get_scissor, _set_scissor)
214213

215214
@property
216-
def ctx(self) -> Context:
215+
def ctx(self) -> "Context":
217216
"""The context this object belongs to."""
218217
return self._ctx
219218

@@ -519,7 +518,7 @@ def _check_completeness() -> None:
519518
)
520519

521520
def __repr__(self):
522-
return f"<Framebuffer glo={self._glo.value}>"
521+
return "<Framebuffer glo={}>".format(self._glo.value)
523522

524523

525524
class DefaultFrameBuffer(Framebuffer):
@@ -542,7 +541,7 @@ class DefaultFrameBuffer(Framebuffer):
542541

543542
__slots__ = ()
544543

545-
def __init__(self, ctx: Context):
544+
def __init__(self, ctx: "Context"):
546545
self._ctx = ctx
547546
# TODO: Can we query this?
548547
self._samples = 0

arcade/gl/glsl.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
2-
from collections.abc import Iterable
3-
from typing import TYPE_CHECKING
2+
from typing import TYPE_CHECKING, Iterable
43

54
from pyglet import gl
65

@@ -125,10 +124,12 @@ def _find_glsl_version(self) -> int:
125124
source = "\n".join(f"{str(i + 1).zfill(3)}: {line} " for i, line in enumerate(self._lines))
126125

127126
raise ShaderException(
128-
"Cannot find #version in shader source. "
129-
"Please provide at least a #version 330 statement in the beginning of the shader.\n"
130-
f"---- [{SHADER_TYPE_NAMES[self._type]}] ---\n"
131-
f"{source}"
127+
(
128+
"Cannot find #version in shader source. "
129+
"Please provide at least a #version 330 statement in the beginning of the shader.\n"
130+
f"---- [{SHADER_TYPE_NAMES[self._type]}] ---\n"
131+
f"{source}"
132+
)
132133
)
133134

134135
@staticmethod
@@ -150,7 +151,7 @@ def apply_defines(lines: list[str], defines: dict[str, str]) -> list[str]:
150151
if value is None:
151152
continue
152153

153-
lines[nr] = f"#define {name} {str(value)}"
154+
lines[nr] = "#define {} {}".format(name, str(value))
154155
except IndexError:
155156
pass
156157

arcade/gl/program.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import typing
22
import weakref
3-
from collections.abc import Iterable
43
from ctypes import (
54
POINTER,
65
byref,
@@ -12,7 +11,7 @@
1211
create_string_buffer,
1312
pointer,
1413
)
15-
from typing import TYPE_CHECKING, Any
14+
from typing import TYPE_CHECKING, Any, Iterable
1615

1716
from pyglet import gl
1817

@@ -546,7 +545,7 @@ def link(glo):
546545
gl.glGetProgramiv(glo, gl.GL_INFO_LOG_LENGTH, length)
547546
log = c_buffer(length.value)
548547
gl.glGetProgramInfoLog(glo, len(log), None, log)
549-
raise ShaderException(f"Program link error: {log.value.decode()}")
548+
raise ShaderException("Program link error: {}".format(log.value.decode()))
550549

551550
def __repr__(self):
552-
return f"<Program id={self._glo}>"
551+
return "<Program id={}>".format(self._glo)

arcade/gl/sampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Sampler:
2222

2323
def __init__(
2424
self,
25-
ctx: Context,
25+
ctx: "Context",
2626
texture: Texture2D,
2727
*,
2828
filter: tuple[PyGLuint, PyGLuint] | None = None,

arcade/gl/texture.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ def _texture_2d(self, data):
303303
)
304304
except gl.GLException as ex:
305305
raise gl.GLException(
306-
f"Unable to create texture: {ex} : dtype={self._dtype} "
307-
f"size={self.size} components={self._components} "
308-
f"MAX_TEXTURE_SIZE = {self.ctx.info.MAX_TEXTURE_SIZE}"
309-
f": {ex}"
306+
(
307+
f"Unable to create texture: {ex} : dtype={self._dtype} "
308+
f"size={self.size} components={self._components} "
309+
f"MAX_TEXTURE_SIZE = {self.ctx.info.MAX_TEXTURE_SIZE}"
310+
f": {ex}"
311+
)
310312
)
311313

312314
@property
@@ -754,7 +756,7 @@ def delete(self):
754756
self._glo.value = 0
755757

756758
@staticmethod
757-
def delete_glo(ctx: Context, glo: gl.GLuint):
759+
def delete_glo(ctx: "Context", glo: gl.GLuint):
758760
"""
759761
Destroy the texture.
760762
@@ -854,8 +856,6 @@ def get_handle(self, resident: bool = True) -> int:
854856
return handle
855857

856858
def __repr__(self) -> str:
857-
return (
858-
f"<Texture glo={self._glo.value} "
859-
f"size={self._width}x{self._height} "
860-
f"components={self._components}>"
859+
return "<Texture glo={} size={}x{} components={}>".format(
860+
self._glo.value, self._width, self._height, self._components
861861
)

0 commit comments

Comments
 (0)