warp.GLTextureResource#
- class warp.GLTextureResource(*args, **kwargs)[source]#
Register and use an OpenGL texture with Warp.
Experimental
The texture API is experimental and subject to change without a formal deprecation cycle. See
Texturefor details.The texture must be mapped before it can be accessed by Warp and unmapped before it can be used by OpenGL again.
This class requires
pygletto be installed (pip install pyglet).Example:
import ctypes import warp as wp from pyglet import gl # create OpenGL texture tex_id = gl.GLuint() gl.glGenTextures(1, ctypes.byref(tex_id)) gl.glBindTexture(gl.GL_TEXTURE_2D, tex_id) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGBA8, 1024, 768, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, None, ) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) # register texture resource tex_resource = wp.GLTextureResource(tex_id, gl.GL_TEXTURE_2D) a = wp.full((768, 1024), 255, dtype=wp.vec4ub) # map and access the texture tex = tex_resource.map() tex.copy_from(a) tex_resource.unmap()
- __init__(
- gl_tex_id,
- gl_tex_target,
- device=None,
- flags=TextureResourceFlags.NONE,
Register OpenGL texture.
- Parameters:
gl_tex_id (int) – OpenGL texture ID, e.g., from
pyglet.gl.glGenTextures().gl_tex_target (int) – OpenGL texture target, e.g.,
pyglet.gl.GL_TEXTURE_2D.device (DeviceLike) – The CUDA device where the texture resides.
flags (int) – Texture resource flags, see
TextureResourceFlags.
Methods
__init__(gl_tex_id, gl_tex_target[, device, ...])Register OpenGL texture.
map()Map OpenGL texture.
unmap()Unmap OpenGL texture.