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

I really have no idea why, but OSMesa screws up lightbox rendering

when i use glDrawArrays. Using glDrawElements (with an index array)
fixes it.
parent dff1fb3d
No related branches found
No related tags found
No related merge requests found
...@@ -117,10 +117,11 @@ def preDraw(self): ...@@ -117,10 +117,11 @@ def preDraw(self):
def draw(self, zpos, xform=None): def draw(self, zpos, xform=None):
"""Draws a slice of the image at the given Z location. """ """Draws a slice of the image at the given Z location. """
vertices, voxCoords, texCoords = self.generateVertices(zpos, xform) vertices, voxCoords, texCoords = self.generateVertices(zpos, xform)
vertices = np.array(vertices, dtype=np.float32).ravel('C') vertices = np.array(vertices, dtype=np.float32).ravel('C')
gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices) gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices)
self.shader.setAttr('texCoord', texCoords) self.shader.setAttr('texCoord', texCoords)
...@@ -136,18 +137,25 @@ def drawAll(self, zposes, xforms): ...@@ -136,18 +137,25 @@ def drawAll(self, zposes, xforms):
nslices = len(zposes) nslices = len(zposes)
vertices = np.zeros((nslices * 6, 3), dtype=np.float32) vertices = np.zeros((nslices * 6, 3), dtype=np.float32)
texCoords = np.zeros((nslices * 6, 3), dtype=np.float32) texCoords = np.zeros((nslices * 6, 3), dtype=np.float32)
indices = np.arange(nslices * 6, dtype=np.uint32)
for i, (zpos, xform) in enumerate(zip(zposes, xforms)): for i, (zpos, xform) in enumerate(zip(zposes, xforms)):
v, vc, tc = self.generateVertices(zpos, xform) v, vc, tc = self.generateVertices(zpos, xform)
vertices[ i * 6: i * 6 + 6, :] = v vertices[ i * 6: i * 6 + 6, :] = v
texCoords[i * 6: i * 6 + 6, :] = tc texCoords[i * 6: i * 6 + 6, :] = tc
vertices = vertices.ravel('C') vertices = vertices.ravel('C')
gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices) gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices)
self.shader.setAttr('texCoord', texCoords) self.shader.setAttr('texCoord', texCoords)
gl.glDrawArrays(gl.GL_TRIANGLES, 0, nslices * 6)
gl.glDrawElements(gl.GL_TRIANGLES,
nslices * 6,
gl.GL_UNSIGNED_INT,
indices)
def postDraw(self): def postDraw(self):
......
...@@ -252,6 +252,11 @@ class GLLabel(globject.GLImageObject): ...@@ -252,6 +252,11 @@ class GLLabel(globject.GLImageObject):
"""Calls the version-dependent ``draw`` function. """ """Calls the version-dependent ``draw`` function. """
fslgl.gllabel_funcs.draw(self, zpos, xform) fslgl.gllabel_funcs.draw(self, zpos, xform)
def drawAll(self, zpos, xform=None):
"""Calls the version-dependent ``drawAll`` function. """
fslgl.gllabel_funcs.drawAll(self, zpos, xform)
def postDraw(self): def postDraw(self):
"""Unbinds the ``ImageTexture`` and ``LookupTableTexture``, and calls """Unbinds the ``ImageTexture`` and ``LookupTableTexture``, and calls
......
...@@ -217,6 +217,8 @@ class ARBPShader(object): ...@@ -217,6 +217,8 @@ class ARBPShader(object):
pos = self.vertParamPositions[name] pos = self.vertParamPositions[name]
value = np.array(value, dtype=np.float32).reshape((-1, 4)) value = np.array(value, dtype=np.float32).reshape((-1, 4))
log.debug('Setting vertex parameter {} = {}'.format(name, value))
for i, row in enumerate(value): for i, row in enumerate(value):
arbvp.glProgramLocalParameter4fARB( arbvp.glProgramLocalParameter4fARB(
...@@ -230,6 +232,8 @@ class ARBPShader(object): ...@@ -230,6 +232,8 @@ class ARBPShader(object):
""" """
pos = self.fragParamPositions[name] pos = self.fragParamPositions[name]
value = np.array(value, dtype=np.float32).reshape((-1, 4)) value = np.array(value, dtype=np.float32).reshape((-1, 4))
log.debug('Setting fragment parameter {} = {}'.format(name, value))
for i, row in enumerate(value): for i, row in enumerate(value):
arbfp.glProgramLocalParameter4fARB( arbfp.glProgramLocalParameter4fARB(
...@@ -247,8 +251,12 @@ class ARBPShader(object): ...@@ -247,8 +251,12 @@ class ARBPShader(object):
texUnit = self.__getAttrTexUnit(name) texUnit = self.__getAttrTexUnit(name)
size = value.shape[1] size = value.shape[1]
value = np.array(value, dtype=np.float32) value = np.array(value, dtype=np.float32)
value = value.ravel('C')
log.debug('Setting vertex attribute {} = [{} * {}]'.format(
name, value.shape[0], size))
value = value.ravel('C')
gl.glClientActiveTexture(texUnit) gl.glClientActiveTexture(texUnit)
gl.glTexCoordPointer(size, gl.GL_FLOAT, 0, value) gl.glTexCoordPointer(size, gl.GL_FLOAT, 0, value)
......
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