|
98 | 98 | .rotate90 = true, |
99 | 99 | }); |
100 | 100 |
|
| 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 | +
|
101 | 118 | Finally if you plan to render the framebuffer in a render pass with different |
102 | 119 | properties than the default swapchain format, you'll need to provide |
103 | 120 | a color- and depth-pixelformat and a sample count which matches the |
|
169 | 186 | .pixels = SG_RANGE(pixels), |
170 | 187 | }); |
171 | 188 |
|
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 | | -
|
182 | 189 | The sfb_update() function will do up to two calls to the sokol-gfx |
183 | 190 | function sg_update_image() - once for the pixel data and once for the |
184 | 191 | palette data (this is why the function must only be called at most |
|
215 | 222 |
|
216 | 223 | TODO: refer to a future sokol_crt.h header. |
217 | 224 |
|
| 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 | +
|
218 | 239 | If you want to do the final rendering entirely yourself you can get handles |
219 | 240 | to all the internally used resources of a framebuffer object via: |
220 | 241 |
|
221 | 242 | sfb_framebuffer_info info = sfb_query_framebuffer_info(fb); |
222 | 243 |
|
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. |
225 | 246 |
|
226 | 247 | To query the current 'resource state' of a framebuffer: |
227 | 248 |
|
@@ -346,7 +367,8 @@ typedef enum sfb_format { |
346 | 367 | /* |
347 | 368 | sfb_rect |
348 | 369 |
|
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. |
350 | 372 | */ |
351 | 373 | typedef struct sfb_rect { |
352 | 374 | int x; |
@@ -453,9 +475,10 @@ typedef struct sfb_texture_info { |
453 | 475 | sfb_framebuffer_info |
454 | 476 |
|
455 | 477 | 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). |
459 | 482 | */ |
460 | 483 | typedef struct sfb_framebuffer_info { |
461 | 484 | sfb_texture_info update; // properties of the internal update texture |
|
0 commit comments