[SOLVED] Ogre 1.9 RC2/"stable" + Android + libRocket

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

[SOLVED] Ogre 1.9 RC2/"stable" + Android + libRocket

Post by technique » Mon Nov 18, 2013 6:26 pm

I tried to use the new Ogre 1.9 RC2/"stable" using libRocket on Android. I used my project running just fine on 1.9 RC1 and did not change anything but the Ogre version.
(original thread: http://www.ogre3d.org/forums/viewtopic. ... 76#p493576)

Now i get those strange font errors:
Image

Again: nothing changed but the Ogre RC version! Did anyone else tried to use libRocket on Ogre 1.9 RC2 @ Android?

Looks like the IOS error mentioned sometimes before: http://www.ogre3d.org/forums/viewtopic. ... os#p480978
Last edited by technique on Sun Dec 08, 2013 7:58 pm, edited 2 times in total.
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

mega28
Gnoblar
Posts: 4
Joined: Fri Jun 14, 2013 12:43 am

Re: Ogre 1.9 RC2 + Android + libRocket

Post by mega28 » Tue Nov 19, 2013 3:36 am

Same problem here but with the latest Ogre 1.10 source.
0 x

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2 + Android + libRocket

Post by technique » Tue Nov 19, 2013 11:34 pm

Thank you for you reply!

Today i found a workaround for the problem. In the libRocket-Wrapper, RocketApplication.cpp there is the ConfigureRenderSystem()-method which set up the render-system for gui-system.
I ve recognized the texture filtering is not longer working correctly using the wrapper. I added the line

Code: Select all

	render_system->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_POINT);
to the method RenderCompiledGeometry() in the RenderInterfaceOgre3D.cpp

Code: Select all

void RenderInterfaceOgre3D::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
{
	render_system = Ogre::Root::getSingleton().getRenderSystem();

	Ogre::Matrix4 transform;
	transform.makeTrans(translation.x, translation.y, 0);
	render_system->_setWorldMatrix(transform);

	Ogre::Matrix4 projection_matrix;
	BuildProjectionMatrix(projection_matrix);
	mVertexProgramParams->setNamedConstant("worldViewProj", projection_matrix * transform);
	render_system->bindGpuProgramParameters(Ogre::GPT_VERTEX_PROGRAM, mVertexProgramParams, Ogre::GPV_ALL);

	RocketOgre3DCompiledGeometry* ogre3d_geometry = (RocketOgre3DCompiledGeometry*) geometry;

	if (ogre3d_geometry->texture != NULL)
	{
		render_system->_setTexture(0, true, ogre3d_geometry->texture->texture);
[color=#008000]                // ADD THIS LINE:
		render_system->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_POINT);[/color]

		// Ogre can change the blending modes when textures are disabled - so in case the last render had no texture,
		// we need to re-specify them.
		render_system->_setTextureBlendMode(0, colour_blend_mode);
		render_system->_setTextureBlendMode(0, alpha_blend_mode);
	}
	else
	{
                // ADD THIS LINE:
[color=#008000]		render_system->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_POINT);[/color]
                // render_system->_disableTextureUnit(0);
		render_system->_setTexture( 0, true, mBlankTexture);
	}

	render_system->_render(ogre3d_geometry->render_operation);
}
and i also repaced the "render_system->_disableTextureUnit(0);" with a 1x1 texture using "render_system->_setTexture( 0, true, mBlankTexture);" to display colored librockets elements correctly.
Create a texture using this line:

Code: Select all

	mBlankTexture = texture_manager->load("blank.png",
											"Rocket",
											Ogre::TEX_TYPE_2D,
											0);
where "blank.png" is a white RGBA32-Texture.

This way, solid colored elements are rendered correctly and the font problem is gone. I think the rendersystem texture-filter configuration is in the wrong state while rendering. might be due to some ogre3d internal changes.
Would be great if you can check if the solution is working @ 1.10!
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

mega28
Gnoblar
Posts: 4
Joined: Fri Jun 14, 2013 12:43 am

Re: Ogre 1.9 RC2 + Android + libRocket

Post by mega28 » Wed Nov 20, 2013 4:38 am

Great job !
I can verify it works for 1.10, however the bug reappears if the android surface regains focus. Is this the case for 1.9 also?
0 x

scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 2

Re: Ogre 1.9 RC2 + Android + libRocket

Post by scrawl » Wed Nov 20, 2013 4:58 am

and i also repaced the "render_system->_disableTextureUnit(0);" with a 1x1 texture using "render_system->_setTexture( 0, true, mBlankTexture);" to display colored librockets elements correctly.
Sounds like that should be reported as a bug on the JIRA tracker.
0 x

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2 + Android + libRocket

Post by technique » Wed Nov 20, 2013 12:23 pm

mega28 wrote:Great job !
I can verify it works for 1.10, however the bug reappears if the android surface regains focus. Is this the case for 1.9 also?
Sadly - yes! The fonts disappear completly but all texts set up programmatically are displayed correctly. I m not sure if this is Ogre related or just a ogre-libRocket-interface implementation fault. I'll try to get rid of this - if i m successful i ll post my solution here.
Sounds like that should be reported as a bug on the JIRA tracker.
Okay!
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2 + Android + libRocket

Post by technique » Mon Nov 25, 2013 7:31 pm

Same problem for Ogre 1.9 "stable"...

Didnt found a workaround yet - if the focus is lost - all fonts are gone except for those created after the focus is gained again.
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Ogre 1.9 RC2/"stable" + Android + libRocket

Post by masterfalcon » Thu Nov 28, 2013 6:11 am

You did report this, correct? Is it OGRE-336 in JIRA?
0 x

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2/"stable" + Android + libRocket

Post by technique » Thu Nov 28, 2013 2:02 pm

0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2/"stable" + Android + libRocket

Post by technique » Fri Nov 29, 2013 6:50 pm

I added two full OpenGL ES traces of the first frame while starting the app (working) and lose focus and gain focus again (not working) + diff on JIRA (https://ogre3d.atlassian.net/browse/OGRE-336?filter=-2).

Lot of calls - but may be helpful for somebody who knows how ogres opengl es rendersystem works.
As it might be a texture problem i just filtered for the glTex*-calls and for the working trace they are 824 and for the bad trace there are only 822 on frame one. Sound far-fetched but maybe there are some missing texture calls - so any states are missing?
The same for the c-Call on the working frame 303 and on the not working one only 300. Since its the same App and there are no monte-carlo-algorithm inside the rendersystem the opengl-texture calls should be the same?

*update* Added context_state.txt - containg the whole GL_STATE for the first context (working) and the second one (not working) - the second one begins on line 5236! The second context have much less information after the first frame.
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2/"stable" + Android + libRocket

Post by technique » Sun Dec 08, 2013 7:08 pm

I found that i need to reinitilize the font textures generated by the libRocket RenderInterfaceOgre3D. All Ogre automatically added resources are reloaded before the focus is gained again. The manual created textures of the RenderInterfaceOgre3D::GenerateTexture() method are just not recreated. I tried to use the old OgreTexturePtr and loadRawData() and / or reload() to recreate the texture content but the texture is just black so the fonts are just black too.

I read about a similiar problem here http://www.ogre3d.org/forums/viewtopic. ... re#p491591.
I have no idea how to reinitialize the textureptr without changing the texture handle that libRocket uses internal.
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Ogre 1.9 RC2/"stable" + Android + libRocket

Post by technique » Sun Dec 08, 2013 7:57 pm

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à!
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

Post Reply