[AD] Making the projection transform bitmap local

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


The projection transform being display-local has been a wart in Allegro for quite a long time. Unlike every other global state, the projection transform was extremely volatile... if you looked at Allegro wrong, it would reset it to orthographic... the only practical way of using it is to reset it to the desired transformation pretty much all the time before drawing. There is in fact a bug about this http://sourceforge.net/p/alleg/bugs/349/ submitted by myself 3 years ago which involved the font addon not properly restoring it after it was clobbered by an intra-addon al_set_target_bitmap call.

After a year of on and off work (it wasn't a priority), I managed to change it to be a bitmap local state. Now, it is acts essentially the same as the regular bitmap transform, and it preserves its set value at in all situations except two:

- The backbuffer bitmap's projection transform reverts back to orthographic when it is resized (simultaneously with the al_acknowledge_resize call). - A video bitmap's projection transform reverts back to orthographic when it is converted to a memory bitmap (those only support orthographic transforms).

I think it works pretty good, actually and resulted in some simplification in the internals' code. Some other benefits of this change include these projection transforms actually working properly for sub-bitmaps (they did not work reliably before this change).

This mostly affects people who use projection transforms (naturally), but it also affects people who don't in the following way:

- iOS now sends the resize events somewhat more often (this shouldn't be a big issue) - Android now sends a resize event after ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING. This is to allow ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING event to not change the backbuffer's transform (instead, the user simply needs to handle the resize event and everything will happen automagically).

Obviously, as this touched some hairy code, this might introduce some bugs, but I've tested this somewhat extensively on all our core platforms (except a physical iOS device... I don't have one, so I could only use the simulator).

Check out the implementation here: https://github.com/liballeg/allegro5/pull/13

And in patch form: https://github.com/liballeg/allegro5/pull/13.patch

Some migration notes:

al_get_projection_transform(display)

changes approximately to (might need to insert a al_set_target_bitmap() call):

al_get_current_projection_transform()


al_set_projection_transform(display, &trans)

changes approximately to (might need to insert a al_set_target_bitmap() call):

al_use_projection_transform(&trans)

That said, in principle you should be able to remove many al_set_projection_transform calls altogether if all you were doing is resetting them every frame. Now you can just set it and forget it (except for the two cases outlined above).

Some implementation notes:

The display retains a cached 'projview' transform for the purposes of shaders, but otherwise everything is set up in the update_transformation method in the ALLEGRO_DISPLAY_INTERFACE.

-SL




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/