Source/ThunderBeast/QuakeToonProto1/ref_gl/gl_image.c
image_t *GL_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type, int bits)
{
	image_t		*image;
	int			i;

	// find a free image_t
	for (i=0, image=gltextures ; i<numgltextures ; i++,image++)
	{
		if (!image->texnum)
			break;
	}
	if (i == numgltextures)
	{
		if (numgltextures == MAX_GLTEXTURES)
			ri.Sys_Error (ERR_DROP, "MAX_GLTEXTURES");
		numgltextures++;
	}
	image = &gltextures[i];

	if (strlen(name) >= sizeof(image->name))
		ri.Sys_Error (ERR_DROP, "Draw_LoadPic: \"%s\" is too long", name);
	strcpy (image->name, name);
	image->registration_sequence = registration_sequence;

	image->width = width;
	image->height = height;
	image->type = type;

	if (type == it_skin && bits == 8)
		R_FloodFillSkin(pic, width, height);

	// load little pics into the scrap
	if (image->type == it_pic && bits == 8
		&& image->width < 64 && image->height < 64)
	{
		int		x, y;
		int		i, j, k;
		int		texnum;

		texnum = Scrap_AllocBlock (image->width, image->height, &x, &y);
		if (texnum == -1)
			goto nonscrap;
		scrap_dirty = true;

		// copy the texels into the scrap block
		k = 0;
		for (i=0 ; i<image->height ; i++)
			for (j=0 ; j<image->width ; j++, k++)
				scrap_texels[texnum][(y+i)*BLOCK_WIDTH + x + j] = pic[k];
		image->texnum = TEXNUM_SCRAPS + texnum;
		image->scrap = true;
		image->has_alpha = true;
		image->sl = (x+0.01)/(float)BLOCK_WIDTH;
		image->sh = (x+image->width-0.01)/(float)BLOCK_WIDTH;
		image->tl = (y+0.01)/(float)BLOCK_WIDTH;
		image->th = (y+image->height-0.01)/(float)BLOCK_WIDTH;
	}
	else
	{
nonscrap:
		image->scrap = false;
		image->texnum = TEXNUM_IMAGES + (image - gltextures);
		GL_Bind(image->texnum);
		if (bits == 8)
			image->has_alpha = GL_Upload8 (pic, width, height, (image->type != it_pic && image->type != it_sky), image->type == it_sky );
		else
			image->has_alpha = GL_Upload32 ((unsigned *)pic, width, height, (image->type != it_pic && image->type != it_sky) );
		image->upload_width = upload_width;		// after power of 2 and scales
		image->upload_height = upload_height;
		image->paletted = uploaded_paletted;
		image->sl = 0;
		image->sh = 1;
		image->tl = 0;
		image->th = 1;
	}

	return image;
}
/*
================
GL_LoadPic

This is also used as an entry point for the generated r_notexture
================
*/
GL_LoadPic
This is also used as an entry point for the generated r_notexture
GL_LoadPic This is also used as an entry point for the generated r_notexture
image_t *GL_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type, int bits)
{
	image_t		*image;
	int			i;
	for (i=0, image=gltextures ; i<numgltextures ; i++,image++)
	{
		if (!image->texnum)
			break;
	}
	if (i == numgltextures)
	{
		if (numgltextures == MAX_GLTEXTURES)
			ri.Sys_Error (ERR_DROP, "MAX_GLTEXTURES");
		numgltextures++;
	}
	image = &gltextures[i];
	if (strlen(name) >= sizeof(image->name))
		ri.Sys_Error (ERR_DROP, "Draw_LoadPic: \"%s\" is too long", name);
	strcpy (image->name, name);
	image->registration_sequence = registration_sequence;
	image->width = width;
	image->height = height;
	image->type = type;
	if (type == it_skin && bits == 8)
		R_FloodFillSkin(pic, width, height);
	if (image->type == it_pic && bits == 8
		&& image->width < 64 && image->height < 64)
	{
		int		x, y;
		int		i, j, k;
		int		texnum;
		texnum = Scrap_AllocBlock (image->width, image->height, &x, &y);
		if (texnum == -1)
			goto nonscrap;
		scrap_dirty = true;
		k = 0;
		for (i=0 ; i<image->height ; i++)
			for (j=0 ; j<image->width ; j++, k++)
				scrap_texels[texnum][(y+i)*BLOCK_WIDTH + x + j] = pic[k];
		image->texnum = TEXNUM_SCRAPS + texnum;
		image->scrap = true;
		image->has_alpha = true;
		image->sl = (x+0.01)/(float)BLOCK_WIDTH;
		image->sh = (x+image->width-0.01)/(float)BLOCK_WIDTH;
		image->tl = (y+0.01)/(float)BLOCK_WIDTH;
		image->th = (y+image->height-0.01)/(float)BLOCK_WIDTH;
	}
	else
	{
nonscrap:
		image->scrap = false;
		image->texnum = TEXNUM_IMAGES + (image - gltextures);
		GL_Bind(image->texnum);
		if (bits == 8)
			image->has_alpha = GL_Upload8 (pic, width, height, (image->type != it_pic && image->type != it_sky), image->type == it_sky );
		else
			image->has_alpha = GL_Upload32 ((unsigned *)pic, width, height, (image->type != it_pic && image->type != it_sky) );
		image->upload_width = upload_width;		
		image->upload_height = upload_height;
		image->paletted = uploaded_paletted;
		image->sl = 0;
		image->sh = 1;
		image->tl = 0;
		image->th = 1;
	}
	return image;
}
image_t * GL_LoadPic ( char * name , byte * pic , int width , int height , imagetype_t type , int bits ) { image_t * image ; int i ; for ( i = 0 , image = gltextures ; i < numgltextures ; i ++ , image ++ ) { if ( ! image -> texnum ) break ; } if ( i == numgltextures ) { if ( numgltextures == MAX_GLTEXTURES ) ri . Sys_Error ( ERR_DROP , " " ) ; numgltextures ++ ; } image = & gltextures [ i ] ; if ( strlen ( name ) >= sizeof ( image -> name ) ) ri . Sys_Error ( ERR_DROP , " \" \" " , name ) ; strcpy ( image -> name , name ) ; image -> registration_sequence = registration_sequence ; image -> width = width ; image -> height = height ; image -> type = type ; if ( type == it_skin && bits == 8 ) R_FloodFillSkin ( pic , width , height ) ; if ( image -> type == it_pic && bits == 8 && image -> width < 64 && image -> height < 64 ) { int x , y ; int i , j , k ; int texnum ; texnum = Scrap_AllocBlock ( image -> width , image -> height , & x , & y ) ; if ( texnum == -1 ) goto nonscrap ; scrap_dirty = true ; k = 0 ; for ( i = 0 ; i < image -> height ; i ++ ) for ( j = 0 ; j < image -> width ; j ++ , k ++ ) scrap_texels [ texnum ] [ ( y + i ) * BLOCK_WIDTH + x + j ] = pic [ k ] ; image -> texnum = TEXNUM_SCRAPS + texnum ; image -> scrap = true ; image -> has_alpha = true ; image -> sl = ( x + 0.01 ) / ( float ) BLOCK_WIDTH ; image -> sh = ( x + image -> width - 0.01 ) / ( float ) BLOCK_WIDTH ; image -> tl = ( y + 0.01 ) / ( float ) BLOCK_WIDTH ; image -> th = ( y + image -> height - 0.01 ) / ( float ) BLOCK_WIDTH ; } else { nonscrap : image -> scrap = false ; image -> texnum = TEXNUM_IMAGES + ( image - gltextures ) ; GL_Bind ( image -> texnum ) ; if ( bits == 8 ) image -> has_alpha = GL_Upload8 ( pic , width , height , ( image -> type != it_pic && image -> type != it_sky ) , image -> type == it_sky ) ; else image -> has_alpha = GL_Upload32 ( ( unsigned * ) pic , width , height , ( image -> type != it_pic && image -> type != it_sky ) ) ; image -> upload_width = upload_width ; image -> upload_height = upload_height ; image -> paletted = uploaded_paletted ; image -> sl = 0 ; image -> sh = 1 ; image -> tl = 0 ; image -> th = 1 ; } return image ; }
GL_LoadPic
This is also used as an entry point for the generated r_notexture
GL_LoadPic This is also used as an entry point for the generated r_notexture
// find a free image_t // load little pics into the scrap // copy the texels into the scrap block // after power of 2 and scales