Further work on added IO support from CameraNode.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "Exception.h"
|
||||
#include "CameraNode.h"
|
||||
#include "Group.h"
|
||||
#include "Image.h"
|
||||
|
||||
using namespace ive;
|
||||
|
||||
@@ -31,28 +32,138 @@ void CameraNode::write(DataOutputStream* out){
|
||||
throw Exception("CameraNode::write(): Could not cast this osg::CameraNode to an osg::Group.");
|
||||
|
||||
|
||||
out->writeVec4(getClearColor());
|
||||
out->writeUInt(getClearMask());
|
||||
|
||||
out->writeBool(getColorMask()!=0);
|
||||
if (getColorMask()!=0)
|
||||
{
|
||||
out->writeStateAttribute(getColorMask());
|
||||
}
|
||||
|
||||
out->writeBool(getViewport()!=0);
|
||||
if (getViewport()!=0)
|
||||
{
|
||||
out->writeStateAttribute(getViewport());
|
||||
}
|
||||
|
||||
out->writeInt(getTransformOrder());
|
||||
|
||||
// Write CameraNode's properties.
|
||||
out->writeMatrixd(getProjectionMatrix());
|
||||
out->writeMatrixd(getViewMatrix());
|
||||
|
||||
out->writeInt(getRenderOrder());
|
||||
out->writeInt(getRenderTargetImplementation());
|
||||
out->writeInt(getRenderTargetFallback());
|
||||
|
||||
out->writeUInt(getDrawBuffer());
|
||||
out->writeUInt(getReadBuffer());
|
||||
|
||||
const BufferAttachmentMap& baf = getBufferAttachmentMap();
|
||||
out->writeUInt(baf.size());
|
||||
for(BufferAttachmentMap::const_iterator itr = baf.begin();
|
||||
itr != baf.end();
|
||||
++itr)
|
||||
{
|
||||
BufferComponent buffer = itr->first;
|
||||
const Attachment& attachment = itr->second;
|
||||
|
||||
out->writeInt( buffer );
|
||||
out->writeUInt( attachment._internalFormat);
|
||||
|
||||
// this ain't right... what if we need to share images????
|
||||
out->writeBool(attachment._image.valid());
|
||||
if(attachment._image.valid())
|
||||
((ive::Image*)attachment._image.get())->write(out);
|
||||
|
||||
out->writeBool(attachment._texture.valid());
|
||||
if(attachment._texture.valid())
|
||||
out->writeStateAttribute(attachment._texture.get());
|
||||
|
||||
out->writeUInt(attachment._level);
|
||||
out->writeUInt(attachment._face);
|
||||
out->writeBool(attachment._mipMapGeneration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CameraNode::read(DataInputStream* in){
|
||||
void CameraNode::read(DataInputStream* in)
|
||||
{
|
||||
// Read CameraNode's identification.
|
||||
int id = in->peekInt();
|
||||
if(id == IVECAMERANODE){
|
||||
if(id == IVECAMERANODE)
|
||||
{
|
||||
// Code to read CameraNode's properties.
|
||||
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){
|
||||
if(group)
|
||||
{
|
||||
((ive::Group*)(group))->read(in);
|
||||
}
|
||||
else
|
||||
throw Exception("CameraNode::read(): Could not cast this osg::CameraNode to an osg::Group.");
|
||||
|
||||
setClearColor(in->readVec4());
|
||||
setClearMask(in->readUInt());
|
||||
|
||||
if (in->readBool())
|
||||
{
|
||||
osg::ref_ptr<osg::StateAttribute> attribute = in->readStateAttribute();
|
||||
osg::ColorMask* cm = dynamic_cast<osg::ColorMask*>(attribute.get());
|
||||
if (cm) setColorMask(cm);
|
||||
}
|
||||
|
||||
if (in->readBool())
|
||||
{
|
||||
osg::ref_ptr<osg::StateAttribute> attribute = in->readStateAttribute();
|
||||
osg::Viewport* vp = dynamic_cast<osg::Viewport*>(attribute.get());
|
||||
if (vp) setViewport(vp);
|
||||
}
|
||||
|
||||
setTransformOrder((TransformOrder)in->readInt());
|
||||
|
||||
// Read matrix
|
||||
setProjectionMatrix(in->readMatrixd());
|
||||
setViewMatrix(in->readMatrixd());
|
||||
|
||||
|
||||
setRenderOrder((RenderOrder)in->readInt());
|
||||
|
||||
RenderTargetImplementation impl = (RenderTargetImplementation)in->readInt();
|
||||
RenderTargetImplementation fallback = (RenderTargetImplementation)in->readInt();
|
||||
setRenderTargetImplementation(impl, fallback);
|
||||
|
||||
setDrawBuffer((GLenum)in->readUInt());
|
||||
setReadBuffer((GLenum)in->readUInt());
|
||||
|
||||
_bufferAttachmentMap.clear();
|
||||
|
||||
unsigned int numAttachments = in->readUInt();
|
||||
for(unsigned int i=0; i<numAttachments; ++i)
|
||||
{
|
||||
Attachment& attachment = _bufferAttachmentMap[(BufferComponent)in->readInt()];
|
||||
attachment._internalFormat = (GLenum)in->readUInt();
|
||||
|
||||
if (in->readBool())
|
||||
{
|
||||
// this ain't right... what if we need to share images????
|
||||
attachment._image = new osg::Image;
|
||||
((ive::Image*)attachment._image.get())->read(in);
|
||||
}
|
||||
|
||||
if (in->readBool())
|
||||
{
|
||||
osg::ref_ptr<osg::StateAttribute> attribute = in->readStateAttribute();
|
||||
osg::Texture* texture = dynamic_cast<osg::Texture*>(attribute.get());
|
||||
if (texture) attachment._texture = texture;
|
||||
}
|
||||
|
||||
attachment._level = in->readUInt();
|
||||
attachment._face = in->readUInt();
|
||||
attachment._mipMapGeneration = in->readBool();
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw Exception("CameraNode::read(): Expected CameraNode identification");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
@@ -30,23 +31,39 @@ bool CameraNode_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
CameraNode& camera = static_cast<CameraNode&>(obj);
|
||||
|
||||
if (fr[0].matchWord("Type"))
|
||||
if (fr.matchSequence("clearColor %f %f %f %f"))
|
||||
{
|
||||
if (fr[1].matchWord("DYNAMIC"))
|
||||
{
|
||||
camera.setDataVariance(osg::Object::DYNAMIC);
|
||||
fr +=2 ;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
else if (fr[1].matchWord("STATIC"))
|
||||
{
|
||||
camera.setDataVariance(osg::Object::STATIC);
|
||||
fr +=2 ;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
}
|
||||
Vec4 color;
|
||||
fr[1].getFloat(color[0]);
|
||||
fr[2].getFloat(color[1]);
|
||||
fr[3].getFloat(color[2]);
|
||||
fr[4].getFloat(color[3]);
|
||||
camera.setClearColor(color);
|
||||
fr +=5 ;
|
||||
iteratorAdvanced = true;
|
||||
};
|
||||
|
||||
if (fr.matchSequence("clearMask %i"))
|
||||
{
|
||||
unsigned int value;
|
||||
fr[1].getUInt(value);
|
||||
camera.setClearMask(value);
|
||||
fr += 2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::StateAttribute> attribute;
|
||||
while((attribute=fr.readStateAttribute())!=NULL)
|
||||
{
|
||||
osg::Viewport* viewport = dynamic_cast<osg::Viewport*>(attribute.get());
|
||||
if (viewport) camera.setViewport(viewport);
|
||||
else
|
||||
{
|
||||
osg::ColorMask* colormask = dynamic_cast<osg::ColorMask*>(attribute.get());
|
||||
camera.setColorMask(colormask);
|
||||
}
|
||||
}
|
||||
|
||||
Matrix matrix;
|
||||
if (readMatrix(matrix,fr,"ProjectionMatrix"))
|
||||
{
|
||||
@@ -68,6 +85,19 @@ bool CameraNode_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const CameraNode& camera = static_cast<const CameraNode&>(obj);
|
||||
|
||||
fw.indent()<<"clearColor "<<camera.getClearColor()<<std::endl;
|
||||
fw.indent()<<"clearMask 0x"<<std::hex<<camera.getClearMask()<<std::endl;
|
||||
|
||||
if (camera.getColorMask())
|
||||
{
|
||||
fw.writeObject(*camera.getColorMask());
|
||||
}
|
||||
|
||||
if (camera.getViewport())
|
||||
{
|
||||
fw.writeObject(*camera.getViewport());
|
||||
}
|
||||
|
||||
writeMatrix(camera.getProjectionMatrix(),fw,"ProjectionMatrix");
|
||||
writeMatrix(camera.getViewMatrix(),fw,"ViewMatrix");
|
||||
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
#undef OUT
|
||||
#endif
|
||||
|
||||
TYPE_NAME_ALIAS(std::vector< GLenum >, osg::CameraNode::RenderBufferList);
|
||||
|
||||
TYPE_NAME_ALIAS(std::map< osg::CameraNode::BufferComponent COMMA osg::CameraNode::Attachment >, osg::CameraNode::BufferAttachmentMap);
|
||||
|
||||
BEGIN_ENUM_REFLECTOR(osg::CameraNode::TransformOrder)
|
||||
@@ -122,10 +120,6 @@ BEGIN_OBJECT_REFLECTOR(osg::CameraNode)
|
||||
I_Method0(GLenum, getDrawBuffer);
|
||||
I_Method1(void, setReadBuffer, IN, GLenum, buffer);
|
||||
I_Method0(GLenum, getReadBuffer);
|
||||
I_Method2(void, setRenderBuffer, IN, unsigned int, pos, IN, GLenum, buffer);
|
||||
I_Method1(GLenum, getRenderBuffer, IN, unsigned int, pos);
|
||||
I_Method0(osg::CameraNode::RenderBufferList &, getRenderBufferList);
|
||||
I_Method0(const osg::CameraNode::RenderBufferList &, getRenderBufferList);
|
||||
I_Method2(void, attach, IN, osg::CameraNode::BufferComponent, buffer, IN, GLenum, internalFormat);
|
||||
I_MethodWithDefaults5(void, attach, IN, osg::CameraNode::BufferComponent, buffer, , IN, osg::Texture *, texture, , IN, unsigned int, level, 0, IN, unsigned int, face, 0, IN, bool, mipMapGeneration, false);
|
||||
I_Method2(void, attach, IN, osg::CameraNode::BufferComponent, buffer, IN, osg::Image *, image);
|
||||
@@ -153,8 +147,6 @@ BEGIN_OBJECT_REFLECTOR(osg::CameraNode)
|
||||
I_Property(osg::CameraNode::DrawCallback *, PostDrawCallback);
|
||||
I_Property(const osg::Matrixd &, ProjectionMatrix);
|
||||
I_Property(GLenum, ReadBuffer);
|
||||
I_IndexedProperty1(GLenum, RenderBuffer, unsigned int, pos);
|
||||
I_ReadOnlyProperty(osg::CameraNode::RenderBufferList &, RenderBufferList);
|
||||
I_Property(osg::CameraNode::RenderOrder, RenderOrder);
|
||||
I_ReadOnlyProperty(osg::CameraNode::RenderTargetImplementation, RenderTargetFallback);
|
||||
I_Property(osg::CameraNode::RenderTargetImplementation, RenderTargetImplementation);
|
||||
@@ -181,5 +173,3 @@ END_REFLECTOR
|
||||
|
||||
STD_MAP_REFLECTOR(std::map< osg::CameraNode::BufferComponent COMMA osg::CameraNode::Attachment >);
|
||||
|
||||
STD_VECTOR_REFLECTOR(std::vector< GLenum >);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user