Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TextureInfo AssetStorage::Add(const Texture& texture, const std::string&strFilename){
- if (INVALID_UNSIGNED != GetTextureInfo(strFilename).uTextureId){
- std::ostringstream strOut;
- strOut << __FUNCTION__ << " can not store " << strFilename << " multiple times";
- throw ExceptionHandler(strOut);
- }
- TextureInfo textureInfo;
- textureInfo.hasTransparency = texture.hasAlphaChannel;
- textureInfo.size = glm::uvec2(texture.uWidth, texture.uHeight);
- glGenTextures(1, &textureInfo.uTextureId);
- glBindTexture(GL_TEXTURE_2D, textureInfo.uTextureId);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (texture.wrapRepeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (texture.wrapRepeat ? GL_REPEAT : GL_CLAMP_TO_EDGE));
- const glm::uvec2& openglVersion = s_pSettings->GetOpenGLVersion();
- if (texture.generateMipMap){
- switch (texture.filterQuality){
- case TextureInfo::FILTER_NONE:{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
- break;
- }
- case TextureInfo::FILTER_GOOD:{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
- break;
- }
- case TextureInfo::FILTER_BEST:{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- break;
- }
- default:{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- break;
- }
- }
- if (openglVersion.x < 3){
- static const unsigned int GL_GENERATE_MIPMAP = 0x8191;
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
- }
- } else {
- switch (texture.filterQuality){
- case TextureInfo::FILTER_NONE:
- case TextureInfo::FILTER_GOOD:{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- break;
- }
- default:{
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- }
- }
- }
- glPixelStorei(GL_UNPACK_ALIGNMENT, texture.hasAlphaChannel ? 4 : 1);
- glTexImage2D(GL_TEXTURE_2D,
- 0,
- (texture.hasAlphaChannel?GL_RGBA8:GL_RGB8),
- texture.uWidth,
- texture.uHeight,
- 0,
- (texture.hasAlphaChannel?GL_RGBA:GL_RGB),
- GL_UNSIGNED_BYTE,
- &texture.vPixelData[0]);
- if (texture.generateMipMap)
- glGenerateMipmap(GL_TEXTURE_2D);
- BlockThread blockThread(s_criticalSection);
- _textureInfos.insert(MapTextureInfos::value_type(strFilename, textureInfo));
- if (s_pSettings->IsDebugLoggingEnabled(Settings::DEBUG_MEMORY))
- Logger::log(std::string("Created ") + strFilename + std::string("\n"));
- return textureInfo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement