diff options
author | Brian Paul <[email protected]> | 2002-03-16 00:53:15 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2002-03-16 00:53:15 +0000 |
commit | 18a285a5e244b7405b85feb7315a30d99920ec5d (patch) | |
tree | 02fbfa95292ef56eef26bb2e8456f65cf1348f18 /src/mesa/drivers/x11/xm_dd.c | |
parent | 8d687e7e58a148f3f16573636023e54755372010 (diff) |
Lots of changes related to framebuffer/window buffer resizing. Basically,
instead of passing a GLcontext* to ResizeBuffers(), pass a GLframebuffer*.
The idea is that a window can be resized without it being bound to a rendering
context. This makes for a nice clean-up in the XFree86 server-side GLX code.
Renamed ctx->Driver.ResizeBuffersMESA() to ctx->Driver.ResizeBuffers().
Diffstat (limited to 'src/mesa/drivers/x11/xm_dd.c')
-rw-r--r-- | src/mesa/drivers/x11/xm_dd.c | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c index ec79f3c5149..642aee8a229 100644 --- a/src/mesa/drivers/x11/xm_dd.c +++ b/src/mesa/drivers/x11/xm_dd.c @@ -1,8 +1,8 @@ -/* $Id: xm_dd.c,v 1.29 2002/03/01 04:28:32 brianp Exp $ */ +/* $Id: xm_dd.c,v 1.30 2002/03/16 00:53:15 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 4.0.2 * * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. * @@ -48,17 +48,18 @@ /* - * Return the size (width,height of the current color buffer. - * This function should be called by the glViewport function because - * glViewport is often called when the window gets resized. We need to - * update some X/Mesa stuff when that happens. + * Return the size (width, height) of the X window for the given GLframebuffer. * Output: width - width of buffer in pixels. * height - height of buffer in pixels. */ static void -get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) +get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) { - const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + /* We can do this cast because the first field in the XMesaBuffer + * struct is a GLframebuffer struct. If this weren't true, we'd + * need a pointer from the GLframebuffer to the XMesaBuffer. + */ + const XMesaBuffer xmBuffer = (XMesaBuffer) buffer; unsigned int winwidth, winheight; #ifndef XFree86Server Window root; @@ -66,58 +67,19 @@ get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) unsigned int bw, d; _glthread_LOCK_MUTEX(_xmesa_lock); - XGetGeometry( xmesa->display, xmesa->xm_buffer->frontbuffer, &root, + XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontbuffer, &root, &winx, &winy, &winwidth, &winheight, &bw, &d ); _glthread_UNLOCK_MUTEX(_xmesa_lock); #else - - winwidth = xmesa->xm_buffer->frontbuffer->width; - winheight = xmesa->xm_buffer->frontbuffer->height; + /* XFree86 GLX renderer */ + winwidth = xmBuffer->frontbuffer->width; + winheight = xmBuffer->frontbuffer->height; #endif (void)kernel8; /* Muffle compiler */ *width = winwidth; *height = winheight; - - if ( winwidth!=xmesa->xm_buffer->width - || winheight!=xmesa->xm_buffer->height) { - xmesa->xm_buffer->width = winwidth; - xmesa->xm_buffer->height = winheight; - xmesa_alloc_back_buffer( xmesa->xm_buffer ); - } - - /* Needed by FLIP macro */ - xmesa->xm_buffer->bottom = (int) winheight - 1; - - if (xmesa->xm_buffer->backimage) { - /* Needed by PIXELADDR1 macro */ - xmesa->xm_buffer->ximage_width1 - = xmesa->xm_buffer->backimage->bytes_per_line; - xmesa->xm_buffer->ximage_origin1 - = (GLubyte *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width1 * (winheight-1); - - /* Needed by PIXELADDR2 macro */ - xmesa->xm_buffer->ximage_width2 - = xmesa->xm_buffer->backimage->bytes_per_line / 2; - xmesa->xm_buffer->ximage_origin2 - = (GLushort *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width2 * (winheight-1); - - /* Needed by PIXELADDR3 macro */ - xmesa->xm_buffer->ximage_width3 - = xmesa->xm_buffer->backimage->bytes_per_line; - xmesa->xm_buffer->ximage_origin3 - = (GLubyte *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width3 * (winheight-1); - - /* Needed by PIXELADDR4 macro */ - xmesa->xm_buffer->ximage_width4 = xmesa->xm_buffer->backimage->width; - xmesa->xm_buffer->ximage_origin4 - = (GLuint *) xmesa->xm_buffer->backimage->data - + xmesa->xm_buffer->ximage_width4 * (winheight-1); - } } @@ -780,10 +742,51 @@ clear_buffers( GLcontext *ctx, GLbitfield mask, } -static void -resize_buffers( GLcontext *ctx ) +/* + * When we detect that the user has resized the window this function will + * get called. Here we'll reallocate the back buffer, depth buffer, + * stencil buffer etc. to match the new window size. + */ +void +xmesa_resize_buffers( GLframebuffer *buffer ) { - _swrast_alloc_buffers( ctx ); + int height = (int) buffer->Height; + /* We can do this cast because the first field in the XMesaBuffer + * struct is a GLframebuffer struct. If this weren't true, we'd + * need a pointer from the GLframebuffer to the XMesaBuffer. + */ + XMesaBuffer xmBuffer = (XMesaBuffer) buffer; + + xmBuffer->width = buffer->Width; + xmBuffer->height = buffer->Height; + xmesa_alloc_back_buffer( xmBuffer ); + + /* Needed by FLIP macro */ + xmBuffer->bottom = height - 1; + + if (xmBuffer->backimage) { + /* Needed by PIXELADDR1 macro */ + xmBuffer->ximage_width1 = xmBuffer->backimage->bytes_per_line; + xmBuffer->ximage_origin1 = (GLubyte *) xmBuffer->backimage->data + + xmBuffer->ximage_width1 * (height-1); + + /* Needed by PIXELADDR2 macro */ + xmBuffer->ximage_width2 = xmBuffer->backimage->bytes_per_line / 2; + xmBuffer->ximage_origin2 = (GLushort *) xmBuffer->backimage->data + + xmBuffer->ximage_width2 * (height-1); + + /* Needed by PIXELADDR3 macro */ + xmBuffer->ximage_width3 = xmBuffer->backimage->bytes_per_line; + xmBuffer->ximage_origin3 = (GLubyte *) xmBuffer->backimage->data + + xmBuffer->ximage_width3 * (height-1); + + /* Needed by PIXELADDR4 macro */ + xmBuffer->ximage_width4 = xmBuffer->backimage->width; + xmBuffer->ximage_origin4 = (GLuint *) xmBuffer->backimage->data + + xmBuffer->ximage_width4 * (height-1); + } + + _swrast_alloc_buffers( buffer ); } #if 0 @@ -951,7 +954,7 @@ void xmesa_init_pointers( GLcontext *ctx ) ctx->Driver.Accum = _swrast_Accum; ctx->Driver.Bitmap = _swrast_Bitmap; ctx->Driver.Clear = clear_buffers; - ctx->Driver.ResizeBuffersMESA = resize_buffers; + ctx->Driver.ResizeBuffers = xmesa_resize_buffers; ctx->Driver.CopyPixels = _swrast_CopyPixels; ctx->Driver.DrawPixels = _swrast_DrawPixels; ctx->Driver.ReadPixels = _swrast_ReadPixels; |