Re: PyOpenGL_accelerate / subclassed numpy arrays

"Mike C. Fletcher" <[email protected]> Wed, 11 Nov 2015 14:23:38 -0500
Newsgroups gmane.comp.python.opengl.user
Message-ID <[email protected]>
On 09/11/15 11:05, Chris Barker - NOAA Federal wrote:
> It looks like accelerate is written in Cython. So you should be able
> to refactor it to use memoryviews, which I _think_ will work out of
> the box with proper nearest subclasses.

I thought so too ;) . But in fact the behaviour of PyOpenGL is 
sufficiently generic that it *doesn't* work with memoryviews (I was told 
by the cython folks, basically "yeah, don't do that").

It *is*, however, supposed to work with subclasses of known/supported 
types. It takes an unknown type and walks the __mro__ to find a type 
that it *does* recognize... but apparently that's failing. To explicitly 
register a type, you can do the following:

     from OpenGL.plugins import FormatHandler
     FormatHandler( 'glumpy','OpenGL.arrays.numpymodule.NumpyHandler',[
         'glumpy.gloo.buffer.VertexBuffer',
     ])

which will register the handler name 'glumpy' to use the NumpyHandler, 
which *should* AFAIK work. I can't get glumpy to compile/install, so I'm 
afraid I actually can't test it at the moment.

Take care,
Mike

> On Nov 9, 2015, at 5:22 AM, Nicolas P. Rougier <[email protected]> wrote:
>
>
> Ok, thanks for the explanation, I'll look into that then.
>
> Nicolas
>
>
>
>>> On 08 Nov 2015, at 18:04, Chris Barker <[email protected]> wrote:
>>>
>>> On Sun, Nov 8, 2015 at 8:20 AM, Rob McMullen - NOAA Affiliate <[email protected]> wrote:
>>> I know I've run into that problem when my VBO data was in recarray format. Defining the VBO as a view of the array in dtype=np.float32 format worked.
>>>
>>> I haven't lloked an ANY of the relevant coce here, but this seems to indicae that  PyOpenGL_accelerate can't handle subclasses of ndarray -- which doesn't surprise me -- it's notoriously difficult to do that.
>>>
>>> but the error:
>>>
>>> File "arraydatatype.pyx", line 57, in OpenGL_accelerate.arraydatatype.HandlerRegistry.c_lookup (src/arraydatatype.c:2230)
>>> TypeError: No array-type handler for type <class 'glumpy.gloo.buffer.VertexBuffer'> (value: VertexBuffer([151,  10,   1, ...,   0, 128,  63], ) registered
>>>
>>> makes me think that arraydatatype.HandlerRegistry is where you need to put awareness of a new subclass.
>>>
>>> or it needs to be fixed to recognize ndarray subclasses -- either by directly checking if it is a proper subclass, or by using the array protocol -- which I think is the __array__ method...
>>>
>>> HTH,
>>>
>>> -CHris
>>>
>>>
>>>
>>> Rob
>>>
>>> On Thu, Nov 5, 2015 at 11:08 PM, Nicolas P. Rougier <[email protected]> wrote:
>>>
>>> I've made a numpy array subclass for a vertex buffer that works great with PyOpenGL but does not work if PyOpenGL_accelerate is installed, it complains about about missing handler:
>>>
>>> File "/Users/rougier/Development/Public/glumpy/glumpy/gloo/buffer.py", line 75, in _update
>>>     gl.glBufferSubData(self.target, offset, nbytes, data)
>>>   File "latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.__call__ (src/latebind.c:1201)
>>>   File "/usr/locaL/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/OpenGL/GL/VERSION/GL_1_5.py", line 122, in glBufferSubData
>>>     data = ArrayDatatype.asArray( data )
>>>   File "arraydatatype.pyx", line 174, in OpenGL_accelerate.arraydatatype.ArrayDatatype.asArray (src/arraydatatype.c:4221)
>>>   File "arraydatatype.pyx", line 57, in OpenGL_accelerate.arraydatatype.HandlerRegistry.c_lookup (src/arraydatatype.c:2230)
>>> TypeError: No array-type handler for type <class 'glumpy.gloo.buffer.VertexBuffer'> (value: VertexBuffer([151,  10,   1, ...,   0, 128,  63], ) registered
>>>
>>>
>>> Python: 3.5
>>> PyOpenGL: 3.1.0
>>> PyOpenGL_accelerate: 3.1.0
>>> The package I'm developing: http://glumpy.github.io
>>>
>>> Any idea ?
>>>
>>> Nicolas
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> PyOpenGL Homepage
>>> http://pyopengl.sourceforge.net
>>> _______________________________________________
>>> PyOpenGL-Users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pyopengl-users
>>>
>>>
>>> ------------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> PyOpenGL Homepage
>>> http://pyopengl.sourceforge.net
>>> _______________________________________________
>>> PyOpenGL-Users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pyopengl-users
>>>
>>>
>>>
>>>
>>> --
>>>
>>> Christopher Barker, Ph.D.
>>> Oceanographer
>>>
>>> Emergency Response Division
>>> NOAA/NOS/OR&R            (206) 526-6959   voice
>>> 7600 Sand Point Way NE   (206) 526-6329   fax
>>> Seattle, WA  98115       (206) 526-6317   main reception
>>>
>>> [email protected]
> ------------------------------------------------------------------------------
> Presto, an open source distributed SQL query engine for big data, initially
> developed by Facebook, enables you to easily query your data on Hadoop in a
> more interactive manner. Teradata is also now providing full enterprise
> support for Presto. Download a free open source copy now.
> http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
> _______________________________________________
> PyOpenGL Homepage
> http://pyopengl.sourceforge.net
> _______________________________________________
> PyOpenGL-Users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyopengl-users
>


-- 
________________________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://www.vrplumber.com
   http://blog.vrplumber.com


------------------------------------------------------------------------------
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net