23 Oct 2008
This commit is contained in:
parent
8746843635
commit
b993db4592
|
@ -35,4 +35,5 @@ launch\bsplib\
|
|||
launch\sprite\
|
||||
launch\studio\
|
||||
launch\viewer\
|
||||
launch\imagelib\
|
||||
launch\extragen\
|
||||
|
|
|
@ -129,7 +129,7 @@ static void LoadShaderImage( bsp_shader_t *si )
|
|||
Mem_Copy( si->pixels, pic->buffer, pic->size );
|
||||
FS_FreeImage( pic ); // release pic
|
||||
}
|
||||
else MsgDev( D_WARN, "%s have type %s\n", si->name, PFDesc[pic->type].name );
|
||||
else MsgDev( D_WARN, "%s have type %s\n", si->name, PFDesc( pic->type )->name );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,339 +6,6 @@
|
|||
#ifndef COM_ZLIB_H
|
||||
#define COM_ZLIB_H
|
||||
|
||||
// skyorder_q2[6] = { 2, 3, 1, 0, 4, 5, }; // Quake, Half-Life skybox ordering
|
||||
// skyorder_ms[6] = { 4, 5, 1, 0, 2, 3 }; // Microsoft DDS ordering (reverse)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IL_HINT_NO = 0,
|
||||
|
||||
// dds cubemap hints ( Microsoft sides order )
|
||||
IL_HINT_POSX,
|
||||
IL_HINT_NEGX,
|
||||
IL_HINT_POSZ,
|
||||
IL_HINT_NEGZ,
|
||||
IL_HINT_POSY,
|
||||
IL_HINT_NEGY,
|
||||
|
||||
// palette choosing
|
||||
IL_HINT_Q1,
|
||||
IL_HINT_Q2,
|
||||
IL_HINT_HL,
|
||||
} image_hint_t;
|
||||
|
||||
typedef struct loadformat_s
|
||||
{
|
||||
const char *formatstring;
|
||||
const char *ext;
|
||||
bool (*loadfunc)( const char *name, const byte *buffer, size_t filesize );
|
||||
image_hint_t hint;
|
||||
} loadformat_t;
|
||||
|
||||
typedef struct saveformat_s
|
||||
{
|
||||
const char *formatstring;
|
||||
const char *ext;
|
||||
bool (*savefunc)( const char *name, rgbdata_t *pix, int saveformat );
|
||||
} saveformat_t;
|
||||
|
||||
typedef struct imglib_s
|
||||
{
|
||||
const loadformat_t *loadformats;
|
||||
const saveformat_t *saveformats;
|
||||
|
||||
// current 2d image state
|
||||
int width;
|
||||
int height;
|
||||
byte num_layers; // num layers in
|
||||
byte num_mips; // build mipmaps
|
||||
uint type; // main type switcher
|
||||
uint flags; // additional image flags
|
||||
byte bits_count; // bits per RGBA
|
||||
size_t size; // image rgba size (for bounds checking)
|
||||
uint ptr; // safe image pointer
|
||||
byte *rgba; // image pointer (see image_type for details)
|
||||
|
||||
// current cubemap state
|
||||
int source_width; // locked cubemap dims (all wrong sides will be automatically resampled)
|
||||
int source_height;
|
||||
uint source_type; // shared image type for all mipmaps or cubemap sides
|
||||
int num_sides; // how much sides is loaded
|
||||
byte *cubemap; // cubemap pack
|
||||
|
||||
// indexed images state
|
||||
uint *d_currentpal; // installed version of internal palette
|
||||
int d_rendermode; // palette rendermode
|
||||
byte *palette; // palette pointer
|
||||
|
||||
// global parms
|
||||
int curwidth; // cubemap side, layer or mipmap width
|
||||
int curheight; // cubemap side, layer or mipmap height
|
||||
int curdepth; // current layer number
|
||||
int bpp; // PFDesc[type].bpp
|
||||
int bpc; // PFDesc[type].bpc
|
||||
int bps; // width * bpp * bpc
|
||||
int SizeOfPlane; // bps * height
|
||||
int SizeOfData; // SizeOfPlane * bps
|
||||
int SizeOfFile; // Image_DxtGetSize
|
||||
bool (*decompress)( uint, int, int, uint, uint, uint, const void* );
|
||||
|
||||
image_hint_t hint; // hint for some loaders
|
||||
byte *tempbuffer; // for convert operations
|
||||
int cmd_flags;
|
||||
} imglib_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.PCX image format (ZSoft Paintbrush)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
char bits_per_pixel;
|
||||
word xmin,ymin,xmax,ymax;
|
||||
word hres,vres;
|
||||
byte palette[48];
|
||||
char reserved;
|
||||
char color_planes;
|
||||
word bytes_per_line;
|
||||
word palette_type;
|
||||
char filler[58];
|
||||
} pcx_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.WAL image format (Wally textures)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct wal_s
|
||||
{
|
||||
char name[32];
|
||||
uint width, height;
|
||||
uint offsets[4]; // four mip maps stored
|
||||
char animname[32]; // next frame in animation chain
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
} wal_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.LMP image format (Quake1 gfx lumps)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct flat_s
|
||||
{
|
||||
short width;
|
||||
short height;
|
||||
short desc[2]; // probably not used
|
||||
} flat_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.BMP image format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char id[2]; //bmfh.bfType
|
||||
dword fileSize; //bmfh.bfSize
|
||||
dword reserved0; //bmfh.bfReserved1 + bmfh.bfReserved2
|
||||
dword bitmapDataOffset; //bmfh.bfOffBits
|
||||
dword bitmapHeaderSize; //bmih.biSize
|
||||
dword width; //bmih.biWidth
|
||||
dword height; //bmih.biHeight
|
||||
word planes; //bmih.biPlanes
|
||||
word bitsPerPixel; //bmih.biBitCount
|
||||
dword compression; //bmih.biCompression
|
||||
dword bitmapDataSize; //bmih.biSizeImage
|
||||
dword hRes; //bmih.biXPelsPerMeter
|
||||
dword vRes; //bmih.biYPelsPerMeter
|
||||
dword colors; //bmih.biClrUsed
|
||||
dword importantColors; //bmih.biClrImportant
|
||||
byte palette[256][4]; //RGBQUAD palette
|
||||
} bmp_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.TGA image format (Truevision Targa)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct tga_s
|
||||
{
|
||||
byte id_length;
|
||||
byte colormap_type;
|
||||
byte image_type;
|
||||
word colormap_index;
|
||||
word colormap_length;
|
||||
byte colormap_size;
|
||||
word x_origin;
|
||||
word y_origin;
|
||||
word width;
|
||||
word height;
|
||||
byte pixel_size;
|
||||
byte attributes;
|
||||
} tga_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.JPG image format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct huffman_table_s
|
||||
{
|
||||
// Huffman coding tables
|
||||
byte bits[16];
|
||||
byte hval[256];
|
||||
byte size[256];
|
||||
word code[256];
|
||||
} huffman_table_t;
|
||||
|
||||
typedef struct jpg_s
|
||||
{
|
||||
// not a real header
|
||||
file_t *file; // file
|
||||
byte *buffer; // jpg buffer
|
||||
|
||||
int width; // width image
|
||||
int height; // height image
|
||||
byte *data; // image
|
||||
int data_precision; // bit per component
|
||||
int num_components; // number component
|
||||
int restart_interval; // restart interval
|
||||
bool progressive_mode; // progressive format
|
||||
|
||||
struct
|
||||
{
|
||||
int id; // identifier
|
||||
int h; // horizontal sampling factor
|
||||
int v; // vertical sampling factor
|
||||
int t; // quantization table selector
|
||||
int td; // DC table selector
|
||||
int ta; // AC table selector
|
||||
} component_info[3]; // RGB (alpha not supported)
|
||||
|
||||
huffman_table_t hac[4]; // AC table
|
||||
huffman_table_t hdc[4]; // DC table
|
||||
|
||||
int qtable[4][64]; // quantization table
|
||||
|
||||
struct
|
||||
{
|
||||
int ss,se; // progressive jpeg spectral selection
|
||||
int ah,al; // progressive jpeg successive approx
|
||||
} scan;
|
||||
|
||||
int dc[3];
|
||||
int curbit;
|
||||
byte curbyte;
|
||||
|
||||
} jpg_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.DDS image format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
#define DDSHEADER ((' '<<24)+('S'<<16)+('D'<<8)+'D') // little-endian "DDS "
|
||||
|
||||
// various four-cc types
|
||||
#define TYPE_DXT1 (('1'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT1"
|
||||
#define TYPE_DXT2 (('2'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT2"
|
||||
#define TYPE_DXT3 (('3'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT3"
|
||||
#define TYPE_DXT4 (('4'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT4"
|
||||
#define TYPE_DXT5 (('5'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT5"
|
||||
|
||||
#define TYPE_ATI1 (('1'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI1"
|
||||
#define TYPE_ATI2 (('2'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI2"
|
||||
|
||||
#define TYPE_RXGB (('B'<<24)+('G'<<16)+('X'<<8)+'R') // little-endian "RXGB" doom3 normalmaps
|
||||
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
|
||||
#define TYPE_t (('\0'<<24)+('\0'<<16)+('\0'<<8)+'t') // little-endian "t"
|
||||
|
||||
#define DDS_CAPS 0x00000001L
|
||||
#define DDS_HEIGHT 0x00000002L
|
||||
#define DDS_WIDTH 0x00000004L
|
||||
|
||||
#define DDS_RGB 0x00000040L
|
||||
#define DDS_PIXELFORMAT 0x00001000L
|
||||
#define DDS_LUMINANCE 0x00020000L
|
||||
|
||||
#define DDS_ALPHAPIXELS 0x00000001L
|
||||
#define DDS_ALPHA 0x00000002L
|
||||
#define DDS_FOURCC 0x00000004L
|
||||
#define DDS_PITCH 0x00000008L
|
||||
#define DDS_COMPLEX 0x00000008L
|
||||
#define DDS_CUBEMAP 0x00000200L
|
||||
#define DDS_TEXTURE 0x00001000L
|
||||
#define DDS_MIPMAPCOUNT 0x00020000L
|
||||
#define DDS_LINEARSIZE 0x00080000L
|
||||
#define DDS_VOLUME 0x00200000L
|
||||
#define DDS_MIPMAP 0x00400000L
|
||||
#define DDS_DEPTH 0x00800000L
|
||||
|
||||
#define DDS_CUBEMAP_POSITIVEX 0x00000400L
|
||||
#define DDS_CUBEMAP_NEGATIVEX 0x00000800L
|
||||
#define DDS_CUBEMAP_POSITIVEY 0x00001000L
|
||||
#define DDS_CUBEMAP_NEGATIVEY 0x00002000L
|
||||
#define DDS_CUBEMAP_POSITIVEZ 0x00004000L
|
||||
#define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
|
||||
|
||||
typedef struct dds_pf_s
|
||||
{
|
||||
uint dwSize;
|
||||
uint dwFlags;
|
||||
uint dwFourCC;
|
||||
uint dwRGBBitCount;
|
||||
uint dwRBitMask;
|
||||
uint dwGBitMask;
|
||||
uint dwBBitMask;
|
||||
uint dwABitMask;
|
||||
} dds_pixf_t;
|
||||
|
||||
// DDCAPS2
|
||||
typedef struct dds_caps_s
|
||||
{
|
||||
uint dwCaps1;
|
||||
uint dwCaps2;
|
||||
uint dwCaps3;
|
||||
uint dwCaps4;
|
||||
} dds_caps_t;
|
||||
|
||||
typedef struct dds_s
|
||||
{
|
||||
uint dwIdent; // must matched with DDSHEADER
|
||||
uint dwSize;
|
||||
uint dwFlags; // determines what fields are valid
|
||||
uint dwHeight;
|
||||
uint dwWidth;
|
||||
uint dwLinearSize; // Formless late-allocated optimized surface size
|
||||
uint dwDepth; // depth if a volume texture
|
||||
uint dwMipMapCount; // number of mip-map levels requested
|
||||
uint dwAlphaBitDepth; // depth of alpha buffer requested
|
||||
uint dwReserved1[10]; // reserved for future expansions
|
||||
dds_pixf_t dsPixelFormat;
|
||||
dds_caps_t dsCaps;
|
||||
uint dwTextureStage;
|
||||
} dds_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
PAK FILES
|
||||
|
@ -353,7 +20,7 @@ The .pak files are just a linear collapse of a directory tree
|
|||
#define IDPK3CDRHEADER (('\2'<<24)+('\1'<<16)+('K'<<8)+'P') // little-endian "PK\1\2"
|
||||
#define IDPK3ENDHEADER (('\6'<<24)+('\5'<<16)+('K'<<8)+'P') // little-endian "PK\5\6"
|
||||
|
||||
#define MAX_FILES_IN_PACK 65536 // pack\pak2
|
||||
#define MAX_FILES_IN_PACK 65536 // pak\pk2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -496,76 +163,4 @@ extern int deflateReset (z_stream *strm);
|
|||
#define deflateInit(strm, level) deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) deflateInit2_((strm),(level),(method),(windowBits),(memLevel),(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
// imagelib definitions
|
||||
#define IMAGE_MAXWIDTH 4096
|
||||
#define IMAGE_MAXHEIGHT 4096
|
||||
#define LUMP_MAXWIDTH 1024 // WorldCraft limits
|
||||
#define LUMP_MAXHEIGHT 1024
|
||||
|
||||
#define TRANS_THRESHOLD 10 // in pixels
|
||||
enum
|
||||
{
|
||||
LUMP_NORMAL = 0,
|
||||
LUMP_TRANSPARENT,
|
||||
LUMP_DECAL,
|
||||
LUMP_QFONT
|
||||
};
|
||||
|
||||
extern imglib_t image;
|
||||
extern cvar_t *img_oldformats;
|
||||
extern cvar_t *fs_wadsupport;
|
||||
extern byte *fs_mempool;
|
||||
|
||||
void Image_RoundDimensions( int *scaled_width, int *scaled_height );
|
||||
byte *Image_ResampleInternal( const void *indata, int inwidth, int inheight, int outwidth, int outheight, int intype );
|
||||
byte *Image_FlipInternal( const byte *in, int *srcwidth, int *srcheight, int type, int flags );
|
||||
void Image_FreeImage( rgbdata_t *pack );
|
||||
void Image_Save( const char *filename, rgbdata_t *pix );
|
||||
rgbdata_t *Image_Load(const char *filename, const byte *buffer, size_t buffsize );
|
||||
bool Image_Copy8bitRGBA( const byte *in, byte *out, int pixels );
|
||||
bool FS_AddMipmapToPack( const byte *in, int width, int height );
|
||||
void Image_ConvertPalTo24bit( rgbdata_t *pic );
|
||||
void Image_GetPaletteLMP( const byte *pal, int rendermode );
|
||||
void Image_GetPalettePCX( const byte *pal );
|
||||
void Image_CopyPalette24bit( void );
|
||||
void Image_CopyPalette32bit( void );
|
||||
uint Image_ShortToFloat( word y );
|
||||
void Image_GetPaletteQ2( void );
|
||||
void Image_GetPaletteQ1( void );
|
||||
void Image_GetPaletteD1( void ); // doom 2 on TNT :)
|
||||
|
||||
|
||||
//
|
||||
// formats load
|
||||
//
|
||||
bool Image_LoadMIP( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadMDL( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadSPR( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadDDS( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadBMP( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadJPG( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadPNG( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadPCX( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadLMP( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadWAL( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadFLT( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadPAL( const char *name, const byte *buffer, size_t filesize );
|
||||
|
||||
//
|
||||
// formats save
|
||||
//
|
||||
bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SaveDDS( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SaveBMP( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SavePNG( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SavePCX( const char *name, rgbdata_t *pix, int saveformat );
|
||||
|
||||
//
|
||||
// img_utils.c
|
||||
//
|
||||
byte *Image_Copy( size_t size );
|
||||
bool Image_ValidSize( const char *name );
|
||||
bool Image_LumpValidSize( const char *name );
|
||||
|
||||
#endif//COM_ZLIB_H
|
|
@ -0,0 +1,530 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2008 ©
|
||||
// imagelib.h - engine image lib
|
||||
//=======================================================================
|
||||
#ifndef IMAGELIB_H
|
||||
#define IMAGELIB_H
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
// skyorder_q2[6] = { 2, 3, 1, 0, 4, 5, }; // Quake, Half-Life skybox ordering
|
||||
// skyorder_ms[6] = { 4, 5, 1, 0, 2, 3 }; // Microsoft DDS ordering (reverse)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IL_HINT_NO = 0,
|
||||
|
||||
// dds cubemap hints ( Microsoft sides order )
|
||||
IL_HINT_POSX,
|
||||
IL_HINT_NEGX,
|
||||
IL_HINT_POSZ,
|
||||
IL_HINT_NEGZ,
|
||||
IL_HINT_POSY,
|
||||
IL_HINT_NEGY,
|
||||
|
||||
// palette choosing
|
||||
IL_HINT_Q1,
|
||||
IL_HINT_Q2,
|
||||
IL_HINT_HL,
|
||||
} image_hint_t;
|
||||
|
||||
typedef struct loadformat_s
|
||||
{
|
||||
const char *formatstring;
|
||||
const char *ext;
|
||||
bool (*loadfunc)( const char *name, const byte *buffer, size_t filesize );
|
||||
image_hint_t hint;
|
||||
} loadformat_t;
|
||||
|
||||
typedef struct saveformat_s
|
||||
{
|
||||
const char *formatstring;
|
||||
const char *ext;
|
||||
bool (*savefunc)( const char *name, rgbdata_t *pix, int saveformat );
|
||||
} saveformat_t;
|
||||
|
||||
typedef struct imglib_s
|
||||
{
|
||||
const loadformat_t *loadformats;
|
||||
const saveformat_t *saveformats;
|
||||
|
||||
// current 2d image state
|
||||
int width;
|
||||
int height;
|
||||
byte num_layers; // num layers in
|
||||
byte num_mips; // build mipmaps
|
||||
uint type; // main type switcher
|
||||
uint flags; // additional image flags
|
||||
byte bits_count; // bits per RGBA
|
||||
size_t size; // image rgba size (for bounds checking)
|
||||
uint ptr; // safe image pointer
|
||||
byte *rgba; // image pointer (see image_type for details)
|
||||
|
||||
// current cubemap state
|
||||
int source_width; // locked cubemap dims (all wrong sides will be automatically resampled)
|
||||
int source_height;
|
||||
uint source_type; // shared image type for all mipmaps or cubemap sides
|
||||
int num_sides; // how much sides is loaded
|
||||
byte *cubemap; // cubemap pack
|
||||
|
||||
// indexed images state
|
||||
uint *d_currentpal; // installed version of internal palette
|
||||
int d_rendermode; // palette rendermode
|
||||
byte *palette; // palette pointer
|
||||
|
||||
// global parms
|
||||
int curwidth; // cubemap side, layer or mipmap width
|
||||
int curheight; // cubemap side, layer or mipmap height
|
||||
int curdepth; // current layer number
|
||||
int cur_mips; // number of mips
|
||||
int bpp; // PFDesc[type].bpp
|
||||
int bpc; // PFDesc[type].bpc
|
||||
int bps; // width * bpp * bpc
|
||||
int SizeOfPlane; // bps * height
|
||||
int SizeOfData; // SizeOfPlane * bps
|
||||
int SizeOfFile; // Image_DxtGetSize
|
||||
bool (*decompress)( uint, int, int, uint, uint, uint, const void* );
|
||||
|
||||
image_hint_t hint; // hint for some loaders
|
||||
byte *tempbuffer; // for convert operations
|
||||
int cmd_flags;
|
||||
} imglib_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.PCX image format (ZSoft Paintbrush)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
char bits_per_pixel;
|
||||
word xmin,ymin,xmax,ymax;
|
||||
word hres,vres;
|
||||
byte palette[48];
|
||||
char reserved;
|
||||
char color_planes;
|
||||
word bytes_per_line;
|
||||
word palette_type;
|
||||
char filler[58];
|
||||
} pcx_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.WAL image format (Wally textures)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct wal_s
|
||||
{
|
||||
char name[32];
|
||||
uint width, height;
|
||||
uint offsets[4]; // four mip maps stored
|
||||
char animname[32]; // next frame in animation chain
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
} wal_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.LMP image format (Quake1 gfx lumps)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct flat_s
|
||||
{
|
||||
short width;
|
||||
short height;
|
||||
short desc[2]; // probably not used
|
||||
} flat_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.BMP image format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char id[2]; //bmfh.bfType
|
||||
dword fileSize; //bmfh.bfSize
|
||||
dword reserved0; //bmfh.bfReserved1 + bmfh.bfReserved2
|
||||
dword bitmapDataOffset; //bmfh.bfOffBits
|
||||
dword bitmapHeaderSize; //bmih.biSize
|
||||
dword width; //bmih.biWidth
|
||||
dword height; //bmih.biHeight
|
||||
word planes; //bmih.biPlanes
|
||||
word bitsPerPixel; //bmih.biBitCount
|
||||
dword compression; //bmih.biCompression
|
||||
dword bitmapDataSize; //bmih.biSizeImage
|
||||
dword hRes; //bmih.biXPelsPerMeter
|
||||
dword vRes; //bmih.biYPelsPerMeter
|
||||
dword colors; //bmih.biClrUsed
|
||||
dword importantColors; //bmih.biClrImportant
|
||||
byte palette[256][4]; //RGBQUAD palette
|
||||
} bmp_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.TGA image format (Truevision Targa)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct tga_s
|
||||
{
|
||||
byte id_length;
|
||||
byte colormap_type;
|
||||
byte image_type;
|
||||
word colormap_index;
|
||||
word colormap_length;
|
||||
byte colormap_size;
|
||||
word x_origin;
|
||||
word y_origin;
|
||||
word width;
|
||||
word height;
|
||||
byte pixel_size;
|
||||
byte attributes;
|
||||
} tga_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.JPG image format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct huffman_table_s
|
||||
{
|
||||
// Huffman coding tables
|
||||
byte bits[16];
|
||||
byte hval[256];
|
||||
byte size[256];
|
||||
word code[256];
|
||||
} huffman_table_t;
|
||||
|
||||
typedef struct jpg_s
|
||||
{
|
||||
// not a real header
|
||||
file_t *file; // file
|
||||
byte *buffer; // jpg buffer
|
||||
|
||||
int width; // width image
|
||||
int height; // height image
|
||||
byte *data; // image
|
||||
int data_precision; // bit per component
|
||||
int num_components; // number component
|
||||
int restart_interval; // restart interval
|
||||
bool progressive_mode; // progressive format
|
||||
|
||||
struct
|
||||
{
|
||||
int id; // identifier
|
||||
int h; // horizontal sampling factor
|
||||
int v; // vertical sampling factor
|
||||
int t; // quantization table selector
|
||||
int td; // DC table selector
|
||||
int ta; // AC table selector
|
||||
} component_info[3]; // RGB (alpha not supported)
|
||||
|
||||
huffman_table_t hac[4]; // AC table
|
||||
huffman_table_t hdc[4]; // DC table
|
||||
|
||||
int qtable[4][64]; // quantization table
|
||||
|
||||
struct
|
||||
{
|
||||
int ss,se; // progressive jpeg spectral selection
|
||||
int ah,al; // progressive jpeg successive approx
|
||||
} scan;
|
||||
|
||||
int dc[3];
|
||||
int curbit;
|
||||
byte curbyte;
|
||||
|
||||
} jpg_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.DDS image format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
#define DDSHEADER ((' '<<24)+('S'<<16)+('D'<<8)+'D') // little-endian "DDS "
|
||||
|
||||
// various four-cc types
|
||||
#define TYPE_DXT1 (('1'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT1"
|
||||
#define TYPE_DXT2 (('2'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT2"
|
||||
#define TYPE_DXT3 (('3'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT3"
|
||||
#define TYPE_DXT4 (('4'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT4"
|
||||
#define TYPE_DXT5 (('5'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT5"
|
||||
|
||||
#define TYPE_ATI1 (('1'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI1"
|
||||
#define TYPE_ATI2 (('2'<<24)+('I'<<16)+('T'<<8)+'A') // little-endian "ATI2"
|
||||
|
||||
#define TYPE_RXGB (('B'<<24)+('G'<<16)+('X'<<8)+'R') // little-endian "RXGB" doom3 normalmaps
|
||||
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
|
||||
#define TYPE_t (('\0'<<24)+('\0'<<16)+('\0'<<8)+'t') // little-endian "t"
|
||||
|
||||
#define DDS_CAPS 0x00000001L
|
||||
#define DDS_HEIGHT 0x00000002L
|
||||
#define DDS_WIDTH 0x00000004L
|
||||
|
||||
#define DDS_RGB 0x00000040L
|
||||
#define DDS_PIXELFORMAT 0x00001000L
|
||||
#define DDS_LUMINANCE 0x00020000L
|
||||
|
||||
#define DDS_ALPHAPIXELS 0x00000001L
|
||||
#define DDS_ALPHA 0x00000002L
|
||||
#define DDS_FOURCC 0x00000004L
|
||||
#define DDS_PITCH 0x00000008L
|
||||
#define DDS_COMPLEX 0x00000008L
|
||||
#define DDS_CUBEMAP 0x00000200L
|
||||
#define DDS_TEXTURE 0x00001000L
|
||||
#define DDS_MIPMAPCOUNT 0x00020000L
|
||||
#define DDS_LINEARSIZE 0x00080000L
|
||||
#define DDS_VOLUME 0x00200000L
|
||||
#define DDS_MIPMAP 0x00400000L
|
||||
#define DDS_DEPTH 0x00800000L
|
||||
|
||||
#define DDS_CUBEMAP_POSITIVEX 0x00000400L
|
||||
#define DDS_CUBEMAP_NEGATIVEX 0x00000800L
|
||||
#define DDS_CUBEMAP_POSITIVEY 0x00001000L
|
||||
#define DDS_CUBEMAP_NEGATIVEY 0x00002000L
|
||||
#define DDS_CUBEMAP_POSITIVEZ 0x00004000L
|
||||
#define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
|
||||
|
||||
typedef struct dds_pf_s
|
||||
{
|
||||
uint dwSize;
|
||||
uint dwFlags;
|
||||
uint dwFourCC;
|
||||
uint dwRGBBitCount;
|
||||
uint dwRBitMask;
|
||||
uint dwGBitMask;
|
||||
uint dwBBitMask;
|
||||
uint dwABitMask;
|
||||
} dds_pixf_t;
|
||||
|
||||
// DDCAPS2
|
||||
typedef struct dds_caps_s
|
||||
{
|
||||
uint dwCaps1;
|
||||
uint dwCaps2;
|
||||
uint dwCaps3;
|
||||
uint dwCaps4;
|
||||
} dds_caps_t;
|
||||
|
||||
typedef struct dds_s
|
||||
{
|
||||
uint dwIdent; // must matched with DDSHEADER
|
||||
uint dwSize;
|
||||
uint dwFlags; // determines what fields are valid
|
||||
uint dwHeight;
|
||||
uint dwWidth;
|
||||
uint dwLinearSize; // Formless late-allocated optimized surface size
|
||||
uint dwDepth; // depth if a volume texture
|
||||
uint dwMipMapCount; // number of mip-map levels requested
|
||||
uint dwAlphaBitDepth; // depth of alpha buffer requested
|
||||
uint dwReserved1[10]; // reserved for future expansions
|
||||
dds_pixf_t dsPixelFormat;
|
||||
dds_caps_t dsCaps;
|
||||
uint dwTextureStage;
|
||||
} dds_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.VTF image format (Half-Life 2 dxt wrapper)
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
#define VTFHEADER (('\0'<<24)+('F'<<16)+('T'<<8)+'V')
|
||||
#define VTF_VERSION 7
|
||||
#define VTF_SUBVERSION1 1 // some old textures from beta
|
||||
#define VTF_SUBVERSION2 2 // current subversion
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VTF_UNKNOWN = -1, // image absent
|
||||
VTF_RGBA8888 = 0, // PF_RGBA_32
|
||||
VTF_ABGR8888, // unsupported
|
||||
VTF_RGB888, // PF_RGB_24
|
||||
VTF_BGR888, // unsupported
|
||||
VTF_RGB565, // unsupported
|
||||
VTF_I8, // PF_LUMINANCE
|
||||
VTF_IA88, // PF_LUMINANCE_ALPHA
|
||||
VTF_P8, // PF_INDEXED_24 ??
|
||||
VTF_A8, // unsupported
|
||||
VTF_RGB888_BLUESCREEN, // PF_RGB_24 - just fill alpha pixels with (0 0 255) color
|
||||
VTF_BGR888_BLUESCREEN, // unsupported
|
||||
VTF_ARGB8888, // PF_ARGB_32
|
||||
VTF_BGRA8888, // unsupported
|
||||
VTF_DXT1, // PF_DXT1
|
||||
VTF_DXT3, // PF_DXT3
|
||||
VTF_DXT5, // PF_DXT5
|
||||
VTF_BGRX8888, // unsupported
|
||||
VTF_BGR565, // unsupported
|
||||
VTF_BGRX5551, // unsupported
|
||||
VTF_BGRA4444, // unsupported
|
||||
VTF_DXT1_ONEBITALPHA, // PF_DXT1 - loader automatically detected alpha bits
|
||||
VTF_BGRA5551, // unsupported
|
||||
VTF_UV88, // unsupported
|
||||
VTF_UVWQ8888, // unsupported
|
||||
VTF_RGBA16161616F, // PF_ABGR_64_F ??
|
||||
VTF_RGBA16161616, // unsupported
|
||||
VTF_UVLX8888, // unsupported
|
||||
VTF_TOTALCOUNT
|
||||
} vtf_format_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// flags from the *.txt config file
|
||||
VF_POINTSAMPLE = BIT(0),
|
||||
VF_TRILINEAR = BIT(1),
|
||||
VF_CLAMPS = BIT(2),
|
||||
VF_CLAMPT = BIT(3),
|
||||
VF_ANISOTROPIC = BIT(4),
|
||||
VF_HINT_DXT5 = BIT(5),
|
||||
VF_NOCOMPRESS = BIT(6),
|
||||
VF_NORMAL = BIT(7),
|
||||
VF_NOMIP = BIT(8),
|
||||
VF_NOLOD = BIT(9),
|
||||
VF_MINMIP = BIT(10),
|
||||
VF_PROCEDURAL = BIT(11),
|
||||
|
||||
// these are automatically generated by vtex from the texture data.
|
||||
VF_ONEBITALPHA = BIT(12),
|
||||
VF_EIGHTBITALPHA = BIT(13),
|
||||
|
||||
// newer flags from the *.txt config file
|
||||
VF_ENVMAP = BIT(14),
|
||||
VF_RENDERTARGET = BIT(15),
|
||||
VF_DEPTHRENDERTARGET= BIT(16),
|
||||
VF_NODEBUGOVERRIDE = BIT(17),
|
||||
VF_SINGLECOPY = BIT(18),
|
||||
VF_ONEALPHAMIP = BIT(19),
|
||||
VF_PREMULTCOLOR = BIT(20),
|
||||
VF_NORMALTODUDV = BIT(21),
|
||||
VF_ALPHATESTMIPGEN = BIT(22),
|
||||
VF_NODEPTHBUFFER = BIT(23),
|
||||
VF_NICEFILTERED = BIT(24),
|
||||
VF_LASTFLAG = BIT(24),
|
||||
} vtf_flags_t;
|
||||
|
||||
// dirty Valve tricks with compiler features...
|
||||
#pragma pack( 1 )
|
||||
__declspec(align( 16 )) typedef struct vtf_s
|
||||
{
|
||||
int ident; // must matched with VTFHEADER
|
||||
int ver_major; // current version is 7
|
||||
int ver_minor; // 1 or 2
|
||||
int hdr_size; // ver 7.1 == 64 bytes, ver 7.2 == 80 bytes
|
||||
word width; // maxwidth 2048
|
||||
word height; // maxheight 2048
|
||||
uint flags; // misc image flags
|
||||
int num_frames; // sprite frames
|
||||
int start_frame; // ???
|
||||
vec4_t reflectivity; // vrad precomputed texcolor
|
||||
float bumpScale; // ovverided from vmt file
|
||||
vtf_format_t imageFormat; // see vtf_format_t for details
|
||||
byte numMipLevels; // never reached 255 mipLevels
|
||||
|
||||
// probably it's used for WorldCraft texture explorer
|
||||
vtf_format_t lowResImageFormat;
|
||||
byte lowResImageWidth; // maxWidth = 256
|
||||
byte lowResImageHeight; // maxHeight = 256
|
||||
|
||||
// 20 additonal bytes for subversion 2 probably used for HDR settings
|
||||
int unknown[4];
|
||||
} vtf_t;
|
||||
#pragma pack()
|
||||
|
||||
// imagelib definitions
|
||||
#define IMAGE_MAXWIDTH 4096
|
||||
#define IMAGE_MAXHEIGHT 4096
|
||||
#define LUMP_MAXWIDTH 1024 // WorldCraft limits
|
||||
#define LUMP_MAXHEIGHT 1024
|
||||
|
||||
#define TRANS_THRESHOLD 10 // in pixels
|
||||
enum
|
||||
{
|
||||
LUMP_NORMAL = 0,
|
||||
LUMP_TRANSPARENT,
|
||||
LUMP_DECAL,
|
||||
LUMP_QFONT
|
||||
};
|
||||
|
||||
extern imglib_t image;
|
||||
extern cvar_t *img_oldformats;
|
||||
extern cvar_t *fs_wadsupport;
|
||||
extern byte *fs_mempool;
|
||||
extern const bpc_desc_t PFDesc[];
|
||||
|
||||
void Image_RoundDimensions( int *scaled_width, int *scaled_height );
|
||||
byte *Image_ResampleInternal( const void *indata, int inwidth, int inheight, int outwidth, int outheight, int intype );
|
||||
byte *Image_FlipInternal( const byte *in, int *srcwidth, int *srcheight, int type, int flags );
|
||||
void Image_FreeImage( rgbdata_t *pack );
|
||||
void Image_Save( const char *filename, rgbdata_t *pix );
|
||||
size_t Image_DXTGetLinearSize( int type, int width, int height, int depth, int rgbcount );
|
||||
rgbdata_t *Image_Load(const char *filename, const byte *buffer, size_t buffsize );
|
||||
bool Image_Copy8bitRGBA( const byte *in, byte *out, int pixels );
|
||||
bool FS_AddMipmapToPack( const byte *in, int width, int height );
|
||||
void Image_SetPixelFormat( int width, int height, int depth );
|
||||
void Image_ConvertPalTo24bit( rgbdata_t *pic );
|
||||
void Image_DecompressDDS( const byte *buffer, uint target );
|
||||
void Image_GetPaletteLMP( const byte *pal, int rendermode );
|
||||
void Image_GetPalettePCX( const byte *pal );
|
||||
void Image_CopyPalette24bit( void );
|
||||
void Image_CopyPalette32bit( void );
|
||||
uint Image_ShortToFloat( word y );
|
||||
void Image_GetPaletteQ2( void );
|
||||
void Image_GetPaletteQ1( void );
|
||||
void Image_GetPaletteD1( void ); // doom 2 on TNT :)
|
||||
|
||||
|
||||
//
|
||||
// formats load
|
||||
//
|
||||
bool Image_LoadMIP( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadMDL( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadSPR( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadDDS( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadBMP( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadJPG( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadVTF( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadPNG( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadPCX( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadLMP( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadWAL( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadFLT( const char *name, const byte *buffer, size_t filesize );
|
||||
bool Image_LoadPAL( const char *name, const byte *buffer, size_t filesize );
|
||||
|
||||
//
|
||||
// formats save
|
||||
//
|
||||
bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SaveDDS( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SaveBMP( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SavePNG( const char *name, rgbdata_t *pix, int saveformat );
|
||||
bool Image_SavePCX( const char *name, rgbdata_t *pix, int saveformat );
|
||||
|
||||
//
|
||||
// img_utils.c
|
||||
//
|
||||
byte *Image_Copy( size_t size );
|
||||
bool Image_ValidSize( const char *name );
|
||||
bool Image_LumpValidSize( const char *name );
|
||||
|
||||
#endif//IMAGELIB_H
|
|
@ -3,9 +3,7 @@
|
|||
// img_bmp.c - bmp format load & save
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
|
||||
/*
|
||||
=============
|
|
@ -3,10 +3,8 @@
|
|||
// img_dds.c - dds format load & save
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "imagelib.h"
|
||||
#include "mathlib.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
// TODO: tune this ?
|
||||
#define REDWEIGHT 4
|
||||
|
@ -1506,6 +1504,7 @@ bool Image_DecompressDXT( uint target, int level, int intformat, uint width, uin
|
|||
|
||||
w = width;
|
||||
h = height;
|
||||
|
||||
size = width * height * image.curdepth * 4;
|
||||
fout = Mem_Realloc( Sys.imagepool, image.tempbuffer, size );
|
||||
|
||||
|
@ -1975,6 +1974,7 @@ bool Image_DecompressRGBA( uint target, int level, int intformat, uint width, ui
|
|||
{
|
||||
byte *fin, *fout;
|
||||
int i, size;
|
||||
color16 *col;
|
||||
|
||||
if( !data ) return false;
|
||||
fin = (byte *)data;
|
||||
|
@ -1984,6 +1984,15 @@ bool Image_DecompressRGBA( uint target, int level, int intformat, uint width, ui
|
|||
|
||||
switch( PFDesc[intformat].format )
|
||||
{
|
||||
case PF_RGB_16:
|
||||
for( i = 0, col = (color16 *)fin; i < width * height; i++, col += sizeof( color16 ))
|
||||
{
|
||||
fout[(i<<2)+0] = col->r;
|
||||
fout[(i<<2)+1] = col->g;
|
||||
fout[(i<<2)+2] = col->b;
|
||||
fout[(i<<2)+3] = 255;
|
||||
}
|
||||
break;
|
||||
case PF_RGB_24:
|
||||
for (i = 0; i < width * height; i++ )
|
||||
{
|
||||
|
@ -1993,9 +2002,19 @@ bool Image_DecompressRGBA( uint target, int level, int intformat, uint width, ui
|
|||
fout[(i<<2)+3] = 255;
|
||||
}
|
||||
break;
|
||||
case PF_BGR_24:
|
||||
for (i = 0; i < width * height; i++ )
|
||||
{
|
||||
fout[(i<<2)+0] = fin[i+2];
|
||||
fout[(i<<2)+1] = fin[i+1];
|
||||
fout[(i<<2)+2] = fin[i+0];
|
||||
fout[(i<<2)+3] = 255;
|
||||
}
|
||||
break;
|
||||
case PF_RGBA_32:
|
||||
Mem_Copy( fout, fin, size );
|
||||
break;
|
||||
case PF_BGRA_32:
|
||||
case PF_ABGR_64:
|
||||
for( i = 0; i < width * height; i++ )
|
||||
{
|
||||
|
@ -2026,6 +2045,7 @@ void Image_DecompressDDS( const byte *buffer, uint target )
|
|||
{
|
||||
case PF_RGB_24:
|
||||
case PF_RGBA_32:
|
||||
case PF_BGRA_32:
|
||||
case PF_ABGR_64: image.decompress = Image_DecompressRGBA; break;
|
||||
case PF_LUMINANCE:
|
||||
case PF_LUMINANCE_16:
|
||||
|
@ -2048,7 +2068,7 @@ void Image_DecompressDDS( const byte *buffer, uint target )
|
|||
case PF_UNKNOWN: break;
|
||||
}
|
||||
|
||||
for( i = 0; i < image.num_mips; i++, buffer += size )
|
||||
for( i = 0; i < image.cur_mips; i++, buffer += size )
|
||||
{
|
||||
Image_SetPixelFormat( w, h, d );
|
||||
size = image.SizeOfFile;
|
||||
|
@ -2076,6 +2096,15 @@ bool Image_ForceDecompress( void )
|
|||
// extract cubemap side from complex image
|
||||
if( image.hint != IL_HINT_NO )
|
||||
return true;
|
||||
|
||||
// FIXME: load it properly with gl loader
|
||||
switch( image.type )
|
||||
{
|
||||
case PF_RXGB: return true; // g-cont. test it with GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ?
|
||||
case PF_ATI1N: return true; // hey, how called your OpenGL extension, ATI ?
|
||||
case PF_ATI2N: return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2141,6 +2170,9 @@ bool Image_LoadDDS( const char *name, const byte *buffer, size_t filesize )
|
|||
if( image.flags & IMAGE_CUBEMAP ) numsides = 6;
|
||||
Image_SetPixelFormat( image.width, image.height, image.num_layers ); // setup
|
||||
image.size = image.ptr = 0;
|
||||
if( image.cmd_flags & IL_IGNORE_MIPS )
|
||||
image.cur_mips = 1;
|
||||
else image.cur_mips = image.num_mips;
|
||||
image.num_mips = 1;
|
||||
|
||||
for( i = 0, offset = 0; i < numsides; i++, buf += offset )
|
|
@ -3,9 +3,7 @@
|
|||
// img_jpg.c - jpg format load & save
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
|
||||
jpg_t jpg_file; // jpeg read struct
|
||||
|
|
@ -3,9 +3,7 @@
|
|||
// img_load.c - load various image formats
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
// global image variables
|
||||
|
@ -62,6 +60,45 @@ static const cubepack_t load_cubemap[] =
|
|||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
// soul of ImageLib - table of image format constants
|
||||
const bpc_desc_t PFDesc[] =
|
||||
{
|
||||
{PF_UNKNOWN, "raw", 0x1908, 0x1401, 0, 0, 0 },
|
||||
{PF_INDEXED_24, "pal 24", 0x1908, 0x1401, 1, 1, 0 }, // expand data to RGBA buffer
|
||||
{PF_INDEXED_32, "pal 32", 0x1908, 0x1401, 1, 1, 0 },
|
||||
{PF_RGBA_32, "RGBA 32",0x1908, 0x1401, 4, 1, -4 },
|
||||
{PF_BGRA_32, "BGRA 32",0x80E1, 0x1401, 4, 1, -4 },
|
||||
{PF_ARGB_32, "ARGB 32",0x1908, 0x1401, 4, 1, -4 },
|
||||
{PF_ABGR_64, "ABGR 64",0x80E1, 0x1401, 4, 2, -8 },
|
||||
{PF_RGB_24, "RGB 24", 0x1908, 0x1401, 3, 1, -3 },
|
||||
{PF_BGR_24, "BGR 24", 0x80E0, 0x1401, 3, 1, -3 },
|
||||
{PF_RGB_16, "RGB 16", 0x8054, 0x8364, 3, 2, 16 }, // FIXME: do revision
|
||||
{PF_DXT1, "DXT1", 0x1908, 0x1401, 4, 1, 8 },
|
||||
{PF_DXT2, "DXT2", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_DXT3, "DXT3", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_DXT4, "DXT4", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_DXT5, "DXT5", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_RXGB, "RXGB", 0x1908, 0x1401, 3, 1, 16 },
|
||||
{PF_ATI1N, "ATI1N", 0x1908, 0x1401, 1, 1, 8 },
|
||||
{PF_ATI2N, "3DC", 0x1908, 0x1401, 3, 1, 16 },
|
||||
{PF_LUMINANCE, "LUM 8", 0x1909, 0x1401, 1, 1, -1 },
|
||||
{PF_LUMINANCE_16, "LUM 16", 0x1909, 0x1401, 2, 2, -2 },
|
||||
{PF_LUMINANCE_ALPHA,"LUM A", 0x190A, 0x1401, 2, 1, -2 },
|
||||
{PF_R_16F, "R 16f", 0x8884, 0x1406, 1, 4, -2 }, // FIXME: these NV extension, reinstall for ATI
|
||||
{PF_R_32F, "R 32f", 0x8885, 0x1406, 1, 4, -4 },
|
||||
{PF_GR_32F, "GR 32f", 0x8886, 0x1406, 2, 4, -4 },
|
||||
{PF_GR_64F, "GR 64f", 0x8887, 0x1406, 2, 4, -8 },
|
||||
{PF_ABGR_64F, "ABGR64f",0x888A, 0x1406, 4, 2, -8 },
|
||||
{PF_ABGR_128F, "ABGR128",0x888B, 0x1406, 4, 4, -16},
|
||||
{PF_RGBA_GN, "system", 0x1908, 0x1401, 4, 1, -4 },
|
||||
};
|
||||
|
||||
bpc_desc_t *Image_GetPixelFormat( pixformat_t type )
|
||||
{
|
||||
type = bound( PF_UNKNOWN, type, PF_TOTALCOUNT - 1 );
|
||||
return (bpc_desc_t *)&PFDesc[type];
|
||||
}
|
||||
|
||||
void Image_Reset( void )
|
||||
{
|
||||
// reset global variables
|
||||
|
@ -200,7 +237,7 @@ loading and unpack to rgba any known image
|
|||
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
|
||||
{
|
||||
const char *ext = FS_FileExtension( filename );
|
||||
string path, loadname, texname, sidename;
|
||||
string path, loadname, sidename;
|
||||
bool anyformat = !com_stricmp( ext, "" ) ? true : false;
|
||||
bool dds_installed = false; // current loadformats list supported dds
|
||||
int i, filesize = 0;
|
||||
|
@ -212,13 +249,12 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
|
|||
if( !buffer || !buffsize ) buffer = (char *)florr1_2_jpg, buffsize = sizeof(florr1_2_jpg);
|
||||
#endif
|
||||
Image_Reset(); // clear old image
|
||||
com.strncpy( loadname, filename, sizeof( loadname ));
|
||||
FS_StripExtension( loadname ); // remove extension if needed
|
||||
|
||||
// HACKHACK: skip any checks, load file from buffer
|
||||
if( filename[0] == '#' && buffer && size ) goto load_internal;
|
||||
|
||||
com.strncpy( loadname, filename, sizeof( loadname ));
|
||||
FS_StripExtension( loadname ); // remove extension if needed
|
||||
|
||||
// developer warning
|
||||
if( !anyformat ) MsgDev( D_NOTE, "Note: %s will be loading only with ext .%s\n", loadname, ext );
|
||||
|
||||
|
@ -231,11 +267,9 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
|
|||
com_sprintf( path, format->formatstring, loadname, "", format->ext );
|
||||
image.hint = format->hint;
|
||||
f = FS_LoadFile( path, &filesize );
|
||||
if(f && filesize > 0)
|
||||
if( f && filesize > 0 )
|
||||
{
|
||||
// this name will be used only for tell user about problems
|
||||
FS_FileBase( path, texname );
|
||||
if( format->loadfunc( texname, f, filesize ))
|
||||
if( format->loadfunc( path, f, filesize ))
|
||||
{
|
||||
Mem_Free(f); // release buffer
|
||||
return ImagePack(); // loaded
|
||||
|
@ -265,8 +299,7 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
|
|||
if( f && filesize > 0 )
|
||||
{
|
||||
// this name will be used only for tell user about problems
|
||||
FS_FileBase( path, texname );
|
||||
if( Image_LoadDDS( texname, f, filesize ))
|
||||
if( Image_LoadDDS( path, f, filesize ))
|
||||
{
|
||||
Mem_Free(f); // release buffer
|
||||
return ImagePack(); // loaded
|
||||
|
@ -299,8 +332,7 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
|
|||
if( f && filesize > 0 )
|
||||
{
|
||||
// this name will be used only for tell user about problems
|
||||
FS_FileBase( path, texname );
|
||||
if( format->loadfunc( texname, f, filesize ))
|
||||
if( format->loadfunc( path, f, filesize ))
|
||||
{
|
||||
com_snprintf( sidename, MAX_STRING, "%s%s.%s", loadname, cmap->type[i].suf, format->ext );
|
||||
if( FS_AddSideToPack( sidename, cmap->type[i].flags )) // process flags to flip some sides
|
||||
|
@ -336,9 +368,6 @@ rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size )
|
|||
}
|
||||
|
||||
load_internal:
|
||||
// last chanse: try to load image from internal buffer
|
||||
com.strncpy( texname, filename, sizeof( texname ));
|
||||
|
||||
for( format = image.loadformats; format && format->formatstring; format++ )
|
||||
{
|
||||
if( anyformat || !com_stricmp( ext, format->ext ))
|
||||
|
@ -346,9 +375,7 @@ load_internal:
|
|||
image.hint = format->hint;
|
||||
if( buffer && size > 0 )
|
||||
{
|
||||
// this name will be used only for tell user about problems
|
||||
FS_FileBase( texname, texname );
|
||||
if( format->loadfunc( texname, buffer, size ))
|
||||
if( format->loadfunc( loadname, buffer, size ))
|
||||
return ImagePack(); // loaded
|
||||
}
|
||||
}
|
||||
|
@ -357,7 +384,7 @@ load_internal:
|
|||
if( !image.loadformats || image.loadformats->ext == NULL )
|
||||
MsgDev( D_NOTE, "FS_LoadImage: imagelib offline\n" );
|
||||
else if(!com_stristr( filename, "#internal" ))
|
||||
MsgDev( D_WARN, "FS_LoadImage: couldn't load \"%s\"\n", texname );
|
||||
MsgDev( D_WARN, "FS_LoadImage: couldn't load \"%s\"\n", loadname );
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -3,9 +3,7 @@
|
|||
// img_pcx.c - pcx format load & save
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
|
||||
/*
|
||||
=============
|
|
@ -4,9 +4,7 @@
|
|||
//=======================================================================
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
|
||||
#define PNG_LIBPNG_VER_STRING "1.2.4"
|
||||
#define PNG_COLOR_MASK_PALETTE 1
|
|
@ -3,9 +3,7 @@
|
|||
// img_tga.c - tga format load & save
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
|
||||
/*
|
||||
=============
|
|
@ -3,9 +3,7 @@
|
|||
// img_utils.c - image common tools
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
cvar_t *image_profile;
|
||||
|
@ -182,7 +180,8 @@ static const loadformat_t load_hl1[] =
|
|||
// version7 - using only Half-Life 2 images
|
||||
static const loadformat_t load_hl2[] =
|
||||
{
|
||||
// FIXME: implement
|
||||
{ "materials/%s%s.%s", "vtf", Image_LoadVTF, IL_HINT_NO }, // hl2 dds wrapper
|
||||
{ "%s%s.%s", "vtf", Image_LoadVTF, IL_HINT_NO },
|
||||
{ NULL, NULL, NULL, IL_HINT_NO }
|
||||
};
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2008 ©
|
||||
// img_vtf.c - vtf format load & save
|
||||
//=======================================================================
|
||||
|
||||
#include "imagelib.h"
|
||||
|
||||
pixformat_t Image_VTFFormat( vtf_format_t srcFormat )
|
||||
{
|
||||
switch( srcFormat )
|
||||
{
|
||||
case VTF_UNKNOWN:
|
||||
return VTF_UNKNOWN;
|
||||
case VTF_RGBA8888:
|
||||
return PF_RGBA_32;
|
||||
case VTF_RGB888:
|
||||
return PF_RGB_24;
|
||||
case VTF_BGR888:
|
||||
return PF_BGR_24;
|
||||
case VTF_RGB565:
|
||||
return PF_RGB_16;
|
||||
case VTF_I8:
|
||||
return PF_LUMINANCE;
|
||||
case VTF_IA88:
|
||||
return PF_LUMINANCE_ALPHA;
|
||||
case VTF_P8:
|
||||
return PF_INDEXED_24;
|
||||
case VTF_ARGB8888:
|
||||
return PF_ARGB_32;
|
||||
case VTF_DXT1:
|
||||
case VTF_DXT1_ONEBITALPHA:
|
||||
return PF_DXT1;
|
||||
case VTF_DXT3:
|
||||
return PF_DXT3;
|
||||
case VTF_DXT5:
|
||||
return PF_DXT5;
|
||||
case VTF_BGRA8888:
|
||||
return PF_BGRA_32;
|
||||
case VTF_RGBA16161616F:
|
||||
return PF_ABGR_64F;
|
||||
default: return PF_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
size_t Image_VTFCalcImageSize( vtf_t *hdr, int numFrames )
|
||||
{
|
||||
size_t mipsize;
|
||||
int numSides = 1;
|
||||
|
||||
if( image.flags & IMAGE_CUBEMAP ) numSides = 6;
|
||||
mipsize = Image_DXTGetLinearSize( image.type, hdr->width, hdr->height, 1, 0 );
|
||||
return mipsize * numFrames * numSides;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
Image_VTFCalcMipmapSize
|
||||
|
||||
stupid idea - last miplevel (1x1) put at begin of buffer
|
||||
or DX8 format requries it, i'm don't know...
|
||||
================
|
||||
*/
|
||||
size_t Image_VTFCalcMipmapSize( vtf_t *hdr, int startMip, int numFrames )
|
||||
{
|
||||
size_t buffsize = 0;
|
||||
int numSides = 1;
|
||||
int w, h, i, mipsize = 0;
|
||||
|
||||
if( image.flags & IMAGE_CUBEMAP ) numSides = 6;
|
||||
|
||||
// now correct buffer size
|
||||
for( i = image.num_mips - 1; i > startMip; --i )
|
||||
{
|
||||
w = max( 1, (hdr->width)>>i);
|
||||
h = max( 1, (hdr->height)>>i);
|
||||
mipsize = Image_DXTGetLinearSize( image.type, w, h, 1, 0 );
|
||||
buffsize += mipsize * numFrames * numSides;
|
||||
}
|
||||
return buffsize;
|
||||
}
|
||||
|
||||
size_t Image_VTFCalcLowResSize( vtf_t *hdr )
|
||||
{
|
||||
size_t buffsize = 0;
|
||||
int w, h, format;
|
||||
|
||||
format = Image_VTFFormat( LittleLong( hdr->lowResImageFormat ));
|
||||
|
||||
// missing lowRes image for -1 value
|
||||
if( format != VTF_UNKNOWN )
|
||||
{
|
||||
w = hdr->lowResImageWidth;
|
||||
h = hdr->lowResImageHeight;
|
||||
buffsize = Image_DXTGetLinearSize( format, w, h, 1, 0 );
|
||||
}
|
||||
return buffsize;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
Image_LoadVTF
|
||||
=============
|
||||
*/
|
||||
bool Image_LoadVTF( const char *name, const byte *buffer, size_t filesize )
|
||||
{
|
||||
vtf_t vtf;
|
||||
byte *fin;
|
||||
string shortname;
|
||||
int i, flags, numFrames, vtfFormat;
|
||||
uint hdrSize, resSize, mipSize, lowResSize;
|
||||
|
||||
fin = (byte *)buffer;
|
||||
Mem_Copy( &vtf, fin, sizeof( vtf ));
|
||||
hdrSize = LittleLong( vtf.hdr_size );
|
||||
|
||||
if( LittleLong( vtf.ident ) != VTFHEADER ) return false; // it's not a dds file, just skip it
|
||||
FS_FileBase( name, shortname );
|
||||
|
||||
// bounds check
|
||||
i = LittleLong( vtf.ver_major );
|
||||
if( i != VTF_VERSION )
|
||||
{
|
||||
MsgDev( D_ERROR, "Image_LoadVTF: %s has wrong ver (%i should be %i)\n", shortname, i, VTF_VERSION );
|
||||
return false;
|
||||
}
|
||||
|
||||
i = LittleLong( vtf.ver_minor );
|
||||
if( i == VTF_SUBVERSION1 && vtf.hdr_size == 64 )
|
||||
MsgDev( D_NOTE, "Image_LoadVTF: ver 7.1 without HDR\n" );
|
||||
else if( i == VTF_SUBVERSION2 && vtf.hdr_size == sizeof( vtf_t ))
|
||||
MsgDev( D_NOTE, "Image_LoadVTF: ver 7.2 with HDR\n" );
|
||||
else
|
||||
{
|
||||
MsgDev( D_ERROR, "Image_LoadVTF: file (%s) has wrong subversion %i\n", shortname, i );
|
||||
return false;
|
||||
}
|
||||
|
||||
image.width = LittleShort( vtf.width );
|
||||
image.height = LittleShort( vtf.height );
|
||||
if(!Image_ValidSize( name )) return false;
|
||||
|
||||
// translate VF_flags into IMAGE_flags
|
||||
flags = LittleLong( vtf.flags );
|
||||
if((flags & VF_ONEBITALPHA) || (flags & VF_EIGHTBITALPHA))
|
||||
image.flags |= IMAGE_HAVE_ALPHA;
|
||||
if( flags & VF_ENVMAP ) image.flags |= IMAGE_CUBEMAP;
|
||||
|
||||
vtfFormat = LittleLong( vtf.imageFormat );
|
||||
numFrames = LittleLong( vtf.num_frames );
|
||||
image.type = Image_VTFFormat( vtfFormat );
|
||||
image.num_mips = LittleLong( vtf.numMipLevels );
|
||||
|
||||
lowResSize = Image_VTFCalcLowResSize( &vtf );
|
||||
resSize = Image_VTFCalcImageSize( &vtf, numFrames );
|
||||
mipSize = Image_VTFCalcMipmapSize( &vtf, 0, numFrames );
|
||||
image.size = hdrSize + lowResSize + mipSize + resSize;
|
||||
fin += hdrSize + lowResSize + mipSize;
|
||||
image.num_layers = 1;
|
||||
|
||||
if( image.type == PF_UNKNOWN )
|
||||
{
|
||||
MsgDev( D_ERROR, "Image_LoadVTF: file (%s) has unknown format %i\n", shortname, vtfFormat );
|
||||
return false;
|
||||
}
|
||||
else if( image.size == filesize )
|
||||
{
|
||||
int offset, numsides = 1;
|
||||
uint target = 1;
|
||||
byte *buf = fin;
|
||||
|
||||
// if hardware loader is absent or image not power of two
|
||||
// or user want load current side from cubemap we run software decompressing
|
||||
if( image.flags & IMAGE_CUBEMAP ) numsides = 6;
|
||||
Image_SetPixelFormat( image.width, image.height, image.num_layers ); // setup
|
||||
image.size = image.ptr = 0;
|
||||
if( image.cmd_flags & IL_IGNORE_MIPS )
|
||||
image.cur_mips = 1;
|
||||
else image.cur_mips = image.num_mips;
|
||||
image.num_mips = 1; // defaulting to one mip
|
||||
|
||||
for( i = 0, offset = 0; i < numsides; i++, buf += offset )
|
||||
{
|
||||
Image_SetPixelFormat( image.curwidth, image.curheight, image.curdepth );
|
||||
offset = image.SizeOfFile; // move pointer
|
||||
|
||||
Image_DecompressDDS( buf, target + i );
|
||||
}
|
||||
// now we can change type to RGBA
|
||||
if( image.hint != IL_HINT_NO ) image.flags &= ~IMAGE_CUBEMAP; // side extracted
|
||||
image.type = PF_RGBA_32;
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgDev( D_WARN, "wrong vtf size: %i, calc size %i\n", filesize, image.size );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -3,9 +3,7 @@
|
|||
// img_mip.c - hl1 q1 image mips
|
||||
//=======================================================================
|
||||
|
||||
#include "launch.h"
|
||||
#include "byteorder.h"
|
||||
#include "filesystem.h"
|
||||
#include "imagelib.h"
|
||||
|
||||
/*
|
||||
============
|
|
@ -43,7 +43,7 @@ RSC=rc.exe
|
|||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LAUNCH_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" /I "../public" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" /I "./imagelib" /I "../public" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
|
@ -54,7 +54,7 @@ BSC32=bscmake.exe
|
|||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /opt:nowin98
|
||||
# ADD LINK32 zlib.lib png.lib user32.lib gdi32.lib advapi32.lib winmm.lib /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"libc.lib" /opt:nowin98
|
||||
# ADD LINK32 zlib.lib png.lib user32.lib gdi32.lib advapi32.lib winmm.lib /nologo /dll /pdb:none /machine:I386 /nodefaultlib:"libc.lib" /libpath:"./imagelib" /opt:nowin98
|
||||
# Begin Custom Build
|
||||
TargetDir=\Xash3D\src_main\temp\launch\!release
|
||||
InputPath=\Xash3D\src_main\temp\launch\!release\launch.dll
|
||||
|
@ -79,7 +79,7 @@ SOURCE="$(InputPath)"
|
|||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LAUNCH_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "./" /I "../public" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "./" /I "./imagelib" /I "../public" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
|
@ -90,7 +90,7 @@ BSC32=bscmake.exe
|
|||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 zlib.lib png.lib user32.lib gdi32.lib advapi32.lib winmm.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libc.lib" /pdbtype:sept
|
||||
# ADD LINK32 zlib.lib png.lib user32.lib gdi32.lib advapi32.lib winmm.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libc.lib" /pdbtype:sept /libpath:"./imagelib"
|
||||
# Begin Custom Build
|
||||
TargetDir=\Xash3D\src_main\temp\launch\!debug
|
||||
InputPath=\Xash3D\src_main\temp\launch\!debug\launch.dll
|
||||
|
@ -140,39 +140,43 @@ SOURCE=.\filesystem.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_bmp.c
|
||||
SOURCE=.\imagelib\img_bmp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_dds.c
|
||||
SOURCE=.\imagelib\img_dds.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_jpg.c
|
||||
SOURCE=.\imagelib\img_jpg.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_main.c
|
||||
SOURCE=.\imagelib\img_main.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_pcx.c
|
||||
SOURCE=.\imagelib\img_pcx.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_png.c
|
||||
SOURCE=.\imagelib\img_png.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_tga.c
|
||||
SOURCE=.\imagelib\img_tga.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_utils.c
|
||||
SOURCE=.\imagelib\img_utils.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\img_wad.c
|
||||
SOURCE=.\imagelib\img_vtf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\imagelib\img_wad.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
|
|
|
@ -313,6 +313,7 @@ bool FS_WriteFile (const char *filename, const void *data, fs_offset_t len);
|
|||
rgbdata_t *FS_LoadImage( const char *name, const byte *buffer, size_t size );
|
||||
void FS_SaveImage( const char *name, int format, rgbdata_t *image );
|
||||
void Image_Process( rgbdata_t **pix, int w, int h, uint flags );
|
||||
bpc_desc_t *Image_GetPixelFormat( pixformat_t type );
|
||||
void FS_FreeImage( rgbdata_t *pack );
|
||||
|
||||
search_t *FS_Search(const char *pattern, int caseinsensitive );
|
||||
|
|
|
@ -195,6 +195,7 @@ void Sys_GetStdAPI( void )
|
|||
com.ImageSave = FS_SaveImage; // save image into specified format
|
||||
com.ImageFree = FS_FreeImage; // release image buffer
|
||||
com.ImglibSetup = Image_Setup; // set imagelib global features
|
||||
com.ImagePFDesc = Image_GetPixelFormat; // get some info about current fmt
|
||||
com.ImageConvert = Image_Process; // flip, rotate, resample etc
|
||||
|
||||
com.Com_RandomLong = Com_RandomLong;
|
||||
|
|
|
@ -18,6 +18,7 @@ typedef struct physragdoll_s NewtonRagDoll;
|
|||
typedef struct physmaterial_s NewtonMaterial;
|
||||
typedef struct physcolision_s NewtonCollision;
|
||||
typedef struct physragbone_s NewtonRagDollBone;
|
||||
typedef void (*cmread_t) (void* handle, void* buffer, size_t size);
|
||||
|
||||
extern physic_imp_t pi;
|
||||
extern stdlib_api_t com;
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
#pragma warning(disable : 4018) // signed/unsigned mismatch
|
||||
#pragma warning(disable : 4305) // truncation from const double to float (probably not needed)
|
||||
|
||||
#define MAX_QPATH 64 // get rid of this
|
||||
#define MAX_QPATH 64 // FIXME: get rid of this
|
||||
#define MAX_STRING 256
|
||||
#define MAX_SYSPATH 1024
|
||||
#define MAX_MSGLEN 32768 // max length of network message
|
||||
|
||||
typedef enum{ false, true } bool;
|
||||
typedef enum { false, true } bool;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
typedef unsigned long dword;
|
||||
|
@ -26,13 +26,13 @@ typedef int model_t;
|
|||
typedef int video_t;
|
||||
typedef int string_t;
|
||||
typedef int shader_t;
|
||||
typedef float vec_t;
|
||||
typedef float vec_t; // FIXME: remove
|
||||
typedef vec_t vec2_t[2];
|
||||
typedef vec_t vec3_t[3];
|
||||
typedef vec_t vec4_t[4];
|
||||
typedef vec_t matrix3x3[3][3];
|
||||
typedef vec_t matrix3x4[3][4];
|
||||
typedef vec_t matrix4x3[4][3];
|
||||
typedef vec_t matrix3x4[3][4]; // FIXME: remove
|
||||
typedef vec_t matrix4x3[4][3]; // FIXME: remove
|
||||
typedef vec_t matrix4x4[4][4];
|
||||
typedef vec_t gl_matrix[16]; // linear array
|
||||
typedef char string[MAX_STRING];
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#ifndef LAUNCH_APH_H
|
||||
#define LAUNCH_APH_H
|
||||
|
||||
// platform states
|
||||
// platform instances
|
||||
typedef enum
|
||||
{
|
||||
HOST_OFFLINE = 0, // host_init( g_Instance ) same much as:
|
||||
|
@ -22,4 +22,747 @@ typedef enum
|
|||
HOST_COUNTS, // terminator
|
||||
} instance_t;
|
||||
|
||||
enum dev_level
|
||||
{
|
||||
D_INFO = 1, // "-dev 1", shows various system messages
|
||||
D_WARN, // "-dev 2", shows not critical system warnings
|
||||
D_ERROR, // "-dev 3", shows critical warnings
|
||||
D_LOAD, // "-dev 4", show messages about loading resources
|
||||
D_NOTE, // "-dev 5", show system notifications for engine develeopers
|
||||
D_MEMORY, // "-dev 6", writes to log memory allocation
|
||||
D_STRING, // "-dev 7", writes to log tempstrings allocation
|
||||
};
|
||||
|
||||
typedef long fs_offset_t;
|
||||
typedef struct cvar_s cvar_t;
|
||||
typedef struct file_s file_t; // normal file
|
||||
typedef struct vfile_s vfile_t; // virtual file
|
||||
typedef struct wfile_s wfile_t; // wad file
|
||||
typedef struct { const char *name; void **func; } dllfunc_t; // Sys_LoadLibrary stuff
|
||||
typedef struct { int numfilenames; char **filenames; char *filenamesbuffer; } search_t;
|
||||
typedef void ( *setpair_t )( const char *key, const char *value, void *buffer, void *numpairs );
|
||||
typedef enum { NA_BAD, NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX } netadrtype_t;
|
||||
typedef enum { NS_CLIENT, NS_SERVER } netsrc_t;
|
||||
typedef void ( *xcommand_t )( void );
|
||||
|
||||
// command buffer modes
|
||||
enum
|
||||
{
|
||||
EXEC_NOW = 0,
|
||||
EXEC_INSERT,
|
||||
EXEC_APPEND,
|
||||
};
|
||||
|
||||
// timestamp modes
|
||||
enum
|
||||
{
|
||||
TIME_FULL = 0,
|
||||
TIME_DATE_ONLY,
|
||||
TIME_TIME_ONLY,
|
||||
TIME_NO_SECONDS,
|
||||
TIME_YEAR_ONLY,
|
||||
};
|
||||
|
||||
// cvar flags
|
||||
typedef enum
|
||||
{
|
||||
CVAR_ARCHIVE = BIT(0), // set to cause it to be saved to vars.rc
|
||||
CVAR_USERINFO = BIT(1), // added to userinfo when changed
|
||||
CVAR_SERVERINFO = BIT(2), // added to serverinfo when changed
|
||||
CVAR_SYSTEMINFO = BIT(3), // don't changed from console, saved into config.dll
|
||||
CVAR_INIT = BIT(4), // don't allow change from console at all, but can be set from the command line
|
||||
CVAR_LATCH = BIT(5), // save changes until server restart
|
||||
CVAR_READ_ONLY = BIT(6), // display only, cannot be set by user at all
|
||||
CVAR_USER_CREATED = BIT(7), // created by a set command (prvm used)
|
||||
CVAR_TEMP = BIT(8), // can be set even when cheats are disabled, but is not archived
|
||||
CVAR_CHEAT = BIT(9), // can not be changed if cheats are disabled
|
||||
CVAR_NORESTART = BIT(10),// do not clear when a cvar_restart is issued
|
||||
} cvar_flags_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
netadrtype_t type;
|
||||
byte ip[4];
|
||||
byte ipx[10];
|
||||
word port;
|
||||
} netadr_t;
|
||||
|
||||
typedef struct sizebuf_s // FIXME: rename to netbuf
|
||||
{
|
||||
bool overflowed; // set to true if the buffer size failed
|
||||
|
||||
byte *data;
|
||||
int maxsize;
|
||||
int cursize;
|
||||
int readcount;
|
||||
} sizebuf_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
SYS EVENT
|
||||
|
||||
keep console cmds, network messages, mouse reletives and key buttons
|
||||
========================================================================
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SE_NONE = 0, // ev.time is still valid
|
||||
SE_KEY, // ev.value[0] is a key code, ev.value[1] is the down flag
|
||||
SE_CHAR, // ev.value[0] is an ascii char
|
||||
SE_MOUSE, // ev.value[0] and ev.value[1] are reletive signed x / y moves
|
||||
SE_CONSOLE, // ev.data is a char*
|
||||
SE_PACKET // ev.data is a netadr_t followed by data bytes to ev.length
|
||||
} ev_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dword time;
|
||||
ev_type_t type;
|
||||
int value[2];
|
||||
void *data;
|
||||
size_t length;
|
||||
} sys_event_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
GAMEINFO stuff
|
||||
|
||||
internal shared gameinfo structure (readonly for engine parts)
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct gameinfo_s
|
||||
{
|
||||
// filesystem info
|
||||
string basedir;
|
||||
string gamedir;
|
||||
string startmap;
|
||||
string title;
|
||||
string username; // OS current username
|
||||
float version; // engine or mod version
|
||||
|
||||
int viewmode;
|
||||
int gamemode;
|
||||
|
||||
// shared system info
|
||||
int cpunum; // count of cpu's
|
||||
int64 tickcount; // cpu frequency in 'ticks'
|
||||
float cpufreq; // cpu frequency in MHz
|
||||
bool rdtsc; // rdtsc support (profiler stuff)
|
||||
|
||||
string vprogs_dir; // default progs directory
|
||||
string source_dir; // default source directory
|
||||
|
||||
string gamedirs[128]; // environment folders (for change game from menu)
|
||||
int numgamedirs;
|
||||
|
||||
char TXcommand; // FIXME: quark .map comment
|
||||
char instance; // global engine instance
|
||||
} gameinfo_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
internal dll's loader
|
||||
|
||||
two main types - native dlls and other win32 libraries will be recognized automatically
|
||||
NOTE: never change this structure because all dll descriptions in xash code
|
||||
writes into struct by offsets not names
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct dll_info_s
|
||||
{
|
||||
// generic interface
|
||||
const char *name; // library name
|
||||
const dllfunc_t *fcts; // list of dll exports
|
||||
const char *entry; // entrypoint name (internal libs only)
|
||||
void *link; // hinstance of loading library
|
||||
|
||||
// xash interface
|
||||
void *(*main)( void*, void* );
|
||||
bool crash; // crash if dll not found
|
||||
|
||||
size_t api_size; // interface size
|
||||
} dll_info_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
internal image format
|
||||
|
||||
typically expanded to rgba buffer
|
||||
========================================================================
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
PF_UNKNOWN = 0,
|
||||
PF_INDEXED_24, // inflated palette (768 bytes)
|
||||
PF_INDEXED_32, // deflated palette (1024 bytes)
|
||||
PF_RGBA_32, // normal rgba buffer
|
||||
PF_BGRA_32, // big endian RGBA (MacOS)
|
||||
PF_ARGB_32, // uncompressed dds image
|
||||
PF_ABGR_64, // uint image
|
||||
PF_RGB_24, // uncompressed dds or another 24-bit image
|
||||
PF_BGR_24, // big-endian RGB (MacOS)
|
||||
PF_RGB_16, // 5-6-5 weighted image
|
||||
PF_DXT1, // nvidia DXT1 format
|
||||
PF_DXT2, // nvidia DXT2 format
|
||||
PF_DXT3, // nvidia DXT3 format
|
||||
PF_DXT4, // nvidia DXT5 format
|
||||
PF_DXT5, // nvidia DXT5 format
|
||||
PF_RXGB, // doom3 normal maps
|
||||
PF_ATI1N, // ati 1N texture
|
||||
PF_ATI2N, // ati 2N texture
|
||||
PF_LUMINANCE, // b&w dds image
|
||||
PF_LUMINANCE_16, // b&w hi-res image
|
||||
PF_LUMINANCE_ALPHA, // b&w dds image with alpha channel
|
||||
PF_R_16F, // red channel half-float image
|
||||
PF_R_32F, // red channel float image
|
||||
PF_GR_32F, // Green-Red channels half-float image (dudv maps)
|
||||
PF_GR_64F, // Green-Red channels float image (dudv maps)
|
||||
PF_ABGR_64F, // ABGR half-float image
|
||||
PF_ABGR_128F, // ABGR float image
|
||||
PF_RGBA_GN, // internal generated texture
|
||||
PF_TOTALCOUNT, // must be last
|
||||
} pixformat_t;
|
||||
|
||||
typedef struct bpc_desc_s
|
||||
{
|
||||
int format; // pixelformat
|
||||
char name[16]; // used for debug
|
||||
uint glmask; // RGBA mask
|
||||
uint gltype; // pixel size (byte, short etc)
|
||||
int bpp; // channels (e.g. rgb = 3, rgba = 4)
|
||||
int bpc; // sizebytes (byte, short, float)
|
||||
int block; // blocksize < 0 needs alternate calc
|
||||
} bpc_desc_t;
|
||||
|
||||
// imagelib global settings
|
||||
typedef enum
|
||||
{
|
||||
IL_DDS_HARDWARE = BIT(0), // instance have dds hardware support (disable software unpacker)
|
||||
IL_ATI_FLOAT_EXT = BIT(1), // reinstall float images glmask for ati extensions
|
||||
IL_NV_FLOAT_EXT = BIT(2), // reinstall float images glmask for nv extensions
|
||||
IL_USE_LERPING = BIT(3), // lerping images during resample
|
||||
IL_KEEP_8BIT = BIT(4), // don't expand paletted images
|
||||
IL_ALLOW_OVERWRITE = BIT(5), // allow to overwrite stored images
|
||||
IL_IGNORE_MIPS = BIT(6), // ignore mip-levels to loading
|
||||
} ilFlags_t;
|
||||
|
||||
// rgbdata output flags
|
||||
typedef enum
|
||||
{
|
||||
// rgbdata->flags
|
||||
IMAGE_CUBEMAP = BIT(0), // it's 6-sides cubemap buffer
|
||||
IMAGE_HAVE_ALPHA = BIT(1), // image contain alpha-channel
|
||||
IMAGE_COLORINDEX = BIT(2), // all colors in palette is gradients of last color (decals)
|
||||
IMAGE_PREMULT = BIT(3), // need to premultiply alpha (DXT2, DXT4)
|
||||
IMAGE_S3 = BIT(4), // s&3 image
|
||||
|
||||
// Image_Process manipulation flags
|
||||
IMAGE_FLIP_X = BIT(16), // flip the image by width
|
||||
IMAGE_FLIP_Y = BIT(17), // flip the image by height
|
||||
IMAGE_ROT_90 = BIT(18), // flip from upper left corner to down right corner
|
||||
IMAGE_ROT180 = IMAGE_FLIP_X|IMAGE_FLIP_Y,
|
||||
IMAGE_ROT270 = IMAGE_FLIP_X|IMAGE_FLIP_Y|IMAGE_ROT_90,
|
||||
IMAGE_ROUND = BIT(19), // round image to nearest Pow2
|
||||
IMAGE_RESAMPLE = BIT(20), // resample image to specified dims
|
||||
IMAGE_PALTO24 = BIT(21), // turn 32-bit palette into 24-bit mode (only for indexed images)
|
||||
IMAGE_DXTTO32 = BIT(22), // force to use software dds loader (render requires for some reasons)
|
||||
} imgFlags_t;
|
||||
|
||||
typedef struct rgbdata_s
|
||||
{
|
||||
int width; // image width
|
||||
int height; // image height
|
||||
byte numLayers; // multi-layer volume
|
||||
byte numMips; // mipmap count
|
||||
byte bitsCount; // RGB bits count
|
||||
word numFrames; // SPR or VTF framecount
|
||||
byte type; // compression type
|
||||
uint flags; // misc image flags
|
||||
byte *palette; // palette if present
|
||||
byte *buffer; // image buffer
|
||||
size_t size; // for bounds checking
|
||||
} rgbdata_t;
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
STDLIB SYSTEM INTERFACE
|
||||
==============================================================================
|
||||
*/
|
||||
typedef struct stdilib_api_s
|
||||
{
|
||||
// interface validator
|
||||
size_t api_size; // must matched with sizeof(stdlib_api_t)
|
||||
|
||||
gameinfo_t *GameInfo; // user game info (filled by engine)
|
||||
|
||||
// base events
|
||||
void (*instance)( const char *name, const char *fmsg ); // restart engine with new instance
|
||||
void (*print)( const char *msg ); // basic text message
|
||||
void (*printf)( const char *msg, ... ); // formatted text message
|
||||
void (*dprintf)( int level, const char *msg, ...); // developer text message
|
||||
void (*error)( const char *msg, ... ); // abnormal termination with message
|
||||
void (*abort)( const char *msg, ... ); // normal tremination with message
|
||||
void (*exit)( void ); // normal silent termination
|
||||
void (*sleep)( int msec ); // sleep for some msec
|
||||
char *(*clipboard)( void ); // get clipboard data
|
||||
void (*queevent)( dword time, ev_type_t type, int value, int value2, int length, void *ptr );
|
||||
sys_event_t (*getevent)( void ); // get system events
|
||||
|
||||
// crclib.c funcs
|
||||
void (*crc_init)(word *crcvalue); // set initial crc value
|
||||
word (*crc_block)(byte *start, int count); // calculate crc block
|
||||
void (*crc_process)(word *crcvalue, byte data); // process crc byte
|
||||
byte (*crc_sequence)(byte *base, int length, int sequence); // calculate crc for sequence
|
||||
uint (*crc_blockchecksum)(void *buffer, int length); // map checksum
|
||||
uint (*crc_blockchecksumkey)(void *buf, int len, int key); // process key checksum
|
||||
|
||||
// memlib.c funcs
|
||||
void (*memcpy)(void *dest, const void *src, size_t size, const char *file, int line);
|
||||
void (*memset)(void *dest, int set, size_t size, const char *filename, int fileline);
|
||||
void *(*realloc)(byte *pool, void *mem, size_t size, const char *file, int line);
|
||||
void (*move)(byte *pool, void **dest, void *src, size_t size, const char *file, int line); // not a memmove
|
||||
void *(*malloc)(byte *pool, size_t size, const char *file, int line);
|
||||
void (*free)(void *data, const char *file, int line);
|
||||
|
||||
// xash memlib extension - memory pools
|
||||
byte *(*mallocpool)(const char *name, const char *file, int line);
|
||||
void (*freepool)(byte **poolptr, const char *file, int line);
|
||||
void (*clearpool)(byte *poolptr, const char *file, int line);
|
||||
void (*memcheck)(const char *file, int line); // check memory pools for consistensy
|
||||
|
||||
// xash memlib extension - memory arrays
|
||||
byte *(*newarray)( byte *pool, size_t elementsize, int count, const char *file, int line );
|
||||
void (*delarray)( byte *array, const char *file, int line );
|
||||
void *(*newelement)( byte *array, const char *file, int line );
|
||||
void (*delelement)( byte *array, void *element, const char *file, int line );
|
||||
void *(*getelement)( byte *array, size_t index );
|
||||
size_t (*arraysize)( byte *arrayptr );
|
||||
|
||||
// network.c funcs
|
||||
void (*NET_Init)( void );
|
||||
void (*NET_Shutdown)( void );
|
||||
void (*NET_ShowIP)( void );
|
||||
void (*NET_Config)( bool net_enable );
|
||||
char *(*NET_AdrToString)( netadr_t a );
|
||||
bool (*NET_IsLANAddress)( netadr_t adr );
|
||||
bool (*NET_StringToAdr)( const char *s, netadr_t *a );
|
||||
void (*NET_SendPacket)( int length, const void *data, netadr_t to );
|
||||
|
||||
// common functions
|
||||
void (*Com_InitRootDir)( char *path ); // init custom rootdir
|
||||
void (*Com_LoadGameInfo)( const char *filename ); // gate game info from script file
|
||||
void (*Com_AddGameHierarchy)(const char *dir); // add base directory in search list
|
||||
int (*Com_CheckParm)( const char *parm ); // check parm in cmdline
|
||||
bool (*Com_GetParm)( char *parm, char *out ); // get parm from cmdline
|
||||
void (*Com_FileBase)(const char *in, char *out); // get filename without path & ext
|
||||
bool (*Com_FileExists)(const char *filename); // return true if file exist
|
||||
long (*Com_FileSize)(const char *filename); // same as Com_FileExists but return filesize
|
||||
long (*Com_FileTime)(const char *filename); // same as Com_FileExists but return filetime
|
||||
const char *(*Com_FileExtension)(const char *in); // return extension of file
|
||||
const char *(*Com_RemovePath)(const char *in); // return file without path
|
||||
void (*Com_StripExtension)(char *path); // remove extension if present
|
||||
void (*Com_StripFilePath)(const char* const src, char* dst);// get file path without filename.ext
|
||||
void (*Com_DefaultExtension)(char *path, const char *ext ); // append extension if not present
|
||||
void (*Com_ClearSearchPath)( void ); // delete all search pathes
|
||||
void (*Com_CreateThread)(int, bool, void(*fn)(int)); // run individual thread
|
||||
void (*Com_ThreadLock)( void ); // lock current thread
|
||||
void (*Com_ThreadUnlock)( void ); // unlock numthreads
|
||||
int (*Com_NumThreads)( void ); // returns count of active threads
|
||||
bool (*Com_LoadScript)(const char *name,char *buf,int size);// load script into stack from file or bufer
|
||||
bool (*Com_AddScript)(const char *name,char *buf, int size);// include script from file or buffer
|
||||
void (*Com_ResetScript)( void ); // reset current script state
|
||||
void (*Com_PushScript)( const char **data_p ); // save script to stack
|
||||
void (*Com_PopScript)( const char **data_p ); // restore script from stack
|
||||
void (*Com_SkipBracedSection)( char **data_p, int depth ); // skip braced section
|
||||
char *(*Com_ReadToken)( bool newline ); // get next token on a line or newline
|
||||
bool (*Com_TryToken)( void ); // return 1 if have token on a line
|
||||
void (*Com_FreeToken)( void ); // free current token to may get it again
|
||||
void (*Com_SkipToken)( void ); // skip current token and jump into newline
|
||||
bool (*Com_MatchToken)( const char *match ); // compare current token with user keyword
|
||||
bool (*Com_ParseToken_Simple)(const char **data_p); // basic parse (can't handle single characters)
|
||||
char *(*Com_ParseToken)(const char **data, bool newline ); // parse token from char buffer
|
||||
char *(*Com_ParseWord)( const char **data, bool newline ); // parse word from char buffer
|
||||
search_t *(*Com_Search)(const char *pattern, int casecmp ); // returned list of found files
|
||||
bool (*Com_Filter)(char *filter, char *name, int casecmp ); // compare keyword by mask with filter
|
||||
uint (*Com_HashKey)( const char *string, uint hashSize ); // returns hash key for a string
|
||||
byte *(*Com_LoadRes)( const char *filename, size_t *size ); // find internal resource in baserc.dll
|
||||
long com_scriptline; // contains current scriptline
|
||||
char *com_token; // contains current token
|
||||
|
||||
// console variables
|
||||
cvar_t *(*Cvar_Get)(const char *name, const char *value, int flags, const char *desc);
|
||||
void (*Cvar_LookupVars)( int checkbit, void *buffer, void *ptr, setpair_t callback );
|
||||
void (*Cvar_SetString)( const char *name, const char *value );
|
||||
void (*Cvar_SetLatched)( const char *name, const char *value);
|
||||
void (*Cvar_FullSet)( char *name, char *value, int flags );
|
||||
void (*Cvar_SetValue )( const char *name, float value);
|
||||
float (*Cvar_GetValue )(const char *name);
|
||||
char *(*Cvar_GetString)(const char *name);
|
||||
cvar_t *(*Cvar_FindVar)(const char *name);
|
||||
bool userinfo_modified; // tell to client about userinfo modified
|
||||
|
||||
// console commands
|
||||
void (*Cmd_Exec)(int exec_when, const char *text); // process cmd buffer
|
||||
uint (*Cmd_Argc)( void );
|
||||
char *(*Cmd_Args)( void );
|
||||
char *(*Cmd_Argv)( uint arg );
|
||||
void (*Cmd_LookupCmds)( char *buffer, void *ptr, setpair_t callback );
|
||||
void (*Cmd_AddCommand)(const char *name, xcommand_t function, const char *desc);
|
||||
void (*Cmd_TokenizeString)(const char *text_in);
|
||||
void (*Cmd_DelCommand)(const char *name);
|
||||
|
||||
// real filesystem
|
||||
file_t *(*fopen)(const char* path, const char* mode); // same as fopen
|
||||
int (*fclose)(file_t* file); // same as fclose
|
||||
long (*fwrite)(file_t* file, const void* data, size_t datasize); // same as fwrite
|
||||
long (*fread)(file_t* file, void* buffer, size_t buffersize); // same as fread, can see trough pakfile
|
||||
int (*fprint)(file_t* file, const char *msg); // printed message into file
|
||||
int (*fprintf)(file_t* file, const char* format, ...); // same as fprintf
|
||||
int (*fgets)(file_t* file, byte *string, size_t bufsize ); // like a fgets, but can return EOF
|
||||
int (*fseek)(file_t* file, fs_offset_t offset, int whence); // fseek, can seek in packfiles too
|
||||
bool (*fremove)( const char *path ); // remove sepcified file
|
||||
long (*ftell)(file_t* file); // like a ftell
|
||||
|
||||
// virtual filesystem
|
||||
vfile_t *(*vfcreate)( const byte *buffer, size_t buffsize ); // create virtual stream
|
||||
vfile_t *(*vfopen)(file_t *handle, const char* mode); // virtual fopen
|
||||
file_t *(*vfclose)(vfile_t* file); // free buffer or write dump
|
||||
long (*vfwrite)(vfile_t* file, const void* buf, size_t datasize); // write into buffer
|
||||
long (*vfread)(vfile_t* file, void* buffer, size_t buffersize); // read from buffer
|
||||
int (*vfgets)(vfile_t* file, byte *string, size_t bufsize ); // read text line
|
||||
int (*vfprint)(vfile_t* file, const char *msg); // write message
|
||||
int (*vfprintf)(vfile_t* file, const char* format, ...); // write formatted message
|
||||
int (*vfseek)(vfile_t* file, fs_offset_t offset, int whence); // fseek, can seek in packfiles too
|
||||
bool (*vfunpack)( void* comp, size_t size1, void **buf, size_t size2);// deflate zipped buffer
|
||||
byte *(*vfbuffer)( vfile_t *file ); // get pointer to virtual filebuff
|
||||
long (*vftell)(vfile_t* file); // like a ftell
|
||||
bool (*vfeof)( vfile_t* file); // like a feof
|
||||
|
||||
// wadstorage filesystem
|
||||
int (*wfcheck)( const char *filename ); // validate container
|
||||
wfile_t *(*wfopen)( const char *filename, const char *mode ); // open wad file or create new
|
||||
void (*wfclose)( wfile_t *wad ); // close wadfile
|
||||
long (*wfwrite)( wfile_t *wad, const char *lump, const void* data, size_t datasize, char type, char cmp );
|
||||
byte *(*wfread)( wfile_t *wad, const char *lump, size_t *lumpsizeptr, const char type );
|
||||
|
||||
// filesystem simply user interface
|
||||
byte *(*Com_LoadFile)(const char *path, long *filesize ); // load file into heap
|
||||
bool (*Com_WriteFile)(const char *path, const void *data, long len ); // write file into disk
|
||||
bool (*Com_LoadLibrary)( dll_info_t *dll ); // load library
|
||||
bool (*Com_FreeLibrary)( dll_info_t *dll ); // free library
|
||||
void*(*Com_GetProcAddress)( dll_info_t *dll, const char* name ); // gpa
|
||||
double (*Com_DoubleTime)( void ); // hi-res timer
|
||||
dword (*Com_Milliseconds)( void ); // hi-res timer
|
||||
|
||||
// built-in imagelib functions
|
||||
void (*ImglibSetup)( const char *formats, const uint flags ); // set main attributes
|
||||
rgbdata_t *(*ImageLoad)( const char *, const byte *, size_t ); // load image from disk or buffer
|
||||
void (*ImageSave)( const char *name, int format, rgbdata_t *image ); // save image into specified format
|
||||
void (*ImageConvert)( rgbdata_t **pix, int w, int h, uint flags ); // image manipulations
|
||||
bpc_desc_t *(*ImagePFDesc)( pixformat_t imagetype ); // get const info about specified fmt
|
||||
void (*ImageFree)( rgbdata_t *pack ); // release image buffer
|
||||
|
||||
// random generator
|
||||
long (*Com_RandomLong)( long lMin, long lMax ); // returns random integer
|
||||
float (*Com_RandomFloat)( float fMin, float fMax ); // returns random float
|
||||
|
||||
// stdlib.c funcs
|
||||
void (*strnupr)(const char *in, char *out, size_t size_out); // convert string to upper case
|
||||
void (*strnlwr)(const char *in, char *out, size_t size_out); // convert string to lower case
|
||||
void (*strupr)(const char *in, char *out); // convert string to upper case
|
||||
void (*strlwr)(const char *in, char *out); // convert string to lower case
|
||||
int (*strlen)( const char *string ); // returns string real length
|
||||
int (*cstrlen)( const char *string ); // strlen that stripped color prefixes
|
||||
char (*toupper)(const char in ); // convert one charcster to upper case
|
||||
char (*tolower)(const char in ); // convert one charcster to lower case
|
||||
size_t (*strncat)(char *dst, const char *src, size_t n); // add new string at end of buffer
|
||||
size_t (*strcat)(char *dst, const char *src); // add new string at end of buffer
|
||||
size_t (*strncpy)(char *dst, const char *src, size_t n); // copy string to existing buffer
|
||||
size_t (*strcpy)(char *dst, const char *src); // copy string to existing buffer
|
||||
char *(*stralloc)(byte *mp,const char *in,const char *file,int line); // create buffer and copy string here
|
||||
int (*atoi)(const char *str); // convert string to integer
|
||||
float (*atof)(const char *str); // convert string to float
|
||||
void (*atov)( float *dst, const char *src, size_t n ); // convert string to vector
|
||||
char *(*strchr)(const char *s, char c); // find charcster at start of string
|
||||
char *(*strrchr)(const char *s, char c); // find charcster at end of string
|
||||
int (*strnicmp)(const char *s1, const char *s2, int n); // compare strings with case insensative
|
||||
int (*stricmp)(const char *s1, const char *s2); // compare strings with case insensative
|
||||
int (*strncmp)(const char *s1, const char *s2, int n); // compare strings with case sensative
|
||||
int (*strcmp)(const char *s1, const char *s2); // compare strings with case sensative
|
||||
char *(*stristr)( const char *s1, const char *s2 ); // find s2 in s1 with case insensative
|
||||
char *(*strstr)( const char *s1, const char *s2 ); // find s2 in s1 with case sensative
|
||||
size_t (*strpack)( byte *buf, size_t pos, char *s1, int n ); // put string at end ofbuffer
|
||||
size_t (*strunpack)( byte *buf, size_t pos, char *s1 ); // extract string from buffer
|
||||
int (*vsprintf)(char *buf, const char *fmt, va_list args); // format message
|
||||
int (*sprintf)(char *buffer, const char *format, ...); // print into buffer
|
||||
char *(*va)(const char *format, ...); // print into temp buffer
|
||||
int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list args); // format message
|
||||
int (*snprintf)(char *buffer, size_t buffersize, const char *format, ...); // print into buffer
|
||||
const char* (*timestamp)( int format ); // returns current time stamp
|
||||
|
||||
// stringtable system
|
||||
int (*st_create)( const char *name, size_t max_strings );
|
||||
const char *(*st_getstring)( int handle, string_t index );
|
||||
string_t (*st_setstring)( int handle, const char *string );
|
||||
int (*st_load)( wfile_t *wad, const char *name );
|
||||
bool (*st_save)( int h, wfile_t *wad );
|
||||
void (*st_remove)( int handle );
|
||||
} stdlib_api_t;
|
||||
|
||||
#ifndef LAUNCH_DLL
|
||||
/*
|
||||
==============================================================================
|
||||
STDLIB GENERIC ALIAS NAMES
|
||||
don't add aliases for launch.dll because it may be conflicted with real names
|
||||
==============================================================================
|
||||
*/
|
||||
/*
|
||||
========================================================================
|
||||
console variables
|
||||
external and internal cvars struct have some differences
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct cvar_s
|
||||
{
|
||||
char *name;
|
||||
char *string; // normal string
|
||||
float value; // com.atof( string )
|
||||
int integer; // com.atoi( string )
|
||||
bool modified; // set each time the cvar is changed
|
||||
} cvar_t;
|
||||
|
||||
/*
|
||||
==========================================
|
||||
memory manager funcs
|
||||
==========================================
|
||||
*/
|
||||
#define Mem_Alloc(pool, size) com.malloc(pool, size, __FILE__, __LINE__)
|
||||
#define Mem_Realloc(pool, ptr, size) com.realloc(pool, ptr, size, __FILE__, __LINE__)
|
||||
#define Mem_Move(pool, ptr, data, size) com.move(pool, ptr, data, size, __FILE__, __LINE__)
|
||||
#define Mem_Free(mem) com.free(mem, __FILE__, __LINE__)
|
||||
#define Mem_AllocPool(name) com.mallocpool(name, __FILE__, __LINE__)
|
||||
#define Mem_FreePool(pool) com.freepool(pool, __FILE__, __LINE__)
|
||||
#define Mem_EmptyPool(pool) com.clearpool(pool, __FILE__, __LINE__)
|
||||
#define Mem_Copy(dest, src, size ) com.memcpy(dest, src, size, __FILE__, __LINE__)
|
||||
#define Mem_Set(dest, val, size ) com.memcpy(dest, val, size, __FILE__, __LINE__)
|
||||
#define Mem_Check() com.memcheck(__FILE__, __LINE__)
|
||||
#define Mem_CreateArray( p, s, n ) com.newarray( p, s, n, __FILE__, __LINE__)
|
||||
#define Mem_RemoveArray( array ) com.delarray( array, __FILE__, __LINE__)
|
||||
#define Mem_AllocElement( array ) com.newelement( array, __FILE__, __LINE__)
|
||||
#define Mem_FreeElement( array, el ) com.delelement( array, el, __FILE__, __LINE__ )
|
||||
#define Mem_GetElement( array, idx ) com.getelement( array, idx )
|
||||
#define Mem_ArraySize( array ) com.arraysize( array )
|
||||
|
||||
/*
|
||||
==========================================
|
||||
parsing manager funcs
|
||||
==========================================
|
||||
*/
|
||||
#define Com_ParseToken com.Com_ParseToken
|
||||
#define Com_ParseWord com.Com_ParseWord
|
||||
#define Com_SimpleGetToken com.Com_ParseToken_Simple
|
||||
#define Com_SkipBracedSection com.Com_SkipBracedSection
|
||||
#define Com_Filter com.Com_Filter
|
||||
#define Com_HashKey com.Com_HashKey
|
||||
#define Com_LoadScript com.Com_LoadScript
|
||||
#define Com_IncludeScript com.Com_AddScript
|
||||
#define Com_ResetScript com.Com_ResetScript
|
||||
#define Com_GetToken com.Com_ReadToken
|
||||
#define Com_TryToken com.Com_TryToken
|
||||
#define Com_FreeToken com.Com_FreeToken
|
||||
#define Com_SkipToken com.Com_SkipToken
|
||||
#define Com_MatchToken com.Com_MatchToken
|
||||
#define Com_PushScript com.Com_PushScript
|
||||
#define Com_PopScript com.Com_PopScript
|
||||
#define com_token com.com_token
|
||||
#define scriptline com.com_scriptline
|
||||
#define g_TXcommand com.GameInfo->TXcommand
|
||||
#define g_Instance com.GameInfo->instance
|
||||
|
||||
/*
|
||||
===========================================
|
||||
filesystem manager
|
||||
===========================================
|
||||
*/
|
||||
#define FS_AddGameHierarchy com.Com_AddGameHierarchy
|
||||
#define FS_LoadGameInfo com.Com_LoadGameInfo
|
||||
#define FS_InitRootDir com.Com_InitRootDir
|
||||
#define FS_LoadFile com.Com_LoadFile
|
||||
#define FS_Search com.Com_Search
|
||||
#define FS_WriteFile com.Com_WriteFile
|
||||
#define FS_Open( path, mode ) com.fopen( path, mode )
|
||||
#define FS_Read( file, buffer, size ) com.fread( file, buffer, size )
|
||||
#define FS_Write( file, buffer, size ) com.fwrite( file, buffer, size )
|
||||
#define FS_StripExtension( path ) com.Com_StripExtension( path )
|
||||
#define FS_ExtractFilePath( src, dest) com.Com_StripFilePath( src, dest )
|
||||
#define FS_DefaultExtension com.Com_DefaultExtension
|
||||
#define FS_FileExtension( ext ) com.Com_FileExtension( ext )
|
||||
#define FS_FileExists( file ) com.Com_FileExists( file )
|
||||
#define FS_FileSize( file ) com.Com_FileSize( file )
|
||||
#define FS_FileTime( file ) com.Com_FileTime( file )
|
||||
#define FS_Close( file ) com.fclose( file )
|
||||
#define FS_FileBase( x, y ) com.Com_FileBase( x, y )
|
||||
#define FS_LoadInternal( x, y ) com.Com_LoadRes( x, y )
|
||||
#define FS_Printf com.fprintf
|
||||
#define FS_Print com.fprint
|
||||
#define FS_Seek com.fseek
|
||||
#define FS_Tell com.ftell
|
||||
#define FS_Gets com.fgets
|
||||
#define FS_Gamedir com.GameInfo->gamedir
|
||||
#define FS_Title com.GameInfo->title
|
||||
#define FS_ClearSearchPath com.Com_ClearSearchPath
|
||||
#define FS_CheckParm com.Com_CheckParm
|
||||
#define FS_GetParmFromCmdLine com.Com_GetParm
|
||||
|
||||
/*
|
||||
===========================================
|
||||
network messages
|
||||
===========================================
|
||||
*/
|
||||
#define NET_Init com.NET_Init
|
||||
#define NET_Shutdown com.NET_Shutdown
|
||||
#define NET_ShowIP com.NET_ShowIP
|
||||
#define NET_Config com.NET_Config
|
||||
#define NET_AdrToString com.NET_AdrToString
|
||||
#define NET_IsLANAddress com.NET_IsLANAddress
|
||||
#define Sys_StringToAdr com.NET_StringToAdr
|
||||
#define Sys_SendPacket com.NET_SendPacket
|
||||
|
||||
/*
|
||||
===========================================
|
||||
console variables
|
||||
===========================================
|
||||
*/
|
||||
#define Cvar_Get com.Cvar_Get
|
||||
#define Cvar_LookupVars com.Cvar_LookupVars
|
||||
#define Cvar_Set com.Cvar_SetString
|
||||
#define Cvar_FullSet com.Cvar_FullSet
|
||||
#define Cvar_SetLatched com.Cvar_SetLatched
|
||||
#define Cvar_SetValue com.Cvar_SetValue
|
||||
#define Cvar_VariableValue com.Cvar_GetValue
|
||||
#define Cvar_VariableString com.Cvar_GetString
|
||||
#define Cvar_FindVar com.Cvar_FindVar
|
||||
#define userinfo_modified com.userinfo_modified
|
||||
|
||||
/*
|
||||
===========================================
|
||||
console commands
|
||||
===========================================
|
||||
*/
|
||||
#define Cbuf_ExecuteText com.Cmd_Exec
|
||||
#define Cbuf_AddText( text ) com.Cmd_Exec( EXEC_APPEND, text )
|
||||
#define Cmd_ExecuteString( text ) com.Cmd_Exec( EXEC_NOW, text )
|
||||
#define Cbuf_InsertText( text ) com.Cmd_Exec( EXEC_INSERT, text )
|
||||
#define Cbuf_Execute() com.Cmd_Exec( EXEC_NOW, NULL )
|
||||
|
||||
#define Cmd_Argc com.Cmd_Argc
|
||||
#define Cmd_Args com.Cmd_Args
|
||||
#define Cmd_Argv com.Cmd_Argv
|
||||
#define Cmd_TokenizeString com.Cmd_TokenizeString
|
||||
#define Cmd_LookupCmds com.Cmd_LookupCmds
|
||||
#define Cmd_AddCommand com.Cmd_AddCommand
|
||||
#define Cmd_RemoveCommand com.Cmd_DelCommand
|
||||
|
||||
/*
|
||||
===========================================
|
||||
virtual filesystem manager
|
||||
===========================================
|
||||
*/
|
||||
#define VFS_Create com.vfcreate
|
||||
#define VFS_GetBuffer com.vfbuffer
|
||||
#define VFS_Open com.vfopen
|
||||
#define VFS_Write com.vfwrite
|
||||
#define VFS_Read com.vfread
|
||||
#define VFS_Print com.vfprint
|
||||
#define VFS_Printf com.vfprintf
|
||||
#define VFS_Gets com.vfgets
|
||||
#define VFS_Seek com.vfseek
|
||||
#define VFS_Tell com.vftell
|
||||
#define VFS_Eof com.vfeof
|
||||
#define VFS_Close com.vfclose
|
||||
#define VFS_Unpack com.vfunpack
|
||||
|
||||
/*
|
||||
===========================================
|
||||
wadstorage filesystem manager
|
||||
===========================================
|
||||
*/
|
||||
#define WAD_Open com.wfopen
|
||||
#define WAD_Check com.wfcheck
|
||||
#define WAD_Close com.wfclose
|
||||
#define WAD_Write com.wfwrite
|
||||
#define WAD_Read com.wfread
|
||||
|
||||
/*
|
||||
===========================================
|
||||
crclib manager
|
||||
===========================================
|
||||
*/
|
||||
#define CRC_Init com.crc_init
|
||||
#define CRC_Block com.crc_block
|
||||
#define CRC_ProcessByte com.crc_process
|
||||
#define CRC_Sequence com.crc_sequence
|
||||
#define Com_BlockChecksum com.crc_blockchecksum
|
||||
#define Com_BlockChecksumKey com.crc_blockchecksumkey
|
||||
|
||||
/*
|
||||
===========================================
|
||||
imglib manager
|
||||
===========================================
|
||||
*/
|
||||
#define FS_LoadImage com.ImageLoad
|
||||
#define FS_SaveImage com.ImageSave
|
||||
#define FS_FreeImage com.ImageFree
|
||||
#define Image_Init com.ImglibSetup
|
||||
#define PFDesc( x ) com.ImagePFDesc( x )
|
||||
#define Image_Process com.ImageConvert
|
||||
|
||||
/*
|
||||
===========================================
|
||||
misc utils
|
||||
===========================================
|
||||
*/
|
||||
#define GI com.GameInfo
|
||||
#define Msg com.printf
|
||||
#define MsgDev com.dprintf
|
||||
#define Sys_LoadLibrary com.Com_LoadLibrary
|
||||
#define Sys_FreeLibrary com.Com_FreeLibrary
|
||||
#define Sys_GetProcAddress com.Com_GetProcAddress
|
||||
#define Sys_NewInstance com.instance
|
||||
#define Sys_Sleep com.sleep
|
||||
#define Sys_Print com.print
|
||||
#define Sys_GetEvent com.getevent
|
||||
#define Sys_QueEvent com.queevent
|
||||
#define Sys_GetClipboardData com.clipboard
|
||||
#define Sys_Quit com.exit
|
||||
#define Sys_Break com.abort
|
||||
#define Sys_DoubleTime com.Com_DoubleTime
|
||||
#define Sys_Milliseconds com.Com_Milliseconds
|
||||
#define GetNumThreads com.Com_NumThreads
|
||||
#define ThreadLock com.Com_ThreadLock
|
||||
#define ThreadUnlock com.Com_ThreadUnlock
|
||||
#define RunThreadsOnIndividual com.Com_CreateThread
|
||||
#define Com_RandomLong com.Com_RandomLong
|
||||
#define Com_RandomFloat com.Com_RandomFloat
|
||||
#define StringTable_Create com.st_create
|
||||
#define StringTable_Delete com.st_remove
|
||||
#define StringTable_GetString com.st_getstring
|
||||
#define StringTable_SetString com.st_setstring
|
||||
#define StringTable_Load com.st_load
|
||||
#define StringTable_Save com.st_save
|
||||
|
||||
/*
|
||||
===========================================
|
||||
stdlib function names that not across with windows stdlib
|
||||
===========================================
|
||||
*/
|
||||
#define timestamp com.timestamp
|
||||
#define copystring( str ) com.stralloc( NULL, str, __FILE__, __LINE__ )
|
||||
#define va com.va
|
||||
|
||||
#endif//LAUNCH_DLL
|
||||
#endif//LAUNCH_APH_H
|
|
@ -21,38 +21,16 @@
|
|||
#define bound(min, num, max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
|
||||
typedef long fs_offset_t;
|
||||
typedef enum { NA_BAD, NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX } netadrtype_t;
|
||||
typedef enum { NS_CLIENT, NS_SERVER } netsrc_t;
|
||||
|
||||
|
||||
typedef struct { uint b:5; uint g:6; uint r:5; } color16;
|
||||
typedef struct { byte r:8; byte g:8; byte b:8; } color24;
|
||||
typedef struct { byte r; byte g; byte b; byte a; } color32;
|
||||
typedef struct { const char *name; void **func; } dllfunc_t; // Sys_LoadLibrary stuff
|
||||
|
||||
typedef struct { int ofs; int type; const char *name; } fields_t; // prvm custom fields
|
||||
typedef void (*cmread_t) (void* handle, void* buffer, size_t size);
|
||||
typedef enum { mod_bad, mod_world, mod_brush, mod_studio, mod_sprite } modtype_t;
|
||||
typedef void (*cmsave_t) (void* handle, const void* buffer, size_t size);
|
||||
typedef void (*cmdraw_t)( int color, int numpoints, const float *points );
|
||||
typedef struct { int numfilenames; char **filenames; char *filenamesbuffer; } search_t;
|
||||
typedef void (*setpair_t)(const char *key, const char *value, void *buffer, void *numpairs );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
netadrtype_t type;
|
||||
byte ip[4];
|
||||
byte ipx[10];
|
||||
word port;
|
||||
} netadr_t;
|
||||
|
||||
typedef struct sizebuf_s
|
||||
{
|
||||
bool overflowed; // set to true if the buffer size failed
|
||||
|
||||
byte *data;
|
||||
int maxsize;
|
||||
int cursize;
|
||||
int readcount;
|
||||
} sizebuf_t;
|
||||
|
||||
typedef struct edict_s edict_t;
|
||||
typedef struct sv_edict_s sv_edict_t;
|
||||
|
@ -65,11 +43,6 @@ typedef struct sv_globalvars_s sv_globalvars_t;
|
|||
typedef struct cl_globalvars_s cl_globalvars_t;
|
||||
typedef struct ui_globalvars_s ui_globalvars_t;
|
||||
typedef struct physbody_s physbody_t;
|
||||
typedef struct cvar_s cvar_t;
|
||||
typedef struct file_s file_t; // normal file
|
||||
typedef struct vfile_s vfile_t; // virtual file
|
||||
typedef struct wfile_s wfile_t; // wad file
|
||||
typedef void (*xcommand_t) (void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -204,721 +177,6 @@ typedef struct usercmd_s
|
|||
/*
|
||||
========================================================================
|
||||
|
||||
SYS EVENT
|
||||
|
||||
keep console cmds, network messages, mouse reletives and key buttons
|
||||
========================================================================
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SE_NONE = 0, // ev.time is still valid
|
||||
SE_KEY, // ev.value is a key code, ev.value2 is the down flag
|
||||
SE_CHAR, // ev.value is an ascii char
|
||||
SE_MOUSE, // ev.value and ev.value2 are reletive signed x / y moves
|
||||
SE_CONSOLE, // ev.data is a char*
|
||||
SE_PACKET // ev.data is a netadr_t followed by data bytes to ev.length
|
||||
} ev_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dword time;
|
||||
ev_type_t type;
|
||||
int value[2];
|
||||
void *data;
|
||||
size_t length;
|
||||
} sys_event_t;
|
||||
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
GAMEINFO stuff
|
||||
|
||||
internal shared gameinfo structure (readonly for engine parts)
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct gameinfo_s
|
||||
{
|
||||
// filesystem info
|
||||
string basedir;
|
||||
string gamedir;
|
||||
string startmap;
|
||||
string title;
|
||||
string username; // OS current user
|
||||
float version; // engine or mod version
|
||||
|
||||
int viewmode;
|
||||
int gamemode;
|
||||
|
||||
// shared system info
|
||||
int cpunum; // count of cpu's
|
||||
int64 tickcount; // cpu frequency in 'ticks'
|
||||
float cpufreq; // cpu frequency in MHz
|
||||
bool rdtsc; // rdtsc support (profiler stuff)
|
||||
|
||||
string vprogs_dir; // default progs directory
|
||||
string source_dir; // default source directory
|
||||
|
||||
string gamedirs[128]; // environment folders
|
||||
int numgamedirs;
|
||||
|
||||
char TXcommand; // quark .map comment
|
||||
char instance; // global engine instance
|
||||
} gameinfo_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
internal dll's loader
|
||||
|
||||
two main types - native dlls and other win32 libraries will be recognized automatically
|
||||
========================================================================
|
||||
*/
|
||||
typedef struct dll_info_s
|
||||
{
|
||||
// generic interface
|
||||
const char *name; // library name
|
||||
const dllfunc_t *fcts; // list of dll exports
|
||||
const char *entry; // entrypoint name (internal libs only)
|
||||
void *link; // hinstance of loading library
|
||||
|
||||
// xash interface
|
||||
void *(*main)( void*, void* );
|
||||
bool crash; // crash if dll not found
|
||||
|
||||
size_t api_size; // interface size
|
||||
|
||||
} dll_info_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
internal image format
|
||||
|
||||
typically expanded to rgba buffer
|
||||
========================================================================
|
||||
*/
|
||||
enum comp_format
|
||||
{
|
||||
PF_UNKNOWN = 0,
|
||||
PF_INDEXED_24, // studio model skins
|
||||
PF_INDEXED_32, // sprite 32-bit palette
|
||||
PF_RGBA_32, // already prepared ".bmp", ".tga" or ".jpg" image
|
||||
PF_ARGB_32, // uncompressed dds image
|
||||
PF_ABGR_64, // uint image
|
||||
PF_RGB_24, // uncompressed dds or another 24-bit image
|
||||
PF_DXT1, // nvidia DXT1 format
|
||||
PF_DXT2, // nvidia DXT2 format
|
||||
PF_DXT3, // nvidia DXT3 format
|
||||
PF_DXT4, // nvidia DXT5 format
|
||||
PF_DXT5, // nvidia DXT5 format
|
||||
PF_RXGB, // doom3 normal maps
|
||||
PF_ATI1N, // ati 1N texture
|
||||
PF_ATI2N, // ati 2N texture
|
||||
PF_LUMINANCE, // b&w dds image
|
||||
PF_LUMINANCE_16, // b&w hi-res image
|
||||
PF_LUMINANCE_ALPHA, // b&w dds image with alpha channel
|
||||
PF_R_16F, // red channel half-float image
|
||||
PF_R_32F, // red channel float image
|
||||
PF_GR_32F, // Green-Red channels half-float image (dudv maps)
|
||||
PF_GR_64F, // Green-Red channels float image (dudv maps)
|
||||
PF_ABGR_64F, // ABGR half-float image
|
||||
PF_ABGR_128F, // ABGR float image
|
||||
PF_RGBA_GN, // internal generated texture
|
||||
PF_TOTALCOUNT, // must be last
|
||||
};
|
||||
|
||||
typedef struct bpc_desc_s
|
||||
{
|
||||
int format; // pixelformat
|
||||
char name[8]; // used for debug
|
||||
uint glmask; // RGBA mask
|
||||
uint gltype; // pixel size (byte, short etc)
|
||||
int bpp; // channels (e.g. rgb = 3, rgba = 4)
|
||||
int bpc; // sizebytes (byte, short, float)
|
||||
int block; // blocksize < 0 needs alternate calc
|
||||
} bpc_desc_t;
|
||||
|
||||
static const bpc_desc_t PFDesc[] =
|
||||
{
|
||||
{PF_UNKNOWN, "raw", 0x1908, 0x1401, 0, 0, 0 },
|
||||
{PF_INDEXED_24, "pal 24", 0x1908, 0x1401, 1, 1, 0 }, // expand data to RGBA buffer
|
||||
{PF_INDEXED_32, "pal 32", 0x1908, 0x1401, 1, 1, 0 },
|
||||
{PF_RGBA_32, "RGBA 32",0x1908, 0x1401, 4, 1, -4 },
|
||||
{PF_ARGB_32, "ARGB 32",0x1908, 0x1401, 4, 1, -4 },
|
||||
{PF_ABGR_64, "ABGR 64",0x80E1, 0x1401, 4, 2, -8 },
|
||||
{PF_RGB_24, "RGB 24", 0x1908, 0x1401, 3, 1, -3 },
|
||||
{PF_DXT1, "DXT1", 0x1908, 0x1401, 4, 1, 8 },
|
||||
{PF_DXT2, "DXT2", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_DXT3, "DXT3", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_DXT4, "DXT4", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_DXT5, "DXT5", 0x1908, 0x1401, 4, 1, 16 },
|
||||
{PF_RXGB, "RXGB", 0x1908, 0x1401, 3, 1, 16 },
|
||||
{PF_ATI1N, "ATI1N", 0x1908, 0x1401, 1, 1, 8 },
|
||||
{PF_ATI2N, "3DC", 0x1908, 0x1401, 3, 1, 16 },
|
||||
{PF_LUMINANCE, "LUM 8", 0x1909, 0x1401, 1, 1, -1 },
|
||||
{PF_LUMINANCE_16, "LUM 16", 0x1909, 0x1401, 2, 2, -2 },
|
||||
{PF_LUMINANCE_ALPHA,"LUM A", 0x190A, 0x1401, 2, 1, -2 },
|
||||
{PF_R_16F, "R 16f", 0x8884, 0x1406, 1, 4, -2 }, // FIXME: these NV extension, reinstall for ATI
|
||||
{PF_R_32F, "R 32f", 0x8885, 0x1406, 1, 4, -4 },
|
||||
{PF_GR_32F, "GR 32f", 0x8886, 0x1406, 2, 4, -4 },
|
||||
{PF_GR_64F, "GR 64f", 0x8887, 0x1406, 2, 4, -8 },
|
||||
{PF_ABGR_64F, "ABGR64f",0x888A, 0x1406, 4, 2, -8 },
|
||||
{PF_ABGR_128F, "ABGR128",0x888B, 0x1406, 4, 4, -16},
|
||||
{PF_RGBA_GN, "system", 0x1908, 0x1401, 4, 1, -4 },
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IL_DDS_HARDWARE = BIT(0), // instance have dds hardware support (disable software unpacker)
|
||||
IL_ATI_FLOAT_EXT = BIT(1), // reinstall float images glmask for ati extensions
|
||||
IL_NV_FLOAT_EXT = BIT(2), // reinstall float images glmask for nv extensions
|
||||
IL_USE_LERPING = BIT(3), // lerping images during resample
|
||||
IL_KEEP_8BIT = BIT(4), // don't expand paletted images
|
||||
IL_ALLOW_OVERWRITE = BIT(5), // allow to overwrite stored images
|
||||
} ilFlags_t;
|
||||
|
||||
// rgbdata output flags
|
||||
typedef enum
|
||||
{
|
||||
// rgbdata->flags
|
||||
IMAGE_CUBEMAP = BIT(0), // it's 6-sides cubemap buffer
|
||||
IMAGE_HAVE_ALPHA = BIT(1), // image contain alpha-channel
|
||||
IMAGE_COLORINDEX = BIT(2), // all colors in palette is gradients of last color (decals)
|
||||
IMAGE_PREMULT = BIT(3), // need to premultiply alpha (DXT2, DXT4)
|
||||
IMAGE_S3 = BIT(4), // s&3 image
|
||||
|
||||
// manipulation flags
|
||||
IMAGE_FLIP_X = BIT(16), // flip the image by width
|
||||
IMAGE_FLIP_Y = BIT(17), // flip the image by height
|
||||
IMAGE_ROT_90 = BIT(18), // flip from upper left corner to down right corner
|
||||
IMAGE_ROT180 = IMAGE_FLIP_X|IMAGE_FLIP_Y,
|
||||
IMAGE_ROT270 = IMAGE_FLIP_X|IMAGE_FLIP_Y|IMAGE_ROT_90,
|
||||
IMAGE_ROUND = BIT(19), // round image to nearest Pow2
|
||||
IMAGE_RESAMPLE = BIT(20), // resample image to specified dims
|
||||
IMAGE_PALTO24 = BIT(21), // turn 32-bit palette into 24-bit mode (only for indexed images)
|
||||
IMAGE_DXTTO32 = BIT(22), // force to use software dds loader (render requires for some reasons)
|
||||
} imgFlags_t;
|
||||
|
||||
typedef struct rgbdata_s
|
||||
{
|
||||
int width; // image width
|
||||
int height; // image height
|
||||
byte numLayers; // multi-layer volume
|
||||
byte numMips; // mipmap count
|
||||
byte bitsCount; // RGB bits count
|
||||
uint type; // compression type
|
||||
uint flags; // misc image flags
|
||||
byte *palette; // palette if present
|
||||
byte *buffer; // image buffer
|
||||
size_t size; // for bounds checking
|
||||
} rgbdata_t;
|
||||
|
||||
enum dev_level
|
||||
{
|
||||
D_INFO = 1, // "-dev 1", shows various system messages
|
||||
D_WARN, // "-dev 2", shows not critical system warnings
|
||||
D_ERROR, // "-dev 3", shows critical warnings
|
||||
D_LOAD, // "-dev 4", show messages about loading resources
|
||||
D_NOTE, // "-dev 5", show system notifications for engine develeopers
|
||||
D_MEMORY, // "-dev 6", show memory allocation
|
||||
D_STRING, // "-dev 7", show tempstrings allocation
|
||||
};
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
STDLIB SYSTEM INTERFACE
|
||||
==============================================================================
|
||||
*/
|
||||
typedef struct stdilib_api_s
|
||||
{
|
||||
// interface validator
|
||||
size_t api_size; // must matched with sizeof(stdlib_api_t)
|
||||
|
||||
// base events
|
||||
void (*instance)( const char *name, const char *fmsg ); // restart engine with new instance
|
||||
void (*print)( const char *msg ); // basic text message
|
||||
void (*printf)( const char *msg, ... ); // formatted text message
|
||||
void (*dprintf)( int level, const char *msg, ...); // developer text message
|
||||
void (*error)( const char *msg, ... ); // abnormal termination with message
|
||||
void (*abort)( const char *msg, ... ); // normal tremination with message
|
||||
void (*exit)( void ); // normal silent termination
|
||||
void (*sleep)( int msec ); // sleep for some msec
|
||||
char *(*clipboard)( void ); // get clipboard data
|
||||
void (*queevent)( dword time, ev_type_t type, int value, int value2, int length, void *ptr );
|
||||
sys_event_t (*getevent)( void ); // get system events
|
||||
|
||||
// crclib.c funcs
|
||||
void (*crc_init)(word *crcvalue); // set initial crc value
|
||||
word (*crc_block)(byte *start, int count); // calculate crc block
|
||||
void (*crc_process)(word *crcvalue, byte data); // process crc byte
|
||||
byte (*crc_sequence)(byte *base, int length, int sequence); // calculate crc for sequence
|
||||
uint (*crc_blockchecksum)(void *buffer, int length); // map checksum
|
||||
uint (*crc_blockchecksumkey)(void *buf, int len, int key); // process key checksum
|
||||
|
||||
// memlib.c funcs
|
||||
void (*memcpy)(void *dest, const void *src, size_t size, const char *file, int line);
|
||||
void (*memset)(void *dest, int set, size_t size, const char *filename, int fileline);
|
||||
void *(*realloc)(byte *pool, void *mem, size_t size, const char *file, int line);
|
||||
void (*move)(byte *pool, void **dest, void *src, size_t size, const char *file, int line); // not a memmove
|
||||
void *(*malloc)(byte *pool, size_t size, const char *file, int line);
|
||||
void (*free)(void *data, const char *file, int line);
|
||||
|
||||
// xash memlib extension - memory pools
|
||||
byte *(*mallocpool)(const char *name, const char *file, int line);
|
||||
void (*freepool)(byte **poolptr, const char *file, int line);
|
||||
void (*clearpool)(byte *poolptr, const char *file, int line);
|
||||
void (*memcheck)(const char *file, int line); // check memory pools for consistensy
|
||||
|
||||
// xash memlib extension - memory arrays
|
||||
byte *(*newarray)( byte *pool, size_t elementsize, int count, const char *file, int line );
|
||||
void (*delarray)( byte *array, const char *file, int line );
|
||||
void *(*newelement)( byte *array, const char *file, int line );
|
||||
void (*delelement)( byte *array, void *element, const char *file, int line );
|
||||
void *(*getelement)( byte *array, size_t index );
|
||||
size_t (*arraysize)( byte *arrayptr );
|
||||
|
||||
// network.c funcs
|
||||
void (*NET_Init)( void );
|
||||
void (*NET_Shutdown)( void );
|
||||
void (*NET_ShowIP)( void );
|
||||
void (*NET_Config)( bool net_enable );
|
||||
char *(*NET_AdrToString)( netadr_t a );
|
||||
bool (*NET_IsLANAddress)( netadr_t adr );
|
||||
bool (*NET_StringToAdr)( const char *s, netadr_t *a );
|
||||
void (*NET_SendPacket)( int length, const void *data, netadr_t to );
|
||||
|
||||
// common functions
|
||||
void (*Com_InitRootDir)( char *path ); // init custom rootdir
|
||||
void (*Com_LoadGameInfo)( const char *filename ); // gate game info from script file
|
||||
void (*Com_AddGameHierarchy)(const char *dir); // add base directory in search list
|
||||
int (*Com_CheckParm)( const char *parm ); // check parm in cmdline
|
||||
bool (*Com_GetParm)( char *parm, char *out ); // get parm from cmdline
|
||||
void (*Com_FileBase)(const char *in, char *out); // get filename without path & ext
|
||||
bool (*Com_FileExists)(const char *filename); // return true if file exist
|
||||
long (*Com_FileSize)(const char *filename); // same as Com_FileExists but return filesize
|
||||
long (*Com_FileTime)(const char *filename); // same as Com_FileExists but return filetime
|
||||
const char *(*Com_FileExtension)(const char *in); // return extension of file
|
||||
const char *(*Com_RemovePath)(const char *in); // return file without path
|
||||
void (*Com_StripExtension)(char *path); // remove extension if present
|
||||
void (*Com_StripFilePath)(const char* const src, char* dst);// get file path without filename.ext
|
||||
void (*Com_DefaultExtension)(char *path, const char *ext ); // append extension if not present
|
||||
void (*Com_ClearSearchPath)( void ); // delete all search pathes
|
||||
void (*Com_CreateThread)(int, bool, void(*fn)(int)); // run individual thread
|
||||
void (*Com_ThreadLock)( void ); // lock current thread
|
||||
void (*Com_ThreadUnlock)( void ); // unlock numthreads
|
||||
int (*Com_NumThreads)( void ); // returns count of active threads
|
||||
bool (*Com_LoadScript)(const char *name,char *buf,int size);// load script into stack from file or bufer
|
||||
bool (*Com_AddScript)(const char *name,char *buf, int size);// include script from file or buffer
|
||||
void (*Com_ResetScript)( void ); // reset current script state
|
||||
void (*Com_PushScript)( const char **data_p ); // save script to stack
|
||||
void (*Com_PopScript)( const char **data_p ); // restore script from stack
|
||||
void (*Com_SkipBracedSection)( char **data_p, int depth ); // skip braced section
|
||||
char *(*Com_ReadToken)( bool newline ); // get next token on a line or newline
|
||||
bool (*Com_TryToken)( void ); // return 1 if have token on a line
|
||||
void (*Com_FreeToken)( void ); // free current token to may get it again
|
||||
void (*Com_SkipToken)( void ); // skip current token and jump into newline
|
||||
bool (*Com_MatchToken)( const char *match ); // compare current token with user keyword
|
||||
bool (*Com_ParseToken_Simple)(const char **data_p); // basic parse (can't handle single characters)
|
||||
char *(*Com_ParseToken)(const char **data, bool newline ); // parse token from char buffer
|
||||
char *(*Com_ParseWord)( const char **data, bool newline ); // parse word from char buffer
|
||||
search_t *(*Com_Search)(const char *pattern, int casecmp ); // returned list of found files
|
||||
bool (*Com_Filter)(char *filter, char *name, int casecmp ); // compare keyword by mask with filter
|
||||
uint (*Com_HashKey)( const char *string, uint hashSize ); // returns hash key for a string
|
||||
byte *(*Com_LoadRes)( const char *filename, size_t *size ); // find internal resource in baserc.dll
|
||||
long com_scriptline; // contains current scriptline
|
||||
char *com_token; // contains current token
|
||||
|
||||
// console variables
|
||||
cvar_t *(*Cvar_Get)(const char *name, const char *value, int flags, const char *desc);
|
||||
void (*Cvar_LookupVars)( int checkbit, void *buffer, void *ptr, setpair_t callback );
|
||||
void (*Cvar_SetString)( const char *name, const char *value );
|
||||
void (*Cvar_SetLatched)( const char *name, const char *value);
|
||||
void (*Cvar_FullSet)( char *name, char *value, int flags );
|
||||
void (*Cvar_SetValue )( const char *name, float value);
|
||||
float (*Cvar_GetValue )(const char *name);
|
||||
char *(*Cvar_GetString)(const char *name);
|
||||
cvar_t *(*Cvar_FindVar)(const char *name);
|
||||
bool userinfo_modified; // tell to client about userinfo modified
|
||||
|
||||
// console commands
|
||||
void (*Cmd_Exec)(int exec_when, const char *text); // process cmd buffer
|
||||
uint (*Cmd_Argc)( void );
|
||||
char *(*Cmd_Args)( void );
|
||||
char *(*Cmd_Argv)( uint arg );
|
||||
void (*Cmd_LookupCmds)( char *buffer, void *ptr, setpair_t callback );
|
||||
void (*Cmd_AddCommand)(const char *name, xcommand_t function, const char *desc);
|
||||
void (*Cmd_TokenizeString)(const char *text_in);
|
||||
void (*Cmd_DelCommand)(const char *name);
|
||||
|
||||
// real filesystem
|
||||
file_t *(*fopen)(const char* path, const char* mode); // same as fopen
|
||||
int (*fclose)(file_t* file); // same as fclose
|
||||
long (*fwrite)(file_t* file, const void* data, size_t datasize); // same as fwrite
|
||||
long (*fread)(file_t* file, void* buffer, size_t buffersize); // same as fread, can see trough pakfile
|
||||
int (*fprint)(file_t* file, const char *msg); // printed message into file
|
||||
int (*fprintf)(file_t* file, const char* format, ...); // same as fprintf
|
||||
int (*fgets)(file_t* file, byte *string, size_t bufsize ); // like a fgets, but can return EOF
|
||||
int (*fseek)(file_t* file, fs_offset_t offset, int whence); // fseek, can seek in packfiles too
|
||||
bool (*fremove)( const char *path ); // remove sepcified file
|
||||
long (*ftell)(file_t* file); // like a ftell
|
||||
|
||||
// virtual filesystem
|
||||
vfile_t *(*vfcreate)( const byte *buffer, size_t buffsize ); // create virtual stream
|
||||
vfile_t *(*vfopen)(file_t *handle, const char* mode); // virtual fopen
|
||||
file_t *(*vfclose)(vfile_t* file); // free buffer or write dump
|
||||
long (*vfwrite)(vfile_t* file, const void* buf, size_t datasize); // write into buffer
|
||||
long (*vfread)(vfile_t* file, void* buffer, size_t buffersize); // read from buffer
|
||||
int (*vfgets)(vfile_t* file, byte *string, size_t bufsize ); // read text line
|
||||
int (*vfprint)(vfile_t* file, const char *msg); // write message
|
||||
int (*vfprintf)(vfile_t* file, const char* format, ...); // write formatted message
|
||||
int (*vfseek)(vfile_t* file, fs_offset_t offset, int whence); // fseek, can seek in packfiles too
|
||||
bool (*vfunpack)( void* comp, size_t size1, void **buf, size_t size2);// deflate zipped buffer
|
||||
byte *(*vfbuffer)( vfile_t *file ); // get pointer to virtual filebuff
|
||||
long (*vftell)(vfile_t* file); // like a ftell
|
||||
bool (*vfeof)( vfile_t* file); // like a feof
|
||||
|
||||
// wadstorage filesystem
|
||||
int (*wfcheck)( const char *filename ); // validate container
|
||||
wfile_t *(*wfopen)( const char *filename, const char *mode ); // open wad file or create new
|
||||
void (*wfclose)( wfile_t *wad ); // close wadfile
|
||||
long (*wfwrite)( wfile_t *wad, const char *lump, const void* data, size_t datasize, char type, char cmp );
|
||||
byte *(*wfread)( wfile_t *wad, const char *lump, size_t *lumpsizeptr, const char type );
|
||||
|
||||
// filesystem simply user interface
|
||||
byte *(*Com_LoadFile)(const char *path, long *filesize ); // load file into heap
|
||||
bool (*Com_WriteFile)(const char *path, const void *data, long len ); // write file into disk
|
||||
bool (*Com_LoadLibrary)( dll_info_t *dll ); // load library
|
||||
bool (*Com_FreeLibrary)( dll_info_t *dll ); // free library
|
||||
void*(*Com_GetProcAddress)( dll_info_t *dll, const char* name ); // gpa
|
||||
double (*Com_DoubleTime)( void ); // hi-res timer
|
||||
dword (*Com_Milliseconds)( void ); // hi-res timer
|
||||
|
||||
// built-in imagelib functions
|
||||
void (*ImglibSetup)( const char *formats, const uint flags ); // set main attributes
|
||||
rgbdata_t *(*ImageLoad)( const char *, const byte *, size_t ); // load image from disk or buffer
|
||||
void (*ImageSave)( const char *name, int format, rgbdata_t *image ); // save image into specified format
|
||||
void (*ImageConvert)( rgbdata_t **pix, int w, int h, uint flags ); // image manipulations
|
||||
void (*ImageFree)( rgbdata_t *pack ); // release image buffer
|
||||
|
||||
// random generator
|
||||
long (*Com_RandomLong)( long lMin, long lMax ); // returns random integer
|
||||
float (*Com_RandomFloat)( float fMin, float fMax ); // returns random float
|
||||
|
||||
// stdlib.c funcs
|
||||
void (*strnupr)(const char *in, char *out, size_t size_out); // convert string to upper case
|
||||
void (*strnlwr)(const char *in, char *out, size_t size_out); // convert string to lower case
|
||||
void (*strupr)(const char *in, char *out); // convert string to upper case
|
||||
void (*strlwr)(const char *in, char *out); // convert string to lower case
|
||||
int (*strlen)( const char *string ); // returns string real length
|
||||
int (*cstrlen)( const char *string ); // return string length without color prefixes
|
||||
char (*toupper)(const char in ); // convert one charcster to upper case
|
||||
char (*tolower)(const char in ); // convert one charcster to lower case
|
||||
size_t (*strncat)(char *dst, const char *src, size_t n); // add new string at end of buffer
|
||||
size_t (*strcat)(char *dst, const char *src); // add new string at end of buffer
|
||||
size_t (*strncpy)(char *dst, const char *src, size_t n); // copy string to existing buffer
|
||||
size_t (*strcpy)(char *dst, const char *src); // copy string to existing buffer
|
||||
char *(*stralloc)(byte *mp,const char *in,const char *file,int line); // create buffer and copy string here
|
||||
int (*atoi)(const char *str); // convert string to integer
|
||||
float (*atof)(const char *str); // convert string to float
|
||||
void (*atov)( float *dst, const char *src, size_t n ); // convert string to vector
|
||||
char *(*strchr)(const char *s, char c); // find charcster in string at left side
|
||||
char *(*strrchr)(const char *s, char c); // find charcster in string at right side
|
||||
int (*strnicmp)(const char *s1, const char *s2, int n); // compare strings with case insensative
|
||||
int (*stricmp)(const char *s1, const char *s2); // compare strings with case insensative
|
||||
int (*strncmp)(const char *s1, const char *s2, int n); // compare strings with case sensative
|
||||
int (*strcmp)(const char *s1, const char *s2); // compare strings with case sensative
|
||||
char *(*stristr)( const char *s1, const char *s2 ); // find s2 in s1 with case insensative
|
||||
char *(*strstr)( const char *s1, const char *s2 ); // find s2 in s1 with case sensative
|
||||
size_t (*strpack)( byte *buf, size_t pos, char *s1, int n ); // include string into buffer (same as strncat)
|
||||
size_t (*strunpack)( byte *buf, size_t pos, char *s1 ); // extract string from buffer
|
||||
int (*vsprintf)(char *buf, const char *fmt, va_list args); // format message
|
||||
int (*sprintf)(char *buffer, const char *format, ...); // print into buffer
|
||||
char *(*va)(const char *format, ...); // print into temp buffer
|
||||
int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list args); // format message
|
||||
int (*snprintf)(char *buffer, size_t buffersize, const char *format, ...); // print into buffer
|
||||
const char* (*timestamp)( int format ); // returns current time stamp
|
||||
|
||||
// stringtable system
|
||||
int (*st_create)( const char *name, size_t max_strings );
|
||||
const char *(*st_getstring)( int handle, string_t index );
|
||||
string_t (*st_setstring)( int handle, const char *string );
|
||||
int (*st_load)( wfile_t *wad, const char *name );
|
||||
bool (*st_save)( int h, wfile_t *wad );
|
||||
void (*st_remove)( int handle );
|
||||
|
||||
// misc utils
|
||||
gameinfo_t *GameInfo; // user game info (filled by engine)
|
||||
|
||||
} stdlib_api_t;
|
||||
|
||||
// command buffer modes
|
||||
#define EXEC_NOW 0
|
||||
#define EXEC_INSERT 1
|
||||
#define EXEC_APPEND 2
|
||||
|
||||
// timestamp modes
|
||||
#define TIME_FULL 0
|
||||
#define TIME_DATE_ONLY 1
|
||||
#define TIME_TIME_ONLY 2
|
||||
#define TIME_NO_SECONDS 3
|
||||
|
||||
// cvar flags
|
||||
#define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
|
||||
#define CVAR_USERINFO 2 // added to userinfo when changed
|
||||
#define CVAR_SERVERINFO 4 // added to serverinfo when changed
|
||||
#define CVAR_SYSTEMINFO 8 // don't changed from console, saved into config.dll
|
||||
#define CVAR_INIT 16 // don't allow change from console at all, but can be set from the command line
|
||||
#define CVAR_LATCH 32 // save changes until server restart
|
||||
#define CVAR_READ_ONLY 64 // display only, cannot be set by user at all
|
||||
#define CVAR_USER_CREATED 128 // created by a set command (prvm used)
|
||||
#define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived
|
||||
#define CVAR_CHEAT 512 // can not be changed if cheats are disabled
|
||||
#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
|
||||
#define CVAR_MAXFLAGSVAL 2047 // maximum number of flags
|
||||
|
||||
#ifndef LAUNCH_DLL
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
STDLIB GENERIC ALIAS NAMES
|
||||
don't add aliases for launch.dll so it will be conflicted width real names
|
||||
==============================================================================
|
||||
*/
|
||||
/*
|
||||
==========================================
|
||||
memory manager funcs
|
||||
==========================================
|
||||
*/
|
||||
#define Mem_Alloc(pool, size) com.malloc(pool, size, __FILE__, __LINE__)
|
||||
#define Mem_Realloc(pool, ptr, size) com.realloc(pool, ptr, size, __FILE__, __LINE__)
|
||||
#define Mem_Move(pool, ptr, data, size) com.move(pool, ptr, data, size, __FILE__, __LINE__)
|
||||
#define Mem_Free(mem) com.free(mem, __FILE__, __LINE__)
|
||||
#define Mem_AllocPool(name) com.mallocpool(name, __FILE__, __LINE__)
|
||||
#define Mem_FreePool(pool) com.freepool(pool, __FILE__, __LINE__)
|
||||
#define Mem_EmptyPool(pool) com.clearpool(pool, __FILE__, __LINE__)
|
||||
#define Mem_Copy(dest, src, size ) com.memcpy(dest, src, size, __FILE__, __LINE__)
|
||||
#define Mem_Set(dest, val, size ) com.memcpy(dest, val, size, __FILE__, __LINE__)
|
||||
#define Mem_Check() com.memcheck(__FILE__, __LINE__)
|
||||
#define Mem_CreateArray( p, s, n ) com.newarray( p, s, n, __FILE__, __LINE__)
|
||||
#define Mem_RemoveArray( array ) com.delarray( array, __FILE__, __LINE__)
|
||||
#define Mem_AllocElement( array ) com.newelement( array, __FILE__, __LINE__)
|
||||
#define Mem_FreeElement( array, el ) com.delelement( array, el, __FILE__, __LINE__ )
|
||||
#define Mem_GetElement( array, idx ) com.getelement( array, idx )
|
||||
#define Mem_ArraySize( array ) com.arraysize( array )
|
||||
|
||||
/*
|
||||
==========================================
|
||||
parsing manager funcs
|
||||
==========================================
|
||||
*/
|
||||
#define Com_ParseToken com.Com_ParseToken
|
||||
#define Com_ParseWord com.Com_ParseWord
|
||||
#define Com_SimpleGetToken com.Com_ParseToken_Simple
|
||||
#define Com_SkipBracedSection com.Com_SkipBracedSection
|
||||
#define Com_Filter com.Com_Filter
|
||||
#define Com_HashKey com.Com_HashKey
|
||||
#define Com_LoadScript com.Com_LoadScript
|
||||
#define Com_IncludeScript com.Com_AddScript
|
||||
#define Com_ResetScript com.Com_ResetScript
|
||||
#define Com_GetToken com.Com_ReadToken
|
||||
#define Com_TryToken com.Com_TryToken
|
||||
#define Com_FreeToken com.Com_FreeToken
|
||||
#define Com_SkipToken com.Com_SkipToken
|
||||
#define Com_MatchToken com.Com_MatchToken
|
||||
#define Com_PushScript com.Com_PushScript
|
||||
#define Com_PopScript com.Com_PopScript
|
||||
#define com_token com.com_token
|
||||
#define scriptline com.com_scriptline
|
||||
#define g_TXcommand com.GameInfo->TXcommand
|
||||
#define g_Instance com.GameInfo->instance
|
||||
|
||||
/*
|
||||
===========================================
|
||||
filesystem manager
|
||||
===========================================
|
||||
*/
|
||||
#define FS_AddGameHierarchy com.Com_AddGameHierarchy
|
||||
#define FS_LoadGameInfo com.Com_LoadGameInfo
|
||||
#define FS_InitRootDir com.Com_InitRootDir
|
||||
#define FS_LoadFile com.Com_LoadFile
|
||||
#define FS_Search com.Com_Search
|
||||
#define FS_WriteFile com.Com_WriteFile
|
||||
#define FS_Open( path, mode ) com.fopen( path, mode )
|
||||
#define FS_Read( file, buffer, size ) com.fread( file, buffer, size )
|
||||
#define FS_Write( file, buffer, size ) com.fwrite( file, buffer, size )
|
||||
#define FS_StripExtension( path ) com.Com_StripExtension( path )
|
||||
#define FS_ExtractFilePath( src, dest) com.Com_StripFilePath( src, dest )
|
||||
#define FS_DefaultExtension com.Com_DefaultExtension
|
||||
#define FS_FileExtension( ext ) com.Com_FileExtension( ext )
|
||||
#define FS_FileExists( file ) com.Com_FileExists( file )
|
||||
#define FS_FileSize( file ) com.Com_FileSize( file )
|
||||
#define FS_FileTime( file ) com.Com_FileTime( file )
|
||||
#define FS_Close( file ) com.fclose( file )
|
||||
#define FS_FileBase( x, y ) com.Com_FileBase( x, y )
|
||||
#define FS_LoadInternal( x, y ) com.Com_LoadRes( x, y )
|
||||
#define FS_Printf com.fprintf
|
||||
#define FS_Print com.fprint
|
||||
#define FS_Seek com.fseek
|
||||
#define FS_Tell com.ftell
|
||||
#define FS_Gets com.fgets
|
||||
#define FS_Gamedir com.GameInfo->gamedir
|
||||
#define FS_Title com.GameInfo->title
|
||||
#define FS_ClearSearchPath com.Com_ClearSearchPath
|
||||
#define FS_CheckParm com.Com_CheckParm
|
||||
#define FS_GetParmFromCmdLine com.Com_GetParm
|
||||
|
||||
/*
|
||||
===========================================
|
||||
network messages
|
||||
===========================================
|
||||
*/
|
||||
#define NET_Init com.NET_Init
|
||||
#define NET_Shutdown com.NET_Shutdown
|
||||
#define NET_ShowIP com.NET_ShowIP
|
||||
#define NET_Config com.NET_Config
|
||||
#define NET_AdrToString com.NET_AdrToString
|
||||
#define NET_IsLANAddress com.NET_IsLANAddress
|
||||
#define Sys_StringToAdr com.NET_StringToAdr
|
||||
#define Sys_SendPacket com.NET_SendPacket
|
||||
|
||||
/*
|
||||
===========================================
|
||||
console variables
|
||||
===========================================
|
||||
*/
|
||||
#define Cvar_Get com.Cvar_Get
|
||||
#define Cvar_LookupVars com.Cvar_LookupVars
|
||||
#define Cvar_Set com.Cvar_SetString
|
||||
#define Cvar_FullSet com.Cvar_FullSet
|
||||
#define Cvar_SetLatched com.Cvar_SetLatched
|
||||
#define Cvar_SetValue com.Cvar_SetValue
|
||||
#define Cvar_VariableValue com.Cvar_GetValue
|
||||
#define Cvar_VariableString com.Cvar_GetString
|
||||
#define Cvar_FindVar com.Cvar_FindVar
|
||||
#define userinfo_modified com.userinfo_modified
|
||||
|
||||
/*
|
||||
===========================================
|
||||
console commands
|
||||
===========================================
|
||||
*/
|
||||
#define Cbuf_ExecuteText com.Cmd_Exec
|
||||
#define Cbuf_AddText( text ) com.Cmd_Exec( EXEC_APPEND, text )
|
||||
#define Cmd_ExecuteString( text ) com.Cmd_Exec( EXEC_NOW, text )
|
||||
#define Cbuf_InsertText( text ) com.Cmd_Exec( EXEC_INSERT, text )
|
||||
#define Cbuf_Execute() com.Cmd_Exec( EXEC_NOW, NULL )
|
||||
|
||||
#define Cmd_Argc com.Cmd_Argc
|
||||
#define Cmd_Args com.Cmd_Args
|
||||
#define Cmd_Argv com.Cmd_Argv
|
||||
#define Cmd_TokenizeString com.Cmd_TokenizeString
|
||||
#define Cmd_LookupCmds com.Cmd_LookupCmds
|
||||
#define Cmd_AddCommand com.Cmd_AddCommand
|
||||
#define Cmd_RemoveCommand com.Cmd_DelCommand
|
||||
|
||||
/*
|
||||
===========================================
|
||||
virtual filesystem manager
|
||||
===========================================
|
||||
*/
|
||||
#define VFS_Create com.vfcreate
|
||||
#define VFS_GetBuffer com.vfbuffer
|
||||
#define VFS_Open com.vfopen
|
||||
#define VFS_Write com.vfwrite
|
||||
#define VFS_Read com.vfread
|
||||
#define VFS_Print com.vfprint
|
||||
#define VFS_Printf com.vfprintf
|
||||
#define VFS_Gets com.vfgets
|
||||
#define VFS_Seek com.vfseek
|
||||
#define VFS_Tell com.vftell
|
||||
#define VFS_Eof com.vfeof
|
||||
#define VFS_Close com.vfclose
|
||||
#define VFS_Unpack com.vfunpack
|
||||
|
||||
/*
|
||||
===========================================
|
||||
wadstorage filesystem manager
|
||||
===========================================
|
||||
*/
|
||||
#define WAD_Open com.wfopen
|
||||
#define WAD_Check com.wfcheck
|
||||
#define WAD_Close com.wfclose
|
||||
#define WAD_Write com.wfwrite
|
||||
#define WAD_Read com.wfread
|
||||
|
||||
/*
|
||||
===========================================
|
||||
crclib manager
|
||||
===========================================
|
||||
*/
|
||||
#define CRC_Init com.crc_init
|
||||
#define CRC_Block com.crc_block
|
||||
#define CRC_ProcessByte com.crc_process
|
||||
#define CRC_Sequence com.crc_sequence
|
||||
#define Com_BlockChecksum com.crc_blockchecksum
|
||||
#define Com_BlockChecksumKey com.crc_blockchecksumkey
|
||||
|
||||
/*
|
||||
===========================================
|
||||
imglib manager
|
||||
===========================================
|
||||
*/
|
||||
#define FS_LoadImage com.ImageLoad
|
||||
#define FS_SaveImage com.ImageSave
|
||||
#define FS_FreeImage com.ImageFree
|
||||
#define Image_Init com.ImglibSetup
|
||||
#define Image_Process com.ImageConvert
|
||||
|
||||
/*
|
||||
===========================================
|
||||
misc utils
|
||||
===========================================
|
||||
*/
|
||||
#define GI com.GameInfo
|
||||
#define Msg com.printf
|
||||
#define MsgDev com.dprintf
|
||||
#define Sys_LoadLibrary com.Com_LoadLibrary
|
||||
#define Sys_FreeLibrary com.Com_FreeLibrary
|
||||
#define Sys_GetProcAddress com.Com_GetProcAddress
|
||||
#define Sys_NewInstance com.instance
|
||||
#define Sys_Sleep com.sleep
|
||||
#define Sys_Print com.print
|
||||
#define Sys_GetEvent com.getevent
|
||||
#define Sys_QueEvent com.queevent
|
||||
#define Sys_GetClipboardData com.clipboard
|
||||
#define Sys_Quit com.exit
|
||||
#define Sys_Break com.abort
|
||||
#define Sys_DoubleTime com.Com_DoubleTime
|
||||
#define Sys_Milliseconds com.Com_Milliseconds
|
||||
#define GetNumThreads com.Com_NumThreads
|
||||
#define ThreadLock com.Com_ThreadLock
|
||||
#define ThreadUnlock com.Com_ThreadUnlock
|
||||
#define RunThreadsOnIndividual com.Com_CreateThread
|
||||
#define Com_RandomLong com.Com_RandomLong
|
||||
#define Com_RandomFloat com.Com_RandomFloat
|
||||
#define StringTable_Create com.st_create
|
||||
#define StringTable_Delete com.st_remove
|
||||
#define StringTable_GetString com.st_getstring
|
||||
#define StringTable_SetString com.st_setstring
|
||||
#define StringTable_Load com.st_load
|
||||
#define StringTable_Save com.st_save
|
||||
|
||||
/*
|
||||
===========================================
|
||||
stdlib function names that not across with windows stdlib
|
||||
===========================================
|
||||
*/
|
||||
#define timestamp com.timestamp
|
||||
#define copystring( str ) com.stralloc( NULL, str, __FILE__, __LINE__ )
|
||||
#define va com.va
|
||||
|
||||
#endif//LAUNCH_DLL
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
internal physic data
|
||||
|
||||
hold linear and angular velocity, current position stored too
|
||||
|
@ -939,27 +197,6 @@ typedef struct physdata_s
|
|||
physbody_t *body; // ptr to physic body
|
||||
} physdata_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
console variables
|
||||
|
||||
external and internal cvars struct have some differences
|
||||
========================================================================
|
||||
*/
|
||||
#ifndef LAUNCH_DLL
|
||||
typedef struct cvar_s
|
||||
{
|
||||
char *name;
|
||||
char *string; // normal string
|
||||
float value; // atof( string )
|
||||
int integer; // atoi( string )
|
||||
bool modified; // set each time the cvar is changed
|
||||
} cvar_t;
|
||||
#endif
|
||||
|
||||
// euler angle order
|
||||
#define PITCH 0
|
||||
#define YAW 1
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2008 ©
|
||||
// vprogs_api.h - xash virtual machine
|
||||
//=======================================================================
|
||||
#ifndef VPROGS_API_H
|
||||
#define VPROGS_API_H
|
||||
|
||||
#endif//VPROGS_API_H
|
|
@ -51,6 +51,9 @@ typedef struct
|
|||
GLuint glTarget;
|
||||
GLuint glSamples;
|
||||
|
||||
// image loader
|
||||
bool (*texImage)( GLuint, GLint, GLint, GLuint, GLuint, GLint, GLuint, const GLvoid* );
|
||||
|
||||
uint tflags; // TF_ flags
|
||||
uint flags; // IMAGE_ flags
|
||||
byte *pal;
|
||||
|
@ -232,7 +235,7 @@ void R_TextureList_f( void )
|
|||
Msg( "%4i: ", i );
|
||||
|
||||
Msg( "%4i %4i ", texture->width, texture->height );
|
||||
Msg("%3s", PFDesc[texture->type].name );
|
||||
Msg("%3s", PFDesc( texture->type )->name );
|
||||
|
||||
switch( texture->target )
|
||||
{
|
||||
|
@ -406,12 +409,12 @@ void R_SetPixelFormat( int width, int height, int depth )
|
|||
{
|
||||
int BlockSize;
|
||||
|
||||
BlockSize = PFDesc[image_desc.format].block;
|
||||
image_desc.bpp = PFDesc[image_desc.format].bpp;
|
||||
image_desc.bpc = PFDesc[image_desc.format].bpc;
|
||||
BlockSize = PFDesc( image_desc.format )->block;
|
||||
image_desc.bpp = PFDesc( image_desc.format )->bpp;
|
||||
image_desc.bpc = PFDesc( image_desc.format )->bpc;
|
||||
|
||||
image_desc.glMask = PFDesc[image_desc.format].glmask;
|
||||
image_desc.glType = PFDesc[image_desc.format].gltype;
|
||||
image_desc.glMask = PFDesc( image_desc.format )->glmask;
|
||||
image_desc.glType = PFDesc( image_desc.format )->gltype;
|
||||
|
||||
image_desc.numLayers = depth;
|
||||
image_desc.width = width;
|
||||
|
@ -439,69 +442,60 @@ bool R_GetPixelFormat( rgbdata_t *pic, uint tex_flags, float bumpScale )
|
|||
|
||||
if( !pic || !pic->buffer ) return false;
|
||||
Mem_EmptyPool( r_imagepool ); // flush buffers
|
||||
memset( &image_desc + MAX_STRING, 0, sizeof(image_desc) - MAX_STRING );
|
||||
for(i = 0; i < PF_TOTALCOUNT; i++)
|
||||
memset( &image_desc + MAX_STRING, 0, sizeof(image_desc) - MAX_STRING ); // FIXME
|
||||
|
||||
BlockSize = PFDesc( pic->type )->block;
|
||||
image_desc.bpp = PFDesc( pic->type )->bpp;
|
||||
image_desc.bpc = PFDesc( pic->type )->bpc;
|
||||
image_desc.glMask = PFDesc( pic->type )->glmask;
|
||||
image_desc.glType = PFDesc( pic->type )->gltype;
|
||||
image_desc.format = pic->type;
|
||||
|
||||
image_desc.numLayers = d = pic->numLayers;
|
||||
image_desc.width = w = pic->width;
|
||||
image_desc.height = h = pic->height;
|
||||
image_desc.flags = pic->flags;
|
||||
image_desc.tflags = tex_flags;
|
||||
|
||||
image_desc.bps = image_desc.width * image_desc.bpp * image_desc.bpc;
|
||||
image_desc.SizeOfPlane = image_desc.bps * image_desc.height;
|
||||
image_desc.SizeOfData = image_desc.SizeOfPlane * image_desc.numLayers;
|
||||
image_desc.BitsCount = pic->bitsCount;
|
||||
image_desc.bumpScale = bumpScale;
|
||||
|
||||
// now correct buffer size
|
||||
for( i = 0; i < pic->numMips; i++, totalsize += mipsize )
|
||||
{
|
||||
if(pic->type == PFDesc[i].format)
|
||||
{
|
||||
BlockSize = PFDesc[i].block;
|
||||
image_desc.bpp = PFDesc[i].bpp;
|
||||
image_desc.bpc = PFDesc[i].bpc;
|
||||
image_desc.glMask = PFDesc[i].glmask;
|
||||
image_desc.glType = PFDesc[i].gltype;
|
||||
image_desc.format = pic->type;
|
||||
break;
|
||||
}
|
||||
mipsize = R_GetImageSize( BlockSize, w, h, d, image_desc.bpp, image_desc.BitsCount / 8 );
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1;
|
||||
}
|
||||
|
||||
if( i != PF_TOTALCOUNT ) // make sure what match found
|
||||
if( tex_flags & ( TF_IMAGE2D|TF_SKYSIDE ))
|
||||
{
|
||||
image_desc.numLayers = d = pic->numLayers;
|
||||
image_desc.width = w = pic->width;
|
||||
image_desc.height = h = pic->height;
|
||||
image_desc.flags = pic->flags;
|
||||
image_desc.tflags = tex_flags;
|
||||
|
||||
image_desc.bps = image_desc.width * image_desc.bpp * image_desc.bpc;
|
||||
image_desc.SizeOfPlane = image_desc.bps * image_desc.height;
|
||||
image_desc.SizeOfData = image_desc.SizeOfPlane * image_desc.numLayers;
|
||||
image_desc.BitsCount = pic->bitsCount;
|
||||
image_desc.bumpScale = bumpScale;
|
||||
|
||||
// now correct buffer size
|
||||
for( i = 0; i < pic->numMips; i++, totalsize += mipsize )
|
||||
{
|
||||
mipsize = R_GetImageSize( BlockSize, w, h, d, image_desc.bpp, image_desc.BitsCount / 8 );
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1;
|
||||
}
|
||||
|
||||
if( tex_flags & ( TF_IMAGE2D|TF_SKYSIDE ))
|
||||
{
|
||||
// don't build mips for sky and hud pics
|
||||
image_desc.tflags &= ~TF_GEN_MIPMAPS;
|
||||
image_desc.MipCount = 1; // and ignore it to load
|
||||
}
|
||||
else if( pic->numMips > 1 )
|
||||
{
|
||||
// .dds, .wal or .mip image
|
||||
image_desc.tflags &= ~TF_GEN_MIPMAPS;
|
||||
image_desc.MipCount = pic->numMips;
|
||||
image_desc.tflags |= TF_MIPMAPS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// so it normal texture without mips
|
||||
image_desc.tflags |= (TF_MIPMAPS|TF_GEN_MIPMAPS);
|
||||
image_desc.MipCount = pic->numMips;
|
||||
}
|
||||
|
||||
if( image_desc.MipCount < 1 ) image_desc.MipCount = 1;
|
||||
image_desc.pal = pic->palette;
|
||||
|
||||
// check for permanent images
|
||||
if( image_desc.format == PF_RGBA_GN ) image_desc.tflags |= TF_STATIC;
|
||||
if( tex_flags & TF_IMAGE2D ) image_desc.tflags |= TF_STATIC;
|
||||
// don't build mips for sky and hud pics
|
||||
image_desc.tflags &= ~TF_GEN_MIPMAPS;
|
||||
image_desc.MipCount = 1; // and ignore it to load
|
||||
}
|
||||
else if( pic->numMips > 1 )
|
||||
{
|
||||
// .dds, .wal or .mip image
|
||||
image_desc.tflags &= ~TF_GEN_MIPMAPS;
|
||||
image_desc.MipCount = pic->numMips;
|
||||
image_desc.tflags |= TF_MIPMAPS;
|
||||
}
|
||||
else
|
||||
{
|
||||
// so it normal texture without mips
|
||||
image_desc.tflags |= (TF_MIPMAPS|TF_GEN_MIPMAPS);
|
||||
image_desc.MipCount = pic->numMips;
|
||||
}
|
||||
|
||||
if( image_desc.MipCount < 1 ) image_desc.MipCount = 1;
|
||||
image_desc.pal = pic->palette;
|
||||
|
||||
// check for permanent images
|
||||
if( image_desc.format == PF_RGBA_GN ) image_desc.tflags |= TF_STATIC;
|
||||
if( tex_flags & TF_IMAGE2D ) image_desc.tflags |= TF_STATIC;
|
||||
|
||||
// restore temp dimensions
|
||||
w = image_desc.width;
|
||||
|
@ -903,7 +897,7 @@ void GL_GenerateMipmaps( int width, int height )
|
|||
{
|
||||
// g-cont. because i'm don't know how to generate miplevels for GL_FLOAT or GL_SHORT_REV_1_bla_bla
|
||||
// ok, please show me videocard which don't supported GL_GENERATE_MIPMAP_SGIS ...
|
||||
MsgDev( D_ERROR, "GL_GenerateMipmaps: software mip generator failed on %s\n", PFDesc[image_desc.format].name );
|
||||
MsgDev( D_ERROR, "GL_GenerateMipmaps: software mip generator failed on %s\n", PFDesc( image_desc.format )->name );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -920,349 +914,21 @@ void GL_GenerateMipmaps( int width, int height )
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
qrsCompressedTexImage2D
|
||||
|
||||
cpu version of decompress dds
|
||||
===============
|
||||
*/
|
||||
bool qrsCompressedTexImage2D( uint target, int level, int internalformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
bool R_LoadImageDXT( GLuint target, GLint level, GLint intformat, GLuint width, GLuint height, GLint border, GLuint imageSize, const GLvoid* data )
|
||||
{
|
||||
color32 colours[4], *col;
|
||||
uint bits, bitmask, Offset;
|
||||
int scaled_width, scaled_height;
|
||||
word sAlpha, sColor0, sColor1;
|
||||
byte *fin, *fout = image_desc.source;
|
||||
byte alphas[8], *alpha, *alphamask;
|
||||
int w, h, x, y, z, i, j, k, Select;
|
||||
uint *scaled = (uint *)image_desc.scaled;
|
||||
bool has_alpha = false;
|
||||
GLuint dxtformat;
|
||||
|
||||
if (!data) return false;
|
||||
fin = (byte *)data;
|
||||
w = width;
|
||||
h = height;
|
||||
|
||||
switch( internalformat )
|
||||
switch( intformat )
|
||||
{
|
||||
case PF_DXT1:
|
||||
colours[0].a = 0xFF;
|
||||
colours[1].a = 0xFF;
|
||||
colours[2].a = 0xFF;
|
||||
|
||||
for (z = 0; z < image_desc.numLayers; z++)
|
||||
{
|
||||
for (y = 0; y < h; y += 4)
|
||||
{
|
||||
for (x = 0; x < w; x += 4)
|
||||
{
|
||||
sColor0 = *((word*)fin);
|
||||
sColor0 = LittleShort(sColor0);
|
||||
sColor1 = *((word*)(fin + 2));
|
||||
sColor1 = LittleShort(sColor1);
|
||||
|
||||
R_DXTReadColor(sColor0, colours);
|
||||
R_DXTReadColor(sColor1, colours + 1);
|
||||
|
||||
bitmask = ((uint*)fin)[1];
|
||||
bitmask = LittleLong( bitmask );
|
||||
fin += 8;
|
||||
|
||||
if (sColor0 > sColor1)
|
||||
{
|
||||
// Four-color block: derive the other two colors.
|
||||
// 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
|
||||
// These 2-bit codes correspond to the 2-bit fields
|
||||
// stored in the 64-bit block.
|
||||
colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3;
|
||||
colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3;
|
||||
colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3;
|
||||
colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3;
|
||||
colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3;
|
||||
colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3;
|
||||
colours[3].a = 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Three-color block: derive the other color.
|
||||
// 00 = color_0, 01 = color_1, 10 = color_2,
|
||||
// 11 = transparent.
|
||||
// These 2-bit codes correspond to the 2-bit fields
|
||||
// stored in the 64-bit block.
|
||||
colours[2].b = (colours[0].b + colours[1].b) / 2;
|
||||
colours[2].g = (colours[0].g + colours[1].g) / 2;
|
||||
colours[2].r = (colours[0].r + colours[1].r) / 2;
|
||||
colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3;
|
||||
colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3;
|
||||
colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3;
|
||||
colours[3].a = 0x00;
|
||||
}
|
||||
for (j = 0, k = 0; j < 4; j++)
|
||||
{
|
||||
for (i = 0; i < 4; i++, k++)
|
||||
{
|
||||
Select = (bitmask & (0x03 << k*2)) >> k*2;
|
||||
col = &colours[Select];
|
||||
|
||||
if (((x + i) < w) && ((y + j) < h))
|
||||
{
|
||||
uint ofs = z * image_desc.SizeOfPlane + (y + j) * image_desc.bps + (x + i) * image_desc.bpp;
|
||||
fout[ofs + 0] = col->r;
|
||||
fout[ofs + 1] = col->g;
|
||||
fout[ofs + 2] = col->b;
|
||||
fout[ofs + 3] = col->a;
|
||||
if(col->a == 0) has_alpha = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PF_DXT3:
|
||||
for (z = 0; z < image_desc.numLayers; z++)
|
||||
{
|
||||
for (y = 0; y < h; y += 4)
|
||||
{
|
||||
for (x = 0; x < w; x += 4)
|
||||
{
|
||||
alpha = fin;
|
||||
fin += 8;
|
||||
R_DXTReadColors(fin, colours);
|
||||
bitmask = ((uint*)fin)[1];
|
||||
bitmask = LittleLong(bitmask);
|
||||
fin += 8;
|
||||
|
||||
// Four-color block: derive the other two colors.
|
||||
// 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
|
||||
// These 2-bit codes correspond to the 2-bit fields
|
||||
// stored in the 64-bit block.
|
||||
colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3;
|
||||
colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3;
|
||||
colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3;
|
||||
colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3;
|
||||
colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3;
|
||||
colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3;
|
||||
|
||||
k = 0;
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
for (i = 0; i < 4; i++, k++)
|
||||
{
|
||||
Select = (bitmask & (0x03 << k*2)) >> k*2;
|
||||
col = &colours[Select];
|
||||
if (((x + i) < w) && ((y + j) < h))
|
||||
{
|
||||
Offset = z * image_desc.SizeOfPlane + (y + j) * image_desc.bps + (x + i) * image_desc.bpp;
|
||||
fout[Offset + 0] = col->r;
|
||||
fout[Offset + 1] = col->g;
|
||||
fout[Offset + 2] = col->b;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
sAlpha = alpha[2*j] + 256*alpha[2*j+1];
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (((x + i) < w) && ((y + j) < h))
|
||||
{
|
||||
Offset = z * image_desc.SizeOfPlane + (y + j) * image_desc.bps + (x + i) * image_desc.bpp + 3;
|
||||
fout[Offset] = sAlpha & 0x0F;
|
||||
fout[Offset] = fout[Offset] | (fout[Offset]<<4);
|
||||
if(sAlpha == 0) has_alpha = true;
|
||||
}
|
||||
sAlpha >>= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PF_DXT5:
|
||||
for (z = 0; z < image_desc.numLayers; z++)
|
||||
{
|
||||
for (y = 0; y < h; y += 4)
|
||||
{
|
||||
for (x = 0; x < w; x += 4)
|
||||
{
|
||||
if (y >= h || x >= w) break;
|
||||
alphas[0] = fin[0];
|
||||
alphas[1] = fin[1];
|
||||
alphamask = fin + 2;
|
||||
fin += 8;
|
||||
|
||||
R_DXTReadColors(fin, colours);
|
||||
bitmask = ((uint*)fin)[1];
|
||||
bitmask = LittleLong(bitmask);
|
||||
fin += 8;
|
||||
|
||||
// Four-color block: derive the other two colors.
|
||||
// 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
|
||||
// These 2-bit codes correspond to the 2-bit fields
|
||||
// stored in the 64-bit block.
|
||||
colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3;
|
||||
colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3;
|
||||
colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3;
|
||||
colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3;
|
||||
colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3;
|
||||
colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3;
|
||||
|
||||
k = 0;
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
for (i = 0; i < 4; i++, k++)
|
||||
{
|
||||
Select = (bitmask & (0x03 << k*2)) >> k*2;
|
||||
col = &colours[Select];
|
||||
// only put pixels out < width or height
|
||||
if (((x + i) < w) && ((y + j) < h))
|
||||
{
|
||||
Offset = z * image_desc.SizeOfPlane + (y + j) * image_desc.bps + (x + i) * image_desc.bpp;
|
||||
fout[Offset + 0] = col->r;
|
||||
fout[Offset + 1] = col->g;
|
||||
fout[Offset + 2] = col->b;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 8-alpha or 6-alpha block?
|
||||
if (alphas[0] > alphas[1])
|
||||
{
|
||||
// 8-alpha block: derive the other six alphas.
|
||||
// Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
|
||||
alphas[2] = (6 * alphas[0] + 1 * alphas[1] + 3) / 7; // bit code 010
|
||||
alphas[3] = (5 * alphas[0] + 2 * alphas[1] + 3) / 7; // bit code 011
|
||||
alphas[4] = (4 * alphas[0] + 3 * alphas[1] + 3) / 7; // bit code 100
|
||||
alphas[5] = (3 * alphas[0] + 4 * alphas[1] + 3) / 7; // bit code 101
|
||||
alphas[6] = (2 * alphas[0] + 5 * alphas[1] + 3) / 7; // bit code 110
|
||||
alphas[7] = (1 * alphas[0] + 6 * alphas[1] + 3) / 7; // bit code 111
|
||||
}
|
||||
else
|
||||
{
|
||||
// 6-alpha block.
|
||||
// Bit code 000 = alpha_0, 001 = alpha_1, others are interpolated.
|
||||
alphas[2] = (4 * alphas[0] + 1 * alphas[1] + 2) / 5; // Bit code 010
|
||||
alphas[3] = (3 * alphas[0] + 2 * alphas[1] + 2) / 5; // Bit code 011
|
||||
alphas[4] = (2 * alphas[0] + 3 * alphas[1] + 2) / 5; // Bit code 100
|
||||
alphas[5] = (1 * alphas[0] + 4 * alphas[1] + 2) / 5; // Bit code 101
|
||||
alphas[6] = 0x00; // Bit code 110
|
||||
alphas[7] = 0xFF; // Bit code 111
|
||||
}
|
||||
// Note: Have to separate the next two loops,
|
||||
// it operates on a 6-byte system.
|
||||
|
||||
// First three bytes
|
||||
bits = (alphamask[0]) | (alphamask[1] << 8) | (alphamask[2] << 16);
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
// only put pixels out < width or height
|
||||
if (((x + i) < w) && ((y + j) < h))
|
||||
{
|
||||
Offset = z * image_desc.SizeOfPlane + (y + j) * image_desc.bps + (x + i) * image_desc.bpp + 3;
|
||||
fout[Offset] = alphas[bits & 0x07];
|
||||
}
|
||||
bits >>= 3;
|
||||
}
|
||||
}
|
||||
// Last three bytes
|
||||
bits = (alphamask[3]) | (alphamask[4] << 8) | (alphamask[5] << 16);
|
||||
for (j = 2; j < 4; j++)
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
// only put pixels out < width or height
|
||||
if (((x + i) < w) && ((y + j) < h))
|
||||
{
|
||||
Offset = z * image_desc.SizeOfPlane + (y + j) * image_desc.bps + (x + i) * image_desc.bpp + 3;
|
||||
fout[Offset] = alphas[bits & 0x07];
|
||||
if(bits & 0x07) has_alpha = true;
|
||||
}
|
||||
bits >>= 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
MsgDev(D_WARN, "qrsCompressedTexImage2D: invalid compression type: %s\n", PFDesc[internalformat].name );
|
||||
return false;
|
||||
case PF_DXT1: dxtformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
|
||||
case PF_DXT3: dxtformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
|
||||
case PF_DXT5: dxtformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
scaled_width = w;
|
||||
scaled_height = h;
|
||||
R_RoundImageDimensions(&scaled_width, &scaled_height );
|
||||
|
||||
// upload base image or miplevel
|
||||
if( image_desc.tflags & TF_COMPRESS )
|
||||
image_desc.glSamples = (has_alpha) ? GL_COMPRESSED_RGBA_ARB : GL_COMPRESSED_RGB_ARB;
|
||||
else image_desc.glSamples = (has_alpha) ? GL_RGBA : GL_RGB;
|
||||
R_ResampleTexture ((uint *)fout, w, h, scaled, scaled_width, scaled_height);
|
||||
if( !level ) GL_GenerateMipmaps( scaled_width, scaled_height ); // generate mips if needed
|
||||
pglTexImage2D ( target, level, image_desc.glSamples, scaled_width, scaled_height, border, image_desc.glMask, image_desc.glType, (byte *)scaled );
|
||||
|
||||
if(pglGetError()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompressedTexImage2D( uint target, int level, int intformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
uint dxtformat = 0;
|
||||
uint pixformat = PFDesc[intformat].format;
|
||||
|
||||
if(GL_Support( R_TEXTURE_COMPRESSION_EXT ))
|
||||
{
|
||||
switch( pixformat )
|
||||
{
|
||||
case PF_DXT1: dxtformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
|
||||
case PF_DXT3: dxtformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
|
||||
case PF_DXT5: dxtformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
|
||||
default: use_gl_extension = false; break;
|
||||
}
|
||||
}
|
||||
else use_gl_extension = false;
|
||||
|
||||
if( use_gl_extension )
|
||||
{
|
||||
if( !level ) GL_GenerateMipmaps( width, height ); // generate mips if needed
|
||||
pglCompressedTexImage2DARB( target, level, dxtformat, width, height, border, imageSize, data );
|
||||
if(!pglGetError()) return true;
|
||||
// otherwise try loading with software unpacker
|
||||
}
|
||||
return qrsCompressedTexImage2D( target, level, pixformat, width, height, border, imageSize, data );
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
R_LoadImageDXT
|
||||
===============
|
||||
*/
|
||||
bool R_LoadImageDXT( byte *data, GLuint target )
|
||||
{
|
||||
int i, size = 0;
|
||||
int w = image_desc.width;
|
||||
int h = image_desc.height;
|
||||
int d = image_desc.numLayers;
|
||||
double time;
|
||||
|
||||
time = Sys_DoubleTime();
|
||||
for( i = 0; i < image_desc.MipCount; i++, data += size )
|
||||
{
|
||||
R_SetPixelFormat( w, h, d );
|
||||
size = image_desc.SizeOfFile;
|
||||
|
||||
if(!CompressedTexImage2D( target, i, image_desc.format, w, h, 0, size, data ))
|
||||
break; // there were errors
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1; //calc size of next mip
|
||||
}
|
||||
|
||||
totalTime += Sys_DoubleTime() - time;
|
||||
|
||||
GL_TexFilter();
|
||||
return true;
|
||||
if( !level ) GL_GenerateMipmaps( width, height ); // generate mips if needed
|
||||
pglCompressedTexImage2DARB( target, level, dxtformat, width, height, border, imageSize, data );
|
||||
return !pglGetError();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1272,7 +938,7 @@ qrsDecompressedTexImage2D
|
|||
cpu version of loading non paletted rgba buffer
|
||||
===============
|
||||
*/
|
||||
bool qrsDecompressedTexImage2D( uint target, int level, int internalformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
bool R_LoadImageRGBA( uint target, int level, int intformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
byte *fin;
|
||||
int i, p;
|
||||
|
@ -1286,7 +952,7 @@ bool qrsDecompressedTexImage2D( uint target, int level, int internalformat, uint
|
|||
scaled_width = width;
|
||||
scaled_height = height;
|
||||
|
||||
switch( PFDesc[internalformat].format )
|
||||
switch( intformat )
|
||||
{
|
||||
case PF_INDEXED_24:
|
||||
if( image_desc.flags & IMAGE_HAVE_ALPHA )
|
||||
|
@ -1342,7 +1008,7 @@ bool qrsDecompressedTexImage2D( uint target, int level, int internalformat, uint
|
|||
fout = fin; // nothing to process
|
||||
break;
|
||||
default:
|
||||
MsgDev(D_WARN, "qrsDecompressedTexImage2D: invalid compression type: %s\n", PFDesc[internalformat].name );
|
||||
MsgDev(D_WARN, "qrsDecompressedTexImage2D: invalid compression type: %s\n", PFDesc( intformat )->name );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1354,131 +1020,14 @@ bool qrsDecompressedTexImage2D( uint target, int level, int internalformat, uint
|
|||
if( !level ) GL_GenerateMipmaps( scaled_width, scaled_height ); // generate mips if needed
|
||||
pglTexImage2D( target, level, image_desc.glSamples, scaled_width, scaled_height, border, image_desc.glMask, image_desc.glType, (byte *)scaled );
|
||||
|
||||
if(pglGetError()) return false;
|
||||
return true;
|
||||
return !pglGetError();
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
R_LoadImageRGBA
|
||||
===============
|
||||
*/
|
||||
bool R_LoadImageRGBA( byte *data, GLuint target )
|
||||
bool R_LoadImageARGB( uint target, int level, int intformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
int i, size = 0;
|
||||
int w = image_desc.width;
|
||||
int h = image_desc.height;
|
||||
int d = image_desc.numLayers; // ABGR_64 may using some layers
|
||||
uint argbformat, datatype;
|
||||
|
||||
for( i = 0; i < image_desc.MipCount; i++, data += size )
|
||||
{
|
||||
R_SetPixelFormat( w, h, d );
|
||||
size = image_desc.SizeOfFile;
|
||||
|
||||
if(!qrsDecompressedTexImage2D( target, i, image_desc.format, w, h, 0, size, data ))
|
||||
break; // there were errors
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1; // calc size of next mip
|
||||
}
|
||||
|
||||
GL_TexFilter();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool qrsDecompressImageARGB( uint target, int level, int internalformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
uint ReadI = 0, TempBpp;
|
||||
uint RedL, RedR, GreenL, GreenR, BlueL, BlueR, AlphaL, AlphaR;
|
||||
uint r_bitmask, g_bitmask, b_bitmask, a_bitmask;
|
||||
uint *scaled = (unsigned *)image_desc.scaled;
|
||||
byte *fin, *fout = image_desc.source;
|
||||
bool has_alpha = false;
|
||||
int scaled_width, scaled_height;
|
||||
int i, w, h;
|
||||
|
||||
if (!data) return false;
|
||||
if(image_desc.pal)
|
||||
{
|
||||
byte *pal = image_desc.pal; // copy ptr
|
||||
r_bitmask = BuffLittleLong( pal ); pal += 4;
|
||||
g_bitmask = BuffLittleLong( pal ); pal += 4;
|
||||
b_bitmask = BuffLittleLong( pal ); pal += 4;
|
||||
a_bitmask = BuffLittleLong( pal ); pal += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgDev(D_ERROR, "R_StoreImageARGB: can't get RGBA bitmask\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
R_GetBitsFromMask(r_bitmask, &RedL, &RedR);
|
||||
R_GetBitsFromMask(g_bitmask, &GreenL, &GreenR);
|
||||
R_GetBitsFromMask(b_bitmask, &BlueL, &BlueR);
|
||||
R_GetBitsFromMask(a_bitmask, &AlphaL, &AlphaR);
|
||||
|
||||
fin = (byte *)data;
|
||||
w = width;
|
||||
h = height;
|
||||
TempBpp = image_desc.BitsCount / 8;
|
||||
|
||||
for( i = 0; i < image_desc.SizeOfData; i += image_desc.bpp )
|
||||
{
|
||||
// TODO: This is SLOOOW...
|
||||
// but the old version crashed in release build under
|
||||
// winxp (and xp is right to stop this code - I always
|
||||
// wondered that it worked the old way at all)
|
||||
if( image_desc.SizeOfData - i < 4 )
|
||||
{
|
||||
// less than 4 byte to write?
|
||||
if( TempBpp == 1 ) ReadI = *((byte*)fin);
|
||||
else if( TempBpp == 2 ) ReadI = BuffLittleShort( fin );
|
||||
else if( TempBpp == 3 ) ReadI = BuffLittleLong( fin );
|
||||
}
|
||||
else ReadI = BuffLittleLong( fin );
|
||||
fin += TempBpp;
|
||||
fout[i] = ((ReadI & r_bitmask)>> RedR) << RedL;
|
||||
|
||||
if( image_desc.bpp >= 3 )
|
||||
{
|
||||
fout[i+1] = ((ReadI & g_bitmask) >> GreenR) << GreenL;
|
||||
fout[i+2] = ((ReadI & b_bitmask) >> BlueR) << BlueL;
|
||||
if (image_desc.bpp == 4)
|
||||
{
|
||||
fout[i+3] = ((ReadI & a_bitmask) >> AlphaR) << AlphaL;
|
||||
if (AlphaL >= 7) fout[i+3] = fout[i+3] ? 0xFF : 0x00;
|
||||
else if (AlphaL >= 4) fout[i+3] = fout[i+3] | (fout[i+3] >> 4);
|
||||
}
|
||||
}
|
||||
else if (image_desc.bpp == 2)
|
||||
{
|
||||
fout[i+1] = ((ReadI & a_bitmask) >> AlphaR) << AlphaL;
|
||||
if (AlphaL >= 7) fout[i+1] = fout[i+1] ? 0xFF : 0x00;
|
||||
else if (AlphaL >= 4) fout[i+1] = fout[i+1] | (fout[i+3] >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
scaled_width = w;
|
||||
scaled_height = h;
|
||||
R_RoundImageDimensions( &scaled_width, &scaled_height );
|
||||
|
||||
// upload base image or miplevel
|
||||
if( image_desc.tflags & TF_COMPRESS )
|
||||
image_desc.glSamples = (has_alpha) ? GL_COMPRESSED_RGBA_ARB : GL_COMPRESSED_RGB_ARB;
|
||||
else image_desc.glSamples = (has_alpha) ? GL_RGBA : GL_RGB;
|
||||
R_ResampleTexture ((uint *)fout, w, h, scaled, scaled_width, scaled_height);
|
||||
if( !level ) GL_GenerateMipmaps( scaled_width, scaled_height ); // generate mips if needed
|
||||
pglTexImage2D ( target, level, image_desc.glSamples, scaled_width, scaled_height, border, image_desc.glMask, image_desc.glType, (byte *)scaled );
|
||||
|
||||
if(pglGetError()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DecompressImageARGB( uint target, int level, int intformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
uint argbformat = 0;
|
||||
uint datatype = 0;
|
||||
uint pixformat = PFDesc[intformat].format;
|
||||
|
||||
switch( pixformat )
|
||||
switch( intformat )
|
||||
{
|
||||
case PF_ARGB_32:
|
||||
case PF_LUMINANCE:
|
||||
|
@ -1487,93 +1036,37 @@ bool DecompressImageARGB( uint target, int level, int intformat, uint width, uin
|
|||
argbformat = GL_RGB5_A1;
|
||||
datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||
break;
|
||||
default: use_gl_extension = false; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if( use_gl_extension )
|
||||
{
|
||||
if( !level ) GL_GenerateMipmaps( width, height ); // generate mips if needed
|
||||
pglTexImage2D( target, level, argbformat, width, height, border, image_desc.glMask, datatype, data );
|
||||
if(!pglGetError()) return true;
|
||||
// otherwise try loading with software unpacker
|
||||
}
|
||||
return qrsDecompressImageARGB(target, level, pixformat, width, height, border, imageSize, data );
|
||||
if( !level ) GL_GenerateMipmaps( width, height ); // generate mips if needed
|
||||
pglTexImage2D( target, level, argbformat, width, height, border, image_desc.glMask, datatype, data );
|
||||
return !pglGetError();
|
||||
}
|
||||
|
||||
bool R_LoadImageARGB( byte *data, GLuint target )
|
||||
bool R_LoadImageFloat( uint target, int level, int intformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
int i, size = 0;
|
||||
int w = image_desc.width;
|
||||
int h = image_desc.height;
|
||||
int d = image_desc.numLayers;
|
||||
uint floatformat, datatype;
|
||||
|
||||
for( i = 0; i < image_desc.MipCount; i++, data += size )
|
||||
{
|
||||
R_SetPixelFormat( w, h, d );
|
||||
size = image_desc.SizeOfFile;
|
||||
|
||||
if(!DecompressImageARGB( target, i, image_desc.format, w, h, 0, size, data ))
|
||||
break; //there were errors
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1; // calc size of next mip
|
||||
}
|
||||
|
||||
GL_TexFilter();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool qrsDecompressImageFloat( uint target, int level, int internalformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
// not implemented
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DecompressImageFloat( uint target, int level, int intformat, uint width, uint height, int border, uint imageSize, const void* data )
|
||||
{
|
||||
uint floatformat = 0;
|
||||
uint datatype = 0;
|
||||
uint pixformat = PFDesc[intformat].format;
|
||||
|
||||
switch( pixformat )
|
||||
switch( intformat )
|
||||
{
|
||||
case PF_R_16F:
|
||||
case PF_R_32F:
|
||||
case PF_GR_32F:
|
||||
case PF_GR_64F:
|
||||
case PF_ABGR_64F:
|
||||
case PF_ABGR_128F:
|
||||
floatformat = GL_FLOAT;
|
||||
datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||
break;
|
||||
default: use_gl_extension = false; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
if( use_gl_extension )
|
||||
{
|
||||
if( !level ) GL_GenerateMipmaps( width, height ); // generate mips if needed // generate mips if needed
|
||||
pglTexImage2D( target, level, floatformat, width, height, border, image_desc.glMask, datatype, data );
|
||||
if(!pglGetError()) return true;
|
||||
// otherwise try loading with software unpacker
|
||||
}
|
||||
return qrsDecompressImageFloat( target, level, pixformat, width, height, border, imageSize, data );
|
||||
if( !level ) GL_GenerateMipmaps( width, height ); // generate mips if needed // generate mips if needed
|
||||
pglTexImage2D( target, level, floatformat, width, height, border, image_desc.glMask, datatype, data );
|
||||
return !pglGetError();
|
||||
}
|
||||
|
||||
bool R_LoadImageFloat( byte *data, GLuint target )
|
||||
{
|
||||
int i, size = 0;
|
||||
int w = image_desc.width;
|
||||
int h = image_desc.height;
|
||||
int d = image_desc.numLayers;
|
||||
|
||||
for( i = 0; i < image_desc.MipCount; i++, data += size )
|
||||
{
|
||||
R_SetPixelFormat( w, h, d );
|
||||
size = image_desc.SizeOfFile;
|
||||
|
||||
if(!DecompressImageFloat( target, i, image_desc.format, w, h, 0, size, data ))
|
||||
break; // there were errors
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1; // calc size of next mip
|
||||
}
|
||||
|
||||
GL_TexFilter();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
R_FindImage
|
||||
|
@ -1619,28 +1112,45 @@ texture_t *R_FindCubeMapTexture( const char *name, uint flags, float bumpScale )
|
|||
|
||||
bool R_UploadTexture( byte *buffer, int type, GLuint target )
|
||||
{
|
||||
bool iResult;
|
||||
int i, size = 0;
|
||||
int w = image_desc.width;
|
||||
int h = image_desc.height;
|
||||
int d = image_desc.numLayers;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case PF_RGB_24:
|
||||
case PF_ABGR_64:
|
||||
case PF_RGBA_32:
|
||||
case PF_RGBA_GN:
|
||||
case PF_INDEXED_24:
|
||||
case PF_INDEXED_32: iResult = R_LoadImageRGBA( buffer, target ); break;
|
||||
case PF_ABGR_64:
|
||||
case PF_RGBA_GN: image_desc.texImage = R_LoadImageRGBA; break;
|
||||
case PF_LUMINANCE:
|
||||
case PF_LUMINANCE_16:
|
||||
case PF_LUMINANCE_ALPHA:
|
||||
case PF_ARGB_32: iResult = R_LoadImageARGB( buffer, target ); break;
|
||||
case PF_ARGB_32: image_desc.texImage = R_LoadImageARGB; break;
|
||||
case PF_DXT1:
|
||||
case PF_DXT3:
|
||||
case PF_DXT5: iResult = R_LoadImageDXT( buffer, target ); break;
|
||||
case PF_ABGR_128F: iResult = R_LoadImageFloat( buffer, target ); break;
|
||||
case PF_UNKNOWN: iResult = false; break;
|
||||
case PF_DXT5: image_desc.texImage = R_LoadImageDXT; break;
|
||||
case PF_R_16F:
|
||||
case PF_R_32F:
|
||||
case PF_GR_32F:
|
||||
case PF_GR_64F:
|
||||
case PF_ABGR_64F:
|
||||
case PF_ABGR_128F: image_desc.texImage = R_LoadImageFloat; break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return iResult;
|
||||
for( i = 0; i < image_desc.MipCount; i++, buffer += size )
|
||||
{
|
||||
R_SetPixelFormat( w, h, d );
|
||||
size = image_desc.SizeOfFile;
|
||||
|
||||
if( !image_desc.texImage( target, i, image_desc.format, w, h, 0, size, buffer ))
|
||||
return false; // there were errors
|
||||
w = (w+1)>>1, h = (h+1)>>1, d = (d+1)>>1; // calc size of next mip
|
||||
}
|
||||
|
||||
GL_TexFilter();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1724,9 +1234,9 @@ texture_t *R_LoadTexture( const char *name, rgbdata_t *pic, uint flags, float bu
|
|||
offset = image_desc.SizeOfFile; // move pointer
|
||||
|
||||
if( numsides == 6 )
|
||||
MsgDev( D_LOAD, "%s[%i] [%s] \n", name, i, PFDesc[image_desc.format].name );
|
||||
else MsgDev( D_LOAD, "%s [%s] \n", name, PFDesc[image_desc.format].name );
|
||||
R_UploadTexture( buf, pic->type, target + i );
|
||||
MsgDev( D_LOAD, "%s[%i] [%s] \n", name, i, PFDesc( image_desc.format )->name );
|
||||
else MsgDev( D_LOAD, "%s [%s] \n", name, PFDesc( image_desc.format )->name );
|
||||
iResult = R_UploadTexture( buf, pic->type, target + i );
|
||||
}
|
||||
// check for errors
|
||||
if( !iResult )
|
||||
|
@ -1798,7 +1308,7 @@ bool VID_ScreenShot( const char *filename, bool levelshot )
|
|||
r_shot->width = r_width->integer;
|
||||
r_shot->height = r_height->integer;
|
||||
r_shot->type = PF_RGB_24;
|
||||
r_shot->size = r_shot->width * r_shot->height * PFDesc[r_shot->type].bpp;
|
||||
r_shot->size = r_shot->width * r_shot->height * PFDesc( r_shot->type )->bpp;
|
||||
r_shot->palette = NULL;
|
||||
r_shot->numLayers = 1;
|
||||
r_shot->numMips = 1;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "ripper.h"
|
||||
#include "qc_gen.h"
|
||||
|
||||
#define VDBSPMODHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'V') // little-endian "VBSP" hl2 bsp's
|
||||
#define IDIWADHEADER (('D'<<24)+('A'<<16)+('W'<<8)+'I') // little-endian "IWAD" doom1 game wad
|
||||
#define IDPWADHEADER (('D'<<24)+('A'<<16)+('W'<<8)+'P') // little-endian "PWAD" doom1 game wad
|
||||
#define IDWAD2HEADER (('2'<<24)+('D'<<16)+('A'<<8)+'W') // little-endian "WAD2" quake1 gfx.wad
|
||||
|
@ -138,10 +139,6 @@ bool Conv_CheckMap( const char *mapname )
|
|||
case IDBSPMODHEADER: // continue checking
|
||||
switch( hdr.version )
|
||||
{
|
||||
case 18:
|
||||
game_family = GAME_HALFLIFE2_BETA;
|
||||
FS_Close( f );
|
||||
return true;
|
||||
case 38:
|
||||
game_family = GAME_QUAKE2;
|
||||
FS_Close( f );
|
||||
|
@ -159,6 +156,19 @@ bool Conv_CheckMap( const char *mapname )
|
|||
FS_Close( f );
|
||||
return true;
|
||||
}
|
||||
case VDBSPMODHEADER: // continue checking
|
||||
switch( hdr.version )
|
||||
{
|
||||
case 18:
|
||||
game_family = GAME_HALFLIFE2_BETA;
|
||||
FS_Close( f );
|
||||
return true;
|
||||
case 19:
|
||||
case 20:
|
||||
game_family = GAME_HALFLIFE2;
|
||||
FS_Close( f );
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
game_family = GAME_GENERIC;
|
||||
FS_Close( f );
|
||||
|
|
|
@ -16,6 +16,7 @@ string gs_searchmask;
|
|||
#define MAX_SEARCHMASK 128
|
||||
string searchmask[MAX_SEARCHMASK];
|
||||
int num_searchmask = 0;
|
||||
bool write_qscsript;
|
||||
int game_family;
|
||||
|
||||
typedef struct convformat_s
|
||||
|
@ -38,6 +39,7 @@ convformat_t convert_formats[] =
|
|||
{"%s.%s", "mip", ConvMIP}, // Quake1/Half-Life textures
|
||||
{"%s.%s", "lmp", ConvLMP}, // Quake1/Half-Life gfx
|
||||
{"%s.%s", "wal", ConvWAL}, // Quake2 textures
|
||||
{"%s.%s", "vtf", ConvVTF}, // Half-Life 2 materials
|
||||
{"%s.%s", "skn", ConvSKN}, // doom1 sprite models
|
||||
{"%s.%s", "bsp", ConvBSP}, // Quake1\Half-Life map textures
|
||||
{"%s.%s", "mus", ConvMID}, // Quake1\Half-Life map textures
|
||||
|
@ -51,22 +53,21 @@ bool ConvertResource( const char *filename )
|
|||
{
|
||||
convformat_t *format;
|
||||
const char *ext = FS_FileExtension( filename );
|
||||
char path[128], convname[128], basename[128];
|
||||
bool anyformat = !com.stricmp(ext, "") ? true : false;
|
||||
string path, convname, basename;
|
||||
int filesize = 0;
|
||||
byte *buffer = NULL;
|
||||
|
||||
com.strncpy( convname, filename, sizeof(convname)-1);
|
||||
com.strncpy( convname, filename, sizeof( convname ));
|
||||
FS_StripExtension( convname ); // remove extension if needed
|
||||
|
||||
// now try all the formats in the selected list
|
||||
for (format = convert_formats; format->formatstring; format++)
|
||||
for( format = convert_formats; format->formatstring; format++ )
|
||||
{
|
||||
if( anyformat || !com.stricmp( ext, format->ext ))
|
||||
{
|
||||
com.sprintf( path, format->formatstring, convname, format->ext );
|
||||
buffer = FS_LoadFile( path, &filesize );
|
||||
FS_FileBase( path, basename );
|
||||
if( buffer && filesize > 0 )
|
||||
{
|
||||
// this path may contains wadname: wadfile/lumpname
|
||||
|
@ -79,6 +80,7 @@ bool ConvertResource( const char *filename )
|
|||
if( buffer ) Mem_Free( buffer ); // release buffer
|
||||
}
|
||||
}
|
||||
FS_FileBase( convname, basename );
|
||||
MsgDev(D_WARN, "ConvertResource: couldn't load \"%s\"\n", basename );
|
||||
return false;
|
||||
}
|
||||
|
@ -160,7 +162,7 @@ void RunConvertor( void )
|
|||
{
|
||||
search_t *search;
|
||||
string errorstring;
|
||||
int i, j, numConvertedRes = 0;
|
||||
int i, j, imageflags, numConvertedRes = 0;
|
||||
cvar_t *fs_defaultdir = Cvar_Get( "fs_defaultdir", "tmpQuArK", CVAR_SYSTEMINFO, NULL );
|
||||
|
||||
memset( errorstring, 0, MAX_STRING );
|
||||
|
@ -168,6 +170,8 @@ void RunConvertor( void )
|
|||
Conv_DetectGameType();
|
||||
|
||||
if( game_family ) Msg("Game: %s family\n", game_names[game_family] );
|
||||
imageflags = IL_USE_LERPING|IL_IGNORE_MIPS;
|
||||
write_qscsript = false;
|
||||
|
||||
switch( game_family )
|
||||
{
|
||||
|
@ -195,6 +199,9 @@ void RunConvertor( void )
|
|||
AddMask( "*.snd" ); // Doom1 sounds
|
||||
AddMask( "*.mus" ); // Doom1 music
|
||||
}
|
||||
imageflags |= IL_KEEP_8BIT;
|
||||
Image_Init( "Doom1", imageflags );
|
||||
write_qscsript = true;
|
||||
break;
|
||||
case GAME_HEXEN2:
|
||||
case GAME_QUAKE1:
|
||||
|
@ -210,6 +217,9 @@ void RunConvertor( void )
|
|||
AddMask( "*.sp32");
|
||||
AddMask( "*.spr" );
|
||||
AddMask( "*.mip" );
|
||||
imageflags |= IL_KEEP_8BIT;
|
||||
write_qscsript = true;
|
||||
Image_Init( "Quake1", imageflags );
|
||||
break;
|
||||
case GAME_QUAKE2:
|
||||
search = FS_Search("textures/*", true );
|
||||
|
@ -226,13 +236,53 @@ void RunConvertor( void )
|
|||
AddMask( "sprites/*.sp2" ); // Quake2 sprites
|
||||
AddMask( "pics/*.pcx"); // Quake2 pics
|
||||
AddMask( "env/*.pcx" ); // Quake2 skyboxes
|
||||
imageflags |= IL_KEEP_8BIT;
|
||||
write_qscsript = true;
|
||||
Image_Init( "Quake2", imageflags );
|
||||
break;
|
||||
case GAME_RTCW:
|
||||
case GAME_QUAKE3:
|
||||
case GAME_QUAKE4:
|
||||
search = FS_Search("textures/*", true );
|
||||
if( search )
|
||||
{
|
||||
// find subdirectories
|
||||
for( i = 0; i < search->numfilenames; i++ )
|
||||
AddMask(va("%s/*.jpg", search->filenames[i]));
|
||||
Mem_Free( search );
|
||||
}
|
||||
else AddMask( "*.jpg" ); // Quake3 textures
|
||||
search = FS_Search("gfx/*", true );
|
||||
if( search )
|
||||
{
|
||||
// find subdirectories
|
||||
for( i = 0; i < search->numfilenames; i++ )
|
||||
AddMask(va("%s/*.jpg", search->filenames[i]));
|
||||
Mem_Free( search );
|
||||
}
|
||||
else AddMask( "gfx/*.jpg" ); // Quake3 hud pics
|
||||
AddMask( "sprites/*.jpg" ); // Quake3 sprite frames
|
||||
Image_Init( "Quake3", imageflags );
|
||||
break;
|
||||
case GAME_HALFLIFE2:
|
||||
case GAME_HALFLIFE2_BETA:
|
||||
Sys_Break("Sorry, nothing to decompile (not implemeneted yet)\n" );
|
||||
search = FS_Search("materials/*", true );
|
||||
|
||||
// hl2 like using double included sub-dirs
|
||||
for( i = 0; search && i < search->numfilenames; i++ )
|
||||
{
|
||||
search_t *search2 = FS_Search( va("%s/*", search->filenames[i] ), true );
|
||||
for( j = 0; search2 && j < search2->numfilenames; j++ )
|
||||
AddMask(va("%s/*.vtf", search2->filenames[j]));
|
||||
if( search2 ) Mem_Free( search2 );
|
||||
}
|
||||
if( search ) Mem_Free( search );
|
||||
else AddMask( "*.jpg" ); // Quake3 textures
|
||||
Image_Init( "Half-Life 2", imageflags );
|
||||
break;
|
||||
case GAME_QUAKE4:
|
||||
// i'm lazy today and i'm forget textures representation of IdTech4 :)
|
||||
Sys_Break( "Sorry, nothing to decompile (not implemeneted yet)\n" );
|
||||
Image_Init( "Quake4", imageflags );
|
||||
break;
|
||||
case GAME_HALFLIFE:
|
||||
search = FS_Search("*.wad", true );
|
||||
|
@ -254,11 +304,17 @@ void RunConvertor( void )
|
|||
}
|
||||
AddMask( "maps/*.bsp" ); // textures from bsp
|
||||
AddMask( "sprites/*.spr" ); // Half-Life sprites
|
||||
imageflags |= IL_KEEP_8BIT;
|
||||
write_qscsript = true;
|
||||
Image_Init( "Half-Life", imageflags );
|
||||
break;
|
||||
case GAME_XASH3D:
|
||||
Sys_Break("Sorry, but a can't decompile himself\n" );
|
||||
Sys_Break("Sorry, but i'm can't decompile himself\n" );
|
||||
Image_Init( "Xash3D", imageflags );
|
||||
break;
|
||||
default:
|
||||
Image_Init( "Generic", imageflags ); // everything else
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// using custom mask
|
||||
|
@ -267,14 +323,14 @@ void RunConvertor( void )
|
|||
ClrMask(); // clear all previous masks
|
||||
AddMask( gs_searchmask ); // custom mask
|
||||
}
|
||||
else if(!game_family ) Sys_Break( "Sorry, game family not recognized\n" );
|
||||
else if( !game_family ) Sys_Break( "Sorry, game family not recognized\n" );
|
||||
|
||||
// directory to extract
|
||||
com.strncpy( gs_gamedir, fs_defaultdir->string, sizeof(gs_gamedir));
|
||||
Msg( "Converting ...\n\n" );
|
||||
|
||||
// search by mask
|
||||
for( i = 0; i < num_searchmask; i++)
|
||||
for( i = 0; i < num_searchmask; i++ )
|
||||
{
|
||||
// skip blank mask
|
||||
if(!com.strlen(searchmask[i])) continue;
|
||||
|
|
|
@ -23,7 +23,7 @@ void Conv_RoundDimensions( int *scaled_width, int *scaled_height )
|
|||
|
||||
bool Conv_WriteShader( const char *shaderpath, const char *imagepath, rgbdata_t *p, float *rad, float scale, int flags, int contents )
|
||||
{
|
||||
file_t *f;
|
||||
file_t *f = NULL;
|
||||
string wadname;
|
||||
string qcname, qcpath;
|
||||
string temp, lumpname;
|
||||
|
@ -37,21 +37,24 @@ bool Conv_WriteShader( const char *shaderpath, const char *imagepath, rgbdata_t
|
|||
FS_DefaultExtension( wadname, ".wad" ); // check for wad later
|
||||
com.snprintf( qcpath, MAX_STRING, "%s/%s/%s", gs_gamedir, temp, qcname );
|
||||
|
||||
if(FS_FileExists( qcpath ))
|
||||
if( write_qscsript )
|
||||
{
|
||||
// already exist, search for current name
|
||||
f = FS_Open( qcpath, "a" ); // append
|
||||
}
|
||||
else
|
||||
{
|
||||
FS_StripExtension( qcname ); // no need anymore
|
||||
f = FS_Open( qcpath, "w" ); // new file
|
||||
// write description
|
||||
FS_Print(f,"//=======================================================================\n");
|
||||
FS_Print(f,"//\t\t\tCopyright XashXT Group 2007 ©\n");
|
||||
FS_Print(f,"//\t\t\twritten by Xash Miptex Decompiler\n");
|
||||
FS_Print(f,"//=======================================================================\n");
|
||||
FS_Printf(f,"$wadname\t%s.wad\n\n", qcname );
|
||||
if(FS_FileExists( qcpath ))
|
||||
{
|
||||
// already exist, search for current name
|
||||
f = FS_Open( qcpath, "a" ); // append
|
||||
}
|
||||
else
|
||||
{
|
||||
FS_StripExtension( qcname ); // no need anymore
|
||||
f = FS_Open( qcpath, "w" ); // new file
|
||||
// write description
|
||||
FS_Print(f,"//=======================================================================\n");
|
||||
FS_Print(f,"//\t\t\tCopyright XashXT Group 2007 ©\n");
|
||||
FS_Print(f,"//\t\t\twritten by Xash Miptex Decompiler\n");
|
||||
FS_Print(f,"//=======================================================================\n");
|
||||
FS_Printf(f,"$wadname\t%s.wad\n\n", qcname );
|
||||
}
|
||||
}
|
||||
|
||||
if( f && p )
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//=======================================================================
|
||||
// Copyright XashXT Group 2008 ©
|
||||
// conv_vtfimage.c - convert vtf materials
|
||||
//=======================================================================
|
||||
|
||||
#include "ripper.h"
|
||||
#include "qc_gen.h"
|
||||
|
||||
/*
|
||||
=============
|
||||
ConvVTF
|
||||
=============
|
||||
*/
|
||||
bool ConvVTF( const char *name, char *buffer, int filesize )
|
||||
{
|
||||
rgbdata_t *pic;
|
||||
|
||||
FS_StripExtension((char *)name );
|
||||
pic = FS_LoadImage( va( "#%s.vtf", name ), buffer, filesize );
|
||||
|
||||
if( pic )
|
||||
{
|
||||
FS_SaveImage( va("%s/%s.tga", gs_gamedir, name ), PF_RGBA_32, pic ); // save converted image
|
||||
Conv_CreateShader( name, pic, "vtf", NULL, 0, 0 );
|
||||
FS_FreeImage( pic ); // release buffer
|
||||
Msg( "%s.vtf\n", name ); // echo to console about current pic
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -153,6 +153,10 @@ SOURCE=.\conv_sprite2.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\conv_vtfimage.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\conv_wadlumps.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
|
@ -15,6 +15,7 @@ extern string gs_gamedir;
|
|||
#define Sys_Error com.error
|
||||
extern vprogs_exp_t *PRVM;
|
||||
extern uint app_name;
|
||||
extern bool write_qscsript;
|
||||
extern int game_family;
|
||||
|
||||
typedef enum
|
||||
|
@ -65,6 +66,7 @@ bool ConvMIP( const char *name, char *buffer, int filesize ); // Quake1, Half-Li
|
|||
bool ConvLMP( const char *name, char *buffer, int filesize ); // Quake1, Half-Life lump images
|
||||
bool ConvFNT( const char *name, char *buffer, int filesize ); // Half-Life system fonts
|
||||
bool ConvWAL( const char *name, char *buffer, int filesize ); // Quake2 textures
|
||||
bool ConvVTF( const char *name, char *buffer, int filesize ); // Quake2 textures
|
||||
bool ConvSKN( const char *name, char *buffer, int filesize ); // Doom1 sprite models
|
||||
bool ConvBSP( const char *name, char *buffer, int filesize ); // Extract textures from bsp (q1\hl)
|
||||
bool ConvSND( const char *name, char *buffer, int filesize ); // not implemented
|
||||
|
|
9
todo.log
9
todo.log
|
@ -23,8 +23,13 @@ GLOBAL:
|
|||
2. Загрузка спрайтов\моделей при помощи ImageLib OK
|
||||
3. Софтверный загрузчик DDS OK
|
||||
4. Правильная растановка сторон для dds OK
|
||||
5. переместить PFDesc в launch.dll
|
||||
5. Полная отладка ImageLib
|
||||
5. переместить PFDesc в launch.dll OK
|
||||
6. запрос для принудительной распаковки DXT
|
||||
7. поддержка vtf - файлов
|
||||
8. поддержка BGRA - форматов (VTF)
|
||||
9. Полная отладка ImageLib
|
||||
10. Отладка extragen
|
||||
11. дописать Image_SaveDDS
|
||||
|
||||
По умолчанию все картинки распаковываются в RGBA_32.
|
||||
Однако, если выставить флаг IL_DDS_HARDWARE, to DDS картинки разжиматься не будут, оставляя работу для
|
||||
|
|
Reference in New Issue