From Stephan Huber, "attached you'll find the latest versions of the QTKit + the AVFoundation-plugin, some changes to osgPresentation and a small enhancement für ImageIO.

I fixed some bugs and did some more tests with both of the video-plugins. I integrated CoreVideo with osgPresentation, ImageStream has a new virtual method called createSuitableTexture which returns NULL for default implementations. Specialized implementations like the QTKit-plugin return a CoreVideo-texture. I refactored the code in SlideShowConstructor::createTexturedQuad to use a texture returned from ImageStream::createSuitableTexture.

I did not use osgDB::readObjectFile to get the texture-object, as a lot of image-related code in SlideShowConstructor had to be refactored to use a texture.  My changes are minimal and should not break existing code.

There's one minor issue with CoreVideo in general: As the implementation is asynchronous, there might be no texture available, when first showing the video the first frame. I am a bit unsure how to tackle this problem, any input on this is appreciated.

Back to the AVFoundation-plugin: the current implementation does not support CoreVideo as the QTKit-plugin supports it. There's no way to get decoded frames from AVFoundation stored on the GPU, which is kind of sad. I added some support for CoreVideo to transfer decoded frames back to the GPU, but in my testings the performance was worse than using the normal approach using glTexSubImage. This is why I disabled CoreVideo for AVFoundation. You can still request a CoreVideoTexture via readObjectFile, though.
"
This commit is contained in:
Robert Osfield
2012-10-24 10:43:01 +00:00
parent 1591fe09f3
commit f9fd4342ba
10 changed files with 170 additions and 79 deletions

View File

@@ -59,6 +59,7 @@
using namespace osgPresentation;
#define USE_CLIENT_STORAGE_HINT 0
#define USE_TEXTURE_FROM_VIDEO_PLUGIN 1
class SetToTransparentBin : public osg::NodeVisitor
{
@@ -770,7 +771,7 @@ void SlideShowConstructor::findImageStreamsAndAddCallbacks(osg::Node* node)
osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3& pos, const osg::Vec4& rotation, float width, float height, osg::Image* image, bool& usedTextureRectangle)
{
osg::Geometry* pictureQuad = 0;
osg::Texture* texture = 0;
osg::ref_ptr<osg::Texture> texture = 0;
osg::StateSet* stateset = 0;
osg::Vec3 positionVec = pos;
@@ -782,7 +783,15 @@ osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3&
heightVec = heightVec*rotationMatrix;
osg::ImageStream* imageStream = dynamic_cast<osg::ImageStream*>(image);
// let the video-plugin create a texture for us, if supported
#if USE_TEXTURE_FROM_VIDEO_PLUGIN
if(imageStream)
{
texture = imageStream->createSuitableTexture();
}
#endif
bool flipYAxis = image->getOrigin()==osg::Image::TOP_LEFT;
#if 1
@@ -798,50 +807,47 @@ osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3&
// pass back info on wether texture 2D is used.
usedTextureRectangle = useTextureRectangle;
if (useTextureRectangle)
if (!texture)
{
pictureQuad = osg::createTexturedQuadGeometry(positionVec,
widthVec,
heightVec,
0.0f, flipYAxis ? image->t() : 0.0f,
image->s(), flipYAxis ? 0.0f : image->t());
stateset = pictureQuad->getOrCreateStateSet();
texture = new osg::TextureRectangle(image);
stateset->setTextureAttributeAndModes(0,
texture,
osg::StateAttribute::ON);
if (useTextureRectangle)
{
texture = new osg::TextureRectangle(image);
}
else
{
texture = new osg::Texture2D(image);
texture->setResizeNonPowerOfTwoHint(false);
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
#if USE_CLIENT_STORAGE_HINT
texture->setClientStorageHint(true);
#endif
}
}
else
if (texture)
{
float t(0), l(0);
float r = (texture->getTextureTarget() == GL_TEXTURE_RECTANGLE) ? image->s() : 1;
float b = (texture->getTextureTarget() == GL_TEXTURE_RECTANGLE) ? image->t() : 1;
if (flipYAxis)
std::swap(t,b);
pictureQuad = osg::createTexturedQuadGeometry(positionVec,
widthVec,
heightVec,
0.0f, flipYAxis ? 1.0f : 0.0f,
1.0f, flipYAxis ? 0.0f : 1.0f);
widthVec,
heightVec,
l, t, r, b);
stateset = pictureQuad->getOrCreateStateSet();
texture = new osg::Texture2D(image);
texture->setResizeNonPowerOfTwoHint(false);
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
#if USE_CLIENT_STORAGE_HINT
texture->setClientStorageHint(true);
#endif
stateset->setTextureAttributeAndModes(0,
texture,
osg::StateAttribute::ON);
texture,
osg::StateAttribute::ON);
}
if (!pictureQuad) return 0;
if (imageStream)
{
imageStream->pause();