Hello,
i want to display a live camera stream on a texture rectangle which i pass to a bunch of shaders.
I just want to ask if the way im doing it is the most efficient one?
The best solution would be to upload the live camera image once to the GPU
and pass the texture to the several shader..

is this accomplished by the following code?
(the picture Quads state attribute is linked to the shader)

struct DrawableUpdateCallback : public osg::Drawable::UpdateCallback
{

   DrawableUpdateCallback(){};
   DrawableUpdateCallback(CameraBase* camera, TextureRectangle* texture)
   {
       this->camera= camera;
       this->texture= texture;
   };

   virtual void update(osg::NodeVisitor*, osg::Drawable* drawable)
   {
       Image* img= texture->getImage();
img->setImage(camera->getWidth(), camera->getHeight(), 1, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, camera->getRawFrame(), Image::NO_DELETE, 1);
       img->dirty();
   }

   CameraBase* camera;
   TextureRectangle* texture;
};

//in my class:
ref_ptr<Image> camImg= new Image();
PixelBufferObject* pbo= new PixelBufferObject(camImg.get());
camImg->setPixelBufferObject(pbo);

ref_ptr<TextureRectangle> texture= new TextureRectangle(camImg.get());

StateSet* state= pictureQuad->getOrCreateStateSet();
state->setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON); pictureQuad->setUpdateCallback(new DrawableUpdateCallback(camera, texture.get()));

cheers,
Fabian

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

Reply via email to