of saving image files inside the IVE file. Currently, only the raw image data is saved into the file. If your model uses jpg images as textures then this will cause your file size to increase. I've added an option that will embed the original image file into the IVE file. The IVE file will then attempt to read the image from memory. Since most image loaders support reading from memory, this shouldn't be a problem. To use this new feature the user must specify the option "includeImageFileInIVEFile" when converting to IVE. I tested this out on the "skydome.osg" model that comes with OSG. Using the old method, the IVE file size would be 785 KB, with the new method it is only 42 KB. Also, I've added the support for TextureRectangle's to the IVE reader/writer."
69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
/**********************************************************************
|
|
*
|
|
* FILE: Texture2D.cpp
|
|
*
|
|
* DESCRIPTION: Read/Write osg::Texture2D 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 "Texture2D.h"
|
|
#include "Texture.h"
|
|
#include "Image.h"
|
|
|
|
using namespace ive;
|
|
|
|
void Texture2D::write(DataOutputStream* out){
|
|
// Write Texture2D's identification.
|
|
out->writeInt(IVETEXTURE2D);
|
|
// If the osg class is inherited by any other class we should also write this to file.
|
|
osg::Texture* tex = dynamic_cast<osg::Texture*>(this);
|
|
if(tex){
|
|
((ive::Texture*)(tex))->write(out);
|
|
}
|
|
else
|
|
throw Exception("Texture2D::write(): Could not cast this osg::Texture2D to an osg::Texture.");
|
|
// Write Texture2D's properties.
|
|
// Write image.
|
|
|
|
// Should we include images date in stream
|
|
IncludeImageMode includeImg = out->getIncludeImageMode();
|
|
out->writeChar(includeImg);
|
|
|
|
out->writeImage(includeImg,getImage());
|
|
}
|
|
|
|
void Texture2D::read(DataInputStream* in){
|
|
// Read Texture2D's identification.
|
|
int id = in->peekInt();
|
|
if(id == IVETEXTURE2D){
|
|
// Code to read Texture2D'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<osg::Texture*>(this);
|
|
if(tex){
|
|
((ive::Texture*)(tex))->read(in);
|
|
}
|
|
else
|
|
throw Exception("Texture2D::read(): Could not cast this osg::Texture2D to an osg::Texture.");
|
|
// Read image.
|
|
|
|
// Should we read image data from stream
|
|
IncludeImageMode includeImg = (IncludeImageMode)in->readChar();
|
|
|
|
osg::Image *image = in->readImage(includeImg);
|
|
if(image) {
|
|
setImage(image);
|
|
}
|
|
}
|
|
else{
|
|
throw Exception("Texture2D::read(): Expected Texture2D identification.");
|
|
}
|
|
}
|