Binding issue with glDrawElements

Ognyan Moore ognyan.moore at gmail.com
Mon Oct 14 03:37:01 BST 2024


Hello,

Slight follow up to this as I omitted relevant information.

The offset arguments have also been accepting integer offsets cast as a
void ptr.  This presently works for glVertexAttribPointer as demonstrated
in the code snippet above. One potential solution would be to have
glDrawElements take a PYQT_OPENGL_BOUND_ARRAY instead of a
PYQT_OPENGL_ARRAY.



On Sun, Oct 13, 2024 at 2:54 PM Ognyan Moore <ognyan.moore at gmail.com> wrote:

> Hello,
>
> There seems to be an issue with the binding on glDrawElements,
> specifically the indices attribute.  Issue can be demonstrated w/ the
> following code:
>
> import struct
>
> from PyQt6 import QtGui, QtOpenGL
> OFFSET = lambda x : x
>
> # from PySide6 import QtGui, QtOpenGL
> # from shiboken6 import VoidPtr
> # OFFSET = lambda x : VoidPtr(x)
>
> class MyWidget(QtOpenGL.QOpenGLWindow):
>     def initializeGL(self):
>         vtx = struct.pack('9f', 0, -1, -1, 1, -1, -1, 1, 1, 1)  # 1 bogus
> float in front
>         ind = struct.pack('6H', 0, 1, 2, 2, 3, 1)
>
>         self.m_vbo =
> QtOpenGL.QOpenGLBuffer(QtOpenGL.QOpenGLBuffer.Type.VertexBuffer)
>         self.m_vbo.create()
>         self.m_vbo.bind()
>         self.m_vbo.allocate(vtx, len(vtx))
>
>         self.m_ibo =
> QtOpenGL.QOpenGLBuffer(QtOpenGL.QOpenGLBuffer.Type.IndexBuffer)
>         self.m_ibo.create()
>         self.m_ibo.bind()
>         self.m_ibo.allocate(ind, len(ind))
>
>         GL = self.get_functions()
>         GL.glEnableVertexAttribArray(0)
>         # specifying an integer offset to skip past the bogus float works
> for glVertexAttribPointer
>         GL.glVertexAttribPointer(0, 2, 0x1406, False, 0, OFFSET(4))
>
>     def get_functions(self):
>         vp = QtOpenGL.QOpenGLVersionProfile()
>         vp.setVersion(2, 0)
>         return QtOpenGL.QOpenGLVersionFunctionsFactory.get(vp,
> self.context())
>
>     def paintGL(self):
>         GL = self.get_functions()
>         GL.glClear(0x4000)
>
>         # draw 2 triangles separately to demonstrate the issue
>
>         try:
>             # unlike the binding for glVertexAttribPointer, we are not
> able to
>             # supply an integer offset.
>             GL.glColor3f(1, 0, 0)
>             GL.glDrawElements(4, 3, 0x1403, OFFSET(None))
>
>             GL.glColor3f(0, 1, 0)
>             GL.glDrawElements(4, 3, 0x1403, OFFSET(6))
>         except TypeError as e:
>             # should have been defined as PYQT_OPENGL_BOUND_ARRAY?
>             print(e)
>
> app = QtGui.QGuiApplication([])
> win = MyWidget()
> win.show()
> app.exec()
>
>
> the except TypeError as e: print(e) outputs the following:
>
> glDrawElements(self, mode: int, count: int, type: int, indices:
> PYQT_OPENGL_ARRAY):
> glDrawElements(self, mode: int, count: int, type: int, indices:
> PYQT_OPENGL_ARRAY):
>
> the OpenGL docs
> <https://registry.khronos.org/OpenGL-Refpages/gl4/html/glDrawElements.xhtml>
> indicate it should be a pointer to the location where the indices are
> stored. With the pyside bindings, using VoidPtr(x) seems to be sufficient.
> When using PyQt bindings, in other places we've often gotten what's needed
> for similar arguments using lambda expressions, which we expected to be
> able to do the same here as well.
>
> Thanks,
> Ogi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20241014/e5eb4864/attachment-0001.htm>


More information about the PyQt mailing list