示例#1
0
	   void Texture::Revert()
	   {
		   if (IsCachedIn())
		   {
			   CacheOut();
			   CacheIn();
		   }
	   }
示例#2
0
      void Texture::SetFilter(Filter minFilter, Filter magFilter)
      {
         m_impl->m_minificationFilter = minFilter;
         m_impl->m_magnificationFilter = magFilter;

         if (IsCachedIn())
         {
            Activate();
            UpdateFiltering(m_impl);
         }
      }
示例#3
0
 void Texture::CacheOut()
 {
    if (!Bad() && IsCachedIn())
    {
       UnbindTextureFromOpenGL(m_impl);
       delete [] m_impl->m_texture_surface;
       delete [] m_impl->m_texture_dirty_array;
       m_impl->m_texture_surface = NULL;
       m_impl->m_texture_dirty_array = NULL;
    }
 }
示例#4
0
bool DOS_Drive_Cache::ReadDir(Bit16u id, char* &result) {
	// shouldnt happen...
	if (id>MAX_OPENDIRS) return false;

	if (!IsCachedIn(dirSearch[id])) {
		// Try to open directory
		dir_information* dirp = open_directory(dirPath);
		if (!dirp) {
			if (dirSearch[id]) {
				dirSearch[id]->id = MAX_OPENDIRS;
				dirSearch[id] = 0;
			}
			return false;
		}
		// Read complete directory
		char dir_name[CROSS_LEN];
		bool is_directory;
		if (read_directory_first(dirp, dir_name, is_directory)) {
			CreateEntry(dirSearch[id], dir_name, is_directory);
			while (read_directory_next(dirp, dir_name, is_directory)) {
				CreateEntry(dirSearch[id], dir_name, is_directory);
			}
		}

		// close dir
		close_directory(dirp);

		// Info
/*		if (!dirp) {
			LOG_DEBUG("DIR: Error Caching in %s",dirPath);			
			return false;
		} else {	
			char buffer[128];
			sprintf(buffer,"DIR: Caching in %s (%d Files)",dirPath,dirSearch[srchNr]->fileList.size());
			LOG_DEBUG(buffer);
		};*/
	};
	if (SetResult(dirSearch[id], result, dirSearch[id]->nextEntry)) return true;
	if (dirSearch[id]) {
		dirSearch[id]->id = MAX_OPENDIRS;
		dirSearch[id] = 0;
	}
	return false;
}
示例#5
0
      void Texture::Activate()
      {
         if (!Bad())
         {
            if (IsCachedIn())
            {
               glBindTexture(GL_TEXTURE_2D, m_impl->m_id);
            }
            else
            {
               // texture not loaded try to cache in
               CacheIn();

               // make sure the cache in worked
               if (!Bad())
               {
                  glBindTexture(GL_TEXTURE_2D, m_impl->m_id);
               }
            }
         }
      }
示例#6
0
DOS_Drive_Cache::CFileInfo* DOS_Drive_Cache::FindDirInfo(const char* path, char* expandedPath) {
	// statics
	static char	split[2] = { CROSS_FILESPLIT,0 };
	
	char		dir  [CROSS_LEN]; 
	char		work [CROSS_LEN];
	const char*	start = path;
	const char*		pos;
	CFileInfo*	curDir = dirBase;
	Bit16u		id;

	if (save_dir && (strcmp(path,save_path)==0)) {
		strcpy(expandedPath,save_expanded);
		return save_dir;
	};

//	LOG_DEBUG("DIR: Find %s",path);

	// Remove base dir path
	start += strlen(basePath);
	strcpy(expandedPath,basePath);

	// hehe, baseDir should be cached in... 
	if (!IsCachedIn(curDir)) {
		strcpy(work,basePath);
		if (OpenDir(curDir,work,id)) {
			char buffer[CROSS_LEN];
			char* result = 0;
			strcpy(buffer,dirPath);
			ReadDir(id,result);
			strcpy(dirPath,buffer);
			if (dirSearch[id]) {
				dirSearch[id]->id = MAX_OPENDIRS;
				dirSearch[id] = 0;
			}
		};
	};

	do {
//		bool errorcheck = false;
		pos = strchr(start,CROSS_FILESPLIT);
		if (pos) { safe_strncpy(dir,start,pos-start+1); /*errorcheck = true;*/ }
		else	 { strcpy(dir,start); };
 
		// Path found
		Bits nextDir = GetLongName(curDir,dir);
		strcat(expandedPath,dir);

		// Error check
/*		if ((errorcheck) && (nextDir<0)) {
			LOG_DEBUG("DIR: Error: %s not found.",expandedPath);
		};
*/
		// Follow Directory
		if ((nextDir>=0) && curDir->fileList[nextDir]->isDir) {
			curDir = curDir->fileList[nextDir];
			strcpy (curDir->orgname,dir);
			if (!IsCachedIn(curDir)) {
				if (OpenDir(curDir,expandedPath,id)) {
					char buffer[CROSS_LEN];
					char* result = 0;
					strcpy(buffer,dirPath);
					ReadDir(id,result);
					strcpy(dirPath,buffer);
					if (dirSearch[id]) {
						dirSearch[id]->id = MAX_OPENDIRS;
						dirSearch[id] = 0;
					}
				};
			}
		};
		if (pos) {
			strcat(expandedPath,split);
			start = pos+1;
		}
	} while (pos);

	// Save last result for faster access next time
	strcpy(save_path,path);
	strcpy(save_expanded,expandedPath);
	save_dir = curDir;

	return curDir;
}
示例#7
0
      bool Texture::CacheIn()
      {
         fbyte *im;
         if (Bad())
         {
            return false;
         }
         if (!IsCachedIn())
         {
            ILuint image_id;
            ILint format;
            
            ilGenImages(1, &image_id);
            ilBindImage(image_id);

            if(!ilLoadImage((ILstring)m_impl->m_filename.c_str()))
            {
               ilDeleteImages(1, &image_id);
               m_impl->m_bad = true;
               cerr << "Failed to load texture file " << m_impl->m_filename << endl;
               return false;
            }

            format=ilGetInteger(IL_DXTC_DATA_FORMAT);
            switch(format)
            {
            case IL_DXT_NO_COMP:
               break;
            case IL_DXT1:
               m_impl->m_dxt_format = TextureImpl::e_dxt1;
               break;
            case IL_DXT2:
               m_impl->m_dxt_format = TextureImpl::e_dxt2;
               break;
            case IL_DXT3:
               m_impl->m_dxt_format = TextureImpl::e_dxt3;
               break;
            case IL_DXT4:
               m_impl->m_dxt_format = TextureImpl::e_dxt4;
               break;
            case IL_DXT5:
               m_impl->m_dxt_format = TextureImpl::e_dxt5;
               break;
            }
            if(m_impl->m_dxt_format!=TextureImpl::e_dxt_none)
            {
               m_impl->m_width=ilGetInteger(IL_IMAGE_WIDTH);
               m_impl->m_height=ilGetInteger(IL_IMAGE_HEIGHT);
               m_impl->m_widthP2 = m_impl->m_width;
               m_impl->m_heightP2 = m_impl->m_height;
               m_impl->m_type = Texture::TYPE_RGBA;
               ILint s;
               char *data;
               s = ilGetDXTCData(NULL,0,format);
               m_impl->m_dxt_size = s;
               im = new fbyte[s];
               ilGetDXTCData(im,s,format);
               BindTextureToOpenGL(m_impl, im);
               delete [] im;

            }
            else
            {
               format=ilGetInteger(IL_IMAGE_FORMAT);

               if(format == IL_RGBA || format == IL_BGRA || format == IL_LUMINANCE_ALPHA || m_impl->m_autoGenAlphaMask)
               {
                  ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE);
                  m_impl->m_type = Texture::TYPE_RGBA;
               }
               else
               {
                  ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE);
                  m_impl->m_type = Texture::TYPE_RGB;
               }

               m_impl->m_width=ilGetInteger(IL_IMAGE_WIDTH);
               m_impl->m_height=ilGetInteger(IL_IMAGE_HEIGHT);
               m_impl->m_widthP2 = m_impl->m_width;
               m_impl->m_heightP2 = m_impl->m_height;

               if((m_impl->m_width  & (m_impl->m_width  - 1)) != 0 ||
                  (m_impl->m_height & (m_impl->m_height - 1)) != 0)
               {
                  for(fdword i=2;i<=c_max_texture_size_power;i++)
                  {
                     if((m_impl->m_width<<1) > (1UL<<i))
                     {
                        m_impl->m_widthP2 = (1UL<<i);
                     }
                     if((m_impl->m_height<<1) > (1UL<<i))
                     {
                        m_impl->m_heightP2 = (1UL<<i);
                     }
                  }

				  cerr << m_impl->m_filename << " has invalid texture size: " << 
                     m_impl->m_width << "x" << m_impl->m_height << 
                     "  resizing to " <<
                     m_impl->m_widthP2 << "x" << m_impl->m_heightP2 << endl;

                  cerr << "   Wasted space due to texture resize: " << 
                     (((m_impl->m_widthP2 * m_impl->m_heightP2) - 
                       (m_impl->m_width * m_impl->m_height)) / 
                       float(m_impl->m_widthP2 * m_impl->m_heightP2)) * 100.0f << 
                       "%" << endl;

                  iluImageParameter(ILU_PLACEMENT, ILU_UPPER_LEFT);
                  ilClearColour(1.0f,0.2f,0.8f,1.0f);

                  if(!iluEnlargeCanvas(m_impl->m_widthP2, m_impl->m_heightP2, ilGetInteger(IL_IMAGE_DEPTH)))
                  {
                     ilDeleteImages(1, &image_id);
                     m_impl->m_bad = true;
                     cerr << "Resize of texture canvas failed" << endl;
                     return false;
                  }
               }

               im = ilGetData();
               if(m_impl->m_autoGenAlphaMask)
               {
                  Colour c;
                  fdword i,j;
                  for(j=0;j<m_impl->m_height;j++)
                  {
                     for(i=0;i<m_impl->m_width;i++)
                     {
                        c.FromInteger(((fdword *)im)[j*m_impl->m_widthP2+i],
                           c_rgba_red_mask, c_rgba_red_shift,
                           c_rgba_green_mask, c_rgba_green_shift,
                           c_rgba_blue_mask, c_rgba_blue_shift,
                           c_rgba_alpha_mask, c_rgba_alpha_shift);
                        GF1::Colour cd(c - m_impl->m_autoGenAlphaMaskColour);
                        if(m_impl->m_autoGenAlphaMaskFade && m_impl->m_autoGenAlphaMaskTolerance > 0)
                        {
                           c.a = cd.Length() / m_impl->m_autoGenAlphaMaskTolerance;
                        }
                        else
                        {
                           if(cd.LengthSquared() <= m_impl->m_autoGenAlphaMaskTolerance * m_impl->m_autoGenAlphaMaskTolerance)
                           {
                              c.a=0.0f;
                           }
                           else
                           {
                              c.a=1.0f;
                           }
                        }
                        ((fdword *)im)[j*m_impl->m_widthP2+i] = c.ToInteger(255,0,255,8,255,16,255,24);
                     }
                  }
               }
               BindTextureToOpenGL(m_impl, im);
            }
            ilDeleteImages(1, &image_id);
         }
         return true;
      }