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

ARBPShader load separated out into program load, and attribute (texture

coordinate) load. I have absolutely no idea, but off-screen rendering
won't work unless i set vertex coordinates *before* setting texture
coordinates.
parent ccee4d15
No related branches found
No related tags found
No related merge requests found
...@@ -110,8 +110,9 @@ def updateShaderState(self): ...@@ -110,8 +110,9 @@ def updateShaderState(self):
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. """
gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
self.shader.load() self.shader.load()
self.shader.loadAtts()
gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
def draw(self, zpos, xform=None): def draw(self, zpos, xform=None):
...@@ -119,10 +120,10 @@ def draw(self, zpos, xform=None): ...@@ -119,10 +120,10 @@ def draw(self, zpos, xform=None):
vertices, voxCoords, texCoords = self.generateVertices(zpos, xform) vertices, voxCoords, texCoords = self.generateVertices(zpos, xform)
self.shader.setAttr('texCoord', texCoords)
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)
gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6) gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
...@@ -142,11 +143,10 @@ def drawAll(self, zposes, xforms): ...@@ -142,11 +143,10 @@ def drawAll(self, zposes, xforms):
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
self.shader.setAttr('texCoord', texCoords)
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)
gl.glDrawArrays(gl.GL_TRIANGLES, 0, nslices * 6) gl.glDrawArrays(gl.GL_TRIANGLES, 0, nslices * 6)
...@@ -155,4 +155,5 @@ def postDraw(self): ...@@ -155,4 +155,5 @@ def postDraw(self):
instance. instance.
""" """
gl.glDisableClientState(gl.GL_VERTEX_ARRAY) gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
self.shader.unloadAtts()
self.shader.unload() self.shader.unload()
...@@ -69,8 +69,11 @@ class ARBPShader(object): ...@@ -69,8 +69,11 @@ class ARBPShader(object):
program = GLSLShader(vertSrc, fragSrc, textures) program = GLSLShader(vertSrc, fragSrc, textures)
# Load the program # Load the program, and
# enable program attributes
# (texture coordinates)
program.load() program.load()
progra.loadAtts()
# Set some parameters # Set some parameters
program.setVertParam('transform', np.eye(4)) program.setVertParam('transform', np.eye(4))
...@@ -85,6 +88,7 @@ class ARBPShader(object): ...@@ -85,6 +88,7 @@ class ARBPShader(object):
gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(vertices)) gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(vertices))
# Clear the GL state # Clear the GL state
program.unloadAtts()
program.unload() program.unload()
# Delete the program when # Delete the program when
...@@ -179,6 +183,8 @@ class ARBPShader(object): ...@@ -179,6 +183,8 @@ class ARBPShader(object):
arbfp.glBindProgramARB(arbfp.GL_FRAGMENT_PROGRAM_ARB, arbfp.glBindProgramARB(arbfp.GL_FRAGMENT_PROGRAM_ARB,
self.fragmentProgram) self.fragmentProgram)
def loadAtts(self):
"""Enables texture coordinates for all shader program attributes. """
for attr in self.attrs: for attr in self.attrs:
texUnit = self.__getAttrTexUnit(attr) texUnit = self.__getAttrTexUnit(attr)
...@@ -191,6 +197,9 @@ class ARBPShader(object): ...@@ -191,6 +197,9 @@ class ARBPShader(object):
gl.glDisable(arbfp.GL_FRAGMENT_PROGRAM_ARB) gl.glDisable(arbfp.GL_FRAGMENT_PROGRAM_ARB)
gl.glDisable(arbvp.GL_VERTEX_PROGRAM_ARB) gl.glDisable(arbvp.GL_VERTEX_PROGRAM_ARB)
def unloadAtts(self):
"""Disables texture coordinates on all texture units. """
for attr in self.attrs: for attr in self.attrs:
texUnit = self.__getAttrTexUnit(attr) texUnit = self.__getAttrTexUnit(attr)
......
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