[ pyopengl-Bugs-3534110 ] hasGLExtension fail wrt circular import

SourceForge.net <[email protected]> Mon, 11 Jun 2012 07:19:22 -0700
Newsgroups gmane.comp.python.opengl.devel
Message-ID <[email protected]>
Bugs item #3534110, was opened at 2012-06-10 03:02
Message generated for change (Comment added) made by lxnt
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105988&aid=3534110&group_id=5988

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: GL
Group: v3.0.0
Status: Open
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Alexander Sabourenkov (lxnt)
Assigned to: Mike C. Fletcher (mcfletch)
Summary: hasGLExtension fail wrt circular import

Initial Comment:
Given a 3.0+ forward-compatible context, that is, with glGetString barking at GL_EXTENSIONS, "from OpenGL.GL import *" may fail if one of OpenGL.GL.VERSION.GL_* submodules with version below 3.0  calls hasGLExtension() due to the fact that until "from OpenGL.GL.VERSION.GL_3_0 import *" line is executed in OpenGL/GL/__init__.py, the line "from OpenGL.GL import GL_NUM_EXTENSIONS, glGetStringi, glGetIntegerv" is guaranteed to throw an ImportError.

Suggested solution:

replace the aforementioned import statement in the hasExtension() function with the following two lines:

                from OpenGL.GL.VERSION.GL_3_0 import GL_NUM_EXTENSIONS, glGetStringi
                from OpenGL.GL import glGetIntegerv

Works for me.

Attached patch: the above fix plus a couple of nits to make it all work under Python 3.2



----------------------------------------------------------------------

>Comment By: Alexander Sabourenkov (lxnt)
Date: 2012-06-11 07:19

Message:
Thanks for quick reaction.

There is another major problem.

Now hasGLExtension() is called recursively on the first call. That is, at
the first call we get to "from OpenGL.GL.VERSION.GL_3_0 import ...", which
does "from OpenGL.GL.ARB.vertex_array_object import *", which in turn ends
up calling hasGLExtension(). 

The problem is that at the time of that second call glGetStringi()'s
restype is not yet set. Thus it returns GLubytearrays or something, which
leads to ARB_vertex_array_object extension be declared unavailable. 

The attached patch fixes the issue, moving restype assignment to above the
extension imports.

Those two calls to hasGlExtension() end up doing the work twice. This isn't
so much a problem in itself, just not quite elegant.

----------------------------------------------------------------------

Comment By: Mike C. Fletcher (mcfletch)
Date: 2012-06-10 19:33

Message:
I've merged approximately this patch in.

I reverted the "as" changes, as I don't believe I've ever officially
announced dropping support for Python 2.5 (though I likely should some day
soon).  The change that would break unicode string checking on Python 2.x
was also not included (AFAIK that code would work perfectly well on Python
3.x); there was a real reason to say "string or unicode" there.  I had to
add an alias for the __bool__ as well so that earlier Python's would still
be able to do boolean checking.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105988&aid=3534110&group_id=5988

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net