MCPcopy Create free account
hub / github.com/OGRECave/ogre / _switchContext

Method _switchContext

RenderSystems/GL/src/OgreGLRenderSystem.cpp:2574–2638  ·  view source on GitHub ↗

---------------------------------------------------------------------

Source from the content-addressed store, hash-verified

2572
2573 //---------------------------------------------------------------------
2574 void GLRenderSystem::_switchContext(GLContext *context)
2575 {
2576 // Unbind GPU programs and rebind to new context later, because
2577 // scene manager treat render system as ONE 'context' ONLY, and it
2578 // cached the GPU programs using state.
2579 if (mCurrentVertexProgram)
2580 mCurrentVertexProgram->unbindProgram();
2581 if (mCurrentGeometryProgram)
2582 mCurrentGeometryProgram->unbindProgram();
2583 if (mCurrentFragmentProgram)
2584 mCurrentFragmentProgram->unbindProgram();
2585
2586 // Disable lights
2587 for (unsigned short i = 0; i < mCurrentLights; ++i)
2588 {
2589 setGLLight(i, false);
2590 }
2591 mCurrentLights = 0;
2592
2593 // Disable textures
2594 _disableTextureUnitsFrom(0);
2595
2596 // It's ready for switching
2597 if (mCurrentContext!=context)
2598 {
2599#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
2600 // NSGLContext::makeCurrentContext does not flush automatically. everybody else does.
2601 glFlushRenderAPPLE();
2602#endif
2603 if (mCurrentContext)
2604 mCurrentContext->endCurrent();
2605 mCurrentContext = context;
2606 }
2607
2608 if (mCurrentContext)
2609 {
2610 mCurrentContext->setCurrent();
2611
2612 mStateCacheManager = mCurrentContext->createOrRetrieveStateCacheManager<GLStateCacheManager>();
2613
2614 // Check if the context has already done one-time initialisation
2615 if(!mCurrentContext->getInitialized())
2616 {
2617 _oneTimeContextInitialization();
2618 mCurrentContext->setInitialized();
2619 }
2620 }
2621
2622 // Rebind GPU programs to new context
2623 if (mCurrentVertexProgram)
2624 mCurrentVertexProgram->bindProgram();
2625 if (mCurrentGeometryProgram)
2626 mCurrentGeometryProgram->bindProgram();
2627 if (mCurrentFragmentProgram)
2628 mCurrentFragmentProgram->bindProgram();
2629
2630 // Must reset depth/colour write mask to according with user desired, otherwise,
2631 // clearFrameBuffer would be wrong because the value we are recorded may be

Callers

nothing calls this directly

Calls 7

unbindProgramMethod · 0.45
endCurrentMethod · 0.45
setCurrentMethod · 0.45
bindProgramMethod · 0.45
setDepthMaskMethod · 0.45
setColourMaskMethod · 0.45
setStencilMaskMethod · 0.45

Tested by

no test coverage detected