@@ -82,7 +82,7 @@ static bool ogl_lock_region_nonbb_writeonly(
82
82
int x , int gl_y , int w , int h , int real_format );
83
83
static bool ogl_lock_region_nonbb_readwrite (
84
84
ALLEGRO_BITMAP * bitmap , ALLEGRO_BITMAP_EXTRA_OPENGL * ogl_bitmap ,
85
- int x , int gl_y , int w , int h , int real_format );
85
+ int x , int gl_y , int w , int h , int real_format , bool * restore_fbo );
86
86
static bool ogl_lock_region_nonbb_readwrite_fbo (
87
87
ALLEGRO_BITMAP * bitmap , ALLEGRO_BITMAP_EXTRA_OPENGL * ogl_bitmap ,
88
88
int x , int gl_y , int w , int h , int real_format );
@@ -257,7 +257,9 @@ static ALLEGRO_LOCKED_REGION *ogl_lock_region_nonbb(ALLEGRO_BITMAP *bitmap,
257
257
const int gl_y = bitmap -> h - y - h ;
258
258
ALLEGRO_DISPLAY * disp ;
259
259
ALLEGRO_DISPLAY * old_disp = NULL ;
260
+ ALLEGRO_BITMAP * old_target = al_get_target_bitmap ();
260
261
bool ok ;
262
+ bool restore_fbo = false;
261
263
262
264
disp = al_get_current_display ();
263
265
@@ -300,10 +302,27 @@ static ALLEGRO_LOCKED_REGION *ogl_lock_region_nonbb(ALLEGRO_BITMAP *bitmap,
300
302
ALLEGRO_DEBUG ("Locking non-backbuffer %s\n" ,
301
303
(flags & ALLEGRO_LOCK_READONLY ) ? "READONLY" : "READWRITE" );
302
304
ok = ogl_lock_region_nonbb_readwrite (bitmap , ogl_bitmap ,
303
- x , gl_y , w , h , real_format );
305
+ x , gl_y , w , h , real_format , & restore_fbo );
306
+ }
307
+ }
308
+
309
+ /* Restore state after switching FBO. */
310
+ if (restore_fbo ) {
311
+ if (!old_target ) {
312
+ /* Old target was NULL; release the context. */
313
+ _al_set_current_display_only (NULL );
314
+ }
315
+ else if (!_al_get_bitmap_display (old_target )) {
316
+ /* Old target was memory bitmap; leave the current display alone. */
317
+ }
318
+ else if (old_target != bitmap ) {
319
+ /* Old target was another OpenGL bitmap. */
320
+ _al_ogl_setup_fbo (_al_get_bitmap_display (old_target ), old_target );
304
321
}
305
322
}
306
323
324
+ ASSERT (al_get_target_bitmap () == old_target );
325
+
307
326
if (old_disp != NULL ) {
308
327
_al_set_current_display_only (old_disp );
309
328
}
@@ -348,23 +367,20 @@ static bool ogl_lock_region_nonbb_writeonly(
348
367
349
368
static bool ogl_lock_region_nonbb_readwrite (
350
369
ALLEGRO_BITMAP * bitmap , ALLEGRO_BITMAP_EXTRA_OPENGL * ogl_bitmap ,
351
- int x , int gl_y , int w , int h , int real_format )
370
+ int x , int gl_y , int w , int h , int real_format , bool * restore_fbo )
352
371
{
353
- ALLEGRO_BITMAP * old_target ;
354
- bool fbo_was_set ;
355
372
bool ok ;
356
373
357
374
ASSERT (bitmap -> parent == NULL );
358
375
ASSERT (bitmap -> locked == false);
359
376
ASSERT (_al_get_bitmap_display (bitmap ) == al_get_current_display ());
360
377
361
378
/* Try to create an FBO if there isn't one. */
362
- old_target = al_get_target_bitmap ();
363
- fbo_was_set =
379
+ * restore_fbo =
364
380
_al_ogl_setup_fbo_non_backbuffer (_al_get_bitmap_display (bitmap ), bitmap );
365
381
366
382
/* Unlike in desktop GL, there seems to be nothing we can do without an FBO. */
367
- if (fbo_was_set && ogl_bitmap -> fbo_info ) {
383
+ if (* restore_fbo && ogl_bitmap -> fbo_info ) {
368
384
ok = ogl_lock_region_nonbb_readwrite_fbo (bitmap , ogl_bitmap ,
369
385
x , gl_y , w , h , real_format );
370
386
}
@@ -373,23 +389,6 @@ static bool ogl_lock_region_nonbb_readwrite(
373
389
ok = false;
374
390
}
375
391
376
- /* Restore state after switching FBO. */
377
- if (fbo_was_set ) {
378
- if (!old_target ) {
379
- /* Old target was NULL; release the context. */
380
- _al_set_current_display_only (NULL );
381
- }
382
- else if (!_al_get_bitmap_display (old_target )) {
383
- /* Old target was memory bitmap; leave the current display alone. */
384
- }
385
- else if (old_target != bitmap ) {
386
- /* Old target was another OpenGL bitmap. */
387
- _al_ogl_setup_fbo (_al_get_bitmap_display (old_target ), old_target );
388
- }
389
- }
390
-
391
- ASSERT (al_get_target_bitmap () == old_target );
392
-
393
392
return ok ;
394
393
}
395
394
0 commit comments