Skip to content

Issue with pyopengl-accelerate and glGenVertexArrays/glDeleteVertexArrays #159

@pauldmccarthy

Description

@pauldmccarthy

Howdy, I've just hit an issue with pyopengl-accelerate - it seems that glGenVertexArrays returns a scalar np.uint32, but gl.glDeleteVertexArrays requires an array. I'm not sure if other GL functions are affected.

This code works fine when pyopengl-accelerate is not installed (this code was run within an environment where a GL context had already been successfully created):

import OpenGL.GL as gl
vao = gl.glGenVertexArrays(1)
gl.glDeleteVertexArrays(1, vao)

However, with pyopengl-accelerate installed:

In [1]: import OpenGL.GL as gl

In [2]: vao = gl.glGenVertexArrays(1)

In [3]: vao
Out[3]: np.uint32(23)

In [4]: gl.glDeleteVertexArrays(1, vao)
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
Cell In[4], line 1
----> 1 gl.glDeleteVertexArrays(1, vao)

File src/latebind.pyx:40, in OpenGL_accelerate.latebind.LateBind.__call__()

File src/wrapper.pyx:315, in OpenGL_accelerate.wrapper.Wrapper.__call__()

File src/wrapper.pyx:312, in OpenGL_accelerate.wrapper.Wrapper.__call__()

File ${PREFIX}/lib/python3.12/site-packages/OpenGL/platform/baseplatform.py:487, in _NullFunctionPointer.__call__(self, *args, **named)
    485 def __call__(self, *args, **named):
    486     if self.load():
--> 487         return self(*args, **named)
    488     else:
    489         try:

ArgumentError: ("argument 2: TypeError: Numpy format handler passed a non-numpy-array object 23 (of type <class 'numpy.uint32'>)", (1, np.uint32(23)))

The error originates from NumpyHandler.c_check_array. So far my naive attempts to patch this file have not worked, as I don't understand how the pyopengl code works. I'll keep poking, but it would be great if somebody with more knowledge of the code base could take a look.

The call to glDeleteVertexArrays does work if I change the code to gl.glDeleteVertexArrays(np.array([vao]). But I believe that this coding pattern is used extensively, so it would be a shame for downstream code to be required to pass arrays, particularly as this code works just fine without pyopengl-accelerate.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions