I'm trying to get red cyan anaglyphic stereo to run on Android.
As for the setup: I'm running a custom project on my Android device with ogre 1.9 compiled according to the CMake quick build tut by the great wolfman.
It starts and runs and stuff but when I try to apply my compositor and the listeners to the two render targets, they simply never get called.
Now I know the material and all work, since I can change the shader i wrote and i get different coloring in my scene.
I took the Stereomanager apart since it wouldn't work on Android and came up with the following minimal example:
Code: Select all
class myRenderTargetListener: public Ogre::RenderTargetListener
{
public:
virtual void preRenderTargetUpdate (const Ogre::RenderTargetEvent& evt)
{
//never thrown
__android_log_write(ANDROID_LOG_VERBOSE, "DEBUGGING", "myRenderListener preRenderTargetUpdate");
}
virtual void postRenderTargetUpdate (const Ogre::RenderTargetEvent& evt)
{
//never thrown
__android_log_write(ANDROID_LOG_VERBOSE, "DEBUGGING", "myRenderListener postRenderTargetUpdate");
}
virtual void preViewportUpdate (const Ogre::RenderTargetViewportEvent &evt)
{
//never thrown
__android_log_write(ANDROID_LOG_VERBOSE, "DEBUGGING", "myRenderListener preViewportUpdate");
}
virtual void postViewportUpdate (const Ogre::RenderTargetViewportEvent &evt)
{
//never thrown
__android_log_write(ANDROID_LOG_VERBOSE, "DEBUGGING", "myRenderListener postViewportUpdate");
}
};
void MyApp::setupViewport(Ogre::SceneManager *curr)
{
Ogre::String materialName="Stereo/RedCyanAnaglyph";
Ogre::Viewport *vp = mWindow->addViewport(mCamera); //Our Viewport linked to the camera
Ogre::CompositorInstance* mCompositorInstance = CompositorManager::getSingleton().addCompositor(vp, "Stereo/BaseCompositor");
if(!mCompositorInstance)
OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Cannot create compositor, missing StereoManager resources",
"StereoManager::initCompositor"); //not thrown
CompositorManager::getSingleton().setCompositorEnabled(vp, "Stereo/BaseCompositor", true);
MaterialPtr mat = static_cast<MaterialPtr>(MaterialManager::getSingleton().getByName(materialName));
if(mat.isNull())
OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, materialName + " not found, missing StereoManager resources",
"StereoManager::initCompositor"); //not thrown
mCompositorInstance->getTechnique()->getOutputTargetPass()->getPass(0)->setMaterial(mat);
Ogre::RenderTarget* leftTarget = mCompositorInstance->getRenderTarget("Stereo/Left");
Ogre::RenderTarget* rightTarget = mCompositorInstance->getRenderTarget("Stereo/Right");
Ogre::Viewport* out_left = leftTarget->getViewport(0);
Ogre::Viewport* out_right = rightTarget->getViewport(0);
leftTarget->addListener(new myRenderTargetListener());
rightTarget->addListener(new myRenderTargetListener());
}
Code: Select all
compositor Stereo/BaseCompositor
{
technique
{
// Temporary textures
texture Stereo/Left target_width target_height PF_R8G8B8
texture Stereo/Right target_width target_height PF_R8G8B8
target Stereo/Left
{
input none
pass clear
{
}
pass render_scene
{
}
}
target Stereo/Right
{
input none
pass clear
{
}
pass render_scene
{
}
}
target_output
{
// Start with clear output
input none
pass render_quad
{
// Renders a fullscreen quad with a material
// redefined by the manager
material Stereo/BaseCompositorMaterial
input 0 Stereo/Left
input 1 Stereo/Right
}
}
}
}
Code: Select all
fragment_program Stereo/Anaglyph_RC_GLSLES_FP glsles
{
default_params
{
param_named LEFT_MASK float4 1.0 1.0 0.0 1.0
param_named RIGHT_MASK float4 0.0 0.0 1.0 1.0
param_named Left int 0
param_named Right int 1
}
source redcyan.glsles
}
fragment_program Stereo/Anaglyph_RC unified
{
//delegate Stereo/Anaglyph_RC_GLSL_FP
delegate Stereo/Anaglyph_RC_GLSLES_FP
//delegate Stereo/Anaglyph_RC_CG_FP
}
material Stereo/BaseCompositorMaterial
{
technique
{
pass
{
vertex_program_ref Ogre/Compositor/StdQuad_vp
{
}
texture_unit Left
{
tex_address_mode clamp
filtering linear linear none
tex_coord_set 0
texture_alias Left
}
texture_unit Right
{
tex_address_mode clamp
filtering linear linear none
tex_coord_set 0
texture_alias Right
}
}
}
}
material Stereo/RedCyanAnaglyph : Stereo/BaseCompositorMaterial
{
technique
{
pass
{
fragment_program_ref Stereo/Anaglyph_RC
{
}
}
}
}
Code: Select all
#version 100
precision mediump int;
precision mediump float;
uniform sampler2D Left;
uniform sampler2D Right;
uniform vec4 LEFT_MASK;
uniform vec4 RIGHT_MASK;
varying vec2 uv;
void main()
{
vec4 left = texture2D(Left, uv);
vec4 right = texture2D(Right, uv);
//this is the actual thing. the others were for testing purposes:
//gl_FragColor = left * LEFT_MASK + right * RIGHT_MASK;
//testing:
//gl_FragColor = right;
//testing:
//gl_FragColor = left * LEFT_MASK;
//testing:
gl_FragColor = right * RIGHT_MASK;
}