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 "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)

View 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]);

View 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));

View 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

View 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];