fsleyes.gl.shaders.filter
¶
This module provides the Filter
class, which provides an interface
to loading and running simple filter shader programs, which require a
Texture2D
as their input.
- fsleyes.gl.shaders.filter.GL14_CONSTANTS = {'smooth': ['kernSize']}¶
This dictionary contains the names of any constant parameters that are required by GL14 filter implementations. It is used by the
Filter.set()
method.The
Filter.set()
method allows both uniform and constant paramters to be updated, but when a constant parameter is updated, the shader needs to be recompiled.
- class fsleyes.gl.shaders.filter.Filter(filterName, texture)[source]¶
Bases:
object
A
Filter
object encapsulates a shader program which applies some sort of image filter to aTexture2D
.All filters use the same vertex shader, which is called
filter_vert.glsl
orfilter_vert.prog
.Filter fragment shaders are assumed to have the name
filter_[name]_frag.glsl
orfilter_[name]_frag.prog
, where[name]
is the name of the filter that can be passed to__init__()
.Filter fragment shaders must define the following varyings/uniforms/ attributes:
texture
- the 2D texture which contains the filter inputfragTexCoord
- The texture coordinate, as passed through from thevertex shader.
Other settable filter parameters must be declared as uniforms, and can be set via the
set()
method.- __init__(filterName, texture)[source]¶
Create a
Filter
.- Parameters
filterName – Name of the filter to create.
texture – Number of the texture unit that the filter input texture will be bound to. This must be specified when the shader program is compiled, to support OpenGL 1.4.
- destroy()[source]¶
Must be called when this
Filter
is no longer needed. Destroys the shader program.
- set(**kwargs)[source]¶
Set filter parameters. This method must be called before
apply()
orosApply()
can be called, even if no parameters need to be set.The filter parameters vary depending on the specific filter that is used.
- __dict__ = mappingproxy({'__module__': 'fsleyes.gl.shaders.filter', '__doc__': 'A ``Filter`` object encapsulates a shader program which applies some\n sort of image filter to a :class:`.Texture2D`.\n\n All filters use the same vertex shader, which is called\n ``filter_vert.glsl`` or ``filter_vert.prog``.\n\n Filter fragment shaders are assumed to have the name\n ``filter_[name]_frag.glsl`` or ``filter_[name]_frag.prog``, where\n ``[name]`` is the name of the filter that can be passed to\n :meth:`__init__`.\n\n Filter fragment shaders must define the following varyings/uniforms/\n attributes:\n\n - ``texture`` - the 2D texture which contains the filter input\n - ``fragTexCoord`` - The texture coordinate, as passed through from the\n vertex shader.\n\n Other settable filter parameters must be declared as uniforms, and can be\n set via the :meth:`set` method.\n ', '__init__': <function Filter.__init__>, 'destroy': <function Filter.destroy>, 'set': <function Filter.set>, 'apply': <function Filter.apply>, 'osApply': <function Filter.osApply>, '__dict__': <attribute '__dict__' of 'Filter' objects>, '__weakref__': <attribute '__weakref__' of 'Filter' objects>, '__annotations__': {}})¶
- __module__ = 'fsleyes.gl.shaders.filter'¶
- __weakref__¶
list of weak references to the object (if defined)
- apply(source, zpos, xmin, xmax, ymin, ymax, xax, yax, xform=None, **kwargs)[source]¶
Apply the filter to the given
source
texture, and render the results according to the given bounds.- Parameters
source –
Texture2D
instance to apply the filter tozpos – Position along the Z axis, in the display coordinate system.
xmin – Minimum X axis coordinate.
xmax – Maximum X axis coordinate.
ymin – Minimum Y axis coordinate.
ymax – Maximum Y axis coordinate.
xax – Display space axis which maps to the horizontal screen axis.
yax – Display space axis which maps to the vertical screen axis.
xform – Transformation matrix to appply to vertices.
All other keyword arguments are passed through to the
Texture2D.draw()
method of thesource
texture.
- osApply(source, dest, clearDest=True, **kwargs)[source]¶
Apply the filter to the given
source
texture, rendering the results to the givendest
texture.This method can be used for ping-ponging, by using two
RenderTexture
objects, and swapping thesource
anddest
parameters on each iteration.- Parameters
source –
Texture2D
instance to apply the filter todest –
RenderTexture
instance to render the result toclearDest – If
True
(the default), thedest
texture is cleared before the draw.
All other arguments are passed to the
apply()
method.