[osg-users] how to get the handle of opengl texture that corresponds to a OSG::Texture

245 views
Skip to first unread message

Qingjie Zhang

unread,
Sep 8, 2015, 10:25:41 AM9/8/15
to osg-...@lists.openscenegraph.org
Hi,
I generated a texture2d with osg, to use the texture in CUDA, I have to get the corresponding "opengl texture" handle(GLuint), and then access to the texture by the handle in CUDA.
Now I don't know how to get the handle.
Many thanks for your reply!!!
...

Thank you!

Cheers,
Qingjie

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65061#65061





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Sep 8, 2015, 10:36:38 AM9/8/15
to OpenSceneGraph Users
Hi Qingjie,

The osgTexture::TextureObject* osg::Texture::getTextureObject(uint contextID)  method can be used to get the OSG's wrapper for the OpenGL texture object.  The TextureObject::id() method returns the OpenGL texture object id.

Robert.

Qingjie Zhang

unread,
Sep 8, 2015, 10:56:52 AM9/8/15
to osg-...@lists.openscenegraph.org
Thank you Robert,
well, I've checked the source code of OSG, and found what you said, but I still don't know about the contextID, what value of the parameter should I give to the function?
Thanks so much!
Qingjie.


robertosfield wrote:
> Hi Qingjie,
>
>
> The osgTexture::TextureObject* osg::Texture::getTextureObject(uint contextID)  method can be used to get the OSG's wrapper for the OpenGL texture object.  The TextureObject::id() method returns the OpenGL texture object id.
>
>
> Robert.
>

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=65067#65067

Qingjie Zhang

unread,
Sep 8, 2015, 11:28:35 PM9/8/15
to osg-...@lists.openscenegraph.org
Hi Robert,
I'm knowing that the RenderInfo->getContextID() can give me the contextID to use in the getTextureObject(uint contextID), but where can I get the RenderInfo? I searched the source code of Texture but did not find that..
Many thanks.

Qingjie


robertosfield wrote:
> Hi Qingjie,
>
>
> The osgTexture::TextureObject* osg::Texture::getTextureObject(uint contextID)  method can be used to get the OSG's wrapper for the OpenGL texture object.  The TextureObject::id() method returns the OpenGL texture object id.
>
>
> Robert.
>
>

> On 8 September 2015 at 15:20, Qingjie Zhang < ()> wrote:
>
> > Hi,
> > I generated a texture2d with osg, to use the texture in CUDA, I have to get the corresponding "opengl texture" handle(GLuint), and then access to the texture by the handle in CUDA.
> > Now I don't know how to get the handle.
> > Many thanks for your reply!!!
> > ...
> >
> > Thank you!
> >
> > Cheers,
> > Qingjie
> >
> > ------------------
> > Read this topic online here:

> > http://forum.openscenegraph.org/viewtopic.php?p=65061#65061 (http://forum.openscenegraph.org/viewtopic.php?p=65061#65061)
> >
> >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> >
>
>
> ------------------
> Post generated by Mail2Forum


------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=65073#65073

Robert Osfield

unread,
Sep 9, 2015, 3:33:11 AM9/9/15
to OpenSceneGraph Users
Hi Qingjie,

The RenderInfo is managed by the my the rendering back end, it's passed to all draw callbacks and Drawables.

Robert

Qingjie Zhang

unread,
Sep 9, 2015, 4:26:48 AM9/9/15
to osg-...@lists.openscenegraph.org
Hi Robert,

Do you mean the DrawCallback in the Camera class, which contains
virtual void operator () (osg::RenderInfo& renderInfo) ? And here I can use the RenderInfo right?

As I know, the following code can get a contextID:
camera->getGraphicsContext()->getState()->getContextID();
Is this contextID same as the upper one?

And,

Thank you!

Qingjie.


robertosfield wrote:
> Hi Qingjie,
>
>

> The RenderInfo is managed by the my the rendering back end, it's passed to all draw callbacks and Drawables.
>
>
> Robert
>
>
> On 9 September 2015 at 04:29, Qingjie Zhang < ()> wrote:
>
> > Hi Robert,
> > I'm knowing that the RenderInfo->getContextID() can give me the contextID to use in the getTextureObject(uint contextID), but where can I get the RenderInfo? I searched the source code of Texture but did not find that..
> > Many thanks.
> >
> > Qingjie
> >
> >
> > robertosfield wrote:
> >
> > > Hi Qingjie,
> > >
> > >
> > > The osgTexture::TextureObject* osg::Texture::getTextureObject(uint contextID)  method can be used to get the OSG's wrapper for the OpenGL texture object.  The TextureObject::id() method returns the OpenGL texture object id.
> > >
> > >
> > > Robert.
> > >
> > >
> > > On 8 September 2015 at 15:20, Qingjie Zhang < ()> wrote:
> > >
> > >

> > > > Hi,
> > > > I generated a texture2d with osg, to use the texture in CUDA, I have to get the corresponding "opengl texture" handle(GLuint), and then access to the texture by the handle in CUDA.
> > > > Now I don't know how to get the handle.
> > > > Many thanks for your reply!!!
> > > > ...
> > > >
> > > > Thank you!
> > > >
> > > > Cheers,
> > > > Qingjie
> > > >
> > > > ------------------
> > > > Read this topic online here:

> > > > http://forum.openscenegraph.org/viewtopic.php?p=65061#65061 (http://forum.openscenegraph.org/viewtopic.php?p=65061#65061) (http://forum.openscenegraph.org/viewtopic.php?p=65061#65061 (http://forum.openscenegraph.org/viewtopic.php?p=65061#65061))


> > > >
> > > >
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > osg-users mailing list
> > > >   ()

> > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org) (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org))


> > > >
> > > >
> > >
> > >
> > >   ------------------
> > > Post generated by Mail2Forum
> > >
> >
> >

> > ------------------
> > Read this topic online here:

> > http://forum.openscenegraph.org/viewtopic.php?p=65073#65073 (http://forum.openscenegraph.org/viewtopic.php?p=65073#65073)


> >
> >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> >
> >
> >
>
>
> ------------------
> Post generated by Mail2Forum

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=65075#65075

Robert Osfield

unread,
Sep 9, 2015, 4:43:17 AM9/9/15
to OpenSceneGraph Users
Hi Qingjie,

On 9 September 2015 at 09:27, Qingjie Zhang <3054...@qq.com> wrote:
Do you mean the DrawCallback in the Camera class, which contains
virtual void operator () (osg::RenderInfo& renderInfo) ? And here I can use the RenderInfo right?

Yes.  You can attach draw callbacks to Drawables, StateAtttribute and Camera's.

 

As I know, the following code can get a contextID:
camera->getGraphicsContext()->getState()->getContextID();
Is this contextID same as the upper one?

If you only need the contexID then getting it from the graphics context is perfectly fine.  What route to take depends on when you need to do your queries.

I would add that the TextureObject for each context is only created by the draw thread for each context, so the TextureObject won't exist right away when you create your osg::Texture and assign them to the scene graph.

Robert.
 

Qingjie Zhang

unread,
Sep 9, 2015, 11:41:05 PM9/9/15
to osg-...@lists.openscenegraph.org
Hi Robert,
To get the handle of opengl texture, I attached a DrawCallback to the main camera, doing like these codes:
struct MyCameraPostDrawCallback : public osg::Camera::DrawCallback
{
virtual void operator()(const osg::RenderInfo &renderInfo)
{
int contextID = renderInfo.getContextID();
GLuint frontTexHandle = m_frontTex->getTextureObject(contextID)->id();
GLuint backTexHandle = m_backTex->getTextureObject(contextID)->id();
}
};
camera->setPostDrawCallback(new MyCameraPostDrawCallback);

But the function operator() int the callback does not run, I tried setPostDrawCallback() and setFinalDrawCallback(), they were the same.
I was thinking that the DrawCallback would run every frame...
Can you tell me when the callback runs?
And, to get the handle, is it right to attach DrawCallback to camera? If not, can you tell me the detailed method to get the handle?

Thank you,

Qingjie.


robertosfield wrote:
> Hi Qingjie,

> ------------------
> Post generated by Mail2Forum

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=65083#65083

Robert Osfield

unread,
Sep 10, 2015, 3:22:22 AM9/10/15
to OpenSceneGraph Users
Hi Qingjie,

This is no longer about the OSG, it's about C++.  Your mistake is straight forward C++ issue of not matching the base classes parameters when overidding a method:  The Camera::DrawCallback base class is:


        /** Draw callback for custom operations.*/
        struct OSG_EXPORT DrawCallback : virtual public Object
        {
            DrawCallback() {}

            DrawCallback(const DrawCallback&,const CopyOp&) {}

            META_Object(osg, DrawCallback);

            /** Functor method called by rendering thread. Users will typically override this method to carry tasks such as screen capture.*/
            virtual void operator () (osg::RenderInfo& renderInfo) const;

            /** Functor method, provided for backwards compatibility, called by operator() (osg::RenderInfo& renderInfo) method.*/
            virtual void operator () (const osg::Camera& /*camera*/) const {}
        };

Please look carefully at your own code to see your mistake.

Robert.


Qingjie Zhang

unread,
Sep 12, 2015, 3:53:55 AM9/12/15
to osg-...@lists.openscenegraph.org
Hi Robert,

I fount it! I'm so sorry for my carelessness.
Thank you soooo much!!

Qingjie.


robertosfield wrote:
> Hi Qingjie,
>
>

> > ------------------
> > Read this topic online here:

> > http://forum.openscenegraph.org/viewtopic.php?p=65083#65083 (http://forum.openscenegraph.org/viewtopic.php?p=65083#65083)


> >
> >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> >
> >
> >
>
>

> ------------------
> Post generated by Mail2Forum

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=65118#65118

Reply all
Reply to author
Forward
0 new messages