From dff1fb3d70a5ce08aaf488875a8843aa288381a9 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Sun, 17 Jan 2016 13:40:34 +0000
Subject: [PATCH] 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.

---
 fsl/fsleyes/gl/gl14/glvolume_funcs.py  | 13 +++++++------
 fsl/fsleyes/gl/shaders/arbp/program.py | 11 ++++++++++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/fsl/fsleyes/gl/gl14/glvolume_funcs.py b/fsl/fsleyes/gl/gl14/glvolume_funcs.py
index 033d99809..50dfee229 100644
--- a/fsl/fsleyes/gl/gl14/glvolume_funcs.py
+++ b/fsl/fsleyes/gl/gl14/glvolume_funcs.py
@@ -110,8 +110,9 @@ def updateShaderState(self):
 def preDraw(self):
     """Prepares to draw a slice from the given :class:`.GLVolume` instance. """
 
-    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
     self.shader.load()
+    self.shader.loadAtts()
+    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
 
 
 def draw(self, zpos, xform=None):
@@ -119,10 +120,10 @@ def draw(self, zpos, xform=None):
     
     vertices, voxCoords, texCoords = self.generateVertices(zpos, xform)
 
-    self.shader.setAttr('texCoord', texCoords)
-
     vertices = np.array(vertices,  dtype=np.float32).ravel('C')
     gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices)
+
+    self.shader.setAttr('texCoord', texCoords)
     
     gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
 
@@ -142,11 +143,10 @@ def drawAll(self, zposes, xforms):
         vertices[ i * 6: i * 6 + 6, :] = v
         texCoords[i * 6: i * 6 + 6, :] = tc
 
-    self.shader.setAttr('texCoord', texCoords)
-
     vertices = vertices.ravel('C')
-    
+
     gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices)
+    self.shader.setAttr('texCoord', texCoords)
     gl.glDrawArrays(gl.GL_TRIANGLES, 0, nslices * 6) 
 
 
@@ -155,4 +155,5 @@ def postDraw(self):
     instance.
     """
     gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
+    self.shader.unloadAtts()
     self.shader.unload()
diff --git a/fsl/fsleyes/gl/shaders/arbp/program.py b/fsl/fsleyes/gl/shaders/arbp/program.py
index f82efed26..1a8e13225 100644
--- a/fsl/fsleyes/gl/shaders/arbp/program.py
+++ b/fsl/fsleyes/gl/shaders/arbp/program.py
@@ -69,8 +69,11 @@ class ARBPShader(object):
 
         program = GLSLShader(vertSrc, fragSrc, textures)
 
-        # Load the program
+        # Load the program, and
+        # enable program attributes
+        # (texture coordinates)
         program.load()
+        progra.loadAtts()
 
         # Set some parameters
         program.setVertParam('transform', np.eye(4))
@@ -85,6 +88,7 @@ class ARBPShader(object):
         gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(vertices))
 
         # Clear the GL state
+        program.unloadAtts()
         program.unload()
 
         # Delete the program when
@@ -179,6 +183,8 @@ class ARBPShader(object):
         arbfp.glBindProgramARB(arbfp.GL_FRAGMENT_PROGRAM_ARB,
                                self.fragmentProgram)
 
+    def loadAtts(self):
+        """Enables texture coordinates for all shader program attributes. """
         for attr in self.attrs:
             texUnit = self.__getAttrTexUnit(attr)
 
@@ -191,6 +197,9 @@ class ARBPShader(object):
         gl.glDisable(arbfp.GL_FRAGMENT_PROGRAM_ARB)
         gl.glDisable(arbvp.GL_VERTEX_PROGRAM_ARB)
 
+        
+    def unloadAtts(self):
+        """Disables texture coordinates on all texture units. """
         for attr in self.attrs:
             texUnit = self.__getAttrTexUnit(attr)
 
-- 
GitLab