NativeWindow.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/util/StdTypes.h>
  7. #include <anki/util/Array.h>
  8. #include <anki/util/String.h>
  9. #include <anki/util/Allocator.h>
  10. namespace anki
  11. {
  12. class NativeWindowImpl;
  13. using Context = void*;
  14. /// Native window with GL context
  15. class NativeWindow
  16. {
  17. public:
  18. /// Window initializer
  19. struct Initializer
  20. {
  21. U32 m_width = 640;
  22. U32 m_height = 768;
  23. Array<U32, 4> m_rgbaBits = {{8, 8, 8, 0}};
  24. U32 m_depthBits = 0;
  25. U32 m_stencilBits = 0;
  26. U32 m_samplesCount = 0;
  27. static const Bool m_doubleBuffer = true;
  28. /// Create a fullscreen window with the desktop's resolution
  29. Bool8 m_fullscreenDesktopRez = false;
  30. /// @name GL context properties
  31. /// @{
  32. /// Minor OpenGL version. Used to create core profile context
  33. U32 m_minorVersion = 0;
  34. /// Major OpenGL version. Used to create core profile context
  35. U32 m_majorVersion = 0;
  36. Bool8 m_useGles = false; ///< Use OpenGL ES
  37. Bool8 m_debugContext = false; ///< Enables KHR_debug
  38. /// @}
  39. const char* m_title = "Untitled window";
  40. };
  41. NativeWindow()
  42. {
  43. }
  44. ~NativeWindow()
  45. {
  46. destroy();
  47. }
  48. ANKI_USE_RESULT Error create(
  49. Initializer& initializer, HeapAllocator<U8>& alloc);
  50. NativeWindowImpl& getNative()
  51. {
  52. ANKI_ASSERT(isCreated());
  53. return *m_impl;
  54. }
  55. U32 getWidth() const
  56. {
  57. return m_width;
  58. }
  59. U32 getHeight() const
  60. {
  61. return m_height;
  62. }
  63. void swapBuffers();
  64. Context createSharedContext();
  65. Context getCurrentContext();
  66. void contextMakeCurrent(Context ctx);
  67. /// @privatesector
  68. /// @{
  69. HeapAllocator<U8>& _getAllocator()
  70. {
  71. return m_alloc;
  72. }
  73. /// @}
  74. private:
  75. U32 m_width = 0;
  76. U32 m_height = 0;
  77. NativeWindowImpl* m_impl = nullptr;
  78. HeapAllocator<U8> m_alloc;
  79. Bool isCreated() const
  80. {
  81. return m_impl != nullptr;
  82. }
  83. void destroy();
  84. };
  85. } // end namespace anki