2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
|
|
|
Copyright (C) 2002-2009 John Fitzgibbons and others
|
|
|
|
Copyright (C) 2007-2008 Kristian Duske
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//gl_texmgr.c -- fitzquake's texture manager. manages opengl texture images
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
|
|
|
const int gl_solid_format = 3;
|
|
|
|
const int gl_alpha_format = 4;
|
|
|
|
|
2012-01-23 18:51:12 +00:00
|
|
|
static cvar_t gl_texturemode = {"gl_texturemode", "", CVAR_ARCHIVE};
|
2011-12-30 14:00:28 +00:00
|
|
|
static cvar_t gl_texture_anisotropy = {"gl_texture_anisotropy", "1", CVAR_ARCHIVE};
|
|
|
|
static cvar_t gl_max_size = {"gl_max_size", "0", CVAR_NONE};
|
|
|
|
static cvar_t gl_picmip = {"gl_picmip", "0", CVAR_NONE};
|
|
|
|
static GLint gl_hardware_maxsize;
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
#define MAX_GLTEXTURES 2048
|
2011-12-30 14:00:28 +00:00
|
|
|
static int numgltextures;
|
|
|
|
static gltexture_t *active_gltextures, *free_gltextures;
|
|
|
|
gltexture_t *notexture, *nulltexture;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-04-22 19:02:29 +00:00
|
|
|
unsigned int d_8to24table[256];
|
|
|
|
unsigned int d_8to24table_fbright[256];
|
|
|
|
unsigned int d_8to24table_nobright[256];
|
|
|
|
unsigned int d_8to24table_conchars[256];
|
|
|
|
unsigned int d_8to24table_shirt[256];
|
|
|
|
unsigned int d_8to24table_pants[256];
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
COMMANDS
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int magfilter;
|
2010-08-29 02:22:55 +00:00
|
|
|
int minfilter;
|
|
|
|
const char *name;
|
2010-02-15 23:26:55 +00:00
|
|
|
} glmode_t;
|
2012-01-24 21:24:14 +00:00
|
|
|
static glmode_t glmodes[] = {
|
2011-12-30 14:00:28 +00:00
|
|
|
{GL_NEAREST, GL_NEAREST, "GL_NEAREST"},
|
2010-02-15 23:26:55 +00:00
|
|
|
{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, "GL_NEAREST_MIPMAP_NEAREST"},
|
|
|
|
{GL_NEAREST, GL_NEAREST_MIPMAP_LINEAR, "GL_NEAREST_MIPMAP_LINEAR"},
|
2011-12-30 14:00:28 +00:00
|
|
|
{GL_LINEAR, GL_LINEAR, "GL_LINEAR"},
|
2010-02-15 23:26:55 +00:00
|
|
|
{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, "GL_LINEAR_MIPMAP_NEAREST"},
|
|
|
|
{GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, "GL_LINEAR_MIPMAP_LINEAR"},
|
|
|
|
};
|
2012-03-08 10:14:58 +00:00
|
|
|
#define NUM_GLMODES (int)(sizeof(glmodes)/sizeof(glmodes[0]))
|
2012-01-24 21:24:14 +00:00
|
|
|
static int glmode_idx = NUM_GLMODES - 1; /* trilinear */
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_DescribeTextureModes_f -- report available texturemodes
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_DescribeTextureModes_f (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < NUM_GLMODES; i++)
|
2012-01-24 21:24:14 +00:00
|
|
|
Con_SafePrintf (" %2i: %s\n", i + 1, glmodes[i].name);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
Con_Printf ("%i modes\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_SetFilterModes
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_SetFilterModes (gltexture_t *glt)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
GL_Bind (glt);
|
|
|
|
|
|
|
|
if (glt->flags & TEXPREF_NEAREST)
|
|
|
|
{
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
}
|
|
|
|
else if (glt->flags & TEXPREF_LINEAR)
|
|
|
|
{
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
else if (glt->flags & TEXPREF_MIPMAP)
|
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glmodes[glmode_idx].magfilter);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glmodes[glmode_idx].minfilter);
|
2012-02-18 22:04:38 +00:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_anisotropy.value);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glmodes[glmode_idx].magfilter);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glmodes[glmode_idx].magfilter);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
2012-01-20 18:59:20 +00:00
|
|
|
TexMgr_TextureMode_f -- called when gl_texturemode changes
|
2010-02-15 23:26:55 +00:00
|
|
|
===============
|
|
|
|
*/
|
2012-01-20 18:59:20 +00:00
|
|
|
static void TexMgr_TextureMode_f (cvar_t *var)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
int i;
|
|
|
|
|
2012-01-20 18:59:20 +00:00
|
|
|
for (i = 0; i < NUM_GLMODES; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
if (!Q_strcmp (glmodes[i].name, gl_texturemode.string))
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
if (glmode_idx != i)
|
2012-01-20 19:31:18 +00:00
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
glmode_idx = i;
|
2012-01-20 19:31:18 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
|
|
|
TexMgr_SetFilterModes (glt);
|
|
|
|
Sbar_Changed (); //sbar graphics need to be redrawn with new filter mode
|
|
|
|
//FIXME: warpimages need to be redrawn, too.
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-20 18:59:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_GLMODES; i++)
|
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
if (!Q_strcasecmp (glmodes[i].name, gl_texturemode.string))
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
Cvar_SetQuick (&gl_texturemode, glmodes[i].name);
|
2012-01-20 18:59:20 +00:00
|
|
|
return;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
2012-01-20 18:59:20 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2012-01-20 18:59:20 +00:00
|
|
|
i = atoi(gl_texturemode.string);
|
|
|
|
if (i >= 1 && i <= NUM_GLMODES)
|
|
|
|
{
|
2012-01-24 21:24:14 +00:00
|
|
|
Cvar_SetQuick (&gl_texturemode, glmodes[i-1].name);
|
2012-01-20 18:59:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2012-01-20 18:59:20 +00:00
|
|
|
Con_Printf ("\"%s\" is not a valid texturemode\n", gl_texturemode.string);
|
2012-01-24 21:24:14 +00:00
|
|
|
Cvar_SetQuick (&gl_texturemode, glmodes[glmode_idx].name);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_Anisotropy_f -- called when gl_texture_anisotropy changes
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_Anisotropy_f (cvar_t *var)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2012-01-19 20:22:29 +00:00
|
|
|
if (gl_texture_anisotropy.value < 1)
|
|
|
|
{
|
|
|
|
Cvar_SetQuick (&gl_texture_anisotropy, "1");
|
|
|
|
}
|
|
|
|
else if (gl_texture_anisotropy.value > gl_max_anisotropy)
|
|
|
|
{
|
|
|
|
Cvar_SetValueQuick (&gl_texture_anisotropy, gl_max_anisotropy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2012-02-18 22:04:38 +00:00
|
|
|
{
|
|
|
|
/* TexMgr_SetFilterModes (glt);*/
|
|
|
|
if (glt->flags & TEXPREF_MIPMAP) {
|
|
|
|
GL_Bind (glt);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glmodes[glmode_idx].magfilter);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glmodes[glmode_idx].minfilter);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_anisotropy.value);
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 20:22:29 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_Imagelist_f -- report loaded textures
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_Imagelist_f (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
float mb;
|
|
|
|
float texels = 0;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf (" %4i x%4i %s\n", glt->width, glt->height, glt->name);
|
|
|
|
if (glt->flags & TEXPREF_MIPMAP)
|
|
|
|
texels += glt->width * glt->height * 4.0f / 3.0f;
|
|
|
|
else
|
|
|
|
texels += (glt->width * glt->height);
|
|
|
|
}
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
mb = texels * (Cvar_VariableValue("vid_bpp") / 8.0f) / 0x100000;
|
2010-02-15 23:26:55 +00:00
|
|
|
Con_Printf ("%i textures %i pixels %1.1f megabytes\n", numgltextures, (int)texels, mb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_Imagedump_f -- dump all current textures to TGA files
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_Imagedump_f (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
char tganame[MAX_OSPATH], tempname[MAX_OSPATH], dirname[MAX_OSPATH];
|
|
|
|
gltexture_t *glt;
|
|
|
|
byte *buffer;
|
|
|
|
char *c;
|
|
|
|
|
|
|
|
//create directory
|
2011-12-27 10:50:42 +00:00
|
|
|
q_snprintf(dirname, sizeof(dirname), "%s/imagedump", com_gamedir);
|
2010-02-15 23:26:55 +00:00
|
|
|
Sys_mkdir (dirname);
|
|
|
|
|
|
|
|
//loop through textures
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-27 13:15:31 +00:00
|
|
|
q_strlcpy (tempname, glt->name, sizeof(tempname));
|
chase.c, cl_input.c, cl_parse.c, client.h, common.c, common.h, console.h,
cvar.h, draw.h, gl_draw.c, gl_fog.c, gl_mesh.c, gl_model.c, gl_model.h,
gl_rmain.c, gl_rmisc.c, gl_screen.c, gl_sky.c, gl_texmgr.c, glquake.h,
host.c, keys.c, keys.h, main.c, menu.c, menu.h, pr_cmds.c, quakedef.h,
r_alias.c, r_brush.c, r_part.c, r_sprite.c, r_world.c, sbar.c, sbar.h,
screen.h, snd_dma.c, snd_mem.c, snd_mix.c, sv_main.c, sys_sdl.c, vid.h,
view.h, world.c, world.h: Loads of warning fixes about missing function
prototypes, missing parens around &, missing braces leading to ambiguous
else statements and unused and uninitialized variables. There are still a
couple of unitialised variables here and there, but not much. The warnings
about strict aliasing violations need taking care of.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@21 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-16 12:01:07 +00:00
|
|
|
while ( (c = strchr(tempname, ':')) ) *c = '_';
|
|
|
|
while ( (c = strchr(tempname, '/')) ) *c = '_';
|
|
|
|
while ( (c = strchr(tempname, '*')) ) *c = '_';
|
2011-12-27 10:50:42 +00:00
|
|
|
q_snprintf(tganame, sizeof(tganame), "imagedump/%s.tga", tempname);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
GL_Bind (glt);
|
|
|
|
if (glt->flags & TEXPREF_ALPHA)
|
|
|
|
{
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
buffer = (byte *) malloc(glt->width*glt->height*4);
|
2010-02-15 23:26:55 +00:00
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
Image_WriteTGA (tganame, buffer, glt->width, glt->height, 32, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
buffer = (byte *) malloc(glt->width*glt->height*3);
|
2010-02-15 23:26:55 +00:00
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
Image_WriteTGA (tganame, buffer, glt->width, glt->height, 24, true);
|
|
|
|
}
|
|
|
|
free (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf ("dumped %i textures to %s\n", numgltextures, dirname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_FrameUsage -- report texture memory usage for this frame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
float TexMgr_FrameUsage (void)
|
|
|
|
{
|
|
|
|
float mb;
|
|
|
|
float texels = 0;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
|
|
|
{
|
2010-02-15 23:26:55 +00:00
|
|
|
if (glt->visframe == r_framecount)
|
|
|
|
{
|
|
|
|
if (glt->flags & TEXPREF_MIPMAP)
|
|
|
|
texels += glt->width * glt->height * 4.0f / 3.0f;
|
|
|
|
else
|
|
|
|
texels += (glt->width * glt->height);
|
|
|
|
}
|
2011-12-30 14:00:28 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
mb = texels * (Cvar_VariableValue("vid_bpp") / 8.0f) / 0x100000;
|
2010-02-15 23:26:55 +00:00
|
|
|
return mb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
TEXTURE MANAGER
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_FindTexture
|
|
|
|
================
|
|
|
|
*/
|
2012-05-30 08:56:06 +00:00
|
|
|
gltexture_t *TexMgr_FindTexture (qmodel_t *owner, const char *name)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
|
|
|
{
|
2010-02-15 23:26:55 +00:00
|
|
|
if (glt->owner == owner && !strcmp (glt->name, name))
|
|
|
|
return glt;
|
2011-12-30 14:00:28 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_NewTexture
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
gltexture_t *TexMgr_NewTexture (void)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
if (numgltextures == MAX_GLTEXTURES)
|
|
|
|
Sys_Error("numgltextures == MAX_GLTEXTURES\n");
|
|
|
|
|
|
|
|
glt = free_gltextures;
|
|
|
|
free_gltextures = glt->next;
|
|
|
|
glt->next = active_gltextures;
|
|
|
|
active_gltextures = glt;
|
|
|
|
|
2011-12-29 19:06:08 +00:00
|
|
|
glGenTextures(1, &glt->texnum);
|
2010-02-15 23:26:55 +00:00
|
|
|
numgltextures++;
|
|
|
|
return glt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_FreeTexture
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TexMgr_FreeTexture (gltexture_t *kill)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
if (kill == NULL)
|
|
|
|
{
|
|
|
|
Con_Printf ("TexMgr_FreeTexture: NULL texture\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active_gltextures == kill)
|
|
|
|
{
|
|
|
|
active_gltextures = kill->next;
|
|
|
|
kill->next = free_gltextures;
|
|
|
|
free_gltextures = kill;
|
|
|
|
|
2011-12-29 19:06:08 +00:00
|
|
|
glDeleteTextures(1, &kill->texnum);
|
2010-02-15 23:26:55 +00:00
|
|
|
numgltextures--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2011-12-30 14:00:28 +00:00
|
|
|
{
|
2010-02-15 23:26:55 +00:00
|
|
|
if (glt->next == kill)
|
|
|
|
{
|
|
|
|
glt->next = kill->next;
|
|
|
|
kill->next = free_gltextures;
|
|
|
|
free_gltextures = kill;
|
|
|
|
|
2011-12-29 19:06:08 +00:00
|
|
|
glDeleteTextures(1, &kill->texnum);
|
2010-02-15 23:26:55 +00:00
|
|
|
numgltextures--;
|
|
|
|
return;
|
|
|
|
}
|
2011-12-30 14:00:28 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
Con_Printf ("TexMgr_FreeTexture: not found\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_FreeTextures
|
|
|
|
|
|
|
|
compares each bit in "flags" to the one in glt->flags only if that bit is active in "mask"
|
|
|
|
================
|
|
|
|
*/
|
2012-03-31 18:30:09 +00:00
|
|
|
void TexMgr_FreeTextures (unsigned int flags, unsigned int mask)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt, *next;
|
|
|
|
|
|
|
|
for (glt = active_gltextures; glt; glt = next)
|
|
|
|
{
|
|
|
|
next = glt->next;
|
|
|
|
if ((glt->flags & mask) == (flags & mask))
|
|
|
|
TexMgr_FreeTexture (glt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_FreeTexturesForOwner
|
|
|
|
================
|
|
|
|
*/
|
2012-05-30 08:56:06 +00:00
|
|
|
void TexMgr_FreeTexturesForOwner (qmodel_t *owner)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt, *next;
|
|
|
|
|
|
|
|
for (glt = active_gltextures; glt; glt = next)
|
|
|
|
{
|
|
|
|
next = glt->next;
|
|
|
|
if (glt && glt->owner == owner)
|
|
|
|
TexMgr_FreeTexture (glt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
INIT
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
TexMgr_LoadPalette -- johnfitz -- was VID_SetPalette, moved here, renamed, rewritten
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void TexMgr_LoadPalette (void)
|
|
|
|
{
|
|
|
|
byte *pal, *src, *dst;
|
|
|
|
int i, mark;
|
|
|
|
FILE *f;
|
|
|
|
|
2011-01-02 21:45:16 +00:00
|
|
|
COM_FOpenFile ("gfx/palette.lmp", &f, NULL);
|
2010-02-15 23:26:55 +00:00
|
|
|
if (!f)
|
|
|
|
Sys_Error ("Couldn't load gfx/palette.lmp");
|
|
|
|
|
|
|
|
mark = Hunk_LowMark ();
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
pal = (byte *) Hunk_Alloc (768);
|
2010-02-15 23:26:55 +00:00
|
|
|
fread (pal, 1, 768, f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
//standard palette, 255 is transparent
|
|
|
|
dst = (byte *)d_8to24table;
|
|
|
|
src = pal;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = 255;
|
|
|
|
}
|
2011-01-01 14:05:20 +00:00
|
|
|
((byte *) &d_8to24table[255]) [3] = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//fullbright palette, 0-223 are black (for additive blending)
|
|
|
|
src = pal + 224*3;
|
2011-12-15 06:37:12 +00:00
|
|
|
dst = (byte *) &d_8to24table_fbright[224];
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 224; i < 256; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = 255;
|
|
|
|
}
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < 224; i++)
|
2011-01-01 14:05:20 +00:00
|
|
|
{
|
|
|
|
dst = (byte *) &d_8to24table_fbright[i];
|
|
|
|
dst[3] = 255;
|
|
|
|
dst[2] = dst[1] = dst[0] = 0;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//nobright palette, 224-255 are black (for additive blending)
|
|
|
|
dst = (byte *)d_8to24table_nobright;
|
|
|
|
src = pal;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = *src++;
|
|
|
|
*dst++ = 255;
|
|
|
|
}
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 224; i < 256; i++)
|
2011-01-01 14:05:20 +00:00
|
|
|
{
|
|
|
|
dst = (byte *) &d_8to24table_nobright[i];
|
|
|
|
dst[3] = 255;
|
|
|
|
dst[2] = dst[1] = dst[0] = 0;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//conchars palette, 0 and 255 are transparent
|
|
|
|
memcpy(d_8to24table_conchars, d_8to24table, 256*4);
|
2011-01-01 14:05:20 +00:00
|
|
|
((byte *) &d_8to24table_conchars[0]) [3] = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
Hunk_FreeToLowMark (mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_NewGame
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TexMgr_NewGame (void)
|
|
|
|
{
|
|
|
|
TexMgr_FreeTextures (0, TEXPREF_PERSIST); //deletes all textures where TEXPREF_PERSIST is unset
|
|
|
|
TexMgr_LoadPalette ();
|
2011-01-12 09:32:22 +00:00
|
|
|
#if defined(USE_QS_CONBACK)
|
2010-02-20 09:55:32 +00:00
|
|
|
/* QuakeSpasm customization: */
|
|
|
|
Draw_CheckConback ();
|
2011-01-12 09:32:22 +00:00
|
|
|
#endif /* USE_QS_CONBACK */
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
TexMgr_RecalcWarpImageSize -- called during init, and after a vid_restart
|
|
|
|
|
|
|
|
choose safe warpimage size and resize existing warpimage textures
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void TexMgr_RecalcWarpImageSize (void)
|
|
|
|
{
|
|
|
|
int mark, oldsize;
|
|
|
|
gltexture_t *glt;
|
|
|
|
byte *dummy;
|
|
|
|
|
|
|
|
//
|
|
|
|
// find the new correct size
|
|
|
|
//
|
|
|
|
oldsize = gl_warpimagesize;
|
|
|
|
|
|
|
|
gl_warpimagesize = TexMgr_SafeTextureSize (512);
|
|
|
|
|
2012-03-08 10:14:58 +00:00
|
|
|
while (gl_warpimagesize > vid.width)
|
2010-02-15 23:26:55 +00:00
|
|
|
gl_warpimagesize >>= 1;
|
2012-03-08 10:14:58 +00:00
|
|
|
while (gl_warpimagesize > vid.height)
|
2010-02-15 23:26:55 +00:00
|
|
|
gl_warpimagesize >>= 1;
|
|
|
|
|
|
|
|
if (gl_warpimagesize == oldsize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//
|
|
|
|
// resize the textures in opengl
|
|
|
|
//
|
|
|
|
mark = Hunk_LowMark();
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
dummy = (byte *) Hunk_Alloc (gl_warpimagesize*gl_warpimagesize*4);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
if (glt->flags & TEXPREF_WARPIMAGE)
|
|
|
|
{
|
|
|
|
GL_Bind (glt);
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, gl_warpimagesize, gl_warpimagesize, 0, GL_RGBA, GL_UNSIGNED_BYTE, dummy);
|
|
|
|
glt->width = glt->height = gl_warpimagesize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hunk_FreeToLowMark (mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_Init
|
|
|
|
|
|
|
|
must be called before any texture loading
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TexMgr_Init (void)
|
|
|
|
{
|
chase.c, cl_input.c, cl_parse.c, client.h, common.c, common.h, console.h,
cvar.h, draw.h, gl_draw.c, gl_fog.c, gl_mesh.c, gl_model.c, gl_model.h,
gl_rmain.c, gl_rmisc.c, gl_screen.c, gl_sky.c, gl_texmgr.c, glquake.h,
host.c, keys.c, keys.h, main.c, menu.c, menu.h, pr_cmds.c, quakedef.h,
r_alias.c, r_brush.c, r_part.c, r_sprite.c, r_world.c, sbar.c, sbar.h,
screen.h, snd_dma.c, snd_mem.c, snd_mix.c, sv_main.c, sys_sdl.c, vid.h,
view.h, world.c, world.h: Loads of warning fixes about missing function
prototypes, missing parens around &, missing braces leading to ambiguous
else statements and unused and uninitialized variables. There are still a
couple of unitialised variables here and there, but not much. The warnings
about strict aliasing violations need taking care of.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@21 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-16 12:01:07 +00:00
|
|
|
int i;
|
2010-02-15 23:26:55 +00:00
|
|
|
static byte notexture_data[16] = {159,91,83,255,0,0,0,255,0,0,0,255,159,91,83,255}; //black and pink checker
|
|
|
|
static byte nulltexture_data[16] = {127,191,255,255,0,0,0,255,0,0,0,255,127,191,255,255}; //black and blue checker
|
|
|
|
extern texture_t *r_notexture_mip, *r_notexture_mip2;
|
|
|
|
|
|
|
|
// init texture list
|
|
|
|
free_gltextures = (gltexture_t *) Hunk_AllocName (MAX_GLTEXTURES * sizeof(gltexture_t), "gltextures");
|
|
|
|
active_gltextures = NULL;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < MAX_GLTEXTURES - 1; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
free_gltextures[i].next = &free_gltextures[i+1];
|
|
|
|
free_gltextures[i].next = NULL;
|
|
|
|
numgltextures = 0;
|
|
|
|
|
|
|
|
// palette
|
|
|
|
TexMgr_LoadPalette ();
|
|
|
|
|
2011-12-28 22:01:33 +00:00
|
|
|
Cvar_RegisterVariable (&gl_max_size);
|
|
|
|
Cvar_RegisterVariable (&gl_picmip);
|
|
|
|
Cvar_RegisterVariable (&gl_texture_anisotropy);
|
2012-01-21 09:51:38 +00:00
|
|
|
Cvar_SetCallback (&gl_texture_anisotropy, &TexMgr_Anisotropy_f);
|
2012-01-24 21:24:14 +00:00
|
|
|
gl_texturemode.string = glmodes[glmode_idx].name;
|
2012-01-20 18:59:20 +00:00
|
|
|
Cvar_RegisterVariable (&gl_texturemode);
|
2012-01-21 09:51:38 +00:00
|
|
|
Cvar_SetCallback (&gl_texturemode, &TexMgr_TextureMode_f);
|
2010-02-15 23:26:55 +00:00
|
|
|
Cmd_AddCommand ("gl_describetexturemodes", &TexMgr_DescribeTextureModes_f);
|
|
|
|
Cmd_AddCommand ("imagelist", &TexMgr_Imagelist_f);
|
|
|
|
Cmd_AddCommand ("imagedump", &TexMgr_Imagedump_f);
|
|
|
|
|
|
|
|
// poll max size from hardware
|
|
|
|
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &gl_hardware_maxsize);
|
|
|
|
|
|
|
|
// load notexture images
|
64 bit compatibility effort, 2/nn: type correctness work in common.h,
gl_draw.c, gl_model.c, gl_sky.c, gl_texmgr.c, gl_texmgr.h, r_alias.c,
r_brush.c, r_part.c, r_world.c, snd_mem.c. next step will be server
side (progs) work which is actually the heart of the problems.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@34 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-16 21:26:11 +00:00
|
|
|
notexture = TexMgr_LoadImage (NULL, "notexture", 2, 2, SRC_RGBA, notexture_data, "", (src_offset_t)notexture_data, TEXPREF_NEAREST | TEXPREF_PERSIST | TEXPREF_NOPICMIP);
|
|
|
|
nulltexture = TexMgr_LoadImage (NULL, "nulltexture", 2, 2, SRC_RGBA, nulltexture_data, "", (src_offset_t)nulltexture_data, TEXPREF_NEAREST | TEXPREF_PERSIST | TEXPREF_NOPICMIP);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//have to assign these here becuase Mod_Init is called before TexMgr_Init
|
|
|
|
r_notexture_mip->gltexture = r_notexture_mip2->gltexture = notexture;
|
|
|
|
|
|
|
|
//set safe size for warpimages
|
|
|
|
gl_warpimagesize = 0;
|
|
|
|
TexMgr_RecalcWarpImageSize ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
IMAGE LOADING
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_Pad -- return smallest power of two greater than or equal to s
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int TexMgr_Pad (int s)
|
|
|
|
{
|
|
|
|
int i;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 1; i < s; i<<=1)
|
|
|
|
;
|
2010-02-15 23:26:55 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_SafeTextureSize -- return a size with hardware and user prefs in mind
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
int TexMgr_SafeTextureSize (int s)
|
|
|
|
{
|
|
|
|
s = TexMgr_Pad(s);
|
|
|
|
if ((int)gl_max_size.value > 0)
|
2011-01-10 10:35:40 +00:00
|
|
|
s = q_min(TexMgr_Pad((int)gl_max_size.value), s);
|
|
|
|
s = q_min(gl_hardware_maxsize, s);
|
2010-02-15 23:26:55 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_PadConditional -- only pad if a texture of that size would be padded. (used for tex coords)
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int TexMgr_PadConditional (int s)
|
|
|
|
{
|
|
|
|
if (s < TexMgr_SafeTextureSize(s))
|
|
|
|
return TexMgr_Pad(s);
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_MipMapW
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static unsigned *TexMgr_MipMapW (unsigned *data, int width, int height)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
int i, size;
|
2010-02-15 23:26:55 +00:00
|
|
|
byte *out, *in;
|
|
|
|
|
|
|
|
out = in = (byte *)data;
|
|
|
|
size = (width*height)>>1;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < size; i++, out += 4, in += 8)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
out[0] = (in[0] + in[4])>>1;
|
|
|
|
out[1] = (in[1] + in[5])>>1;
|
|
|
|
out[2] = (in[2] + in[6])>>1;
|
|
|
|
out[3] = (in[3] + in[7])>>1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_MipMapH
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static unsigned *TexMgr_MipMapH (unsigned *data, int width, int height)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
int i, j;
|
2010-02-15 23:26:55 +00:00
|
|
|
byte *out, *in;
|
|
|
|
|
|
|
|
out = in = (byte *)data;
|
|
|
|
height>>=1;
|
|
|
|
width<<=2;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < height; i++, in += width)
|
|
|
|
{
|
|
|
|
for (j = 0; j < width; j += 4, out += 4, in += 4)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
out[0] = (in[0] + in[width+0])>>1;
|
|
|
|
out[1] = (in[1] + in[width+1])>>1;
|
|
|
|
out[2] = (in[2] + in[width+2])>>1;
|
|
|
|
out[3] = (in[3] + in[width+3])>>1;
|
|
|
|
}
|
2011-12-30 14:00:28 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_ResampleTexture -- bilinear resample
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static unsigned *TexMgr_ResampleTexture (unsigned *in, int inwidth, int inheight, qboolean alpha)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
byte *nwpx, *nepx, *swpx, *sepx, *dest;
|
|
|
|
unsigned xfrac, yfrac, x, y, modx, mody, imodx, imody, injump, outjump;
|
|
|
|
unsigned *out;
|
|
|
|
int i, j, outwidth, outheight;
|
|
|
|
|
|
|
|
if (inwidth == TexMgr_Pad(inwidth) && inheight == TexMgr_Pad(inheight))
|
|
|
|
return in;
|
|
|
|
|
|
|
|
outwidth = TexMgr_Pad(inwidth);
|
|
|
|
outheight = TexMgr_Pad(inheight);
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
out = (unsigned *) Hunk_Alloc(outwidth*outheight*4);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
xfrac = ((inwidth-1) << 16) / (outwidth-1);
|
|
|
|
yfrac = ((inheight-1) << 16) / (outheight-1);
|
|
|
|
y = outjump = 0;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < outheight; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
mody = (y>>8) & 0xFF;
|
|
|
|
imody = 256 - mody;
|
|
|
|
injump = (y>>16) * inwidth;
|
|
|
|
x = 0;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (j = 0; j < outwidth; j++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
modx = (x>>8) & 0xFF;
|
|
|
|
imodx = 256 - modx;
|
|
|
|
|
|
|
|
nwpx = (byte *)(in + (x>>16) + injump);
|
|
|
|
nepx = nwpx + 4;
|
|
|
|
swpx = nwpx + inwidth*4;
|
|
|
|
sepx = swpx + 4;
|
|
|
|
|
|
|
|
dest = (byte *)(out + outjump + j);
|
|
|
|
|
|
|
|
dest[0] = (nwpx[0]*imodx*imody + nepx[0]*modx*imody + swpx[0]*imodx*mody + sepx[0]*modx*mody)>>16;
|
|
|
|
dest[1] = (nwpx[1]*imodx*imody + nepx[1]*modx*imody + swpx[1]*imodx*mody + sepx[1]*modx*mody)>>16;
|
|
|
|
dest[2] = (nwpx[2]*imodx*imody + nepx[2]*modx*imody + swpx[2]*imodx*mody + sepx[2]*modx*mody)>>16;
|
|
|
|
if (alpha)
|
|
|
|
dest[3] = (nwpx[3]*imodx*imody + nepx[3]*modx*imody + swpx[3]*imodx*mody + sepx[3]*modx*mody)>>16;
|
|
|
|
else
|
|
|
|
dest[3] = 255;
|
|
|
|
|
|
|
|
x += xfrac;
|
|
|
|
}
|
|
|
|
outjump += outwidth;
|
|
|
|
y += yfrac;
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_AlphaEdgeFix
|
|
|
|
|
|
|
|
eliminate pink edges on sprites, etc.
|
|
|
|
operates in place on 32bit data
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_AlphaEdgeFix (byte *data, int width, int height)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
int i, j, n = 0, b, c[3] = {0,0,0},
|
|
|
|
lastrow, thisrow, nextrow,
|
|
|
|
lastpix, thispix, nextpix;
|
|
|
|
byte *dest = data;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < height; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
lastrow = width * 4 * ((i == 0) ? height-1 : i-1);
|
|
|
|
thisrow = width * 4 * i;
|
|
|
|
nextrow = width * 4 * ((i == height-1) ? 0 : i+1);
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (j = 0; j < width; j++, dest += 4)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
if (dest[3]) //not transparent
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lastpix = 4 * ((j == 0) ? width-1 : j-1);
|
|
|
|
thispix = 4 * j;
|
|
|
|
nextpix = 4 * ((j == width-1) ? 0 : j+1);
|
|
|
|
|
|
|
|
b = lastrow + lastpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = thisrow + lastpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = nextrow + lastpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = lastrow + thispix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = nextrow + thispix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = lastrow + nextpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = thisrow + nextpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
b = nextrow + nextpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
|
|
|
|
|
|
|
|
//average all non-transparent neighbors
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
dest[0] = (byte)(c[0]/n);
|
|
|
|
dest[1] = (byte)(c[1]/n);
|
|
|
|
dest[2] = (byte)(c[2]/n);
|
|
|
|
|
|
|
|
n = c[0] = c[1] = c[2] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_PadEdgeFixW -- special case of AlphaEdgeFix for textures that only need it because they were padded
|
|
|
|
|
|
|
|
operates in place on 32bit data, and expects unpadded height and width values
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_PadEdgeFixW (byte *data, int width, int height)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
byte *src, *dst;
|
|
|
|
int i, padw, padh;
|
|
|
|
|
|
|
|
padw = TexMgr_PadConditional(width);
|
|
|
|
padh = TexMgr_PadConditional(height);
|
|
|
|
|
|
|
|
//copy last full column to first empty column, leaving alpha byte at zero
|
|
|
|
src = data + (width - 1) * 4;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < padh; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
src[4] = src[0];
|
|
|
|
src[5] = src[1];
|
|
|
|
src[6] = src[2];
|
|
|
|
src += padw * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
//copy first full column to last empty column, leaving alpha byte at zero
|
|
|
|
src = data;
|
|
|
|
dst = data + (padw - 1) * 4;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < padh; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
src += padw * 4;
|
|
|
|
dst += padw * 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
TexMgr_PadEdgeFixH -- special case of AlphaEdgeFix for textures that only need it because they were padded
|
|
|
|
|
|
|
|
operates in place on 32bit data, and expects unpadded height and width values
|
|
|
|
===============
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_PadEdgeFixH (byte *data, int width, int height)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
byte *src, *dst;
|
|
|
|
int i, padw, padh;
|
|
|
|
|
|
|
|
padw = TexMgr_PadConditional(width);
|
|
|
|
padh = TexMgr_PadConditional(height);
|
|
|
|
|
|
|
|
//copy last full row to first empty row, leaving alpha byte at zero
|
|
|
|
dst = data + height * padw * 4;
|
|
|
|
src = dst - padw * 4;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < padw; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
src += 4;
|
|
|
|
dst += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
//copy first full row to last empty row, leaving alpha byte at zero
|
|
|
|
dst = data + (padh - 1) * padw * 4;
|
|
|
|
src = data;
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < padw; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[2];
|
|
|
|
src += 4;
|
|
|
|
dst += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_8to32
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static unsigned *TexMgr_8to32 (byte *in, int pixels, unsigned int *usepal)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned *out, *data;
|
|
|
|
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
out = data = (unsigned *) Hunk_Alloc(pixels*4);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < pixels; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
*out++ = usepal[*in++];
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_PadImageW -- return image with width padded up to power-of-two dimentions
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static byte *TexMgr_PadImageW (byte *in, int width, int height, byte padbyte)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
int i, j, outwidth;
|
|
|
|
byte *out, *data;
|
|
|
|
|
|
|
|
if (width == TexMgr_Pad(width))
|
|
|
|
return in;
|
|
|
|
|
|
|
|
outwidth = TexMgr_Pad(width);
|
|
|
|
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
out = data = (byte *) Hunk_Alloc(outwidth*height);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < height; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
for (j = 0; j < width; j++)
|
2010-02-15 23:26:55 +00:00
|
|
|
*out++ = *in++;
|
2011-12-30 14:00:28 +00:00
|
|
|
for ( ; j < outwidth; j++)
|
2010-02-15 23:26:55 +00:00
|
|
|
*out++ = padbyte;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_PadImageH -- return image with height padded up to power-of-two dimentions
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static byte *TexMgr_PadImageH (byte *in, int width, int height, byte padbyte)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
int i, srcpix, dstpix;
|
|
|
|
byte *data, *out;
|
|
|
|
|
|
|
|
if (height == TexMgr_Pad(height))
|
|
|
|
return in;
|
|
|
|
|
|
|
|
srcpix = width * height;
|
|
|
|
dstpix = width * TexMgr_Pad(height);
|
|
|
|
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
out = data = (byte *) Hunk_Alloc(dstpix);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < srcpix; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
*out++ = *in++;
|
2011-12-30 14:00:28 +00:00
|
|
|
for ( ; i < dstpix; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
*out++ = padbyte;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_LoadImage32 -- handles 32bit source data
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_LoadImage32 (gltexture_t *glt, unsigned *data)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
int internalformat, miplevel, mipwidth, mipheight, picmip;
|
|
|
|
|
|
|
|
// resample up
|
|
|
|
data = TexMgr_ResampleTexture (data, glt->width, glt->height, glt->flags & TEXPREF_ALPHA);
|
|
|
|
glt->width = TexMgr_Pad(glt->width);
|
|
|
|
glt->height = TexMgr_Pad(glt->height);
|
|
|
|
|
|
|
|
// mipmap down
|
2011-01-10 10:35:40 +00:00
|
|
|
picmip = (glt->flags & TEXPREF_NOPICMIP) ? 0 : q_max((int)gl_picmip.value, 0);
|
2010-02-15 23:26:55 +00:00
|
|
|
mipwidth = TexMgr_SafeTextureSize (glt->width >> picmip);
|
|
|
|
mipheight = TexMgr_SafeTextureSize (glt->height >> picmip);
|
2011-12-29 19:06:08 +00:00
|
|
|
while ((int) glt->width > mipwidth)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
TexMgr_MipMapW (data, glt->width, glt->height);
|
|
|
|
glt->width >>= 1;
|
|
|
|
if (glt->flags & TEXPREF_ALPHA)
|
|
|
|
TexMgr_AlphaEdgeFix ((byte *)data, glt->width, glt->height);
|
|
|
|
}
|
2011-12-29 19:06:08 +00:00
|
|
|
while ((int) glt->height > mipheight)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
TexMgr_MipMapH (data, glt->width, glt->height);
|
|
|
|
glt->height >>= 1;
|
|
|
|
if (glt->flags & TEXPREF_ALPHA)
|
|
|
|
TexMgr_AlphaEdgeFix ((byte *)data, glt->width, glt->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// upload
|
|
|
|
GL_Bind (glt);
|
|
|
|
internalformat = (glt->flags & TEXPREF_ALPHA) ? gl_alpha_format : gl_solid_format;
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, internalformat, glt->width, glt->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
|
|
|
|
|
|
|
// upload mipmaps
|
|
|
|
if (glt->flags & TEXPREF_MIPMAP)
|
|
|
|
{
|
|
|
|
mipwidth = glt->width;
|
|
|
|
mipheight = glt->height;
|
|
|
|
|
|
|
|
for (miplevel=1; mipwidth > 1 || mipheight > 1; miplevel++)
|
|
|
|
{
|
|
|
|
if (mipwidth > 1)
|
|
|
|
{
|
|
|
|
TexMgr_MipMapW (data, mipwidth, mipheight);
|
|
|
|
mipwidth >>= 1;
|
|
|
|
}
|
|
|
|
if (mipheight > 1)
|
|
|
|
{
|
|
|
|
TexMgr_MipMapH (data, mipwidth, mipheight);
|
|
|
|
mipheight >>= 1;
|
|
|
|
}
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, miplevel, internalformat, mipwidth, mipheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set filter modes
|
|
|
|
TexMgr_SetFilterModes (glt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_LoadImage8 -- handles 8bit source data, then passes it to LoadImage32
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_LoadImage8 (gltexture_t *glt, byte *data)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
extern cvar_t gl_fullbrights;
|
|
|
|
qboolean padw = false, padh = false;
|
|
|
|
byte padbyte;
|
|
|
|
unsigned int *usepal;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// HACK HACK HACK -- taken from tomazquake
|
2011-12-30 14:00:28 +00:00
|
|
|
if (strstr(glt->name, "shot1sid") &&
|
|
|
|
glt->width == 32 && glt->height == 32 &&
|
|
|
|
CRC_Block(data, 1024) == 65393)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
// This texture in b_shell1.bsp has some of the first 32 pixels painted white.
|
|
|
|
// They are invisible in software, but look really ugly in GL. So we just copy
|
|
|
|
// 32 pixels from the bottom to make it look nice.
|
|
|
|
memcpy (data, data + 32*31, 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
// detect false alpha cases
|
|
|
|
if (glt->flags & TEXPREF_ALPHA && !(glt->flags & TEXPREF_CONCHARS))
|
|
|
|
{
|
2011-12-29 19:06:08 +00:00
|
|
|
for (i = 0; i < (int) (glt->width * glt->height); i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
if (data[i] == 255) //transparent index
|
|
|
|
break;
|
2011-12-29 19:06:08 +00:00
|
|
|
if (i == (int) (glt->width * glt->height))
|
2010-02-15 23:26:55 +00:00
|
|
|
glt->flags -= TEXPREF_ALPHA;
|
|
|
|
}
|
|
|
|
|
|
|
|
// choose palette and padbyte
|
|
|
|
if (glt->flags & TEXPREF_FULLBRIGHT)
|
|
|
|
{
|
|
|
|
usepal = d_8to24table_fbright;
|
|
|
|
padbyte = 0;
|
|
|
|
}
|
|
|
|
else if (glt->flags & TEXPREF_NOBRIGHT && gl_fullbrights.value)
|
|
|
|
{
|
|
|
|
usepal = d_8to24table_nobright;
|
|
|
|
padbyte = 0;
|
|
|
|
}
|
|
|
|
else if (glt->flags & TEXPREF_CONCHARS)
|
|
|
|
{
|
|
|
|
usepal = d_8to24table_conchars;
|
|
|
|
padbyte = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usepal = d_8to24table;
|
|
|
|
padbyte = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pad each dimention, but only if it's not going to be downsampled later
|
|
|
|
if (glt->flags & TEXPREF_PAD)
|
|
|
|
{
|
2011-12-29 19:06:08 +00:00
|
|
|
if ((int) glt->width < TexMgr_SafeTextureSize(glt->width))
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
data = TexMgr_PadImageW (data, glt->width, glt->height, padbyte);
|
|
|
|
glt->width = TexMgr_Pad(glt->width);
|
|
|
|
padw = true;
|
|
|
|
}
|
2011-12-29 19:06:08 +00:00
|
|
|
if ((int) glt->height < TexMgr_SafeTextureSize(glt->height))
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
data = TexMgr_PadImageH (data, glt->width, glt->height, padbyte);
|
|
|
|
glt->height = TexMgr_Pad(glt->height);
|
|
|
|
padh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert to 32bit
|
|
|
|
data = (byte *)TexMgr_8to32(data, glt->width * glt->height, usepal);
|
|
|
|
|
|
|
|
// fix edges
|
|
|
|
if (glt->flags & TEXPREF_ALPHA)
|
|
|
|
TexMgr_AlphaEdgeFix (data, glt->width, glt->height);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (padw)
|
|
|
|
TexMgr_PadEdgeFixW (data, glt->source_width, glt->source_height);
|
|
|
|
if (padh)
|
|
|
|
TexMgr_PadEdgeFixH (data, glt->source_width, glt->source_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// upload it
|
|
|
|
TexMgr_LoadImage32 (glt, (unsigned *)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_LoadLightmap -- handles lightmap data
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void TexMgr_LoadLightmap (gltexture_t *glt, byte *data)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
// upload it
|
|
|
|
GL_Bind (glt);
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, glt->width, glt->height, 0, gl_lightmap_format, GL_UNSIGNED_BYTE, data);
|
|
|
|
|
|
|
|
// set filter modes
|
|
|
|
TexMgr_SetFilterModes (glt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_LoadImage -- the one entry point for loading all textures
|
|
|
|
================
|
|
|
|
*/
|
2012-05-30 08:56:06 +00:00
|
|
|
gltexture_t *TexMgr_LoadImage (qmodel_t *owner, const char *name, int width, int height, enum srcformat format,
|
2010-08-29 02:22:55 +00:00
|
|
|
byte *data, const char *source_file, src_offset_t source_offset, unsigned flags)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
unsigned short crc;
|
|
|
|
gltexture_t *glt;
|
chase.c, cl_input.c, cl_parse.c, client.h, common.c, common.h, console.h,
cvar.h, draw.h, gl_draw.c, gl_fog.c, gl_mesh.c, gl_model.c, gl_model.h,
gl_rmain.c, gl_rmisc.c, gl_screen.c, gl_sky.c, gl_texmgr.c, glquake.h,
host.c, keys.c, keys.h, main.c, menu.c, menu.h, pr_cmds.c, quakedef.h,
r_alias.c, r_brush.c, r_part.c, r_sprite.c, r_world.c, sbar.c, sbar.h,
screen.h, snd_dma.c, snd_mem.c, snd_mix.c, sv_main.c, sys_sdl.c, vid.h,
view.h, world.c, world.h: Loads of warning fixes about missing function
prototypes, missing parens around &, missing braces leading to ambiguous
else statements and unused and uninitialized variables. There are still a
couple of unitialised variables here and there, but not much. The warnings
about strict aliasing violations need taking care of.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@21 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-16 12:01:07 +00:00
|
|
|
int mark;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
if (isDedicated)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// cache check
|
|
|
|
switch (format)
|
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
case SRC_INDEXED:
|
|
|
|
crc = CRC_Block(data, width * height);
|
|
|
|
break;
|
|
|
|
case SRC_LIGHTMAP:
|
|
|
|
crc = CRC_Block(data, width * height * lightmap_bytes);
|
|
|
|
break;
|
|
|
|
case SRC_RGBA:
|
|
|
|
crc = CRC_Block(data, width * height * 4);
|
|
|
|
break;
|
|
|
|
default: /* not reachable but avoids compiler warnings */
|
|
|
|
crc = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
if ((flags & TEXPREF_OVERWRITE) && (glt = TexMgr_FindTexture (owner, name)))
|
|
|
|
{
|
|
|
|
if (glt->source_crc == crc)
|
|
|
|
return glt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glt = TexMgr_NewTexture ();
|
|
|
|
|
|
|
|
// copy data
|
|
|
|
glt->owner = owner;
|
2011-12-27 13:15:31 +00:00
|
|
|
q_strlcpy (glt->name, name, sizeof(glt->name));
|
2010-02-15 23:26:55 +00:00
|
|
|
glt->width = width;
|
|
|
|
glt->height = height;
|
|
|
|
glt->flags = flags;
|
|
|
|
glt->shirt = -1;
|
|
|
|
glt->pants = -1;
|
2011-12-27 13:15:31 +00:00
|
|
|
q_strlcpy (glt->source_file, source_file, sizeof(glt->source_file));
|
2010-02-15 23:26:55 +00:00
|
|
|
glt->source_offset = source_offset;
|
|
|
|
glt->source_format = format;
|
|
|
|
glt->source_width = width;
|
|
|
|
glt->source_height = height;
|
|
|
|
glt->source_crc = crc;
|
|
|
|
|
|
|
|
//upload it
|
|
|
|
mark = Hunk_LowMark();
|
|
|
|
|
|
|
|
switch (glt->source_format)
|
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
case SRC_INDEXED:
|
|
|
|
TexMgr_LoadImage8 (glt, data);
|
|
|
|
break;
|
|
|
|
case SRC_LIGHTMAP:
|
|
|
|
TexMgr_LoadLightmap (glt, data);
|
|
|
|
break;
|
|
|
|
case SRC_RGBA:
|
|
|
|
TexMgr_LoadImage32 (glt, (unsigned *)data);
|
|
|
|
break;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Hunk_FreeToLowMark(mark);
|
|
|
|
|
|
|
|
return glt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
COLORMAPPING AND TEXTURE RELOADING
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_ReloadImage -- reloads a texture, and colormaps it if needed
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants)
|
|
|
|
{
|
|
|
|
byte translation[256];
|
|
|
|
byte *src, *dst, *data = NULL, *translated;
|
2011-12-30 14:00:28 +00:00
|
|
|
int mark, size, i;
|
2010-02-15 23:26:55 +00:00
|
|
|
//
|
|
|
|
// get source data
|
|
|
|
//
|
|
|
|
mark = Hunk_LowMark ();
|
|
|
|
|
|
|
|
if (glt->source_file[0] && glt->source_offset)
|
|
|
|
{
|
|
|
|
//lump inside file
|
2012-02-11 14:30:19 +00:00
|
|
|
long size;
|
|
|
|
FILE *f;
|
|
|
|
COM_FOpenFile(glt->source_file, &f, NULL);
|
|
|
|
if (!f)
|
2010-02-15 23:26:55 +00:00
|
|
|
goto invalid;
|
2012-02-11 14:30:19 +00:00
|
|
|
fseek (f, glt->source_offset, SEEK_CUR);
|
|
|
|
size = (long) (glt->source_width * glt->source_height);
|
|
|
|
/* should be SRC_INDEXED, but no harm being paranoid: */
|
|
|
|
if (glt->source_format == SRC_RGBA)
|
|
|
|
size *= 4;
|
|
|
|
else if (glt->source_format == SRC_LIGHTMAP)
|
|
|
|
size *= lightmap_bytes;
|
2012-03-08 10:14:58 +00:00
|
|
|
data = (byte *) Hunk_Alloc (size);
|
2012-02-11 14:30:19 +00:00
|
|
|
fread (data, 1, size, f);
|
|
|
|
fclose (f);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
else if (glt->source_file[0] && !glt->source_offset)
|
|
|
|
data = Image_LoadImage (glt->source_file, (int *)&glt->source_width, (int *)&glt->source_height); //simple file
|
|
|
|
else if (!glt->source_file[0] && glt->source_offset)
|
|
|
|
data = (byte *) glt->source_offset; //image in memory
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
invalid:
|
|
|
|
Con_Printf ("TexMgr_ReloadImage: invalid source for %s\n", glt->name);
|
|
|
|
Hunk_FreeToLowMark(mark);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glt->width = glt->source_width;
|
|
|
|
glt->height = glt->source_height;
|
|
|
|
//
|
|
|
|
// apply shirt and pants colors
|
|
|
|
//
|
|
|
|
// if shirt and pants are -1,-1, use existing shirt and pants colors
|
|
|
|
// if existing shirt and pants colors are -1,-1, don't bother colormapping
|
|
|
|
if (shirt > -1 && pants > -1)
|
|
|
|
{
|
|
|
|
if (glt->source_format == SRC_INDEXED)
|
|
|
|
{
|
|
|
|
glt->shirt = shirt;
|
|
|
|
glt->pants = pants;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Con_Printf ("TexMgr_ReloadImage: can't colormap a non SRC_INDEXED texture: %s\n", glt->name);
|
|
|
|
}
|
|
|
|
if (glt->shirt > -1 && glt->pants > -1)
|
|
|
|
{
|
|
|
|
//create new translation table
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
translation[i] = i;
|
|
|
|
|
|
|
|
shirt = glt->shirt * 16;
|
|
|
|
if (shirt < 128)
|
2011-12-30 14:00:28 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
translation[TOP_RANGE+i] = shirt + i;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
else
|
2011-12-30 14:00:28 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < 16; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
translation[TOP_RANGE+i] = shirt+15-i;
|
2011-12-30 14:00:28 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
pants = glt->pants * 16;
|
|
|
|
if (pants < 128)
|
2011-12-30 14:00:28 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
translation[BOTTOM_RANGE+i] = pants + i;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
else
|
2011-12-30 14:00:28 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < 16; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
translation[BOTTOM_RANGE+i] = pants+15-i;
|
2011-12-30 14:00:28 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
//translate texture
|
|
|
|
size = glt->width * glt->height;
|
host_cmd.c, console.c, gl_draw.c, image.c, gl_model.c, r_sprite.c, cl_parse.c,
gl_warp.c, host.c, gl_mesh.c, gl_sky.c, gl_texmgr.c, cvar.c, sv_main.c, cvar.h,
gl_screen.c, r_brush.c, gl_vidsdl.c, zone.c, cl_main.c, cmd.c, snd_dma.c,
snd_mem.c, common.c, sv_phys.c: Added explicit casts to eliminate -Wc++-compat
warnings.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@170 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-05-31 07:42:36 +00:00
|
|
|
dst = translated = (byte *) Hunk_Alloc (size);
|
2010-02-15 23:26:55 +00:00
|
|
|
src = data;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (i = 0; i < size; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
*dst++ = translation[*src++];
|
|
|
|
|
|
|
|
data = translated;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// upload it
|
|
|
|
//
|
|
|
|
switch (glt->source_format)
|
|
|
|
{
|
2011-12-30 14:00:28 +00:00
|
|
|
case SRC_INDEXED:
|
|
|
|
TexMgr_LoadImage8 (glt, data);
|
|
|
|
break;
|
|
|
|
case SRC_LIGHTMAP:
|
|
|
|
TexMgr_LoadLightmap (glt, data);
|
|
|
|
break;
|
|
|
|
case SRC_RGBA:
|
|
|
|
TexMgr_LoadImage32 (glt, (unsigned *)data);
|
|
|
|
break;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Hunk_FreeToLowMark(mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_ReloadImages -- reloads all texture images. called only by vid_restart
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TexMgr_ReloadImages (void)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-29 19:06:08 +00:00
|
|
|
glGenTextures(1, &glt->texnum);
|
2010-02-15 23:26:55 +00:00
|
|
|
TexMgr_ReloadImage (glt, -1, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
TexMgr_ReloadNobrightImages -- reloads all texture that were loaded with the nobright palette. called when gl_fullbrights changes
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TexMgr_ReloadNobrightImages (void)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
for (glt = active_gltextures; glt; glt = glt->next)
|
2010-02-15 23:26:55 +00:00
|
|
|
if (glt->flags & TEXPREF_NOBRIGHT)
|
|
|
|
TexMgr_ReloadImage(glt, -1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
TEXTURE BINDING / TEXTURE UNIT SWITCHING
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
*/
|
|
|
|
|
2011-12-30 14:00:28 +00:00
|
|
|
static GLuint currenttexture = (GLuint)-1; // to avoid unnecessary texture sets
|
|
|
|
GLenum TEXTURE0, TEXTURE1; //johnfitz
|
|
|
|
qboolean mtexenabled = false;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_SelectTexture -- johnfitz -- rewritten
|
|
|
|
================
|
|
|
|
*/
|
2011-12-30 14:00:28 +00:00
|
|
|
static void GL_SelectTexture (GLenum target)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
static GLenum currenttarget;
|
2011-12-29 19:06:08 +00:00
|
|
|
static GLuint ct0, ct1;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
if (target == currenttarget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GL_SelectTextureFunc(target);
|
|
|
|
|
|
|
|
if (target == TEXTURE0)
|
|
|
|
{
|
|
|
|
ct1 = currenttexture;
|
|
|
|
currenttexture = ct0;
|
|
|
|
}
|
|
|
|
else //target == TEXTURE1
|
|
|
|
{
|
|
|
|
ct0 = currenttexture;
|
|
|
|
currenttexture = ct1;
|
|
|
|
}
|
|
|
|
|
|
|
|
currenttarget = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_DisableMultitexture -- selects texture unit 0
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void GL_DisableMultitexture(void)
|
|
|
|
{
|
|
|
|
if (mtexenabled)
|
|
|
|
{
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
GL_SelectTexture(TEXTURE0); //johnfitz -- no longer SGIS specific
|
|
|
|
mtexenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_EnableMultitexture -- selects texture unit 1
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void GL_EnableMultitexture(void)
|
|
|
|
{
|
|
|
|
if (gl_mtexable)
|
|
|
|
{
|
|
|
|
GL_SelectTexture(TEXTURE1); //johnfitz -- no longer SGIS specific
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
mtexenabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_Bind -- johnfitz -- heavy revision
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void GL_Bind (gltexture_t *texture)
|
|
|
|
{
|
|
|
|
if (!texture)
|
|
|
|
texture = nulltexture;
|
|
|
|
|
|
|
|
if (texture->texnum != currenttexture)
|
|
|
|
{
|
|
|
|
currenttexture = texture->texnum;
|
|
|
|
glBindTexture (GL_TEXTURE_2D, currenttexture);
|
|
|
|
texture->visframe = r_framecount;
|
|
|
|
}
|
|
|
|
}
|