Python OpenGL Texture not wrapped

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Python OpenGL Texture not wrapped

Postby dermont » Wed Feb 18, 2015 21:51

I'm trying to use an opengl texture from the python PyCEGUIOpenGLRenderer module. It doesn't appear to be wrapped and defaults to a CEGUI::Texture, e.g:

print self.texture.getOpenGLTexture() <------------------

Code: Select all

#AttributeError: 'Texture' object has no attribute 'getOpenGLTexture'
Exception AttributeError: "'NoneType' object has no attribute 'OpenGLRenderer'" in <bound method BaseApp.__del__ of <__main__.BaseApp object at 0x7ffdfb8bab90>> ignored


opengl_renderer.py

Code: Select all

    CEGUI_ns.class_( 'Texture' ).include(already_exposed=True)
    texture = CEGUI_ns.class_("OpenGLTexture")
    texture.include()
    texture.noncopyable = True

    mb.add_declaration_code(
    """
    CEGUI::Texture* castAsGLTexture(CEGUI::Texture * e){ 
        if( dynamic_cast< CEGUI::OpenGLTexture* >( e ) ){
            return (CEGUI::OpenGLTexture*) e;
        }
        return  ( e );
        }
    void *
    Utility_CastVoidPtr ( unsigned long address )
    {
        return (void *) address;
    }
    """
    )
    mb.add_registration_code("""def ("castAsGLTexture", &::castAsGLTexture,\
        (bp::arg("source")), \
        bp::return_value_policy<bp::reference_existing_object, bp::default_call_policies>());""")

    mb.add_registration_code("""def ("CastVoidPtr", &::Utility_CastVoidPtr,\
        (bp::arg("source")), \
        bp::return_value_policy< bp::return_opaque_pointer >());""")


python_CEGUIOpenGLRenderer.h

Code: Select all

#include "CEGUI/RendererModules/OpenGL/Texture.h"


This is my test code:

Code: Select all

def createTexture(self,parent):
        im = open('/media/sdb5/Libraries/OGRE/sdk/v1-9/share/OGRE/Media/materials/textures/checker.png')
        width = im.size[0]
        height = im.size[1]
        image = im.convert("RGBA").tostring("raw", "RGBA")

        size = PyCEGUI.Sizef(float(width), float(height))

        rs = PyCEGUI.System.getSingleton().getRenderer()
        self.texture = rs.createTexture("Checked",size)
        imageArea = PyCEGUI.Rectf(0.0, 0.0, float(width), float(height))
        print self.texture.getOpenGLTexture() <------------------

        #tex = PyCEGUIOpenGLRenderer.castAsGLTexture(self.texture)

        import ctypes
        bm = (ctypes.c_ubyte * width*height*4)()
        ctypes.memmove(bm, image, len(image))

        tex.blitFromMemory(PyCEGUIOpenGLRenderer.CastVoidPtr(ctypes.addressof(bm)),imageArea)


The common_utils.py has hard·wired paths for the gccxml exe and updating/generating the wrapped code would make it not possible to supply a patch since the generated code would be platform specific.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Python OpenGL Texture not wrapped

Postby Ident » Fri Feb 20, 2015 12:26

Thank you, we know about this already.

A lot of API is missing in various PyOpenGLRenderer classes. The fix is unfortunately not easy.
CrazyEddie: "I don't like GUIs"

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Python OpenGL Texture not wrapped

Postby dermont » Fri Feb 20, 2015 18:24

Ident wrote:Thank you, we know about this already.

A lot of API is missing in various PyOpenGLRenderer classes. The fix is unfortunately not easy.

Ok didn't notice that. I'll try and take a look at what needs updating, unfortunately the whole wrapping process is pretty tedious. At least your generators are pretty easy to follow/see what needs updating.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Python OpenGL Texture not wrapped

Postby Ident » Fri Feb 20, 2015 18:48

Edit: We can accept PR's on this matter, see Martin's post below. This is true as long as the change affects the generators.
CrazyEddie: "I don't like GUIs"

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Python OpenGL Texture not wrapped

Postby dermont » Sat Feb 21, 2015 11:20

Ident wrote:Martin will probably fix this sooner or later, when he has time. The problem is that the OpenGL renderers were split at some point (or something related to that).
Unfortunately I dont really know in detail what the issue is ;) but I would say it is safe to assert that only he can fix it, considering how the bindings are created currently. Basically, if he died, all the secrets of creating the bindings would be lost forever :hammer:

Actually it is pretty serious :|

EDIT: You can probably edit the bindings by hand to make it work. But we cannot accept pull requests based on this because a new bindings-export by Martin would erase your changes.


No it was changes made to the generators. I copied across the generators, set the paths to output to my own dir as not to pollute my existing cegui src and wrote some simple Cmake files to build.

Anyway I don't wan't to create duplication in effort, so I'll the updates to you guys. I've uploaded the minor generator changes I made (for Linux) and a sample python program to play a GStreamer1.x video in a Window, Listbox etc.

Edit:
This is for the v0-8 branch.
gst.png
Attachments
cegui.zip
(7.86 KiB) Downloaded 948 times

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Python OpenGL Texture not wrapped

Postby Kulik » Tue Feb 24, 2015 15:14

Please make a patch out of this and consider making a pull request. Contributing via code drops is better than not contributing at all but it makes it very painful for me to accept your contribution.

If it doesn't break anything we can merge it to v0-8.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Python OpenGL Texture not wrapped

Postby Ident » Mon Mar 09, 2015 17:17

I am about to make a PR out of his/her zip.
CrazyEddie: "I don't like GUIs"

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Python OpenGL Texture not wrapped

Postby Ident » Mon Mar 09, 2015 23:13

CrazyEddie: "I don't like GUIs"

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Python OpenGL Texture not wrapped

Postby dermont » Sun Mar 15, 2015 12:07

Kulik wrote:Please make a patch out of this and consider making a pull request. Contributing via code drops is better than not contributing at all but it makes it very painful for me to accept your contribution.

If it doesn't break anything we can merge it to v0-8.


Hi I understand, sorry for the late reply. I understand that the proposed change has been incorporated. The change would probably only work if both the OpenGL and OpenGL3 renderer were selected during the build. Anyway to make things more generic how would you like me to handle the CEGUI build options for OpenGL/OpenGL3.

1) Set flags flags in opengl_renderer.py and output to a different directory, e.g. generate.py:

Code: Select all

      generators.opengl_renderer.generate(OPENGL=TRUE OPENGL3=TRUE)  --> output/CEGUIOpenGLRenderer/GL3Plus
      generators.opengl_renderer.generate(OPENGL=TRUE OPENGL3=FALSE)  --> output/CEGUIOpenGLRenderer/GL
      generators.opengl_renderer.generate(OPENGL=FALSE OPENGL3=TRUE)  --> output/CEGUIOpenGLRenderer/GL3

Then in the build pass a sub directory var to the module macro to pick up the correct source directory.

2) Create a PyOpenGLBase module which PyOpenGLRender has a dependency on and PyOpenGL3Render which may depend on one/or either.

3) Modify the wrapper code during code generation to have ifdefs for the main module register call / wrapper code.

Thanks

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Python OpenGL Texture not wrapped

Postby Ident » Mon Mar 16, 2015 11:18

The change has not been incorporated, the PR is still standing. You can make a PR for the repo behind my PR if you want to change anything.

The problem is that it includes Linux-only texture types for the OGL Renderer which require X11 as dependency, this is not okay for windows system. The generators need some sort of ifdef so that certain texture classes are only included for certain OS(there is an ifdef like this present in the C++ code). I dont know how to do this for python generators.

Regarding your question: We will have to wait for Kulik's response, I dont know.
CrazyEddie: "I don't like GUIs"

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Python OpenGL Texture not wrapped

Postby dermont » Mon Mar 16, 2015 12:28

Ident wrote:The change has not been incorporated, the PR is still standing. You can make a PR for the repo behind my PR if you want to change anything.

The problem is that it includes Linux-only texture types for the OGL Renderer which require X11 as dependency, this is not okay for windows system. The generators need some sort of ifdef so that certain texture classes are only included for certain OS(there is an ifdef like this present in the C++ code). I dont know how to do this for python generators.

Regarding your question: We will have to wait for Kulik's response, I dont know.


Ok that's a simple fix for the generators.

Code: Select all

    if os.name == 'posix' or os.sys.platform == 'darwin':   
        # RendererModules/OpenGL/OpenGLGLXPBTextureTarget.h
        PBTextureTarget = CEGUI_ns.class_("OpenGLGLXPBTextureTarget")
    else:
        PBTextureTarget = CEGUI_ns.class_("WGLPBTextureTarget")
    PBTextureTarget.include()
    PBTextureTarget.noncopyable = True


To be honest the proposed changes are trivial and would probably take less than 5 mins of Kulik's time. Since CEGUI supplies the wrapper code the real issue is tailoring the code generators to fit in with that policy in a cross platform manner.

AFAIK gccxml has support for a number of compilers (on windows last version to build python-ogre was Visual Studio 2008). The wrapper code is specific to the platform/compiler that it was generated under. Using the wrapper code from the repo do the python modules even build on Windows?

Anyway I'll wait for Kulik's answer, in the meantime I'll issue a pull request for an update to common_utils to allow a user ro run the generators outwith the source tree.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Python OpenGL Texture not wrapped

Postby Kulik » Mon Mar 16, 2015 16:36

Your proposed change isn't the solution.

Keep in mind that we generate C++ code for the bindings and commit it so that our users don't have to install pyplusplus. So the generated code needs to work everywhere. Your fix just doesn't accomplish that.

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Python OpenGL Texture not wrapped

Postby dermont » Thu Apr 16, 2015 10:39

I understand that the majority of users will not want to go through the hassle of the generating their own wrapper code via pyplusplus/pygccxml. I also understand the need to exclude certain methods/classes via the generators to ensure that the modules can build in a cross-platform manner.

What about those that do have pyplusplus installed? Unless users have an old copy of Visual Studio 2008 on Windows lying around it's nigh on impossible to generate pull requests in a cross platform way. I guess the only option available is to maintain their own cegui bindings.

Anyway on v0-8 branch adding a tree item to a tree causes a seg fault when the tree item goes out of scope i.e. probably needs to be updated as per the list item.

cegui_base.py

Code: Select all

    tree.mem_fun("addItem").exclude()
    tree.mem_fun("removeItem").exclude()
    tree.add_declaration_code(
    """
    void
    Tree_addItem(CEGUI::Tree& self, PyObject* item)
    {
        CEGUI::TreeItem* nativeItem = boost::python::extract<CEGUI::TreeItem*>(boost::python::incref(item));
        // passed from python so don't delete it!
        nativeItem->setAutoDeleted(false);

        self.addItem(nativeItem);
    }

    void
    Tree_removeItem(CEGUI::Tree& self, PyObject* item)
    {
        CEGUI::TreeItem* nativeItem = boost::python::extract<CEGUI::TreeItem*>(item);
        // don't delete it, python will take care of it
        nativeItem->setAutoDeleted(false);

        self.removeItem(nativeItem);
        boost::python::decref(item);
    }
    """
    )
    tree.add_registration_code('def ("addItem", &::Tree_addItem, (bp::arg("item")));')
    tree.add_registration_code('def ("removeItem", &::Tree_removeItem, (bp::arg("item")));')


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 2 guests