Added support for ImageSequence to all Texture classes

This commit is contained in:
Robert Osfield 2008-07-22 12:28:46 +00:00
parent 74a1b7881e
commit 5ab73e9f80
10 changed files with 160 additions and 7 deletions

View File

@ -58,8 +58,15 @@ class OSG_EXPORT ImageSequence : public ImageStream
bool getPruneOldImages() const { return _pruneOldImages; }
void addImageFile(const std::string& fileName);
FileNames& getFileNames() { return _fileNames; }
const FileNames& getFileNames() const { return _fileNames; }
void addImage(osg::Image* image);
Images& getImages() { return _images; }
const Images& getImages() const { return _images; }
virtual void update(NodeVisitor* nv);

View File

@ -35,6 +35,7 @@ namespace osg {
class NodeVisitor;
class State;
class StateSet;
class Texture;
/** META_StateAttribute macro define the standard clone, isSameKindAs,
* className and getType methods.
@ -209,6 +210,14 @@ class OSG_EXPORT StateAttribute : public Object
/** Return the name of the attribute's class type.*/
virtual const char* className() const { return "StateAttribute"; }
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
virtual Texture* asTexture() { return 0; }
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
virtual const Texture* asTexture() const { return 0; }
/** Return the Type identifier of the attribute's class type.*/
virtual Type getType() const = 0;

View File

@ -282,11 +282,17 @@ class OSG_EXPORT Texture : public osg::StateAttribute
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Texture *>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "Texture"; }
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
virtual Texture* asTexture() { return this; }
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
virtual const Texture* asTexture() const { return this; }
virtual Type getType() const { return TEXTURE; }
virtual bool isTextureAttribute() const { return true; }
virtual GLenum getTextureTarget() const = 0;
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const

View File

@ -24,11 +24,15 @@ using namespace osg;
void ImageSequence::UpdateCallback::operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv)
{
const osg::FrameStamp* fs = nv!=0 ? nv->getFrameStamp() : 0;
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attr);
if (texture2D && texture2D->getImage() && fs)
osg::Texture* texture = attr ? attr->asTexture() : 0;
//osg::notify(osg::NOTICE)<<"ImageSequence::UpdateCallback::"<<texture<<std::endl;
if (texture)
{
texture2D->getImage()->update(nv);
for(unsigned int i=0; i<texture->getNumImages(); ++i)
{
texture->getImage(i)->update(nv);
}
}
}

View File

@ -12,6 +12,7 @@
*/
#include <osg/GLExtensions>
#include <osg/Texture1D>
#include <osg/ImageSequence>
#include <osg/State>
#include <osg/GLU>
@ -87,12 +88,25 @@ int Texture1D::compare(const StateAttribute& sa) const
void Texture1D::setImage(Image* image)
{
if (_image == image) return;
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(0);
setDataVariance(osg::Object::STATIC);
}
// delete old texture objects.
dirtyTextureObject();
_image = image;
_modifiedCount.setAllElementsTo(0);
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(new ImageSequence::UpdateCallback());
setDataVariance(osg::Object::DYNAMIC);
}
}

View File

@ -13,6 +13,7 @@
#include <osg/GLExtensions>
#include <osg/Texture2D>
#include <osg/ImageSequence>
#include <osg/State>
#include <osg/Notify>
#include <osg/GLU>
@ -108,8 +109,22 @@ int Texture2D::compare(const StateAttribute& sa) const
void Texture2D::setImage(Image* image)
{
if (_image == image) return;
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(0);
setDataVariance(osg::Object::STATIC);
}
_image = image;
_modifiedCount.setAllElementsTo(0);
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(new ImageSequence::UpdateCallback());
setDataVariance(osg::Object::DYNAMIC);
}
}

View File

@ -13,6 +13,7 @@
#include <osg/GLExtensions>
#include <osg/Texture2DArray>
#include <osg/State>
#include <osg/ImageSequence>
#include <osg/Notify>
#include <string.h>
@ -110,9 +111,40 @@ void Texture2DArray::setImage(unsigned int layer, Image* image)
return;
}
if (_images[layer] == image) return;
unsigned numImageSequencesBefore = 0;
for (unsigned int i=0; i<getNumImages(); ++i)
{
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get());
if (is) ++numImageSequencesBefore;
}
// set image
_images[layer] = image;
_modifiedCount[layer].setAllElementsTo(0);
// find out if we need to reset the update callback to handle the animation of ImageSequence
unsigned numImageSequencesAfter = 0;
for (unsigned int i=0; i<getNumImages(); ++i)
{
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get());
if (is) ++numImageSequencesAfter;
}
if (numImageSequencesBefore>0)
{
if (numImageSequencesAfter==0)
{
setUpdateCallback(0);
setDataVariance(osg::Object::STATIC);
}
}
else if (numImageSequencesAfter>0)
{
setUpdateCallback(new ImageSequence::UpdateCallback());
setDataVariance(osg::Object::DYNAMIC);
}
}
void Texture2DArray::setTextureSize(int width, int height, int depth)

View File

@ -13,6 +13,7 @@
#include <osg/GLExtensions>
#include <osg/Texture3D>
#include <osg/State>
#include <osg/ImageSequence>
#include <osg/GLU>
#include <osg/Notify>
@ -96,12 +97,26 @@ int Texture3D::compare(const StateAttribute& sa) const
void Texture3D::setImage(Image* image)
{
if (_image == image) return;
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(0);
setDataVariance(osg::Object::STATIC);
}
// delete old texture objects.
dirtyTextureObject();
_modifiedCount.setAllElementsTo(0);
_image = image;
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(new ImageSequence::UpdateCallback());
setDataVariance(osg::Object::DYNAMIC);
}
}
void Texture3D::computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& inwidth, GLsizei& inheight,GLsizei& indepth, GLsizei& numMipmapLevels) const
@ -195,6 +210,8 @@ void Texture3D::apply(State& state) const
}
else if (_image.get() && getModifiedCount(contextID) != _image->getModifiedCount())
{
computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _textureDepth,_numMipmapLevels);
applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMipmapLevels);
// update the modified count to show that it is upto date.
@ -344,13 +361,14 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz
if (!compressed_image)
{
// notify(WARN)<<"glTexImage3D"<<std::endl;
notify(WARN)<<"glTexImage3D '"<<image->getFileName()<<"' data="<<(void*)image->data()<<std::endl;
extensions->glTexImage3D( target, 0, _internalFormat,
inwidth, inheight, indepth,
_borderWidth,
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->data() );
notify(WARN)<<"done glTexImage3D"<<std::endl;
}
else if (extensions->isCompressedTexImage3DSupported())
{

View File

@ -15,6 +15,7 @@
#include <osg/Image>
#include <osg/State>
#include <osg/TextureCubeMap>
#include <osg/ImageSequence>
#include <osg/Notify>
#include <osg/GLU>
@ -128,8 +129,40 @@ int TextureCubeMap::compare(const StateAttribute& sa) const
void TextureCubeMap::setImage( unsigned int face, Image* image)
{
if (_images[face] == image) return;
unsigned numImageSequencesBefore = 0;
for (unsigned int i=0; i<getNumImages(); ++i)
{
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get());
if (is) ++numImageSequencesBefore;
}
_images[face] = image;
_modifiedCount[face].setAllElementsTo(0);
// find out if we need to reset the update callback to handle the animation of ImageSequence
unsigned numImageSequencesAfter = 0;
for (unsigned int i=0; i<getNumImages(); ++i)
{
osg::ImageSequence* is = dynamic_cast<osg::ImageSequence*>(_images[i].get());
if (is) ++numImageSequencesAfter;
}
if (numImageSequencesBefore>0)
{
if (numImageSequencesAfter==0)
{
setUpdateCallback(0);
setDataVariance(osg::Object::STATIC);
}
}
else if (numImageSequencesAfter>0)
{
setUpdateCallback(new ImageSequence::UpdateCallback());
setDataVariance(osg::Object::DYNAMIC);
}
}
Image* TextureCubeMap::getImage(unsigned int face)

View File

@ -13,6 +13,7 @@
#include <osg/GLExtensions>
#include <osg/TextureRectangle>
#include <osg/ImageSequence>
#include <osg/State>
#include <osg/GLU>
#include <osg/Notify>
@ -123,10 +124,24 @@ int TextureRectangle::compare(const StateAttribute& sa) const
void TextureRectangle::setImage(Image* image)
{
if (_image == image) return;
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(0);
setDataVariance(osg::Object::STATIC);
}
// delete old texture objects.
dirtyTextureObject();
_image = image;
if (dynamic_cast<osg::ImageSequence*>(_image.get()))
{
setUpdateCallback(new ImageSequence::UpdateCallback());
setDataVariance(osg::Object::DYNAMIC);
}
}