Texture* ResourceSystem::FindTexture(const char* file) { Texture* texture = NULL; void* it = _textures.Get(file); if( it != NULL ) { texture = (Texture*)it; return texture; } Image image; lfStr fullpath = _searchDir + file; for (int i = 0; i < TexPluginCount; ++i) { if (fullpath.Find(loaderPlugin[i].name) == -1) continue; if( !loaderPlugin[i].pFunc(fullpath.c_str(), &image) ) { Sys_Printf( "load image %s failed\n", fullpath.c_str() ); return FindTexture(DEFAULT_TEXTURE_PATH); } texture = new Texture(); texture->Init(&image); _textures.Put(file, texture); return texture; } Sys_Printf( "load image %s failed\n", fullpath.c_str() ); return FindTexture(DEFAULT_TEXTURE_PATH); };
void CAssParser::FindTextures( S3DModel* model, const aiScene* scene, const LuaTable& modelTable, const std::string& modelPath, const std::string& modelName ) { // Assign textures // The S3O texture handler uses two textures. // The first contains diffuse color (RGB) and teamcolor (A) // The second contains glow (R), reflectivity (G) and 1-bit Alpha (A). // 1. try to find by name (lowest prioriy) if (model->tex1.empty()) model->tex1 = FindTextureByRegex("unittextures/", modelName); // high priority if (model->tex1.empty()) model->tex1 = FindTextureByRegex("unittextures/", modelName + "1"); if (model->tex2.empty()) model->tex2 = FindTextureByRegex("unittextures/", modelName + "2"); if (model->tex1.empty()) model->tex1 = FindTextureByRegex(modelPath, "tex1"); if (model->tex2.empty()) model->tex2 = FindTextureByRegex(modelPath, "tex2"); if (model->tex1.empty()) model->tex1 = FindTextureByRegex(modelPath, "diffuse"); if (model->tex2.empty()) model->tex2 = FindTextureByRegex(modelPath, "glow"); // low priority // 2. gather model-defined textures of first material (medium priority) if (scene->mNumMaterials > 0) { const unsigned int texTypes[] = { aiTextureType_SPECULAR, aiTextureType_UNKNOWN, aiTextureType_DIFFUSE, /* // TODO: support these too (we need to allow constructing tex1 & tex2 from several sources) aiTextureType_EMISSIVE, aiTextureType_HEIGHT, aiTextureType_NORMALS, aiTextureType_SHININESS, aiTextureType_OPACITY, */ }; for (unsigned int n = 0; n < (sizeof(texTypes) / sizeof(texTypes[0])); n++) { aiString textureFile; if (scene->mMaterials[0]->Get(AI_MATKEY_TEXTURE(texTypes[n], 0), textureFile) != aiReturn_SUCCESS) continue; assert(textureFile.length > 0); model->tex1 = FindTexture(textureFile.data, modelPath, model->tex1); } } // 3. try to load from metafile (highest priority) model->tex1 = FindTexture(modelTable.GetString("tex1", ""), modelPath, model->tex1); model->tex2 = FindTexture(modelTable.GetString("tex2", ""), modelPath, model->tex2); model->invertTexYAxis = modelTable.GetBool("fliptextures", true); // Flip texture upside down model->invertTexAlpha = modelTable.GetBool("invertteamcolor", true); // Reverse teamcolor levels }
void MGUI_Button::SetImage(char *n, char *o, char *c) { iTga[0] = FindTexture(n); iTga[1] = FindTexture(o); iTga[2] = FindTexture(c); //g_pSurface->DrawSetTextureFile(iTga[0],n,true,true); //g_pSurface->DrawSetTextureFile(iTga[1],o,true,true); //g_pSurface->DrawSetTextureFile(iTga[2],c,true,true); }
////////////////////// IMAGE void MGUI_Image::SetTexture(char *pName) { //m_iTexture = g_pSurface->CreateNewTextureID(); m_iTexture = FindTexture(pName); //return m_iTexture; }
TexturePtr D3D9VideoBufferManager::LoadCubeTexture(const TString128 & name, const TString128 & source) { TexturePtr t = FindTexture(name); if (t != NULL) return t; D3D9CubeTexture * p = new D3D9CubeTexture(mD3D9Device); p->mName = name; p->mWidth = 0; p->mHeight = 0; p->mDepth = 1; p->mMipLevels = 0; p->mUsage = USAGE_STATIC; p->mFormat = FMT_UNKNOWN; p->mType = TEXTYPE_CUBE; p->mSourceName = source; mCubeTextures.Insert(name, p); p->Load(); return p; }
void gstTextureManager::readThreadFunc() { int idx = 0; int qsz = 0; uchar* next_buffer = NULL; uint64 addr; while (true) { addr = readQueue.pop(); if (addr == InvalidTileAddrHash) { break; } khLockGuard guard(readWorkerMutex); if (addr && !memory_cache_->fetch(addr)) { gstTextureGuard tex = FindTexture(SRCFROMADDR(addr)); assert(tex); if (next_buffer == NULL) { next_buffer = new uchar[tex->cellSize()]; notify(NFY_VERBOSE, "(%d) New tex buffer [%d] sz=%d c:%d r:%d l:%d s:%d", qsz, idx, tex->cellSize(), COLFROMADDR(addr), ROWFROMADDR(addr), LEVFROMADDR(addr), SRCFROMADDR(addr)); ++idx; } if (tex->Load(addr, next_buffer) == true) next_buffer = memory_cache_->insert(next_buffer, addr); } } }
//----------------------------------------------------------------------------- CPUTTexture *CPUTAssetLibrary::GetTexture(const cString &name, bool nameIsFullPathAndFilename, bool loadAsSRGB ) { cString finalName; if( name.at(0) == '%' ) { #ifndef CPUT_OS_WINDOWS finalName = mSystemDirectoryName + _L("/Texture/") + name.substr(1); // TODO: Instead of having the Shader/ directory hardcoded here it could be set like the normal material directory. But then there would need to be a bunch new variables like SetSystemMaterialDirectory #else finalName = mSystemDirectoryName + _L("\\Texture\\") + name.substr(1); // TODO: Instead of having the Shader/ directory hardcoded here it could be set like the normal material directory. But then there would need to be a bunch new variables like SetSystemMaterialDirectory #endif CPUTFileSystem::ResolveAbsolutePathAndFilename(finalName, &finalName); } else if( name.at(0) == '$' ) { finalName = name; } else { CPUTFileSystem::ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mTextureDirectoryName + name), &finalName); } // If we already have one by this name, then return it CPUTTexture *pTexture = FindTexture(finalName, true); if(NULL==pTexture) { return CPUTTexture::CreateTexture( name, finalName, loadAsSRGB); } pTexture->AddRef(); return pTexture; }
void CAssParser::FindTextures( S3DModel* model, const aiScene* scene, const LuaTable& modelTable, const std::string& modelPath, const std::string& modelName ) { // 1. try to find by name (lowest priority) model->texs[0] = FindTextureByRegex("unittextures/", modelName); if (model->texs[0].empty()) model->texs[0] = FindTextureByRegex("unittextures/", modelName + "1"); if (model->texs[1].empty()) model->texs[1] = FindTextureByRegex("unittextures/", modelName + "2"); if (model->texs[0].empty()) model->texs[0] = FindTextureByRegex(modelPath, "tex1"); if (model->texs[1].empty()) model->texs[1] = FindTextureByRegex(modelPath, "tex2"); if (model->texs[0].empty()) model->texs[0] = FindTextureByRegex(modelPath, "diffuse"); if (model->texs[1].empty()) model->texs[1] = FindTextureByRegex(modelPath, "glow"); // lowest-priority name // 2. gather model-defined textures of first material (medium priority) if (scene->mNumMaterials > 0) { constexpr unsigned int texTypes[] = { aiTextureType_SPECULAR, aiTextureType_UNKNOWN, aiTextureType_DIFFUSE, /* // TODO: support these too (we need to allow constructing tex1 & tex2 from several sources) aiTextureType_EMISSIVE, aiTextureType_HEIGHT, aiTextureType_NORMALS, aiTextureType_SHININESS, aiTextureType_OPACITY, */ }; for (unsigned int texType: texTypes) { aiString textureFile; if (scene->mMaterials[0]->Get(AI_MATKEY_TEXTURE(texType, 0), textureFile) != aiReturn_SUCCESS) continue; assert(textureFile.length > 0); model->texs[0] = FindTexture(textureFile.data, modelPath, model->texs[0]); } } // 3. try to load from metafile (highest priority) model->texs[0] = FindTexture(modelTable.GetString("tex1", ""), modelPath, model->texs[0]); model->texs[1] = FindTexture(modelTable.GetString("tex2", ""), modelPath, model->texs[1]); }
void MGLTexture::AddTexture(GLuint tex, std::string name, MGLenum type) { if (FindTexture(tex)) // texture already exists return; m_textures->push_back(tex); m_names->push_back(name); m_types->push_back(type); }
// Find the best texture tile to use for requested address // // this is a callback, triggered by the tileExistanceCache // when the requested tile is no longer in the cache bool gstTextureManager::findTile(TileExistance* &reuse, const uint64& addr) { if (!reuse) reuse = new TileExistance; gstTextureGuard tex = FindTexture(SRCFROMADDR(addr)); assert(tex); tex->Find(reuse, addr); return true; }
static std::string FindTextureByRegex(const std::string& regex_path, const std::string& regex) { //FIXME instead of ".*" only check imagetypes! const std::vector<std::string>& files = CFileHandler::FindFiles(regex_path, regex + ".*"); if (!files.empty()) { return FindTexture(FileSystem::GetFilename(files[0]), "", ""); } return ""; }
RenderTargetPtr D3D9VideoBufferManager::CreateRenderTarget(const TString128 & sName, int iWidth, int iHeight, FORMAT RenderTargetFormat, MULTI_SAMPLE MSAA) { d_assert(FindTexture(sName).IsNull()); if (!RenderSystem::Instance()->CheckRenderTargetFormat(RenderTargetFormat)) { EXCEPTION("Your device can't support texture format '" + D3D9Mapping::GetFormatString(RenderTargetFormat) + "' for render target."); } if (!RenderSystem::Instance()->CheckMSAAFormat(RenderTargetFormat, MSAA)) { EXCEPTION("Your device can't support render target format '" + D3D9Mapping::GetFormatString(RenderTargetFormat) + "' for msaa '" + D3D9Mapping::GetMSAAString(MSAA) + "'."); } int rWidth = iWidth, rHeight = iHeight; if (rWidth == -1 || rHeight == -1) { rWidth = Engine::Instance()->GetDeviceProperty()->Width; rHeight = Engine::Instance()->GetDeviceProperty()->Height; } HRESULT hr = D3D_OK; D3DFORMAT D3DFormat = D3D9Mapping::GetD3DFormat(RenderTargetFormat); D3DMULTISAMPLE_TYPE MultiSampleType = D3D9Mapping::GetD3DMultiSampleType(MSAA); DWORD MultiSampleQuality = 0; IDirect3DTexture9 * pD3D9Texture = NULL; IDirect3DSurface9 * pD3D9RenderTarget = NULL; hr = mD3D9Device->CreateRenderTarget(rWidth, rHeight, D3DFormat, MultiSampleType, MultiSampleQuality, FALSE, &pD3D9RenderTarget, NULL); D3DErrorExceptionFunction(CreateRenderTarget, hr); D3D9RenderTarget * pTexture = new D3D9RenderTarget(mD3D9Device); pTexture->mName = sName; pTexture->mRenderTarget = pD3D9RenderTarget; pTexture->mWidth = iWidth; pTexture->mHeight = iHeight; pTexture->mFormat = RenderTargetFormat; pTexture->mMSAA= MSAA; mRenderTargets.Insert(pTexture->GetName(), pTexture);; return RenderTargetPtr(pTexture); }
Texture* ResourceSystem::AddText( const char* text ) { if( Sys_DrawText(text, &textContent)) { // get the texture pixels, width, height Texture* texture = new Texture; texture->Init(textContent.w, textContent.h, textContent.pData); return texture; } else { Sys_Printf("sys_drawtext error %s\n", text); return FindTexture(DEFAULT_TEXTURE_PATH); } }
hdTexture* hdTextureManager::ReloadTexture(hdTexture *texture, texturetype_t type) { // There's no point resampling if nothing is going to change. if (texture->type != type) { char fname[kMaxTexturePathSize]; snprintf(fname, kMaxTexturePathSize, "%s", texture->name); DestroyTexture(texture); return FindTexture(fname, type); } else { return texture; } }
ITextureInternal *CTextureManager::FindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName ) { ITextureInternal *pTexture = FindTexture( pTextureName ); if ( !pTexture ) { pTexture = LoadTexture( pTextureName, pTextureGroupName ); if ( pTexture ) { // insert into the dictionary using the processed texture name m_TextureList.Insert( pTexture->GetName(), pTexture ); } } return pTexture; }
void EERIE_MESH_TWEAK_Skin(EERIE_3DOBJ * obj, char * s1, char * s2) { if (obj == NULL) return; if (s1 == NULL) return; if (s2 == NULL) return; char skintochange[512]; char skinname[512]; sprintf(skintochange, "Graph\\Obj3D\\Textures\\%s.bmp", s1); MakeUpcase(skintochange); TextureContainer * tex = D3DTextr_CreateTextureFromFile(skintochange); if (obj->originaltextures == NULL) { obj->originaltextures = (char *)malloc(256 * obj->nbmaps); memset(obj->originaltextures, 0, 256 * obj->nbmaps); for (long i = 0; i < obj->nbmaps; i++) { if (obj->texturecontainer[i]) strcpy(obj->originaltextures + 256 * i, obj->texturecontainer[i]->m_texName); } } if ((tex != NULL) && (obj->originaltextures != NULL)) { for (long i = 0; i < obj->nbmaps; i++) { if ((strstr(obj->originaltextures + 256 * i, skintochange))) { strcpy(skintochange, obj->texturecontainer[i]->m_texName); break; } } tex->Restore(GDevice); TextureContainer * tex2 = FindTexture(skintochange); if (tex2) for (long i = 0; i < obj->nbmaps; i++) { if (obj->texturecontainer[i] == tex2) obj->texturecontainer[i] = tex; } } }
TexturePtr D3D9VideoBufferManager::CreateVolumeTexture(const TString128 & sName, int iWidth, int iHeight, int iDepth, int iMipLevel, FORMAT Format, USAGE Usage, bool bRenderTarget) { d_assert(FindTexture(sName).IsNull() && !bRenderTarget); if (!RenderSystem::Instance()->CheckTextureFormat(Format, Usage)) { EXCEPTION("Your device can't support texture format '" + D3D9Mapping::GetFormatString(Format) + "' for usage '" + D3D9Mapping::GetUsageString(Usage)); } HRESULT hr = D3D_OK; DWORD D3DUsage = D3D9Mapping::GetD3DUsage(Usage); D3DPOOL D3DPool = D3D9Mapping::GetD3DPool(Usage); D3DFORMAT D3DFormat = D3D9Mapping::GetD3DFormat(Format); IDirect3DVolumeTexture9 * pD3D9VolumeTexture = NULL; hr = mD3D9Device->CreateVolumeTexture(iWidth, iHeight, iDepth, iMipLevel, D3DUsage, D3DFormat, D3DPool, &pD3D9VolumeTexture, NULL); if (FAILED(hr)) { EXCEPTION("D3D Error: CreateVolumeTexture failed, desc: " + D3D9Mapping::GetD3DErrorDescription(hr)); } D3D9VolumeTexture * pTexture = new D3D9VolumeTexture(mD3D9Device); pTexture->mName = sName; pTexture->mD3D9VolumeTexture = pD3D9VolumeTexture; pTexture->mWidth = iWidth; pTexture->mHeight = iHeight; pTexture->mDepth = iDepth; pTexture->mUsage = Usage; pTexture->mFormat = Format; pTexture->mType = TEXTYPE_3D; pTexture->mMipLevels = iMipLevel; mVolumeTextures.Insert(pTexture->GetName(), pTexture); return TexturePtr(pTexture); }
TextureDefinition* TextureManager::CreateTexture(const char* texturefilename, int minfilter, int magfilter, int wraps, int wrapt) { MyAssert( texturefilename ); LOGInfo( LOGTag, "CreateTexture - %s\n", texturefilename ); // find the texture if it already exists: TextureDefinition* pTextureDef = FindTexture( texturefilename ); if( pTextureDef != 0 ) { pTextureDef->AddRef(); return pTextureDef; } // Create a new texture and add it to m_TexturesStillLoading pTextureDef = MyNew TextureDefinition(); pTextureDef->m_ManagedByTextureManager = true; strcpy_s( pTextureDef->m_Filename, MAX_PATH, texturefilename ); pTextureDef->m_MinFilter = minfilter; pTextureDef->m_MagFilter = magfilter; pTextureDef->m_WrapS = wraps; pTextureDef->m_WrapT = wrapt; m_TexturesStillLoading.AddTail( pTextureDef ); // if the file load hasn't started... start the file load. MyAssert( pTextureDef->m_pFile == 0 ); #if 0 //MYFW_ANDROID //LOGInfo( LOGTag, "Loading Texture: pTextureDef->m_pFile %d\n", pTextureDef->m_pFile ); if( pTextureDef->m_pFile == 0 ) { pTextureDef->m_pFile = RequestTexture( pTextureDef->m_Filename, pTextureDef ); //textureloaded = true; } #else if( pTextureDef->m_pFile == 0 ) { //LOGInfo( LOGTag, "Loading Texture: RequestFile\n" ); pTextureDef->m_pFile = RequestFile( pTextureDef->m_Filename ); //LOGInfo( LOGTag, "Loading Texture: ~RequestFile\n" ); } #endif return pTextureDef; }
//----------------------------------------------------------------------------- // Creates a texture that's a render target //----------------------------------------------------------------------------- ITextureInternal *CTextureManager::CreateRenderTargetTexture( const char *pRTName, // NULL for auto-generated name int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, RenderTargetType_t type, unsigned int textureFlags, unsigned int renderTargetFlags ) { MEM_ALLOC_CREDIT_( __FILE__ ": Render target" ); ITextureInternal *pTexture; if ( pRTName ) { // caller is re-initing or changing pTexture = FindTexture( pRTName ); if ( pTexture ) { // Changing the underlying render target, but leaving the pointer and refcount // alone fixes callers that have exisiting references to this object. ITextureInternal::ChangeRenderTarget( pTexture, w, h, sizeMode, fmt, type, textureFlags, renderTargetFlags ); // download if ready pTexture->Download(); return pTexture; } } pTexture = ITextureInternal::CreateRenderTarget( pRTName, w, h, sizeMode, fmt, type, textureFlags, renderTargetFlags ); if ( !pTexture ) return NULL; // Add the render target to the list of textures // that way it'll get cleaned up correctly in case of a task switch m_TextureList.Insert( pTexture->GetName(), pTexture ); // NOTE: This will download the texture only if the shader api is ready pTexture->Download(); return pTexture; }
ITextureInternal *CTextureManager::FindTexture( const char *pTextureName ) { if ( !pTextureName || pTextureName[0] == 0 ) return NULL; char szCleanName[MAX_PATH]; NormalizeTextureName( pTextureName, szCleanName, sizeof( szCleanName ) ); int i = m_TextureList.Find( szCleanName ); if ( i != m_TextureList.InvalidIndex() ) { return m_TextureList[i]; } i = m_TextureAliases.Find( szCleanName ); if ( i != m_TextureAliases.InvalidIndex() ) { return FindTexture( m_TextureAliases[i] ); } // Special handling: lightmaps if ( char const *szLightMapNum = StringAfterPrefix( szCleanName, "[lightmap" ) ) { int iLightMapNum = atoi( szLightMapNum ); extern CMaterialSystem g_MaterialSystem; CMatLightmaps *plm = g_MaterialSystem.GetLightmaps(); if ( iLightMapNum >= 0 && iLightMapNum < plm->GetNumLightmapPages() ) { ShaderAPITextureHandle_t hTex = plm->GetLightmapPageTextureHandle( iLightMapNum ); if ( hTex != INVALID_SHADERAPI_TEXTURE_HANDLE ) { // Establish the lookup linking in the dictionary ITextureInternal *pTxInt = ITextureInternal::CreateReferenceTextureFromHandle( pTextureName, TEXTURE_GROUP_LIGHTMAP, hTex ); m_TextureList.Insert( pTextureName, pTxInt ); return pTxInt; } } } return NULL; }
//----------------------------------------------------------------------------- CPUTTexture *CPUTAssetLibrary::GetTexture(const cString &name, bool nameIsFullPathAndFilename, bool loadAsSRGB ) { cString finalName; if( name.at(0) == '$' ) { finalName = name; } else { // Resolve name to absolute path CPUTOSServices *pServices = CPUTOSServices::GetOSServices(); pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mTextureDirectoryName + name), &finalName); } // If we already have one by this name, then return it CPUTTexture *pTexture = FindTexture(finalName, true); if(NULL==pTexture) { return CPUTTexture::CreateTexture( name, finalName, loadAsSRGB); } pTexture->AddRef(); return pTexture; }
ITexture* TextureMgr_Impl::CreateTexture(const char* pszFileName, TEXTURE_SAMPLE_TYPE eSample /* = TST_POINT */) { ITexture* pTexture = FindTexture(pszFileName); if (pTexture) { pTexture->IncRef(); return pTexture; } Texture_Impl* pTexture_Impl = new Texture_Impl(pszFileName, eSample); if (!pTexture_Impl || !pTexture_Impl->IsOK()) { SAFE_DELETE(pTexture_Impl); return NULL; } // connect the destroy event pTexture_Impl->ConnectEvent(MI_TEXTURE_DESTROIED, this, (MSG_CALLBACK)&TextureMgr_Impl::OnTextureDestroied); // cache the texture m_TextureMap.insert(std::make_pair(pszFileName, pTexture_Impl)); return pTexture_Impl; }
TexturePtr D3D9VideoBufferManager::CreateTexture(const TString128 & sName, int iWidth, int iHeight, int iMipLevels, FORMAT Format, USAGE Usage, bool bRenderTarget) { int rWidth = iWidth, rHeight = iHeight; if (rWidth == -1 && rHeight == -1) { const DeviceProperty * dp = Engine::Instance()->GetDeviceProperty(); rWidth = dp->Width; rHeight = dp->Height; } d_assert (rWidth && rHeight); d_assert (FindTexture(sName).IsNull()); if (bRenderTarget && !RenderSystem::Instance()->CheckRenderTargetFormat(Format)) { EXCEPTION("Your device can't support texture format '" + D3D9Mapping::GetFormatString(Format) + "' for render target"); } else if (!bRenderTarget && !RenderSystem::Instance()->CheckTextureFormat(Format, Usage)) { EXCEPTION("Your device can't support texture format '" + D3D9Mapping::GetFormatString(Format) + "' for usage '" + D3D9Mapping::GetUsageString(Usage)); } HRESULT hr = D3D_OK; DWORD D3DUsage = D3D9Mapping::GetD3DUsage(Usage); D3DPOOL D3DPool = D3D9Mapping::GetD3DPool(Usage); D3DFORMAT D3DFormat = D3D9Mapping::GetD3DFormat(Format); IDirect3DTexture9 * pD3D9Texture = NULL; if (bRenderTarget) { D3DUsage = D3DUSAGE_RENDERTARGET; D3DPool = D3DPOOL_DEFAULT; iMipLevels = 1; Usage = USAGE_DYNAMIC; } if (iMipLevels == 0) { if (!RenderSystem::Instance()->CheckTextureFormat(Format, Usage, true)) { EXCEPTION("Your driver can't support texture format '" + D3D9Mapping::GetFormatString(Format) + "' for usage '" + D3D9Mapping::GetUsageString(Usage) + "' for auto generater mipmap"); } D3DUsage |= D3DUSAGE_AUTOGENMIPMAP; } hr = mD3D9Device->CreateTexture(rWidth, rHeight, iMipLevels, D3DUsage, D3DFormat, D3DPool, &pD3D9Texture, NULL); if (FAILED(hr)) { EXCEPTION("D3D Error: CreateTexture failed, desc: " + D3D9Mapping::GetD3DErrorDescription(hr)); } D3D9Texture * pTexture = new D3D9Texture(mD3D9Device); pTexture->mName = sName; pTexture->mD3D9Texture = pD3D9Texture; pTexture->mWidth = iWidth; pTexture->mHeight = iHeight; pTexture->mDepth = 1; pTexture->mUsage = Usage; pTexture->mFormat = Format; pTexture->mType = TEXTYPE_2D; pTexture->mMipLevels = iMipLevels; pTexture->mRenderTarget = bRenderTarget; mTextures.Insert(pTexture->GetName(), pTexture); return TexturePtr(pTexture); }
// this is a callback, triggered by the gstCache object // it will get called when the requested object is not in the cache bool gstTextureManager::bindTile(uint& reuseID, const uint64& addr) { // has this tile been loaded yet by our read thread? uchar* buf = memory_cache_->fetchAndPin(addr); // Nope, queue it up to be loaded if (buf == NULL) { if (requested_level_ == LEVFROMADDR(addr)) { readQueue.push(addr); render_unfinished_++; } return false; } // do we need a new texid, or just re-use an old one? uint texid = (reuseID == 0) ? texture_number_++ : reuseID; texture_cache_histogram_->add(texid - BASE_IMAGE_ID); glBindTexture(GL_TEXTURE_2D, texid); gstTextureGuard tex = FindTexture(SRCFROMADDR(addr)); assert(tex); const gstGLTexSpec& glspec = tex->glspec(); if (reuseID) { // base texture handled here (has no alpha) if (SRCFROMADDR(addr) == 0) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, glspec.Width(), glspec.Height(), glspec.Format(), glspec.Type(), static_cast<GLvoid*>(buf)); // overlay RGB } else if (SUBFROMADDR(addr) == 0) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, glspec.Width(), glspec.Height(), glspec.Format(), glspec.Type(), static_cast<GLvoid*>(buf)); // overlay ALPHA } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, glspec.Width(), glspec.Height(), GL_ALPHA, glspec.Type(), static_cast<GLvoid*>(buf)); } } else { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (SRCFROMADDR(addr) == 0) { glTexImage2D(GL_TEXTURE_2D, 0, glspec.InternalFormat(), glspec.Width(), glspec.Height(), 0, glspec.Format(), glspec.Type(), static_cast<GLvoid*>(buf)); } else if (SUBFROMADDR(addr) == 0) { glTexImage2D(GL_TEXTURE_2D, 0, glspec.InternalFormat(), glspec.Width(), glspec.Height(), 0, glspec.Format(), glspec.Type(), static_cast<GLvoid*>(buf)); } else { // XXX // XXX figure out how to get another glspec for alpha // XXX glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, glspec.Width(), glspec.Height(), 0, GL_ALPHA, glspec.Type(), static_cast<GLvoid*>(buf)); } } // unpin once texture is paged since will be requested from // cache again when will be paged again if (!memory_cache_->unpin(addr)) notify(NFY_WARN, "unpin of memoryCache entry for %llu failed", static_cast<long long unsigned>(addr)); reuseID = texid; return true; }
int FindTexdef( char *ident, fp_t rotate, vec2d_t scale, vec2d_t shift, int plane ) { int i; int type; wplane_t *pl; wtexdef_t td; vec2d_t axis[2] = { {1, 0}, {0, 1} }; fp_t angle; fp_t angle_sin, angle_cos; memset( &td, 0, sizeof( wtexdef_t ) ); td.rotate = rotate; Vec2dCopy( td.scale, scale ); // // find projection // pl = &p_planes[plane]; type = pl->type & PLANE_AXIS_MASK; if ( type <= PLANE_Z ) td.flags = type; else if ( type >= PLANE_ANYX ) td.flags = type - PLANE_ANYX; // // rotate // if ( rotate != 0.0 || scale[0] != 1.0 || scale[1] != 1.0 ) { angle = rotate / 180*M_PI; angle_sin = sin( angle ); angle_cos = cos( angle ); for( i = 0; i < 2; i++ ) { td.vec[i][0] = angle_cos*axis[i][0] - angle_sin*axis[i][1]; td.vec[i][1] = angle_sin*axis[i][0] + angle_cos*axis[i][1]; td.vec[i][0] /= scale[0]; td.vec[i][1] /= scale[1]; } td.flags |= PROJECT_VEC; } // // shift // if ( shift[0] != 0.0 || shift[1] != 0.0 ) { td.shift[0] = shift[0]; td.shift[1] = shift[1]; td.flags |= PROJECT_SHIFT; } else { td.shift[0] = 0.0; td.shift[1] = 0.0; } td.clsref_texture = p_wtextures[FindTexture( ident )].clsname; // // search texdef // for ( i = 0; i < p_wtexdefnum; i++ ) { if ( p_wtexdefs[i].clsref_texture == td.clsref_texture && p_wtexdefs[i].flags == td.flags && p_wtexdefs[i].vec[0][0] == td.vec[0][0] && p_wtexdefs[i].vec[0][1] == td.vec[0][1] && p_wtexdefs[i].vec[1][0] == td.vec[1][0] && p_wtexdefs[i].vec[1][1] == td.vec[1][1] && p_wtexdefs[i].shift[0] == td.shift[0] && p_wtexdefs[i].shift[1] == td.shift[1] ) { return i; } } if ( p_wtexdefnum == MAX_WTEXDEFS ) Error( "FindTexdef: reached MAX_TEXDEFS.\n" ); memcpy( &p_wtexdefs[p_wtexdefnum], &td, sizeof( wtexdef_t ) ); p_wtexdefs[p_wtexdefnum].clsname = HManagerGetFreeID(); p_wtexdefnum++; return p_wtexdefnum-1; }
void sXSILoader::ScanMatLib(sInt indent) { sChar chunk[XSISIZE]; sChar name[XSISIZE]; sChar texname[256]; sChar buffer[XSISIZE]; sChar pname[XSISIZE]; sChar tname[XSISIZE]; sChar tsup[2][XSISIZE]; sInt texena[2]; sXSIMaterial *mat; sXSITexture *tex; sInt i,max; sInt pcount,ccount; sInt ival; sF32 fval; ScanInt(); while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent,chunk,name); if(sCmpString(chunk,"SI_Material")==0) { mat = new sXSIMaterial; sCopyString(mat->Name,name,sizeof(mat->Name)); mat->Flags |= 0; Materials->Add(mat); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanInt(); ScanFloat(); ScanFloat(); ScanFloat(); sScanSpace(Scan); while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent+1,chunk,name); if(sCmpString(chunk,"SI_Texture2D")==0) { ScanString(texname,sizeof(texname)); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanInt(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanInt(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); ScanFloat(); EndChunk(); if(mat->Tex[0] == 0) { tex = FindTexture(texname); if(tex) mat->Tex[0] = tex; } } else { SkipChunk(); } sScanSpace(Scan); } EndChunk(); } else if(sCmpString(chunk,"XSI_Material")==0) { mat = new sXSIMaterial; sCopyString(mat->Name,name,sizeof(mat->Name)); mat->TFlags[0] = 0; mat->TFlags[1] = 0; mat->Flags |= 0; sDPrintF("%08x:<%s>\n",Scan,name); Materials->Add(mat); max = ScanInt(); for(i=0;i<max;i++) { ScanString(buffer,sizeof(buffer)); ScanString(buffer,sizeof(buffer)); } sScanSpace(Scan); tsup[0][0]=0; tsup[0][1]=0; texena[0] = 0; texena[1] = 0; while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent+1,chunk,name); if(sCmpString(chunk,"XSI_Shader")==0) { ScanString(buffer,sizeof(buffer)); ScanInt(); pcount = ScanInt(); ccount = ScanInt(); for(i=0;i<pcount;i++) { ScanString(pname,sizeof(pname)); ScanString(tname,sizeof(tname)); if(sCmpString(tname,"STRING")==0) { ScanString(buffer,sizeof(buffer)); if(sCmpString(pname,"tspace_id1")==0) sCopyString(tsup[0],buffer,sizeof(tsup[0])); if(sCmpString(pname,"tspace_id" )==0) sCopyString(tsup[0],buffer,sizeof(tsup[0])); if(sCmpString(pname,"tspace_id2")==0) sCopyString(tsup[1],buffer,sizeof(tsup[1])); } else if(sCmpString(tname,"FLOAT")==0) { fval = ScanFloat(); ival = sRange<sInt>(255*fval,255,0); if(sCmpString(pname,"Ambient.red")==0) mat->Ambient.r = ival; if(sCmpString(pname,"Ambient.green")==0) mat->Ambient.g = ival; if(sCmpString(pname,"Ambient.blue")==0) mat->Ambient.b = ival; if(sCmpString(pname,"Diffuse.red")==0) mat->Diffuse.r = ival; if(sCmpString(pname,"Diffuse.green")==0) mat->Diffuse.g = ival; if(sCmpString(pname,"Diffuse.blue")==0) mat->Diffuse.b = ival; if(sCmpString(pname,"Specular.red")==0) mat->Specular.r = ival; if(sCmpString(pname,"Specular.green")==0) mat->Specular.g = ival; if(sCmpString(pname,"Specular.blue")==0) mat->Specular.b = ival; if(sCmpString(pname,"Shininess")==0) mat->Specularity = fval; } else if(sCmpString(tname,"INTEGER")==0) { ival = ScanInt(); } else if(sCmpString(tname,"BOOLEAN")==0) { ival = ScanInt(); if(ival!=0) { // if(sCmpString(pname,"WrapS1")==0) mat->TFlags[0] |= sMTF_TILE; // if(sCmpString(pname,"WrapT1")==0) mat->TFlags[0] |= sMTF_TILE; if(sCmpString(pname,"Refmap1")==0) mat->TFlags[0] |= sMTF_UVENVI; if(sCmpString(pname,"Texture_1_Enable")==0) texena[0]=1; // if(sCmpString(pname,"WrapS2")==0) mat->TFlags[1] |= sMTF_TILE; // if(sCmpString(pname,"WrapT2")==0) mat->TFlags[1] |= sMTF_TILE; if(sCmpString(pname,"Refmap2")==0) mat->TFlags[1] |= sMTF_UVENVI; if(sCmpString(pname,"Texture_2_Enable")==0) texena[1]=1; } else { if(sCmpString(pname,"Enable_Ambient")==0) mat->Ambient = 0xffffffff; if(sCmpString(pname,"Enable_Diffuse")==0) mat->Diffuse = 0xffffffff; if(sCmpString(pname,"Enable_Specular")==0) mat->Specular = 0xffffffff; if(sCmpString(pname,"Enable_Shininess")==0) mat->Specularity = 0; // if(sCmpString(pname,"Enable_Lighting")==0) mat->Flags &= ~sMF_LIGHTMASK; } } else { Error = sTRUE; } } for(i=0;i<ccount;i++) { ScanString(pname,sizeof(pname)); ScanString(buffer,sizeof(buffer)); ScanString(tname,sizeof(tname)); if(sCmpString(tname,"IMAGE")==0) { if((sCmpString(pname,"Texture_1")==0 || sCmpString(pname,"tex")==0) && texena[0]) { if(mat->Tex[0] == 0 && (tsup[0][0]!=0 || (mat->TFlags[0]&sMTF_UVMASK)==sMTF_UVENVI) && TSCount<sXSI_MAXTS) { tex = FindTexture(buffer); if(tex) { mat->Tex[0] = tex; mat->Mode = sMBM_TEX; sCopyString(TSName[TSCount],tsup[0],XSISIZE); mat->TUV[0] = TSCount++; } } } if(sCmpString(pname,"Texture_2")==0 && texena[1]) { if(mat->Tex[1] == 0 && (tsup[1][0]!=0 || (mat->TFlags[1]&sMTF_UVMASK)==sMTF_UVENVI) && TSCount<sXSI_MAXTS) { tex = FindTexture(buffer); if(tex) { mat->Tex[1] = tex; mat->Mode = sMBM_MUL; // mat->TFlags[1] = sMTF_FILTER|sMTF_MIPMAP;//|sMTF_UVENVI; sCopyString(TSName[TSCount],tsup[1],XSISIZE); mat->TUV[1] = TSCount++; } } } } } sScanSpace(Scan); while(*Scan!=0 && *Scan!='}' && !Error) { ScanChunk(indent+1,chunk,name); SkipChunk(); sScanSpace(Scan); } EndChunk(); } else { SkipChunk(); } sScanSpace(Scan); } if((mat->TFlags[1] & sMTF_UVMASK)==0) mat->TFlags[1] |= sMTF_UV1; if(mat->Specularity>0.0001f || mat->Ambient!=0xffffffff || mat->Diffuse != 0xffffffff || mat->Specular != 0xffffffff) { // mat->Flags = (mat->Flags & (~sMF_LIGHTMASK)) | sMF_LIGHTMAT; // sDPrintF("extlight: %08x %08x %08x\n",mat->Diffuse.Color,mat->Ambient.Color,mat->Specular.Color); } else { // mat->Flags |= sMF_COLBOTH; } mat->TFlags[0] |= sMTF_FILTERMIN | sMTF_FILTERMAG | sMTF_MIPMAP; mat->TFlags[1] |= sMTF_FILTERMIN | sMTF_FILTERMAG | sMTF_MIPMAP; EndChunk(); } else { SkipChunk(); } sScanSpace(Scan); } EndChunk(); }
void CTextureManager::CacheExternalStandardRenderTargets() { m_pFullScreenDepthTexture = FindTexture( "_rt_FullFrameDepth" ); //created/destroyed in engine/matsys_interface.cpp to properly track hdr changes }
bool CTextureManager::IsTextureLoaded( const char *pTextureName ) { ITextureInternal *pTexture = FindTexture( pTextureName ); return ( pTexture != NULL ); }
void CTextureManager::SetExcludedTextures( const char *pScriptName ) { // clear all exisiting texture's exclusion for ( int i = m_TextureExcludes.First(); i != m_TextureExcludes.InvalidIndex(); i = m_TextureExcludes.Next( i ) ) { ITextureInternal *pTexture = FindTexture( m_TextureExcludes.GetElementName( i ) ); if ( pTexture ) { pTexture->MarkAsExcluded( false, 0 ); } } m_TextureExcludes.RemoveAll(); MEM_ALLOC_CREDIT(); // get optional script CUtlBuffer excludeBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER ); if ( g_pFullFileSystem->ReadFile( pScriptName, NULL, excludeBuffer ) ) { char szToken[MAX_PATH]; while ( 1 ) { // must support spaces in names without quotes // have to brute force parse up to a valid line while ( 1 ) { excludeBuffer.EatWhiteSpace(); if ( !excludeBuffer.EatCPPComment() ) { // not a comment break; } } excludeBuffer.GetLine( szToken, sizeof( szToken ) ); int tokenLength = strlen( szToken ); if ( !tokenLength ) { // end of list break; } // remove all trailing whitespace while ( tokenLength > 0 ) { tokenLength--; if ( isgraph( szToken[tokenLength] ) ) { break; } szToken[tokenLength] = '\0'; } // first optional token may be a dimension limit hint int nDimensionsLimit = 0; char *pTextureName = szToken; if ( pTextureName[0] != 0 && isdigit( pTextureName[0] ) ) { nDimensionsLimit = atoi( pTextureName ); // skip forward to name for ( ;; ) { char ch = *pTextureName; if ( !ch || ( !isdigit( ch ) && !isspace( ch ) ) ) { break; } pTextureName++; } } char szCleanName[MAX_PATH]; NormalizeTextureName( pTextureName, szCleanName, sizeof( szCleanName ) ); if ( m_TextureExcludes.Find( szCleanName ) != m_TextureExcludes.InvalidIndex() ) { // avoid duplicates continue; } m_TextureExcludes.Insert( szCleanName, nDimensionsLimit ); // set any existing texture's exclusion // textures that don't exist yet will get caught during their creation path ITextureInternal *pTexture = FindTexture( szCleanName ); if ( pTexture ) { pTexture->MarkAsExcluded( ( nDimensionsLimit == 0 ), nDimensionsLimit ); } } } }
// ===================================================================================== // WriteMiptex // ===================================================================================== void WriteMiptex() { int len, texsize, totaltexsize = 0; byte* data; dmiptexlump_t* l; double start, end; g_texdatasize = 0; start = I_FloatTime(); { if (!TEX_InitFromWad()) return; AddAnimatingTextures(); } end = I_FloatTime(); Verbose("TEX_InitFromWad & AddAnimatingTextures elapsed time = %ldms\n", (long)(end - start)); start = I_FloatTime(); { int i; for (i = 0; i < nummiptex; i++) { lumpinfo_t* found; found = FindTexture(miptex + i); if (found) { miptex[i] = *found; } else { miptex[i].iTexFile = miptex[i].filepos = miptex[i].disksize = 0; } } } end = I_FloatTime(); Verbose("FindTextures elapsed time = %ldms\n", (long)(end - start)); start = I_FloatTime(); { int i; texinfo_t* tx = g_texinfo; // Sort them FIRST by wadfile and THEN by name for most efficient loading in the engine. qsort((void*)miptex, (size_t) nummiptex, sizeof(miptex[0]), lump_sorter_by_wad_and_name); // Sleazy Hack 104 Pt 2 - After sorting the miptex array, reset the texinfos to point to the right miptexs for (i = 0; i < g_numtexinfo; i++, tx++) { char* miptex_name = texmap64_retrieve(tx->miptex); tx->miptex = FindMiptex(miptex_name); // Free up the originally strdup()'ed miptex_name free(miptex_name); } } end = I_FloatTime(); Verbose("qsort(miptex) elapsed time = %ldms\n", (long)(end - start)); start = I_FloatTime(); { int i; // Now setup to get the miptex data (or just the headers if using -wadtextures) from the wadfile l = (dmiptexlump_t*)g_dtexdata; data = (byte*) & l->dataofs[nummiptex]; l->nummiptex = nummiptex; for (i = 0; i < nummiptex; i++) { l->dataofs[i] = data - (byte*) l; len = LoadLump(miptex + i, data, &texsize); if (!len) { l->dataofs[i] = -1; // didn't find the texture } else { totaltexsize += texsize; hlassume(totaltexsize < g_max_map_miptex, assume_MAX_MAP_MIPTEX); } data += len; } g_texdatasize = data - g_dtexdata; } end = I_FloatTime(); Log("Texture usage is at %1.2f mb (of %1.2f mb MAX)\n", (float)totaltexsize / (1024 * 1024), (float)g_max_map_miptex / (1024 * 1024)); Verbose("LoadLump() elapsed time = %ldms\n", (long)(end - start)); }