Skip to content
Snippets Groups Projects
Commit 65172f5d authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Removed all mention of 'softwareMode'. SceneOpts.performance now has

four modes. Things are probably broken.
parent a4aa9962
No related branches found
No related tags found
No related merge requests found
Showing
with 71 additions and 288 deletions
...@@ -539,8 +539,7 @@ choices = TypeDict({ ...@@ -539,8 +539,7 @@ choices = TypeDict({
'SceneOpts.performance' : {1 : 'Fastest', 'SceneOpts.performance' : {1 : 'Fastest',
2 : 'Faster', 2 : 'Faster',
3 : 'Good looking', 3 : 'Good looking',
4 : 'Better looking', 4 : 'Best looking'},
5 : 'Best looking'},
'CanvasOpts.zax' : {0 : 'X axis', 'CanvasOpts.zax' : {0 : 'X axis',
1 : 'Y axis', 1 : 'Y axis',
......
...@@ -287,9 +287,7 @@ _DISPLAY_PROPS = td.TypeDict({ ...@@ -287,9 +287,7 @@ _DISPLAY_PROPS = td.TypeDict({
labels=strings.choices['VolumeOpts.interpolation']), labels=strings.choices['VolumeOpts.interpolation']),
props.Widget('cmap'), props.Widget('cmap'),
props.Widget('invert'), props.Widget('invert'),
props.Widget('invertClipping', props.Widget('invertClipping'),
enabledWhen=lambda o, sw: not sw,
dependencies=[(lambda o: o.display, 'softwareMode')]),
props.Widget('displayRange', props.Widget('displayRange',
showLimits=False, showLimits=False,
slider=True, slider=True,
...@@ -347,13 +345,8 @@ _DISPLAY_PROPS = td.TypeDict({ ...@@ -347,13 +345,8 @@ _DISPLAY_PROPS = td.TypeDict({
'LabelOpts' : [ 'LabelOpts' : [
props.Widget('lut', labels=lambda l: l.name), props.Widget('lut', labels=lambda l: l.name),
props.Widget('outline', props.Widget('outline'),
enabledWhen=lambda o, sw: not sw, props.Widget('outlineWidth', showLimits=False),
dependencies=[(lambda o: o.display, 'softwareMode')]),
props.Widget('outlineWidth',
showLimits=False,
enabledWhen=lambda o, sw: not sw,
dependencies=[(lambda o: o.display, 'softwareMode')]),
# props.Widget('showNames'), # props.Widget('showNames'),
props.Widget('resolution', showLimits=False), props.Widget('resolution', showLimits=False),
props.Widget('volume', props.Widget('volume',
......
...@@ -530,15 +530,11 @@ _TOOLBAR_PROPS = td.TypeDict({ ...@@ -530,15 +530,11 @@ _TOOLBAR_PROPS = td.TypeDict({
tooltip=_TOOLTIPS['LabelOpts.outline'], tooltip=_TOOLTIPS['LabelOpts.outline'],
icon=[icons.findImageFile('outline24'), icon=[icons.findImageFile('outline24'),
icons.findImageFile('filled24')], icons.findImageFile('filled24')],
toggle=True, toggle=True),
enabledWhen=lambda i, sw: not sw,
dependencies=[(lambda o: o.display, 'softwareMode')]),
'outlineWidth' : props.Widget( 'outlineWidth' : props.Widget(
'outlineWidth', 'outlineWidth',
tooltip=_TOOLTIPS['LabelOpts.outlineWidth'], tooltip=_TOOLTIPS['LabelOpts.outlineWidth'],
enabledWhen=lambda i, sw: not sw,
dependencies=[(lambda o: o.display, 'softwareMode')],
showLimits=False, showLimits=False,
spin=False)}, spin=False)},
......
...@@ -91,13 +91,6 @@ class SliceCanvasOpts(props.HasProperties): ...@@ -91,13 +91,6 @@ class SliceCanvasOpts(props.HasProperties):
""" """
softwareMode = props.Boolean(default=False)
"""If ``True``, the :attr:`.Display.softwareMode` property for every
displayed overlay is set to ``True``. This will result in better
performance for slow systems (e.g. software based OpenGL renderers).
"""
resolutionLimit = props.Real(default=0, minval=0, maxval=5, clamped=True) resolutionLimit = props.Real(default=0, minval=0, maxval=5, clamped=True)
"""The minimum resolution at which overlays should be drawn. A higher """The minimum resolution at which overlays should be drawn. A higher
value will result in better performance. value will result in better performance.
......
...@@ -61,12 +61,6 @@ class Display(props.SyncableHasProperties): ...@@ -61,12 +61,6 @@ class Display(props.SyncableHasProperties):
"""Contrast - 50% is normal contrast.""" """Contrast - 50% is normal contrast."""
softwareMode = props.Boolean(default=False)
"""If possible, optimise for a low-performance rendering environment
(e.g. a software-based OpenGL renderer).
"""
def __init__(self, def __init__(self,
overlay, overlay,
overlayList, overlayList,
...@@ -127,7 +121,7 @@ class Display(props.SyncableHasProperties): ...@@ -127,7 +121,7 @@ class Display(props.SyncableHasProperties):
# These properties cannot be unbound, as # These properties cannot be unbound, as
# they affect the OpenGL representation # they affect the OpenGL representation
nounbind=['softwareMode', 'overlayType'], nounbind=['overlayType'],
# Initial sync state between this # Initial sync state between this
# Display and the parent Display # Display and the parent Display
......
...@@ -36,7 +36,6 @@ class SceneOpts(props.HasProperties): ...@@ -36,7 +36,6 @@ class SceneOpts(props.HasProperties):
cursorColour = copy.copy(canvasopts.SliceCanvasOpts.cursorColour) cursorColour = copy.copy(canvasopts.SliceCanvasOpts.cursorColour)
resolutionLimit = copy.copy(canvasopts.SliceCanvasOpts.resolutionLimit) resolutionLimit = copy.copy(canvasopts.SliceCanvasOpts.resolutionLimit)
renderMode = copy.copy(canvasopts.SliceCanvasOpts.renderMode) renderMode = copy.copy(canvasopts.SliceCanvasOpts.renderMode)
softwareMode = copy.copy(canvasopts.SliceCanvasOpts.softwareMode)
showColourBar = props.Boolean(default=False) showColourBar = props.Boolean(default=False)
...@@ -57,13 +56,13 @@ class SceneOpts(props.HasProperties): ...@@ -57,13 +56,13 @@ class SceneOpts(props.HasProperties):
""" """
performance = props.Choice((1, 2, 3, 4, 5), default=5) performance = props.Choice((1, 2, 3, 4), default=4)
"""User controllable performance setting. """User controllable performance setting.
This property is linked to the :attr:`renderMode`, This property is linked to the :attr:`renderMode` and
:attr:`resolutionLimit`, and :attr:`softwareMode` properties. Setting this :attr:`resolutionLimit` properties. Setting this property to a low value
property to a low value will result in faster rendering time, at the cost will result in faster rendering time, at the cost of increased memory
of reduced features, and poorer rendering quality. usage and poorer rendering quality.
See the :meth:`__onPerformanceChange` method. See the :meth:`__onPerformanceChange` method.
""" """
...@@ -73,8 +72,7 @@ class SceneOpts(props.HasProperties): ...@@ -73,8 +72,7 @@ class SceneOpts(props.HasProperties):
"""Create a ``SceneOpts`` instance. """Create a ``SceneOpts`` instance.
This method simply links the :attr:`performance` property to the This method simply links the :attr:`performance` property to the
:attr:`renderMode`, :attr:`softwareMode`, and :attr:`resolutionLimit` :attr:`renderMode` and :attr:`resolutionLimit` properties.
properties.
""" """
name = '{}_{}'.format(type(self).__name__, id(self)) name = '{}_{}'.format(type(self).__name__, id(self))
...@@ -86,40 +84,29 @@ class SceneOpts(props.HasProperties): ...@@ -86,40 +84,29 @@ class SceneOpts(props.HasProperties):
def __onPerformanceChange(self, *a): def __onPerformanceChange(self, *a):
"""Called when the :attr:`performance` property changes. """Called when the :attr:`performance` property changes.
Changes the values of the :attr:`renderMode`, :attr:`softwareMode` Changes the values of the :attr:`renderMode` and and
and :attr:`resolutionLimit` properties accoridng to the performance :attr:`resolutionLimit` properties accoridng to the performance
setting. setting.
""" """
if self.performance == 5: if self.performance == 4:
self.renderMode = 'onscreen' self.renderMode = 'onscreen'
self.softwareMode = False
self.resolutionLimit = 0
elif self.performance == 4:
self.renderMode = 'onscreen'
self.softwareMode = True
self.resolutionLimit = 0 self.resolutionLimit = 0
elif self.performance == 3: elif self.performance == 3:
self.renderMode = 'offscreen' self.renderMode = 'offscreen'
self.softwareMode = True
self.resolutionLimit = 0 self.resolutionLimit = 0
elif self.performance == 2: elif self.performance == 2:
self.renderMode = 'prerender' self.renderMode = 'prerender'
self.softwareMode = True
self.resolutionLimit = 0 self.resolutionLimit = 0
elif self.performance == 1: elif self.performance == 1:
self.renderMode = 'prerender' self.renderMode = 'prerender'
self.softwareMode = True
self.resolutionLimit = 1 self.resolutionLimit = 1
log.debug('Performance settings changed: ' log.debug('Performance settings changed: '
'renderMode={}, ' 'renderMode={}, '
'softwareMode={}, '
'resolutionLimit={}'.format( 'resolutionLimit={}'.format(
self.renderMode, self.renderMode,
self.softwareMode,
self.resolutionLimit)) self.resolutionLimit))
...@@ -53,10 +53,8 @@ def compileShaders(self): ...@@ -53,10 +53,8 @@ def compileShaders(self):
if self.fragmentProgram is not None: if self.fragmentProgram is not None:
arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram)) arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram))
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
vertexProgram, fragmentProgram = shaders.compilePrograms( vertexProgram, fragmentProgram = shaders.compilePrograms(
vertShaderSrc, fragShaderSrc) vertShaderSrc, fragShaderSrc)
......
...@@ -95,10 +95,8 @@ def compileShaders(self): ...@@ -95,10 +95,8 @@ def compileShaders(self):
if self.fragmentProgram is not None: if self.fragmentProgram is not None:
arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram)) arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram))
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
vertexProgram, fragmentProgram = shaders.compilePrograms( vertexProgram, fragmentProgram = shaders.compilePrograms(
vertShaderSrc, fragShaderSrc) vertShaderSrc, fragShaderSrc)
...@@ -173,9 +171,6 @@ def preDraw(self): ...@@ -173,9 +171,6 @@ def preDraw(self):
gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
if self.display.softwareMode:
gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
arbvp.glBindProgramARB(arbvp.GL_VERTEX_PROGRAM_ARB, arbvp.glBindProgramARB(arbvp.GL_VERTEX_PROGRAM_ARB,
self.vertexProgram) self.vertexProgram)
arbfp.glBindProgramARB(arbfp.GL_FRAGMENT_PROGRAM_ARB, arbfp.glBindProgramARB(arbfp.GL_FRAGMENT_PROGRAM_ARB,
...@@ -187,18 +182,12 @@ def draw(self, zpos, xform=None): ...@@ -187,18 +182,12 @@ def draw(self, zpos, xform=None):
at the specified Z location. at the specified Z location.
""" """
display = self.display
opts = self.displayOpts opts = self.displayOpts
vertices, texCoords = self.lineVertices.getVertices(zpos, self) vertices, texCoords = self.lineVertices.getVertices(zpos, self)
if vertices.size == 0: if vertices.size == 0:
return return
if display.softwareMode:
texCoords = texCoords.ravel('C')
gl.glClientActiveTexture(gl.GL_TEXTURE0)
gl.glTexCoordPointer(3, gl.GL_FLOAT, 0, texCoords)
vertices = vertices.ravel('C') vertices = vertices.ravel('C')
v2d = opts.getTransform('voxel', 'display') v2d = opts.getTransform('voxel', 'display')
...@@ -228,6 +217,3 @@ def postDraw(self): ...@@ -228,6 +217,3 @@ def postDraw(self):
gl.glDisable(arbfp.GL_FRAGMENT_PROGRAM_ARB) gl.glDisable(arbfp.GL_FRAGMENT_PROGRAM_ARB)
gl.glDisableClientState(gl.GL_VERTEX_ARRAY) gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
if self.display.softwareMode:
gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
...@@ -55,10 +55,8 @@ def compileShaders(self): ...@@ -55,10 +55,8 @@ def compileShaders(self):
if self.fragmentProgram is not None: if self.fragmentProgram is not None:
arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram)) arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram))
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
vertexProgram, fragmentProgram = shaders.compilePrograms( vertexProgram, fragmentProgram = shaders.compilePrograms(
vertShaderSrc, fragShaderSrc) vertShaderSrc, fragShaderSrc)
......
...@@ -55,10 +55,8 @@ def compileShaders(self): ...@@ -55,10 +55,8 @@ def compileShaders(self):
if self.fragmentProgram is not None: if self.fragmentProgram is not None:
arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram)) arbfp.glDeleteProgramsARB(1, gltypes.GLuint(self.fragmentProgram))
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
vertexProgram, fragmentProgram = shaders.compilePrograms( vertexProgram, fragmentProgram = shaders.compilePrograms(
vertShaderSrc, fragShaderSrc) vertShaderSrc, fragShaderSrc)
......
...@@ -48,10 +48,8 @@ def compileShaders(self): ...@@ -48,10 +48,8 @@ def compileShaders(self):
if self.shaders is not None: if self.shaders is not None:
gl.glDeleteProgram(self.shaders) gl.glDeleteProgram(self.shaders)
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc) self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc)
self.vertexPos = gl.glGetAttribLocation( self.shaders, self.vertexPos = gl.glGetAttribLocation( self.shaders,
......
...@@ -9,22 +9,14 @@ class to render :class:`.Image` overlays as line vector images in an OpenGL 2.1 ...@@ -9,22 +9,14 @@ class to render :class:`.Image` overlays as line vector images in an OpenGL 2.1
compatible manner. compatible manner.
This module uses two different techniques to render a ``GLLineVector``. If This module uses two different techniques to render a ``GLLineVector``. The
the :attr:`.Display.softwareMode` (a.k.a. low performance) mode is enabled, voxel coordinates for every vector are passed directly to a vertex shader
a :class:`.GLLineVertices` instance is used to generate line vertices and program which calculates the position of the corresponding line vertices.
texture coordinates for each voxel in the image. This is the same approach
used by the :mod:`.gl14.gllinevector_funcs` module.
If :attr:`.Display.softwareMode` is disabled, a ``GLLineVertices`` instance is A fragment shader (the same as that used by the :class:`.GLRGBVector` class)
not used. Instead, the voxel coordinates for every vector are passed directly is used to colour each line according to the orientation of the underlying
to a vertex shader program which calculates the position of the corresponding vector.
line vertices.
For both of the above techniques, a fragment shader (the same as that used by
the :class:`.GLRGBVector` class) is used to colour each line according to the
orientation of the underlying vector.
""" """
...@@ -35,9 +27,7 @@ import OpenGL.GL as gl ...@@ -35,9 +27,7 @@ import OpenGL.GL as gl
import OpenGL.raw.GL._types as gltypes import OpenGL.raw.GL._types as gltypes
import fsl.utils.transform as transform import fsl.utils.transform as transform
import fsl.fsleyes.gl.resources as glresources
import fsl.fsleyes.gl.routines as glroutines import fsl.fsleyes.gl.routines as glroutines
import fsl.fsleyes.gl.gllinevector as gllinevector
import fsl.fsleyes.gl.shaders as shaders import fsl.fsleyes.gl.shaders as shaders
...@@ -59,10 +49,6 @@ def init(self): ...@@ -59,10 +49,6 @@ def init(self):
self.vertexIDBuffer = gl.glGenBuffers(1) self.vertexIDBuffer = gl.glGenBuffers(1)
self.lineVertices = None self.lineVertices = None
# False -> hardware shaders are in use
# True -> software shaders are in use
self.swShadersInUse = False
self._vertexResourceName = '{}_{}_vertices'.format( self._vertexResourceName = '{}_{}_vertices'.format(
type(self).__name__, id(self.image)) type(self).__name__, id(self.image))
...@@ -70,7 +56,6 @@ def init(self): ...@@ -70,7 +56,6 @@ def init(self):
def vertexUpdate(*a): def vertexUpdate(*a):
updateVertices(self)
self.updateShaderState() self.updateShaderState()
self.onUpdate() self.onUpdate()
...@@ -99,28 +84,20 @@ def destroy(self): ...@@ -99,28 +84,20 @@ def destroy(self):
self.displayOpts.removeListener('resolution', name) self.displayOpts.removeListener('resolution', name)
self.displayOpts.removeListener('directed', name) self.displayOpts.removeListener('directed', name)
if self.display.softwareMode:
glresources.delete(self._vertexResourceName)
def compileShaders(self): def compileShaders(self):
"""Compiles the vertex/fragment shaders, and stores references to all """Compiles the vertex/fragment shaders, and stores references to all
shader variables as attributes of the :class:`.GLLineVector`. This shader variables as attributes of the :class:`.GLLineVector`.
also results in a call to :func:`updateVertices`.
""" """
if self.shaders is not None: if self.shaders is not None:
gl.glDeleteProgram(self.shaders) gl.glDeleteProgram(self.shaders)
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc) self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc)
self.swShadersInUse = self.display.softwareMode
self.vertexPos = gl.glGetAttribLocation( self.shaders, self.vertexPos = gl.glGetAttribLocation( self.shaders,
'vertex') 'vertex')
self.vertexIDPos = gl.glGetAttribLocation( self.shaders, self.vertexIDPos = gl.glGetAttribLocation( self.shaders,
...@@ -157,15 +134,12 @@ def compileShaders(self): ...@@ -157,15 +134,12 @@ def compileShaders(self):
'voxelOffset') 'voxelOffset')
self.cmapXformPos = gl.glGetUniformLocation(self.shaders, self.cmapXformPos = gl.glGetUniformLocation(self.shaders,
'cmapXform') 'cmapXform')
updateVertices(self)
def updateShaderState(self): def updateShaderState(self):
"""Updates all variables used by the vertex/fragment shaders. """ """Updates all variables used by the vertex/fragment shaders. """
display = self.display opts = self.displayOpts
opts = self.displayOpts
# The coordinate transformation matrices for # The coordinate transformation matrices for
# each of the three colour textures are identical, # each of the three colour textures are identical,
...@@ -194,62 +168,30 @@ def updateShaderState(self): ...@@ -194,62 +168,30 @@ def updateShaderState(self):
gl.glUniform1i(self.yColourTexturePos, 3) gl.glUniform1i(self.yColourTexturePos, 3)
gl.glUniform1i(self.zColourTexturePos, 4) gl.glUniform1i(self.zColourTexturePos, 4)
if not display.softwareMode: directed = opts.directed
imageDims = self.image.pixdim[:3]
directed = opts.directed d2vMat = opts.getTransform('display', 'voxel')
imageDims = self.image.pixdim[:3] v2dMat = opts.getTransform('voxel', 'display')
d2vMat = opts.getTransform('display', 'voxel')
v2dMat = opts.getTransform('voxel', 'display')
# The shader adds these offsets to
# transformed voxel coordinates, so
# it can floor them to get integer
# voxel coordinates
offset = [0.5, 0.5, 0.5]
offset = np.array(offset, dtype=np.float32)
imageDims = np.array(imageDims, dtype=np.float32)
d2vMat = np.array(d2vMat, dtype=np.float32).ravel('C')
v2dMat = np.array(v2dMat, dtype=np.float32).ravel('C')
gl.glUniform1f( self.directedPos, directed)
gl.glUniform3fv(self.imageDimsPos, 1, imageDims)
gl.glUniform3fv(self.voxelOffsetPos, 1, offset)
gl.glUniformMatrix4fv(self.displayToVoxMatPos, 1, False, d2vMat)
gl.glUniformMatrix4fv(self.voxToDisplayMatPos, 1, False, v2dMat)
gl.glUseProgram(0) # The shader adds these offsets to
# transformed voxel coordinates, so
# it can floor them to get integer
# voxel coordinates
offset = [0.5, 0.5, 0.5]
offset = np.array(offset, dtype=np.float32)
imageDims = np.array(imageDims, dtype=np.float32)
d2vMat = np.array(d2vMat, dtype=np.float32).ravel('C')
v2dMat = np.array(v2dMat, dtype=np.float32).ravel('C')
def updateVertices(self): gl.glUniform1f( self.directedPos, directed)
"""If :attr:`.Display.softwareMode` is enabled, a :class:`.GLLineVertices` gl.glUniform3fv(self.imageDimsPos, 1, imageDims)
instance is created/refreshed. Otherwise, this function does nothing. gl.glUniform3fv(self.voxelOffsetPos, 1, offset)
"""
image = self.image gl.glUniformMatrix4fv(self.displayToVoxMatPos, 1, False, d2vMat)
display = self.display gl.glUniformMatrix4fv(self.voxToDisplayMatPos, 1, False, v2dMat)
if not display.softwareMode: gl.glUseProgram(0)
self.lineVertices = None
if glresources.exists(self._vertexResourceName):
log.debug('Clearing any cached line vertices for {}'.format(image))
glresources.delete(self._vertexResourceName)
return
if self.lineVertices is None:
self.lineVertices = glresources.get(
self._vertexResourceName, gllinevector.GLLineVertices, self)
if hash(self.lineVertices) != self.lineVertices.calculateHash(self):
log.debug('Re-generating line vertices for {}'.format(image))
self.lineVertices.refresh(self)
glresources.set(self._vertexResourceName,
self.lineVertices,
overwrite=True)
def preDraw(self): def preDraw(self):
...@@ -260,74 +202,11 @@ def preDraw(self): ...@@ -260,74 +202,11 @@ def preDraw(self):
def draw(self, zpos, xform=None): def draw(self, zpos, xform=None):
"""Draws the line vectors at a plane at the specified Z location.
This is performed using either :func:`softwareDraw` or
:func:`hardwareDraw`, depending upon the value of
:attr:`.Display.softwareMode`.
"""
if self.display.softwareMode: softwareDraw(self, zpos, xform)
else: hardwareDraw(self, zpos, xform)
def softwareDraw(self, zpos, xform=None):
"""Draws the line vectors at a plane at the specified Z location, using
a :class:`.GLLineVertices` instance.
"""
# Software shaders have not yet been compiled -
# we can't draw until they're updated
if not self.swShadersInUse:
return
opts = self.displayOpts
vertices, texCoords = self.lineVertices.getVertices(zpos, self)
if vertices.size == 0:
return
vertices = vertices .ravel('C')
texCoords = texCoords.ravel('C')
v2d = opts.getTransform('voxel', 'display')
if xform is None: xform = v2d
else: xform = transform.concat(v2d, xform)
gl.glPushMatrix()
gl.glMultMatrixf(np.array(xform, dtype=np.float32).ravel('C'))
# upload the vertices
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vertexBuffer)
gl.glBufferData(
gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices, gl.GL_STATIC_DRAW)
gl.glVertexAttribPointer(
self.vertexPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, None)
gl.glEnableVertexAttribArray(self.vertexPos)
# and the texture coordinates
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.texCoordBuffer)
gl.glBufferData(
gl.GL_ARRAY_BUFFER, texCoords.nbytes, texCoords, gl.GL_STATIC_DRAW)
gl.glVertexAttribPointer(
self.texCoordPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, None)
gl.glEnableVertexAttribArray(self.texCoordPos)
gl.glLineWidth(opts.lineWidth)
gl.glDrawArrays(gl.GL_LINES, 0, vertices.size / 3)
gl.glPopMatrix()
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
gl.glDisableVertexAttribArray(self.vertexPos)
def hardwareDraw(self, zpos, xform=None):
"""Draws the line vectors at a plane at the specified Z location. """Draws the line vectors at a plane at the specified Z location.
Voxel coordinates are passed to the vertex shader, which calculates Voxel coordinates are passed to the vertex shader, which calculates
the corresponding line vertex locations. the corresponding line vertex locations.
""" """
if self.swShadersInUse:
return
image = self.image image = self.image
opts = self.displayOpts opts = self.displayOpts
......
...@@ -55,10 +55,8 @@ def compileShaders(self): ...@@ -55,10 +55,8 @@ def compileShaders(self):
if self.shaders is not None: if self.shaders is not None:
gl.glDeleteProgram(self.shaders) gl.glDeleteProgram(self.shaders)
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc) self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc)
......
...@@ -53,10 +53,8 @@ def compileShaders(self): ...@@ -53,10 +53,8 @@ def compileShaders(self):
if self.shaders is not None: if self.shaders is not None:
gl.glDeleteProgram(self.shaders) gl.glDeleteProgram(self.shaders)
vertShaderSrc = shaders.getVertexShader( self, vertShaderSrc = shaders.getVertexShader( self)
sw=self.display.softwareMode) fragShaderSrc = shaders.getFragmentShader(self)
fragShaderSrc = shaders.getFragmentShader(self,
sw=self.display.softwareMode)
self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc) self.shaders = shaders.compileShaders(vertShaderSrc, fragShaderSrc)
# indices of all vertex/fragment shader parameters # indices of all vertex/fragment shader parameters
...@@ -164,16 +162,9 @@ def _prepareVertexAttributes(self, vertices, voxCoords, texCoords): ...@@ -164,16 +162,9 @@ def _prepareVertexAttributes(self, vertices, voxCoords, texCoords):
verPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 36, None) verPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 36, None)
gl.glVertexAttribPointer( gl.glVertexAttribPointer(
texPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 36, ctypes.c_void_p(24)) texPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 36, ctypes.c_void_p(24))
gl.glVertexAttribPointer(
# The sw shader does not use voxel coordinates voxPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 36, ctypes.c_void_p(12))
# so attempting to binding would raise an error. gl.glEnableVertexAttribArray(self.voxCoordPos)
# So we only attempt to bind if softwareMode is
# false, and there is a shader uniform position
# for the voxel coordinates available.
if not self.display.softwareMode and voxPos != -1:
gl.glVertexAttribPointer(
voxPos, 3, gl.GL_FLOAT, gl.GL_FALSE, 36, ctypes.c_void_p(12))
gl.glEnableVertexAttribArray(self.voxCoordPos)
gl.glEnableVertexAttribArray(self.vertexPos) gl.glEnableVertexAttribArray(self.vertexPos)
gl.glEnableVertexAttribArray(self.texCoordPos) gl.glEnableVertexAttribArray(self.texCoordPos)
...@@ -223,11 +214,7 @@ def postDraw(self): ...@@ -223,11 +214,7 @@ def postDraw(self):
gl.glDisableVertexAttribArray(self.vertexPos) gl.glDisableVertexAttribArray(self.vertexPos)
gl.glDisableVertexAttribArray(self.texCoordPos) gl.glDisableVertexAttribArray(self.texCoordPos)
gl.glDisableVertexAttribArray(self.voxCoordPos)
# See comments in _prepareVertexAttributes
# about softwareMode/voxel coordinates
if not self.display.softwareMode and self.voxCoordPos != -1:
gl.glDisableVertexAttribArray(self.voxCoordPos)
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
gl.glUseProgram(0) gl.glUseProgram(0)
...@@ -128,7 +128,6 @@ class GLLabel(globject.GLImageObject): ...@@ -128,7 +128,6 @@ class GLLabel(globject.GLImageObject):
display .addListener('alpha', name, lutUpdate, weak=False) display .addListener('alpha', name, lutUpdate, weak=False)
display .addListener('brightness', name, lutUpdate, weak=False) display .addListener('brightness', name, lutUpdate, weak=False)
display .addListener('contrast', name, lutUpdate, weak=False) display .addListener('contrast', name, lutUpdate, weak=False)
display .addListener('softwareMode', name, shaderCompile, weak=False)
opts .addListener('outline', name, shaderUpdate, weak=False) opts .addListener('outline', name, shaderUpdate, weak=False)
opts .addListener('outlineWidth', name, shaderUpdate, weak=False) opts .addListener('outlineWidth', name, shaderUpdate, weak=False)
opts .addListener('lut', name, lutChanged, weak=False) opts .addListener('lut', name, lutChanged, weak=False)
...@@ -154,7 +153,6 @@ class GLLabel(globject.GLImageObject): ...@@ -154,7 +153,6 @@ class GLLabel(globject.GLImageObject):
display .removeListener( 'alpha', name) display .removeListener( 'alpha', name)
display .removeListener( 'brightness', name) display .removeListener( 'brightness', name)
display .removeListener( 'contrast', name) display .removeListener( 'contrast', name)
display .removeListener( 'softwareMode', name)
opts .removeListener( 'outline', name) opts .removeListener( 'outline', name)
opts .removeListener( 'outlineWidth', name) opts .removeListener( 'outlineWidth', name)
opts .removeListener( 'lut', name) opts .removeListener( 'lut', name)
......
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
vector :class:`.Image` overlays in line mode. vector :class:`.Image` overlays in line mode.
The :class:`.GLLineVertices` class is also defined in this module, and is The :class:`.GLLineVertices` class is also defined in this module, and is used
used in certain rendering situations - when running in OpenGL 1.4, and in certain rendering situations - specifically, when running in OpenGL
when running in *software* (a.k.a. low performance) mode, in OpenGL 2.1. See 1.4. See the :mod:`.gl14.gllinevector_funcs` and
the :mod:`.gl14.gllinevector_funcs` and :mod:`.gl21.gllinevector_funcs` :mod:`.gl21.gllinevector_funcs` modules for more details.
modules for more details.
""" """
import logging import logging
......
...@@ -75,7 +75,6 @@ class GLMask(glvolume.GLVolume): ...@@ -75,7 +75,6 @@ class GLMask(glvolume.GLVolume):
fslgl.glvolume_funcs.updateShaderState(self) fslgl.glvolume_funcs.updateShaderState(self)
self.onUpdate() self.onUpdate()
display.addListener('softwareMode', name, shaderCompile, weak=False)
display.addListener('alpha', name, colourUpdate, weak=False) display.addListener('alpha', name, colourUpdate, weak=False)
display.addListener('brightness', name, colourUpdate, weak=False) display.addListener('brightness', name, colourUpdate, weak=False)
display.addListener('contrast', name, colourUpdate, weak=False) display.addListener('contrast', name, colourUpdate, weak=False)
...@@ -102,7 +101,6 @@ class GLMask(glvolume.GLVolume): ...@@ -102,7 +101,6 @@ class GLMask(glvolume.GLVolume):
opts = self.displayOpts opts = self.displayOpts
name = self.name name = self.name
display.removeListener( 'softwareMode', name)
display.removeListener( 'alpha', name) display.removeListener( 'alpha', name)
display.removeListener( 'brightness', name) display.removeListener( 'brightness', name)
display.removeListener( 'contrast', name) display.removeListener( 'contrast', name)
......
...@@ -158,7 +158,6 @@ class GLVector(globject.GLImageObject): ...@@ -158,7 +158,6 @@ class GLVector(globject.GLImageObject):
self.updateShaderState() self.updateShaderState()
self.onUpdate() self.onUpdate()
display.addListener('softwareMode', name, shaderCompile, weak=False)
display.addListener('alpha', name, cmapUpdate, weak=False) display.addListener('alpha', name, cmapUpdate, weak=False)
display.addListener('brightness', name, cmapUpdate, weak=False) display.addListener('brightness', name, cmapUpdate, weak=False)
display.addListener('contrast', name, cmapUpdate, weak=False) display.addListener('contrast', name, cmapUpdate, weak=False)
...@@ -186,7 +185,6 @@ class GLVector(globject.GLImageObject): ...@@ -186,7 +185,6 @@ class GLVector(globject.GLImageObject):
opts = self.displayOpts opts = self.displayOpts
name = self.name name = self.name
display.removeListener('softwareMode', name)
display.removeListener('alpha', name) display.removeListener('alpha', name)
display.removeListener('brightness', name) display.removeListener('brightness', name)
display.removeListener('contrast', name) display.removeListener('contrast', name)
......
...@@ -200,7 +200,6 @@ class GLVolume(globject.GLImageObject): ...@@ -200,7 +200,6 @@ class GLVolume(globject.GLImageObject):
fslgl.glvolume_funcs.updateShaderState(self) fslgl.glvolume_funcs.updateShaderState(self)
self.onUpdate() self.onUpdate()
display.addListener('softwareMode', lName, shaderCompile, weak=False)
display.addListener('alpha', lName, colourUpdate, weak=False) display.addListener('alpha', lName, colourUpdate, weak=False)
opts .addListener('displayRange', lName, colourUpdate, weak=False) opts .addListener('displayRange', lName, colourUpdate, weak=False)
opts .addListener('clippingRange', lName, shaderUpdate, weak=False) opts .addListener('clippingRange', lName, shaderUpdate, weak=False)
...@@ -231,7 +230,6 @@ class GLVolume(globject.GLImageObject): ...@@ -231,7 +230,6 @@ class GLVolume(globject.GLImageObject):
lName = self.name lName = self.name
display.removeListener( 'softwareMode', lName)
display.removeListener( 'alpha', lName) display.removeListener( 'alpha', lName)
opts .removeListener( 'displayRange', lName) opts .removeListener( 'displayRange', lName)
opts .removeListener( 'clippingRange', lName) opts .removeListener( 'clippingRange', lName)
......
...@@ -71,11 +71,11 @@ class SliceCanvas(props.HasProperties): ...@@ -71,11 +71,11 @@ class SliceCanvas(props.HasProperties):
**Performance optimisations** **Performance optimisations**
The :attr:`renderMode`, :attr:`softwareMode`, and :attr:`resolutionLimit` The :attr:`renderMode` and :attr:`resolutionLimit` properties control
properties control various ``SliceCanvas`` performance settings, which can various ``SliceCanvas`` performance settings, which can be useful when
be useful when running in a low performance environment (e.g. when only a running in a low performance environment (e.g. when only a software based
software based GL driver is available). See also the GL driver is available). See also the :attr:`.SceneOpts.performance`
:attr:`.SceneOpts.performance` setting. setting.
The :attr:`resolutionLimit` property controls the highest resolution at The :attr:`resolutionLimit` property controls the highest resolution at
...@@ -85,13 +85,6 @@ class SliceCanvas(props.HasProperties): ...@@ -85,13 +85,6 @@ class SliceCanvas(props.HasProperties):
:class:`.Image` overlay is updated. :class:`.Image` overlay is updated.
The :attr:`softwareMode` property controls the OpenGL shader program that
is used to render overlays - several :class:`.GLObject` types have shader
programs which are optimised for low-performance environments (at the cost
of a reduced feature set). This property is linked to the
:attr:`.Display.softwareMode` property.
The :attr:`renderMode` property controls the way in which the The :attr:`renderMode` property controls the way in which the
``SliceCanvas`` renders :class:`.GLObject` instances. It has three ``SliceCanvas`` renders :class:`.GLObject` instances. It has three
settings: settings:
...@@ -155,7 +148,6 @@ class SliceCanvas(props.HasProperties): ...@@ -155,7 +148,6 @@ class SliceCanvas(props.HasProperties):
cursorColour = copy.copy(canvasopts.SliceCanvasOpts.cursorColour) cursorColour = copy.copy(canvasopts.SliceCanvasOpts.cursorColour)
bgColour = copy.copy(canvasopts.SliceCanvasOpts.bgColour) bgColour = copy.copy(canvasopts.SliceCanvasOpts.bgColour)
renderMode = copy.copy(canvasopts.SliceCanvasOpts.renderMode) renderMode = copy.copy(canvasopts.SliceCanvasOpts.renderMode)
softwareMode = copy.copy(canvasopts.SliceCanvasOpts.softwareMode)
resolutionLimit = copy.copy(canvasopts.SliceCanvasOpts.resolutionLimit) resolutionLimit = copy.copy(canvasopts.SliceCanvasOpts.resolutionLimit)
...@@ -259,7 +251,6 @@ class SliceCanvas(props.HasProperties): ...@@ -259,7 +251,6 @@ class SliceCanvas(props.HasProperties):
disp.removeListener('overlayType', self.name) disp.removeListener('overlayType', self.name)
disp.removeListener('enabled', self.name) disp.removeListener('enabled', self.name)
disp.unbindProps( 'softwareMode', self)
globj.destroy() globj.destroy()
...@@ -708,9 +699,6 @@ class SliceCanvas(props.HasProperties): ...@@ -708,9 +699,6 @@ class SliceCanvas(props.HasProperties):
if updateRenderTextures: if updateRenderTextures:
self._updateRenderTextures() self._updateRenderTextures()
if not display.isBound('softwareMode', self):
display.bindProps('softwareMode', self)
display.addListener('overlayType', display.addListener('overlayType',
self.name, self.name,
self.__overlayTypeChanged, self.__overlayTypeChanged,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment