NativeWindow.h 1.6 KB

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