Brian Paul | 4 May 2004 01:46

Re: ctx->Driver.ResizeBuffers

tomas carnecky wrote:
> hi folks,
> 
> when (in which cases) is this function called?
> I think that mesa shouldn't manage the buffers. The buffers are 
> allocated by X or any other window (buffer) manager. The window manager 
> provides the buffers, and they also are resized/allocated by the WM.
> What's the purpose of this function?

Matt's pretty much explained things, but I'll give it a shot too, just 
to be complete.

When an X window is resized we need to reallocate the corresponding 
back color buffer, depth buffer, stencil buffer, accumulation buffer, 
etc.  That's pretty obvious, right?

The problem (with X and probably any other window system) is that Mesa 
isn't notified when a window is resized.  The only way an X client 
(which is what stand-alone Mesa is) can be notified of window size 
changes is by calling XGetEvent() (or similar) and looking for 
ConfigureNotify events.  Unfortunately, we can't do this in Mesa's 
Xlib driver since it has no event loop.

So instead, we poll the window system occasionally to get the current 
window size.  If the current size doesn't match Mesa's notion of the 
current size, we resize the depth/stencil/accum/etc buffers to match 
what the window system reported.

Now, the question is: when should Mesa poll for window size changes? 
Well, 99% or so of all OpenGL applications just happen to call 
glViewport() when a window is resized.  glClear() could be another 
good place to poll.

So, in Mesa's _mesa_set_viewport() function, we call the 
_mesa_ResizeBuffers() function which calls ctx->Driver.GetBufferSize() 
and then ctx->Driver.ResizeBuffers() if needed.  The last function 
pointer usually points at _swrast_alloc_buffers().  That function 
reallocates the software depth/stencil/accum/etc buffers.

Admittedly, this is a bit ugly, but it's worked great for years. 
Since Matt's brought it up though, I've been thinking of changing this 
a bit.

Perhaps we should leave it entirely up to the device drivers to do the 
polling and buffer resizing.  The drivers would have to implement a 
viewport function (called by ctx->Driver.Viewport()) which would take 
care of things.  Alternately, the driver could do it in its Clear() 
function if that's simpler.

Comments?

-Brian

PS: Tomas, your emails are dated 01/01/2001.  Maybe you need to set 
your clock.

-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE. 
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click

Gmane