video.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. auto Emulator::videoUpdate() -> void {
  2. if(videoInstance && videoInstance.driver() != settings.video.driver) {
  3. videoInstance.reset();
  4. }
  5. if(!videoInstance) {
  6. videoInstance.create(settings.video.driver);
  7. videoInstance.setContext(program.viewport.handle());
  8. if(!videoInstance.ready()) {
  9. videoInstance.reset();
  10. videoInstance.create(settings.video.driver = "None");
  11. }
  12. settingsMenu.updateShaders();
  13. }
  14. if(videoInstance.hasMonitor(settings.video.monitor)) {
  15. videoInstance.setMonitor(settings.video.monitor);
  16. } else {
  17. settings.video.monitor = videoInstance.monitor();
  18. }
  19. if(videoInstance.hasExclusive()) {
  20. videoInstance.setExclusive(settings.video.exclusive);
  21. } else {
  22. settings.video.exclusive = videoInstance.exclusive();
  23. }
  24. if(videoInstance.hasBlocking()) {
  25. videoInstance.setBlocking(settings.video.blocking);
  26. } else {
  27. settings.video.blocking = videoInstance.blocking();
  28. }
  29. if(videoInstance.hasFlush()) {
  30. videoInstance.setFlush(settings.video.flush);
  31. } else {
  32. settings.video.flush = videoInstance.flush();
  33. }
  34. if(!videoInstance.hasFormat(settings.video.format)) {
  35. settings.video.format = videoInstance.hasFormats().first();
  36. }
  37. videoInstance.setFormat(settings.video.format);
  38. if(videoInstance.hasShader()) {
  39. videoInstance.setShader(settings.video.shader);
  40. }
  41. videoUpdateColors();
  42. }
  43. auto Emulator::videoUpdateColors() -> void {
  44. if(!interface) return;
  45. for(auto screen : root->find<higan::Node::Screen>()) {
  46. screen->setLuminance(settings.video.luminance);
  47. screen->setSaturation(settings.video.saturation);
  48. screen->setGamma(settings.video.gamma);
  49. }
  50. }
  51. auto Emulator::videoUpdateShader() -> void {
  52. videoInstance.setShader(settings.video.shader);
  53. }
  54. auto Emulator::videoToggleFullscreen() -> void {
  55. if(!videoInstance.hasFullScreen()) return;
  56. //todo: when not in exclusive mode, it would be prudent to hide or minimize the programWindow.
  57. //however, doing so causes the keypress to exit fullscreen to fall through to another window.
  58. //if that window binds the same hotkey, it could trigger fullscreen there (eg xfce4-terminal.)
  59. //so far, nothing I've tried can prevent this from happening, so I leave programWindow visible.
  60. videoInstance.clear(); //clear the video in the current mode before changing modes
  61. if(!videoInstance.fullScreen()) {
  62. videoInstance.setFullScreen(true);
  63. if(videoInstance.exclusive()) inputInstance.acquire();
  64. } else {
  65. videoInstance.setFullScreen(false);
  66. inputInstance.release();
  67. program.viewport.setFocused();
  68. }
  69. }