void VDebugShadingModes::OnHandleCallback(IVisCallbackDataObject_cl* pData)
{
  if (pData->m_pSender == &Vision::Callbacks.OnAfterSceneLoaded)
  {
    Vision::RenderLoopHelper.SetReplacementRenderLoop(NULL);
    m_iCurrentDebugShadingMode = -1;
  }
  else if (pData->m_pSender == &Vision::Callbacks.OnBeforeSceneUnloaded)
  {
    Vision::RenderLoopHelper.SetReplacementRenderLoop(NULL);
    m_iCurrentDebugShadingMode = -1;
    m_spBackupRendererNode = NULL;
  }

  int iIndex = GetCallbackIndex(pData);
  if (iIndex >= 0)
  {
    if (m_iCurrentDebugShadingMode == -1)
    {
      // Backup render node so that the debug rendering can be restored to the original rendering
      m_spBackupRendererNode = Vision::Renderer.GetRendererNode(0);
    }

    // Disable when currently active shading mode is triggered again
    if (m_iCurrentDebugShadingMode == iIndex)
    {
      m_iCurrentDebugShadingMode = -1;
      Vision::RenderLoopHelper.SetReplacementRenderLoop(NULL);
      Vision::Renderer.SetRendererNode(0, m_spBackupRendererNode);
    }
    else
    {
      m_iCurrentDebugShadingMode = iIndex;

      // The debug shading works by replacing the current render loop by a debug shading one which applies the different effects
      if (m_spDebugShadingRenderLoop == NULL)
        m_spDebugShadingRenderLoop = new VisDebugShadingRenderLoop_cl();

      m_spDebugShadingRenderLoop->SetEffect(m_debugShadingEffects.GetAt(m_iCurrentDebugShadingMode));

      // Simple render node base on the main render context which encapsulates the debug shading render loop
      VSimpleRendererNode* pSimpleRendererNode = new VSimpleRendererNode(Vision::Contexts.GetMainRenderContext());
      pSimpleRendererNode->InitializeRenderer();

      Vision::Renderer.SetRendererNode(0, pSimpleRendererNode);
      Vision::RenderLoopHelper.SetReplacementRenderLoop(m_spDebugShadingRenderLoop);
    }
  }
}
void VAppHelper::DestroyForwardRenderer()
{
  VSimpleRendererNode* pRenderer = new VSimpleRendererNode(Vision::Contexts.GetMainRenderContext());
  pRenderer->InitializeRenderer();
  Vision::Renderer.SetRendererNode(0, pRenderer);
}
Exemple #3
0
bool VisionApp_cl::InitEngine(VisAppConfig_cl *pConfig)
{
  SetShaderProvider(new VisionShaderProvider_cl());

  // Use default application configuration if none is provided
  if (pConfig != NULL)
    m_appConfig = *pConfig;

  VASSERT(m_iInitializeCount==0);
  if (m_iInitializeCount==0)
  {
    VULPSTATUSMESSAGE_0("Initializing engine");
    ////////////////////////////////////////////////

    // Initialize engine  
    Vision::Init( &m_appConfig.m_engineConfig, s_pszAuthKey ); 

    // Initialize video
#if defined(WIN32) && !defined(_VISION_WINRT)
    if(m_appConfig.m_iInitFlags & VAPP_PEEK_ALL_MESSAGES_DEPRECATED)
      m_appConfig.m_windowConfig.SetPickAllMessage();
    Vision::Video.Init(&m_appConfig.m_windowConfig);

#elif defined(_VISION_PS3)
    *Vision::Video.GetGcmConfig() = m_appConfig.m_gcmConfig;
    Vision::Video.Init();

#else
    Vision::Video.Init();
#endif

    if ((m_appConfig.m_iInitFlags & VAPP_FULLSCREEN)!=0)
      m_appConfig.m_videoConfig.m_bFullScreen = true;

#if defined(WIN32) && defined(_VR_DX9)
    if ((m_appConfig.m_iInitFlags & VAPP_USE_NVPERFHUD)!=0)
      m_appConfig.m_videoConfig.m_bEnableNVPerfHUD = true;
#endif

    BOOL rVideoInit = Vision::Video.SetMode( m_appConfig.m_videoConfig);
    if ( !rVideoInit )
    {
      char szError[1024];
      sprintf(szError,"Unable to initialize video mode\n%s", Vision::Video.GetLastError().AsChar());
      Vision::Error.Warning (szError);

      // Keep a reference to ourself so that we don't get deleted during the engine deinit
      VSmartPtr<VisionApp_cl> keepRef = this;

      Vision::DeInit();
      Vision::Video.DeInit();
      SetShaderProvider(NULL);

      return false;
    }

    if ((m_appConfig.m_iInitFlags & VAPP_DEFER_IM_SHADER_CREATION) == 0)
    {
      // Create fixed-function shaders for immediate mode
      CreateIMShaders();
    }

    m_iInitFlags = m_appConfig.m_iInitFlags;

#ifdef WIN32
    if ((m_appConfig.m_iInitFlags & VAPP_USE_NVPERFHUD)!=0)
      m_iInitFlags &= ~VAPP_USE_DINPUT;
#endif

    //Initialize input
    if (m_appConfig.m_iInitFlags & VAPP_INIT_INPUT)
    {
      InitInput();
      //Vision::Profiling.InitInputMap();
    }

    ////////////////////////////////////////////////
    Vision::Contexts.GetMainRenderContext()->SetPriority(VIS_RENDERCONTEXTPRIORITY_DISPLAY);
    Vision::Contexts.GetMainRenderContext()->SetRenderLoop(new VisionRenderLoop_cl());

    VSimpleRendererNode* pRenderer = new VSimpleRendererNode(Vision::Contexts.GetMainRenderContext());
    pRenderer->InitializeRenderer();

    Vision::Renderer.SetRendererNode(0, pRenderer);   

    VULPSTATUSMESSAGE_0("Engine initialized");
    //Init custom data
    OnInitEngine();    
  }
  m_iInitializeCount++;
  return true;
}