comparison Applications/Generic/GuiAdapter.cpp @ 947:1091b2adeb5a toa2019081001

Fixed animation frame stopping when returning false + big work on the OpenGL objects to make them lost context-safe + debug code to forcefully tag a context as lost + debug macros
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 10 Aug 2019 13:07:31 +0200
parents 86ac61a040c9
children ac88989817e3
comparison
equal deleted inserted replaced
946:dbe3e1e47019 947:1091b2adeb5a
548 } 548 }
549 549
550 // SDL ONLY 550 // SDL ONLY
551 void GuiAdapter::OnAnimationFrame() 551 void GuiAdapter::OnAnimationFrame()
552 { 552 {
553 std::vector<size_t> disabledAnimationHandlers;
553 for (size_t i = 0; i < animationFrameHandlers_.size(); i++) 554 for (size_t i = 0; i < animationFrameHandlers_.size(); i++)
554 { 555 {
555 // TODO: fix time 556 // TODO: fix time
556 (*(animationFrameHandlers_[i].first))(0, animationFrameHandlers_[i].second); 557 bool goOn = (*(animationFrameHandlers_[i].first))(0, animationFrameHandlers_[i].second);
558
559 // If the function returns false, we need to emulate what happens in Web
560 // and remove the function from the handlers...
561 if (!goOn)
562 disabledAnimationHandlers.push_back(i);
563 }
564 for (size_t i = 0; i < disabledAnimationHandlers.size(); i++)
565 {
566 ORTHANC_ASSERT(animationFrameHandlers_.begin() + disabledAnimationHandlers[i] < animationFrameHandlers_.end());
567 animationFrameHandlers_.erase(animationFrameHandlers_.begin() + disabledAnimationHandlers[i]);
557 } 568 }
558 } 569 }
559 570
560 // SDL ONLY 571 // SDL ONLY
561 void GuiAdapter::OnResize() 572 void GuiAdapter::OnResize()
693 //if(foundWidget) 704 //if(foundWidget)
694 // foundWidget-> 705 // foundWidget->
695 } 706 }
696 } 707 }
697 708
709
710 // extern void Debug_SetContextToBeKilled(std::string title);
711 // extern void Debug_SetContextToBeRestored(std::string title);
712
698 // SDL ONLY 713 // SDL ONLY
699 void GuiAdapter::RequestAnimationFrame(OnAnimationFrameFunc func, void* userData) 714 void GuiAdapter::RequestAnimationFrame(OnAnimationFrameFunc func, void* userData)
700 { 715 {
701 animationFrameHandlers_.push_back(std::make_pair(func, userData)); 716 animationFrameHandlers_.push_back(std::make_pair(func, userData));
702 } 717 }
844 { 859 {
845 case SDLK_f: 860 case SDLK_f:
846 // window.GetWindow().ToggleMaximize(); //TODO: move to particular handler 861 // window.GetWindow().ToggleMaximize(); //TODO: move to particular handler
847 break; 862 break;
848 863
864 // This commented out code was used to debug the context
865 // loss/restoring code (2019-08-10)
866 // case SDLK_k:
867 // {
868 // SDL_Window* window = SDL_GetWindowFromID(event.window.windowID);
869 // std::string windowTitle(SDL_GetWindowTitle(window));
870 // Debug_SetContextToBeKilled(windowTitle);
871 // }
872 // break;
873 // case SDLK_l:
874 // {
875 // SDL_Window* window = SDL_GetWindowFromID(event.window.windowID);
876 // std::string windowTitle(SDL_GetWindowTitle(window));
877 // Debug_SetContextToBeRestored(windowTitle);
878 // }
879 // break;
880
849 case SDLK_q: 881 case SDLK_q:
850 stop = true; 882 stop = true;
851 break; 883 break;
852 884
853 default: 885 default: