vtf: fix vtf loading for windows arm( and for other platforms )
This commit is contained in:
parent
3d0025b594
commit
7f267853f4
@ -455,7 +455,9 @@ bool GetVTFPreload360Data( const char *pDebugName, CUtlBuffer &fileBufferIn, CUt
|
||||
// compiler pads, the 360 compiler does NOT.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct VTFFileBaseHeader_t
|
||||
// nillerusr: try to avoid problems with pragma pack, remove c++ inheritance to make this structs platform-independent
|
||||
|
||||
struct alignas(16) VTFFileBaseHeader_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
@ -463,9 +465,13 @@ struct VTFFileBaseHeader_t
|
||||
int headerSize;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_1_t : public VTFFileBaseHeader_t
|
||||
struct alignas(16) VTFFileHeaderV7_1_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
int version[2]; // version[0].version[1]
|
||||
int headerSize;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
@ -484,13 +490,65 @@ struct VTFFileHeaderV7_1_t : public VTFFileBaseHeader_t
|
||||
unsigned char lowResImageHeight;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_2_t : public VTFFileHeaderV7_1_t
|
||||
struct alignas(16) VTFFileHeaderV7_2_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
int version[2]; // version[0].version[1]
|
||||
int headerSize;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
unsigned short numFrames;
|
||||
unsigned short startFrame;
|
||||
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad1[4];
|
||||
VectorAligned reflectivity;
|
||||
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char numMipLevels;
|
||||
ImageFormat lowResImageFormat;
|
||||
unsigned char lowResImageWidth;
|
||||
unsigned char lowResImageHeight;
|
||||
unsigned short depth;
|
||||
};
|
||||
|
||||
struct alignas(16) VTFFileHeaderV7_3_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char fileTypeString[4]; // "VTF" Valve texture file
|
||||
int version[2]; // version[0].version[1]
|
||||
int headerSize;
|
||||
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
unsigned short numFrames;
|
||||
unsigned short startFrame;
|
||||
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad1[4];
|
||||
VectorAligned reflectivity;
|
||||
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char numMipLevels;
|
||||
ImageFormat lowResImageFormat;
|
||||
unsigned char lowResImageWidth;
|
||||
unsigned char lowResImageHeight;
|
||||
unsigned short depth;
|
||||
|
||||
char pad4[3];
|
||||
unsigned int numResources;
|
||||
};
|
||||
|
||||
typedef VTFFileHeaderV7_3_t VTFFileHeader_t;
|
||||
|
||||
#define BYTE_POS( byteVal, shft ) uint32( uint32(uint8(byteVal)) << uint8(shft * 8) )
|
||||
#if !defined( _X360 )
|
||||
#define MK_VTF_RSRC_ID(a, b, c) uint32( BYTE_POS(a, 0) | BYTE_POS(b, 1) | BYTE_POS(c, 2) )
|
||||
@ -535,28 +593,6 @@ struct ResourceEntryInfo
|
||||
unsigned int resData; // Resource data or offset from the beginning of the file
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_3_t : public VTFFileHeaderV7_2_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char pad4[3];
|
||||
unsigned int numResources;
|
||||
|
||||
#if defined( _X360 ) || defined( POSIX )
|
||||
// must manually align in order to maintain pack(1) expected layout with existing binaries
|
||||
char pad5[8];
|
||||
#endif
|
||||
|
||||
// AFTER THE IMPLICIT PADDING CAUSED BY THE COMPILER....
|
||||
// *** followed by *** ResourceEntryInfo resources[0];
|
||||
// Array of resource entry infos sorted ascending by type
|
||||
};
|
||||
|
||||
struct VTFFileHeader_t : public VTFFileHeaderV7_3_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
};
|
||||
|
||||
#define VTF_X360_MAJOR_VERSION 0x0360
|
||||
#define VTF_X360_MINOR_VERSION 8
|
||||
struct VTFFileHeaderX360_t : public VTFFileBaseHeader_t
|
||||
|
55
vtf/vtf.cpp
55
vtf/vtf.cpp
@ -27,7 +27,10 @@ BEGIN_BYTESWAP_DATADESC( VTFFileBaseHeader_t )
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_1_t, VTFFileBaseHeader_t )
|
||||
BEGIN_BYTESWAP_DATADESC( VTFFileHeaderV7_1_t )
|
||||
DEFINE_ARRAY( fileTypeString, FIELD_CHARACTER, 4 ),
|
||||
DEFINE_ARRAY( version, FIELD_INTEGER, 2 ),
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
DEFINE_FIELD( height, FIELD_SHORT ),
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
@ -42,17 +45,45 @@ BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_1_t, VTFFileBaseHeader_t )
|
||||
DEFINE_FIELD( lowResImageHeight, FIELD_CHARACTER ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_2_t, VTFFileHeaderV7_1_t )
|
||||
BEGIN_BYTESWAP_DATADESC( VTFFileHeaderV7_2_t )
|
||||
DEFINE_ARRAY( fileTypeString, FIELD_CHARACTER, 4 ),
|
||||
DEFINE_ARRAY( version, FIELD_INTEGER, 2 ),
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
DEFINE_FIELD( height, FIELD_SHORT ),
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numFrames, FIELD_SHORT ),
|
||||
DEFINE_FIELD( startFrame, FIELD_SHORT ),
|
||||
DEFINE_FIELD( reflectivity, FIELD_VECTOR ),
|
||||
DEFINE_FIELD( bumpScale, FIELD_FLOAT ),
|
||||
DEFINE_FIELD( imageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numMipLevels, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( lowResImageWidth, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageHeight, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( depth, FIELD_SHORT ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderV7_3_t, VTFFileHeaderV7_2_t )
|
||||
BEGIN_BYTESWAP_DATADESC( VTFFileHeaderV7_3_t )
|
||||
DEFINE_ARRAY( fileTypeString, FIELD_CHARACTER, 4 ),
|
||||
DEFINE_ARRAY( version, FIELD_INTEGER, 2 ),
|
||||
DEFINE_FIELD( headerSize, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
DEFINE_FIELD( height, FIELD_SHORT ),
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numFrames, FIELD_SHORT ),
|
||||
DEFINE_FIELD( startFrame, FIELD_SHORT ),
|
||||
DEFINE_FIELD( reflectivity, FIELD_VECTOR ),
|
||||
DEFINE_FIELD( bumpScale, FIELD_FLOAT ),
|
||||
DEFINE_FIELD( imageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( numMipLevels, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageFormat, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( lowResImageWidth, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( lowResImageHeight, FIELD_CHARACTER ),
|
||||
DEFINE_FIELD( depth, FIELD_SHORT ),
|
||||
DEFINE_FIELD( numResources, FIELD_INTEGER ),
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeader_t, VTFFileHeaderV7_2_t )
|
||||
END_DATADESC()
|
||||
|
||||
BEGIN_BYTESWAP_DATADESC_( VTFFileHeaderX360_t, VTFFileBaseHeader_t )
|
||||
DEFINE_FIELD( flags, FIELD_INTEGER ),
|
||||
DEFINE_FIELD( width, FIELD_SHORT ),
|
||||
@ -903,23 +934,11 @@ static bool ReadHeaderFromBufferPastBaseHeader( CUtlBuffer &buf, VTFFileHeader_t
|
||||
else if ( header.version[1] == 2 )
|
||||
{
|
||||
buf.Get( pBuf, sizeof(VTFFileHeaderV7_2_t) - sizeof(VTFFileBaseHeader_t) );
|
||||
|
||||
#if defined( _X360 ) || defined (POSIX)
|
||||
// read 15 dummy bytes to be properly positioned with 7.2 PC data
|
||||
byte dummy[15];
|
||||
buf.Get( dummy, 15 );
|
||||
#endif
|
||||
}
|
||||
else if ( header.version[1] == 1 || header.version[1] == 0 )
|
||||
{
|
||||
// previous version 7.0 or 7.1
|
||||
buf.Get( pBuf, sizeof(VTFFileHeaderV7_1_t) - sizeof(VTFFileBaseHeader_t) );
|
||||
|
||||
#if defined( _X360 ) || defined (POSIX)
|
||||
// read a dummy byte to be properly positioned with 7.0/1 PC data
|
||||
byte dummy;
|
||||
buf.Get( &dummy, 1 );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user