NativeWindow.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_CORE_NATIVE_WINDOW_H
  6. #define ANKI_CORE_NATIVE_WINDOW_H
  7. #include "anki/util/StdTypes.h"
  8. #include "anki/util/Array.h"
  9. #include "anki/util/String.h"
  10. #include "anki/util/Allocator.h"
  11. namespace anki {
  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. ~NativeWindow()
  44. {
  45. destroy();
  46. }
  47. ANKI_USE_RESULT Error create(
  48. Initializer& initializer, HeapAllocator<U8>& alloc);
  49. NativeWindowImpl& getNative()
  50. {
  51. ANKI_ASSERT(isCreated());
  52. return *m_impl;
  53. }
  54. U32 getWidth() const
  55. {
  56. return m_width;
  57. }
  58. U32 getHeight() const
  59. {
  60. return m_height;
  61. }
  62. void swapBuffers();
  63. Context createSharedContext();
  64. Context getCurrentContext();
  65. void contextMakeCurrent(Context ctx);
  66. /// @privatesector
  67. /// @{
  68. HeapAllocator<U8>& _getAllocator()
  69. {
  70. return m_alloc;
  71. }
  72. /// @}
  73. private:
  74. U32 m_width = 0;
  75. U32 m_height = 0;
  76. NativeWindowImpl* m_impl = nullptr;
  77. HeapAllocator<U8> m_alloc;
  78. Bool isCreated() const
  79. {
  80. return m_impl != nullptr;
  81. }
  82. void destroy();
  83. };
  84. } // end namespace anki
  85. #endif