Skip to content

TextureArray Support #2447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 12, 2024
Merged
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
2 changes: 2 additions & 0 deletions arcade/gl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .buffer import Buffer
from .vertex_array import Geometry, VertexArray
from .texture import Texture2D
from .texture_array import TextureArray
from .sampler import Sampler
from .framebuffer import Framebuffer
from .program import Program
Expand All @@ -43,6 +44,7 @@
"ShaderException",
"VertexArray",
"Texture2D",
"TextureArray",
"Sampler",
"geometry",
]
35 changes: 35 additions & 0 deletions arcade/gl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .query import Query
from .sampler import Sampler
from .texture import Texture2D
from .texture_array import TextureArray
from .types import BufferDescription, GLenumLike, PyGLenum
from .vertex_array import Geometry

Expand Down Expand Up @@ -1069,6 +1070,40 @@ def texture(
compressed_data=compressed_data,
)

def texture_array(
self,
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,
) -> TextureArray:
"""
Create a 2D Texture Array.

This is a 2D texture with multiple layers. This is useful for
storing multiple textures in a single texture object. This can
be used for texture atlases or storing multiple frames of an
animation in a single texture or equally sized tile textures.

Note that ``size`` is a 3-tuple where the last value is the number of layers.

See :py:meth:`~arcade.gl.Context.texture` for arguments.
"""
return TextureArray(
self,
size,
components=components,
dtype=dtype,
data=data,
wrap_x=wrap_x,
wrap_y=wrap_y,
filter=filter,
)

def depth_texture(
self, size: Tuple[int, int], *, data: BufferProtocol | None = None
) -> Texture2D:
Expand Down
3 changes: 2 additions & 1 deletion arcade/gl/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ def write(self, data: BufferOrBufferProtocol, level: int = 0, viewport=None) ->
level:
The texture level to write
viewport:
The area of the texture to write. 2 or 4 component tuple
The area of the texture to write. 2 or 4 component tuple.
(x, y, w, h) or (w, h). Default is the full texture.
"""
# TODO: Support writing to layers using viewport + alignment
if self._samples > 0:
Expand Down
Loading
Loading