Skip to content

Commit 6f537d3

Browse files
committed
TextureArray create method
1 parent 7652eef commit 6f537d3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

demosys/opengl/texture.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,30 @@ def __init__(self, path: str=None, mipmap: bool=False, layers=0, **kwargs):
218218
self.layers = layers
219219
self.mipmap = mipmap
220220

221-
if not self.layers > 0:
221+
if self.layers <= 0:
222222
raise ValueError("Texture {} requires a layer parameter > 0".formats(self.path))
223223

224+
@classmethod
225+
def create(cls, size, components=4, data=None, alignment=1, dtype='f1', mipmap=False):
226+
"""
227+
:param size: (x, y, layers) size and layers of the texture
228+
:param components: The number of components 1, 2, 3 or 4
229+
:param data: (bytes) Content of the texture
230+
:param alignment: The byte alignment 1, 2, 4 or 8
231+
:param dtype: (str) The data type
232+
:param mipmap: (bool) Generate mipmaps
233+
"""
234+
texture = cls("create", mipmap=False, layers=size[2])
235+
texture.mglo = context.ctx().texture_array(
236+
size, components,
237+
data=data, alignment=alignment, dtype=dtype,
238+
)
239+
240+
if mipmap:
241+
texture.build_mipmaps()
242+
243+
return texture
244+
224245
def set_image(self, image, flip=True):
225246
"""
226247
Set pixel data using a image file with PIL/Pillow.

0 commit comments

Comments
 (0)