emu_window_glfw.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "common/common.h"
  5. #include "video_core/video_core.h"
  6. #include "citra/citra.h"
  7. #include "citra/emu_window/emu_window_glfw.h"
  8. static void OnKeyEvent(GLFWwindow* win, int key, int action) {
  9. // TODO(bunnei): ImplementMe
  10. }
  11. static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) {
  12. EmuWindow_GLFW* emu_window = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win);
  13. emu_window->SetClientAreaWidth(width);
  14. emu_window->SetClientAreaHeight(height);
  15. }
  16. /// EmuWindow_GLFW constructor
  17. EmuWindow_GLFW::EmuWindow_GLFW() {
  18. // Initialize the window
  19. if(glfwInit() != GL_TRUE) {
  20. printf("Failed to initialize GLFW! Exiting...");
  21. exit(1);
  22. }
  23. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  24. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
  25. m_render_window = glfwCreateWindow(VideoCore::kScreenTopWidth,
  26. (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight),
  27. m_window_title.c_str(), NULL, NULL);
  28. // Setup callbacks
  29. glfwSetWindowUserPointer(m_render_window, this);
  30. //glfwSetKeyCallback(m_render_window, OnKeyEvent);
  31. //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent);
  32. DoneCurrent();
  33. }
  34. /// EmuWindow_GLFW destructor
  35. EmuWindow_GLFW::~EmuWindow_GLFW() {
  36. glfwTerminate();
  37. }
  38. /// Swap buffers to display the next frame
  39. void EmuWindow_GLFW::SwapBuffers() {
  40. glfwSwapBuffers(m_render_window);
  41. }
  42. /// Polls window events
  43. void EmuWindow_GLFW::PollEvents() {
  44. glfwPollEvents();
  45. }
  46. /// Makes the GLFW OpenGL context current for the caller thread
  47. void EmuWindow_GLFW::MakeCurrent() {
  48. glfwMakeContextCurrent(m_render_window);
  49. }
  50. /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
  51. void EmuWindow_GLFW::DoneCurrent() {
  52. glfwMakeContextCurrent(NULL);
  53. }