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

GLSLShader.set keeps track of value changes, and returns True or False

so caller can tell whether shader state was actually
changed. GLVolume (for OpenGL 2.1) updated to use this feature.
parent 8c310b5b
No related branches found
No related tags found
No related merge requests found
...@@ -106,6 +106,8 @@ def updateShaderState(self): ...@@ -106,6 +106,8 @@ def updateShaderState(self):
self.shader.unload() self.shader.unload()
return True
def preDraw(self): def preDraw(self):
"""Prepares to draw a slice from the given :class:`.GLVolume` instance. """ """Prepares to draw a slice from the given :class:`.GLVolume` instance. """
......
...@@ -83,24 +83,28 @@ def updateShaderState(self): ...@@ -83,24 +83,28 @@ def updateShaderState(self):
self.colourTexture.getCoordinateTransform()) self.colourTexture.getCoordinateTransform())
shader.load() shader.load()
changed = False
shader.set('useSpline', opts.interpolation == 'spline') changed |= shader.set('useSpline', opts.interpolation == 'spline')
shader.set('imageShape', self.image.shape[:3]) changed |= shader.set('imageShape', self.image.shape[:3])
shader.set('clipLow', clipLow) changed |= shader.set('clipLow', clipLow)
shader.set('clipHigh', clipHigh) changed |= shader.set('clipHigh', clipHigh)
shader.set('texZero', texZero) changed |= shader.set('texZero', texZero)
shader.set('invertClip', opts.invertClipping) changed |= shader.set('invertClip', opts.invertClipping)
shader.set('useNegCmap', opts.useNegativeCmap) changed |= shader.set('useNegCmap', opts.useNegativeCmap)
shader.set('imageIsClip', opts.clipImage is None) changed |= shader.set('imageIsClip', opts.clipImage is None)
shader.set('img2CmapXform', img2CmapXform) changed |= shader.set('img2CmapXform', img2CmapXform)
shader.set('imageTexture', 0) changed |= shader.set('imageTexture', 0)
shader.set('colourTexture', 1) changed |= shader.set('colourTexture', 1)
shader.set('negColourTexture', 2) changed |= shader.set('negColourTexture', 2)
shader.set('clipTexture', 3) changed |= shader.set('clipTexture', 3)
shader.unload() shader.unload()
return changed
def preDraw(self): def preDraw(self):
"""Sets up the GL state to draw a slice from the given :class:`.GLVolume` """Sets up the GL state to draw a slice from the given :class:`.GLVolume`
......
...@@ -265,11 +265,10 @@ class GLVolume(globject.GLImageObject): ...@@ -265,11 +265,10 @@ class GLVolume(globject.GLImageObject):
def update(*a): def update(*a):
self.notify() self.notify()
def shaderUpdate(*a): def shaderUpdate(*a):
if self.ready(): if self.ready():
fslgl.glvolume_funcs.updateShaderState(self) if fslgl.glvolume_funcs.updateShaderState(self):
self.notify() self.notify()
def colourUpdate(*a): def colourUpdate(*a):
self.refreshColourTextures() self.refreshColourTextures()
......
...@@ -149,6 +149,13 @@ class GLSLShader(object): ...@@ -149,6 +149,13 @@ class GLSLShader(object):
self.vertUniforms, self.vertUniforms,
self.fragUniforms) self.fragUniforms)
# We cache the most recent value for
# every uniform. When a call to set()
# is made, if the value is unchanged,
# we skip the GL call.
self.values = {n : None for n in self.positions.keys()}
# Buffers for vertex attributes
self.buffers = {} self.buffers = {}
for att in self.vertAttributes: for att in self.vertAttributes:
...@@ -234,7 +241,16 @@ class GLSLShader(object): ...@@ -234,7 +241,16 @@ class GLSLShader(object):
def set(self, name, value): def set(self, name, value):
"""Sets the value for the specified GLSL ``uniform`` variable. """ """Sets the value for the specified GLSL ``uniform`` variable.
The ``GLSLShader`` keeps a copy of the value of every uniform, to
avoid unnecessary GL calls.
:returns: ``True`` if the value was changed, ``False`` otherwise.
"""
if self.values[name] == value:
return False
vPos = self.positions[name] vPos = self.positions[name]
vType = self.types[ name] vType = self.types[ name]
...@@ -250,6 +266,8 @@ class GLSLShader(object): ...@@ -250,6 +266,8 @@ class GLSLShader(object):
setfunc(vPos, value) setfunc(vPos, value)
return True
def setAtt(self, name, value, divisor=None): def setAtt(self, name, value, divisor=None):
"""Sets the value for the specified GLSL ``attribute`` variable. """Sets the value for the specified GLSL ``attribute`` variable.
......
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