From Wojciech Lewandowski, "Reading and Writing of Texture2DArrays for IVE format."

This commit is contained in:
Robert Osfield 2010-05-21 09:56:59 +00:00
parent a79a13955a
commit 0165862701
6 changed files with 111 additions and 0 deletions

View File

@ -112,6 +112,7 @@ SET(TARGET_SRC
Text.cpp
Texture1D.cpp
Texture2D.cpp
Texture2DArray.cpp
Texture3D.cpp
Texture.cpp
TextureCubeMap.cpp
@ -240,6 +241,7 @@ SET(TARGET_H
Text.h
Texture1D.h
Texture2D.h
Texture2DArray.h
Texture3D.h
TextureCubeMap.h
Texture.h

View File

@ -35,6 +35,7 @@
#include "LineStipple.h"
#include "Texture1D.h"
#include "Texture2D.h"
#include "Texture2DArray.h"
#include "Texture3D.h"
#include "TextureCubeMap.h"
#include "TextureRectangle.h"
@ -1437,6 +1438,10 @@ osg::StateAttribute* DataInputStream::readStateAttribute()
attribute = new osg::Texture2D();
((ive::Texture2D*)(attribute.get()))->read(this);
}
else if(attributeID == IVETEXTURE2DARRAY){
attribute = new osg::Texture2DArray();
((ive::Texture2DArray*)(attribute.get()))->read(this);
}
else if(attributeID == IVETEXTURE3D){
attribute = new osg::Texture3D();
((ive::Texture3D*)(attribute.get()))->read(this);

View File

@ -36,6 +36,7 @@
#include "LineStipple.h"
#include "Texture1D.h"
#include "Texture2D.h"
#include "Texture2DArray.h"
#include "Texture3D.h"
#include "TextureCubeMap.h"
#include "TextureRectangle.h"
@ -1062,6 +1063,10 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
else if(dynamic_cast<const osg::Texture3D*>(attribute)){
((ive::Texture3D*)(attribute))->write(this);
}
// This is a Texture2DArray
else if(dynamic_cast<const osg::Texture2DArray*>(attribute)){
((ive::Texture2DArray*)(attribute))->write(this);
}
// This is a TextureCubeMap
else if(dynamic_cast<const osg::TextureCubeMap*>(attribute)){
((ive::TextureCubeMap*)(attribute))->write(this);

View File

@ -88,6 +88,7 @@ namespace ive {
#define IVEFOG 0x00001133
#define IVELINESTIPPLE 0x00001134
#define IVEPOLYGONSTIPPLE 0x00001135
#define IVETEXTURE2DARRAY 0x00001136
// Drawables
#define IVEDRAWABLE 0x00001000

View File

@ -0,0 +1,80 @@
/**********************************************************************
*
* FILE: Texture2DArray.cpp
*
* DESCRIPTION: Read/Write osg::Texture2DArray in binary format to disk.
*
* CREATED BY: Wojtek Lewandowski based on TextureCubeMap ive support
*
* HISTORY: Created 12.02.2010
*
**********************************************************************/
#include "Exception.h"
#include "Texture2DArray.h"
#include "Texture.h"
#include "Image.h"
using namespace ive;
void Texture2DArray::write(DataOutputStream* out){
// Write Texture2DArray's identification.
out->writeInt(IVETEXTURE2DARRAY);
// 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
out_THROW_EXCEPTION("Texture2DArray::write(): Could not cast this osg::Texture2DArray to an osg::Texture.");
// Write Texture2DArray's properties.
// Write texture size
out->writeInt(getTextureWidth());
out->writeInt(getTextureHeight());
out->writeInt(getTextureDepth());
// Write number of mipmap levels
out->writeInt(getNumMipmapLevels());
for( int i = 0; i < getTextureDepth(); i++ )
{
out->writeImage( getImage( i ) );
}
}
void Texture2DArray::read(DataInputStream* in)
{
// Peek on Texture2DArray's identification.
int id = in->peekInt();
if(id == IVETEXTURE2DARRAY){
// Read Texture2DArray's identification.
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
in_THROW_EXCEPTION("Texture2DArray::read(): Could not cast this osg::Texture2DArray to an osg::Texture.");
// Read Texture2DArray's properties
// Read texture size
int width = in->readInt();
int height = in->readInt();
int depth = in->readInt();
setTextureSize(width, height, depth);
// Read number of mipmap levels
setNumMipmapLevels((unsigned int)in->readInt());
for( int i = 0; i < depth; i++ )
{
setImage( i, in->readImage() );
}
}
else{
in_THROW_EXCEPTION("Texture2DArray::read(): Expected Texture2DArray identification.");
}
}

View File

@ -0,0 +1,18 @@
#ifndef IVE_TEXTURE2DARRAY
#define IVE_TEXTURE2DARRAY 1
#include <osg/Texture2DArray>
#include "ReadWrite.h"
namespace ive
{
class Texture2DArray : public osg::Texture2DArray, public ReadWrite
{
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif