Introduced SwitchLayer which will form the basis of provided support for varients

This commit is contained in:
Robert Osfield
2008-08-27 10:13:30 +00:00
parent 9499cfa420
commit 95a359bdab
11 changed files with 372 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ SET(TARGET_SRC
ClusterCullingCallback.cpp
ColorMask.cpp
CompositeLayer.cpp
SwitchLayer.cpp
ConeSector.cpp
ConvexPlanarOccluder.cpp
ConvexPlanarPolygon.cpp
@@ -133,6 +134,7 @@ SET(TARGET_H
ClusterCullingCallback.h
ColorMask.h
CompositeLayer.h
SwitchLayer.h
ConeSector.h
ConvexPlanarOccluder.h
ConvexPlanarPolygon.h

View File

@@ -105,6 +105,7 @@
#include "ImageLayer.h"
#include "HeightFieldLayer.h"
#include "CompositeLayer.h"
#include "SwitchLayer.h"
#include "FadeText.h"
#include "Text3D.h"
@@ -1585,6 +1586,11 @@ osgTerrain::Layer* DataInputStream::readLayer()
layer = new osgTerrain::ImageLayer;
((ive::ImageLayer*)(layer))->read(this);
}
else if (layerid==IVESWITCHLAYER)
{
layer = new osgTerrain::SwitchLayer;
((ive::SwitchLayer*)(layer))->read(this);
}
else if (layerid==IVECOMPOSITELAYER)
{
layer = new osgTerrain::CompositeLayer;

View File

@@ -106,6 +106,7 @@
#include "ImageLayer.h"
#include "HeightFieldLayer.h"
#include "CompositeLayer.h"
#include "SwitchLayer.h"
#include <osg/Notify>
#include <osg/io_utils>
@@ -1289,6 +1290,10 @@ void DataOutputStream::writeLayer(const osgTerrain::Layer* layer)
{
((ive::ImageLayer*)(layer))->write(this);
}
else if (dynamic_cast<const osgTerrain::SwitchLayer*>(layer))
{
((ive::SwitchLayer*)(layer))->write(this);
}
else if (dynamic_cast<const osgTerrain::CompositeLayer*>(layer))
{
((ive::CompositeLayer*)(layer))->write(this);

View File

@@ -19,6 +19,7 @@
#include "ImageLayer.h"
#include "HeightFieldLayer.h"
#include "CompositeLayer.h"
#include "SwitchLayer.h"
#include <osgDB/ReadFile>
@@ -108,6 +109,10 @@ void LayerHelper::writeLayer(DataOutputStream* out, osgTerrain::Layer* layer)
{
((ive::ImageLayer*)(layer))->write(out);
}
else if (dynamic_cast<osgTerrain::SwitchLayer*>(layer))
{
((ive::SwitchLayer*)(layer))->write(out);
}
else if (dynamic_cast<osgTerrain::CompositeLayer*>(layer))
{
((ive::CompositeLayer*)(layer))->write(out);
@@ -150,6 +155,12 @@ osgTerrain::Layer* LayerHelper::readLayer(DataInputStream* in)
((ive::ImageLayer*)(layer))->read(in);
return layer;
}
else if (id==IVESWITCHLAYER)
{
osgTerrain::SwitchLayer* layer = new osgTerrain::SwitchLayer;
((ive::SwitchLayer*)(layer))->read(in);
return layer;
}
else if (id==IVECOMPOSITELAYER)
{
osgTerrain::CompositeLayer* layer = new osgTerrain::CompositeLayer;

View File

@@ -135,8 +135,9 @@ namespace ive {
#define IVETERRAINTECHNIQUE 0x00200008
#define IVEGEOMETRYTECHNIQUE 0x00200009
#define IVEVALIDDATAOPERATOR 0x0020000A
#define IVEVALIDRANGE 0x0020000B
#define IVENODATAVALUE 0x0020000C
#define IVEVALIDRANGE 0x0020000B
#define IVENODATAVALUE 0x0020000C
#define IVESWITCHLAYER 0x0020000D
//#define IVETERRAIN 0x0020000A
// osgFX classes

View File

@@ -0,0 +1,88 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include "Exception.h"
#include "SwitchLayer.h"
#include "Layer.h"
using namespace ive;
void SwitchLayer::write(DataOutputStream* out)
{
// Write Layer's identification.
out->writeInt(IVESWITCHLAYER);
// If the osg class is inherited by any other class we should also write this to file.
osgTerrain::Layer* layer = dynamic_cast<osgTerrain::Layer*>(this);
if (layer)
((ive::Layer*)(layer))->write(out);
else
throw Exception("SwitchLayer::write(): Could not cast this osgLayer::SwitchLayer to an osgTerrain::Layer.");
out->writeUInt(getActiveLayer());
LayerHelper helper;
out->writeUInt(getNumLayers());
for(unsigned int i=0; i<getNumLayers(); ++i)
{
if(getLayer(i))
{
out->writeBool(true);
helper.writeLayer(out, getLayer(i));
}
else
{
out->writeBool(false);
out->writeString(getFileName(i));
}
}
}
void SwitchLayer::read(DataInputStream* in)
{
// Peek on Layer's identification.
int id = in->peekInt();
if (id != IVESWITCHLAYER)
throw Exception("SwitchLayer::read(): Expected SwitchLayer identification.");
// Read Layer's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osgTerrain::Layer* layer = dynamic_cast<osgTerrain::Layer*>(this);
if (layer)
((ive::Layer*)(layer))->read(in);
else
throw Exception("SwitchLayer::read(): Could not cast this osgLayer::Layer to an osg::Group.");
setActiveLayer(in->readUInt());
LayerHelper helper;
unsigned int numLayers = in->readUInt();
for(unsigned int i=0; i<numLayers; ++i)
{
bool readInlineLayer = in->readBool();
if (readInlineLayer)
{
addLayer(helper.readLayer(in));
}
else
{
addLayer(in->readString());
}
}
}

View File

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