Ogre 1.8 on iPhone & openGL ES 2

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Ogre 1.8 on iPhone & openGL ES 2

Post by goshua »

i have compiled ogre 1.8 for iphone and i run now my code with it
i have also modified my ogre.cfg file so now it contains :

Code: Select all

Render System=OpenGL ES 2.x Rendering Subsystem

[OpenGL ES 2.x Rendering Subsystem]
FSAA=4
Full Screen=Yes
RTT Preferred Mode=Copy
Video Mode=320 x 480
# Use the following line instead for iPad
# Video Mode=1024 x 768
Orientation=Portrait
but when i look at the log after launch i can read the following lines :

Code: Select all

...
GL_VERSION = OpenGL ES-CM 1.1 IMGSGX535-48.20
...
**************************************
*** OpenGL ES 1.x Renderer Started ***
**************************************
...
RenderSystem Name: OpenGL ES 1.x Rendering Subsystem
...
how to activate openGL ES 2 so ?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by masterfalcon »

Have you run on it on that device previously? Also, just to be sure, what type of device is it?
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by goshua »

yup i ran the app but with ogre 1.7
i deleted xcode cache, build directory, removed my app from my iphone 4 last official iOS not beta (4.2.1), clean all, recompiled
something is sticking in the iphone you think ?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by masterfalcon »

Seems like it. The only things that I can think of are: make sure you're linking with the gles 2 rendersystem lib, using headers from 1.8 and clean rebuild.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by goshua »

soz my fault, i expected the project to have both gles & gles2 declared in pbxproj, now it run with gles2

still, i have no more display now, and

Code: Select all

renderOneFrame
is crashing now

i haven't found so far any ogre 3d gles2 sample, is there any ?
ty
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by DanielSefton »

Just a useless shoutout to mention that I have the same problem.

In no way shape or form can I get GLES 2.0 to run without it crashing at renderOneFrame() (it goes much deeper, but I don't have a stack trace handy atm). Tested in both my app and the XCode templates project.
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by masterfalcon »

There isn't a concrete example anywhere, besides the sample browser, but there should be.

Here's what I've used, slightly adapted from the sample browser:

Somewhere you'll need to define:

Code: Select all

    Ogre::RTShader::ShaderGenerator *mShaderGenerator;                  // The Shader generator instance.
    ShaderGeneratorTechniqueResolverListener *mMaterialMgrListener;		// Shader generator material manager listener.
Then add this:

Code: Select all

ShaderGeneratorTechniqueResolverListener::ShaderGeneratorTechniqueResolverListener(Ogre::RTShader::ShaderGenerator* pShaderGenerator)
{
    mShaderGenerator = pShaderGenerator;			
}

Ogre::Technique* ShaderGeneratorTechniqueResolverListener::handleSchemeNotFound(unsigned short schemeIndex, 
                                              const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, 
                                              const Ogre::Renderable* rend)
{	
    Ogre::Technique* generatedTech = NULL;
    
    // Case this is the default shader generator scheme.
    if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
    {
        bool techniqueCreated;
        
        // Create shader generated technique for this material.
        techniqueCreated = mShaderGenerator->createShaderBasedTechnique(
                                                                        originalMaterial->getName(), 
                                                                        Ogre::MaterialManager::DEFAULT_SCHEME_NAME, 
                                                                        schemeName);	
        
        // Case technique registration succeeded.
        if (techniqueCreated)
        {
            // Force creating the shaders for the generated technique.
            mShaderGenerator->validateMaterial(schemeName, originalMaterial->getName());

            // Grab the generated technique.
            Ogre::Material::TechniqueIterator itTech = originalMaterial->getTechniqueIterator();
            
            while (itTech.hasMoreElements())
            {
                Ogre::Technique* curTech = itTech.getNext();
                
                if (curTech->getSchemeName() == schemeName)
                {
                    generatedTech = curTech;
                    break;
                }
            }				
        }
    }
    
    return generatedTech;
}

/*-----------------------------------------------------------------------------
 | Initialize the RT Shader system.	
 -----------------------------------------------------------------------------*/
bool MyApp::initializeRTShaderSystem(Ogre::SceneManager* sceneMgr)
{			
    if (Ogre::RTShader::ShaderGenerator::initialize())
    {
        mShaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
        
        mShaderGenerator->addSceneManager(sceneMgr);
        
        // Setup core libraries and shader cache path.
        Ogre::StringVector groupVector = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
        Ogre::StringVector::iterator itGroup = groupVector.begin();
        Ogre::StringVector::iterator itGroupEnd = groupVector.end();
        Ogre::String shaderCoreLibsPath;
        Ogre::String shaderCachePath;
        
        for (; itGroup != itGroupEnd; ++itGroup)
        {
            Ogre::ResourceGroupManager::LocationList resLocationsList = Ogre::ResourceGroupManager::getSingleton().getResourceLocationList(*itGroup);
            Ogre::ResourceGroupManager::LocationList::iterator it = resLocationsList.begin();
            Ogre::ResourceGroupManager::LocationList::iterator itEnd = resLocationsList.end();
            bool coreLibsFound = false;
            
            // Try to find the location of the core shader lib functions and use it
            // as shader cache path as well - this will reduce the number of generated files
            // when running from different directories.
            for (; it != itEnd; ++it)
            {
                if ((*it)->archive->getName().find("RTShaderLib") != Ogre::String::npos)
                {
                    shaderCoreLibsPath = (*it)->archive->getName() + "/";
                    shaderCachePath = shaderCoreLibsPath;
                    coreLibsFound = true;
                    break;
                }
            }
            // Core libs path found in the current group.
            if (coreLibsFound) 
                break; 
        }
        
        // Core shader libs not found -> shader generating will fail.
        if (shaderCoreLibsPath.empty())			
            return false;			
        
#ifdef _RTSS_WRITE_SHADERS_TO_DISK
        // Set shader cache path.
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
        shaderCachePath = Ogre::macCachePath();
#endif
        mShaderGenerator->setShaderCachePath(shaderCachePath);		
#endif
        // Create and register the material manager listener.
        mMaterialMgrListener = new ShaderGeneratorTechniqueResolverListener(mShaderGenerator);				
        Ogre::MaterialManager::getSingleton().addListener(mMaterialMgrListener);
    }
    
    return true;
}

/*-----------------------------------------------------------------------------
 | Finalize the RT Shader system.	
 -----------------------------------------------------------------------------*/
void MyApp::finalizeRTShaderSystem()
{
    // Restore default scheme.
    Ogre::MaterialManager::getSingleton().setActiveScheme(Ogre::MaterialManager::DEFAULT_SCHEME_NAME);
    
    // Unregister the material manager listener.
    if (mMaterialMgrListener != NULL)
    {			
        Ogre::MaterialManager::getSingleton().removeListener(mMaterialMgrListener);
        delete mMaterialMgrListener;
        mMaterialMgrListener = NULL;
    }
    
    // Finalize RTShader system.
    if (mShaderGenerator != NULL)
    {				
        Ogre::RTShader::ShaderGenerator::finalize();
				mShaderGenerator = NULL;
    }
}
Call initializeRTShaderSystem after creating your scene manager. Then I just use a display link to render one frame, as seen in the sample browser.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by goshua »

atm on my iphone 'initializeRTShaderSystem' fails to find "RTShaderLib" and returns false then
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by masterfalcon »

Oh, I forgot about that. Look in the sample browser Media directory for it and include it in your app's resources. Also make sure to add RTShaderLib and RTShaderLib/materials as resource locations.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by goshua »

righty, done that but

Code: Select all

Ogre::StringVector groupVector = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
finds 3 empty groups
my resources.cfg is :

Code: Select all

# Resource locations to be added to the 'bootstrap' path
# This also contains the minimum you need to use the Ogre example framework
[Bootstrap]
Zip=./media/zip/OgreCore.zip

# Resource locations to be added to the default path
[General]
FileSystem=./media/entities/robot
FileSystem=./media/RTShaderLib





edit : all right, i just needed to initialize RTSS after resource group manager :)

Code: Select all

ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
initializeRTShaderSystem(m_poSceneManager);

i got the display now, ty :)
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by DanielSefton »

Sigh, still doesn't work and crashes at renderOneFrame() :(

Here's excerpts of my log:
**************************************
*** OpenGL ES 2.x Renderer Started ***
**************************************
GLSL ES support detected
Registering ResourceManager for type GpuProgram
GL ES 2: Using FBOs for rendering to textures
FBO PF_UNKNOWN depth/stencil support: D16S0 D24S0 Packed-D24S8
FBO PF_R5G6B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_B5G6R5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_A4R4G4B4 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_A1R5G5B5 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_A8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_A8B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_B8G8R8A8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_X8R8G8B8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
FBO PF_X8B8G8R8 depth/stencil support: D0S0 D0S8 D16S0 D24S0 Packed-D24S8
[GLES2] : Valid FBO targets PF_UNKNOWN PF_R5G6B5 PF_B5G6R5 PF_A4R4G4B4 PF_A1R5G5B5 PF_R8G8B8 PF_B8G8R8 PF_A8R8G8B8 PF_A8B8G8R8 PF_B8G8R8A8 PF_X8R8G8B8 PF_X8B8G8R8
RenderSystem capabilities
-------------------------
RenderSystem Name: OpenGL ES 2.x Rendering Subsystem
Added resource location '/var/mobile/Applications/BE687F46-D639-419E-8189-DC0CB2E15B8A/x.app/media/RTShaderLib' of type 'FileSystem' to resource group 'General'
Added resource location '/var/mobile/Applications/BE687F46-D639-419E-8189-DC0CB2E15B8A/x.app/media/RTShaderLib/materials' of type 'FileSystem' to resource group 'General'
- INFO: GraphicsManager::_initialiseRTShaderSystem()
Initialising resource group General
Parsing scripts for resource group General
Parsing script fader.material
Parsing script RTShaderSystem.material
Parsing script OgreCore.material
Parsing script OgreProfiler.material
*renderOneFrame()*
Program received signal: “EXC_BAD_ACCESS”.
In summary:
- GLES 2.0 is initialised
- I add the resource locations media/RTShaderLib and media/RTShaderLib/materials
- I call initialiseRTShaderSystem() after the scene manager is created and just before initialiseAllResourceGroups() (@goshua Has to be before that because otherwise you get "RTShaderSystem.material(23): token "rtshader_system" is not recognized")
- It parses RTShaderSystem.material ok
- I use CADisplayLink

Here's the stack trace:
#0 0x012e9028 in Ogre::GLSLESLinkProgram::getAttributeIndex at error_code.hpp:229
#1 0x012e962c in Ogre::GLSLESLinkProgram::isAttributeValid at error_code.hpp:229
#2 0x012d20e4 in Ogre::GLES2RenderSystem::_render at error_code.hpp:229
#3 0x00f02644 in Ogre::SceneManager::renderSingleObject at error_code.hpp:229
#4 0x00ef9e14 in Ogre::SceneManager::BRAND NAME::visit at error_code.hpp:229
#5 0x00e793e4 in Ogre::QueuedRenderableCollection::acceptVisitor at error_code.hpp:229
#6 0x00ef9a48 in Ogre::SceneManager::renderObjects at error_code.hpp:229
#7 0x00ef9eec in Ogre::SceneManager::renderBasicQueueGroupObjects at error_code.hpp:229
#8 0x00efc848 in Ogre::SceneManager::renderVisibleObjectsDefaultSequence at error_code.hpp:229
#9 0x00f09f04 in Ogre::SceneManager::_renderScene at error_code.hpp:229
#10 0x00ca1e64 in Ogre::Camera::_renderScene at error_code.hpp:229
#11 0x01061974 in Ogre::Viewport::update at error_code.hpp:229
#12 0x00eab0f8 in Ogre::RenderTarget::_updateViewport at error_code.hpp:229
#13 0x00eabed8 in Ogre::RenderTarget::_updateAutoUpdatedViewports at error_code.hpp:229
#14 0x00eaacac in Ogre::RenderTarget::updateImpl at error_code.hpp:229
#15 0x00eaae5c in Ogre::RenderTarget::update at error_code.hpp:229
#16 0x00e83c74 in Ogre::RenderSystem::_updateAllRenderTargets at error_code.hpp:229
#17 0x00ee65a8 in Ogre::Root::_updateAllRenderTargets at error_code.hpp:229
#18 0x00ee66cc in Ogre::Root::renderOneFrame at error_code.hpp:229
Any ideas what I might be missing? :?
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by goshua »

DanielSefton wrote:Sigh, still doesn't work and crashes at renderOneFrame() :(
...
- I call initialiseRTShaderSystem() after the scene manager is created and just before initialiseAllResourceGroups() (@goshua Has to be before that because otherwise you get "RTShaderSystem.material(23): token "rtshader_system" is not recognized")
...
if you look at initialiseRTShaderSystem you gonna see that resources must have been declared first since initialiseRTShaderSystem will search in your directory structure the RTShaderLib subdirectory, if it doesnt find it then initialiseRTShaderSystem returns false. check what initialiseRTShaderSystem returns, as long as it is false then you won't anyway run shaders. the stack trace will return you the same result as long as shaders are not initialized properly/found by the system. i call initialiseRTShaderSystem after initialiseAllResourceGroups and i don't have any "token "rtshader_system" is not recognized".
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: Ogre 1.8 on iPhone & openGL ES 2

Post by DanielSefton »

goshua wrote:if you look at initialiseRTShaderSystem you gonna see that resources must have been declared first since initialiseRTShaderSystem will search in your directory structure the RTShaderLib subdirectory
Which is why you define it after all your addResourceLocation code, that's all it requires. initialiseAllResourceGroups() parses the scripts. If you don't initialise the RT shader system before you parse the scripts, it has no way of knowing what an rtshader_system is in your material. Not sure why that works for you though.