Advertisement
Guest User

Untitled

a guest
Dec 31st, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 KB | None | 0 0
  1. TextureInfo AssetStorage::Add(const Texture& texture, const std::string&strFilename){
  2.     if (INVALID_UNSIGNED != GetTextureInfo(strFilename).uTextureId){
  3.         std::ostringstream strOut;
  4.         strOut << __FUNCTION__ << " can not store " << strFilename << " multiple times";
  5.         throw ExceptionHandler(strOut);
  6.     }
  7.  
  8.     TextureInfo textureInfo;
  9.     textureInfo.hasTransparency = texture.hasAlphaChannel;
  10.     textureInfo.size = glm::uvec2(texture.uWidth, texture.uHeight);
  11.  
  12.     glGenTextures(1, &textureInfo.uTextureId);
  13.     glBindTexture(GL_TEXTURE_2D, textureInfo.uTextureId);
  14.  
  15.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (texture.wrapRepeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
  16.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (texture.wrapRepeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
  17.    
  18.     const glm::uvec2& openglVersion = s_pSettings->GetOpenGLVersion();
  19.  
  20.     if (texture.generateMipMap){
  21.         switch (texture.filterQuality){
  22.             case TextureInfo::FILTER_NONE:{
  23.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  24.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
  25.                 break;
  26.             }
  27.             case TextureInfo::FILTER_GOOD:{
  28.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  29.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
  30.                 break;
  31.             }
  32.             case TextureInfo::FILTER_BEST:{
  33.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  34.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  35.                 break;
  36.             }
  37.             default:{
  38.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  39.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  40.                 break;
  41.             }
  42.         }
  43.  
  44.         if (openglVersion.x < 3){
  45.             static const unsigned int GL_GENERATE_MIPMAP = 0x8191;
  46.             glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
  47.         }
  48.     } else {
  49.         switch (texture.filterQuality){
  50.             case TextureInfo::FILTER_NONE:
  51.             case TextureInfo::FILTER_GOOD:{
  52.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  53.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  54.                 break;
  55.             }
  56.             default:{
  57.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  58.                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  59.             }
  60.         }
  61.     }
  62.  
  63.     glPixelStorei(GL_UNPACK_ALIGNMENT, texture.hasAlphaChannel ? 4 : 1);
  64.     glTexImage2D(GL_TEXTURE_2D,
  65.         0,
  66.         (texture.hasAlphaChannel?GL_RGBA8:GL_RGB8),
  67.         texture.uWidth,
  68.         texture.uHeight,
  69.         0,
  70.         (texture.hasAlphaChannel?GL_RGBA:GL_RGB),
  71.         GL_UNSIGNED_BYTE,
  72.         &texture.vPixelData[0]);
  73.  
  74.     if (texture.generateMipMap)
  75.         glGenerateMipmap(GL_TEXTURE_2D);
  76.  
  77.     BlockThread blockThread(s_criticalSection);
  78.     _textureInfos.insert(MapTextureInfos::value_type(strFilename, textureInfo));
  79.  
  80.     if (s_pSettings->IsDebugLoggingEnabled(Settings::DEBUG_MEMORY))
  81.         Logger::log(std::string("Created ") + strFilename + std::string("\n"));
  82.  
  83.     return textureInfo;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement