NativeWindow.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2009-2016, 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/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. /// Window initializer
  15. class NativeWindowInitInfo
  16. {
  17. public:
  18. U32 m_width = 640;
  19. U32 m_height = 768;
  20. Array<U32, 4> m_rgbaBits = {{8, 8, 8, 0}};
  21. U32 m_depthBits = 0;
  22. U32 m_stencilBits = 0;
  23. U32 m_samplesCount = 0;
  24. static const Bool m_doubleBuffer = true;
  25. /// Create a fullscreen window with the desktop's resolution
  26. Bool8 m_fullscreenDesktopRez = false;
  27. CString m_title = "Untitled window";
  28. };
  29. /// Native window with GL context
  30. class NativeWindow
  31. {
  32. public:
  33. NativeWindow()
  34. {
  35. }
  36. ~NativeWindow()
  37. {
  38. destroy();
  39. }
  40. ANKI_USE_RESULT Error create(
  41. 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