NativeWindow.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef ANKI_CORE_NATIVE_WINDOW_H
  2. #define ANKI_CORE_NATIVE_WINDOW_H
  3. #include "anki/util/StdTypes.h"
  4. #include "anki/util/Array.h"
  5. #include "anki/util/Singleton.h"
  6. #include <string>
  7. #include <memory>
  8. namespace anki {
  9. struct NativeWindowImpl;
  10. struct ContextImpl;
  11. /// Window initializer
  12. struct NativeWindowInitializer
  13. {
  14. U32 width = 640;
  15. U32 height = 768;
  16. Array<U32, 4> rgbaBits = {{8, 8, 8, 0}};
  17. U32 depthBits = 0;
  18. U32 stencilBits = 0;
  19. U32 samplesCount = 0;
  20. static const Bool doubleBuffer = true;
  21. /// Create a fullscreen window with the desktop's resolution
  22. Bool fullscreenDesktopRez = false;
  23. /// @name GL context properties
  24. /// @{
  25. /// Minor OpenGL version. Used to create core profile context
  26. U32 minorVersion = 0;
  27. /// Major OpenGL version. Used to create core profile context
  28. U32 majorVersion = 0;
  29. Bool useGles = false; ///< Use OpenGL ES
  30. Bool debugContext = false; ///< Enables KHR_debug
  31. /// @}
  32. std::string title = "Untitled window";
  33. };
  34. /// Native window with GL context
  35. class NativeWindow
  36. {
  37. public:
  38. NativeWindow()
  39. {}
  40. ~NativeWindow();
  41. /// @name Accessors
  42. /// @{
  43. NativeWindowImpl& getNative()
  44. {
  45. ANKI_ASSERT(isCreated());
  46. return *impl;
  47. }
  48. U32 getWidth() const
  49. {
  50. return width;
  51. }
  52. U32 getHeight() const
  53. {
  54. return height;
  55. }
  56. /// @}
  57. /// @name Public interface
  58. /// Don't implement them in .h files
  59. /// @{
  60. void create(NativeWindowInitializer& initializer);
  61. void destroy();
  62. void swapBuffers();
  63. ContextImpl* createSharedContext();
  64. void contextMakeCurrent(ContextImpl& ctx);
  65. /// @}
  66. private:
  67. U32 width;
  68. U32 height;
  69. std::shared_ptr<NativeWindowImpl> impl;
  70. Bool isCreated() const
  71. {
  72. return impl.get() != nullptr;
  73. }
  74. };
  75. /// Native window singleton
  76. typedef Singleton<NativeWindow> NativeWindowSingleton;
  77. } // end namespace anki
  78. #endif