Commit 31acfd00 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: decouple glsh/glvector from canvas

parent b481b40b
......@@ -165,35 +165,27 @@ def preDraw(self):
"""Called by :meth:`.GLSH.preDraw`. Loads the shader program, and updates
some shader attributes.
"""
shader = self.shader
shader.load()
# Calculate a transformation matrix for
# normal vectors - T(I(MV matrix))
mvMat = self.canvas.viewMatrix[:3, :3]
v2dMat = self.opts.getTransform('voxel', 'display')[:3, :3]
normalMatrix = affine.concat(mvMat, v2dMat)
normalMatrix = npla.inv(normalMatrix).T
shader.set('normalMatrix', normalMatrix)
self.shader.load()
gl.glEnable(gl.GL_CULL_FACE)
gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glCullFace(gl.GL_BACK)
def draw2D(self, zpos, axes, xform=None, applyBbox=True):
def draw2D(self, canvas, zpos, axes, xform=None, applyBbox=True):
"""Called by :meth:`.GLSH.draw2D`. Draws the scene. """
opts = self.opts
shader = self.shader
canvas = self.canvas
mvp = canvas.mvpMatrix
v2dMat = opts.getTransform('voxel', 'display')
# Calculate a transformation matrix for
# normal vectors - T(I(MV matrix))
mvMat = canvas.viewMatrix[:3, :3]
normalMatrix = affine.concat(mvMat, v2dMat[:3, :3])
normalMatrix = npla.inv(normalMatrix).T
if applyBbox: bbox = canvas.viewport
else: bbox = None
......@@ -211,8 +203,9 @@ def draw2D(self, zpos, axes, xform=None, applyBbox=True):
shader.setAtt('voxel', voxels, divisor=1)
shader.setAtt('voxelID', voxIdxs, divisor=1)
shader.set( 'voxToDisplayMat', xform)
shader.set( 'normalMatrix', normalMatrix)
shader.set( 'radTexShape', radTexShape)
shader.set( 'radXform', self.radTexture.voxValXform)
shader.set( 'radXform', self.radTexture.voxValXform)\
with shader.loadedAtts():
glexts.glDrawElementsInstanced(gl.GL_TRIANGLES,
......@@ -222,10 +215,10 @@ def draw2D(self, zpos, axes, xform=None, applyBbox=True):
len(voxels))
def drawAll(self, axes, zposes, xforms):
def drawAll(self, canvas, axes, zposes, xforms):
"""Draws all of the specified slices. """
for zpos, xform in zip(zposes, xforms):
draw2D(self, zpos, axes, xform, applyBbox=False)
draw2D(self, canvas, zpos, axes, xform, applyBbox=False)
def postDraw(self):
......
......@@ -87,7 +87,7 @@ class GLSH(glvector.GLVectorBase):
"""
def __init__(self, image, overlayList, displayCtx, canvas, threedee):
def __init__(self, image, overlayList, displayCtx, threedee):
"""Create a ``GLSH`` object.
......@@ -99,7 +99,6 @@ class GLSH(glvector.GLVectorBase):
:arg image: The :class:`.Image` instance
:arg overlayList: The :class:`.OverlayList`
:arg displayCtx: The :class:`.DisplayContext` managing the scene.
:arg canvas: The canvas doing the drawing.
:arg threedee: Set up for 2D or 3D rendering.
"""
......@@ -126,7 +125,6 @@ class GLSH(glvector.GLVectorBase):
image,
overlayList,
displayCtx,
canvas,
threedee,
preinit=self.compileShaders,
init=self.__shStateChanged)
......
......@@ -89,7 +89,6 @@ class GLVectorBase(glimageobject.GLImageObject):
overlay,
overlayList,
displayCtx,
canvas,
threedee,
init=None,
preinit=None):
......@@ -112,8 +111,6 @@ class GLVectorBase(glimageobject.GLImageObject):
:arg displayCtx: A :class:`.DisplayContext` object which describes
how the overlay is to be displayed.
:arg canvas: The canvas doing the drawing.
:arg threedee: 2D or 3D rendering.
:arg init: An optional function to be called when all of the
......@@ -130,7 +127,6 @@ class GLVectorBase(glimageobject.GLImageObject):
overlay,
overlayList,
displayCtx,
canvas,
threedee)
name = self.name
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment