Skip to content

Commit 2aa46d8

Browse files
committed
sokol_framebuffer.h: update documentation
1 parent 284680a commit 2aa46d8

1 file changed

Lines changed: 39 additions & 16 deletions

File tree

util/sokol_framebuffer.h

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@
9898
.rotate90 = true,
9999
});
100100
101+
You can define a sub-rectangle of the framebuffer to be rendered. For instance
102+
to only render the upper-left quadrant of a 320x256 framebuffer:
103+
104+
sfb_framebuffer fb = sfb_make_framebuffer(&(sfb_framebuffer_desc){
105+
.width = 512
106+
.height = 512,
107+
.format = SFB_FORMAT_PALETTE8,
108+
.prescale = 2,
109+
.rotate90 = true,
110+
.cliprect = {
111+
.x = 0,
112+
.y = 0,
113+
.width = 160,
114+
.height = 128,
115+
}
116+
});
117+
101118
Finally if you plan to render the framebuffer in a render pass with different
102119
properties than the default swapchain format, you'll need to provide
103120
a color- and depth-pixelformat and a sample count which matches the
@@ -169,16 +186,6 @@
169186
.pixels = SG_RANGE(pixels),
170187
});
171188
172-
You can also provide a cliprect here to only render a subsection of the
173-
frame buffer. For instance to only render the top-left quadrant of a
174-
320x256 framebuffer:
175-
176-
sfb_update(fb, &(sfb_update_desc){
177-
.pixels = SG_RANGE(pixels),
178-
.palette = SG_RANGE(palette),
179-
.cliprect = { .x = 0, .y = 0, .width = 160, .height = 128 },
180-
});
181-
182189
The sfb_update() function will do up to two calls to the sokol-gfx
183190
function sg_update_image() - once for the pixel data and once for the
184191
palette data (this is why the function must only be called at most
@@ -215,13 +222,27 @@
215222
216223
TODO: refer to a future sokol_crt.h header.
217224
225+
If any of the sizing properties of the framebuffer changes, call:
226+
227+
bool size_changed = sfb_resize(fb, &(sfb_resize_desc){
228+
.width = new_width,
229+
.height = new_height,
230+
.prescale = new_prescale,
231+
.cliprect = new_cliprect
232+
});
233+
234+
The sfb_resize() function is 'lazy', it will only destroy and recreate internal
235+
objects when actually needed (e.g. the size of image objects has changed). In
236+
that case, true is returned. When the function returns false, it was
237+
basically a cheap no-op.
238+
218239
If you want to do the final rendering entirely yourself you can get handles
219240
to all the internally used resources of a framebuffer object via:
220241
221242
sfb_framebuffer_info info = sfb_query_framebuffer_info(fb);
222243
223-
This gives you the internally managed sokol-gfx image and view object handles
224-
for use in your own rendering.
244+
This returns handles to all internal image, view and sampler objects
245+
as well as image sizes and pixel formats.
225246
226247
To query the current 'resource state' of a framebuffer:
227248
@@ -346,7 +367,8 @@ typedef enum sfb_format {
346367
/*
347368
sfb_rect
348369
349-
Used as clipping rectangle in struct sfb_update_desc.
370+
Used as clipping rectangle in struct sfb_framebuffer_desc
371+
and sfb_resize_desc.
350372
*/
351373
typedef struct sfb_rect {
352374
int x;
@@ -453,9 +475,10 @@ typedef struct sfb_texture_info {
453475
sfb_framebuffer_info
454476
455477
Result of sfb_query_framebuffer_info(), returns handles to the internally
456-
managed images, texture views and samplers. This is mostly useful when completely
457-
replacing the sfb_render[_ex]() functions with a complete custom implementation
458-
(like a CRT shader which requires multiple render passes).
478+
managed images, texture views and samplers, image sizes and pixel formats.
479+
This is mostly useful when completely replacing the sfb_render[_ex]()
480+
functions with a complete custom implementation (like a CRT shader which
481+
requires multiple render passes).
459482
*/
460483
typedef struct sfb_framebuffer_info {
461484
sfb_texture_info update; // properties of the internal update texture

0 commit comments

Comments
 (0)