Debian Codegraph @

sokol/sokol_glue.h

raw symbols SCIP
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
8 Project URL: https://github.com/floooh/sokol
9
10 Do this:
11 #define SOKOL_IMPL or
12 #define SOKOL_GLUE_IMPL
13 before you include this file in *one* C or C++ file to create the
14 implementation.
15
16 ...optionally provide the following macros to override defaults:
17
18 SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
19 SOKOL_GLUE_API_DECL - public function declaration prefix (default: extern)
20 SOKOL_API_DECL - same as SOKOL_GLUE_API_DECL
21 SOKOL_API_IMPL - public function implementation prefix (default: -)
22
23 If sokol_glue.h is compiled as a DLL, define the following before
24 including the declaration or implementation:
25
26 SOKOL_DLL
27
28 On Windows, SOKOL_DLL will define SOKOL_GLUE_API_DECL as __declspec(dllexport)
29 or __declspec(dllimport) as needed.
30
31 OVERVIEW
32 ========
33 sokol_glue.h provides glue helper functions between sokol_gfx.h and sokol_app.h,
34 so that sokol_gfx.h doesn't need to depend on sokol_app.h but can be
35 used with different window system glue libraries.
36
37 PROVIDED FUNCTIONS
38 ==================
39
40 sg_environment sglue_environment(void)
41
42 Returns an sg_environment struct initialized by calling sokol_app.h
43 functions. Use this in the sg_setup() call like this:
44
45 sg_setup(&(sg_desc){
46 .environment = sglue_environment(),
47 ...
48 });
49
50 sg_swapchain sglue_swapchain(void)
51
52 Returns an sg_swapchain struct initialized by calling sokol_app.h
53 functions. Use this in sg_begin_pass() for a 'swapchain pass' like
54 this:
55
56 sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain(), ... });
57
58 LICENSE
59 =======
60 zlib/libpng license
61
62 Copyright (c) 2018 Andre Weissflog
63
64 This software is provided 'as-is', without any express or implied warranty.
65 In no event will the authors be held liable for any damages arising from the
66 use of this software.
67
68 Permission is granted to anyone to use this software for any purpose,
69 including commercial applications, and to alter it and redistribute it
70 freely, subject to the following restrictions:
71
72 1. The origin of this software must not be misrepresented; you must not
73 claim that you wrote the original software. If you use this software in a
74 product, an acknowledgment in the product documentation would be
75 appreciated but is not required.
76
77 2. Altered source versions must be plainly marked as such, and must not
78 be misrepresented as being the original software.
79
80 3. This notice may not be removed or altered from any source
81 distribution.
82 */
83 #define SOKOL_GLUE_INCLUDED
84
85 #if defined(SOKOL_API_DECL) && !defined(SOKOL_GLUE_API_DECL)
86 #define SOKOL_GLUE_API_DECL SOKOL_API_DECL
87 #endif
88 #ifndef SOKOL_GLUE_API_DECL
89 #if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GLUE_IMPL)
90 #define SOKOL_GLUE_API_DECL __declspec(dllexport)
91 #elif defined(_WIN32) && defined(SOKOL_DLL)
92 #define SOKOL_GLUE_API_DECL __declspec(dllimport)
93 #else
94 #define SOKOL_GLUE_API_DECL extern
95 #endif
96 #endif
97
98 #ifndef SOKOL_GFX_INCLUDED
99 #error "Please include sokol_gfx.h before sokol_glue.h"
100 #endif
101
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105
106 SOKOL_GLUE_API_DECL sg_environment sglue_environment(void);
107 SOKOL_GLUE_API_DECL sg_swapchain sglue_swapchain(void);
108
109 #ifdef __cplusplus
110 } /* extern "C" */
111 #endif
112 #endif /* SOKOL_GLUE_INCLUDED */
113
114 /*-- IMPLEMENTATION ----------------------------------------------------------*/
115 #ifdef SOKOL_GLUE_IMPL
116 #define SOKOL_GLUE_IMPL_INCLUDED (1)
117 #include <string.h> /* memset */
118
119 #ifndef SOKOL_APP_INCLUDED
120 #error "Please include sokol_app.h before the sokol_glue.h implementation"
121 #endif
122
123 #ifndef SOKOL_API_IMPL
124 #define SOKOL_API_IMPL
125 #endif
126
127
128 SOKOL_API_IMPL sg_environment sglue_environment(void) {
129 sg_environment env;
130 memset(&env, 0, sizeof(env));
131 env.defaults.color_format = (sg_pixel_format) sapp_color_format();
132 env.defaults.depth_format = (sg_pixel_format) sapp_depth_format();
133 env.defaults.sample_count = sapp_sample_count();
134 env.metal.device = sapp_metal_get_device();
135 env.d3d11.device = sapp_d3d11_get_device();
136 env.d3d11.device_context = sapp_d3d11_get_device_context();
137 env.wgpu.device = sapp_wgpu_get_device();
138 return env;
139 }
140
141 SOKOL_API_IMPL sg_swapchain sglue_swapchain(void) {
142 sg_swapchain swapchain;
143 memset(&swapchain, 0, sizeof(swapchain));
144 swapchain.width = sapp_width();
145 swapchain.height = sapp_height();
146 swapchain.sample_count = sapp_sample_count();
147 swapchain.color_format = (sg_pixel_format)sapp_color_format();
148 swapchain.depth_format = (sg_pixel_format)sapp_depth_format();
149 swapchain.metal.current_drawable = sapp_metal_get_current_drawable();
150 swapchain.metal.depth_stencil_texture = sapp_metal_get_depth_stencil_texture();
151 swapchain.metal.msaa_color_texture = sapp_metal_get_msaa_color_texture();
152 swapchain.d3d11.render_view = sapp_d3d11_get_render_view();
153 swapchain.d3d11.resolve_view = sapp_d3d11_get_resolve_view();
154 swapchain.d3d11.depth_stencil_view = sapp_d3d11_get_depth_stencil_view();
155 swapchain.wgpu.render_view = sapp_wgpu_get_render_view();
156 swapchain.wgpu.resolve_view = sapp_wgpu_get_resolve_view();
157 swapchain.wgpu.depth_stencil_view = sapp_wgpu_get_depth_stencil_view();
158 swapchain.gl.framebuffer = sapp_gl_get_framebuffer();
159 return swapchain;
160 }
161
162 #endif /* SOKOL_GLUE_IMPL */