sokol_glue.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #if defined(SOKOL_IMPL) && !defined(SOKOL_GLUE_IMPL)
  2. #define SOKOL_GLUE_IMPL
  3. #endif
  4. #ifndef SOKOL_GLUE_INCLUDED
  5. /*
  6. sokol_glue.h -- glue helper functions for sokol headers
  7. Project URL: https://github.com/floooh/sokol
  8. Do this:
  9. #define SOKOL_IMPL or
  10. #define SOKOL_GLUE_IMPL
  11. before you include this file in *one* C or C++ file to create the
  12. implementation.
  13. ...optionally provide the following macros to override defaults:
  14. SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
  15. SOKOL_GLUE_API_DECL - public function declaration prefix (default: extern)
  16. SOKOL_API_DECL - same as SOKOL_GLUE_API_DECL
  17. SOKOL_API_IMPL - public function implementation prefix (default: -)
  18. If sokol_glue.h is compiled as a DLL, define the following before
  19. including the declaration or implementation:
  20. SOKOL_DLL
  21. On Windows, SOKOL_DLL will define SOKOL_GLUE_API_DECL as __declspec(dllexport)
  22. or __declspec(dllimport) as needed.
  23. OVERVIEW
  24. ========
  25. The sokol core headers should not depend on each other, but sometimes
  26. it's useful to have a set of helper functions as "glue" between
  27. two or more sokol headers.
  28. This is what sokol_glue.h is for. Simply include the header after other
  29. sokol headers (both for the implementation and declaration), and
  30. depending on what headers have been included before, sokol_glue.h
  31. will make available "glue functions".
  32. PROVIDED FUNCTIONS
  33. ==================
  34. - if sokol_app.h and sokol_gfx.h is included:
  35. sg_context_desc sapp_sgcontext(void):
  36. Returns an initialized sg_context_desc function initialized
  37. by calling sokol_app.h functions.
  38. LICENSE
  39. =======
  40. zlib/libpng license
  41. Copyright (c) 2018 Andre Weissflog
  42. This software is provided 'as-is', without any express or implied warranty.
  43. In no event will the authors be held liable for any damages arising from the
  44. use of this software.
  45. Permission is granted to anyone to use this software for any purpose,
  46. including commercial applications, and to alter it and redistribute it
  47. freely, subject to the following restrictions:
  48. 1. The origin of this software must not be misrepresented; you must not
  49. claim that you wrote the original software. If you use this software in a
  50. product, an acknowledgment in the product documentation would be
  51. appreciated but is not required.
  52. 2. Altered source versions must be plainly marked as such, and must not
  53. be misrepresented as being the original software.
  54. 3. This notice may not be removed or altered from any source
  55. distribution.
  56. */
  57. #define SOKOL_GLUE_INCLUDED
  58. #if defined(SOKOL_API_DECL) && !defined(SOKOL_GLUE_API_DECL)
  59. #define SOKOL_GLUE_API_DECL SOKOL_API_DECL
  60. #endif
  61. #ifndef SOKOL_GLUE_API_DECL
  62. #if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GLUE_IMPL)
  63. #define SOKOL_GLUE_API_DECL __declspec(dllexport)
  64. #elif defined(_WIN32) && defined(SOKOL_DLL)
  65. #define SOKOL_GLUE_API_DECL __declspec(dllimport)
  66. #else
  67. #define SOKOL_GLUE_API_DECL extern
  68. #endif
  69. #endif
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. #if defined(SOKOL_GFX_INCLUDED) && defined(SOKOL_APP_INCLUDED)
  74. SOKOL_GLUE_API_DECL sg_context_desc sapp_sgcontext(void);
  75. #endif
  76. #ifdef __cplusplus
  77. } /* extern "C" */
  78. #endif
  79. #endif /* SOKOL_GLUE_INCLUDED */
  80. /*-- IMPLEMENTATION ----------------------------------------------------------*/
  81. #ifdef SOKOL_GLUE_IMPL
  82. #define SOKOL_GLUE_IMPL_INCLUDED (1)
  83. #include <string.h> /* memset */
  84. #ifndef SOKOL_API_IMPL
  85. #define SOKOL_API_IMPL
  86. #endif
  87. #if defined(SOKOL_GFX_INCLUDED) && defined(SOKOL_APP_INCLUDED)
  88. SOKOL_API_IMPL sg_context_desc sapp_sgcontext(void) {
  89. sg_context_desc desc;
  90. memset(&desc, 0, sizeof(desc));
  91. desc.color_format = (sg_pixel_format) sapp_color_format();
  92. desc.depth_format = (sg_pixel_format) sapp_depth_format();
  93. desc.sample_count = sapp_sample_count();
  94. desc.metal.device = sapp_metal_get_device();
  95. desc.metal.renderpass_descriptor_cb = sapp_metal_get_renderpass_descriptor;
  96. desc.metal.drawable_cb = sapp_metal_get_drawable;
  97. desc.d3d11.device = sapp_d3d11_get_device();
  98. desc.d3d11.device_context = sapp_d3d11_get_device_context();
  99. desc.d3d11.render_target_view_cb = sapp_d3d11_get_render_target_view;
  100. desc.d3d11.depth_stencil_view_cb = sapp_d3d11_get_depth_stencil_view;
  101. desc.wgpu.device = sapp_wgpu_get_device();
  102. desc.wgpu.render_view_cb = sapp_wgpu_get_render_view;
  103. desc.wgpu.resolve_view_cb = sapp_wgpu_get_resolve_view;
  104. desc.wgpu.depth_stencil_view_cb = sapp_wgpu_get_depth_stencil_view;
  105. return desc;
  106. }
  107. #endif
  108. #endif /* SOKOL_GLUE_IMPL */