Window.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. // This code contains NVIDIA Confidential Information and is disclosed
  3. // under the Mutual Non-Disclosure Agreement.
  4. //
  5. // Notice
  6. // ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
  7. // NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
  8. // THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
  9. // MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  10. //
  11. // NVIDIA Corporation assumes no responsibility for the consequences of use of such
  12. // information or for any infringement of patents or other rights of third parties that may
  13. // result from its use. No license is granted by implication or otherwise under any patent
  14. // or patent rights of NVIDIA Corporation. No third party distribution is allowed unless
  15. // expressly authorized by NVIDIA. Details are subject to change without notice.
  16. // This code supersedes and replaces all information previously supplied.
  17. // NVIDIA Corporation products are not authorized for use as critical
  18. // components in life support devices or systems without express written approval of
  19. // NVIDIA Corporation.
  20. //
  21. // Copyright (c) 2014-2016 NVIDIA Corporation. All rights reserved.
  22. //
  23. // NVIDIA Corporation and its licensors retain all intellectual property and proprietary
  24. // rights in and to this software and related documentation and any modifications thereto.
  25. // Any use, reproduction, disclosure or distribution of this software and related
  26. // documentation without an express license agreement from NVIDIA Corporation is
  27. // strictly prohibited.
  28. //
  29. /////////////////////////////////////////////////////////////////////////////////////////
  30. #ifndef SAMPLES_COMMON_WINDOW_HPP__
  31. #define SAMPLES_COMMON_WINDOW_HPP__
  32. #include <dw/core/EGL.h>
  33. #include <dw/gl/GL.h>
  34. class WindowBase
  35. {
  36. public:
  37. typedef void (*KeyPressCallback)(int key);
  38. typedef void (*MouseDownCallback)(int button, float x, float y);
  39. typedef void (*MouseUpCallback)(int button, float x, float y);
  40. typedef void (*MouseMoveCallback)(float x, float y);
  41. typedef void (*MouseWheelCallback)(float dx, float dy);
  42. typedef void (*ResizeWindowCallback)(int width, int height);
  43. // create an X11 window
  44. // width: width of window
  45. // height: height of window
  46. WindowBase(int windowWidth, int windowHeight)
  47. : m_width(windowWidth)
  48. , m_height(windowHeight)
  49. , m_keyPressCallback(nullptr)
  50. , m_mouseDownCallback(nullptr)
  51. , m_mouseUpCallback(nullptr)
  52. , m_mouseMoveCallback(nullptr)
  53. , m_mouseWheelCallback(nullptr)
  54. , m_resizeWindowCallback(nullptr)
  55. {
  56. }
  57. // release window
  58. virtual ~WindowBase()
  59. {
  60. }
  61. // swap back and front buffers
  62. virtual bool swapBuffers() = 0;
  63. // reset EGL context
  64. virtual void resetContext() = 0;
  65. // create shared EGL context for the calling thread
  66. virtual EGLContext createSharedContext() const = 0;
  67. // make window context current to the calling thread
  68. virtual bool makeCurrent() = 0;
  69. // remove current window context from the calling thread
  70. virtual bool resetCurrent() = 0;
  71. // indicate that a window should be closed, i.e. requested by the user
  72. virtual bool shouldClose() { return false; }
  73. // Set the window size
  74. virtual bool setWindowSize(int w, int h) { (void)w; (void)h; return false; }
  75. // get EGL display
  76. virtual EGLDisplay getEGLDisplay(void) = 0;
  77. virtual EGLContext getEGLContext(void) = 0;
  78. int width() const { return m_width; }
  79. int height() const { return m_height; }
  80. void setOnKeypressCallback(KeyPressCallback callback)
  81. {
  82. m_keyPressCallback = callback;
  83. }
  84. void setOnMouseDownCallback(MouseDownCallback callback)
  85. {
  86. m_mouseDownCallback = callback;
  87. }
  88. void setOnMouseUpCallback(MouseUpCallback callback)
  89. {
  90. m_mouseUpCallback = callback;
  91. }
  92. void setOnMouseMoveCallback(MouseMoveCallback callback)
  93. {
  94. m_mouseMoveCallback = callback;
  95. }
  96. void setOnMouseWheelCallback(MouseWheelCallback callback)
  97. {
  98. m_mouseWheelCallback = callback;
  99. }
  100. void setOnResizeWindowCallback(ResizeWindowCallback callback)
  101. {
  102. m_resizeWindowCallback = callback;
  103. }
  104. protected:
  105. int m_width;
  106. int m_height;
  107. KeyPressCallback m_keyPressCallback;
  108. MouseDownCallback m_mouseDownCallback;
  109. MouseUpCallback m_mouseUpCallback;
  110. MouseMoveCallback m_mouseMoveCallback;
  111. MouseWheelCallback m_mouseWheelCallback;
  112. ResizeWindowCallback m_resizeWindowCallback;
  113. };
  114. #endif // SAMPLES_COMMON_WINDOW_HPP__