GLuint TextureController::_CreateBlankGLTexture(int32 width, int32 height) { GLuint tex_id; glGenTextures(1, &tex_id); if (VideoManager->CheckGLError()) { IF_PRINT_WARNING(VIDEO_DEBUG) << "an OpenGL error was detected: " << VideoManager->CreateGLErrorString() << endl; _DeleteTexture(tex_id); return INVALID_TEXTURE_ID; } _BindTexture(tex_id); // NOTE: this call makes another call to VideoManager->CheckGLError() // If the binding was successful, initialize the texture with glTexImage2D() if (VideoManager->GetGLError() == GL_NO_ERROR) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } if (VideoManager->CheckGLError()) { PRINT_ERROR << "failed to create new texture. OpenGL reported the following error: " << VideoManager->CreateGLErrorString() << endl; _DeleteTexture(tex_id); return INVALID_TEXTURE_ID; } // Set linear texture interpolation only if we are at a non-natural resolution GLenum filtering_type = VideoManager->_ShouldSmooth() ? GL_LINEAR : GL_NEAREST; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering_type); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering_type); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); return tex_id; }
GLuint TextureController::_CreateBlankGLTexture(int32_t width, int32_t height) { GLuint tex_id; glGenTextures(1, &tex_id); if(VideoManager->CheckGLError()) { IF_PRINT_WARNING(VIDEO_DEBUG) << "an OpenGL error was detected: " << VideoManager->CreateGLErrorString() << std::endl; _DeleteTexture(tex_id); return INVALID_TEXTURE_ID; } _BindTexture(tex_id); // If the binding was successful, initialize the texture with glTexImage2D() if(VideoManager->GetGLError() == GL_NO_ERROR) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } if(VideoManager->CheckGLError()) { PRINT_ERROR << "failed to create new texture. OpenGL reported the following error: " << VideoManager->CreateGLErrorString() << std::endl; _DeleteTexture(tex_id); return INVALID_TEXTURE_ID; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); return tex_id; }
bool TextureController::UnloadTextures() { bool success = true; // Save temporary textures to disk, in other words textures which were not // loaded from a file. This way when we recreate the GL context we will // be able to load them again. if (_SaveTempTextures() == false) { IF_PRINT_WARNING(VIDEO_DEBUG) << "call to _SaveTempTextures() failed" << endl; success = false; } // Unload all texture sheets vector<TexSheet*>::iterator i = _tex_sheets.begin(); while (i != _tex_sheets.end()) { if (*i != NULL) { if ((*i)->Unload() == false) { IF_PRINT_WARNING(VIDEO_DEBUG) << "a TextureSheet::Unload() call failed" << endl; success = false; } } else { IF_PRINT_WARNING(VIDEO_DEBUG) << "a NULL TextureSheet was found in the _tex_sheets container" << endl; success = false; } i++; } // Delete the light overlay texture if (VideoManager->_light_overlay != INVALID_TEXTURE_ID) { _DeleteTexture(VideoManager->_light_overlay); VideoManager->_light_overlay = INVALID_TEXTURE_ID; } // Clear all font caches map<string, FontProperties*>::iterator j = TextManager->_font_map.begin(); while (j != TextManager->_font_map.end()) { FontProperties *fp = j->second; if (fp->glyph_cache) { for (map<uint16, FontGlyph*>::iterator k = fp->glyph_cache->begin(); k != fp->glyph_cache->end(); k++) { _DeleteTexture((*k).second->texture); delete (*k).second; } fp->glyph_cache->clear(); } j++; } return success; } // bool TextureController::UnloadTextures()
r3dTexture* r3dRenderLayer::LoadTexture( const char* TexFile, D3DFORMAT TexFormat, bool bCheckFormat, int DownScale /*= 1*/, int DownScaleMinDim /*= 1*/, int SystemMem /*= 0*/, int gameResourcePool /*= 0*/ ) { if(!bInited) return NULL; r3dCSHolderWithDeviceQueue csholder( g_ResourceCritSection ) ; (void)csholder ; assert(TexFile); char szFileName[ MAX_PATH ]; FixFileName( TexFile, szFileName ); r3dTexture* Tex; // goes thru all textures and see if we already have with that name for(Tex = FirstTexture; Tex; Tex = Tex->pNext) { if((!bCheckFormat || (Tex->GetD3DFormat() == TexFormat) ) && (Tex->IsLoaded()) && (strcmp(Tex->getFileLoc().FileName, szFileName ) == NULL)) { Tex->Instances++; return Tex; } } Tex = _CreateTexture(); if( gameResourcePool == PlayerTexMem ) { Tex->MarkPlayerTexture() ; } if(!Tex->Load(szFileName, TexFormat, DownScale, DownScaleMinDim, SystemMem )) { _DeleteTexture(Tex); return NULL; } //r3dOutToLog("TEXTURE: LoadTexture %s complete\n", szFileName); // insert to LList. _InsertTexture(&FirstTexture, Tex); Tex->Instances++; return Tex; }
void r3dRenderLayer::DeleteTexture(r3dTexture *Tex, int bForceDelete) { if(!Tex) return; r3dCSHolderWithDeviceQueue csholder( g_ResourceCritSection ) ; (void)csholder ; // if(!Tex->IsValid()) // return; // if (!Tex->Tex) return; Tex->Instances--; if (bForceDelete) Tex->Instances = 0; if(Tex->Instances > 0) return; if (!bForceDelete) { if (Tex->bPersistent) { Tex->Instances = 1; return; } } if(Tex->pNext) Tex->pNext->pPrev = Tex->pPrev; if(Tex->pPrev) Tex->pPrev->pNext = Tex->pNext; if(Tex == FirstTexture) FirstTexture = Tex->pNext; _DeleteTexture(Tex); }