NativeWindow.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/core/Common.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. {
  13. class NativeWindowImpl;
  14. using Context = void*;
  15. /// Window initializer
  16. class NativeWindowInitInfo
  17. {
  18. public:
  19. U32 m_width = 640;
  20. U32 m_height = 768;
  21. Array<U32, 4> m_rgbaBits = {8, 8, 8, 0};
  22. U32 m_depthBits = 0;
  23. U32 m_stencilBits = 0;
  24. U32 m_samplesCount = 0;
  25. static const Bool m_doubleBuffer = true;
  26. /// Create a fullscreen window with the desktop's resolution
  27. Bool m_fullscreenDesktopRez = false;
  28. CString m_title = "Untitled window";
  29. };
  30. /// Native window with GL context
  31. class NativeWindow
  32. {
  33. public:
  34. NativeWindow()
  35. {
  36. }
  37. ~NativeWindow()
  38. {
  39. destroy();
  40. }
  41. ANKI_USE_RESULT Error init(NativeWindowInitInfo& initializer, HeapAllocator<U8>& alloc);
  42. NativeWindowImpl& getNative()
  43. {
  44. ANKI_ASSERT(isCreated());
  45. return *m_impl;
  46. }
  47. U32 getWidth() const
  48. {
  49. return m_width;
  50. }
  51. U32 getHeight() const
  52. {
  53. return m_height;
  54. }
  55. /// @privatesector
  56. /// @{
  57. HeapAllocator<U8>& _getAllocator()
  58. {
  59. return m_alloc;
  60. }
  61. /// @}
  62. private:
  63. U32 m_width = 0;
  64. U32 m_height = 0;
  65. NativeWindowImpl* m_impl = nullptr;
  66. HeapAllocator<U8> m_alloc;
  67. Bool isCreated() const
  68. {
  69. return m_impl != nullptr;
  70. }
  71. void destroy();
  72. };
  73. } // end namespace anki