From 41823a115d4856ffe3fe17a1c2ae2e0683c4da21 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 1 Nov 2004 10:04:40 +0000 Subject: [PATCH] Added handling of endian in DrawElementsUShort/UInt implementations --- src/osgPlugins/ive/DrawElementsUByte.cpp | 1 + src/osgPlugins/ive/DrawElementsUInt.cpp | 12 +++++++++++- src/osgPlugins/ive/DrawElementsUShort.cpp | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/osgPlugins/ive/DrawElementsUByte.cpp b/src/osgPlugins/ive/DrawElementsUByte.cpp index e39835f6f..942538722 100644 --- a/src/osgPlugins/ive/DrawElementsUByte.cpp +++ b/src/osgPlugins/ive/DrawElementsUByte.cpp @@ -54,6 +54,7 @@ void DrawElementsUByte::read(DataInputStream* in){ int size = in->readInt(); resize(size); in->readCharArray((char*)&front(), size * CHARSIZE); + } else{ throw Exception("DrawElementsUByte::read(): Expected DrawElementsUByte identification."); diff --git a/src/osgPlugins/ive/DrawElementsUInt.cpp b/src/osgPlugins/ive/DrawElementsUInt.cpp index cc1647224..473ebacd5 100644 --- a/src/osgPlugins/ive/DrawElementsUInt.cpp +++ b/src/osgPlugins/ive/DrawElementsUInt.cpp @@ -15,6 +15,7 @@ #include "Exception.h" #include "DrawElementsUInt.h" #include "PrimitiveSet.h" +#include using namespace ive; @@ -36,7 +37,8 @@ void DrawElementsUInt::write(DataOutputStream* out){ out->writeCharArray((const char*)&front(), size() * INTSIZE); } -void DrawElementsUInt::read(DataInputStream* in){ +void DrawElementsUInt::read(DataInputStream* in) +{ // Read DrawElementsUInt's identification. int id = in->peekInt(); if(id == IVEDRAWELEMENTSUINT){ @@ -54,6 +56,14 @@ void DrawElementsUInt::read(DataInputStream* in){ int size = in->readInt(); resize(size); in->readCharArray((char*)&front(), size * INTSIZE); + + if (in->_byteswap) + { + for (int i = 0 ; i < size ; i++ ) + { + osg::swapBytes4((char*)&((*this)[i])) ; + } + } } else{ throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification."); diff --git a/src/osgPlugins/ive/DrawElementsUShort.cpp b/src/osgPlugins/ive/DrawElementsUShort.cpp index f497edcd7..698ccb77e 100644 --- a/src/osgPlugins/ive/DrawElementsUShort.cpp +++ b/src/osgPlugins/ive/DrawElementsUShort.cpp @@ -15,6 +15,7 @@ #include "Exception.h" #include "DrawElementsUShort.h" #include "PrimitiveSet.h" +#include using namespace ive; @@ -54,6 +55,14 @@ void DrawElementsUShort::read(DataInputStream* in){ int size = in->readInt(); resize(size); in->readCharArray((char*)&front(), size * SHORTSIZE); + + if (in->_byteswap) + { + for (int i = 0 ; i < size ; i++ ) + { + osg::swapBytes((char *)&((*this)[i]),SHORTSIZE) ; + } + } } else{ throw Exception("DrawElementsUShort::read(): Expected DrawElementsUShort identification.");