From: ehofman Date: Wed, 6 Aug 2003 17:54:19 +0000 (+0000) Subject: Improve endian awareness somehwat. Still not therer though X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f404161d23130646858fa74bc053018206e33d3e;p=simgear.git Improve endian awareness somehwat. Still not therer though --- diff --git a/simgear/scene/sky/clouds3d/SkyArchive.cpp b/simgear/scene/sky/clouds3d/SkyArchive.cpp index 3ff75095..256eb5ad 100644 --- a/simgear/scene/sky/clouds3d/SkyArchive.cpp +++ b/simgear/scene/sky/clouds3d/SkyArchive.cpp @@ -24,6 +24,8 @@ #include #include "SkyArchive.hpp" +#include + // FIXME: Remove this section whenever plib has it's own endian conversion // funcrtions for 64-bit data types. #ifndef ulEndianLittleDouble @@ -34,8 +36,6 @@ inline double ulEndianLittleDouble(double x) { } #endif -#include - struct SkyArchiveEntry { SkyArchiveEntry() : type(0), pData(NULL), iDataSize(0) {} @@ -520,7 +520,7 @@ SKYRESULT SkyArchive::FindInt16(const char* pName, short* pInt16, unsigned int i if (pEntry) { unsigned short* pData = (unsigned short*)(pEntry->pData); - *pInt16 = ulEndianLittle16(*pData); + *pInt16 = *pData; return SKYRESULT_OK; } return SKYRESULT_FAIL; @@ -540,7 +540,7 @@ SKYRESULT SkyArchive::FindInt32(const char* pName, int* pInt32, unsigned int ind if (pEntry) { unsigned int* pData = (unsigned int*)(pEntry->pData); - *pInt32 = ulEndianLittle32(*pData); + *pInt32 = *pData; return SKYRESULT_OK; } return SKYRESULT_FAIL; @@ -580,7 +580,7 @@ SKYRESULT SkyArchive::FindUInt16(const char* pName, unsigned short* pUInt16, uns if (pEntry) { unsigned short* pData = (unsigned short*)(pEntry->pData); - *pUInt16 = ulEndianLittle16(*pData); + *pUInt16 = *pData; return SKYRESULT_OK; } return SKYRESULT_FAIL; @@ -600,7 +600,7 @@ SKYRESULT SkyArchive::FindUInt32(const char* pName, unsigned int* pUInt32, unsig if (pEntry) { unsigned int* pData = (unsigned int*)(pEntry->pData); - *pUInt32 = ulEndianLittle32(*pData); + *pUInt32 = *pData; return SKYRESULT_OK; } return SKYRESULT_FAIL; @@ -620,7 +620,7 @@ SKYRESULT SkyArchive::FindFloat32(const char* pName, float* pFloat32, unsigned i if (pEntry) { float* pData = (float*)(pEntry->pData); - *pFloat32 = ulEndianLittleFloat(*pData); + *pFloat32 = *pData; return SKYRESULT_OK; } return SKYRESULT_FAIL; @@ -640,7 +640,7 @@ SKYRESULT SkyArchive::FindFloat64(const char* pName, double* pFloat64, unsigned if (pEntry) { double* pData = (double*)(pEntry->pData); - *pFloat64 = ulEndianLittleDouble(*pData); + *pFloat64 = *pData; return SKYRESULT_OK; } return SKYRESULT_FAIL; @@ -1175,8 +1175,7 @@ SKYRESULT SkyArchive::_Load( FILE* pSrcFile) if (!iNumItemsRead) FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::_Load(): failed to read Archive header."); - unsigned int ui = thisItem.iDataSize; - thisItem.iDataSize = ulEndianLittle32(ui); + _ulEndianSwap(&thisItem.iDataSize); _pName = new char[::strlen(thisItem.pName)+1]; ::strcpy( _pName, thisItem.pName); @@ -1189,8 +1188,7 @@ SKYRESULT SkyArchive::_Load( FILE* pSrcFile) if (1 > iNumItemsRead) FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::_Load(): failed to read embedded archive item."); - unsigned int ui = embeddedItem.iDataSize; - embeddedItem.iDataSize = ulEndianLittle32(ui); + _ulEndianSwap(&embeddedItem.iDataSize); switch( embeddedItem.type) diff --git a/simgear/scene/sky/clouds3d/SkyCloud.cpp b/simgear/scene/sky/clouds3d/SkyCloud.cpp index 70690caf..843bc967 100644 --- a/simgear/scene/sky/clouds3d/SkyCloud.cpp +++ b/simgear/scene/sky/clouds3d/SkyCloud.cpp @@ -639,8 +639,13 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive, //_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius)); archive.FindUInt32("CldNumParticles", &iNumParticles); + _ulEndianSwap(&iNumParticles); + //if (!bLocal) archive.FindVec3f("CldCenter", &vecCenter); + _ulEndianSwap((unsigned int*)&vecCenter.x); + _ulEndianSwap((unsigned int*)&vecCenter.y); + _ulEndianSwap((unsigned int*)&vecCenter.z); Vec3f *pParticlePositions = new Vec3f[iNumParticles]; float *pParticleRadii = new float[iNumParticles]; @@ -650,9 +655,22 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive, archive.FindData("CldParticlePositions", ANY_TYPE, (void**const)&pParticlePositions, &iNumBytes); archive.FindData("CldParticleRadii", ANY_TYPE, (void**const)&pParticleRadii, &iNumBytes); archive.FindData("CldParticleColors", ANY_TYPE, (void**const)&pParticleColors, &iNumBytes); - + for (unsigned int i = 0; i < iNumParticles; ++i) { + + _ulEndianSwap((unsigned int*)&pParticlePositions[i].x); + _ulEndianSwap((unsigned int*)&pParticlePositions[i].y); + _ulEndianSwap((unsigned int*)&pParticlePositions[i].z); + + _ulEndianSwap((unsigned int*)&pParticleRadii[i]); + + _ulEndianSwap((unsigned int*)&pParticleColors[i].x); + _ulEndianSwap((unsigned int*)&pParticleColors[i].y); + _ulEndianSwap((unsigned int*)&pParticleColors[i].z); + _ulEndianSwap((unsigned int*)&pParticleColors[i].w); + + SkyCloudParticle *pParticle = new SkyCloudParticle((pParticlePositions[i] + vecCenter) * rScale, pParticleRadii[i] * rScale, pParticleColors[i]); diff --git a/simgear/scene/sky/clouds3d/SkySceneLoader.cpp b/simgear/scene/sky/clouds3d/SkySceneLoader.cpp index 288133fc..1737622e 100644 --- a/simgear/scene/sky/clouds3d/SkySceneLoader.cpp +++ b/simgear/scene/sky/clouds3d/SkySceneLoader.cpp @@ -128,6 +128,7 @@ bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude ) unsigned int iNumFiles; if (!SKYFAILED(archive.GetInfo("CloudFile", STRING_TYPE, &iNumFiles))) { + _ulEndianSwap(&iNumFiles); for (unsigned int i = 0; i < iNumFiles; ++i) { FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i)); diff --git a/simgear/scene/sky/clouds3d/SkySceneManager.cpp b/simgear/scene/sky/clouds3d/SkySceneManager.cpp index 9569f952..07b36696 100644 --- a/simgear/scene/sky/clouds3d/SkySceneManager.cpp +++ b/simgear/scene/sky/clouds3d/SkySceneManager.cpp @@ -513,6 +513,7 @@ SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale, do { unsigned int iNumClouds = 0; cloudArchive.FindUInt32("CldNumClouds", &iNumClouds); + _ulEndianSwap(&iNumClouds); SkyArchive subArchive; //iNumClouds = 5; //set this value to reduce cloud field for debugging diff --git a/simgear/scene/sky/clouds3d/SkyTextureState.cpp b/simgear/scene/sky/clouds3d/SkyTextureState.cpp index 4cdbe1e0..6c7174e4 100644 --- a/simgear/scene/sky/clouds3d/SkyTextureState.cpp +++ b/simgear/scene/sky/clouds3d/SkyTextureState.cpp @@ -57,13 +57,13 @@ SkyTextureState::SkyTextureState() glActiveTexturePtr = (glActiveTextureProc) SGLookupFunction("glActiveTextureARB"); - } - - glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &iNumTextureUnits); - if (iNumTextureUnits > 0) - s_iNumTextureUnits = iNumTextureUnits; - else - s_iNumTextureUnits = 1; + glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &iNumTextureUnits); + if (iNumTextureUnits > 0) + s_iNumTextureUnits = iNumTextureUnits; + else + s_iNumTextureUnits = 1; + } else + s_iNumTextureUnits = 1; } _pTextureUnitState = new TexState[s_iNumTextureUnits];