Repository: pyqtgraph/pyqtgraph

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*


Discussion:
I could not reproduce this on

- PyQt5 5.12.2 Qt 5.12.3
- Python 3.6.5
- Windows 10

and
 - PyQt5 5.13.0 Qt 5.13.0
 - Python 3.7.4
 - Manjaro Linux (Arch)

It might be caused by PySide2?
Could not reproduce on

- PySide2 5.13.0 Qt 5.13.0
- Python 3.6.5
- Windows 10

@DoC-Noah How often does this occur if you try it? If you rotate the view via the left mouse button, does the grid reappear?
I re-ran the code and it actually worked, however after adding another GLScatterPlotItem, the grid starts disappearing again. I updated my code above to include a third point.

The error has occurred every time I've tried it (except the first time I ran it just now). 
Rotating the view does not make the grid reappear for me.

Tried with Python 3.6.5 and the grid still disappeared.
After correcting the one `pl3 = ...` to `plt3 = ...`, I could reproduce this with the new code on the following systems!

 - PyQt5 5.12.2 Qt 5.12.3
 - Python 3.6.5
 - Windows 10

---

 - PySide2 5.13.0 Qt 5.13.0
 - Python 3.6.5
 - Windows 10

Resolving patch:
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 @@ def __init__(self, data, smooth=False, glOptions='translucent'):
         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 @@ def __init__(self, **kwds):
         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 @@ def setData(self, **kwds):
         self.update()
 
     def initializeGL(self):
+        if self.shader is not None:
+            return
         
         ## Generate texture for rendering points
         w = 64


Test patch: