SDL_metal.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_metal.h
  20. *
  21. * Header file for functions to creating Metal layers and views on SDL windows.
  22. */
  23. #ifndef SDL_metal_h_
  24. #define SDL_metal_h_
  25. #include "SDL_video.h"
  26. #include "begin_code.h"
  27. /* Set up for C function definitions, even when using C++ */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * \brief A handle to a CAMetalLayer-backed NSView (macOS) or UIView (iOS/tvOS).
  33. *
  34. * \note This can be cast directly to an NSView or UIView.
  35. */
  36. typedef void *SDL_MetalView;
  37. /**
  38. * \name Metal support functions
  39. */
  40. /* @{ */
  41. /**
  42. * \brief Create a CAMetalLayer-backed NSView/UIView and attach it to the
  43. * specified window.
  44. *
  45. * On macOS, this does *not* associate a MTLDevice with the CAMetalLayer on its
  46. * own. It is up to user code to do that.
  47. *
  48. * The returned handle can be casted directly to a NSView or UIView.
  49. * To access the backing CAMetalLayer, call SDL_Metal_GetLayer().
  50. *
  51. * \note \a window must be created with the SDL_WINDOW_METAL flag.
  52. *
  53. * \sa SDL_Metal_DestroyView
  54. * \sa SDL_Metal_GetLayer
  55. */
  56. extern DECLSPEC SDL_MetalView SDLCALL SDL_Metal_CreateView(SDL_Window * window);
  57. /**
  58. * \brief Destroy an existing SDL_MetalView object.
  59. *
  60. * This should be called before SDL_DestroyWindow, if SDL_Metal_CreateView was
  61. * called after SDL_CreateWindow.
  62. *
  63. * \sa SDL_Metal_CreateView
  64. */
  65. extern DECLSPEC void SDLCALL SDL_Metal_DestroyView(SDL_MetalView view);
  66. /**
  67. * \brief Get a pointer to the backing CAMetalLayer for the given view.
  68. *
  69. * \sa SDL_MetalCreateView
  70. */
  71. extern DECLSPEC void *SDLCALL SDL_Metal_GetLayer(SDL_MetalView view);
  72. /**
  73. * \brief Get the size of a window's underlying drawable in pixels (for use
  74. * with setting viewport, scissor & etc).
  75. *
  76. * \param window SDL_Window from which the drawable size should be queried
  77. * \param w Pointer to variable for storing the width in pixels,
  78. * may be NULL
  79. * \param h Pointer to variable for storing the height in pixels,
  80. * may be NULL
  81. *
  82. * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
  83. * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
  84. * platform with high-DPI support (Apple calls this "Retina"), and not disabled
  85. * by the \c SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
  86. *
  87. * \note On macOS high-DPI support must be enabled for an application by
  88. * setting NSHighResolutionCapable to true in its Info.plist.
  89. *
  90. * \sa SDL_GetWindowSize()
  91. * \sa SDL_CreateWindow()
  92. */
  93. extern DECLSPEC void SDLCALL SDL_Metal_GetDrawableSize(SDL_Window* window, int *w,
  94. int *h);
  95. /* @} *//* Metal support functions */
  96. /* Ends C function definitions when using C++ */
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #include "close_code.h"
  101. #endif /* SDL_metal_h_ */