icculus quake2 doxygen  1.0 dev
gl_image.c File Reference
#include "gl_local.h"

Go to the source code of this file.

Classes

struct  glmode_t
 
struct  gltmode_t
 
struct  _TargaHeader
 
struct  floodfill_t
 

Macros

#define NUM_GL_MODES   (sizeof(modes) / sizeof (glmode_t))
 
#define NUM_GL_ALPHA_MODES   (sizeof(gl_alpha_modes) / sizeof (gltmode_t))
 
#define NUM_GL_SOLID_MODES   (sizeof(gl_solid_modes) / sizeof (gltmode_t))
 
#define MAX_SCRAPS   1
 
#define BLOCK_WIDTH   256
 
#define BLOCK_HEIGHT   256
 
#define FLOODFILL_FIFO_SIZE   0x1000
 
#define FLOODFILL_FIFO_MASK   (FLOODFILL_FIFO_SIZE - 1)
 
#define FLOODFILL_STEP(off, dx, dy)
 

Typedefs

typedef struct _TargaHeader TargaHeader
 

Functions

qboolean GL_Upload8 (byte *data, int width, int height, qboolean mipmap, qboolean is_sky)
 
qboolean GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap)
 
void GL_SetTexturePalette (unsigned palette[256])
 
void GL_EnableMultitexture (qboolean enable)
 
void GL_SelectTexture (GLenum texture)
 
void GL_TexEnv (GLenum mode)
 
void GL_Bind (int texnum)
 
void GL_MBind (GLenum target, int texnum)
 
void GL_TextureMode (char *string)
 
void GL_TextureAlphaMode (char *string)
 
void GL_TextureSolidMode (char *string)
 
void GL_ImageList_f (void)
 
int Scrap_AllocBlock (int w, int h, int *x, int *y)
 
void Scrap_Upload (void)
 
void LoadPCX (char *filename, byte **pic, byte **palette, int *width, int *height)
 
void LoadTGA (char *name, byte **pic, int *width, int *height)
 
void R_FloodFillSkin (byte *skin, int skinwidth, int skinheight)
 
void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
 
void GL_LightScaleTexture (unsigned *in, int inwidth, int inheight, qboolean only_gamma)
 
void GL_MipMap (byte *in, int width, int height)
 
void GL_BuildPalettedTexture (unsigned char *paletted_texture, unsigned char *scaled, int scaled_width, int scaled_height)
 
image_tGL_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type, int bits)
 
image_tGL_LoadWal (char *name)
 
image_tGL_FindImage (char *name, imagetype_t type)
 
struct image_sR_RegisterSkin (char *name)
 
void GL_FreeUnusedImages (void)
 
int Draw_GetPalette (void)
 
void GL_InitImages (void)
 
void GL_ShutdownImages (void)
 

Variables

image_t gltextures [MAX_GLTEXTURES]
 
int numgltextures
 
int base_textureid
 
static byte intensitytable [256]
 
static unsigned char gammatable [256]
 
cvar_tintensity
 
unsigned d_8to24table [256]
 
int gl_solid_format = 3
 
int gl_alpha_format = 4
 
int gl_tex_solid_format = 3
 
int gl_tex_alpha_format = 4
 
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST
 
int gl_filter_max = GL_LINEAR
 
glmode_t modes []
 
gltmode_t gl_alpha_modes []
 
gltmode_t gl_solid_modes []
 
int scrap_allocated [MAX_SCRAPS][BLOCK_WIDTH]
 
byte scrap_texels [MAX_SCRAPS][BLOCK_WIDTH *BLOCK_HEIGHT]
 
qboolean scrap_dirty
 
int scrap_uploads
 
int upload_width
 
int upload_height
 
qboolean uploaded_paletted
 

Macro Definition Documentation

◆ BLOCK_HEIGHT

#define BLOCK_HEIGHT   256

Definition at line 360 of file gl_image.c.

◆ BLOCK_WIDTH

#define BLOCK_WIDTH   256

Definition at line 359 of file gl_image.c.

◆ FLOODFILL_FIFO_MASK

#define FLOODFILL_FIFO_MASK   (FLOODFILL_FIFO_SIZE - 1)

Definition at line 765 of file gl_image.c.

◆ FLOODFILL_FIFO_SIZE

#define FLOODFILL_FIFO_SIZE   0x1000

Definition at line 764 of file gl_image.c.

◆ FLOODFILL_STEP

#define FLOODFILL_STEP (   off,
  dx,
  dy 
)
Value:
{ \
if (pos[off] == fillcolor) \
{ \
pos[off] = 255; \
fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
} \
else if (pos[off] != 255) fdc = pos[off]; \
}

Definition at line 767 of file gl_image.c.

◆ MAX_SCRAPS

#define MAX_SCRAPS   1

Definition at line 358 of file gl_image.c.

◆ NUM_GL_ALPHA_MODES

#define NUM_GL_ALPHA_MODES   (sizeof(gl_alpha_modes) / sizeof (gltmode_t))

Definition at line 196 of file gl_image.c.

◆ NUM_GL_MODES

#define NUM_GL_MODES   (sizeof(modes) / sizeof (glmode_t))

Definition at line 179 of file gl_image.c.

◆ NUM_GL_SOLID_MODES

#define NUM_GL_SOLID_MODES   (sizeof(gl_solid_modes) / sizeof (gltmode_t))

Definition at line 210 of file gl_image.c.

Typedef Documentation

◆ TargaHeader

typedef struct _TargaHeader TargaHeader

Function Documentation

◆ Draw_GetPalette()

int Draw_GetPalette ( void  )

Definition at line 1509 of file gl_image.c.

1510 {
1511  int i;
1512  int r, g, b;
1513  unsigned v;
1514  byte *pic, *pal;
1515  int width, height;
1516 
1517  // get the palette
1518 
1519  LoadPCX ("pics/colormap.pcx", &pic, &pal, &width, &height);
1520  if (!pal)
1521  ri.Sys_Error (ERR_FATAL, "Couldn't load pics/colormap.pcx");
1522 
1523  for (i=0 ; i<256 ; i++)
1524  {
1525  r = pal[i*3+0];
1526  g = pal[i*3+1];
1527  b = pal[i*3+2];
1528 
1529  v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
1530  d_8to24table[i] = LittleLong(v);
1531  }
1532 
1533  d_8to24table[255] &= LittleLong(0xffffff); // 255 is transparent
1534 
1535  free (pic);
1536  free (pal);
1537 
1538  return 0;
1539 }

Referenced by GL_InitImages(), and R_Init().

◆ GL_Bind()

void GL_Bind ( int  texnum)

◆ GL_BuildPalettedTexture()

void GL_BuildPalettedTexture ( unsigned char *  paletted_texture,
unsigned char *  scaled,
int  scaled_width,
int  scaled_height 
)

Definition at line 953 of file gl_image.c.

954 {
955  int i;
956 
957  for ( i = 0; i < scaled_width * scaled_height; i++ )
958  {
959  unsigned int r, g, b, c;
960 
961  r = ( scaled[0] >> 3 ) & 31;
962  g = ( scaled[1] >> 2 ) & 63;
963  b = ( scaled[2] >> 3 ) & 31;
964 
965  c = r | ( g << 5 ) | ( b << 11 );
966 
967  paletted_texture[i] = gl_state.d_16to8table[c];
968 
969  scaled += 4;
970  }
971 }

Referenced by GL_Upload32().

◆ GL_EnableMultitexture()

void GL_EnableMultitexture ( qboolean  enable)

Definition at line 70 of file gl_image.c.

71 {
72  if ( !qglSelectTextureSGIS && !qglActiveTextureARB )
73  return;
74 
75  if ( enable )
76  {
78  qglEnable( GL_TEXTURE_2D );
79  GL_TexEnv( GL_REPLACE );
80  }
81  else
82  {
84  qglDisable( GL_TEXTURE_2D );
85  GL_TexEnv( GL_REPLACE );
86  }
88  GL_TexEnv( GL_REPLACE );
89 }

Referenced by DrawTextureChains(), GL_BeginBuildingLightmaps(), GL_EndBuildingLightmaps(), R_DrawBrushModel(), R_DrawInlineBModel(), and R_DrawWorld().

◆ GL_FindImage()

image_t* GL_FindImage ( char *  name,
imagetype_t  type 
)

Definition at line 1393 of file gl_image.c.

1394 {
1395  image_t *image;
1396  int i, len;
1397  byte *pic, *palette;
1398  int width, height;
1399  char *ptr;
1400 
1401  if (!name)
1402  return NULL; // ri.Sys_Error (ERR_DROP, "GL_FindImage: NULL name");
1403  len = strlen(name);
1404  if (len<5)
1405  return NULL; // ri.Sys_Error (ERR_DROP, "GL_FindImage: bad name: %s", name);
1406 
1407 #ifndef _WIN32
1408  // fix backslashes
1409  while ((ptr=strchr(name,'\\'))) {
1410  *ptr = '/';
1411  }
1412 #endif
1413 
1414  // look for it
1415  for (i=0, image=gltextures ; i<numgltextures ; i++,image++)
1416  {
1417  if (!strcmp(name, image->name))
1418  {
1420  return image;
1421  }
1422  }
1423 
1424  //
1425  // load the pic from disk
1426  //
1427  pic = NULL;
1428  palette = NULL;
1429  if (!strcmp(name+len-4, ".pcx"))
1430  {
1431  LoadPCX (name, &pic, &palette, &width, &height);
1432  if (!pic)
1433  return NULL; // ri.Sys_Error (ERR_DROP, "GL_FindImage: can't load %s", name);
1434  image = GL_LoadPic (name, pic, width, height, type, 8);
1435  }
1436  else if (!strcmp(name+len-4, ".wal"))
1437  {
1438  image = GL_LoadWal (name);
1439  }
1440  else if (!strcmp(name+len-4, ".tga"))
1441  {
1442  LoadTGA (name, &pic, &width, &height);
1443  if (!pic)
1444  return NULL; // ri.Sys_Error (ERR_DROP, "GL_FindImage: can't load %s", name);
1445  image = GL_LoadPic (name, pic, width, height, type, 32);
1446  }
1447  else
1448  return NULL; // ri.Sys_Error (ERR_DROP, "GL_FindImage: bad extension on: %s", name);
1449 
1450 
1451  if (pic)
1452  free(pic);
1453  if (palette)
1454  free(palette);
1455 
1456  return image;
1457 }

Referenced by Draw_FindPic(), Draw_InitLocal(), Mod_LoadAliasModel(), Mod_LoadSpriteModel(), Mod_LoadTexinfo(), R_RegisterModel(), R_RegisterSkin(), and R_SetSky().

◆ GL_FreeUnusedImages()

void GL_FreeUnusedImages ( void  )

Definition at line 1480 of file gl_image.c.

1481 {
1482  int i;
1483  image_t *image;
1484 
1485  // never free r_notexture or particle texture
1488 
1489  for (i=0, image=gltextures ; i<numgltextures ; i++, image++)
1490  {
1492  continue; // used this sequence
1493  if (!image->registration_sequence)
1494  continue; // free image_t slot
1495  if (image->type == it_pic)
1496  continue; // don't free pics
1497  // free it
1498  qglDeleteTextures (1, (GLuint *)&image->texnum);
1499  memset (image, 0, sizeof(*image));
1500  }
1501 }

Referenced by R_EndRegistration().

◆ GL_ImageList_f()

void GL_ImageList_f ( void  )

Definition at line 302 of file gl_image.c.

303 {
304  int i;
305  image_t *image;
306  int texels;
307  const char *palstrings[2] =
308  {
309  "RGB",
310  "PAL"
311  };
312 
313  ri.Con_Printf (PRINT_ALL, "------------------\n");
314  texels = 0;
315 
316  for (i=0, image=gltextures ; i<numgltextures ; i++, image++)
317  {
318  if (image->texnum <= 0)
319  continue;
320  texels += image->upload_width*image->upload_height;
321  switch (image->type)
322  {
323  case it_skin:
324  ri.Con_Printf (PRINT_ALL, "M");
325  break;
326  case it_sprite:
327  ri.Con_Printf (PRINT_ALL, "S");
328  break;
329  case it_wall:
330  ri.Con_Printf (PRINT_ALL, "W");
331  break;
332  case it_pic:
333  ri.Con_Printf (PRINT_ALL, "P");
334  break;
335  default:
336  ri.Con_Printf (PRINT_ALL, " ");
337  break;
338  }
339 
340  ri.Con_Printf (PRINT_ALL, " %3i %3i %s: %s\n",
341  image->upload_width, image->upload_height, palstrings[image->paletted], image->name);
342  }
343  ri.Con_Printf (PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels);
344 }

Referenced by R_Register().

◆ GL_InitImages()

void GL_InitImages ( void  )

Definition at line 1547 of file gl_image.c.

1548 {
1549  int i, j;
1550  float g = vid_gamma->value;
1551 
1553 
1554  // init intensity conversions
1555  intensity = ri.Cvar_Get ("intensity", "2", 0);
1556 
1557  if ( intensity->value <= 1 )
1558  ri.Cvar_Set( "intensity", "1" );
1559 
1561 
1562  Draw_GetPalette ();
1563 
1564  if ( qglColorTableEXT )
1565  {
1566  ri.FS_LoadFile( "pics/16to8.dat", (void **)&gl_state.d_16to8table );
1567  if ( !gl_state.d_16to8table )
1568  ri.Sys_Error( ERR_FATAL, "Couldn't load pics/16to8.pcx");
1569  }
1570 
1572  {
1573  g = 1.0F;
1574  }
1575 
1576  for ( i = 0; i < 256; i++ )
1577  {
1578  if ( g == 1 || gl_state.hwgamma )
1579  {
1580  gammatable[i] = i;
1581  }
1582  else
1583  {
1584  float inf;
1585 
1586  inf = 255 * pow ( (i+0.5)/255.5 , g ) + 0.5;
1587  if (inf < 0)
1588  inf = 0;
1589  if (inf > 255)
1590  inf = 255;
1591  gammatable[i] = inf;
1592  }
1593  }
1594 
1595  for (i=0 ; i<256 ; i++)
1596  {
1597  j = i*intensity->value;
1598  if (j > 255)
1599  j = 255;
1600  intensitytable[i] = j;
1601  }
1602 }

Referenced by R_Init().

◆ GL_LightScaleTexture()

void GL_LightScaleTexture ( unsigned *  in,
int  inwidth,
int  inheight,
qboolean  only_gamma 
)

Definition at line 885 of file gl_image.c.

886 {
887  if ( only_gamma )
888  {
889  int i, c;
890  byte *p;
891 
892  p = (byte *)in;
893 
894  c = inwidth*inheight;
895  for (i=0 ; i<c ; i++, p+=4)
896  {
897  p[0] = gammatable[p[0]];
898  p[1] = gammatable[p[1]];
899  p[2] = gammatable[p[2]];
900  }
901  }
902  else
903  {
904  int i, c;
905  byte *p;
906 
907  p = (byte *)in;
908 
909  c = inwidth*inheight;
910  for (i=0 ; i<c ; i++, p+=4)
911  {
912  p[0] = gammatable[intensitytable[p[0]]];
913  p[1] = gammatable[intensitytable[p[1]]];
914  p[2] = gammatable[intensitytable[p[2]]];
915  }
916  }
917 }

Referenced by GL_Upload32().

◆ GL_LoadPic()

image_t* GL_LoadPic ( char *  name,
byte pic,
int  width,
int  height,
imagetype_t  type,
int  bits 
)

Definition at line 1255 of file gl_image.c.

1256 {
1257  image_t *image;
1258  int i;
1259 #ifdef RETEX
1260  miptex_t *mt;
1261  int len;
1262  char s[128];
1263 #endif
1264 
1265  // find a free image_t
1266  for (i=0, image=gltextures ; i<numgltextures ; i++,image++)
1267  {
1268  if (!image->texnum)
1269  break;
1270  }
1271  if (i == numgltextures)
1272  {
1274  ri.Sys_Error (ERR_DROP, "MAX_GLTEXTURES");
1275  numgltextures++;
1276  }
1277  image = &gltextures[i];
1278 
1279  if (strlen(name) >= sizeof(image->name))
1280  ri.Sys_Error (ERR_DROP, "Draw_LoadPic: \"%s\" is too long", name);
1281  strcpy (image->name, name);
1283 
1284  image->width = width;
1285  image->height = height;
1286  image->type = type;
1287 
1288 #ifdef RETEX
1289  len = strlen(name);
1290  strcpy(s,name);
1291 
1292  if (!strcmp(s+len-4, ".tga") || !strcmp(s+len-4, ".jpg") || !strcmp(s+len-4, ".png"))
1293  {
1294  s[len-3] = 'w'; s[len-2] = 'a'; s[len-1] = 'l';
1295  ri.FS_LoadFile (s, (void **)&mt); //load .wal file
1296 
1297  if (mt) {
1298  image->width = LittleLong (mt->width);
1299  image->height = LittleLong (mt->height);
1300  ri.FS_FreeFile ((void *)mt);
1301  }
1302  }
1303 #endif
1304 
1305  if (type == it_skin && bits == 8)
1306  R_FloodFillSkin(pic, width, height);
1307 
1308  // load little pics into the scrap
1309  if (image->type == it_pic && bits == 8
1310  && image->width < 64 && image->height < 64)
1311  {
1312  int x, y;
1313  int i, j, k;
1314  int texnum;
1315 
1316  texnum = Scrap_AllocBlock (image->width, image->height, &x, &y);
1317  if (texnum == -1)
1318  goto nonscrap;
1319  scrap_dirty = true;
1320 
1321  // copy the texels into the scrap block
1322  k = 0;
1323  for (i=0 ; i<image->height ; i++)
1324  for (j=0 ; j<image->width ; j++, k++)
1325  scrap_texels[texnum][(y+i)*BLOCK_WIDTH + x + j] = pic[k];
1326  image->texnum = TEXNUM_SCRAPS + texnum;
1327  image->scrap = true;
1328  image->has_alpha = true;
1329  image->sl = (x+0.01)/(float)BLOCK_WIDTH;
1330  image->sh = (x+image->width-0.01)/(float)BLOCK_WIDTH;
1331  image->tl = (y+0.01)/(float)BLOCK_WIDTH;
1332  image->th = (y+image->height-0.01)/(float)BLOCK_WIDTH;
1333  }
1334  else
1335  {
1336 nonscrap:
1337  image->scrap = false;
1338  image->texnum = TEXNUM_IMAGES + (image - gltextures);
1339  GL_Bind(image->texnum);
1340  if (bits == 8)
1341  image->has_alpha = GL_Upload8 (pic, width, height, (image->type != it_pic && image->type != it_sky), image->type == it_sky );
1342  else
1343  image->has_alpha = GL_Upload32 ((unsigned *)pic, width, height, (image->type != it_pic && image->type != it_sky) );
1344  image->upload_width = upload_width; // after power of 2 and scales
1345  image->upload_height = upload_height;
1346  image->paletted = uploaded_paletted;
1347  image->sl = 0;
1348  image->sh = 1;
1349  image->tl = 0;
1350  image->th = 1;
1351  }
1352 
1353  return image;
1354 }

Referenced by GL_FindImage(), and GL_LoadWal().

◆ GL_LoadWal()

image_t* GL_LoadWal ( char *  name)

Definition at line 1362 of file gl_image.c.

1363 {
1364  miptex_t *mt;
1365  int width, height, ofs;
1366  image_t *image;
1367 
1368  ri.FS_LoadFile (name, (void **)&mt);
1369  if (!mt)
1370  {
1371  ri.Con_Printf (PRINT_ALL, "GL_FindImage: can't load %s\n", name);
1372  return r_notexture;
1373  }
1374 
1375  width = LittleLong (mt->width);
1376  height = LittleLong (mt->height);
1377  ofs = LittleLong (mt->offsets[0]);
1378 
1379  image = GL_LoadPic (name, (byte *)mt + ofs, width, height, it_wall, 8);
1380 
1381  ri.FS_FreeFile ((void *)mt);
1382 
1383  return image;
1384 }

Referenced by GL_FindImage().

◆ GL_MBind()

void GL_MBind ( GLenum  target,
int  texnum 
)

Definition at line 148 of file gl_image.c.

149 {
150  GL_SelectTexture( target );
151  if ( target == QGL_TEXTURE0 )
152  {
153  if ( gl_state.currenttextures[0] == texnum )
154  return;
155  }
156  else
157  {
158  if ( gl_state.currenttextures[1] == texnum )
159  return;
160  }
161  GL_Bind( texnum );
162 }

Referenced by GL_RenderLightmappedPoly().

◆ GL_MipMap()

void GL_MipMap ( byte in,
int  width,
int  height 
)

Definition at line 926 of file gl_image.c.

927 {
928  int i, j;
929  byte *out;
930 
931  width <<=2;
932  height >>= 1;
933  out = in;
934  for (i=0 ; i<height ; i++, in+=width)
935  {
936  for (j=0 ; j<width ; j+=8, out+=4, in+=8)
937  {
938  out[0] = (in[0] + in[4] + in[width+0] + in[width+4])>>2;
939  out[1] = (in[1] + in[5] + in[width+1] + in[width+5])>>2;
940  out[2] = (in[2] + in[6] + in[width+2] + in[width+6])>>2;
941  out[3] = (in[3] + in[7] + in[width+3] + in[width+7])>>2;
942  }
943  }
944 }

Referenced by GL_Upload32().

◆ GL_ResampleTexture()

void GL_ResampleTexture ( unsigned *  in,
int  inwidth,
int  inheight,
unsigned *  out,
int  outwidth,
int  outheight 
)

Definition at line 835 of file gl_image.c.

836 {
837  int i, j;
838  unsigned *inrow, *inrow2;
839  unsigned frac, fracstep;
840  unsigned p1[1024], p2[1024];
841  byte *pix1, *pix2, *pix3, *pix4;
842 
843  fracstep = inwidth*0x10000/outwidth;
844 
845  frac = fracstep>>2;
846  for (i=0 ; i<outwidth ; i++)
847  {
848  p1[i] = 4*(frac>>16);
849  frac += fracstep;
850  }
851  frac = 3*(fracstep>>2);
852  for (i=0 ; i<outwidth ; i++)
853  {
854  p2[i] = 4*(frac>>16);
855  frac += fracstep;
856  }
857 
858  for (i=0 ; i<outheight ; i++, out += outwidth)
859  {
860  inrow = in + inwidth*(int)((i+0.25)*inheight/outheight);
861  inrow2 = in + inwidth*(int)((i+0.75)*inheight/outheight);
862  frac = fracstep >> 1;
863  for (j=0 ; j<outwidth ; j++)
864  {
865  pix1 = (byte *)inrow + p1[j];
866  pix2 = (byte *)inrow + p2[j];
867  pix3 = (byte *)inrow2 + p1[j];
868  pix4 = (byte *)inrow2 + p2[j];
869  ((byte *)(out+j))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2;
870  ((byte *)(out+j))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2;
871  ((byte *)(out+j))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2;
872  ((byte *)(out+j))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3])>>2;
873  }
874  }
875 }

Referenced by GL_Upload32().

◆ GL_SelectTexture()

void GL_SelectTexture ( GLenum  texture)

Definition at line 91 of file gl_image.c.

92 {
93  int tmu;
94 
95  if ( !qglSelectTextureSGIS && !qglActiveTextureARB )
96  return;
97 
98  if ( texture == QGL_TEXTURE0 )
99  {
100  tmu = 0;
101  }
102  else
103  {
104  tmu = 1;
105  }
106 
107  if ( tmu == gl_state.currenttmu )
108  {
109  return;
110  }
111 
112  gl_state.currenttmu = tmu;
113 
114  if ( qglSelectTextureSGIS )
115  {
116  qglSelectTextureSGIS( texture );
117  }
118  else if ( qglActiveTextureARB )
119  {
120  qglActiveTextureARB( texture );
121  qglClientActiveTextureARB( texture );
122  }
123 }

Referenced by GL_BeginBuildingLightmaps(), GL_EnableMultitexture(), GL_MBind(), R_DrawBrushModel(), and R_DrawWorld().

◆ GL_SetTexturePalette()

void GL_SetTexturePalette ( unsigned  palette[256])

Definition at line 47 of file gl_image.c.

48 {
49  int i;
50  unsigned char temptable[768];
51 
52  if ( qglColorTableEXT && gl_ext_palettedtexture->value )
53  {
54  for ( i = 0; i < 256; i++ )
55  {
56  temptable[i*3+0] = ( palette[i] >> 0 ) & 0xff;
57  temptable[i*3+1] = ( palette[i] >> 8 ) & 0xff;
58  temptable[i*3+2] = ( palette[i] >> 16 ) & 0xff;
59  }
60 
61  qglColorTableEXT( GL_SHARED_TEXTURE_PALETTE_EXT,
62  GL_RGB,
63  256,
64  GL_RGB,
65  GL_UNSIGNED_BYTE,
66  temptable );
67  }
68 }

Referenced by GL_SetDefaultState(), and R_SetPalette().

◆ GL_ShutdownImages()

void GL_ShutdownImages ( void  )

Definition at line 1609 of file gl_image.c.

1610 {
1611  int i;
1612  image_t *image;
1613 
1614  for (i=0, image=gltextures ; i<numgltextures ; i++, image++)
1615  {
1616  if (!image->registration_sequence)
1617  continue; // free image_t slot
1618  // free it
1619  qglDeleteTextures (1, (GLuint *)&image->texnum);
1620  memset (image, 0, sizeof(*image));
1621  }
1622 }

Referenced by R_Shutdown().

◆ GL_TexEnv()

void GL_TexEnv ( GLenum  mode)

Definition at line 125 of file gl_image.c.

126 {
127  static int lastmodes[2] = { -1, -1 };
128 
129  if ( mode != lastmodes[gl_state.currenttmu] )
130  {
131  qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode );
132  lastmodes[gl_state.currenttmu] = mode;
133  }
134 }

Referenced by DrawTextureChains(), GL_DrawParticles(), GL_EnableMultitexture(), GL_SetDefaultState(), R_DrawAliasModel(), R_DrawAlphaSurfaces(), R_DrawBrushModel(), R_DrawInlineBModel(), R_DrawSkyBox(), R_DrawSpriteModel(), R_DrawWorld(), and R_RenderBrushPoly().

◆ GL_TextureAlphaMode()

void GL_TextureAlphaMode ( char *  string)

Definition at line 254 of file gl_image.c.

255 {
256  int i;
257 
258  for (i=0 ; i< NUM_GL_ALPHA_MODES ; i++)
259  {
260  if ( !Q_stricmp( gl_alpha_modes[i].name, string ) )
261  break;
262  }
263 
264  if (i == NUM_GL_ALPHA_MODES)
265  {
266  ri.Con_Printf (PRINT_ALL, "bad alpha texture mode name\n");
267  return;
268  }
269 
271 }

Referenced by GL_SetDefaultState(), and R_BeginFrame().

◆ GL_TextureMode()

void GL_TextureMode ( char *  string)

Definition at line 217 of file gl_image.c.

218 {
219  int i;
220  image_t *glt;
221 
222  for (i=0 ; i< NUM_GL_MODES ; i++)
223  {
224  if ( !Q_stricmp( modes[i].name, string ) )
225  break;
226  }
227 
228  if (i == NUM_GL_MODES)
229  {
230  ri.Con_Printf (PRINT_ALL, "bad filter name\n");
231  return;
232  }
233 
236 
237  // change all the existing mipmap texture objects
238  for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++)
239  {
240  if (glt->type != it_pic && glt->type != it_sky )
241  {
242  GL_Bind (glt->texnum);
243  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
244  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
245  }
246  }
247 }

Referenced by GL_SetDefaultState(), and R_BeginFrame().

◆ GL_TextureSolidMode()

void GL_TextureSolidMode ( char *  string)

Definition at line 278 of file gl_image.c.

279 {
280  int i;
281 
282  for (i=0 ; i< NUM_GL_SOLID_MODES ; i++)
283  {
284  if ( !Q_stricmp( gl_solid_modes[i].name, string ) )
285  break;
286  }
287 
288  if (i == NUM_GL_SOLID_MODES)
289  {
290  ri.Con_Printf (PRINT_ALL, "bad solid texture mode name\n");
291  return;
292  }
293 
295 }

Referenced by GL_SetDefaultState(), and R_BeginFrame().

◆ GL_Upload32()

qboolean GL_Upload32 ( unsigned *  data,
int  width,
int  height,
qboolean  mipmap 
)

Definition at line 976 of file gl_image.c.

977 {
978  int samples;
979  unsigned scaled[256*256];
980  unsigned char paletted_texture[256*256];
981  int scaled_width, scaled_height;
982  int i, c;
983  byte *scan;
984  int comp;
985 
986  uploaded_paletted = false;
987 
988  for (scaled_width = 1 ; scaled_width < width ; scaled_width<<=1)
989  ;
990  if (gl_round_down->value && scaled_width > width && mipmap)
991  scaled_width >>= 1;
992  for (scaled_height = 1 ; scaled_height < height ; scaled_height<<=1)
993  ;
994  if (gl_round_down->value && scaled_height > height && mipmap)
995  scaled_height >>= 1;
996 
997  // let people sample down the world textures for speed
998  if (mipmap)
999  {
1000  scaled_width >>= (int)gl_picmip->value;
1001  scaled_height >>= (int)gl_picmip->value;
1002  }
1003 
1004  // don't ever bother with >256 textures
1005  if (scaled_width > 256)
1006  scaled_width = 256;
1007  if (scaled_height > 256)
1008  scaled_height = 256;
1009 
1010  if (scaled_width < 1)
1011  scaled_width = 1;
1012  if (scaled_height < 1)
1013  scaled_height = 1;
1014 
1015  upload_width = scaled_width;
1016  upload_height = scaled_height;
1017 
1018  if (scaled_width * scaled_height > sizeof(scaled)/4)
1019  ri.Sys_Error (ERR_DROP, "GL_Upload32: too big");
1020 
1021  // scan the texture for any non-255 alpha
1022  c = width*height;
1023  scan = ((byte *)data) + 3;
1024  samples = gl_solid_format;
1025  for (i=0 ; i<c ; i++, scan += 4)
1026  {
1027  if ( *scan != 255 )
1028  {
1029  samples = gl_alpha_format;
1030  break;
1031  }
1032  }
1033 
1034  if (samples == gl_solid_format)
1035  comp = gl_tex_solid_format;
1036  else if (samples == gl_alpha_format)
1037  comp = gl_tex_alpha_format;
1038  else {
1040  "Unknown number of texture components %i\n",
1041  samples);
1042  comp = samples;
1043  }
1044 
1045 #if 0
1046  if (mipmap)
1047  gluBuild2DMipmaps (GL_TEXTURE_2D, samples, width, height, GL_RGBA, GL_UNSIGNED_BYTE, trans);
1048  else if (scaled_width == width && scaled_height == height)
1049  qglTexImage2D (GL_TEXTURE_2D, 0, comp, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
1050  else
1051  {
1052  gluScaleImage (GL_RGBA, width, height, GL_UNSIGNED_BYTE, trans,
1053  scaled_width, scaled_height, GL_UNSIGNED_BYTE, scaled);
1054  qglTexImage2D (GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
1055  }
1056 #else
1057 
1058  if (scaled_width == width && scaled_height == height)
1059  {
1060  if (!mipmap)
1061  {
1062  if ( qglColorTableEXT && gl_ext_palettedtexture->value && samples == gl_solid_format )
1063  {
1064  uploaded_paletted = true;
1065  GL_BuildPalettedTexture( paletted_texture, ( unsigned char * ) data, scaled_width, scaled_height );
1066  qglTexImage2D( GL_TEXTURE_2D,
1067  0,
1068  GL_COLOR_INDEX8_EXT,
1069  scaled_width,
1070  scaled_height,
1071  0,
1072  GL_COLOR_INDEX,
1073  GL_UNSIGNED_BYTE,
1074  paletted_texture );
1075  }
1076  else
1077  {
1078  qglTexImage2D (GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
1079  }
1080  goto done;
1081  }
1082  memcpy (scaled, data, width*height*4);
1083  }
1084  else
1085  GL_ResampleTexture (data, width, height, scaled, scaled_width, scaled_height);
1086 
1087  GL_LightScaleTexture (scaled, scaled_width, scaled_height, !mipmap );
1088 
1089  if ( qglColorTableEXT && gl_ext_palettedtexture->value && ( samples == gl_solid_format ) )
1090  {
1091  uploaded_paletted = true;
1092  GL_BuildPalettedTexture( paletted_texture, ( unsigned char * ) scaled, scaled_width, scaled_height );
1093  qglTexImage2D( GL_TEXTURE_2D,
1094  0,
1095  GL_COLOR_INDEX8_EXT,
1096  scaled_width,
1097  scaled_height,
1098  0,
1099  GL_COLOR_INDEX,
1100  GL_UNSIGNED_BYTE,
1101  paletted_texture );
1102  }
1103  else
1104  {
1105  qglTexImage2D( GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled );
1106  }
1107 
1108  if (mipmap)
1109  {
1110  int miplevel;
1111 
1112  miplevel = 0;
1113  while (scaled_width > 1 || scaled_height > 1)
1114  {
1115  GL_MipMap ((byte *)scaled, scaled_width, scaled_height);
1116  scaled_width >>= 1;
1117  scaled_height >>= 1;
1118  if (scaled_width < 1)
1119  scaled_width = 1;
1120  if (scaled_height < 1)
1121  scaled_height = 1;
1122  miplevel++;
1123  if ( qglColorTableEXT && gl_ext_palettedtexture->value && samples == gl_solid_format )
1124  {
1125  uploaded_paletted = true;
1126  GL_BuildPalettedTexture( paletted_texture, ( unsigned char * ) scaled, scaled_width, scaled_height );
1127  qglTexImage2D( GL_TEXTURE_2D,
1128  miplevel,
1129  GL_COLOR_INDEX8_EXT,
1130  scaled_width,
1131  scaled_height,
1132  0,
1133  GL_COLOR_INDEX,
1134  GL_UNSIGNED_BYTE,
1135  paletted_texture );
1136  }
1137  else
1138  {
1139  qglTexImage2D (GL_TEXTURE_2D, miplevel, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
1140  }
1141  }
1142  }
1143 done: ;
1144 #endif
1145 
1146 
1147  if (mipmap)
1148  {
1149  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
1150  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
1151  }
1152  else
1153  {
1154  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
1155  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
1156  }
1157 
1158  return (samples == gl_alpha_format);
1159 }

Referenced by GL_LoadPic(), and GL_Upload8().

◆ GL_Upload8()

qboolean GL_Upload8 ( byte data,
int  width,
int  height,
qboolean  mipmap,
qboolean  is_sky 
)

Definition at line 1185 of file gl_image.c.

1186 {
1187  unsigned trans[512*256];
1188  int i, s;
1189  int p;
1190 
1191  s = width*height;
1192 
1193  if (s > sizeof(trans)/4)
1194  ri.Sys_Error (ERR_DROP, "GL_Upload8: too large");
1195 
1196  if ( qglColorTableEXT &&
1198  is_sky )
1199  {
1200  qglTexImage2D( GL_TEXTURE_2D,
1201  0,
1202  GL_COLOR_INDEX8_EXT,
1203  width,
1204  height,
1205  0,
1206  GL_COLOR_INDEX,
1207  GL_UNSIGNED_BYTE,
1208  data );
1209 
1210  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
1211  qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
1212 
1213  return false; // SBF: FIXME - what is the correct return value?
1214  }
1215  else
1216  {
1217  for (i=0 ; i<s ; i++)
1218  {
1219  p = data[i];
1220  trans[i] = d_8to24table[p];
1221 
1222  if (p == 255)
1223  { // transparent, so scan around for another color
1224  // to avoid alpha fringes
1225  // FIXME: do a full flood fill so mips work...
1226  if (i > width && data[i-width] != 255)
1227  p = data[i-width];
1228  else if (i < s-width && data[i+width] != 255)
1229  p = data[i+width];
1230  else if (i > 0 && data[i-1] != 255)
1231  p = data[i-1];
1232  else if (i < s-1 && data[i+1] != 255)
1233  p = data[i+1];
1234  else
1235  p = 0;
1236  // copy rgb components
1237  ((byte *)&trans[i])[0] = ((byte *)&d_8to24table[p])[0];
1238  ((byte *)&trans[i])[1] = ((byte *)&d_8to24table[p])[1];
1239  ((byte *)&trans[i])[2] = ((byte *)&d_8to24table[p])[2];
1240  }
1241  }
1242 
1243  return GL_Upload32 (trans, width, height, mipmap);
1244  }
1245 }

Referenced by GL_LoadPic(), and Scrap_Upload().

◆ LoadPCX()

void LoadPCX ( char *  filename,
byte **  pic,
byte **  palette,
int width,
int height 
)

Definition at line 432 of file gl_image.c.

433 {
434  byte *raw;
435  pcx_t *pcx;
436  int x, y;
437  int len;
438  int dataByte, runLength;
439  byte *out, *pix;
440 
441  *pic = NULL;
442  *palette = NULL;
443 
444  //
445  // load the file
446  //
447  len = ri.FS_LoadFile (filename, (void **)&raw);
448  if (!raw)
449  {
450  ri.Con_Printf (PRINT_DEVELOPER, "Bad pcx file %s\n", filename);
451  return;
452  }
453 
454  //
455  // parse the PCX file
456  //
457  pcx = (pcx_t *)raw;
458 
459  pcx->xmin = LittleShort(pcx->xmin);
460  pcx->ymin = LittleShort(pcx->ymin);
461  pcx->xmax = LittleShort(pcx->xmax);
462  pcx->ymax = LittleShort(pcx->ymax);
463  pcx->hres = LittleShort(pcx->hres);
464  pcx->vres = LittleShort(pcx->vres);
467 
468  raw = &pcx->data;
469 
470  if (pcx->manufacturer != 0x0a
471  || pcx->version != 5
472  || pcx->encoding != 1
473  || pcx->bits_per_pixel != 8
474  || pcx->xmax >= 640
475  || pcx->ymax >= 480)
476  {
477  ri.Con_Printf (PRINT_ALL, "Bad pcx file %s\n", filename);
478  return;
479  }
480 
481  out = malloc ( (pcx->ymax+1) * (pcx->xmax+1) );
482 
483  *pic = out;
484 
485  pix = out;
486 
487  if (palette)
488  {
489  *palette = malloc(768);
490  memcpy (*palette, (byte *)pcx + len - 768, 768);
491  }
492 
493  if (width)
494  *width = pcx->xmax+1;
495  if (height)
496  *height = pcx->ymax+1;
497 
498  for (y=0 ; y<=pcx->ymax ; y++, pix += pcx->xmax+1)
499  {
500  for (x=0 ; x<=pcx->xmax ; )
501  {
502  dataByte = *raw++;
503 
504  if((dataByte & 0xC0) == 0xC0)
505  {
506  runLength = dataByte & 0x3F;
507  dataByte = *raw++;
508  }
509  else
510  runLength = 1;
511 
512  while(runLength-- > 0)
513  pix[x++] = dataByte;
514  }
515 
516  }
517 
518  if ( raw - (byte *)pcx > len)
519  {
520  ri.Con_Printf (PRINT_DEVELOPER, "PCX file %s was malformed", filename);
521  free (*pic);
522  *pic = NULL;
523  }
524 
525  ri.FS_FreeFile (pcx);
526 }

Referenced by Draw_GetPalette(), and GL_FindImage().

◆ LoadTGA()

void LoadTGA ( char *  name,
byte **  pic,
int width,
int height 
)

Definition at line 550 of file gl_image.c.

551 {
552  int columns, rows, numPixels;
553  byte *pixbuf;
554  int row, column;
555  byte *buf_p;
556  byte *buffer;
557  int length;
558  TargaHeader targa_header;
559  byte *targa_rgba;
560  byte tmp[2];
561 
562  *pic = NULL;
563 
564  //
565  // load the file
566  //
567  length = ri.FS_LoadFile (name, (void **)&buffer);
568  if (!buffer)
569  {
570  ri.Con_Printf (PRINT_DEVELOPER, "Bad tga file %s\n", name);
571  return;
572  }
573 
574  buf_p = buffer;
575 
576  targa_header.id_length = *buf_p++;
577  targa_header.colormap_type = *buf_p++;
578  targa_header.image_type = *buf_p++;
579 
580  tmp[0] = buf_p[0];
581  tmp[1] = buf_p[1];
582  targa_header.colormap_index = LittleShort ( *((short *)tmp) );
583  buf_p+=2;
584  tmp[0] = buf_p[0];
585  tmp[1] = buf_p[1];
586  targa_header.colormap_length = LittleShort ( *((short *)tmp) );
587  buf_p+=2;
588  targa_header.colormap_size = *buf_p++;
589  targa_header.x_origin = LittleShort ( *((short *)buf_p) );
590  buf_p+=2;
591  targa_header.y_origin = LittleShort ( *((short *)buf_p) );
592  buf_p+=2;
593  targa_header.width = LittleShort ( *((short *)buf_p) );
594  buf_p+=2;
595  targa_header.height = LittleShort ( *((short *)buf_p) );
596  buf_p+=2;
597  targa_header.pixel_size = *buf_p++;
598  targa_header.attributes = *buf_p++;
599 
600  if (targa_header.image_type!=2
601  && targa_header.image_type!=10)
602  ri.Sys_Error (ERR_DROP, "LoadTGA: Only type 2 and 10 targa RGB images supported\n");
603 
604  if (targa_header.colormap_type !=0
605  || (targa_header.pixel_size!=32 && targa_header.pixel_size!=24))
606  ri.Sys_Error (ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
607 
608  columns = targa_header.width;
609  rows = targa_header.height;
610  numPixels = columns * rows;
611 
612  if (width)
613  *width = columns;
614  if (height)
615  *height = rows;
616 
617  targa_rgba = malloc (numPixels*4);
618  *pic = targa_rgba;
619 
620  if (targa_header.id_length != 0)
621  buf_p += targa_header.id_length; // skip TARGA image comment
622 
623  if (targa_header.image_type==2) { // Uncompressed, RGB images
624  for(row=rows-1; row>=0; row--) {
625  pixbuf = targa_rgba + row*columns*4;
626  for(column=0; column<columns; column++) {
627  unsigned char red,green,blue,alphabyte;
628  switch (targa_header.pixel_size) {
629  case 24:
630 
631  blue = *buf_p++;
632  green = *buf_p++;
633  red = *buf_p++;
634  *pixbuf++ = red;
635  *pixbuf++ = green;
636  *pixbuf++ = blue;
637  *pixbuf++ = 255;
638  break;
639  case 32:
640  blue = *buf_p++;
641  green = *buf_p++;
642  red = *buf_p++;
643  alphabyte = *buf_p++;
644  *pixbuf++ = red;
645  *pixbuf++ = green;
646  *pixbuf++ = blue;
647  *pixbuf++ = alphabyte;
648  break;
649  }
650  }
651  }
652  }
653  else if (targa_header.image_type==10) { // Runlength encoded RGB images
654  unsigned char red,green,blue,alphabyte,packetHeader,packetSize,j;
655  for(row=rows-1; row>=0; row--) {
656  pixbuf = targa_rgba + row*columns*4;
657  for(column=0; column<columns; ) {
658  packetHeader= *buf_p++;
659  packetSize = 1 + (packetHeader & 0x7f);
660  if (packetHeader & 0x80) { // run-length packet
661  switch (targa_header.pixel_size) {
662  case 24:
663  blue = *buf_p++;
664  green = *buf_p++;
665  red = *buf_p++;
666  alphabyte = 255;
667  break;
668  case 32:
669  blue = *buf_p++;
670  green = *buf_p++;
671  red = *buf_p++;
672  alphabyte = *buf_p++;
673  break;
674  default:
675  blue = 0;
676  green = 0;
677  red = 0;
678  alphabyte = 0;
679  break;
680  }
681 
682  for(j=0;j<packetSize;j++) {
683  *pixbuf++=red;
684  *pixbuf++=green;
685  *pixbuf++=blue;
686  *pixbuf++=alphabyte;
687  column++;
688  if (column==columns) { // run spans across rows
689  column=0;
690  if (row>0)
691  row--;
692  else
693  goto breakOut;
694  pixbuf = targa_rgba + row*columns*4;
695  }
696  }
697  }
698  else { // non run-length packet
699  for(j=0;j<packetSize;j++) {
700  switch (targa_header.pixel_size) {
701  case 24:
702  blue = *buf_p++;
703  green = *buf_p++;
704  red = *buf_p++;
705  *pixbuf++ = red;
706  *pixbuf++ = green;
707  *pixbuf++ = blue;
708  *pixbuf++ = 255;
709  break;
710  case 32:
711  blue = *buf_p++;
712  green = *buf_p++;
713  red = *buf_p++;
714  alphabyte = *buf_p++;
715  *pixbuf++ = red;
716  *pixbuf++ = green;
717  *pixbuf++ = blue;
718  *pixbuf++ = alphabyte;
719  break;
720  }
721  column++;
722  if (column==columns) { // pixel packet run spans across rows
723  column=0;
724  if (row>0)
725  row--;
726  else
727  goto breakOut;
728  pixbuf = targa_rgba + row*columns*4;
729  }
730  }
731  }
732  }
733  breakOut:;
734  }
735  }
736 
738 }

Referenced by GL_FindImage().

◆ R_FloodFillSkin()

void R_FloodFillSkin ( byte skin,
int  skinwidth,
int  skinheight 
)

Definition at line 778 of file gl_image.c.

779 {
780  byte fillcolor = *skin; // assume this is the pixel to fill
782  int inpt = 0, outpt = 0;
783  int filledcolor = -1;
784  int i;
785 
786  if (filledcolor == -1)
787  {
788  filledcolor = 0;
789  // attempt to find opaque black
790  for (i = 0; i < 256; ++i)
791  /* if (d_8to24table[i] == (255 << 0)) // alpha 1.0
792  * ENDIAN problem, fix by xvi
793  */
794  if (LittleLong(d_8to24table[i]) == (255 << 0)) // alpha 1.0
795  {
796  filledcolor = i;
797  break;
798  }
799  }
800 
801  // can't fill to filled color or to transparent color (used as visited marker)
802  if ((fillcolor == filledcolor) || (fillcolor == 255))
803  {
804  //printf( "not filling skin from %d to %d\n", fillcolor, filledcolor );
805  return;
806  }
807 
808  fifo[inpt].x = 0, fifo[inpt].y = 0;
809  inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;
810 
811  while (outpt != inpt)
812  {
813  int x = fifo[outpt].x, y = fifo[outpt].y;
814  int fdc = filledcolor;
815  byte *pos = &skin[x + skinwidth * y];
816 
817  outpt = (outpt + 1) & FLOODFILL_FIFO_MASK;
818 
819  if (x > 0) FLOODFILL_STEP( -1, -1, 0 );
820  if (x < skinwidth - 1) FLOODFILL_STEP( 1, 1, 0 );
821  if (y > 0) FLOODFILL_STEP( -skinwidth, 0, -1 );
822  if (y < skinheight - 1) FLOODFILL_STEP( skinwidth, 0, 1 );
823  skin[x + skinwidth * y] = fdc;
824  }
825 }

Referenced by GL_LoadPic().

◆ R_RegisterSkin()

struct image_s* R_RegisterSkin ( char *  name)

Definition at line 1466 of file gl_image.c.

1467 {
1468  return GL_FindImage (name, it_skin);
1469 }

Referenced by GetRefAPI().

◆ Scrap_AllocBlock()

int Scrap_AllocBlock ( int  w,
int  h,
int x,
int y 
)

Definition at line 367 of file gl_image.c.

368 {
369  int i, j;
370  int best, best2;
371  int texnum;
372 
373  for (texnum=0 ; texnum<MAX_SCRAPS ; texnum++)
374  {
375  best = BLOCK_HEIGHT;
376 
377  for (i=0 ; i<BLOCK_WIDTH-w ; i++)
378  {
379  best2 = 0;
380 
381  for (j=0 ; j<w ; j++)
382  {
383  if (scrap_allocated[texnum][i+j] >= best)
384  break;
385  if (scrap_allocated[texnum][i+j] > best2)
386  best2 = scrap_allocated[texnum][i+j];
387  }
388  if (j == w)
389  { // this is a valid spot
390  *x = i;
391  *y = best = best2;
392  }
393  }
394 
395  if (best + h > BLOCK_HEIGHT)
396  continue;
397 
398  for (i=0 ; i<w ; i++)
399  scrap_allocated[texnum][*x + i] = best + h;
400 
401  return texnum;
402  }
403 
404  return -1;
405 // Sys_Error ("Scrap_AllocBlock: full");
406 }

Referenced by GL_LoadPic().

◆ Scrap_Upload()

void Scrap_Upload ( void  )

Definition at line 410 of file gl_image.c.

411 {
412  scrap_uploads++;
414  GL_Upload8 (scrap_texels[0], BLOCK_WIDTH, BLOCK_HEIGHT, false, false );
415  scrap_dirty = false;
416 }

Referenced by Draw_Pic(), and Draw_StretchPic().

Variable Documentation

◆ base_textureid

int base_textureid

Definition at line 25 of file gl_image.c.

◆ d_8to24table

◆ gammatable

unsigned char gammatable[256]
static

Definition at line 28 of file gl_image.c.

Referenced by GL_InitImages(), and GL_LightScaleTexture().

◆ gl_alpha_format

int gl_alpha_format = 4

Definition at line 39 of file gl_image.c.

Referenced by GL_Upload32().

◆ gl_alpha_modes

gltmode_t gl_alpha_modes[]
Initial value:
= {
{"default", 4},
{"GL_RGBA", GL_RGBA},
{"GL_RGBA8", GL_RGBA8},
{"GL_RGB5_A1", GL_RGB5_A1},
{"GL_RGBA4", GL_RGBA4},
{"GL_RGBA2", GL_RGBA2},
}

Definition at line 187 of file gl_image.c.

Referenced by GL_TextureAlphaMode().

◆ gl_filter_max

int gl_filter_max = GL_LINEAR

Definition at line 45 of file gl_image.c.

Referenced by GL_SetDefaultState(), GL_TextureMode(), GL_Upload32(), and GL_Upload8().

◆ gl_filter_min

int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST

Definition at line 44 of file gl_image.c.

Referenced by GL_SetDefaultState(), GL_TextureMode(), and GL_Upload32().

◆ gl_solid_format

int gl_solid_format = 3

Definition at line 38 of file gl_image.c.

Referenced by GL_Upload32().

◆ gl_solid_modes

gltmode_t gl_solid_modes[]
Initial value:
= {
{"default", 3},
{"GL_RGB", GL_RGB},
{"GL_RGB8", GL_RGB8},
{"GL_RGB5", GL_RGB5},
{"GL_RGB4", GL_RGB4},
{"GL_R3_G3_B2", GL_R3_G3_B2},
}

Definition at line 198 of file gl_image.c.

Referenced by GL_TextureSolidMode().

◆ gl_tex_alpha_format

int gl_tex_alpha_format = 4

Definition at line 42 of file gl_image.c.

Referenced by GL_BeginBuildingLightmaps(), GL_TextureAlphaMode(), and GL_Upload32().

◆ gl_tex_solid_format

int gl_tex_solid_format = 3

◆ gltextures

◆ intensity

cvar_t* intensity

◆ intensitytable

byte intensitytable[256]
static

Definition at line 27 of file gl_image.c.

Referenced by GL_InitImages(), and GL_LightScaleTexture().

◆ modes

glmode_t modes[]
Initial value:
= {
{"GL_NEAREST", GL_NEAREST, GL_NEAREST},
{"GL_LINEAR", GL_LINEAR, GL_LINEAR},
{"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
{"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
{"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
{"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
}

Definition at line 170 of file gl_image.c.

Referenced by GL_TextureMode().

◆ numgltextures

◆ scrap_allocated

int scrap_allocated[MAX_SCRAPS][BLOCK_WIDTH]

Definition at line 362 of file gl_image.c.

Referenced by Scrap_AllocBlock().

◆ scrap_dirty

qboolean scrap_dirty

Definition at line 364 of file gl_image.c.

Referenced by Draw_Pic(), Draw_StretchPic(), GL_LoadPic(), and Scrap_Upload().

◆ scrap_texels

Definition at line 363 of file gl_image.c.

Referenced by GL_LoadPic(), and Scrap_Upload().

◆ scrap_uploads

int scrap_uploads

Definition at line 408 of file gl_image.c.

Referenced by Scrap_Upload().

◆ upload_height

int upload_height

Definition at line 973 of file gl_image.c.

Referenced by GL_LoadPic(), and GL_Upload32().

◆ upload_width

int upload_width

Definition at line 973 of file gl_image.c.

Referenced by GL_LoadPic(), and GL_Upload32().

◆ uploaded_paletted

qboolean uploaded_paletted

Definition at line 974 of file gl_image.c.

Referenced by GL_LoadPic(), and GL_Upload32().

GL_RENDERER_VOODOO
#define GL_RENDERER_VOODOO
Definition: gl_local.h:364
MAX_SCRAPS
#define MAX_SCRAPS
Definition: gl_image.c:358
FLOODFILL_FIFO_MASK
#define FLOODFILL_FIFO_MASK
Definition: gl_image.c:765
it_sprite
@ it_sprite
Definition: r_local.h:59
numgltextures
int numgltextures
Definition: gl_image.c:24
LoadTGA
void LoadTGA(char *name, byte **pic, int *width, int *height)
Definition: gl_image.c:550
height
GLsizei height
Definition: qgl_win.c:69
scrap_uploads
int scrap_uploads
Definition: gl_image.c:408
LittleShort
short LittleShort(short l)
Definition: q_shared.c:946
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
green
GLfloat green
Definition: qgl_win.c:74
image_s::th
float th
Definition: gl_local.h:103
_TargaHeader::y_origin
unsigned short y_origin
Definition: r_image.c:194
r_notexture
image_t * r_notexture
Definition: gl_rmain.c:38
scrap_texels
byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH *BLOCK_HEIGHT]
Definition: gl_image.c:363
GL_SHARED_TEXTURE_PALETTE_EXT
#define GL_SHARED_TEXTURE_PALETTE_EXT
Definition: qgl.h:464
scrap_dirty
qboolean scrap_dirty
Definition: gl_image.c:364
gl_state
glstate_t gl_state
Definition: gl_rmain.c:36
skinwidth
int skinwidth
Definition: r_polyse.c:114
ri
refimport_t ri
Definition: r_main.c:25
pcx_t
Definition: qfiles.h:60
glstate_t::currenttextures
int currenttextures[2]
Definition: gl_local.h:426
PRINT_DEVELOPER
#define PRINT_DEVELOPER
Definition: qcommon.h:744
d_8to24table
unsigned d_8to24table[256]
Definition: gl_image.c:32
miptex_s
Definition: qfiles.h:198
GL_LoadWal
image_t * GL_LoadWal(char *name)
Definition: gl_image.c:1362
v
GLdouble v
Definition: qgl_win.c:143
it_wall
@ it_wall
Definition: r_local.h:60
_TargaHeader::x_origin
unsigned short x_origin
Definition: r_image.c:194
_TargaHeader::pixel_size
unsigned char pixel_size
Definition: r_image.c:195
glstate_t::currenttmu
int currenttmu
Definition: gl_local.h:427
refimport_t::FS_LoadFile
int(* FS_LoadFile)(char *name, void **buf)
Definition: ref.h:235
refimport_t::Cvar_Get
cvar_t *(* Cvar_Get)(char *name, char *value, int flags)
Definition: ref.h:242
pcx_t::version
char version
Definition: qfiles.h:63
pcx_t::data
unsigned char data
Definition: qfiles.h:74
x
GLint GLenum GLint x
Definition: qgl_win.c:116
i
int i
Definition: q_shared.c:305
gl_solid_format
int gl_solid_format
Definition: gl_image.c:38
gl_alpha_modes
gltmode_t gl_alpha_modes[]
Definition: gl_image.c:187
gammatable
static unsigned char gammatable[256]
Definition: gl_image.c:28
NUM_GL_ALPHA_MODES
#define NUM_GL_ALPHA_MODES
Definition: gl_image.c:196
buffer
GLenum GLfloat * buffer
Definition: qgl_win.c:151
upload_width
int upload_width
Definition: gl_image.c:973
refimport_t::Cvar_Set
cvar_t *(* Cvar_Set)(char *name, char *value)
Definition: ref.h:243
GL_Upload32
qboolean GL_Upload32(unsigned *data, int width, int height, qboolean mipmap)
Definition: gl_image.c:976
floodfill_t::x
short x
Definition: gl_image.c:760
_TargaHeader::image_type
unsigned char image_type
Definition: r_image.c:191
width
GLint GLsizei width
Definition: qgl_win.c:115
gl_round_down
cvar_t * gl_round_down
Definition: gl_rmain.c:115
scrap_allocated
int scrap_allocated[MAX_SCRAPS][BLOCK_WIDTH]
Definition: gl_image.c:362
pcx_t::hres
unsigned short hres
Definition: qfiles.h:67
gl_nobind
cvar_t * gl_nobind
Definition: gl_rmain.c:114
image_s::registration_sequence
int registration_sequence
Definition: r_local.h:71
type
GLenum type
Definition: qgl_win.c:72
uploaded_paletted
qboolean uploaded_paletted
Definition: gl_image.c:974
_TargaHeader::colormap_size
unsigned char colormap_size
Definition: r_image.c:193
NUM_GL_SOLID_MODES
#define NUM_GL_SOLID_MODES
Definition: gl_image.c:210
glmode_t::minimize
int minimize
Definition: gl_image.c:167
_TargaHeader::colormap_index
unsigned short colormap_index
Definition: r_image.c:192
intensity
cvar_t * intensity
Definition: gl_image.c:30
refimport_t::FS_FreeFile
void(* FS_FreeFile)(void *buf)
Definition: ref.h:236
j
GLint j
Definition: qgl_win.c:150
gl_solid_modes
gltmode_t gl_solid_modes[]
Definition: gl_image.c:198
R_FloodFillSkin
void R_FloodFillSkin(byte *skin, int skinwidth, int skinheight)
Definition: gl_image.c:778
gl_filter_min
int gl_filter_min
Definition: gl_image.c:44
gl_tex_alpha_format
int gl_tex_alpha_format
Definition: gl_image.c:42
GL_MipMap
void GL_MipMap(byte *in, int width, int height)
Definition: gl_image.c:926
gltextures
image_t gltextures[MAX_GLTEXTURES]
Definition: gl_image.c:23
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:228
GL_FindImage
image_t * GL_FindImage(char *name, imagetype_t type)
Definition: gl_image.c:1393
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:743
pcx_t::ymin
unsigned short ymin
Definition: qfiles.h:66
TEXNUM_IMAGES
#define TEXNUM_IMAGES
Definition: gl_local.h:112
image_s::scrap
qboolean scrap
Definition: gl_local.h:104
skin
cvar_t * skin
Definition: cl_main.c:95
miplevel
static int miplevel
Definition: r_edge.c:77
it_pic
@ it_pic
Definition: r_local.h:61
gl_alpha_format
int gl_alpha_format
Definition: gl_image.c:39
r
GLdouble GLdouble r
Definition: qgl_win.c:336
gltmode_t::mode
int mode
Definition: gl_image.c:184
LittleLong
int LittleLong(int l)
Definition: q_shared.c:948
image_s::height
int height
Definition: r_local.h:69
_TargaHeader::colormap_length
unsigned short colormap_length
Definition: r_image.c:192
intensitytable
static byte intensitytable[256]
Definition: gl_image.c:27
GLuint
GLuint(APIENTRY *qglGenLists)(GLsizei range)
image_s::texnum
int texnum
Definition: gl_local.h:102
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:220
GL_Bind
void GL_Bind(int texnum)
Definition: gl_image.c:136
gl_picmip
static cvar_t * gl_picmip
Definition: vid_menu.c:36
glmode_t::maximize
int maximize
Definition: gl_image.c:167
_TargaHeader::attributes
unsigned char attributes
Definition: r_image.c:195
pcx_t::ymax
unsigned short ymax
Definition: qfiles.h:66
cvar_s::value
float value
Definition: q_shared.h:324
r_particletexture
image_t * r_particletexture
Definition: gl_rmain.c:39
GL_Upload8
qboolean GL_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky)
Definition: gl_image.c:1185
FLOODFILL_STEP
#define FLOODFILL_STEP(off, dx, dy)
Definition: gl_image.c:767
MAX_GLTEXTURES
#define MAX_GLTEXTURES
Definition: gl_local.h:114
floodfill_t
Definition: gl_image.c:758
image_s::type
imagetype_t type
Definition: r_local.h:68
pcx_t::encoding
char encoding
Definition: qfiles.h:64
NULL
#define NULL
Definition: q_shared.h:60
GL_ResampleTexture
void GL_ResampleTexture(unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
Definition: gl_image.c:835
glstate_t::inverse_intensity
float inverse_intensity
Definition: gl_local.h:417
image_s::width
int width
Definition: r_local.h:69
modes
glmode_t modes[]
Definition: gl_image.c:170
image_s::tl
float tl
Definition: gl_local.h:103
pcx_t::palette_type
unsigned short palette_type
Definition: qfiles.h:72
upload_height
int upload_height
Definition: gl_image.c:973
image_s::name
char name[MAX_QPATH]
Definition: r_local.h:67
QGL_TEXTURE0
int QGL_TEXTURE0
Definition: gl_rmain.c:29
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:736
Q_stricmp
int Q_stricmp(char *s1, char *s2)
Definition: q_shared.c:1192
it_skin
@ it_skin
Definition: r_local.h:58
gl_filter_max
int gl_filter_max
Definition: gl_image.c:45
pcx_t::bits_per_pixel
char bits_per_pixel
Definition: qfiles.h:65
name
cvar_t * name
Definition: cl_main.c:94
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:735
QGL_TEXTURE1
int QGL_TEXTURE1
Definition: gl_rmain.c:29
pcx_t::xmin
unsigned short xmin
Definition: qfiles.h:66
glconfig_t::renderer
int renderer
Definition: gl_local.h:406
y
GLint y
Definition: qgl_win.c:115
image_s::paletted
qboolean paletted
Definition: gl_local.h:107
GL_RENDERER_VOODOO2
#define GL_RENDERER_VOODOO2
Definition: gl_local.h:365
FLOODFILL_FIFO_SIZE
#define FLOODFILL_FIFO_SIZE
Definition: gl_image.c:764
_TargaHeader
Definition: r_image.c:190
gl_tex_solid_format
int gl_tex_solid_format
Definition: gl_image.c:41
glstate_t::hwgamma
qboolean hwgamma
Definition: gl_local.h:432
image_s::upload_width
int upload_width
Definition: gl_local.h:99
image_s::sl
float sl
Definition: gl_local.h:103
vid_gamma
cvar_t * vid_gamma
Definition: vid_dll.c:42
gl_config
glconfig_t gl_config
Definition: gl_rmain.c:35
GL_TexEnv
void GL_TexEnv(GLenum mode)
Definition: gl_image.c:125
image_s::has_alpha
qboolean has_alpha
Definition: gl_local.h:105
blue
GLfloat GLfloat blue
Definition: qgl_win.c:74
gl_ext_palettedtexture
static cvar_t * gl_ext_palettedtexture
Definition: vid_menu.c:37
pcx_t::manufacturer
char manufacturer
Definition: qfiles.h:62
_TargaHeader::colormap_type
unsigned char colormap_type
Definition: r_image.c:191
_TargaHeader::width
unsigned short width
Definition: r_image.c:194
GL_LoadPic
image_t * GL_LoadPic(char *name, byte *pic, int width, int height, imagetype_t type, int bits)
Definition: gl_image.c:1255
_TargaHeader::id_length
unsigned char id_length
Definition: r_image.c:191
BLOCK_HEIGHT
#define BLOCK_HEIGHT
Definition: gl_image.c:360
pcx_t::vres
unsigned short vres
Definition: qfiles.h:67
_TargaHeader::height
unsigned short height
Definition: r_image.c:194
texture
GLuint texture
Definition: qgl_win.c:68
image_s::upload_height
int upload_height
Definition: gl_local.h:99
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
registration_sequence
int registration_sequence
Definition: r_model.c:44
GL_BuildPalettedTexture
void GL_BuildPalettedTexture(unsigned char *paletted_texture, unsigned char *scaled, int scaled_width, int scaled_height)
Definition: gl_image.c:953
image_s
Definition: r_local.h:65
mode
GLenum mode
Definition: qgl_win.c:113
pcx_t::xmax
unsigned short xmax
Definition: qfiles.h:66
GL_SelectTexture
void GL_SelectTexture(GLenum texture)
Definition: gl_image.c:91
floodfill_t::y
short y
Definition: gl_image.c:760
Draw_GetPalette
int Draw_GetPalette(void)
Definition: gl_image.c:1509
Scrap_AllocBlock
int Scrap_AllocBlock(int w, int h, int *x, int *y)
Definition: gl_image.c:367
LoadPCX
void LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height)
Definition: gl_image.c:432
NUM_GL_MODES
#define NUM_GL_MODES
Definition: gl_image.c:179
draw_chars
image_t * draw_chars
Definition: r_draw.c:26
glstate_t::d_16to8table
unsigned char * d_16to8table
Definition: gl_local.h:422
TEXNUM_SCRAPS
#define TEXNUM_SCRAPS
Definition: gl_local.h:111
GL_LightScaleTexture
void GL_LightScaleTexture(unsigned *in, int inwidth, int inheight, qboolean only_gamma)
Definition: gl_image.c:885
BLOCK_WIDTH
#define BLOCK_WIDTH
Definition: gl_image.c:359
pcx_t::bytes_per_line
unsigned short bytes_per_line
Definition: qfiles.h:71
image_s::sh
float sh
Definition: gl_local.h:103
it_sky
@ it_sky
Definition: r_local.h:62