20 Sep 2007

This commit is contained in:
g-cont 2007-09-20 00:00:00 +04:00 committed by Alibek Omarov
parent e0a3de04fd
commit 2505539dee
22 changed files with 2018 additions and 1590 deletions

View File

@ -38,7 +38,13 @@ SV_ClipToLinks SV_ClipMoveToEntities
переписать CM_LoadModel OK
игрок застревает в полу после команды reconnect OK
отладка физики
избавиться от папки source2
}
19. Написать конвертор PCX в TGA
{
избавиться от d_8to24table в загрузке LoadImage8 OK
}
20. Пофиксить проигрывание .cin и .pcx файлов
//==================================================
// то, что уже готово

View File

@ -137,6 +137,10 @@ SOURCE=.\bsplib\flow.c
# End Source File
# Begin Source File
SOURCE=.\common\image.c
# End Source File
# Begin Source File
SOURCE=.\common\imglib.c
# End Source File
# Begin Source File

73
common/common.plg Normal file
View File

@ -0,0 +1,73 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: common - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\Temp\RSP3C3.tmp" with contents
[
/nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "./" /I "../public" /I "./bsplib/" /I "./qcclib" /I "./common" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR"..\temp\common\!debug/" /Fo"..\temp\common\!debug/" /Fd"..\temp\common\!debug/" /FD /GZ /c
"D:\XASH3D\src_main\!source\common\common\image.c"
]
Creating command line "cl.exe @C:\Temp\RSP3C3.tmp"
Creating temporary file "C:\Temp\RSP3C4.tmp" with contents
[
msvcrt.lib winmm.lib user32.lib /nologo /dll /incremental:yes /pdb:"..\temp\common\!debug/common.pdb" /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\temp\common\!debug/common.dll" /implib:"..\temp\common\!debug/common.lib" /pdbtype:sept
"\XASH3D\src_main\!source\temp\common\!debug\brushbsp.obj"
"\XASH3D\src_main\!source\temp\common\!debug\bspfile.obj"
"\XASH3D\src_main\!source\temp\common\!debug\csg.obj"
"\XASH3D\src_main\!source\temp\common\!debug\faces.obj"
"\XASH3D\src_main\!source\temp\common\!debug\filesystem.obj"
"\XASH3D\src_main\!source\temp\common\!debug\flow.obj"
"\XASH3D\src_main\!source\temp\common\!debug\image.obj"
"\XASH3D\src_main\!source\temp\common\!debug\imglib.obj"
"\XASH3D\src_main\!source\temp\common\!debug\leakfile.obj"
"\XASH3D\src_main\!source\temp\common\!debug\lightmap.obj"
"\XASH3D\src_main\!source\temp\common\!debug\map.obj"
"\XASH3D\src_main\!source\temp\common\!debug\memory.obj"
"\XASH3D\src_main\!source\temp\common\!debug\patches.obj"
"\XASH3D\src_main\!source\temp\common\!debug\platform.obj"
"\XASH3D\src_main\!source\temp\common\!debug\portals.obj"
"\XASH3D\src_main\!source\temp\common\!debug\pr_comp.obj"
"\XASH3D\src_main\!source\temp\common\!debug\pr_lex.obj"
"\XASH3D\src_main\!source\temp\common\!debug\prtfile.obj"
"\XASH3D\src_main\!source\temp\common\!debug\qbsp3.obj"
"\XASH3D\src_main\!source\temp\common\!debug\qcc_utils.obj"
"\XASH3D\src_main\!source\temp\common\!debug\qccmain.obj"
"\XASH3D\src_main\!source\temp\common\!debug\qrad3.obj"
"\XASH3D\src_main\!source\temp\common\!debug\qvis3.obj"
"\XASH3D\src_main\!source\temp\common\!debug\shaders.obj"
"\XASH3D\src_main\!source\temp\common\!debug\spritegen.obj"
"\XASH3D\src_main\!source\temp\common\!debug\studio.obj"
"\XASH3D\src_main\!source\temp\common\!debug\studio_utils.obj"
"\XASH3D\src_main\!source\temp\common\!debug\textures.obj"
"\XASH3D\src_main\!source\temp\common\!debug\trace.obj"
"\XASH3D\src_main\!source\temp\common\!debug\tree.obj"
"\XASH3D\src_main\!source\temp\common\!debug\utils.obj"
"\XASH3D\src_main\!source\temp\common\!debug\winding.obj"
"\XASH3D\src_main\!source\temp\common\!debug\writebsp.obj"
"\XASH3D\src_main\!source\temp\common\!debug\ziplib.obj"
]
Creating command line "link.exe @C:\Temp\RSP3C4.tmp"
Creating temporary file "C:\Temp\RSP3C5.bat" with contents
[
@echo off
copy \XASH3D\src_main\!source\temp\common\!debug\common.dll "D:\Xash3D\bin\common.dll"
]
Creating command line "C:\Temp\RSP3C5.bat"
Compiling...
image.c
Linking...
<h3>Output Window</h3>
Performing Custom Build Step on \XASH3D\src_main\!source\temp\common\!debug\common.dll
‘ª®¯¨à®¢ ­® ä ©«®¢: 1.
<h3>Results</h3>
common.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -2350,6 +2350,7 @@ filesystem_api_t FS_GetAPI( void )
fs.LoadFile = FS_LoadFile;
fs.WriteFile = FS_WriteFile;
fs.LoadImage = FS_LoadImage;
fs.SaveImage = FS_SaveImage;
fs.FreeImage = FS_FreeImage;
return fs;

1584
common/common/image.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -231,4 +231,7 @@ typedef struct jpg_s
static jpg_t jpg_file;
extern uint *d_currentpal;
void Image_GetPalettePCX( byte *pal );
#endif//IMAGE_H

File diff suppressed because it is too large Load Diff

View File

@ -101,7 +101,7 @@ choseclump:
void *_Mem_Realloc(byte *poolptr, void *memptr, size_t size, const char *filename, int fileline)
{
char *nb;
memheader_t *hdr;
memheader_t *memhdr;
if (size <= 0) return memptr; //no need to reallocate
nb = _Mem_Alloc(poolptr, size, filename, fileline);
@ -109,14 +109,43 @@ void *_Mem_Realloc(byte *poolptr, void *memptr, size_t size, const char *filenam
if (memptr) //first allocate?
{
//get size of old block
hdr = (memheader_t *)((byte *) memptr - sizeof(memheader_t));
_Mem_Copy( nb, memptr, hdr->size, filename, fileline );
memhdr = (memheader_t *)((byte *) memptr - sizeof(memheader_t));
_Mem_Copy( nb, memptr, memhdr->size, filename, fileline );
_Mem_Free( memptr, filename, fileline);//free unused old block
}
return (void *)nb;
}
void _Mem_Move(byte *poolptr, void **dest, void *src, size_t size, const char *filename, int fileline)
{
memheader_t *mem;
void *memptr = *dest;
if(!memptr) Sys_Error("Mem_Move: dest == NULL (called at %s:%i)", filename, fileline);
if(!src) Sys_Error("Mem_Move: src == NULL (called at %s:%i)", filename, fileline);
if (size <= 0) //just free memory
{
_Mem_Free( memptr, filename, fileline );
*dest = src; // swap blocks
return;
}
mem = (memheader_t *)((byte *) memptr - sizeof(memheader_t));//get size of old block
if(mem->size != size)
{
_Mem_Free( memptr, filename, fileline );// release old buffer
memptr = _Mem_Alloc( poolptr, size, filename, fileline );// alloc new size
}
else memset( memptr, 0, size ); // no need to reallocate buffer
_Mem_Copy( memptr, src, size, filename, fileline ); //move memory...
_Mem_Free( src, filename, fileline );//...and free old pointer
*dest = memptr;
}
static void _Mem_FreeBlock(memheader_t *mem, const char *filename, int fileline)
{
int i, firstblock, endblock;
@ -283,15 +312,6 @@ void _Mem_CheckSentinelsGlobal(const char *filename, int fileline)
_Mem_CheckClumpSentinels(clump, filename, fileline);
}
void _Mem_Move (void *dest, void *src, size_t size, const char *filename, int fileline)
{
if (src == NULL || size <= 0) return;
if (dest == NULL) dest = _Mem_Alloc( basepool, size, filename, fileline); //allocate room
// move block
memmove( dest, src, size );
}
void _Mem_Copy (void *dest, void *src, size_t size, const char *filename, int fileline)
{
if (src == NULL || size <= 0) return; //nothing to copy
@ -343,7 +363,4 @@ void FreeMemory( void )
{
Mem_FreePool( &basepool );
Mem_FreePool( &zonepool );
//abnormal freeing pools
Mem_FreePool( &studiopool );
}

View File

@ -31,7 +31,7 @@ typedef struct memheader_s
size_t size; // size of the memory after the header (excluding header and sentinel2)
const char *filename;// file name and line where Mem_Alloc was called
int fileline;
unsigned int sentinel1;// should always be MEMHEADER_SENTINEL1
uint sentinel1;// should always be MEMHEADER_SENTINEL1
// immediately followed by data, which is followed by a MEMHEADER_SENTINEL2 byte
}
memheader_t;

View File

@ -1786,12 +1786,8 @@ void Shift_Animation( s_animation_t *panim)
ppos = Kalloc( size );
prot = Kalloc( size );
memmove( ppos, &panim->pos[j][panim->startframe], size );
memmove( prot, &panim->rot[j][panim->startframe], size );
Free( panim->pos[j] );
Free( panim->rot[j] );
Mem_Move( studiopool, (void *)&ppos, &panim->pos[j][panim->startframe], size );
Mem_Move( studiopool, (void *)&prot, &panim->rot[j][panim->startframe], size );
panim->pos[j] = ppos;
panim->rot[j] = prot;
}

View File

@ -732,14 +732,7 @@ s_trianglevert_t *lookup_triangle( s_mesh_t *pmesh, int index )
{
int start = pmesh->alloctris;
pmesh->alloctris = index + 256;
if (pmesh->triangle)
{
pmesh->triangle = Realloc( pmesh->triangle, pmesh->alloctris * sizeof( *pmesh->triangle ));
}
else
{
pmesh->triangle = Kalloc( pmesh->alloctris * sizeof( *pmesh->triangle ));
}
pmesh->triangle = Realloc( pmesh->triangle, pmesh->alloctris * sizeof( *pmesh->triangle ));
}
return pmesh->triangle[index];
}

View File

@ -1540,6 +1540,7 @@ compilers_api_t Comp_GetAPI( void )
cp.Studio = CompileStudioModel;
cp.Sprite = CompileSpriteModel;
cp.Image = ConvertImagePixels;
cp.PrepareBSP = PrepareBSPModel;
cp.BSP = CompileBSPModel;
cp.PrepareDAT = PrepareDATProgs;

View File

@ -84,11 +84,11 @@ void FS_Shutdown (void);
#define Mem_Alloc(pool, size) _Mem_Alloc(pool, size, __FILE__, __LINE__)
#define Mem_Realloc(pool, ptr, size) _Mem_Realloc(pool, ptr, size, __FILE__, __LINE__)
#define Mem_Move(pool, ptr, data, size) _Mem_Move(pool, ptr, data, size, __FILE__, __LINE__)
#define Mem_Free(mem) _Mem_Free(mem, __FILE__, __LINE__)
#define Mem_AllocPool(name) _Mem_AllocPool(name, __FILE__, __LINE__)
#define Mem_FreePool(pool) _Mem_FreePool(pool, __FILE__, __LINE__)
#define Mem_EmptyPool(pool) _Mem_EmptyPool(pool, __FILE__, __LINE__)
#define Mem_Move(dest, src, size ) _Mem_Move (dest, src, size, __FILE__, __LINE__)
#define Mem_Copy(dest, src, size ) _Mem_Copy (dest, src, size, __FILE__, __LINE__)
extern stdlib_api_t std;
@ -141,6 +141,7 @@ _inline double I_FloatTime (void) { time_t t; time(&t); return t; }
//misc
bool CompileStudioModel ( byte *mempool, const char *name, byte parms );
bool CompileSpriteModel ( byte *mempool, const char *name, byte parms );
bool ConvertImagePixels ( byte *mempool, const char *name, byte parms );
bool PrepareBSPModel ( const char *dir, const char *name, byte params );
bool CompileBSPModel ( void );

View File

@ -39,6 +39,7 @@ rgbdata_t *FS_LoadImage(const char *filename, char *data, int size );
bool FS_WriteFile (const char *filename, void *data, fs_offset_t len);
search_t *FS_Search(const char *pattern, int caseinsensitive );
search_t *FS_SearchDirs(const char *pattern, int caseinsensitive );
void FS_SaveImage(const char *filename, rgbdata_t *buffer );
void FS_FreeImage( rgbdata_t *pack );
//=====================================
@ -46,11 +47,11 @@ void FS_FreeImage( rgbdata_t *pack );
//=====================================
void *_Mem_Alloc(byte *pool, size_t size, const char *filename, int fileline);
void *_Mem_Realloc(byte *poolptr, void *memptr, size_t size, const char *filename, int fileline);
void _Mem_Move(byte *poolptr, void **dest, void *src, size_t size, const char *filename, int fileline);
void _Mem_Free(void *data, const char *filename, int fileline);
byte *_Mem_AllocPool(const char *name, const char *filename, int fileline);
void _Mem_FreePool(byte **pool, const char *filename, int fileline);
void _Mem_EmptyPool(byte *pool, const char *filename, int fileline);
void _Mem_Move (void *dest, void *src, size_t size, const char *filename, int fileline);
void _Mem_Copy (void *dest, void *src, size_t size, const char *filename, int fileline);
//=====================================

View File

@ -55,5 +55,5 @@ if exist server.dat move server.dat D:\Xash3D\xash\server.dat
echo Build succeeded!
echo Please wait. Xash is now loading
cd D:\Xash3D\
xash.exe +map base1 -log
xash.exe +map qctest -log
:done

View File

@ -494,7 +494,7 @@ destroy win32 console
void Sys_DestroyConsoleW( void )
{
// last text message into console or log
Msg("Sys_FreeLibrary: Unloading launch.dll\n");
MsgDev(D_ERROR, "Sys_FreeLibrary: Unloading launch.dll\n");
if ( s_wcd.hWnd )
{

View File

@ -28,6 +28,7 @@ typedef enum
HOST_DEDICATED, // "host_dedicated"
HOST_EDITOR, // "host_editor"
BSPLIB, // "bsplib"
IMGLIB, // "imglib"
QCCLIB, // "qcclib"
SPRITE, // "sprite"
STUDIO, // "studio"
@ -102,6 +103,13 @@ void LookupInstance( const char *funcname )
strcpy(log_path, "bsplib.log" ); // xash3d root directory
strcpy(caption, "Xash3D BSP Compiler");
}
else if(!strcmp(progname, "imglib"))
{
app_name = IMGLIB;
linked_dll = &common_dll; // pointer to common.dll info
sprintf(log_path, "%s/convert.log", sys_rootdir ); // same as .exe file
strcpy(caption, "Xash3D Image Converter");
}
else if(!strcmp(progname, "qcclib"))
{
app_name = QCCLIB;
@ -198,10 +206,8 @@ void CommonInit ( char *funcname, int argc, char **argv )
Com->Compile.PrepareDAT( gamedir, source, qccflags );
break;
case IMGLIB:
case SPRITE:
Com->InitRootDir(".");
start = Com->DoubleTime();
break;
case STUDIO:
Com->InitRootDir(".");
start = Com->DoubleTime();
@ -214,41 +220,51 @@ void CommonInit ( char *funcname, int argc, char **argv )
void CommonMain ( void )
{
search_t *search;
char qcfilename[64], typemod[16];
int i, numCompiledMods = 0;
char filename[MAX_QPATH], typemod[16], searchmask[16];
bool (*CompileMod)( byte *mempool, const char *name, byte parms ) = NULL;
byte parms = 0; // future expansion
int i, numCompiledMods = 0;
switch(app_name)
{
case SPRITE:
CompileMod = Com->Compile.Sprite;
strcpy(typemod, "sprites" );
strcpy(searchmask, "*.qc" );
break;
case STUDIO:
CompileMod = Com->Compile.Studio;
strcpy(typemod, "models" );
strcpy(searchmask, "*.qc" );
break;
case IMGLIB:
CompileMod = Com->Compile.Image;
strcpy(typemod, "images" );
strcpy(searchmask, "*.pcx" );
break;
case BSPLIB:
Com->Compile.BSP();
strcpy(typemod, "maps" );
strcpy(searchmask, "*.map" );
break;
case QCCLIB:
Com->Compile.DAT();
strcpy(typemod, "progs" );
strcpy(searchmask, "*.src" );
break;
case DEFAULT:
strcpy(typemod, "things" );
strcpy(searchmask, "*.*" );
break;
}
if(!CompileMod) return;//back to shutdown
mempool = Mem_AllocPool("compiler");
if(!GetParmFromCmdLine("-qcfile", qcfilename ))
if(!GetParmFromCmdLine("-file", filename ))
{
//search for all .ac files in folder
search = Com->Fs.Search("*.qc", true );
if(!search) Sys_Error("no qcfiles found in this folder!\n");
search = Com->Fs.Search(searchmask, true );
if(!search) Sys_Error("no %s found in this folder!\n", searchmask );
for( i = 0; i < search->numfilenames; i++ )
{
@ -256,7 +272,7 @@ void CommonMain ( void )
numCompiledMods++;
}
}
else CompileMod( mempool, qcfilename, parms );
else CompileMod( mempool, filename, parms );
end = Com->DoubleTime();
Msg ("%5.1f seconds elapsed\n", end - start);
@ -302,6 +318,7 @@ void CreateInstance( void )
break;
case BSPLIB:
case QCCLIB:
case IMGLIB:
case SPRITE:
case STUDIO:
CreateCom = (void *)linked_dll->main;

View File

@ -16,6 +16,10 @@ cd ..
cd editor
makefile.nmake
cd ..
cd imglib
makefile.nmake
cd ..
cd qcclib
makefile.nmake

View File

@ -44,6 +44,23 @@ _inline void VectorScale(const vec3_t a, const float b, vec3_t c){c[0]=b*a[0];c[
#define VectorMAMAMAM(scale1, b1, scale2, b2, scale3, b3, scale4, b4, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0] + (scale4) * (b4)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1] + (scale4) * (b4)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2] + (scale4) * (b4)[2])
_inline float anglemod(const float a){return(360.0/65536) * ((int)(a*(65536/360.0)) & 65535);}
_inline int nearest_pow(int size)
{
int i = 2;
while( 1 )
{
i <<= 1;
if (size == i) return i;
if (size > i && size < (i <<1))
{
if (size >= ((i+(i<<1))/2))
return i<<1;
else return i;
}
}
}
_inline void VectorBound(const float min, vec3_t v, const float max)
{
v[0] = bound(min, v[0], max);

View File

@ -49,7 +49,6 @@
enum comp_format
{
PF_UNKNOWN = 0,
PF_INDEXED_8, // pcx or wal images with transparent color in palette
PF_INDEXED_24, // studio model skins
PF_INDEXED_32, // sprite 32-bit palette
PF_RGBA_32, // already prepared ".bmp", ".tga" or ".jpg" image
@ -104,7 +103,6 @@ typedef struct
static bpc_desc_t PixelFormatDescription[] =
{
{PF_INDEXED_8, "pal 8", 4, 1, 0 },
{PF_INDEXED_24, "pal 24", 3, 1, 0 },
{PF_INDEXED_32, "pal 32", 4, 1, 0 },
{PF_RGBA_32, "RGBA", 4, 1, -4 },
@ -385,6 +383,7 @@ typedef struct filesystem_api_s
byte *(*LoadFile)(const char *path, long *filesize ); // load file into heap
bool (*WriteFile)(const char *filename, void *data, long len); // write file into disk
rgbdata_t *(*LoadImage)(const char *filename, char *data, int size ); // returned rgb data image
void (*SaveImage)(const char *filename, rgbdata_t *buffer ); // write image into disk
void (*FreeImage)( rgbdata_t *pack ); // release image buffer
} filesystem_api_t;
@ -425,7 +424,7 @@ typedef struct memsystem_api_s
// user simply interface
void *(*Alloc)(byte *pool, size_t size, const char *file, int line); //same as malloc
void *(*Realloc)(byte *pool, void *mem, size_t size, const char *file, int line); //same as realloc
void (*Move)(void *dest, void *src, size_t size, const char *file, int line); //same as memmove
void (*Move)(byte *pool, void **dest, void *src, size_t size, const char *file, int line);//same as memmove
void (*Copy)(void *dest, void *src, size_t size, const char *file, int line); //same as memcpy
void (*Free)(void *data, const char *file, int line); //same as free
@ -489,6 +488,7 @@ typedef struct compilers_api_s
bool (*Studio)( byte *mempool, const char *name, byte parms ); // input name of qc-script
bool (*Sprite)( byte *mempool, const char *name, byte parms ); // input name of qc-script
bool (*Image)( byte *mempool, const char *name, byte parms ); // input name of image
bool (*PrepareBSP)( const char *dir, const char *name, byte params ); // compile map in gamedir
bool (*BSP)( void );
bool (*PrepareDAT)( const char *dir, const char *name, byte params ); // compile dat in gamedir

View File

@ -38,7 +38,7 @@ Draw_InitLocal
void Draw_InitLocal (void)
{
// load console characters (don't bilerp characters)
draw_chars = R_FindImage ("base_menu/conchars.tga", def_font, sizeof(def_font), it_pic);
draw_chars = R_FindImage ("fonts/conchars", def_font, sizeof(def_font), it_pic);
GL_Bind( draw_chars->texnum[0] );
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

View File

@ -100,11 +100,7 @@ void R_ImageList_f (void)
{
int i;
image_t *image;
const char *palstrings[2] =
{
"RGB",
"PAL"
};
const char *palstrings[2] = {"RGB","PAL"};
Msg( "------------------\n");
for (i = 0, image = gltextures; i < numgltextures; i++, image++)
@ -112,11 +108,11 @@ void R_ImageList_f (void)
if (image->texnum[0] <= 0) continue;
switch (image->type)
{
case it_skin: Msg( "Skin"); break;
case it_sprite: Msg( "Spr "); break;
case it_wall: Msg( "Wall"); break;
case it_pic: Msg( "Pic "); break;
case it_sky: Msg( "Sky "); break;
case it_wall: Msg( "Wall"); break;
case it_skin: Msg( "Skin"); break;
case it_sprite: Msg( "Spr "); break;
case it_cubemap: Msg( "Cubemap "); break;
default: Msg( "Sys "); break;
}
@ -159,7 +155,7 @@ void R_SetPixelFormat( int width, int height, int depth )
image_desc.SizeOfFile = file_size;
}
if (image_desc.width * image_desc.height > imagebufsize / 4)// warning
if (image_desc.width * image_desc.height > imagebufsize / 4) // warning
MsgWarn("R_SetPixelFormat: image too big [%i*%i]\n", image_desc.width, image_desc.height);
}
@ -220,7 +216,7 @@ void R_GetPixelFormat( rgbdata_t *pic, imagetype_t type )
image_desc.SizeOfFile = file_size;
}
//don't build mips for sky & hud pics
// don't build mips for sky and hud pics
if(type == it_pic || type == it_sky) image_desc.flags &= ~IMAGE_GEN_MIPS;
else image_desc.flags |= IMAGE_GEN_MIPS;
@ -474,8 +470,9 @@ void R_RoundImageDimensions(int *scaled_width, int *scaled_height, bool mipmap)
{
int width = *scaled_width;
int height = *scaled_height;
for (*scaled_width = 1; *scaled_width < width; *scaled_width<<=1);
for (*scaled_height = 1; *scaled_height < height; *scaled_height<<=1);
*scaled_width = nearest_pow( *scaled_width );
*scaled_height = nearest_pow( *scaled_height);
if (mipmap)
{
@ -496,41 +493,54 @@ void R_RoundImageDimensions(int *scaled_width, int *scaled_height, bool mipmap)
bool R_ResampleTexture (uint *in, int inwidth, int inheight, uint *out, int outwidth, int outheight)
{
int i, j;
uint *inrow;
uint frac, fracstep;
uint *inrow, *inrow2;
uint p1[4096], p2[4096];
byte *pix1, *pix2, *pix3, *pix4;
//check for buffers
if(!in || !out) return false;
if(!in || !out || in == out) return false;
if(outheight == 0 || outwidth == 0) return false;
// nothing to resample ?
if (inwidth == outwidth && inheight == outheight)
{
memcpy (out, in, inwidth * inheight * 4);
memcpy(out, in, inwidth * inheight * 4);
return false;
}
fracstep = inwidth * 0x10000/outwidth;
fracstep = inwidth * 0x10000 / outwidth;
frac = fracstep>>2;
for( i = 0; i < outwidth; i++)
{
p1[i] = 4 * (frac>>16);
frac += fracstep;
}
frac = 3 * (fracstep>>2);
for( i = 0; i < outwidth; i++)
{
p2[i] = 4 * (frac>>16);
frac += fracstep;
}
for (i = 0; i < outheight; i++, out += outwidth)
{
inrow = in + inwidth*(i*inheight/outheight);
frac = outwidth*fracstep;
j = outwidth - 1;
while ((j+1) &3)
inrow = in + inwidth * (int)((i + 0.25) * inheight / outheight);
inrow2 = in + inwidth * (int)((i + 0.75) * inheight / outheight);
frac = fracstep>>1;
for (j = 0; j < outwidth; j++)
{
out[j] = inrow[frac>>16];
frac -= fracstep;
j--;
}
for (; j >= 0; j -= 4)
{
out[j+3] = inrow[frac>>16];
frac -= fracstep;
out[j+2] = inrow[frac>>16];
frac -= fracstep;
out[j+1] = inrow[frac>>16];
frac -= fracstep;
out[j+0] = inrow[frac>>16];
frac -= fracstep;
pix1 = (byte *)inrow + p1[j];
pix2 = (byte *)inrow + p2[j];
pix3 = (byte *)inrow2 + p1[j];
pix4 = (byte *)inrow2 + p2[j];
((byte *)(out+j))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2;
((byte *)(out+j))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2;
((byte *)(out+j))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2;
((byte *)(out+j))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3])>>2;
}
}
return true;
@ -665,8 +675,8 @@ bool qrsCompressedTexImage2D( uint target, int level, int internalformat, uint w
}
}
break;
case PF_DXT2:
case PF_DXT3:
case PF_DXT2:
case PF_DXT3:
for (z = 0; z < image_desc.numLayers; z++)
{
for (y = 0; y < h; y += 4)
@ -729,8 +739,8 @@ bool qrsCompressedTexImage2D( uint target, int level, int internalformat, uint w
// so the result will be wrong unless corrected.
if(image_desc.flags & IMAGE_PREMULT) R_ImageCorrectPreMult( (uint *)fout, image_desc.SizeOfData );
break;
case PF_DXT4:
case PF_DXT5:
case PF_DXT4:
case PF_DXT5:
for (z = 0; z < image_desc.numLayers; z++)
{
for (y = 0; y < h; y += 4)
@ -839,7 +849,7 @@ bool qrsCompressedTexImage2D( uint target, int level, int internalformat, uint w
// so the result will be wrong unless corrected.
if(image_desc.flags & IMAGE_PREMULT) R_ImageCorrectPreMult( (uint *)fout, image_desc.SizeOfData );
break;
case PF_RXGB:
case PF_RXGB:
for (z = 0; z < image_desc.numLayers; z++)
{
for (y = 0; y < h; y += 4)
@ -1000,7 +1010,7 @@ bool CompressedTexImage2D( uint target, int level, int intformat, uint width, ui
if(!qglGetError()) return true;
// otherwise try loading with software unpacker
}
return qrsCompressedTexImage2D(target, level, pixformat, width, height, border, imageSize, data );
return qrsCompressedTexImage2D(target, level, pixformat, width, height, border, imageSize, data );
}
/*
@ -1011,8 +1021,8 @@ R_LoadTexImage
bool R_LoadTexImage( uint *data )
{
int samples, miplevel = 0;
unsigned *scaled = (unsigned *)uploadbuffer;
int scaled_width, scaled_height;
uint *scaled = (unsigned *)uploadbuffer;
bool mipmap = (image_desc.flags & IMAGE_GEN_MIPS) ? true : false;
scaled_width = image_desc.width;
@ -1424,7 +1434,7 @@ bool R_LoadImage32 (byte *data )
byte *trans = imagebuffer;
int i, s = image_desc.width * image_desc.height;
//nothing to process
// nothing to process
if(!image_desc.pal) return R_LoadTexImage((uint*)data );
if (s&3)
@ -1442,44 +1452,6 @@ bool R_LoadImage32 (byte *data )
return R_LoadTexImage((uint*)trans );
}
/*
===============
R_LoadImage8
===============
*/
bool R_LoadImage8( byte *data )
{
uint *trans = (uint *)imagebuffer;
int i, p, s = image_desc.width * image_desc.height;
for (i=0 ; i<s ; i++)
{
p = data[i];
trans[i] = d_8to24table[p];
if (p == 255)
{
// transparent, so scan around for another color
// to avoid alpha fringes
// FIXME: do a full flood fill so mips work...
if (i > image_desc.width && data[i-image_desc.width] != 255)
p = data[i - image_desc.width];
else if (i < s-image_desc.width && data[i+image_desc.width] != 255)
p = data[i + image_desc.width];
else if (i > 0 && data[i - 1] != 255) p = data[i-1];
else if (i < s-1 && data[i+1] != 255) p = data[i+1];
else p = 0;
// copy rgb components
((byte *)&trans[i])[0] = ((byte *)&d_8to24table[p])[0];
((byte *)&trans[i])[1] = ((byte *)&d_8to24table[p])[1];
((byte *)&trans[i])[2] = ((byte *)&d_8to24table[p])[2];
}
}
return R_LoadTexImage ( trans );
}
/*
===============
R_LoadImage24
@ -1492,6 +1464,12 @@ bool R_LoadImage24(byte *data )
bool noalpha;
int p;
if (s&3)
{
MsgDev(D_ERROR, "R_LoadImage24: s&3\n");
return false;
}
// if there are no transparent pixels, make it a 3 component
// texture even if it was specified as otherwise
if (image_desc.flags & IMAGE_HAS_ALPHA)
@ -1526,11 +1504,6 @@ bool R_LoadImage24(byte *data )
}
else
{
if (s&3)
{
MsgDev(D_ERROR, "R_LoadImage24: s&3\n");
return false;
}
if(image_desc.pal)
{
for (i = 0; i < s; i+=1)
@ -1650,7 +1623,6 @@ image_t *R_LoadImage(char *name, rgbdata_t *pic, imagetype_t type )
switch(pic->type)
{
case PF_INDEXED_8: iResult = R_LoadImage8 ( buf ); break;
case PF_INDEXED_24: iResult = R_LoadImage24( buf ); break;
case PF_INDEXED_32: iResult = R_LoadImage32( buf ); break;
case PF_PROCEDURE_TEX: