Code: Select all
Ogre::HlmsPbsDatablock *datablock = static_cast<Ogre::HlmsPbsDatablock*>(
subitem->getDatablock() );
datablock->getTexture(Ogre::PBSM_DIFFUSE)->reload();
Code: Select all
Ogre::HlmsPbsDatablock *datablock = static_cast<Ogre::HlmsPbsDatablock*>(
subitem->getDatablock() );
datablock->getTexture(Ogre::PBSM_DIFFUSE)->reload();
Code: Select all
Ogre::HlmsManager *hlmsManager = Ogre::Root::getSingletonPtr()->getHlmsManager();
Ogre::HlmsTextureManager *hlmsTextureManager = hlmsManager->getTextureManager();
hlmsTextureManager->destroyTexture("texture.dds");
Ogre::HlmsTextureManager::TextureLocation texLocation = hlmsTextureManager->createOrRetrieveTexture( "texture.dds", Ogre::HlmsTextureManager::TEXTURE_TYPE_DIFFUSE);
Ogre::HlmsPbsDatablock *datablock = static_cast<Ogre::HlmsPbsDatablock*>( subitem->getDatablock() );
datablock->setTexture( Ogre::PBSM_DIFFUSE, texLocation.xIdx, texLocation.texture );
Code: Select all
Ogre::TextureManager::ResourceMapIterator textureResourceMapIterator = Ogre::TextureManager::getSingleton().getResourceIterator();
while (textureResourceMapIterator.hasMoreElements())
{
Ogre::ResourcePtr texturePtr = textureResourceMapIterator.getNext();
std::cout<<texturePtr->getName()<<std::endl;
}
Code: Select all
[Hash 0xeb2bfd33]
[Hash 0xd84c7c3a]
[Hash 0x296098eb]
[Hash 0x594d701c]
[Hash 0xf16e7c5b]
[Hash 0x9b4ce5aa]
[Hash 0xa7121903]
HlmsTextureManager/0
HlmsTextureManager/1
HlmsTextureManager/2
HlmsTextureManager/3
HlmsTextureManager/4
HlmsTextureManager/5
HlmsTextureManager/6
HlmsTextureManager/7
HlmsTextureManager/8
HlmsTextureManager/9
HlmsTextureManager/10
HlmsTextureManager/11
HlmsTextureManager/12
HlmsTextureManager/13
rtt/140084109256816/[Hash 0x83fe644c]
Code: Select all
textureArray.texture = TextureManager::getSingleton().createManual(
"HlmsTextureManager/" +
StringConverter::toString( mTextureId++ ),
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
texType, width, height, depth, numMipmaps - baseMipLevel,
defaultPixelFormat == PF_UNKNOWN ? imageFormat :
defaultPixelFormat,
TU_DEFAULT & ~TU_AUTOMIPMAP, 0,
mDefaultTextureParameters[mapType].hwGammaCorrection,
0, BLANKSTRING, false );
Code: Select all
textureArray.texture = TextureManager::getSingleton().createManual(
texName, //<<<<<<<<<< actual file name
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
texType, width, height, depth, numMipmaps - baseMipLevel,
defaultPixelFormat == PF_UNKNOWN ? imageFormat :
defaultPixelFormat,
TU_DEFAULT & ~TU_AUTOMIPMAP, 0,
mDefaultTextureParameters[mapType].hwGammaCorrection,
0, BLANKSTRING, false );
Yes. Re-read the manual section about the HlmsTextureManager, then re-read my post again:xrgo wrote:any particular reason why in OgreHlmsTextureManager.cpp line ~506
The TexturePtr may contain "tens of textures in the same texture". A lot of things can break if you assign a name of an actual texture to these automatically generated textures.The TexturePtr is an old interface that is manually filled by the HlmsTextureManager
Doh, I alwaays knew that, I dont know what I was thinking xD.dark_sylinc wrote:The TexturePtr may contain "tens of textures in the same texture"
Code: Select all
Ogre::HlmsTextureManager::TextureLocation texLocation = hlmsTextureManager->createOrRetrieveTexture( fileName, Ogre::HlmsTextureManager::TEXTURE_TYPE_MONOCHROME);
datablock->setTexture( Ogre::PBSM_DIFFUSE, texLocation.xIdx, texLocation.texture );
textureName[fileName] = texLocation.texture->getName();
Code: Select all
Ogre::HlmsPbsDatablock *datablock = static_cast<Ogre::HlmsPbsDatablock*>( Item->getSubItem(0)->getDatablock() );
if( !datablock->getTexture(Ogre::PBSM_DIFFUSE).isNull() &&
datablock->getTexture(Ogre::PBSM_DIFFUSE)->getName() == textureName.at(textureFileName) ){
hlmsTextureManager->destroyTexture(textureFileName);
Ogre::HlmsTextureManager::TextureLocation texLocation texLocation = hlmsTextureManager->createOrRetrieveTexture( textureFileName, Ogre::HlmsTextureManager::TEXTURE_TYPE_DIFFUSE);
datablock->setTexture( Ogre::PBSM_DIFFUSE, texLocation.xIdx, texLocation.texture );
textureName[textureFileName] = texLocation.texture->getName()); //update texture name
}
Code: Select all
void HlmsTextureManager::destroyTexture( IdString aliasName )
{
TextureEntry searchName( aliasName );
TextureEntryVec::iterator it = std::lower_bound( mEntries.begin(), mEntries.end(), searchName );
if( it != mEntries.end() && it->name == searchName.name )
{
mEntries.erase( it ); <--------------------- THIS INVALIDATES THE ITERATOR it
TextureArrayVec::iterator texArrayIt = mTextureArrays[it->mapType].begin() + it->arrayIdx; <--- BUT STILL WE USE IT
texArrayIt->destroyEntry( it->entryIdx ); <----------- AND AGAIN
if( texArrayIt->activeEntries == texArrayIt->maxTextures )
{
//The whole array has no actual content. Destroy the texture.
ResourcePtr texResource = texArrayIt->texture;
TextureManager::getSingleton().remove( texResource );
texArrayIt = efficientVectorRemove( mTextureArrays[it->mapType], texArrayIt ); <-------- AND AGAIN
if( texArrayIt != mTextureArrays[it->mapType].end() ) <-------------- AND AGAIN
{
//The last element has now a new index. Update the references in mEntries
size_t newArrayIdx = it->arrayIdx; <--------------------- YEP, AGAIN :)
StringVector::const_iterator itor = texArrayIt->entries.begin();
StringVector::const_iterator end = texArrayIt->entries.end();
while( itor != end )
{
searchName.name = *itor;
it = std::lower_bound( mEntries.begin(), mEntries.end(), searchName );
assert( it != mEntries.end() && it->name == searchName.name );
it->arrayIdx = newArrayIdx;
++itor;
}
}
}
}
}
Code: Select all
uint16 arrayIdx = it->arrayIdx;
uint16 entryIdx = it->entryIdx;
TextureMapType mapType = it->mapType;
mEntries.erase( it );
Code: Select all
assert( itEntry != mEntries.end() && itEntry->name == searchName.name );
Thank you, I tried forcing a max res in the HlmsTextureManager and it worked, but now I want to do it inside my code, I tried setting up a custom RenderSystemCapabilities, but I am having some trouble.dark_sylinc wrote:The HlmsTextureManager will already try to downscale the texture when looking at RenderSystemCapabilities::getMaximumResolutionXD (where X is a number).
Code: Select all
Ogre::RenderSystemCapabilities *caps = renderSys->createRenderSystemCapabilities();
Code: Select all
renderSys->useCustomRenderSystemCapabilities(caps);
Code: Select all
Custom render capabilities must be set before the RenderSystem is initialised
Code: Select all
TextureLocation createOrRetrieveTexture( const String &texName, TextureMapType mapType, float minLod=0 );
Code: Select all
............
width = static_cast<uint>( floorf( maxResolution * aspectRatio ) );
height = maxResolution;
}
image.resize( width, height );
}
}
//New resize!! when asked
if( minLod!=0 ){
baseMipLevel = 0;
while( baseMipLevel < minLod
&& (baseMipLevel <= image.getNumMipmaps()) )
{
width >>= 1;
height >>= 1;
++baseMipLevel;
}
}
//Find an array where we can put it. If there is none, we'll have have to create a new one
TextureArrayVec::iterator dstArrayIt = findSuitableArray( mapType, width, height, depth,
faces, imageFormat,
numMipmaps - baseMipLevel );
.........
Call image.generateMipmaps; but beware it won't work with all formats (e.g. compressed formats). Returns false if mipmaps weren't generated. Also previous mipmaps will be discarded (e.g. if already embedded in the file)xrgo wrote:For example now in my app I have a quality selector: in "High" texture memory usage is like 1.5gb, and in "Low" is like 0.5gb.
The only problem is that it needs mipmaps, but all my textures already have it so not an issue for me
Is there any chances something like this gets implemented in to Ogre?
Thanks!!
Any chances to see this (or similar) integrated with Ogre??dark_sylinc wrote:The idea is quite clever btw. I was thinking of something similar, but I like yours better.
Is something like this possible in Ogre 2.1? I dont need it now, but I think is very interesting and usefulStainless wrote:One trick I use a lot is to record the highest mipmap ever used on a texture. It's complicated to get the detection to work, but it can be done. Then I can generate a report and flag any large textures that are never used at full resolution.
xrgo wrote:dark_sylinc wrote:Is something like this possible in Ogre 2.1? I dont need it now, but I think is very interesting and usefulStainless wrote:One trick I use a lot is to record the highest mipmap ever used on a texture. It's complicated to get the detection to work, but it can be done. Then I can generate a report and flag any large textures that are never used at full resolution.
Thanks!