fsleyes.gl.textures.rendertexture¶
This module provides the RenderTexture and
GLObjectRenderTexture classes, which are Texture2D
sub-classes intended to be used as targets for off-screen rendering.
These classes are used by the SliceCanvas and
LightBoxCanvas classes for off-screen rendering, and in various
other situations throughout FSLeyes. See also the
RenderTextureStack, which uses RenderTexture instances.
-
class
fsleyes.gl.textures.rendertexture.RenderTexture(*args, **kwargs)¶ Bases:
fsleyes.gl.textures.texture.Texture2DThe
RenderTextureclass is a 2D RGBA texture which manages a frame buffer and a render buffer or anotherTexture2Dwhich is used as the depth+stencil, or depth attachment.A
RenderTextureis intended to be used as a target for off-screen rendering. Using aRenderTexture(texin the example below) as the rendering target is easy:# Set the texture size in pixels tex.setSize(1024, 768) # Bind the texture/frame buffer, and configure # the viewport for orthoghraphic display. lo = (0.0, 0.0, 0.0) hi = (1.0, 1.0, 1.0) tex.bindAsRenderTarget() tex.setRenderViewport(0, 1, lo, hi) # ... # draw the scene # ... # Unbind the texture/frame buffer, # and restore the previous viewport. tex.unbindAsRenderTarget() tex.restoreViewport()
The contents of the
RenderTexturecan later be drawn to the screen via theTexture2D.draw()orTexture2D.drawOnBounds()methods.A
RenderTexturecan be configured in one of three ways:- Using a
RGBA8Texture2d(theRenderTextureitself) as the colour attachment, and no depth or stencil attachments. - As above for the colour attachment, and a
DEPTH_COMPONENT24Texture2Das the depth attachment. - As above for the colour attachment, and a
DEPTH24_STENCIL8renderbuffer as the combined depth+stencil attachment.
These are the only available options due to limitations in different GL implementations. You can choose which option you wish to use via the
rttypeargument to__init__.If you choose option #2, a second
Texture2Dinstance will be used as the depth attachment. The resulting depth values created after drawing to theRenderTexturemay be used in subsequent processing. You can either access the depth texture directly via thedepthTexture()method, or you can draw the contents of theRenderTexture, with depth information, by passing theuseDepthflag to either thedraw()ordrawOnBounds()methods.-
__init__(*args, **kwargs)¶ Create a
RenderTexture. All argumenst are passed through to theTexture2D.__init__()method.Parameters: rttype – RenderTextureconfiguration. If provided, must be passed as a keyword argument. Valid values are:'c': Only a colour attachment is configured'cd': Colour and depth attachments are- configured
'cds': Colour, depth, and stencil attachments- are configured. This is the default.
Note
A rendering target must have been set for the GL context before a frame buffer can be created … in other words, call
context.SetCurrentbefore creating aRenderTexture.
-
destroy()¶ Must be called when this
RenderTextureis no longer needed. Destroys the frame buffer and render buffer, and callsTexture2D.destroy().
-
setData(data)¶ Raises a
NotImplementedError. TheRenderTexturederives from theTexture2Dclass, but is not intended to have its texture data manually set - see theTexture2Ddocumentation.
-
getDepthTexture= <MagicMock name='mock.deprecated()()' id='139845843667040'>¶
-
depthTexture¶ Returns the
Texture2Dinstance used as the depth buffer. ReturnsNoneif thisRenderTexturewas not configured with'cd'(see__init__()).
-
setSize(width, height)¶ Overrides
Texture2D.setSize(). Calls that method, and also calls it on the depth texture if it exists.
-
renderViewport(xax, yax, lo, hi)¶ Context manager which sets and restores the viewport via
setRenderViewport()andrestoreViewport().
-
setRenderViewport(xax, yax, lo, hi)¶ Configures the GL viewport for a 2D orthographic display. See the
routines.show2D()function.The existing viewport settings are cached, and can be restored via the
restoreViewport()method.Parameters: - xax – The display coordinate system axis which corresponds to the horizontal screen axis.
- yax – The display coordinate system axis which corresponds to the vertical screen axis.
- lo – A tuple containing the minimum
(x, y, z)display coordinates. - hi – A tuple containing the maximum
(x, y, z)display coordinates.
-
restoreViewport()¶ Restores the GL viewport settings which were saved via a prior call to
setRenderViewport().
-
bound(*args, **kwargs)¶ Context manager which binds and unbinds this
RenderTextureas the render target, viabindAsRenderTarget()andunbindAsRenderTarget().If any arguments are provided, the viewport is also set and restored via
setRenderViewport()andrestoreViewport().
-
bindAsRenderTarget()¶ Configures the frame buffer and render buffer of this
RenderTextureas the targets for rendering.The existing farme buffer and render buffer are cached, and can be restored via the
unbindAsRenderTarget()method.
-
unbindAsRenderTarget()¶ Restores the frame buffer and render buffer which were saved via a prior call to
bindAsRenderTarget().
-
refresh()¶ Overrides
Texture2D.refresh(). Calls the base-class implementation, and ensures that the frame buffer and render buffer of thisRenderTextureare configured correctly.
-
draw(*args, **kwargs)¶ Overrides
Texture2D.draw(). Calls that method, optionally using the information in the depth texture.Parameters: useDepth – Must be passed as a keyword argument. Defaults to False. IfTrue, and thisRenderTexturewas configured to use a depth texture, the texture is rendered with depth information using a fragment programA
RuntimeErrorwill be raised ifuseDepth is True, but thisRenderTexturewas not configured appropriately (the'cd'setting in__init__()).
-
_RenderTexture__initShader()¶ Called by
__init__()if thisRenderTexturewas configured to use a colour and depth texture. Compiles vertex/fragment shader programs which pass the colour and depth values through.These shaders are used if the
draw()orTexture2D.drawOnBounds()methods are used with theuseDepth=Trueargument.
-
__module__= 'fsleyes.gl.textures.rendertexture'¶
- Using a
-
class
fsleyes.gl.textures.rendertexture.GLObjectRenderTexture(name, globj, xax, yax, maxResolution=2048)¶ Bases:
fsleyes.gl.textures.rendertexture.RenderTextureThe
GLObjectRenderTextureis aRenderTextureintended to be used for renderingGLObjectinstances off-screen.The advantage of using a
GLObjectRenderTextureover aRenderTextureis that aGLObjectRenderTexturewill automatically adjust its size to suit the resolution of theGLObject- see theGLObject.getDataResolution()method.In order to accomplish this, the
setAxes()method must be called whenever the display orientation changes, so that the render texture size can be re-calculated.-
__init__(name, globj, xax, yax, maxResolution=2048)¶ Create a
GLObjectRenderTexture.Parameters: - name – A unique name for this
GLObjectRenderTexture. - globj – The
GLObjectinstance which is to be rendered. - xax – Index of the display coordinate system axis to be used as the horizontal render texture axis.
- yax – Index of the display coordinate system axis to be used as the vertical render texture axis.
- maxResolution – Maximum resolution in pixels, along either the
horizontal or vertical axis, for this
GLObjectRenderTexture.
- name – A unique name for this
-
destroy()¶ Must be called when this
GLObjectRenderTextureis no longer needed. Removes the update listener from theGLObject, and callsRenderTexture.destroy().
-
_GLObjectRenderTexture__updateSize(*a)¶ Updates the size of this
GLObjectRenderTexture, basing it on the resolution returned by theGLObject.getDataResolution()method. If that method returnsNone, a default resolution is used.
-
__module__= 'fsleyes.gl.textures.rendertexture'¶
-
setAxes(xax, yax)¶ This method must be called when the display orientation of the
GLObjectchanges. It updates the size of thisGLObjectRenderTextureso that the resolution and aspect ratio of theGLOBjectare maintained.
-
setSize(width, height)¶ Raises a
NotImplementedError. The size of aGLObjectRenderTextureis set automatically.
-