From Paul Martz, completion of .ive and .osg support for OcclusionQueryNode

This commit is contained in:
Robert Osfield 2008-01-04 11:14:11 +00:00
parent b222d4201c
commit 6231c3a5a4
7 changed files with 124 additions and 1 deletions

View File

@ -59,6 +59,7 @@ Multisample.cpp
Node.cpp
Object.cpp
OccluderNode.cpp
OcclusionQueryNode.cpp
PagedLOD.cpp
Point.cpp
PointSprite.cpp
@ -155,6 +156,7 @@ MultiTextureControl.h
Node.h
Object.h
OccluderNode.h
OcclusionQueryNode.h
PagedLOD.h
Point.h
PointSprite.h

View File

@ -71,6 +71,7 @@
#include "Transform.h"
#include "Switch.h"
#include "OccluderNode.h"
#include "OcclusionQueryNode.h"
#include "Impostor.h"
#include "CoordinateSystemNode.h"
#include "Uniform.h"
@ -1418,6 +1419,10 @@ osg::Node* DataInputStream::readNode()
node = new osg::OccluderNode();
((ive::OccluderNode*)(node))->read(this);
}
else if(nodeTypeID== IVEOCCLUSIONQUERYNODE){
node = new osg::OcclusionQueryNode();
((ive::OcclusionQueryNode*)(node))->read(this);
}
else if(nodeTypeID== IVEVISIBILITYGROUP){
node = new osgSim::VisibilityGroup();
((ive::VisibilityGroup*)(node))->read(this);

View File

@ -73,6 +73,7 @@
#include "Transform.h"
#include "Switch.h"
#include "OccluderNode.h"
#include "OcclusionQueryNode.h"
#include "Impostor.h"
#include "CoordinateSystemNode.h"
@ -1038,6 +1039,9 @@ void DataOutputStream::writeNode(const osg::Node* node)
else if(dynamic_cast<const osg::OccluderNode*>(node)){
((ive::OccluderNode*)(node))->write(this);
}
else if(dynamic_cast<const osg::OcclusionQueryNode*>(node)){
((ive::OcclusionQueryNode*)(node))->write(this);
}
else if(dynamic_cast<const osg::Transform*>(node)){
((ive::Transform*)(node))->write(this);
}

View File

@ -0,0 +1,66 @@
/**********************************************************************
*
* FILE: OcclusionQueryNode.cpp
*
* DESCRIPTION: Read/Write osg::OcclusionQueryNode in binary format to disk.
*
* CREATED BY: Copied and hacked OccluderNode.cpp by Paul Martz
*
* HISTORY: Created 2007.12.26
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "OcclusionQueryNode.h"
#include "Group.h"
using namespace ive;
void OcclusionQueryNode::write( DataOutputStream* out )
{
// Write OcclusionQueryNode's identification.
out->writeInt(IVEOCCLUSIONQUERYNODE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("OcclusionQueryNode::write(): Could not cast this osg::OcclusionQueryNode to an osg::Group.");
// Write OcclusionQueryNode's properties.
out->writeBool( getQueriesEnabled() );
out->writeUInt( getVisibilityThreshold() );
out->writeInt( getQueryFrameCount() );
out->writeBool( getDebugDisplay() );
}
void OcclusionQueryNode::read( DataInputStream* in )
{
// Peek on OcclusionQueryNode's identification.
int id = in->peekInt();
if(id == IVEOCCLUSIONQUERYNODE)
{
// Read OcclusionQueryNode's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("OcclusionQueryNode::read(): Could not cast this osg::OcclusionQueryNode to an osg::Group.");
// Read OcclusionQueryNode's properties
setQueriesEnabled( in->readBool() );
setVisibilityThreshold( in->readUInt() );
setQueryFrameCount( in->readInt() );
setDebugDisplay( in->readBool() );
}
else{
throw Exception("OcclusionQueryNode::read(): Expected OcclusionQueryNode identification.");
}
}

View File

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

View File

@ -37,6 +37,7 @@ namespace ive {
#define IVECAMERA 0x00000028
#define IVECAMERAVIEW 0x00000029
#define IVEAUTOTRANSFORM 0x00000030
#define IVEOCCLUSIONQUERYNODE 0x00000031
// Node callbacks
#define IVENODECALLBACK 0x00000050

View File

@ -15,6 +15,7 @@
#include <osg/OcclusionQueryNode>
#include <iostream>
#include <sstream>
#include <string>
#include <osg/io_utils>
@ -40,7 +41,7 @@ bool OQN_readLocalData( osg::Object &obj, osgDB::Input &fr )
{
osg::OcclusionQueryNode& oqn = static_cast<osg::OcclusionQueryNode&>( obj );
bool advanced( false );
int param;
if (fr[0].matchWord( "QueriesEnabled" ))
{
bool enable( fr[1].getStr() == std::string("TRUE") );
@ -48,6 +49,27 @@ bool OQN_readLocalData( osg::Object &obj, osgDB::Input &fr )
fr+=2;
advanced = true;
}
if (fr.matchSequence( "VisibilityThreshold %i" ))
{
fr[1].getInt( param );
oqn.setVisibilityThreshold( param );
fr+=2;
advanced = true;
}
if (fr.matchSequence( "QueryFrameCount %i" ))
{
fr[1].getInt( param );
oqn.setQueryFrameCount( param );
fr+=2;
advanced = true;
}
if (fr[0].matchWord( "DebugDisplay" ))
{
bool enable( fr[1].getStr() == std::string("TRUE") );
oqn.setDebugDisplay( enable );
fr+=2;
advanced = true;
}
return advanced;
}
@ -61,6 +83,13 @@ bool OQN_writeLocalData( const osg::Object &obj, osgDB::Output &fw )
fw.indent() << "QueriesEnabled " <<
(oqn.getQueriesEnabled() ? "TRUE" : "FALSE")
<< std::endl;
fw.indent() << "VisibilityThreshold " <<
oqn.getVisibilityThreshold() << std::endl;
fw.indent() << "QueryFrameCount " <<
oqn.getQueryFrameCount() << std::endl;
fw.indent() << "DebugDisplay " <<
(oqn.getDebugDisplay() ? "TRUE" : "FALSE")
<< std::endl;
return true;
}