We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Removing and adding a GLScatterPlotItem removes a GLViewWidget's GLGridItems
### Short description
This bug is mercurial and will not occur if you're only using one ScatterPlotItem, or if you toggle the second instead of the first, or if you immediately remove and then show the first item before toggling it, ...

Looks related to  #103 and #145

### Code to reproduce

```python
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np

app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('GLScatterPlotItem making GLGridItem invisible example')

gx = gl.GLGridItem()
w.addItem(gx)


window = QtWidgets.QMainWindow()

plt1 = gl.GLScatterPlotItem(pos=np.zeros((1, 3)))
plt2 = gl.GLScatterPlotItem(pos=np.zeros((1, 3)))
plt3 = gl.GLScatterPlotItem(pos=np.zeros((1, 3)))
w.addItem(plt1)
w.addItem(plt2)
w.addItem(plt3)

show = False
def toggle():
    global show
    if show:
        w.addItem(plt2)
    else:
        w.removeItem(plt2)
    show = not show

ok = QtWidgets.QPushButton('Ok')
ok.clicked.connect(toggle)

window.setCentralWidget(ok)

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        window.show()
        QtGui.QApplication.instance().exec_()
```

Click the button twice and the grids disappear.

### Tested environment(s)

 * PyQtGraph version: 0.11.0.dev0+gad7453c
 * Qt Python binding: PySide2 5.13.0 Qt 5.13.0
 * Python version: 3.7.4 x64
 * NumPy version: 1.17.0
 * Operating system: Windows 10
 * Installation method: <!-- e.g. pip, conda, system packages, ... -->


*edit by ixjlyons: code fences around the example code*

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyqtgraph/opengl/items/GLImageItem.py`
Content:
```
1 from OpenGL.GL import *
2 from .. GLGraphicsItem import GLGraphicsItem
3 from ...Qt import QtGui
4 import numpy as np
5 
6 __all__ = ['GLImageItem']
7 
8 class GLImageItem(GLGraphicsItem):
9     """
10     **Bases:** :class:`GLGraphicsItem <pyqtgraph.opengl.GLGraphicsItem>`
11     
12     Displays image data as a textured quad.
13     """
14     
15     
16     def __init__(self, data, smooth=False, glOptions='translucent'):
17         """
18         
19         ==============  =======================================================================================
20         **Arguments:**
21         data            Volume data to be rendered. *Must* be 3D numpy array (x, y, RGBA) with dtype=ubyte.
22                         (See functions.makeRGBA)
23         smooth          (bool) If True, the volume slices are rendered with linear interpolation 
24         ==============  =======================================================================================
25         """
26         
27         self.smooth = smooth
28         self._needUpdate = False
29         GLGraphicsItem.__init__(self)
30         self.setData(data)
31         self.setGLOptions(glOptions)
32         
33     def initializeGL(self):
34         glEnable(GL_TEXTURE_2D)
35         self.texture = glGenTextures(1)
36         
37     def setData(self, data):
38         self.data = data
39         self._needUpdate = True
40         self.update()
41         
42     def _updateTexture(self):
43         glBindTexture(GL_TEXTURE_2D, self.texture)
44         if self.smooth:
45             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
46             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
47         else:
48             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
49             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
50         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER)
51         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER)
52         #glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER)
53         shape = self.data.shape
54         
55         ## Test texture dimensions first
56         glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, None)
57         if glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) == 0:
58             raise Exception("OpenGL failed to create 2D texture (%dx%d); too large for this hardware." % shape[:2])
59         
60         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.data.transpose((1,0,2)))
61         glDisable(GL_TEXTURE_2D)
62         
63         #self.lists = {}
64         #for ax in [0,1,2]:
65             #for d in [-1, 1]:
66                 #l = glGenLists(1)
67                 #self.lists[(ax,d)] = l
68                 #glNewList(l, GL_COMPILE)
69                 #self.drawVolume(ax, d)
70                 #glEndList()
71 
72                 
73     def paint(self):
74         if self._needUpdate:
75             self._updateTexture()
76         glEnable(GL_TEXTURE_2D)
77         glBindTexture(GL_TEXTURE_2D, self.texture)
78         
79         self.setupGLState()
80         
81         #glEnable(GL_DEPTH_TEST)
82         ##glDisable(GL_CULL_FACE)
83         #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
84         #glEnable( GL_BLEND )
85         #glEnable( GL_ALPHA_TEST )
86         glColor4f(1,1,1,1)
87 
88         glBegin(GL_QUADS)
89         glTexCoord2f(0,0)
90         glVertex3f(0,0,0)
91         glTexCoord2f(1,0)
92         glVertex3f(self.data.shape[0], 0, 0)
93         glTexCoord2f(1,1)
94         glVertex3f(self.data.shape[0], self.data.shape[1], 0)
95         glTexCoord2f(0,1)
96         glVertex3f(0, self.data.shape[1], 0)
97         glEnd()
98         glDisable(GL_TEXTURE_3D)
99                 
100
```

Path: `pyqtgraph/opengl/items/GLScatterPlotItem.py`
Content:
```
1 from OpenGL.GL import *
2 from OpenGL.arrays import vbo
3 from .. GLGraphicsItem import GLGraphicsItem
4 from .. import shaders
5 from ... import QtGui
6 import numpy as np
7 
8 __all__ = ['GLScatterPlotItem']
9 
10 class GLScatterPlotItem(GLGraphicsItem):
11     """Draws points at a list of 3D positions."""
12     
13     def __init__(self, **kwds):
14         GLGraphicsItem.__init__(self)
15         glopts = kwds.pop('glOptions', 'additive')
16         self.setGLOptions(glopts)
17         self.pos = []
18         self.size = 10
19         self.color = [1.0,1.0,1.0,0.5]
20         self.pxMode = True
21         #self.vbo = {}      ## VBO does not appear to improve performance very much.
22         self.setData(**kwds)
23     
24     def setData(self, **kwds):
25         """
26         Update the data displayed by this item. All arguments are optional; 
27         for example it is allowed to update spot positions while leaving 
28         colors unchanged, etc.
29         
30         ====================  ==================================================
31         **Arguments:**
32         pos                   (N,3) array of floats specifying point locations.
33         color                 (N,4) array of floats (0.0-1.0) specifying
34                               spot colors OR a tuple of floats specifying
35                               a single color for all spots.
36         size                  (N,) array of floats specifying spot sizes or 
37                               a single value to apply to all spots.
38         pxMode                If True, spot sizes are expressed in pixels. 
39                               Otherwise, they are expressed in item coordinates.
40         ====================  ==================================================
41         """
42         args = ['pos', 'color', 'size', 'pxMode']
43         for k in kwds.keys():
44             if k not in args:
45                 raise Exception('Invalid keyword argument: %s (allowed arguments are %s)' % (k, str(args)))
46             
47         args.remove('pxMode')
48         for arg in args:
49             if arg in kwds:
50                 setattr(self, arg, kwds[arg])
51                 #self.vbo.pop(arg, None)
52                 
53         self.pxMode = kwds.get('pxMode', self.pxMode)
54         self.update()
55 
56     def initializeGL(self):
57         
58         ## Generate texture for rendering points
59         w = 64
60         def fn(x,y):
61             r = ((x-w/2.)**2 + (y-w/2.)**2) ** 0.5
62             return 255 * (w/2. - np.clip(r, w/2.-1.0, w/2.))
63         pData = np.empty((w, w, 4))
64         pData[:] = 255
65         pData[:,:,3] = np.fromfunction(fn, pData.shape[:2])
66         #print pData.shape, pData.min(), pData.max()
67         pData = pData.astype(np.ubyte)
68         
69         if getattr(self, "pointTexture", None) is None:
70             self.pointTexture = glGenTextures(1)
71         glActiveTexture(GL_TEXTURE0)
72         glEnable(GL_TEXTURE_2D)
73         glBindTexture(GL_TEXTURE_2D, self.pointTexture)
74         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pData.shape[0], pData.shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, pData)
75         
76         self.shader = shaders.getShaderProgram('pointSprite')
77         
78     #def getVBO(self, name):
79         #if name not in self.vbo:
80             #self.vbo[name] = vbo.VBO(getattr(self, name).astype('f'))
81         #return self.vbo[name]
82         
83     #def setupGLState(self):
84         #"""Prepare OpenGL state for drawing. This function is called immediately before painting."""
85         ##glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)  ## requires z-sorting to render properly.
86         #glBlendFunc(GL_SRC_ALPHA, GL_ONE)
87         #glEnable( GL_BLEND )
88         #glEnable( GL_ALPHA_TEST )
89         #glDisable( GL_DEPTH_TEST )
90         
91         ##glEnable( GL_POINT_SMOOTH )
92 
93         ##glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
94         ##glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (0, 0, -1e-3))
95         ##glPointParameterfv(GL_POINT_SIZE_MAX, (65500,))
96         ##glPointParameterfv(GL_POINT_SIZE_MIN, (0,))
97         
98     def paint(self):
99         self.setupGLState()
100         
101         glEnable(GL_POINT_SPRITE)
102         
103         glActiveTexture(GL_TEXTURE0)
104         glEnable( GL_TEXTURE_2D )
105         glBindTexture(GL_TEXTURE_2D, self.pointTexture)
106     
107         glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)
108         #glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)    ## use texture color exactly
109         #glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )  ## texture modulates current color
110         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
111         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
112         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
113         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
114         glEnable(GL_PROGRAM_POINT_SIZE)
115         
116             
117         with self.shader:
118             #glUniform1i(self.shader.uniform('texture'), 0)  ## inform the shader which texture to use
119             glEnableClientState(GL_VERTEX_ARRAY)
120             try:
121                 pos = self.pos
122                 #if pos.ndim > 2:
123                     #pos = pos.reshape((reduce(lambda a,b: a*b, pos.shape[:-1]), pos.shape[-1]))
124                 glVertexPointerf(pos)
125             
126                 if isinstance(self.color, np.ndarray):
127                     glEnableClientState(GL_COLOR_ARRAY)
128                     glColorPointerf(self.color)
129                 else:
130                     if isinstance(self.color, QtGui.QColor):
131                         glColor4f(*fn.glColor(self.color))
132                     else:
133                         glColor4f(*self.color)
134                 
135                 if not self.pxMode or isinstance(self.size, np.ndarray):
136                     glEnableClientState(GL_NORMAL_ARRAY)
137                     norm = np.empty(pos.shape)
138                     if self.pxMode:
139                         norm[...,0] = self.size
140                     else:
141                         gpos = self.mapToView(pos.transpose()).transpose()
142                         pxSize = self.view().pixelSize(gpos)
143                         norm[...,0] = self.size / pxSize
144                     
145                     glNormalPointerf(norm)
146                 else:
147                     glNormal3f(self.size, 0, 0)  ## vertex shader uses norm.x to determine point size
148                     #glPointSize(self.size)
149                 glDrawArrays(GL_POINTS, 0, int(pos.size / pos.shape[-1]))
150             finally:
151                 glDisableClientState(GL_NORMAL_ARRAY)
152                 glDisableClientState(GL_VERTEX_ARRAY)
153                 glDisableClientState(GL_COLOR_ARRAY)
154                 #posVBO.unbind()
155                 ##fixes #145
156                 glDisable( GL_TEXTURE_2D )
157                                 
158         #for i in range(len(self.pos)):
159             #pos = self.pos[i]
160             
161             #if isinstance(self.color, np.ndarray):
162                 #color = self.color[i]
163             #else:
164                 #color = self.color
165             #if isinstance(self.color, QtGui.QColor):
166                 #color = fn.glColor(self.color)
167                 
168             #if isinstance(self.size, np.ndarray):
169                 #size = self.size[i]
170             #else:
171                 #size = self.size
172                 
173             #pxSize = self.view().pixelSize(QtGui.QVector3D(*pos))
174             
175             #glPointSize(size / pxSize)
176             #glBegin( GL_POINTS )
177             #glColor4f(*color)  # x is blue
178             ##glNormal3f(size, 0, 0)
179             #glVertex3f(*pos)
180             #glEnd()
181 
182         
183         
184         
185         
186
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pyqtgraph/opengl/items/GLImageItem.py b/pyqtgraph/opengl/items/GLImageItem.py
--- a/pyqtgraph/opengl/items/GLImageItem.py
+++ b/pyqtgraph/opengl/items/GLImageItem.py
@@ -29,8 +29,11 @@
         GLGraphicsItem.__init__(self)
         self.setData(data)
         self.setGLOptions(glOptions)
+        self.texture = None
         
     def initializeGL(self):
+        if self.texture is not None:
+            return
         glEnable(GL_TEXTURE_2D)
         self.texture = glGenTextures(1)
         
diff --git a/pyqtgraph/opengl/items/GLScatterPlotItem.py b/pyqtgraph/opengl/items/GLScatterPlotItem.py
--- a/pyqtgraph/opengl/items/GLScatterPlotItem.py
+++ b/pyqtgraph/opengl/items/GLScatterPlotItem.py
@@ -20,6 +20,7 @@
         self.pxMode = True
         #self.vbo = {}      ## VBO does not appear to improve performance very much.
         self.setData(**kwds)
+        self.shader = None
     
     def setData(self, **kwds):
         """
@@ -54,6 +55,8 @@
         self.update()
 
     def initializeGL(self):
+        if self.shader is not None:
+            return
         
         ## Generate texture for rendering points
         w = 64

{"golden_diff": "diff --git a/pyqtgraph/opengl/items/GLImageItem.py b/pyqtgraph/opengl/items/GLImageItem.py\n--- a/pyqtgraph/opengl/items/GLImageItem.py\n+++ b/pyqtgraph/opengl/items/GLImageItem.py\n@@ -29,8 +29,11 @@\n         GLGraphicsItem.__init__(self)\n         self.setData(data)\n         self.setGLOptions(glOptions)\n+        self.texture = None\n         \n     def initializeGL(self):\n+        if self.texture is not None:\n+            return\n         glEnable(GL_TEXTURE_2D)\n         self.texture = glGenTextures(1)\n         \ndiff --git a/pyqtgraph/opengl/items/GLScatterPlotItem.py b/pyqtgraph/opengl/items/GLScatterPlotItem.py\n--- a/pyqtgraph/opengl/items/GLScatterPlotItem.py\n+++ b/pyqtgraph/opengl/items/GLScatterPlotItem.py\n@@ -20,6 +20,7 @@\n         self.pxMode = True\n         #self.vbo = {}      ## VBO does not appear to improve performance very much.\n         self.setData(**kwds)\n+        self.shader = None\n     \n     def setData(self, **kwds):\n         \"\"\"\n@@ -54,6 +55,8 @@\n         self.update()\n \n     def initializeGL(self):\n+        if self.shader is not None:\n+            return\n         \n         ## Generate texture for rendering points\n         w = 64\n", "issue": "Removing and adding a GLScatterPlotItem removes a GLViewWidget's GLGridItems\n### Short description\r\nThis bug is mercurial and will not occur if you're only using one ScatterPlotItem, or if you toggle the second instead of the first, or if you immediately remove and then show the first item before toggling it, ...\r\n\r\nLooks related to  #103 and #145\r\n\r\n### Code to reproduce\r\n\r\n```python\r\nfrom pyqtgraph.Qt import QtCore, QtGui, QtWidgets\r\nimport pyqtgraph.opengl as gl\r\nimport pyqtgraph as pg\r\nimport numpy as np\r\n\r\napp = QtGui.QApplication([])\r\nw = gl.GLViewWidget()\r\nw.show()\r\nw.setWindowTitle('GLScatterPlotItem making GLGridItem invisible example')\r\n\r\ngx = gl.GLGridItem()\r\nw.addItem(gx)\r\n\r\n\r\nwindow = QtWidgets.QMainWindow()\r\n\r\nplt1 = gl.GLScatterPlotItem(pos=np.zeros((1, 3)))\r\nplt2 = gl.GLScatterPlotItem(pos=np.zeros((1, 3)))\r\nplt3 = gl.GLScatterPlotItem(pos=np.zeros((1, 3)))\r\nw.addItem(plt1)\r\nw.addItem(plt2)\r\nw.addItem(plt3)\r\n\r\nshow = False\r\ndef toggle():\r\n    global show\r\n    if show:\r\n        w.addItem(plt2)\r\n    else:\r\n        w.removeItem(plt2)\r\n    show = not show\r\n\r\nok = QtWidgets.QPushButton('Ok')\r\nok.clicked.connect(toggle)\r\n\r\nwindow.setCentralWidget(ok)\r\n\r\nif __name__ == '__main__':\r\n    import sys\r\n    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):\r\n        window.show()\r\n        QtGui.QApplication.instance().exec_()\r\n```\r\n\r\nClick the button twice and the grids disappear.\r\n\r\n### Tested environment(s)\r\n\r\n * PyQtGraph version: 0.11.0.dev0+gad7453c\r\n * Qt Python binding: PySide2 5.13.0 Qt 5.13.0\r\n * Python version: 3.7.4 x64\r\n * NumPy version: 1.17.0\r\n * Operating system: Windows 10\r\n * Installation method: <!-- e.g. pip, conda, system packages, ... -->\r\n\r\n\r\n*edit by ixjlyons: code fences around the example code*\n", "before_files": [{"content": "from OpenGL.GL import *\nfrom .. GLGraphicsItem import GLGraphicsItem\nfrom ...Qt import QtGui\nimport numpy as np\n\n__all__ = ['GLImageItem']\n\nclass GLImageItem(GLGraphicsItem):\n    \"\"\"\n    **Bases:** :class:`GLGraphicsItem <pyqtgraph.opengl.GLGraphicsItem>`\n    \n    Displays image data as a textured quad.\n    \"\"\"\n    \n    \n    def __init__(self, data, smooth=False, glOptions='translucent'):\n        \"\"\"\n        \n        ==============  =======================================================================================\n        **Arguments:**\n        data            Volume data to be rendered. *Must* be 3D numpy array (x, y, RGBA) with dtype=ubyte.\n                        (See functions.makeRGBA)\n        smooth          (bool) If True, the volume slices are rendered with linear interpolation \n        ==============  =======================================================================================\n        \"\"\"\n        \n        self.smooth = smooth\n        self._needUpdate = False\n        GLGraphicsItem.__init__(self)\n        self.setData(data)\n        self.setGLOptions(glOptions)\n        \n    def initializeGL(self):\n        glEnable(GL_TEXTURE_2D)\n        self.texture = glGenTextures(1)\n        \n    def setData(self, data):\n        self.data = data\n        self._needUpdate = True\n        self.update()\n        \n    def _updateTexture(self):\n        glBindTexture(GL_TEXTURE_2D, self.texture)\n        if self.smooth:\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)\n        else:\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER)\n        #glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER)\n        shape = self.data.shape\n        \n        ## Test texture dimensions first\n        glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, None)\n        if glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) == 0:\n            raise Exception(\"OpenGL failed to create 2D texture (%dx%d); too large for this hardware.\" % shape[:2])\n        \n        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.data.transpose((1,0,2)))\n        glDisable(GL_TEXTURE_2D)\n        \n        #self.lists = {}\n        #for ax in [0,1,2]:\n            #for d in [-1, 1]:\n                #l = glGenLists(1)\n                #self.lists[(ax,d)] = l\n                #glNewList(l, GL_COMPILE)\n                #self.drawVolume(ax, d)\n                #glEndList()\n\n                \n    def paint(self):\n        if self._needUpdate:\n            self._updateTexture()\n        glEnable(GL_TEXTURE_2D)\n        glBindTexture(GL_TEXTURE_2D, self.texture)\n        \n        self.setupGLState()\n        \n        #glEnable(GL_DEPTH_TEST)\n        ##glDisable(GL_CULL_FACE)\n        #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)\n        #glEnable( GL_BLEND )\n        #glEnable( GL_ALPHA_TEST )\n        glColor4f(1,1,1,1)\n\n        glBegin(GL_QUADS)\n        glTexCoord2f(0,0)\n        glVertex3f(0,0,0)\n        glTexCoord2f(1,0)\n        glVertex3f(self.data.shape[0], 0, 0)\n        glTexCoord2f(1,1)\n        glVertex3f(self.data.shape[0], self.data.shape[1], 0)\n        glTexCoord2f(0,1)\n        glVertex3f(0, self.data.shape[1], 0)\n        glEnd()\n        glDisable(GL_TEXTURE_3D)\n                \n", "path": "pyqtgraph/opengl/items/GLImageItem.py"}, {"content": "from OpenGL.GL import *\nfrom OpenGL.arrays import vbo\nfrom .. GLGraphicsItem import GLGraphicsItem\nfrom .. import shaders\nfrom ... import QtGui\nimport numpy as np\n\n__all__ = ['GLScatterPlotItem']\n\nclass GLScatterPlotItem(GLGraphicsItem):\n    \"\"\"Draws points at a list of 3D positions.\"\"\"\n    \n    def __init__(self, **kwds):\n        GLGraphicsItem.__init__(self)\n        glopts = kwds.pop('glOptions', 'additive')\n        self.setGLOptions(glopts)\n        self.pos = []\n        self.size = 10\n        self.color = [1.0,1.0,1.0,0.5]\n        self.pxMode = True\n        #self.vbo = {}      ## VBO does not appear to improve performance very much.\n        self.setData(**kwds)\n    \n    def setData(self, **kwds):\n        \"\"\"\n        Update the data displayed by this item. All arguments are optional; \n        for example it is allowed to update spot positions while leaving \n        colors unchanged, etc.\n        \n        ====================  ==================================================\n        **Arguments:**\n        pos                   (N,3) array of floats specifying point locations.\n        color                 (N,4) array of floats (0.0-1.0) specifying\n                              spot colors OR a tuple of floats specifying\n                              a single color for all spots.\n        size                  (N,) array of floats specifying spot sizes or \n                              a single value to apply to all spots.\n        pxMode                If True, spot sizes are expressed in pixels. \n                              Otherwise, they are expressed in item coordinates.\n        ====================  ==================================================\n        \"\"\"\n        args = ['pos', 'color', 'size', 'pxMode']\n        for k in kwds.keys():\n            if k not in args:\n                raise Exception('Invalid keyword argument: %s (allowed arguments are %s)' % (k, str(args)))\n            \n        args.remove('pxMode')\n        for arg in args:\n            if arg in kwds:\n                setattr(self, arg, kwds[arg])\n                #self.vbo.pop(arg, None)\n                \n        self.pxMode = kwds.get('pxMode', self.pxMode)\n        self.update()\n\n    def initializeGL(self):\n        \n        ## Generate texture for rendering points\n        w = 64\n        def fn(x,y):\n            r = ((x-w/2.)**2 + (y-w/2.)**2) ** 0.5\n            return 255 * (w/2. - np.clip(r, w/2.-1.0, w/2.))\n        pData = np.empty((w, w, 4))\n        pData[:] = 255\n        pData[:,:,3] = np.fromfunction(fn, pData.shape[:2])\n        #print pData.shape, pData.min(), pData.max()\n        pData = pData.astype(np.ubyte)\n        \n        if getattr(self, \"pointTexture\", None) is None:\n            self.pointTexture = glGenTextures(1)\n        glActiveTexture(GL_TEXTURE0)\n        glEnable(GL_TEXTURE_2D)\n        glBindTexture(GL_TEXTURE_2D, self.pointTexture)\n        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pData.shape[0], pData.shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, pData)\n        \n        self.shader = shaders.getShaderProgram('pointSprite')\n        \n    #def getVBO(self, name):\n        #if name not in self.vbo:\n            #self.vbo[name] = vbo.VBO(getattr(self, name).astype('f'))\n        #return self.vbo[name]\n        \n    #def setupGLState(self):\n        #\"\"\"Prepare OpenGL state for drawing. This function is called immediately before painting.\"\"\"\n        ##glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)  ## requires z-sorting to render properly.\n        #glBlendFunc(GL_SRC_ALPHA, GL_ONE)\n        #glEnable( GL_BLEND )\n        #glEnable( GL_ALPHA_TEST )\n        #glDisable( GL_DEPTH_TEST )\n        \n        ##glEnable( GL_POINT_SMOOTH )\n\n        ##glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)\n        ##glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (0, 0, -1e-3))\n        ##glPointParameterfv(GL_POINT_SIZE_MAX, (65500,))\n        ##glPointParameterfv(GL_POINT_SIZE_MIN, (0,))\n        \n    def paint(self):\n        self.setupGLState()\n        \n        glEnable(GL_POINT_SPRITE)\n        \n        glActiveTexture(GL_TEXTURE0)\n        glEnable( GL_TEXTURE_2D )\n        glBindTexture(GL_TEXTURE_2D, self.pointTexture)\n    \n        glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)\n        #glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)    ## use texture color exactly\n        #glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )  ## texture modulates current color\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)\n        glEnable(GL_PROGRAM_POINT_SIZE)\n        \n            \n        with self.shader:\n            #glUniform1i(self.shader.uniform('texture'), 0)  ## inform the shader which texture to use\n            glEnableClientState(GL_VERTEX_ARRAY)\n            try:\n                pos = self.pos\n                #if pos.ndim > 2:\n                    #pos = pos.reshape((reduce(lambda a,b: a*b, pos.shape[:-1]), pos.shape[-1]))\n                glVertexPointerf(pos)\n            \n                if isinstance(self.color, np.ndarray):\n                    glEnableClientState(GL_COLOR_ARRAY)\n                    glColorPointerf(self.color)\n                else:\n                    if isinstance(self.color, QtGui.QColor):\n                        glColor4f(*fn.glColor(self.color))\n                    else:\n                        glColor4f(*self.color)\n                \n                if not self.pxMode or isinstance(self.size, np.ndarray):\n                    glEnableClientState(GL_NORMAL_ARRAY)\n                    norm = np.empty(pos.shape)\n                    if self.pxMode:\n                        norm[...,0] = self.size\n                    else:\n                        gpos = self.mapToView(pos.transpose()).transpose()\n                        pxSize = self.view().pixelSize(gpos)\n                        norm[...,0] = self.size / pxSize\n                    \n                    glNormalPointerf(norm)\n                else:\n                    glNormal3f(self.size, 0, 0)  ## vertex shader uses norm.x to determine point size\n                    #glPointSize(self.size)\n                glDrawArrays(GL_POINTS, 0, int(pos.size / pos.shape[-1]))\n            finally:\n                glDisableClientState(GL_NORMAL_ARRAY)\n                glDisableClientState(GL_VERTEX_ARRAY)\n                glDisableClientState(GL_COLOR_ARRAY)\n                #posVBO.unbind()\n                ##fixes #145\n                glDisable( GL_TEXTURE_2D )\n                                \n        #for i in range(len(self.pos)):\n            #pos = self.pos[i]\n            \n            #if isinstance(self.color, np.ndarray):\n                #color = self.color[i]\n            #else:\n                #color = self.color\n            #if isinstance(self.color, QtGui.QColor):\n                #color = fn.glColor(self.color)\n                \n            #if isinstance(self.size, np.ndarray):\n                #size = self.size[i]\n            #else:\n                #size = self.size\n                \n            #pxSize = self.view().pixelSize(QtGui.QVector3D(*pos))\n            \n            #glPointSize(size / pxSize)\n            #glBegin( GL_POINTS )\n            #glColor4f(*color)  # x is blue\n            ##glNormal3f(size, 0, 0)\n            #glVertex3f(*pos)\n            #glEnd()\n\n        \n        \n        \n        \n", "path": "pyqtgraph/opengl/items/GLScatterPlotItem.py"}], "after_files": [{"content": "from OpenGL.GL import *\nfrom .. GLGraphicsItem import GLGraphicsItem\nfrom ...Qt import QtGui\nimport numpy as np\n\n__all__ = ['GLImageItem']\n\nclass GLImageItem(GLGraphicsItem):\n    \"\"\"\n    **Bases:** :class:`GLGraphicsItem <pyqtgraph.opengl.GLGraphicsItem>`\n    \n    Displays image data as a textured quad.\n    \"\"\"\n    \n    \n    def __init__(self, data, smooth=False, glOptions='translucent'):\n        \"\"\"\n        \n        ==============  =======================================================================================\n        **Arguments:**\n        data            Volume data to be rendered. *Must* be 3D numpy array (x, y, RGBA) with dtype=ubyte.\n                        (See functions.makeRGBA)\n        smooth          (bool) If True, the volume slices are rendered with linear interpolation \n        ==============  =======================================================================================\n        \"\"\"\n        \n        self.smooth = smooth\n        self._needUpdate = False\n        GLGraphicsItem.__init__(self)\n        self.setData(data)\n        self.setGLOptions(glOptions)\n        self.texture = None\n        \n    def initializeGL(self):\n        if self.texture is not None:\n            return\n        glEnable(GL_TEXTURE_2D)\n        self.texture = glGenTextures(1)\n        \n    def setData(self, data):\n        self.data = data\n        self._needUpdate = True\n        self.update()\n        \n    def _updateTexture(self):\n        glBindTexture(GL_TEXTURE_2D, self.texture)\n        if self.smooth:\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)\n        else:\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)\n            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER)\n        #glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER)\n        shape = self.data.shape\n        \n        ## Test texture dimensions first\n        glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, None)\n        if glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH) == 0:\n            raise Exception(\"OpenGL failed to create 2D texture (%dx%d); too large for this hardware.\" % shape[:2])\n        \n        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, shape[0], shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.data.transpose((1,0,2)))\n        glDisable(GL_TEXTURE_2D)\n        \n        #self.lists = {}\n        #for ax in [0,1,2]:\n            #for d in [-1, 1]:\n                #l = glGenLists(1)\n                #self.lists[(ax,d)] = l\n                #glNewList(l, GL_COMPILE)\n                #self.drawVolume(ax, d)\n                #glEndList()\n\n                \n    def paint(self):\n        if self._needUpdate:\n            self._updateTexture()\n        glEnable(GL_TEXTURE_2D)\n        glBindTexture(GL_TEXTURE_2D, self.texture)\n        \n        self.setupGLState()\n        \n        #glEnable(GL_DEPTH_TEST)\n        ##glDisable(GL_CULL_FACE)\n        #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)\n        #glEnable( GL_BLEND )\n        #glEnable( GL_ALPHA_TEST )\n        glColor4f(1,1,1,1)\n\n        glBegin(GL_QUADS)\n        glTexCoord2f(0,0)\n        glVertex3f(0,0,0)\n        glTexCoord2f(1,0)\n        glVertex3f(self.data.shape[0], 0, 0)\n        glTexCoord2f(1,1)\n        glVertex3f(self.data.shape[0], self.data.shape[1], 0)\n        glTexCoord2f(0,1)\n        glVertex3f(0, self.data.shape[1], 0)\n        glEnd()\n        glDisable(GL_TEXTURE_3D)\n                \n", "path": "pyqtgraph/opengl/items/GLImageItem.py"}, {"content": "from OpenGL.GL import *\nfrom OpenGL.arrays import vbo\nfrom .. GLGraphicsItem import GLGraphicsItem\nfrom .. import shaders\nfrom ... import QtGui\nimport numpy as np\n\n__all__ = ['GLScatterPlotItem']\n\nclass GLScatterPlotItem(GLGraphicsItem):\n    \"\"\"Draws points at a list of 3D positions.\"\"\"\n    \n    def __init__(self, **kwds):\n        GLGraphicsItem.__init__(self)\n        glopts = kwds.pop('glOptions', 'additive')\n        self.setGLOptions(glopts)\n        self.pos = []\n        self.size = 10\n        self.color = [1.0,1.0,1.0,0.5]\n        self.pxMode = True\n        #self.vbo = {}      ## VBO does not appear to improve performance very much.\n        self.setData(**kwds)\n        self.shader = None\n    \n    def setData(self, **kwds):\n        \"\"\"\n        Update the data displayed by this item. All arguments are optional; \n        for example it is allowed to update spot positions while leaving \n        colors unchanged, etc.\n        \n        ====================  ==================================================\n        **Arguments:**\n        pos                   (N,3) array of floats specifying point locations.\n        color                 (N,4) array of floats (0.0-1.0) specifying\n                              spot colors OR a tuple of floats specifying\n                              a single color for all spots.\n        size                  (N,) array of floats specifying spot sizes or \n                              a single value to apply to all spots.\n        pxMode                If True, spot sizes are expressed in pixels. \n                              Otherwise, they are expressed in item coordinates.\n        ====================  ==================================================\n        \"\"\"\n        args = ['pos', 'color', 'size', 'pxMode']\n        for k in kwds.keys():\n            if k not in args:\n                raise Exception('Invalid keyword argument: %s (allowed arguments are %s)' % (k, str(args)))\n            \n        args.remove('pxMode')\n        for arg in args:\n            if arg in kwds:\n                setattr(self, arg, kwds[arg])\n                #self.vbo.pop(arg, None)\n                \n        self.pxMode = kwds.get('pxMode', self.pxMode)\n        self.update()\n\n    def initializeGL(self):\n        if self.shader is not None:\n            return\n        \n        ## Generate texture for rendering points\n        w = 64\n        def fn(x,y):\n            r = ((x-w/2.)**2 + (y-w/2.)**2) ** 0.5\n            return 255 * (w/2. - np.clip(r, w/2.-1.0, w/2.))\n        pData = np.empty((w, w, 4))\n        pData[:] = 255\n        pData[:,:,3] = np.fromfunction(fn, pData.shape[:2])\n        #print pData.shape, pData.min(), pData.max()\n        pData = pData.astype(np.ubyte)\n        \n        if getattr(self, \"pointTexture\", None) is None:\n            self.pointTexture = glGenTextures(1)\n        glActiveTexture(GL_TEXTURE0)\n        glEnable(GL_TEXTURE_2D)\n        glBindTexture(GL_TEXTURE_2D, self.pointTexture)\n        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pData.shape[0], pData.shape[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, pData)\n        \n        self.shader = shaders.getShaderProgram('pointSprite')\n        \n    #def getVBO(self, name):\n        #if name not in self.vbo:\n            #self.vbo[name] = vbo.VBO(getattr(self, name).astype('f'))\n        #return self.vbo[name]\n        \n    #def setupGLState(self):\n        #\"\"\"Prepare OpenGL state for drawing. This function is called immediately before painting.\"\"\"\n        ##glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)  ## requires z-sorting to render properly.\n        #glBlendFunc(GL_SRC_ALPHA, GL_ONE)\n        #glEnable( GL_BLEND )\n        #glEnable( GL_ALPHA_TEST )\n        #glDisable( GL_DEPTH_TEST )\n        \n        ##glEnable( GL_POINT_SMOOTH )\n\n        ##glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)\n        ##glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, (0, 0, -1e-3))\n        ##glPointParameterfv(GL_POINT_SIZE_MAX, (65500,))\n        ##glPointParameterfv(GL_POINT_SIZE_MIN, (0,))\n        \n    def paint(self):\n        self.setupGLState()\n        \n        glEnable(GL_POINT_SPRITE)\n        \n        glActiveTexture(GL_TEXTURE0)\n        glEnable( GL_TEXTURE_2D )\n        glBindTexture(GL_TEXTURE_2D, self.pointTexture)\n    \n        glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)\n        #glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)    ## use texture color exactly\n        #glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )  ## texture modulates current color\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)\n        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)\n        glEnable(GL_PROGRAM_POINT_SIZE)\n        \n            \n        with self.shader:\n            #glUniform1i(self.shader.uniform('texture'), 0)  ## inform the shader which texture to use\n            glEnableClientState(GL_VERTEX_ARRAY)\n            try:\n                pos = self.pos\n                #if pos.ndim > 2:\n                    #pos = pos.reshape((reduce(lambda a,b: a*b, pos.shape[:-1]), pos.shape[-1]))\n                glVertexPointerf(pos)\n            \n                if isinstance(self.color, np.ndarray):\n                    glEnableClientState(GL_COLOR_ARRAY)\n                    glColorPointerf(self.color)\n                else:\n                    if isinstance(self.color, QtGui.QColor):\n                        glColor4f(*fn.glColor(self.color))\n                    else:\n                        glColor4f(*self.color)\n                \n                if not self.pxMode or isinstance(self.size, np.ndarray):\n                    glEnableClientState(GL_NORMAL_ARRAY)\n                    norm = np.empty(pos.shape)\n                    if self.pxMode:\n                        norm[...,0] = self.size\n                    else:\n                        gpos = self.mapToView(pos.transpose()).transpose()\n                        pxSize = self.view().pixelSize(gpos)\n                        norm[...,0] = self.size / pxSize\n                    \n                    glNormalPointerf(norm)\n                else:\n                    glNormal3f(self.size, 0, 0)  ## vertex shader uses norm.x to determine point size\n                    #glPointSize(self.size)\n                glDrawArrays(GL_POINTS, 0, int(pos.size / pos.shape[-1]))\n            finally:\n                glDisableClientState(GL_NORMAL_ARRAY)\n                glDisableClientState(GL_VERTEX_ARRAY)\n                glDisableClientState(GL_COLOR_ARRAY)\n                #posVBO.unbind()\n                ##fixes #145\n                glDisable( GL_TEXTURE_2D )\n                                \n        #for i in range(len(self.pos)):\n            #pos = self.pos[i]\n            \n            #if isinstance(self.color, np.ndarray):\n                #color = self.color[i]\n            #else:\n                #color = self.color\n            #if isinstance(self.color, QtGui.QColor):\n                #color = fn.glColor(self.color)\n                \n            #if isinstance(self.size, np.ndarray):\n                #size = self.size[i]\n            #else:\n                #size = self.size\n                \n            #pxSize = self.view().pixelSize(QtGui.QVector3D(*pos))\n            \n            #glPointSize(size / pxSize)\n            #glBegin( GL_POINTS )\n            #glColor4f(*color)  # x is blue\n            ##glNormal3f(size, 0, 0)\n            #glVertex3f(*pos)\n            #glEnd()\n\n        \n        \n        \n        \n", "path": "pyqtgraph/opengl/items/GLScatterPlotItem.py"}]}