Hi Fabian,
It would be cleaner to use a StateAttribute (Texture is subclassed
from StateAttribute) callback rather than a Drawable callback. The
image dirty is also redundent as the setImage will automatically do
this for you.
Other than this the approach you are taking is OK. The OSG will
automatically use texture subloading and the PBO that you attach to
the image, so you'll get good performance from this side of things.
Robert.
On Fri, Aug 22, 2008 at 4:52 AM, Fabian Bützow <[EMAIL PROTECTED]> wrote:
> 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
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org