1 /++
2 + Machine generated D bindings for Sokol library.
3 + 
4 +     Source header: sokol_framebuffer.h
5 +     Module: sokol.framebuffer
6 + 
7 +     Do not edit manually; regenerate using gen_d.py.
8 +/
9 module sokol.framebuffer;
10 import sg = sokol.gfx;
11 
12 /++
13 + Public constants.
14 +/
15 enum invalid_id = 0;
16 /++
17 + sfb_framebuffer
18 + 
19 +     A framebuffer handle, created with sfb_make_framebuffer(), destroyed
20 +     with sfb_destroy_framebuffer()
21 +/
22 extern(C) struct Framebuffer {
23     uint id = 0;
24 }
25 /++
26 + sfb_resource_state
27 + 
28 +     The state of a framebuffer object, obtainable via sfb_query_framebuffer_state().
29 +     Publicly visible values are only SFB_RESOURCESTATE_VALID
30 +     and SFB_RESOURCESTATE_FAILED.
31 +/
32 enum ResourceState {
33     Initial,
34     Alloc,
35     Valid,
36     Failed,
37     Invalid,
38 }
39 /++
40 + sfb_format
41 + 
42 +     The framebuffer pixel format. Either RGBA8 direct color where each
43 +     pixel is an uint32_t, or paletted format with uint8_t pixels as
44 +     index into a 256 entry color palette.
45 +/
46 enum Format {
47     Default = 0,
48     Rgba8,
49     Palette8,
50 }
51 /++
52 + sfb_rect
53 + 
54 +     Used as clipping rectangle in struct sfb_framebuffer_desc
55 +     and sfb_resize_desc.
56 +/
57 extern(C) struct Rect {
58     int x = 0;
59     int y = 0;
60     int width = 0;
61     int height = 0;
62 }
63 /++
64 + sfb_render_pass_desc
65 + 
66 +     Describes render pass properties in an sfb_framebuffer_desc (color-
67 +     and depth-pixel-format, sample count). This is used to create the
68 +     sg_pipeline objects applied in the render functions. When rendering
69 +     to a default swapchain all the values can remain at default (zero).
70 +/
71 extern(C) struct RenderPassDesc {
72     sg.PixelFormat color_format = sg.PixelFormat.Default;
73     sg.PixelFormat depth_format = sg.PixelFormat.Default;
74     int sample_count = 0;
75 }
76 /++
77 + sfb_framebuffer_desc
78 + 
79 +     Creation parameters for a framebuffer object. Passed into
80 +     sfb_make_framebuffer().
81 +/
82 extern(C) struct FramebufferDesc {
83     int width = 0;
84     int height = 0;
85     int prescale = 0;
86     Format format = Format.Default;
87     Rect cliprect = {};
88     bool rotate90 = false;
89     RenderPassDesc render_pass = {};
90 }
91 /++
92 + sfb_resize_desc
93 + 
94 +     Parameters for sfb_resize(). Needs to be called before sfb_update() in a
95 +     frame if with potentially new framebuffer size parameters or clipping
96 +     rectangle. Note that the sfb_resize() function can be called even when no
97 +     resizing needs to happen, in that case the function will be a silent no-op
98 +     and return false. When the function returns true this means that internal
99 +     image objects had been recreated and need to be repopulated again via
100 +     sfb_update()
101 + 
102 +     Resizing is slightly cheaper than destroying and creating the frambuffer
103 +     because only image objects needs to be re-created, but no pipeline objects.
104 +/
105 extern(C) struct ResizeDesc {
106     int width = 0;
107     int height = 0;
108     int prescale = 0;
109     Rect cliprect = {};
110 }
111 /++
112 + sfb_update_desc
113 + 
114 +     Passed into sfb_update() to update the pixel-date and/or color-palette-data
115 +     The sfb_update() function should only be called when any of the above
116 +     actually changes, at most once per frame, and outside any sokol-gfx pass.
117 +/
118 extern(C) struct UpdateDesc {
119     sg.Range pixels = {};
120     sg.Range palette = {};
121 }
122 /++
123 + sfb_render_overrides
124 + 
125 +     Passed into sfb_render_ex() to override the default shader. Mainly
126 +     useful to inject custom shaders (like CRT shaders).
127 + 
128 +     TODO: add more details once sokol_crt.h is ready.
129 +/
130 extern(C) struct RenderDesc {
131     bool use_nearest_filter = false;
132     sg.Pipeline pip = {};
133     sg.View[32] views = [];
134     sg.Sampler[14] samplers = [];
135     sg.Range[8] uniforms = [];
136 }
137 /++
138 + sfb_texture_info
139 + 
140 +     Nested struct in sfb_framebuffer_info to describe the properties of
141 +     an internal image/view pair.
142 +/
143 extern(C) struct TextureInfo {
144     int width = 0;
145     int height = 0;
146     sg.PixelFormat pixel_format = sg.PixelFormat.Default;
147     sg.Image image = {};
148     sg.View tex_view = {};
149 }
150 /++
151 + sfb_framebuffer_info
152 + 
153 +     Result of sfb_query_framebuffer_info(), returns handles to the internally
154 +     managed images, texture views and samplers, image sizes and pixel formats.
155 +     This is mostly useful when completely replacing the sfb_render[_ex]()
156 +     functions with a complete custom implementation (like a CRT shader which
157 +     requires multiple render passes).
158 +/
159 extern(C) struct FramebufferInfo {
160     TextureInfo update = {};
161     TextureInfo offscreen = {};
162     TextureInfo palette = {};
163     sg.Sampler nearest_sampler = {};
164     sg.Sampler linear_sampler = {};
165 }
166 /++
167 + sfb_allocator
168 + 
169 +     Used in sfb_desc to provide custom memory-alloc and -free functions
170 +     to sokol_framebuffer.h. If memory management should be overridden, both the
171 +     alloc and free function must be provided (e.g. it's not valid to
172 +     override one function but not the other).
173 +/
174 extern(C) struct Allocator {
175     extern(C) void* function(size_t, void*) alloc_fn = null;
176     extern(C) void function(void*, void*) free_fn = null;
177     void* user_data = null;
178 }
179 /++
180 + sfb_logger
181 + 
182 +     Used in sfb_desc to provide a custom logging and error reporting
183 +     callback to sokol_framebuffer.h.
184 +/
185 extern(C) struct Logger {
186     extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null;
187     void* user_data = null;
188 }
189 /++
190 + Initialization parameters passed into sfb_setup(). You should at least
191 +     provide a logging function, otherwise you won't see any error logging.
192 +/
193 extern(C) struct Desc {
194     int framebuffer_pool_size = 0;
195     Allocator allocator = {};
196     Logger logger = {};
197 }
198 /++
199 + setup sokol-framebuffer
200 +/
201 extern(C) void sfb_setup(const Desc* desc) @system @nogc nothrow pure;
202 void setup(scope ref Desc desc) @trusted @nogc nothrow pure {
203     sfb_setup(&desc);
204 }
205 /++
206 + shutdown sokol-framebuffer
207 +/
208 extern(C) void sfb_shutdown() @system @nogc nothrow pure;
209 void shutdown() @trusted @nogc nothrow pure {
210     sfb_shutdown();
211 }
212 /++
213 + create a framebuffer object
214 +/
215 extern(C) Framebuffer sfb_make_framebuffer(const FramebufferDesc* desc) @system @nogc nothrow pure;
216 Framebuffer makeFramebuffer(scope ref FramebufferDesc desc) @trusted @nogc nothrow pure {
217     return sfb_make_framebuffer(&desc);
218 }
219 /++
220 + destroy framebuffer object
221 +/
222 extern(C) void sfb_destroy_framebuffer(Framebuffer fb) @system @nogc nothrow pure;
223 void destroyFramebuffer(Framebuffer fb) @trusted @nogc nothrow pure {
224     sfb_destroy_framebuffer(fb);
225 }
226 /++
227 + resize internal images (no-op if resize isn't needed), return true when images had to be re-created
228 +/
229 extern(C) bool sfb_resize(Framebuffer fb, const ResizeDesc* desc) @system @nogc nothrow pure;
230 bool resize(Framebuffer fb, scope ref ResizeDesc desc) @trusted @nogc nothrow pure {
231     return sfb_resize(fb, &desc);
232 }
233 /++
234 + update framebuffer and/or color palette content (must be called outside any sokol-gfx pass)
235 +/
236 extern(C) void sfb_update(Framebuffer fb, const UpdateDesc* desc) @system @nogc nothrow pure;
237 void update(Framebuffer fb, scope ref UpdateDesc desc) @trusted @nogc nothrow pure {
238     sfb_update(fb, &desc);
239 }
240 /++
241 + draw framebuffer content with default shader (must be called inside a sokol-gfx render pass)
242 +/
243 extern(C) void sfb_render(Framebuffer fb) @system @nogc nothrow pure;
244 void render(Framebuffer fb) @trusted @nogc nothrow pure {
245     sfb_render(fb);
246 }
247 /++
248 + draw framebuffer content with injected shader (must be called inside a sokol-gfx render pass)
249 +/
250 extern(C) void sfb_render_ex(Framebuffer fb, const RenderDesc* desc) @system @nogc nothrow pure;
251 void renderEx(Framebuffer fb, scope ref RenderDesc desc) @trusted @nogc nothrow pure {
252     sfb_render_ex(fb, &desc);
253 }
254 /++
255 + query framebuffer resource state (valid or failed)
256 +/
257 extern(C) ResourceState sfb_query_framebuffer_state(Framebuffer fb) @system @nogc nothrow pure;
258 ResourceState queryFramebufferState(Framebuffer fb) @trusted @nogc nothrow pure {
259     return sfb_query_framebuffer_state(fb);
260 }
261 /++
262 + query current framebuffer properties
263 +/
264 extern(C) FramebufferInfo sfb_query_framebuffer_info(Framebuffer fb) @system @nogc nothrow pure;
265 FramebufferInfo queryFramebufferInfo(Framebuffer fb) @trusted @nogc nothrow pure {
266     return sfb_query_framebuffer_info(fb);
267 }
268 /++
269 + query the framebuffer desc, with default values patched in
270 +/
271 extern(C) FramebufferDesc sfb_query_framebuffer_desc(Framebuffer fb) @system @nogc nothrow pure;
272 FramebufferDesc queryFramebufferDesc(Framebuffer fb) @trusted @nogc nothrow pure {
273     return sfb_query_framebuffer_desc(fb);
274 }