/* ================= Mod_LoadTexinfo ================= */ void Mod_LoadTexinfo (lump_t *l) { texinfo_t *in; // image_t *last_image; mtexinfo_t *out, *step; int i, count; char name[MAX_QPATH]; int next; size_t length; in = (texinfo_t *)(mod_base + l->fileofs); if (l->filelen % sizeof(*in)) VID_Error (ERR_DROP, "Mod_LoadTexinfo: funny lump size in %s",loadmodel->name); count = l->filelen / sizeof(*in); out = (mtexinfo_t *) Hunk_Alloc ( count*sizeof(*out)); loadmodel->texinfo = out; loadmodel->numtexinfo = count; for ( i=0 ; i<count ; i++, in++, out++) { memcpy (out->vecs, in->vecs, sizeof(out->vecs)); out->flags = LittleLong(in->flags); next = LittleLong(in->nexttexinfo); if (next > 0) out->next = loadmodel->texinfo + next; else out->next = NULL; fast_strlwr (in->texture); out->image = GL_FindImageBase (in->texture, it_wall); if (out->image) continue; Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture); if (!GetWalInfo (name, &global_hax_texture_x, &global_hax_texture_y)) { VID_Printf (PRINT_ALL, "Couldn't load %s\n", name); out->image = r_notexture; continue; } length = strlen(name); if (load_tga_wals) { //Com_sprintf (name, sizeof(name), "textures/%s.tga", in->texture); memcpy (name + length-3, "tga", 3); out->image = GL_FindImage (name, in->texture, it_wall); } else { out->image = NULL; } if (!out->image) { if (load_png_wals) { memcpy (name + length-3, "png", 3); //Com_sprintf (name, sizeof(name), "textures/%s.png", in->texture); out->image = GL_FindImage (name, in->texture, it_wall); } if (!out->image) { if (load_jpg_wals) { memcpy (name + length-3, "jpg", 3); //Com_sprintf (name, sizeof(name), "textures/%s.jpg", in->texture); out->image = GL_FindImage (name, in->texture, it_wall); } if (!out->image) { memcpy (name + length-3, "wal", 3); //Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture); out->image = GL_FindImage (name, in->texture, it_wall); if (!out->image) { VID_Printf (PRINT_ALL, "Couldn't load %s\n", name); out->image = r_notexture; } } } } //last_image = out->image; global_hax_texture_x = global_hax_texture_y = 0; } // count animation frames for (i=0 ; i<count ; i++) { out = &loadmodel->texinfo[i]; out->numframes = 1; for (step = out->next ; step && step != out ; step=step->next) out->numframes++; } }
/* * Finds or loads the given image */ gl3image_t * GL3_FindImage(char *name, imagetype_t type) { gl3image_t *image; int i, len; byte *pic; int width, height; char *ptr; char namewe[256]; int realwidth = 0, realheight = 0; const char* ext; if (!name) { return NULL; } ext = COM_FileExtension(name); if(!ext[0]) { /* file has no extension */ return NULL; } len = strlen(name); /* Remove the extension */ memset(namewe, 0, 256); memcpy(namewe, name, len - 4); if (len < 5) { return NULL; } /* fix backslashes */ while ((ptr = strchr(name, '\\'))) { *ptr = '/'; } /* look for it */ for (i = 0, image = gl3textures; i < numgl3textures; i++, image++) { if (!strcmp(name, image->name)) { image->registration_sequence = registration_sequence; return image; } } /* load the pic from disk */ pic = NULL; if (strcmp(ext, "pcx") == 0) { if (gl_retexturing->value) { GetPCXInfo(name, &realwidth, &realheight); if(realwidth == 0) { /* No texture found */ return NULL; } /* try to load a tga, png or jpg (in that order/priority) */ if ( LoadSTB(namewe, "tga", &pic, &width, &height) || LoadSTB(namewe, "png", &pic, &width, &height) || LoadSTB(namewe, "jpg", &pic, &width, &height) ) { /* upload tga or png or jpg */ image = GL3_LoadPic(name, pic, width, realwidth, height, realheight, type, 32); } else { /* PCX if no TGA/PNG/JPEG available (exists always) */ LoadPCX(name, &pic, NULL, &width, &height); if (!pic) { /* No texture found */ return NULL; } /* Upload the PCX */ image = GL3_LoadPic(name, pic, width, 0, height, 0, type, 8); } } else /* gl_retexture is not set */ { LoadPCX(name, &pic, NULL, &width, &height); if (!pic) { return NULL; } image = GL3_LoadPic(name, pic, width, 0, height, 0, type, 8); } } else if (strcmp(ext, "wal") == 0) { if (gl_retexturing->value) { /* Get size of the original texture */ GetWalInfo(name, &realwidth, &realheight); if(realwidth == 0) { /* No texture found */ return NULL; } /* try to load a tga, png or jpg (in that order/priority) */ if ( LoadSTB(namewe, "tga", &pic, &width, &height) || LoadSTB(namewe, "png", &pic, &width, &height) || LoadSTB(namewe, "jpg", &pic, &width, &height) ) { /* upload tga or png or jpg */ image = GL3_LoadPic(name, pic, width, realwidth, height, realheight, type, 32); } else { /* WAL if no TGA/PNG/JPEG available (exists always) */ image = LoadWal(namewe); } if (!image) { /* No texture found */ return NULL; } } else /* gl_retexture is not set */ { image = LoadWal(name); if (!image) { /* No texture found */ return NULL; } } } else if (strcmp(ext, "tga") == 0 || strcmp(ext, "png") == 0 || strcmp(ext, "jpg") == 0) { char tmp_name[256]; realwidth = 0; realheight = 0; strcpy(tmp_name, namewe); strcat(tmp_name, ".wal"); GetWalInfo(tmp_name, &realwidth, &realheight); if (realwidth == 0 || realheight == 0) { /* It's a sky or model skin. */ strcpy(tmp_name, namewe); strcat(tmp_name, ".pcx"); GetPCXInfo(tmp_name, &realwidth, &realheight); } /* TODO: not sure if not having realwidth/heigth is bad - a tga/png/jpg * was requested, after all, so there might be no corresponding wal/pcx? * if (realwidth == 0 || realheight == 0) return NULL; */ if(LoadSTB(name, ext, &pic, &width, &height)) { image = GL3_LoadPic(name, pic, width, realwidth, height, realheight, type, 32); } } else { return NULL; } if (pic) { free(pic); } return image; }