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

Qingjie Zhang 305479421 at qq.com
Wed Sep 9 20:42:11 PDT 2015


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,
> On 9 September 2015 at 09:27, Qingjie Zhang < ()> 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.
> 
>  
> 
>  ------------------
> Post generated by Mail2Forum


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








More information about the osg-users mailing list