Oh, how trivial a bit of work it was. I just added a numarray-based array FormatHandler to OpenGL-ctypes. It seems to work fine, though I don't have any non-trivial numarray-using code with which to test it. The difference between the Numpy and numarray code is trivial, other than the imports the modules are identical (including the C code to retrieve a data-pointer).
I'm still pondering how best to handle the format handler registration and lookup. I want something that doesn't load dozens of different modules just to see if they are available (thinking of when PyGame or PyMedia are added), but I also want the built-in functionality to return Numpy or Numarray arrays in most cases. I also want the application developer to be able to readily select the preferred return data-type. I'm thinking something like this:
OpenGL.setReturnArrayType( OpenGL.ARRAY_TYPE_NUMPY )
from OpenGL.GL import *
With similar functions at the top level for specifying image data-types and the like. The idea is that the application (not a library, hopefully) can specify the data-type desired on loading and then the entire library will use that data-type. Other data-types will be accepted as inputs, but outputs would be in the selected format.
Obviously the problem with that situation is when we have formats that have different operators available (e.g. strings versus arrays) and a library assumes e.g. Numpy outputs, while the application coder wants to use e.g. string output. I've considered making it possible to do an import something like:
from OpenGL.numarray.GL import *
and have numarray-specialised functions, but that seems... very messy.
Anyway, the new numarray handlers are in CVS for those wishing to play with them.
Pingbacks are closed.