Okay i solved the problem and found a workaround! The problem is described in my last post - the manual font textures are not regenerated after switching the context (app->homescreen->app). You need to save the raw data used to create the texture the first time and recreate it manually after switching back to the app.
Here comes the step by step guide:
1. Backup the raw data used to create the font texture.
- Create a struct to backup the texture information in RenderInterfaceOgre3D.h
Code: Select all
struct FontTextureBackup
{
Rocket::Core::byte* mSource;
Rocket::Core::Vector2i mSourceDimensions;
Rocket::Core::String mName;
RocketOgre3DTexture* mRocketTexture;
};
To use the RocketOgre3DTexture struct move it from RenderInterfaceOgre3D.cpp to the header above the FontTextureBack declaration.
- Add a container to store the texture informations - i use just a std::vector for that purpose. Put it as a member in RenderInterfaceOgre3D.h
Code: Select all
std::vector<FontTextureBackup*> mBackupFontTextures;
2. Backup the complete texture informations on creation. Replace the old GenerateTexture() method in RenderInterfaceOgre3D with the following code:
Code: Select all
bool RenderInterfaceOgre3D::GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions)
{
static int texture_id = 1;
Ogre::DataStreamPtr stream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream((void*) source, source_dimensions.x * source_dimensions.y * sizeof(unsigned int)));
Rocket::Core::String name = Rocket::Core::String(16, "%d", texture_id++);
Ogre::TexturePtr ogre_texture = Ogre::TextureManager::getSingleton().loadRawData(name.CString(),
"Rocket",
stream,
(unsigned short)(source_dimensions.x),
(unsigned short)(source_dimensions.y),
Ogre::PF_A8B8G8R8,
Ogre::TEX_TYPE_2D,
0);
if (ogre_texture.isNull())
{
return false;
}
FontTextureBackup* backup = new FontTextureBackup();
backup->mSource = (Rocket::Core::byte*) malloc(source_dimensions.x * source_dimensions.y * sizeof(unsigned int));
memcpy(backup->mSource, source, source_dimensions.x * source_dimensions.y * sizeof(unsigned int));
backup->mName = name;
backup->mSourceDimensions = source_dimensions;
backup->mRocketTexture = new RocketOgre3DTexture(ogre_texture);
mBackupFontTextures.push_back(backup);
texture_handle = reinterpret_cast<Rocket::Core::TextureHandle>(backup->mRocketTexture);
return true;
}
3. Create a new method in the RenderInterfaceOgre3D - class.
Code: Select all
void RenderInterfaceOgre3D::reloadFontTexture()
{
for(int i = 0; i < mBackupFontTextures.size(); i++)
{
FontTextureBackup* t = mBackupFontTextures.at(i);
Ogre::TextureManager::getSingleton().remove(t->mRocketTexture->texture->getName());
Ogre::DataStreamPtr stream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream((void*) mBackupFontTextures.at(i)->mSource,
mBackupFontTextures.at(i)->mSourceDimensions.x * mBackupFontTextures.at(i)->mSourceDimensions.y * sizeof(unsigned int)));
Ogre::TexturePtr ogre_texture = Ogre::TextureManager::getSingleton().loadRawData(mBackupFontTextures.at(i)->mName.CString(),
"Rocket",
stream,
(unsigned short)(mBackupFontTextures.at(i)->mSourceDimensions.x),
(unsigned short)(mBackupFontTextures.at(i)->mSourceDimensions.y),
Ogre::PF_A8B8G8R8,
Ogre::TEX_TYPE_2D,
0);
t->mRocketTexture->texture = ogre_texture;
}
}
Since the RenderCompiledGeometry() method just binds the TexturePtr from the RocketOgre3DTexture struct - replacing the pointer with the new generated one did the trick!
4. Add a method-call in the handleCmd() to call the method above.
- add void reloadFontTextures(); to the RocketApplication and call the reload method
Code: Select all
void RocketApplication::reloadFontTextures()
{
ogre_renderer->reloadFontTexture();
}
- add to handleCmd() (main.cpp) in the case APP_CMD_INIT_WINDOW - just right after static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(app->window, config) our new reload method gRocketApplication->reloadFontTextures().
Voilà!