/*
* Mesa 3-D graphics library
- * Version: 6.1
+ * Version: 6.3
*
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
#include "glxheader.h"
#include "bufferobj.h"
+#include "buffers.h"
#include "context.h"
#include "colormac.h"
#include "depth.h"
#include "drawpix.h"
#include "extensions.h"
#include "macros.h"
+#include "image.h"
#include "imports.h"
#include "mtypes.h"
#include "state.h"
#include "xmesaP.h"
#include "array_cache/acache.h"
#include "swrast/swrast.h"
+#include "swrast/s_auxbuffer.h"
#include "swrast/s_context.h"
-#include "swrast/s_drawpix.h"
#include "swrast/s_alphabuf.h"
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
unsigned int winwidth, winheight;
#ifdef XFree86Server
/* XFree86 GLX renderer */
- if (xmBuffer->frontbuffer->width > MAX_WIDTH ||
- xmBuffer->frontbuffer->height > MAX_HEIGHT) {
- winwidth = buffer->Width;
- winheight = buffer->Height;
- } else {
- winwidth = xmBuffer->frontbuffer->width;
- winheight = xmBuffer->frontbuffer->height;
- }
+ winwidth = MIN2(xmBuffer->frontbuffer->width, MAX_WIDTH);
+ winheight = MIN2(xmBuffer->frontbuffer->height, MAX_HEIGHT);
#else
Window root;
int winx, winy;
/*
* Now determine front vs back color buffer.
*/
- if (bufferBit == FRONT_LEFT_BIT) {
+ if (bufferBit == DD_FRONT_LEFT_BIT) {
target->buffer = target->frontbuffer;
+ xmesa_update_span_funcs(ctx);
}
- else if (bufferBit == BACK_LEFT_BIT) {
+ else if (bufferBit == DD_BACK_LEFT_BIT) {
ASSERT(target->db_state);
if (target->backpixmap) {
/* back buffer is a pixmap */
/* No back buffer!!!! Must be out of memory, use front buffer */
target->buffer = target->frontbuffer;
}
+ xmesa_update_span_funcs(ctx);
}
+ else if (bufferBit & (DD_AUX0_BIT | DD_AUX1_BIT | DD_AUX2_BIT | DD_AUX3_BIT)) {
+ _swrast_use_aux_buffer(ctx, buffer, bufferBit);
+ }
else {
_mesa_problem(ctx, "invalid buffer 0x%x in set_buffer() in xm_dd.c");
return;
}
- xmesa_update_span_funcs(ctx);
}
XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->frontbuffer,
xmesa->xm_draw_buffer->cleargc,
0, 0,
- xmesa->xm_draw_buffer->width+1,
- xmesa->xm_draw_buffer->height+1 );
+ xmesa->xm_draw_buffer->mesa_buffer.Width + 1,
+ xmesa->xm_draw_buffer->mesa_buffer.Height + 1 );
}
else {
XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->frontbuffer,
xmesa->xm_draw_buffer->cleargc,
- x, xmesa->xm_draw_buffer->height - y - height,
+ x, xmesa->xm_draw_buffer->mesa_buffer.Height - y - height,
width, height );
}
}
XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->backpixmap,
xmesa->xm_draw_buffer->cleargc,
0, 0,
- xmesa->xm_draw_buffer->width+1,
- xmesa->xm_draw_buffer->height+1 );
+ xmesa->xm_draw_buffer->mesa_buffer.Width + 1,
+ xmesa->xm_draw_buffer->mesa_buffer.Height + 1 );
}
else {
XMesaFillRectangle( xmesa->display, xmesa->xm_draw_buffer->backpixmap,
xmesa->xm_draw_buffer->cleargc,
- x, xmesa->xm_draw_buffer->height - y - height,
+ x, xmesa->xm_draw_buffer->mesa_buffer.Height - y - height,
width, height );
}
}
if ((pixel & 0xff) == ((pixel >> 8) & 0xff)) {
/* low and high bytes are equal so use memset() */
n = xmesa->xm_draw_buffer->backimage->bytes_per_line
- * xmesa->xm_draw_buffer->height;
+ * xmesa->xm_draw_buffer->mesa_buffer.Height;
MEMSET( ptr4, pixel & 0xff, n );
}
else {
pixel = pixel | (pixel<<16);
n = xmesa->xm_draw_buffer->backimage->bytes_per_line
- * xmesa->xm_draw_buffer->height / 4;
+ * xmesa->xm_draw_buffer->mesa_buffer.Height / 4;
do {
*ptr4++ = pixel;
n--;
} while (n!=0);
if ((xmesa->xm_draw_buffer->backimage->bytes_per_line *
- xmesa->xm_draw_buffer->height) & 0x2)
+ xmesa->xm_draw_buffer->mesa_buffer.Height) & 0x2)
*(GLushort *)ptr4 = pixel & 0xffff;
}
}
if (all) {
if (r==g && g==b) {
/* same value for all three components (gray) */
- const GLint w3 = xmesa->xm_draw_buffer->width * 3;
- const GLint h = xmesa->xm_draw_buffer->height;
+ const GLint w3 = xmesa->xm_draw_buffer->mesa_buffer.Width * 3;
+ const GLint h = xmesa->xm_draw_buffer->mesa_buffer.Height;
GLint i;
for (i = 0; i < h; i++) {
bgr_t *ptr3 = PIXELADDR3(xmesa->xm_draw_buffer, 0, i);
}
else {
/* the usual case */
- const GLint w = xmesa->xm_draw_buffer->width;
- const GLint h = xmesa->xm_draw_buffer->height;
+ const GLint w = xmesa->xm_draw_buffer->mesa_buffer.Width;
+ const GLint h = xmesa->xm_draw_buffer->mesa_buffer.Height;
GLint i, j;
for (i = 0; i < h; i++) {
bgr_t *ptr3 = PIXELADDR3(xmesa->xm_draw_buffer, 0, i);
| ((pixel << 24) & 0xff000000);
}
if (all) {
- register GLint n = xmesa->xm_draw_buffer->width * xmesa->xm_draw_buffer->height;
+ register GLint n = xmesa->xm_draw_buffer->mesa_buffer.Width
+ * xmesa->xm_draw_buffer->mesa_buffer.Height;
register GLuint *ptr4 = (GLuint *) xmesa->xm_draw_buffer->backimage->data;
if (pixel==0) {
MEMSET( ptr4, pixel, 4*n );
{
const XMesaContext xmesa = XMESA_CONTEXT(ctx);
XMesaImage *img = xmesa->xm_draw_buffer->backimage;
- if (all) {
- register int i, j;
- width = xmesa->xm_draw_buffer->width;
- height = xmesa->xm_draw_buffer->height;
- for (j=0;j<height;j++) {
- for (i=0;i<width;i++) {
- XMesaPutPixel( img, i, j, xmesa->clearpixel );
- }
- }
- }
- else {
- /* TODO: optimize this */
- register int i, j;
- y = FLIP(xmesa->xm_draw_buffer, y);
- for (j=0;j<height;j++) {
- for (i=0;i<width;i++) {
- XMesaPutPixel( img, x+i, y-j, xmesa->clearpixel );
- }
+ register int i, j;
+
+ /* We can ignore 'all' here - x, y, width, height are always right */
+ (void) all;
+
+ /* TODO: optimize this */
+ y = FLIP(xmesa->xm_draw_buffer, y);
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
+ XMesaPutPixel(img, x+i, y-j, xmesa->clearpixel);
}
}
}
* 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.
+ * The buffer->Width and buffer->Height values will indicate the new size.
*/
void
xmesa_resize_buffers( GLframebuffer *buffer )
*/
XMesaBuffer xmBuffer = (XMesaBuffer) buffer;
- xmBuffer->width = buffer->Width;
- xmBuffer->height = buffer->Height;
xmesa_alloc_back_buffer( xmBuffer );
/* Needed by FLIP macro */
int srcX = unpack->SkipPixels;
int srcY = unpack->SkipRows;
int rowLength = unpack->RowLength ? unpack->RowLength : width;
- if (_swrast_clip_pixelrect(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
+
+ if (unpack->BufferObj->Name) {
+ /* unpack from PBO */
+ GLubyte *buf;
+ if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
+ format, type, pixels)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(invalid PBO access)");
+ return;
+ }
+ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
+ GL_PIXEL_UNPACK_BUFFER_EXT,
+ GL_READ_ONLY_ARB,
+ unpack->BufferObj);
+ if (!buf) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(PBO is mapped)");
+ return;
+ }
+ pixels = ADD_POINTERS(buf, pixels);
+ }
+
+ if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
/* This is a little tricky since all coordinates up to now have
* been in the OpenGL bottom-to-top orientation. X is top-to-bottom
* so we have to carefully compute the Y coordinates/addresses here.
dstY = FLIP(xmesa->xm_draw_buffer, dstY) - h + 1;
XPutImage(dpy, buffer, gc, &ximage, 0, 0, dstX, dstY, w, h);
}
+
+ if (unpack->BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ unpack->BufferObj);
+ }
}
else {
/* software fallback */
int srcX = unpack->SkipPixels;
int srcY = unpack->SkipRows;
int rowLength = unpack->RowLength ? unpack->RowLength : width;
- if (_swrast_clip_pixelrect(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
+
+ if (unpack->BufferObj->Name) {
+ /* unpack from PBO */
+ GLubyte *buf;
+ if (!_mesa_validate_pbo_access(2, unpack, width, height, 1,
+ format, type, pixels)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(invalid PBO access)");
+ return;
+ }
+ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx,
+ GL_PIXEL_UNPACK_BUFFER_EXT,
+ GL_READ_ONLY_ARB,
+ unpack->BufferObj);
+ if (!buf) {
+ /* buffer is already mapped - that's an error */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glDrawPixels(PBO is mapped)");
+ return;
+ }
+ pixels = ADD_POINTERS(buf, pixels);
+ }
+
+ if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) {
/* This is a little tricky since all coordinates up to now have
* been in the OpenGL bottom-to-top orientation. X is top-to-bottom
* so we have to carefully compute the Y coordinates/addresses here.
dstY = FLIP(xmesa->xm_draw_buffer, dstY) - h + 1;
XPutImage(dpy, buffer, gc, &ximage, 0, 0, dstX, dstY, w, h);
}
+
+ if (unpack->BufferObj->Name) {
+ ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+ unpack->BufferObj);
+ }
}
else {
/* software fallback */
if (swrast->NewState)
_swrast_validate_derived( ctx );
- if (ctx->Color.DrawBuffer == GL_FRONT &&
+ if (ctx->Color.DrawBuffer[0] == GL_FRONT &&
ctx->Pixel.ReadBuffer == GL_FRONT &&
drawBuffer && /* buffer != 0 means it's a Window or Pixmap */
readBuffer &&
break;
}
- xmesa_update_span_funcs(ctx);
+ if (ctx->Color._DrawDestMask[0] & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) {
+ xmesa_update_span_funcs(ctx);
+ }
}
}
+/**
+ * In SW, we don't really compress GL_COMPRESSED_RGB[A] textures!
+ */
+static const struct gl_texture_format *
+choose_tex_format( GLcontext *ctx, GLint internalFormat,
+ GLenum format, GLenum type )
+{
+ switch (internalFormat) {
+ case GL_COMPRESSED_RGB_ARB:
+ return &_mesa_texformat_rgb;
+ case GL_COMPRESSED_RGBA_ARB:
+ return &_mesa_texformat_rgba;
+ default:
+ return _mesa_choose_tex_format(ctx, internalFormat, format, type);
+ }
+}
+
+
+/**
+ * Called by glViewport.
+ * This is a good time for us to poll the current X window size and adjust
+ * our ancillary (back color, depth, stencil, etc) buffers to match the
+ * current window size. Remember, we have no opportunity to respond to
+ * conventional X Resize/StructureNotify events since the X driver has no
+ * event loop. Thus, we poll.
+ * Note that this trick isn't fool-proof. If the application never calls
+ * glViewport, our notion of the current window size may be incorrect.
+ */
+static void
+xmesa_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+{
+ _mesa_ResizeBuffersMESA();
+}
+
+
/**
* Initialize the device driver function table with the functions
* we implement in this driver.
*/
-void xmesa_init_driver_functions( XMesaVisual xmvisual,
- struct dd_function_table *driver )
+void
+xmesa_init_driver_functions( XMesaVisual xmvisual,
+ struct dd_function_table *driver )
{
driver->GetString = get_string;
driver->UpdateState = xmesa_update_state;
driver->Enable = enable;
driver->Clear = clear_buffers;
driver->ResizeBuffers = xmesa_resize_buffers;
+ driver->Viewport = xmesa_viewport;
#ifndef XFree86Server
- driver->CopyPixels = /*_swrast_CopyPixels;*/xmesa_CopyPixels;
+ driver->CopyPixels = xmesa_CopyPixels;
if (xmvisual->undithered_pf == PF_8R8G8B &&
xmvisual->dithered_pf == PF_8R8G8B) {
driver->DrawPixels = xmesa_DrawPixels_8R8G8B;
}
#endif
driver->TestProxyTexImage = test_proxy_teximage;
+#if SWTC
+ driver->ChooseTextureFormat = choose_tex_format;
+#else
+ (void) choose_tex_format;
+#endif
}