int Texture::load(const char *fn, int flags) { char fn_buf[512]; char *fn_cube[6]; int i; _loadHDR=flags&TEXTURE_LOAD_HDR; if (flags&TEXTURE_LOAD_CUBEMAP) { _target=GL_TEXTURE_CUBE_MAP; printf("loading cubemap texture.. %s\n",fn); for(i=0;i<6;i++) { if (_filename_cube[i]) free((void*)_filename_cube[i]); _snprintf(fn_buf,sizeof(fn_buf),fn,CUBEMAP_DATA[i].name); printf(" %s (%s): ",CUBEMAP_DATA[i].name,fn_buf); if (_filename_cube[i]=vfs_locate(fn_buf,REPOSITORY_MASK_TEXTURE)) { printf("%s\n",_filename_cube[i]); loadTextureFile( _filename_cube[i],_name, GL_TEXTURE_CUBE_MAP,CUBEMAP_DATA[i].textureTarget, _loadHDR); } else { printf(" <not found> %s\n",_filename_cube[i]); } } glBindTexture(GL_TEXTURE_CUBE_MAP,_name); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_CUBE_MAP,0); } else { if (_filename) free((void*)_filename); _filename=vfs_locate(fn,REPOSITORY_MASK_TEXTURE); if (_filename) { loadTextureFile(_filename,_name,_target,_target, _loadHDR); } else { LOG_WARNING( "WARNING: unable to locate texture file '%s'\n",fn); } } return 1; }
static VFSNode* vfs_vdir_locate(VFSNode *vdir, const char *path) { VFSNode *node; char mutpath[strlen(path)+1]; char *primpath, *subpath; strcpy(mutpath, path); vfs_path_split_left(mutpath, &primpath, &subpath); if((node = ht_get(VDIR_TABLE(vdir), mutpath, NULL))) { return vfs_locate(node, subpath); } return NULL; }
GLuint loadTextureFile(const char *fn_in, GLuint tex_in, GLenum target_texture, GLenum target_image, int HDR) { ILuint img=0; GLuint tex=tex_in; char *fn=0; if (!(fn=vfs_locate(fn_in,REPOSITORY_MASK_TEXTURE))) { LOG_WARNING( "WARNING: unable to find texture file '%s'\n", fn_in); goto finalize; } ilEnable(IL_ORIGIN_SET); ilOriginFunc(IL_ORIGIN_LOWER_LEFT); ilGenImages(1,&img); ilBindImage(img); if (ilLoadImage(fn)!=1) { LOG_WARNING( "WARNING: unable to load texture file '%s'\n", fn); goto finalize; } #if DIYYMA_FILE_LIST>=2 file_list_append(fn); #endif ilConvertImage(HDR?IL_RGB:IL_RGBA,HDR?IL_FLOAT:IL_UNSIGNED_BYTE); if (!tex) glGenTextures(1,&tex); glBindTexture(target_texture,tex); glTexImage2D( target_image,0,HDR?GL_R11F_G11F_B10F:GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH),ilGetInteger(IL_IMAGE_HEIGHT), 0,HDR?GL_RGB:GL_RGBA,HDR?GL_FLOAT:GL_UNSIGNED_BYTE, ilGetData()); glTexParameteri(target_texture,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(target_texture,GL_TEXTURE_MAG_FILTER,GL_LINEAR); finalize: if (fn) free((void*)fn); if (img) ilDeleteImages(1,&img); return tex; }