Improve endian awareness somehwat. Still not therer though

This commit is contained in:
ehofman 2003-08-06 17:54:19 +00:00
parent 5a13068aaa
commit f404161d23
5 changed files with 38 additions and 20 deletions

View File

@ -24,6 +24,8 @@
#include <plib/ul.h> #include <plib/ul.h>
#include "SkyArchive.hpp" #include "SkyArchive.hpp"
#include <assert.h>
// FIXME: Remove this section whenever plib has it's own endian conversion // FIXME: Remove this section whenever plib has it's own endian conversion
// funcrtions for 64-bit data types. // funcrtions for 64-bit data types.
#ifndef ulEndianLittleDouble #ifndef ulEndianLittleDouble
@ -34,8 +36,6 @@ inline double ulEndianLittleDouble(double x) {
} }
#endif #endif
#include <assert.h>
struct SkyArchiveEntry struct SkyArchiveEntry
{ {
SkyArchiveEntry() : type(0), pData(NULL), iDataSize(0) {} SkyArchiveEntry() : type(0), pData(NULL), iDataSize(0) {}
@ -520,7 +520,7 @@ SKYRESULT SkyArchive::FindInt16(const char* pName, short* pInt16, unsigned int i
if (pEntry) if (pEntry)
{ {
unsigned short* pData = (unsigned short*)(pEntry->pData); unsigned short* pData = (unsigned short*)(pEntry->pData);
*pInt16 = ulEndianLittle16(*pData); *pInt16 = *pData;
return SKYRESULT_OK; return SKYRESULT_OK;
} }
return SKYRESULT_FAIL; return SKYRESULT_FAIL;
@ -540,7 +540,7 @@ SKYRESULT SkyArchive::FindInt32(const char* pName, int* pInt32, unsigned int ind
if (pEntry) if (pEntry)
{ {
unsigned int* pData = (unsigned int*)(pEntry->pData); unsigned int* pData = (unsigned int*)(pEntry->pData);
*pInt32 = ulEndianLittle32(*pData); *pInt32 = *pData;
return SKYRESULT_OK; return SKYRESULT_OK;
} }
return SKYRESULT_FAIL; return SKYRESULT_FAIL;
@ -580,7 +580,7 @@ SKYRESULT SkyArchive::FindUInt16(const char* pName, unsigned short* pUInt16, uns
if (pEntry) if (pEntry)
{ {
unsigned short* pData = (unsigned short*)(pEntry->pData); unsigned short* pData = (unsigned short*)(pEntry->pData);
*pUInt16 = ulEndianLittle16(*pData); *pUInt16 = *pData;
return SKYRESULT_OK; return SKYRESULT_OK;
} }
return SKYRESULT_FAIL; return SKYRESULT_FAIL;
@ -600,7 +600,7 @@ SKYRESULT SkyArchive::FindUInt32(const char* pName, unsigned int* pUInt32, unsig
if (pEntry) if (pEntry)
{ {
unsigned int* pData = (unsigned int*)(pEntry->pData); unsigned int* pData = (unsigned int*)(pEntry->pData);
*pUInt32 = ulEndianLittle32(*pData); *pUInt32 = *pData;
return SKYRESULT_OK; return SKYRESULT_OK;
} }
return SKYRESULT_FAIL; return SKYRESULT_FAIL;
@ -620,7 +620,7 @@ SKYRESULT SkyArchive::FindFloat32(const char* pName, float* pFloat32, unsigned i
if (pEntry) if (pEntry)
{ {
float* pData = (float*)(pEntry->pData); float* pData = (float*)(pEntry->pData);
*pFloat32 = ulEndianLittleFloat(*pData); *pFloat32 = *pData;
return SKYRESULT_OK; return SKYRESULT_OK;
} }
return SKYRESULT_FAIL; return SKYRESULT_FAIL;
@ -640,7 +640,7 @@ SKYRESULT SkyArchive::FindFloat64(const char* pName, double* pFloat64, unsigned
if (pEntry) if (pEntry)
{ {
double* pData = (double*)(pEntry->pData); double* pData = (double*)(pEntry->pData);
*pFloat64 = ulEndianLittleDouble(*pData); *pFloat64 = *pData;
return SKYRESULT_OK; return SKYRESULT_OK;
} }
return SKYRESULT_FAIL; return SKYRESULT_FAIL;
@ -1175,8 +1175,7 @@ SKYRESULT SkyArchive::_Load( FILE* pSrcFile)
if (!iNumItemsRead) if (!iNumItemsRead)
FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::_Load(): failed to read Archive header."); FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::_Load(): failed to read Archive header.");
unsigned int ui = thisItem.iDataSize; _ulEndianSwap(&thisItem.iDataSize);
thisItem.iDataSize = ulEndianLittle32(ui);
_pName = new char[::strlen(thisItem.pName)+1]; _pName = new char[::strlen(thisItem.pName)+1];
::strcpy( _pName, thisItem.pName); ::strcpy( _pName, thisItem.pName);
@ -1189,8 +1188,7 @@ SKYRESULT SkyArchive::_Load( FILE* pSrcFile)
if (1 > iNumItemsRead) if (1 > iNumItemsRead)
FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::_Load(): failed to read embedded archive item."); FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::_Load(): failed to read embedded archive item.");
unsigned int ui = embeddedItem.iDataSize; _ulEndianSwap(&embeddedItem.iDataSize);
embeddedItem.iDataSize = ulEndianLittle32(ui);
switch( embeddedItem.type) switch( embeddedItem.type)

View File

@ -639,8 +639,13 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive,
//_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius)); //_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius));
archive.FindUInt32("CldNumParticles", &iNumParticles); archive.FindUInt32("CldNumParticles", &iNumParticles);
_ulEndianSwap(&iNumParticles);
//if (!bLocal) //if (!bLocal)
archive.FindVec3f("CldCenter", &vecCenter); archive.FindVec3f("CldCenter", &vecCenter);
_ulEndianSwap((unsigned int*)&vecCenter.x);
_ulEndianSwap((unsigned int*)&vecCenter.y);
_ulEndianSwap((unsigned int*)&vecCenter.z);
Vec3f *pParticlePositions = new Vec3f[iNumParticles]; Vec3f *pParticlePositions = new Vec3f[iNumParticles];
float *pParticleRadii = new float[iNumParticles]; float *pParticleRadii = new float[iNumParticles];
@ -653,6 +658,19 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive,
for (unsigned int i = 0; i < iNumParticles; ++i) 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, SkyCloudParticle *pParticle = new SkyCloudParticle((pParticlePositions[i] + vecCenter) * rScale,
pParticleRadii[i] * rScale, pParticleRadii[i] * rScale,
pParticleColors[i]); pParticleColors[i]);

View File

@ -128,6 +128,7 @@ bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude )
unsigned int iNumFiles; unsigned int iNumFiles;
if (!SKYFAILED(archive.GetInfo("CloudFile", STRING_TYPE, &iNumFiles))) if (!SKYFAILED(archive.GetInfo("CloudFile", STRING_TYPE, &iNumFiles)))
{ {
_ulEndianSwap(&iNumFiles);
for (unsigned int i = 0; i < iNumFiles; ++i) for (unsigned int i = 0; i < iNumFiles; ++i)
{ {
FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i)); FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i));

View File

@ -513,6 +513,7 @@ SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale, do
{ {
unsigned int iNumClouds = 0; unsigned int iNumClouds = 0;
cloudArchive.FindUInt32("CldNumClouds", &iNumClouds); cloudArchive.FindUInt32("CldNumClouds", &iNumClouds);
_ulEndianSwap(&iNumClouds);
SkyArchive subArchive; SkyArchive subArchive;
//iNumClouds = 5; //set this value to reduce cloud field for debugging //iNumClouds = 5; //set this value to reduce cloud field for debugging

View File

@ -57,13 +57,13 @@ SkyTextureState::SkyTextureState()
glActiveTexturePtr = (glActiveTextureProc) glActiveTexturePtr = (glActiveTextureProc)
SGLookupFunction("glActiveTextureARB"); SGLookupFunction("glActiveTextureARB");
}
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &iNumTextureUnits); glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &iNumTextureUnits);
if (iNumTextureUnits > 0) if (iNumTextureUnits > 0)
s_iNumTextureUnits = iNumTextureUnits; s_iNumTextureUnits = iNumTextureUnits;
else else
s_iNumTextureUnits = 1; s_iNumTextureUnits = 1;
} else
s_iNumTextureUnits = 1;
} }
_pTextureUnitState = new TexState[s_iNumTextureUnits]; _pTextureUnitState = new TexState[s_iNumTextureUnits];