]> git.mxchange.org Git - simgear.git/commitdiff
Improve endian awareness somehwat. Still not therer though
authorehofman <ehofman>
Wed, 6 Aug 2003 17:54:19 +0000 (17:54 +0000)
committerehofman <ehofman>
Wed, 6 Aug 2003 17:54:19 +0000 (17:54 +0000)
simgear/scene/sky/clouds3d/SkyArchive.cpp
simgear/scene/sky/clouds3d/SkyCloud.cpp
simgear/scene/sky/clouds3d/SkySceneLoader.cpp
simgear/scene/sky/clouds3d/SkySceneManager.cpp
simgear/scene/sky/clouds3d/SkyTextureState.cpp

index 3ff750954db7eae42e79dd4e2803fe16429452cf..256eb5adb9d38115bb82440b67b891041843a779 100644 (file)
@@ -24,6 +24,8 @@
 #include <plib/ul.h>
 #include "SkyArchive.hpp"
 
+#include <assert.h>
+
 // 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 <assert.h>
-
 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)
index 70690cafd6b5f131d4f99ed231f858ac2573e46e..843bc96733019f14197b353142128f6ebaa8cbab 100644 (file)
@@ -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]);
index 288133fc462f4116b005a8c40f76e3117cbad47f..1737622e1c566cf90fa84617fbef80effefbc5bc 100644 (file)
@@ -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));
index 9569f952224122b68aaf3e647b22b2cb829e03ae..07b36696e0c6b05678ce488bb72d2686ff630d0a 100644 (file)
@@ -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
index 4cdbe1e018cdf40d060473f3b80c3a31880bf25c..6c7174e49cf2bb72cba2bbea9dcac80cae445cfc 100644 (file)
@@ -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];