Skip to content

Commit

Permalink
Merge pull request #135 from yuyu2172/get-texture
Browse files Browse the repository at this point in the history
Add get method for Texture
  • Loading branch information
rougier committed Feb 19, 2018
2 parents 9896114 + 8024b8e commit f9d58de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/gloo-framebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def on_draw(dt):
window.clear()
framebuffer.activate()
quad_1.draw(gl.GL_TRIANGLE_STRIP)
# The texture can be read as np.ndarray.
# out_texture = framebuffer.color[0].get()
framebuffer.deactivate()
quad_2.draw(gl.GL_TRIANGLE_STRIP)

Expand Down
7 changes: 6 additions & 1 deletion glumpy/gloo/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ def _delete(self):
if self.handle > -1:
gl.glDeleteTextures(np.array([self.handle], dtype=np.uint32))


def get(self):
""" Read the texture data back into CPU memory """
host = np.zeros(self.shape, self.dtype)
gl.glBindTexture(self.target, self._handle)
gl.glGetTexImage(self.target, 0, self.cpu_format, self.gtype, host)
return host


class Texture1D(Texture):
Expand Down

0 comments on commit f9d58de

Please sign in to comment.