From f1b398da6395d97bb0da1a8654f67190313147b5 Mon Sep 17 00:00:00 2001 From: Guillaume Cordonnier Date: Fri, 24 Apr 2020 21:38:59 +0200 Subject: [PATCH] fix_texture_read --- arcade/gl/texture.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arcade/gl/texture.py b/arcade/gl/texture.py index 5df14bd0d..ae7c229e4 100644 --- a/arcade/gl/texture.py +++ b/arcade/gl/texture.py @@ -215,14 +215,16 @@ def wrap_y(self, value): def read(self, level: int = 0, alignment: int = 1) -> bytearray: """ Read the contents of the texture. + :param int level: The texture level to read + :param int alignment: Alignment of the start of each row in memory in number of bytes. Possible values: 1,2,4 """ - gl.glActiveTexture(gl.GL_TEXTURE0) + gl.glBindTexture(self._target, self._glo) - gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1) - gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) + gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, alignment) - buffer = (gl.GLubyte * (self.width * self.height * self._component_size))() - gl.glGetTexImage(gl.GL_TEXTURE_2D, 0, self._format, self._type, buffer) + buffer = (gl.GLubyte * (self.width * self.height * self._component_size * self._components))() + gl.glGetTexImage(gl.GL_TEXTURE_2D, level, self._format, self._type, buffer) + return bytearray(buffer) def write(self, data: Union[bytes, Buffer], level: int = 0, viewport=None):