Skip to content

Commit

Permalink
Big-endian compat (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed May 21, 2023
1 parent 6c2a90f commit 0d997af
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/QD3D/QD3D_Support.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ void MakeShadowTexture(void)
width,
height,
GL_BGRA,
#if !(__BIG_ENDIAN__)
GL_UNSIGNED_INT_8_8_8_8,
#else
GL_UNSIGNED_INT_8_8_8_8_REV,
#endif
pixelData,
0
);
Expand Down
8 changes: 8 additions & 0 deletions src/QD3D/Renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,11 @@ void Render_AllocBackdrop(int width, int height)
width,
height,
GL_BGRA,
#if !(__BIG_ENDIAN__)
GL_UNSIGNED_INT_8_8_8_8,
#else
GL_UNSIGNED_INT_8_8_8_8_REV,
#endif
gBackdropPixels,
kRendererTextureFlags_ClampBoth
);
Expand Down Expand Up @@ -937,7 +941,11 @@ void Render_DrawBackdrop(bool keepBackdropAspectRatio)
damageRect.right - damageRect.left,
damageRect.bottom - damageRect.top,
GL_BGRA,
#if !(__BIG_ENDIAN__)
GL_UNSIGNED_INT_8_8_8_8,
#else
GL_UNSIGNED_INT_8_8_8_8_REV,
#endif
gBackdropPixels + (damageRect.top * gBackdropWidth + damageRect.left));
CHECK_GL_ERROR();

Expand Down
8 changes: 8 additions & 0 deletions src/Screens/Infobar.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,11 @@ static TQ3Point3D points[4] = { { -GPS_DISPLAY_SIZE, GPS_DISPLAY_SIZE, 0 },
GPS_MAP_TEXTURE_SIZE,
GPS_MAP_TEXTURE_SIZE,
GL_BGRA,
#if !(__BIG_ENDIAN__)
GL_UNSIGNED_INT_8_8_8_8,
#else
GL_UNSIGNED_INT_8_8_8_8_REV,
#endif
GetPixBaseAddr(GetGWorldPixMap(gGPSGWorld)),
kRendererTextureFlags_ClampBoth);
mesh->glTextureName = textureName;
Expand Down Expand Up @@ -776,7 +780,11 @@ Boolean forceUpdate = false;
GPS_MAP_TEXTURE_SIZE,
GPS_MAP_TEXTURE_SIZE,
GL_BGRA,
#if !(__BIG_ENDIAN__)
GL_UNSIGNED_INT_8_8_8_8,
#else
GL_UNSIGNED_INT_8_8_8_8_REV,
#endif
GetPixBaseAddr(GetGWorldPixMap(gGPSGWorld)));
CHECK_GL_ERROR();

Expand Down
16 changes: 14 additions & 2 deletions src/System/File.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ SkeletonFile_AnimHeader_Type *animHeaderPtr;
GAME_ASSERT(hand);
HLock(hand);
indexPtr = (UInt16 *) *hand;
#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(UInt16), skeleton->Bones[i].numPointsAttachedToBone, indexPtr);

#endif


/* COPY POINT INDEX ARRAY INTO BONE STRUCT */

Expand All @@ -221,8 +223,10 @@ SkeletonFile_AnimHeader_Type *animHeaderPtr;
GAME_ASSERT(hand);
HLock(hand);
indexPtr = (UInt16 *) *hand;
#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(UInt16), skeleton->Bones[i].numNormalsAttachedToBone, indexPtr);

#endif

/* COPY NORMAL INDEX ARRAY INTO BONE STRUCT */

for (int j = 0; j < skeleton->Bones[i].numNormalsAttachedToBone; j++)
Expand Down Expand Up @@ -563,7 +567,9 @@ long fileSize;
int numTexels = gNumTerrainTextureTiles * OREOMAP_TILE_SIZE * OREOMAP_TILE_SIZE;
GAME_ASSERT(numTexels*2 == fileSize-4);

#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(UInt16), numTexels, gTileDataPtr);
#endif
}


Expand Down Expand Up @@ -627,7 +633,9 @@ int dummy1,dummy2;

offset = *((SInt32 *)(gTerrainPtr+0)); // get offset to TEXTURE_LAYER
shortPtr = (UInt16 *)(gTerrainPtr + offset); // calc ptr to TEXTURE_LAYER
#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(UInt16), gTerrainTileDepth * gTerrainTileWidth, shortPtr);
#endif

for (int row = 0; row < gTerrainTileDepth; row++)
{
Expand All @@ -645,7 +653,9 @@ int dummy1,dummy2;
if (offset > 0)
{
shortPtr = (UInt16 *)(gTerrainPtr + offset); // calc ptr to HEIGHTMAP_LAYER
#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(UInt16), gTerrainTileDepth * gTerrainTileWidth, shortPtr);
#endif

for (int row = 0; row < gTerrainTileDepth; row++)
{
Expand All @@ -664,7 +674,9 @@ int dummy1,dummy2;
if (offset > 0)
{
shortPtr = (UInt16 *)(gTerrainPtr + offset); // calc ptr to PATH_LAYER
#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(UInt16), gTerrainTileDepth * gTerrainTileWidth, shortPtr);
#endif

for (int row = 0; row < gTerrainTileDepth; row++)
{
Expand Down
3 changes: 3 additions & 0 deletions src/System/TGA.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ OSErr ReadTGA(const FSSpec* spec, uint8_t** outPtr, TGAHeader* outHeader, bool f
return err;
}

// Byteswap little-endian header on big-endian systems
UnpackStructs("<8B4H2B", sizeof(TGAHeader), 1, &header);

// Make sure we support the format
switch (header.imageType)
{
Expand Down

0 comments on commit 0d997af

Please sign in to comment.