PDA

View Full Version : Canvas flushing



Judas
11-06-2012, 10:00 PM
The problem:

In ClanLib 2.3 the active RenderBatch was managed by GraphicContext and has now been moved to Canvas along with the rest of the higher level 2D functionality. Unfortunately this means applications has to call flush() before flip().

A possible solution:

We could move the active RenderBatch back to GraphicContext, along with flush() and set_batcher(batcher). That would allow flip() to call flush() before the flip like in the 2.3 series.

However, unlike 2.3 GraphicContext will no longer call flush() automatically when you do lower level graphics operations. If an application decides to do its own lower level operations it is responsible for calling flush() first. This has the advantage over 2.3 that we get no overhead from the constant 'is batched flushed' checks we had earlier. It also means that apps working only at the higher 2D level does not have to be aware of batcher flushing.

This change would also require that RenderBatcher::matrix_changed(modelview, projection) is removed. This shouldn't be a big problem since the batchers are all known by Canvas and can just be told directly if the 2D mapping logic is modified.

rombust
11-07-2012, 08:27 PM
An alternative is:


void Canvas::flip(DisplayWindow &window, int param)
{
flush();
if (window.is_null())
throw Exception("What no window!");
window.flip(param)
}

And, if the display window is provided as a constructor parameter (thus is known):


void Canvas::flip(int param)
{
flush()
if (display_window.is_null())
throw Exception("I can't see through the window");
display_window.flip(param);
}

The last method has the advantage that the application does not have to keep "DisplayWindow" around, can can just use the canvas (after initialisation)

rombust
11-08-2012, 11:31 AM
Until a decision is made (and someone codes it)....

I have patched ClanLib 3.0 as follows:

1) Canvas now stores to display window, is it was provided it, in the constructor.

2) Added:


Canvas::Canvas(DisplayWindowDescription &desc)
{
DisplayWindow window(desc);
*this = Canvas(window);
}

3) Added:


void Canvas::flip(int interval)
{
if (impl->display_window.is_null())
throw Exception("The display window is not known to this canvas");
flush();
impl->display_window.flip(interval);
}


4) For completeness, added:


void Canvas::flip(DisplayWindow &window, int interval)
{
window.throw_if_null();
flush();
window.flip(interval);
}

5) The Basic2D example now contains:


Canvas canvas(desc);
Slot slot_quit = canvas.get_window().sig_window_close().connect(thi s, &Basic2D::on_window_close);
...
canvas.flip(1);