HRESULT ProxyImplDevice::SetTexture(DWORD Stage, IDirect3DBaseTexture9* pBaseTex) { renderTargets_.erase(Stage); if (pBaseTex) { if (pBaseTex->GetType() == D3DRTYPE_TEXTURE) { TextureProxyPtr pTexture(dynamic_cast<TextureProxyRawPtr>(pBaseTex), true); assert(pTexture); D3DSURFACE_DESC desc; HRESULT res = pTexture->GetLevelDesc(0, &desc); assert(SUCCEEDED(res)); if ((desc.Usage & D3DUSAGE_RENDERTARGET) != 0) renderTargets_.insert(Stage); else { auto texUpdateFrame = pTexture->lastUpdateFrame(); if (!texUpdateFrame || *texUpdateFrame > lastAllowedLockFrame_) return pimpl_->SetTexture(Stage, notex_.get()); } } } return MyProxyBase::SetTexture(Stage, pBaseTex); }
std::shared_ptr<Texture> TextureManager::operator[](const std::string& key) { auto it = mTextures.find(key); if (it != mTextures.end()) { return it->second; } else { std::shared_ptr<Texture> pTexture(new Texture{ key }); mTextures.insert(std::pair<std::string, std::shared_ptr<Texture>>(key, pTexture)); return pTexture; } }
std::shared_ptr<Texture> TextureManager::operator[](const TMX::Tileset& tileset) { auto it = mTextures.find(tileset.image); if (it != mTextures.end()) { return it->second; } else { std::shared_ptr<Texture> pTexture(new Texture{ tileset }); mTextures.insert(std::pair<std::string, std::shared_ptr<Texture>>(tileset.image, pTexture)); return pTexture; } }
DxTexture* TextureCache::loadTextureFromFile(const std::string& filename, const Color4B& colorKey) { auto ite = m_pTextureArray->find(filename); if (ite != m_pTextureArray->end()) { DxTexture* temp = ite->second; DxTexture* texture = new DxTexture(); texture->m_contentSize = texture->m_textureSize = temp->m_textureSize; texture->m_pTexture = temp->m_pTexture; return texture; } LPDIRECT3DDEVICE9 pDevice = Director::getInstance()->getDxDevice()->getIDirect3DDevice9(); LPDIRECT3DTEXTURE9 pTexture(nullptr); D3DXIMAGE_INFO info; if (S_OK != D3DXCreateTextureFromFileEx( pDevice, filename.c_str(), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, D3DPOOL_DEFAULT, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_RGBA( colorKey.r, colorKey.g, colorKey.b, colorKey.a), &info, NULL, &pTexture)) { return nullptr; } if (!pTexture) { return nullptr; } int width = info.Width; int height = info.Height; if (width <= 0 || height <= 0) { return nullptr; } DxTexture* texture = new DxTexture(); texture->m_contentSize = texture->m_textureSize = Size(width, height); texture->m_pTexture = pTexture; m_pTextureArray->insert(std::make_pair(filename, texture)); return loadTextureFromFile(filename, colorKey); }
void xmlLeafLoad::DecodeTextures( ticpp::Element* pTextures ) { //извлечь имена текстур if ( pTextures ) { int iSize = 0; pTextures->GetAttribute( m_LeafNames.m_sNum , &iSize , false ); ticpp::Iterator< ticpp::Element > pTexture( m_LeafNames.m_sTexture ); for ( pTexture = pTexture.begin( pTextures ); pTexture != pTexture.end(); pTexture++ ) { //считать атрибут с именем текстуры std::string sTexture; pTexture->GetAttribute( m_LeafNames.m_sVal , &sTexture , false ); m_pData->m_vTextures.push_back( sTexture ); } } }
// static std::shared_ptr< DynamicTexture2D > D3D11Utils_Texture::createTextureFromImage( ID3D11Device* pDevice, const Image4ub& im, bool flipUD ) { std::shared_ptr< DynamicTexture2D > pTexture( DynamicTexture2D::createUnsignedByte4( pDevice, im.width(), im.height() ) ); copyImageToTexture( im, pTexture, flipUD ); return pTexture; }