From eb346bed131c2c44a7ca884d0036f3ba57e67746 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Sep 2004 14:31:06 +0000 Subject: [PATCH] Added Texture3D implementation. --- src/osgPlugins/ive/DataInputStream.cpp | 5 ++ src/osgPlugins/ive/DataOutputStream.cpp | 5 ++ src/osgPlugins/ive/GNUmakefile | 3 +- src/osgPlugins/ive/Texture3D.cpp | 99 +++++++++++++++++++++++++ src/osgPlugins/ive/Texture3D.h | 15 ++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/osgPlugins/ive/Texture3D.cpp create mode 100644 src/osgPlugins/ive/Texture3D.h diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index dfb24de94..55ff55897 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -27,6 +27,7 @@ #include "LineWidth.h" #include "Texture1D.h" #include "Texture2D.h" +#include "Texture3D.h" #include "TextureCubeMap.h" #include "TexEnv.h" #include "TexEnvCombine.h" @@ -657,6 +658,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::Texture2D(); ((ive::Texture2D*)(attribute))->read(this); } + else if(attributeID == IVETEXTURE3D){ + attribute = new osg::Texture3D(); + ((ive::Texture3D*)(attribute))->read(this); + } else if(attributeID == IVETEXTURECUBEMAP){ attribute = new osg::TextureCubeMap(); ((ive::TextureCubeMap*)(attribute))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 70fc376b9..babd49693 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -28,6 +28,7 @@ #include "LineWidth.h" #include "Texture1D.h" #include "Texture2D.h" +#include "Texture3D.h" #include "TextureCubeMap.h" #include "TexEnv.h" #include "TexEnvCombine.h" @@ -455,6 +456,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::Texture2D*)(attribute))->write(this); } + // This is a Texture2D + else if(dynamic_cast(attribute)){ + ((ive::Texture3D*)(attribute))->write(this); + } // This is a TextureCubeMap else if(dynamic_cast(attribute)){ ((ive::TextureCubeMap*)(attribute))->write(this); diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index f6cdf0a1d..e35853f96 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -57,9 +57,10 @@ CXXFILES =\ Texture.cpp\ Texture1D.cpp\ Texture2D.cpp\ + Texture3D.cpp\ + TextureCubeMap.cpp\ FragmentProgram.cpp\ VertexProgram.cpp\ - TextureCubeMap.cpp\ Transform.cpp\ ReaderWriterIVE.cpp\ AzimElevationSector.cpp\ diff --git a/src/osgPlugins/ive/Texture3D.cpp b/src/osgPlugins/ive/Texture3D.cpp new file mode 100644 index 000000000..93ddcc76c --- /dev/null +++ b/src/osgPlugins/ive/Texture3D.cpp @@ -0,0 +1,99 @@ +/********************************************************************** + * + * FILE: Texture3D.cpp + * + * DESCRIPTION: Read/Write osg::Texture3D in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 20.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "Texture3D.h" +#include "Texture.h" +#include "Image.h" + +using namespace ive; + +void Texture3D::write(DataOutputStream* out){ + // Write Texture3D's identification. + out->writeInt(IVETEXTURE3D); + // If the osg class is inherited by any other class we should also write this to file. + osg::Texture* tex = dynamic_cast(this); + if(tex){ + ((ive::Texture*)(tex))->write(out); + } + else + throw Exception("Texture3D::write(): Could not cast this osg::Texture3D to an osg::Texture."); + // Write Texture3D's properties. + // Write image. + + // Should we include images date in stream + bool includeImg = out->getIncludeImageData(); + out->writeBool(includeImg); + + // Include image data in stream + if(includeImg){ + out->writeBool(getImage()!=0); + if(getImage()) + ((ive::Image*)getImage())->write(out); + } + // Only include image name in stream + else{ + if (getImage() && !(getImage()->getFileName().empty())){ + out->writeString(getImage()->getFileName()); + } + else{ + out->writeString(""); + } + } + +} + +void Texture3D::read(DataInputStream* in){ + // Read Texture3D's identification. + int id = in->peekInt(); + if(id == IVETEXTURE3D){ + // Code to read Texture3D's properties. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Texture* tex = dynamic_cast(this); + if(tex){ + ((ive::Texture*)(tex))->read(in); + } + else + throw Exception("Texture3D::read(): Could not cast this osg::Texture3D to an osg::Texture."); + // Read image. + + // Should we read image data from stream + bool includeImg = in->readBool(); + + // Read image data from stream + if(includeImg) + { + if(in->readBool()) + { + osg::Image* image = new osg::Image(); + ((ive::Image*)image)->read(in); + setImage(image); + } + } + // Only read image name from stream. + else{ + std::string filename = in->readString(); + if(filename.compare("")!=0){ + osg::Image* image = in->readImage(filename); + if (image){ + setImage(image); + } + } + } + } + else{ + throw Exception("Texture3D::read(): Expected Texture3D identification."); + } +} diff --git a/src/osgPlugins/ive/Texture3D.h b/src/osgPlugins/ive/Texture3D.h new file mode 100644 index 000000000..2d6c7fed5 --- /dev/null +++ b/src/osgPlugins/ive/Texture3D.h @@ -0,0 +1,15 @@ +#ifndef IVE_TEXTURE3D +#define IVE_TEXTURE3D 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Texture3D : public osg::Texture3D, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif