Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions arcade/gl/backends/opengl/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ def read(self, size: int = -1, offset: int = 0) -> bytes:
# Manually detect this so it doesn't raise a confusing INVALID_VALUE error
if size + offset > self._size:
raise ValueError(
(
"Attempting to read outside the buffer. "
f"Buffer size: {self._size} "
f"Reading from {offset} to {size + offset}"
)
"Attempting to read outside the buffer. "
f"Buffer size: {self._size} "
f"Reading from {offset} to {size + offset}"
)

gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._glo)
Expand Down
2 changes: 1 addition & 1 deletion arcade/gl/backends/opengl/compute_shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, ctx: Context, glsl_source: str) -> None:
gl.glGetProgramiv(self._glo, gl.GL_INFO_LOG_LENGTH, length)
log = c_buffer(length.value)
gl.glGetProgramInfoLog(self._glo, len(log), None, log)
raise ShaderException("Program link error: {}".format(log.value.decode()))
raise ShaderException(f"Program link error: {log.value.decode()}")

self._introspect_uniforms()
self._introspect_uniform_blocks()
Expand Down
22 changes: 11 additions & 11 deletions arcade/gl/backends/opengl/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterable, Sequence
from ctypes import c_char_p, c_float, c_int, cast
from typing import Dict, Iterable, List, Sequence, Tuple

import pyglet
from pyglet import gl
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(
gl.glEnable(gl.GL_SCISSOR_TEST)

@property
def gl_version(self) -> Tuple[int, int]:
def gl_version(self) -> tuple[int, int]:
"""
The OpenGL major and minor version as a tuple.

Expand Down Expand Up @@ -136,7 +136,7 @@ def disable(self, *args):
gl.glDisable(flag)

@Context.blend_func.setter
def blend_func(self, value: Tuple[int, int] | Tuple[int, int, int, int]):
def blend_func(self, value: tuple[int, int] | tuple[int, int, int, int]):
self._blend_func = value
if len(value) == 2:
gl.glBlendFunc(*value)
Expand Down Expand Up @@ -225,8 +225,8 @@ def program(
geometry_shader: str | None = None,
tess_control_shader: str | None = None,
tess_evaluation_shader: str | None = None,
common: List[str] | None = None,
defines: Dict[str, str] | None = None,
common: list[str] | None = None,
defines: dict[str, str] | None = None,
varyings: Sequence[str] | None = None,
varyings_capture_mode: str = "interleaved",
) -> OpenGLProgram:
Expand Down Expand Up @@ -293,14 +293,14 @@ def compute_shader(self, *, source: str, common: Iterable[str] = ()) -> OpenGLCo

def texture(
self,
size: Tuple[int, int],
size: tuple[int, int],
*,
components: int = 4,
dtype: str = "f1",
data: BufferProtocol | None = None,
wrap_x: PyGLenum | None = None,
wrap_y: PyGLenum | None = None,
filter: Tuple[PyGLenum, PyGLenum] | None = None,
filter: tuple[PyGLenum, PyGLenum] | None = None,
samples: int = 0,
immutable: bool = False,
internal_format: PyGLenum | None = None,
Expand All @@ -326,14 +326,14 @@ def texture(
)

def depth_texture(
self, size: Tuple[int, int], *, data: BufferProtocol | None = None
self, size: tuple[int, int], *, data: BufferProtocol | None = None
) -> OpenGLTexture2D:
return OpenGLTexture2D(self, size, data=data, depth=True)

def framebuffer(
self,
*,
color_attachments: OpenGLTexture2D | List[OpenGLTexture2D] | None = None,
color_attachments: OpenGLTexture2D | list[OpenGLTexture2D] | None = None,
depth_attachment: OpenGLTexture2D | None = None,
) -> OpenGLFramebuffer:
return OpenGLFramebuffer(
Expand Down Expand Up @@ -387,14 +387,14 @@ def sampler(self, texture: OpenGLTexture2D) -> OpenGLSampler:

def texture_array(
self,
size: Tuple[int, int, int],
size: tuple[int, int, int],
*,
components: int = 4,
dtype: str = "f1",
data: BufferProtocol | None = None,
wrap_x: PyGLenum | None = None,
wrap_y: PyGLenum | None = None,
filter: Tuple[PyGLenum, PyGLenum] | None = None,
filter: tuple[PyGLenum, PyGLenum] | None = None,
) -> OpenGLTextureArray:
return OpenGLTextureArray(
self,
Expand Down
6 changes: 3 additions & 3 deletions arcade/gl/backends/opengl/framebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class OpenGLFramebuffer(Framebuffer):

def __init__(
self,
ctx: "Context",
ctx: Context,
*,
color_attachments: OpenGLTexture2D | list[OpenGLTexture2D],
depth_attachment: OpenGLTexture2D | None = None,
Expand Down Expand Up @@ -336,7 +336,7 @@ def _check_completeness() -> None:
)

def __repr__(self):
return "<Framebuffer glo={}>".format(self._glo.value)
return f"<Framebuffer glo={self._glo.value}>"


class OpenGLDefaultFrameBuffer(DefaultFrameBuffer, OpenGLFramebuffer):
Expand All @@ -357,7 +357,7 @@ class OpenGLDefaultFrameBuffer(DefaultFrameBuffer, OpenGLFramebuffer):
is_default = True
"""Is this the default framebuffer? (window buffer)"""

def __init__(self, ctx: "Context"):
def __init__(self, ctx: Context):
super().__init__(ctx)

value = c_int()
Expand Down
15 changes: 7 additions & 8 deletions arcade/gl/backends/opengl/glsl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from typing import TYPE_CHECKING, Iterable
from collections.abc import Iterable
from typing import TYPE_CHECKING

from pyglet import gl

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

raise ShaderException(
(
"Cannot find #version in shader source. "
"Please provide at least a #version 330 statement in the beginning of the shader.\n"
f"---- [{SHADER_TYPE_NAMES[self._type]}] ---\n"
f"{source}"
)
"Cannot find #version in shader source. "
"Please provide at least a #version 330 statement in the beginning of the shader.\n"
f"---- [{SHADER_TYPE_NAMES[self._type]}] ---\n"
f"{source}"
)

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

lines[nr] = "#define {} {}".format(name, str(value))
lines[nr] = f"#define {name} {str(value)}"
except IndexError:
pass

Expand Down
9 changes: 5 additions & 4 deletions arcade/gl/backends/opengl/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import typing
import weakref
from collections.abc import Iterable
from ctypes import (
POINTER,
byref,
Expand All @@ -13,7 +14,7 @@
create_string_buffer,
pointer,
)
from typing import TYPE_CHECKING, Any, Iterable
from typing import TYPE_CHECKING, Any

from pyglet import gl

Expand Down Expand Up @@ -168,7 +169,7 @@ def __del__(self):
self._ctx.objects.append(self)

@property
def ctx(self) -> "Context":
def ctx(self) -> Context:
"""The context this program belongs to."""
return self._ctx

Expand Down Expand Up @@ -542,7 +543,7 @@ def link(glo):
gl.glGetProgramiv(glo, gl.GL_INFO_LOG_LENGTH, length)
log = c_buffer(length.value)
gl.glGetProgramInfoLog(glo, len(log), None, log)
raise ShaderException("Program link error: {}".format(log.value.decode()))
raise ShaderException(f"Program link error: {log.value.decode()}")

def __repr__(self):
return "<Program id={}>".format(self._glo)
return f"<Program id={self._glo}>"
18 changes: 9 additions & 9 deletions arcade/gl/backends/opengl/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,10 @@ def _texture_2d(self, data):
)
except gl.GLException as ex:
raise gl.GLException(
(
f"Unable to create texture: {ex} : dtype={self._dtype} "
f"size={self.size} components={self._components} "
f"MAX_TEXTURE_SIZE = {self.ctx.info.MAX_TEXTURE_SIZE}"
f": {ex}"
)
f"Unable to create texture: {ex} : dtype={self._dtype} "
f"size={self.size} components={self._components} "
f"MAX_TEXTURE_SIZE = {self.ctx.info.MAX_TEXTURE_SIZE}"
f": {ex}"
)

@property
Expand Down Expand Up @@ -647,7 +645,7 @@ def delete(self):
self._glo.value = 0

@staticmethod
def delete_glo(ctx: "Context", glo: gl.GLuint):
def delete_glo(ctx: Context, glo: gl.GLuint):
"""
Destroy the texture.

Expand Down Expand Up @@ -747,6 +745,8 @@ def get_handle(self, resident: bool = True) -> int:
return handle

def __repr__(self) -> str:
return "<Texture glo={} size={}x{} components={}>".format(
self._glo.value, self._width, self._height, self._components
return (
f"<Texture glo={self._glo.value} "
f"size={self._width}x{self._height} "
f"components={self._components}>"
)
18 changes: 9 additions & 9 deletions arcade/gl/backends/opengl/texture_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,10 @@ def _texture_2d_array(self, data):
)
except gl.GLException as ex:
raise gl.GLException(
(
f"Unable to create texture: {ex} : dtype={self._dtype} "
f"size={self.size} components={self._components} "
f"MAX_TEXTURE_SIZE = {self.ctx.info.MAX_TEXTURE_SIZE}"
f": {ex}"
)
f"Unable to create texture: {ex} : dtype={self._dtype} "
f"size={self.size} components={self._components} "
f"MAX_TEXTURE_SIZE = {self.ctx.info.MAX_TEXTURE_SIZE}"
f": {ex}"
)

@property
Expand Down Expand Up @@ -591,7 +589,7 @@ def delete(self):
self._glo.value = 0

@staticmethod
def delete_glo(ctx: "Context", glo: gl.GLuint):
def delete_glo(ctx: Context, glo: gl.GLuint):
"""
Destroy the texture.

Expand Down Expand Up @@ -691,6 +689,8 @@ def get_handle(self, resident: bool = True) -> int:
return handle

def __repr__(self) -> str:
return "<TextureArray glo={} size={}x{}x{} components={}>".format(
self._glo.value, self._width, self._layers, self._height, self._components
return (
f"<TextureArray glo={self._glo.value} "
f"size={self._width}x{self._layers}x{self._height} "
f"components={self._components}>"
)
2 changes: 1 addition & 1 deletion arcade/gl/backends/opengl/uniform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import struct
from collections.abc import Callable
from ctypes import POINTER, c_double, c_float, c_int, c_uint, cast
from typing import Callable

from pyglet import gl

Expand Down
27 changes: 11 additions & 16 deletions arcade/gl/backends/opengl/vertex_array.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import weakref
from collections.abc import Sequence
from ctypes import byref, c_void_p
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING

from pyglet import gl

Expand Down Expand Up @@ -141,20 +142,16 @@ def _build(
buff_descr, attr_descr = descr_attribs[prog_attr.name]
except KeyError:
raise ValueError(
(
f"Program needs attribute '{prog_attr.name}', but is not present in buffer "
f"description. Buffer descriptions: {content}"
)
f"Program needs attribute '{prog_attr.name}', but is not present in buffer "
f"description. Buffer descriptions: {content}"
)

# Make sure components described in BufferDescription and in the shader match
if prog_attr.components != attr_descr.components:
raise ValueError(
(
f"Program attribute '{prog_attr.name}' has {prog_attr.components} "
f"components while the buffer description has {attr_descr.components} "
" components. "
)
f"Program attribute '{prog_attr.name}' has {prog_attr.components} "
f"components while the buffer description has {attr_descr.components} "
" components. "
)

gl.glEnableVertexAttribArray(prog_attr.location)
Expand Down Expand Up @@ -182,11 +179,9 @@ def _build(
# Sanity check attribute types between shader and buffer description
if attrib_type != prog_attr.gl_type:
raise ValueError(
(
f"Program attribute '{prog_attr.name}' has type "
f"{gl_name(prog_attr.gl_type)} "
f"while the buffer description has type {gl_name(attr_descr.gl_type)}. "
)
f"Program attribute '{prog_attr.name}' has type "
f"{gl_name(prog_attr.gl_type)} "
f"while the buffer description has type {gl_name(attr_descr.gl_type)}. "
)

if attrib_type in float_types:
Expand Down Expand Up @@ -464,7 +459,7 @@ class OpenGLGeometry(Geometry):

def __init__(
self,
ctx: "Context",
ctx: Context,
content: Sequence[BufferDescription] | None,
index_buffer: Buffer | None = None,
mode: int | None = None,
Expand Down
2 changes: 1 addition & 1 deletion arcade/gl/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def size(self) -> int:
return self._size

@property
def ctx(self) -> "Context":
def ctx(self) -> Context:
"""The context this resource belongs to."""
return self._ctx

Expand Down
Loading
Loading