Am 01.07.11 19:03, schrieb Chris 'Xenon' Hanson:
> Did anyone ever find a solution to this, or is there some guidelines for
> how to get
> subload to work properly on 2.9.x and 3.x?
I am using a TetureSubloadCallback on osg 2.9.x and osg 3.0.x sucessfully.
I ran into problems if I did something along these lines:
texture->setImage(img);
because this triggers some default behaviour in osg, which conflicts
with the texturesubloadcallback.
For references here's my code:
-------------- VideoTextureSubloadCallback.h -----------------
#include <osg/Texture2D>
class VideoTextureSubloadCallback : public osg::Texture2D::SubloadCallback {
public:
VideoTextureSubloadCallback(osg::Texture2D* tex, unsigned int
width,
unsigned int height);
virtual void load (const osg::Texture2D &texture, osg::State
&state)
const;
virtual void subload (const osg::Texture2D &texture, osg::State
&state) const;
void setImage(osg::Image* image) { _image = image; if (_image)
_image->setPixelBufferObject(0); }
private:
unsigned int _potWidth, _potHeight;
osg::ref_ptr<osg::Image>_image;
};
-------------- VideoTextureSubloadCallback.cpp -----------------
VideoTextureSubloadCallback::VideoTextureSubloadCallback(osg::Texture2D*
texture, unsigned int width, unsigned int height)
: osg::Texture2D::SubloadCallback(),
_potWidth(width),
_potHeight(height)
{
texture->setTextureSize(_potWidth, _potHeight);
// set to linear to disable mipmap generation
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
}
void VideoTextureSubloadCallback::load(const osg::Texture2D& texture,
osg::State& state) const
{
glTexImage2D(
GL_TEXTURE_2D,
0,
_image->getInternalTextureFormat(),
(int)_potWidth,
(int)_potHeight,
0,
_image->getPixelFormat(),
_image->getDataType(),
0x0
);
}
void VideoTextureSubloadCallback::subload(const osg::Texture2D& texture,
osg::State& state) const
{
if (_image.valid()) {
glTexSubImage2D(
GL_TEXTURE_2D, 0, 0, 0,
_image->s(), _image->t(),
_image->getPixelFormat(),
_image->getDataType(),
_image->data()
);
}
}
-------------- setup -----------------
osg::Texture2D* tex = new osg::Texture2D();
VideoTextureSubloadCallback* cb = new VideoTextureSubloadCallback(tex,
2048, 1024);
tex->setSubloadCallback(cb);
cb->setImage(an_image_object);
cheers,
Stephan
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org