| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
#include "glxheader.h" |
| 27 |
#include "bufferobj.h" |
| 28 |
#include "buffers.h" |
| 29 |
#include "context.h" |
| 30 |
#include "colormac.h" |
| 31 |
#include "depth.h" |
| 32 |
#include "drawpix.h" |
| 33 |
#include "extensions.h" |
| 34 |
#include "framebuffer.h" |
| 35 |
#include "macros.h" |
| 36 |
#include "image.h" |
| 37 |
#include "imports.h" |
| 38 |
#include "mtypes.h" |
| 39 |
#include "state.h" |
| 40 |
#include "texobj.h" |
| 41 |
#include "teximage.h" |
| 42 |
#include "texstore.h" |
| 43 |
#include "texformat.h" |
| 44 |
#include "xmesaP.h" |
| 45 |
#include "array_cache/acache.h" |
| 46 |
#include "swrast/swrast.h" |
| 47 |
#include "swrast/s_context.h" |
| 48 |
#include "swrast_setup/swrast_setup.h" |
| 49 |
#include "tnl/tnl.h" |
| 50 |
#include "tnl/t_context.h" |
| 51 |
|
| 52 |
#ifdef XFree86Server |
| 53 |
#include <GL/glxtokens.h> |
| 54 |
#endif |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
/* |
| 59 |
* Dithering kernels and lookup tables. |
| 60 |
*/ |
| 61 |
|
| 62 |
const int xmesa_kernel8[DITH_DY * DITH_DX] = { |
| 63 |
0 * MAXC, 8 * MAXC, 2 * MAXC, 10 * MAXC, |
| 64 |
12 * MAXC, 4 * MAXC, 14 * MAXC, 6 * MAXC, |
| 65 |
3 * MAXC, 11 * MAXC, 1 * MAXC, 9 * MAXC, |
| 66 |
15 * MAXC, 7 * MAXC, 13 * MAXC, 5 * MAXC, |
| 67 |
}; |
| 68 |
|
| 69 |
const short xmesa_HPCR_DRGB[3][2][16] = { |
| 70 |
{ |
| 71 |
{ 16, -4, 1,-11, 14, -6, 3, -9, 15, -5, 2,-10, 13, -7, 4, -8}, |
| 72 |
{-15, 5, 0, 12,-13, 7, -2, 10,-14, 6, -1, 11,-12, 8, -3, 9} |
| 73 |
}, |
| 74 |
{ |
| 75 |
{-11, 15, -7, 3, -8, 14, -4, 2,-10, 16, -6, 4, -9, 13, -5, 1}, |
| 76 |
{ 12,-14, 8, -2, 9,-13, 5, -1, 11,-15, 7, -3, 10,-12, 6, 0} |
| 77 |
}, |
| 78 |
{ |
| 79 |
{ 6,-18, 26,-14, 2,-22, 30,-10, 8,-16, 28,-12, 4,-20, 32, -8}, |
| 80 |
{ -4, 20,-24, 16, 0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10} |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
const int xmesa_kernel1[16] = { |
| 85 |
0*47, 9*47, 4*47, 12*47, /* 47 = (255*3)/16 */ |
| 86 |
6*47, 2*47, 14*47, 8*47, |
| 87 |
10*47, 1*47, 5*47, 11*47, |
| 88 |
7*47, 13*47, 3*47, 15*47 |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
/* |
| 93 |
* Return the size (width, height) of the X window for the given GLframebuffer. |
| 94 |
* Output: width - width of buffer in pixels. |
| 95 |
* height - height of buffer in pixels. |
| 96 |
*/ |
| 97 |
static void |
| 98 |
get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height ) |
| 99 |
{ |
| 100 |
/* We can do this cast because the first field in the XMesaBuffer |
| 101 |
* struct is a GLframebuffer struct. If this weren't true, we'd |
| 102 |
* need a pointer from the GLframebuffer to the XMesaBuffer. |
| 103 |
*/ |
| 104 |
const XMesaBuffer xmBuffer = (XMesaBuffer) buffer; |
| 105 |
unsigned int winwidth, winheight; |
| 106 |
#ifdef XFree86Server |
| 107 |
/* XFree86 GLX renderer */ |
| 108 |
winwidth = MIN2(xmBuffer->frontxrb->drawable->width, MAX_WIDTH); |
| 109 |
winheight = MIN2(xmBuffer->frontxrb->drawable->height, MAX_HEIGHT); |
| 110 |
#else |
| 111 |
Window root; |
| 112 |
int winx, winy; |
| 113 |
unsigned int bw, d; |
| 114 |
|
| 115 |
_glthread_LOCK_MUTEX(_xmesa_lock); |
| 116 |
XSync(xmBuffer->xm_visual->display, 0); /* added for Chromium */ |
| 117 |
XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontxrb->pixmap, &root, |
| 118 |
&winx, &winy, &winwidth, &winheight, &bw, &d ); |
| 119 |
_glthread_UNLOCK_MUTEX(_xmesa_lock); |
| 120 |
#endif |
| 121 |
|
| 122 |
*width = winwidth; |
| 123 |
*height = winheight; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
static void |
| 128 |
finish_or_flush( GLcontext *ctx ) |
| 129 |
{ |
| 130 |
#ifdef XFree86Server |
| 131 |
/* NOT_NEEDED */ |
| 132 |
#else |
| 133 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 134 |
if (xmesa) { |
| 135 |
_glthread_LOCK_MUTEX(_xmesa_lock); |
| 136 |
XSync( xmesa->display, False ); |
| 137 |
_glthread_UNLOCK_MUTEX(_xmesa_lock); |
| 138 |
} |
| 139 |
#endif |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
static void |
| 144 |
clear_index( GLcontext *ctx, GLuint index ) |
| 145 |
{ |
| 146 |
if (ctx->DrawBuffer->Name == 0) { |
| 147 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 148 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 149 |
xmesa->clearpixel = (unsigned long) index; |
| 150 |
XMesaSetForeground( xmesa->display, xmbuf->cleargc, (unsigned long) index ); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
static void |
| 156 |
clear_color( GLcontext *ctx, const GLfloat color[4] ) |
| 157 |
{ |
| 158 |
if (ctx->DrawBuffer->Name == 0) { |
| 159 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 160 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 161 |
|
| 162 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]); |
| 163 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]); |
| 164 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]); |
| 165 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]); |
| 166 |
xmesa->clearpixel = xmesa_color_to_pixel( ctx, |
| 167 |
xmesa->clearcolor[0], |
| 168 |
xmesa->clearcolor[1], |
| 169 |
xmesa->clearcolor[2], |
| 170 |
xmesa->clearcolor[3], |
| 171 |
xmesa->xm_visual->undithered_pf ); |
| 172 |
_glthread_LOCK_MUTEX(_xmesa_lock); |
| 173 |
XMesaSetForeground( xmesa->display, xmbuf->cleargc, |
| 174 |
xmesa->clearpixel ); |
| 175 |
_glthread_UNLOCK_MUTEX(_xmesa_lock); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
/* Set index mask ala glIndexMask */ |
| 182 |
static void |
| 183 |
index_mask( GLcontext *ctx, GLuint mask ) |
| 184 |
{ |
| 185 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 186 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 187 |
/* not sure this conditional is really needed */ |
| 188 |
if (xmbuf->backxrb && xmbuf->backxrb->pixmap) { |
| 189 |
unsigned long m; |
| 190 |
if (mask==0xffffffff) { |
| 191 |
m = ((unsigned long)~0L); |
| 192 |
} |
| 193 |
else { |
| 194 |
m = (unsigned long) mask; |
| 195 |
} |
| 196 |
XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m ); |
| 197 |
XMesaSetPlaneMask( xmesa->display, xmbuf->gc, m ); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
/* Implements glColorMask() */ |
| 203 |
static void |
| 204 |
color_mask(GLcontext *ctx, |
| 205 |
GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask) |
| 206 |
{ |
| 207 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 208 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 209 |
const int xclass = xmesa->xm_visual->mesa_visual.visualType; |
| 210 |
(void) amask; |
| 211 |
|
| 212 |
if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { |
| 213 |
unsigned long m; |
| 214 |
if (rmask && gmask && bmask) { |
| 215 |
m = ((unsigned long)~0L); |
| 216 |
} |
| 217 |
else { |
| 218 |
m = 0; |
| 219 |
if (rmask) m |= GET_REDMASK(xmesa->xm_visual); |
| 220 |
if (gmask) m |= GET_GREENMASK(xmesa->xm_visual); |
| 221 |
if (bmask) m |= GET_BLUEMASK(xmesa->xm_visual); |
| 222 |
} |
| 223 |
XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m ); |
| 224 |
XMesaSetPlaneMask( xmesa->display, xmbuf->gc, m ); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
/**********************************************************************/ |
| 231 |
/*** glClear implementations ***/ |
| 232 |
/**********************************************************************/ |
| 233 |
|
| 234 |
|
| 235 |
/** |
| 236 |
* Clear the front or back color buffer, if it's implemented with a pixmap. |
| 237 |
*/ |
| 238 |
static void |
| 239 |
clear_pixmap(GLcontext *ctx, struct xmesa_renderbuffer *xrb, GLboolean all, |
| 240 |
GLint x, GLint y, GLint width, GLint height) |
| 241 |
{ |
| 242 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 243 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 244 |
|
| 245 |
assert(xmbuf); |
| 246 |
assert(xrb->pixmap); |
| 247 |
assert(xmesa); |
| 248 |
assert(xmesa->display); |
| 249 |
assert(xrb->pixmap); |
| 250 |
assert(xmbuf->cleargc); |
| 251 |
|
| 252 |
if (all) { |
| 253 |
XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc, |
| 254 |
0, 0, xrb->Base.Width + 1, xrb->Base.Height + 1 ); |
| 255 |
} |
| 256 |
else { |
| 257 |
XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc, |
| 258 |
x, xrb->Base.Height - y - height, |
| 259 |
width, height ); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
static void |
| 265 |
clear_8bit_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb, |
| 266 |
GLboolean all, GLint x, GLint y, GLint width, GLint height ) |
| 267 |
{ |
| 268 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 269 |
|
| 270 |
if (all) { |
| 271 |
const size_t n = xrb->ximage->bytes_per_line * xrb->Base.Height; |
| 272 |
MEMSET( xrb->ximage->data, xmesa->clearpixel, n ); |
| 273 |
} |
| 274 |
else { |
| 275 |
GLint i; |
| 276 |
for (i=0;i<height;i++) { |
| 277 |
GLubyte *ptr = PIXEL_ADDR1(xrb, x, y + i); |
| 278 |
MEMSET( ptr, xmesa->clearpixel, width ); |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
static void |
| 285 |
clear_HPCR_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb, |
| 286 |
GLboolean all, GLint x, GLint y, GLint width, GLint height ) |
| 287 |
{ |
| 288 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 289 |
|
| 290 |
if (all) { |
| 291 |
GLint i, c16 = (xrb->ximage->bytes_per_line>>4)<<4; |
| 292 |
GLubyte *ptr = (GLubyte *) xrb->ximage->data; |
| 293 |
for (i = 0; i < xrb->Base.Height; i++) { |
| 294 |
GLint j; |
| 295 |
GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0]; |
| 296 |
if (i&1) { |
| 297 |
sptr += 16; |
| 298 |
} |
| 299 |
for (j=0; j<c16; j+=16) { |
| 300 |
ptr[0] = sptr[0]; |
| 301 |
ptr[1] = sptr[1]; |
| 302 |
ptr[2] = sptr[2]; |
| 303 |
ptr[3] = sptr[3]; |
| 304 |
ptr[4] = sptr[4]; |
| 305 |
ptr[5] = sptr[5]; |
| 306 |
ptr[6] = sptr[6]; |
| 307 |
ptr[7] = sptr[7]; |
| 308 |
ptr[8] = sptr[8]; |
| 309 |
ptr[9] = sptr[9]; |
| 310 |
ptr[10] = sptr[10]; |
| 311 |
ptr[11] = sptr[11]; |
| 312 |
ptr[12] = sptr[12]; |
| 313 |
ptr[13] = sptr[13]; |
| 314 |
ptr[14] = sptr[14]; |
| 315 |
ptr[15] = sptr[15]; |
| 316 |
ptr += 16; |
| 317 |
} |
| 318 |
for (; j < xrb->ximage->bytes_per_line; j++) { |
| 319 |
*ptr = sptr[j&15]; |
| 320 |
ptr++; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
else { |
| 325 |
GLint i; |
| 326 |
for (i=y; i<y+height; i++) { |
| 327 |
GLubyte *ptr = PIXEL_ADDR1( xrb, x, i ); |
| 328 |
int j; |
| 329 |
const GLubyte *sptr = xmesa->xm_visual->hpcr_clear_ximage_pattern[0]; |
| 330 |
if (i&1) { |
| 331 |
sptr += 16; |
| 332 |
} |
| 333 |
for (j=x; j<x+width; j++) { |
| 334 |
*ptr = sptr[j&15]; |
| 335 |
ptr++; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
static void |
| 343 |
clear_16bit_ximage( GLcontext *ctx, struct xmesa_renderbuffer *xrb, |
| 344 |
GLboolean all, GLint x, GLint y, GLint width, GLint height) |
| 345 |
{ |
| 346 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 347 |
register GLuint pixel = (GLuint) xmesa->clearpixel; |
| 348 |
|
| 349 |
if (xmesa->swapbytes) { |
| 350 |
pixel = ((pixel >> 8) & 0x00ff) | ((pixel << 8) & 0xff00); |
| 351 |
} |
| 352 |
|
| 353 |
if (all) { |
| 354 |
GLuint *ptr4 = (GLuint *) xrb->ximage->data; |
| 355 |
if ((pixel & 0xff) == ((pixel >> 8) & 0xff)) { |
| 356 |
/* low and high bytes are equal so use memset() */ |
| 357 |
const GLuint n = xrb->ximage->bytes_per_line * xrb->Base.Height; |
| 358 |
MEMSET( ptr4, pixel & 0xff, n ); |
| 359 |
} |
| 360 |
else { |
| 361 |
const GLuint n = xrb->ximage->bytes_per_line * xrb->Base.Height / 4; |
| 362 |
GLuint i; |
| 363 |
pixel = pixel | (pixel<<16); |
| 364 |
for (i = 0; i < n; i++) { |
| 365 |
ptr4[i] = pixel; |
| 366 |
} |
| 367 |
ptr4 += n; |
| 368 |
/* might be one last GLushort to set */ |
| 369 |
if ((xrb->ximage->bytes_per_line * xrb->Base.Height) & 0x2) |
| 370 |
*(GLushort *)ptr4 = pixel & 0xffff; |
| 371 |
} |
| 372 |
} |
| 373 |
else { |
| 374 |
GLint i, j; |
| 375 |
for (j=0;j<height;j++) { |
| 376 |
GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y + j); |
| 377 |
for (i=0;i<width;i++) { |
| 378 |
*ptr2++ = pixel; |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
/* Optimized code provided by Nozomi Ytow <[email protected]> */ |
| 386 |
static void |
| 387 |
clear_24bit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb, |
| 388 |
GLboolean all, GLint x, GLint y, GLint width, GLint height) |
| 389 |
{ |
| 390 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 391 |
const GLubyte r = xmesa->clearcolor[0]; |
| 392 |
const GLubyte g = xmesa->clearcolor[1]; |
| 393 |
const GLubyte b = xmesa->clearcolor[2]; |
| 394 |
|
| 395 |
if (all) { |
| 396 |
if (r == g && g == b) { |
| 397 |
/* same value for all three components (gray) */ |
| 398 |
const GLint w3 = xrb->Base.Width * 3; |
| 399 |
const GLint h = xrb->Base.Height; |
| 400 |
GLint i; |
| 401 |
for (i = 0; i < h; i++) { |
| 402 |
bgr_t *ptr3 = PIXEL_ADDR3(xrb, 0, i); |
| 403 |
MEMSET(ptr3, r, w3); |
| 404 |
} |
| 405 |
} |
| 406 |
else { |
| 407 |
/* the usual case */ |
| 408 |
const GLint w = xrb->Base.Width; |
| 409 |
const GLint h = xrb->Base.Height; |
| 410 |
GLint i, j; |
| 411 |
for (i = 0; i < h; i++) { |
| 412 |
bgr_t *ptr3 = PIXEL_ADDR3(xrb, 0, i); |
| 413 |
for (j = 0; j < w; j++) { |
| 414 |
ptr3->r = r; |
| 415 |
ptr3->g = g; |
| 416 |
ptr3->b = b; |
| 417 |
ptr3++; |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
else { |
| 423 |
/* only clear subrect of color buffer */ |
| 424 |
if (r == g && g == b) { |
| 425 |
/* same value for all three components (gray) */ |
| 426 |
GLint j; |
| 427 |
for (j=0;j<height;j++) { |
| 428 |
bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j); |
| 429 |
MEMSET(ptr3, r, 3 * width); |
| 430 |
} |
| 431 |
} |
| 432 |
else { |
| 433 |
/* non-gray clear color */ |
| 434 |
GLint i, j; |
| 435 |
for (j = 0; j < height; j++) { |
| 436 |
bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j); |
| 437 |
for (i = 0; i < width; i++) { |
| 438 |
ptr3->r = r; |
| 439 |
ptr3->g = g; |
| 440 |
ptr3->b = b; |
| 441 |
ptr3++; |
| 442 |
} |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
static void |
| 450 |
clear_32bit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb, |
| 451 |
GLboolean all, GLint x, GLint y, GLint width, GLint height) |
| 452 |
{ |
| 453 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 454 |
register GLuint pixel = (GLuint) xmesa->clearpixel; |
| 455 |
|
| 456 |
if (xmesa->swapbytes) { |
| 457 |
pixel = ((pixel >> 24) & 0x000000ff) |
| 458 |
| ((pixel >> 8) & 0x0000ff00) |
| 459 |
| ((pixel << 8) & 0x00ff0000) |
| 460 |
| ((pixel << 24) & 0xff000000); |
| 461 |
} |
| 462 |
|
| 463 |
if (all) { |
| 464 |
const GLuint n = xrb->Base.Width * xrb->Base.Height; |
| 465 |
GLuint *ptr4 = (GLuint *) xrb->ximage->data; |
| 466 |
if (pixel == 0) { |
| 467 |
_mesa_memset(ptr4, pixel, 4 * n); |
| 468 |
} |
| 469 |
else { |
| 470 |
GLuint i; |
| 471 |
for (i = 0; i < n; i++) |
| 472 |
ptr4[i] = pixel; |
| 473 |
} |
| 474 |
} |
| 475 |
else { |
| 476 |
GLint i, j; |
| 477 |
for (j = 0; j < height; j++) { |
| 478 |
GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y + j); |
| 479 |
for (i = 0; i < width; i++) { |
| 480 |
ptr4[i] = pixel; |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
static void |
| 488 |
clear_nbit_ximage(GLcontext *ctx, struct xmesa_renderbuffer *xrb, |
| 489 |
GLboolean all, GLint x, GLint y, GLint width, GLint height) |
| 490 |
{ |
| 491 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 492 |
XMesaImage *img = xrb->ximage; |
| 493 |
GLint i, j; |
| 494 |
|
| 495 |
/* We can ignore 'all' here - x, y, width, height are always right */ |
| 496 |
(void) all; |
| 497 |
|
| 498 |
/* TODO: optimize this */ |
| 499 |
y = YFLIP(xrb, y); |
| 500 |
for (j = 0; j < height; j++) { |
| 501 |
for (i = 0; i < width; i++) { |
| 502 |
XMesaPutPixel(img, x+i, y-j, xmesa->clearpixel); |
| 503 |
} |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
static void |
| 510 |
clear_buffers( GLcontext *ctx, GLbitfield mask, |
| 511 |
GLboolean all, GLint x, GLint y, GLint width, GLint height ) |
| 512 |
{ |
| 513 |
if (ctx->DrawBuffer->Name == 0) { |
| 514 |
/* this is a window system framebuffer */ |
| 515 |
const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; |
| 516 |
XMesaBuffer b = (XMesaBuffer) ctx->DrawBuffer; |
| 517 |
|
| 518 |
/* we can't handle color or index masking */ |
| 519 |
if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) { |
| 520 |
if (mask & BUFFER_BIT_FRONT_LEFT) { |
| 521 |
/* clear front color buffer */ |
| 522 |
if (b->frontxrb == (struct xmesa_renderbuffer *) |
| 523 |
ctx->DrawBuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer) { |
| 524 |
/* renderbuffer is not wrapped - great! */ |
| 525 |
b->frontxrb->clearFunc(ctx, b->frontxrb, all, x, y, |
| 526 |
width, height); |
| 527 |
mask &= ~BUFFER_BIT_FRONT_LEFT; |
| 528 |
} |
| 529 |
else { |
| 530 |
/* we can't directly clear an alpha-wrapped color buffer */ |
| 531 |
} |
| 532 |
} |
| 533 |
if (mask & BUFFER_BIT_BACK_LEFT) { |
| 534 |
/* clear back color buffer */ |
| 535 |
if (b->backxrb == (struct xmesa_renderbuffer *) |
| 536 |
ctx->DrawBuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer) { |
| 537 |
/* renderbuffer is not wrapped - great! */ |
| 538 |
b->backxrb->clearFunc(ctx, b->backxrb, all, x, y, |
| 539 |
width, height); |
| 540 |
mask &= ~BUFFER_BIT_BACK_LEFT; |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
if (mask) |
| 546 |
_swrast_Clear( ctx, mask, all, x, y, width, height ); |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
/** |
| 551 |
* Called by ctx->Driver.ResizeBuffers() |
| 552 |
* Resize the front/back colorbuffers to match the latest window size. |
| 553 |
*/ |
| 554 |
void |
| 555 |
xmesa_resize_buffers(GLcontext *ctx, GLframebuffer *buffer, |
| 556 |
GLuint width, GLuint height) |
| 557 |
{ |
| 558 |
/* We can do this cast because the first field in the XMesaBuffer |
| 559 |
* struct is a GLframebuffer struct. If this weren't true, we'd |
| 560 |
* need a pointer from the GLframebuffer to the XMesaBuffer. |
| 561 |
*/ |
| 562 |
XMesaBuffer xmBuffer = (XMesaBuffer) buffer; |
| 563 |
|
| 564 |
xmesa_alloc_back_buffer(xmBuffer, width, height); |
| 565 |
|
| 566 |
_mesa_resize_framebuffer(ctx, buffer, width, height); |
| 567 |
|
| 568 |
if (ctx) |
| 569 |
ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */ |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
#ifndef XFree86Server |
| 574 |
/* XXX this was never tested in the Xserver environment */ |
| 575 |
|
| 576 |
/** |
| 577 |
* This function implements glDrawPixels() with an XPutImage call when |
| 578 |
* drawing to the front buffer (X Window drawable). |
| 579 |
* The image format must be GL_BGRA to match the PF_8R8G8B pixel format. |
| 580 |
*/ |
| 581 |
static void |
| 582 |
xmesa_DrawPixels_8R8G8B( GLcontext *ctx, |
| 583 |
GLint x, GLint y, GLsizei width, GLsizei height, |
| 584 |
GLenum format, GLenum type, |
| 585 |
const struct gl_pixelstore_attrib *unpack, |
| 586 |
const GLvoid *pixels ) |
| 587 |
{ |
| 588 |
struct xmesa_renderbuffer *xrb |
| 589 |
= (struct xmesa_renderbuffer *) ctx->DrawBuffer->_ColorDrawBuffers[0][0]; |
| 590 |
|
| 591 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 592 |
const SWcontext *swrast = SWRAST_CONTEXT( ctx ); |
| 593 |
XMesaDisplay *dpy = xmesa->xm_visual->display; |
| 594 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 595 |
const XMesaGC gc = xmbuf->gc; |
| 596 |
|
| 597 |
ASSERT(dpy); |
| 598 |
ASSERT(gc); |
| 599 |
ASSERT(xmesa->xm_visual->dithered_pf == PF_8R8G8B); |
| 600 |
ASSERT(xmesa->xm_visual->undithered_pf == PF_8R8G8B); |
| 601 |
|
| 602 |
if (swrast->NewState) |
| 603 |
_swrast_validate_derived( ctx ); |
| 604 |
|
| 605 |
if (xrb->pixmap && |
| 606 |
format == GL_BGRA && |
| 607 |
type == GL_UNSIGNED_BYTE && |
| 608 |
(swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */ |
| 609 |
ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */ |
| 610 |
ctx->Pixel.ZoomX == 1.0 && /* no zooming */ |
| 611 |
ctx->Pixel.ZoomY == 1.0) { |
| 612 |
int dstX = x; |
| 613 |
int dstY = y; |
| 614 |
int w = width; |
| 615 |
int h = height; |
| 616 |
int srcX = unpack->SkipPixels; |
| 617 |
int srcY = unpack->SkipRows; |
| 618 |
int rowLength = unpack->RowLength ? unpack->RowLength : width; |
| 619 |
|
| 620 |
if (unpack->BufferObj->Name) { |
| 621 |
/* unpack from PBO */ |
| 622 |
GLubyte *buf; |
| 623 |
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, |
| 624 |
format, type, pixels)) { |
| 625 |
_mesa_error(ctx, GL_INVALID_OPERATION, |
| 626 |
"glDrawPixels(invalid PBO access)"); |
| 627 |
return; |
| 628 |
} |
| 629 |
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, |
| 630 |
GL_PIXEL_UNPACK_BUFFER_EXT, |
| 631 |
GL_READ_ONLY_ARB, |
| 632 |
unpack->BufferObj); |
| 633 |
if (!buf) { |
| 634 |
/* buffer is already mapped - that's an error */ |
| 635 |
_mesa_error(ctx, GL_INVALID_OPERATION, |
| 636 |
"glDrawPixels(PBO is mapped)"); |
| 637 |
return; |
| 638 |
} |
| 639 |
pixels = ADD_POINTERS(buf, pixels); |
| 640 |
} |
| 641 |
|
| 642 |
if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) { |
| 643 |
/* This is a little tricky since all coordinates up to now have |
| 644 |
* been in the OpenGL bottom-to-top orientation. X is top-to-bottom |
| 645 |
* so we have to carefully compute the Y coordinates/addresses here. |
| 646 |
*/ |
| 647 |
XMesaImage ximage; |
| 648 |
MEMSET(&ximage, 0, sizeof(XMesaImage)); |
| 649 |
ximage.width = width; |
| 650 |
ximage.height = height; |
| 651 |
ximage.format = ZPixmap; |
| 652 |
ximage.data = (char *) pixels |
| 653 |
+ ((srcY + h - 1) * rowLength + srcX) * 4; |
| 654 |
ximage.byte_order = LSBFirst; |
| 655 |
ximage.bitmap_unit = 32; |
| 656 |
ximage.bitmap_bit_order = LSBFirst; |
| 657 |
ximage.bitmap_pad = 32; |
| 658 |
ximage.depth = 24; |
| 659 |
ximage.bytes_per_line = -rowLength * 4; /* negative to flip image */ |
| 660 |
ximage.bits_per_pixel = 32; |
| 661 |
/* it seems we don't need to set the ximage.red/green/blue_mask fields */ |
| 662 |
/* flip Y axis for dest position */ |
| 663 |
dstY = YFLIP(xrb, dstY) - h + 1; |
| 664 |
XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h); |
| 665 |
} |
| 666 |
|
| 667 |
if (unpack->BufferObj->Name) { |
| 668 |
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, |
| 669 |
unpack->BufferObj); |
| 670 |
} |
| 671 |
} |
| 672 |
else { |
| 673 |
/* software fallback */ |
| 674 |
_swrast_DrawPixels(ctx, x, y, width, height, |
| 675 |
format, type, unpack, pixels); |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
/** |
| 682 |
* This function implements glDrawPixels() with an XPutImage call when |
| 683 |
* drawing to the front buffer (X Window drawable). The image format |
| 684 |
* must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to |
| 685 |
* match the PF_5R6G5B pixel format. |
| 686 |
*/ |
| 687 |
static void |
| 688 |
xmesa_DrawPixels_5R6G5B( GLcontext *ctx, |
| 689 |
GLint x, GLint y, GLsizei width, GLsizei height, |
| 690 |
GLenum format, GLenum type, |
| 691 |
const struct gl_pixelstore_attrib *unpack, |
| 692 |
const GLvoid *pixels ) |
| 693 |
{ |
| 694 |
struct xmesa_renderbuffer *xrb |
| 695 |
= (struct xmesa_renderbuffer *) ctx->DrawBuffer->_ColorDrawBuffers[0][0]; |
| 696 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 697 |
const SWcontext *swrast = SWRAST_CONTEXT( ctx ); |
| 698 |
XMesaDisplay *dpy = xmesa->xm_visual->display; |
| 699 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 700 |
const XMesaGC gc = xmbuf->gc; |
| 701 |
|
| 702 |
ASSERT(dpy); |
| 703 |
ASSERT(gc); |
| 704 |
ASSERT(xmesa->xm_visual->undithered_pf == PF_5R6G5B); |
| 705 |
|
| 706 |
if (swrast->NewState) |
| 707 |
_swrast_validate_derived( ctx ); |
| 708 |
|
| 709 |
if (xrb->pixmap && |
| 710 |
format == GL_RGB && |
| 711 |
type == GL_UNSIGNED_SHORT_5_6_5 && |
| 712 |
!ctx->Color.DitherFlag && /* no dithering */ |
| 713 |
(swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */ |
| 714 |
ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */ |
| 715 |
ctx->Pixel.ZoomX == 1.0 && /* no zooming */ |
| 716 |
ctx->Pixel.ZoomY == 1.0) { |
| 717 |
int dstX = x; |
| 718 |
int dstY = y; |
| 719 |
int w = width; |
| 720 |
int h = height; |
| 721 |
int srcX = unpack->SkipPixels; |
| 722 |
int srcY = unpack->SkipRows; |
| 723 |
int rowLength = unpack->RowLength ? unpack->RowLength : width; |
| 724 |
|
| 725 |
if (unpack->BufferObj->Name) { |
| 726 |
/* unpack from PBO */ |
| 727 |
GLubyte *buf; |
| 728 |
if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, |
| 729 |
format, type, pixels)) { |
| 730 |
_mesa_error(ctx, GL_INVALID_OPERATION, |
| 731 |
"glDrawPixels(invalid PBO access)"); |
| 732 |
return; |
| 733 |
} |
| 734 |
buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, |
| 735 |
GL_PIXEL_UNPACK_BUFFER_EXT, |
| 736 |
GL_READ_ONLY_ARB, |
| 737 |
unpack->BufferObj); |
| 738 |
if (!buf) { |
| 739 |
/* buffer is already mapped - that's an error */ |
| 740 |
_mesa_error(ctx, GL_INVALID_OPERATION, |
| 741 |
"glDrawPixels(PBO is mapped)"); |
| 742 |
return; |
| 743 |
} |
| 744 |
pixels = ADD_POINTERS(buf, pixels); |
| 745 |
} |
| 746 |
|
| 747 |
if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &srcX, &srcY)) { |
| 748 |
/* This is a little tricky since all coordinates up to now have |
| 749 |
* been in the OpenGL bottom-to-top orientation. X is top-to-bottom |
| 750 |
* so we have to carefully compute the Y coordinates/addresses here. |
| 751 |
*/ |
| 752 |
XMesaImage ximage; |
| 753 |
MEMSET(&ximage, 0, sizeof(XMesaImage)); |
| 754 |
ximage.width = width; |
| 755 |
ximage.height = height; |
| 756 |
ximage.format = ZPixmap; |
| 757 |
ximage.data = (char *) pixels |
| 758 |
+ ((srcY + h - 1) * rowLength + srcX) * 2; |
| 759 |
ximage.byte_order = LSBFirst; |
| 760 |
ximage.bitmap_unit = 16; |
| 761 |
ximage.bitmap_bit_order = LSBFirst; |
| 762 |
ximage.bitmap_pad = 16; |
| 763 |
ximage.depth = 16; |
| 764 |
ximage.bytes_per_line = -rowLength * 2; /* negative to flip image */ |
| 765 |
ximage.bits_per_pixel = 16; |
| 766 |
/* it seems we don't need to set the ximage.red/green/blue_mask fields */ |
| 767 |
/* flip Y axis for dest position */ |
| 768 |
dstY = YFLIP(xrb, dstY) - h + 1; |
| 769 |
XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h); |
| 770 |
} |
| 771 |
|
| 772 |
if (unpack->BufferObj->Name) { |
| 773 |
ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, |
| 774 |
unpack->BufferObj); |
| 775 |
} |
| 776 |
} |
| 777 |
else { |
| 778 |
/* software fallback */ |
| 779 |
_swrast_DrawPixels(ctx, x, y, width, height, |
| 780 |
format, type, unpack, pixels); |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
/** |
| 787 |
* Implement glCopyPixels for the front color buffer (or back buffer Pixmap) |
| 788 |
* for the color buffer. Don't support zooming, pixel transfer, etc. |
| 789 |
* We do support copying from one window to another, ala glXMakeCurrentRead. |
| 790 |
*/ |
| 791 |
static void |
| 792 |
xmesa_CopyPixels( GLcontext *ctx, |
| 793 |
GLint srcx, GLint srcy, GLsizei width, GLsizei height, |
| 794 |
GLint destx, GLint desty, GLenum type ) |
| 795 |
{ |
| 796 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 797 |
const SWcontext *swrast = SWRAST_CONTEXT( ctx ); |
| 798 |
XMesaDisplay *dpy = xmesa->xm_visual->display; |
| 799 |
const XMesaGC gc = ((XMesaBuffer) ctx->DrawBuffer)->gc; |
| 800 |
struct xmesa_renderbuffer *srcXrb = (struct xmesa_renderbuffer *) |
| 801 |
ctx->ReadBuffer->_ColorReadBuffer; |
| 802 |
struct xmesa_renderbuffer *dstXrb = (struct xmesa_renderbuffer *) |
| 803 |
ctx->DrawBuffer->_ColorDrawBuffers[0][0]; |
| 804 |
|
| 805 |
ASSERT(dpy); |
| 806 |
ASSERT(gc); |
| 807 |
|
| 808 |
if (swrast->NewState) |
| 809 |
_swrast_validate_derived( ctx ); |
| 810 |
|
| 811 |
if (ctx->Color.DrawBuffer[0] == GL_FRONT && |
| 812 |
ctx->Pixel.ReadBuffer == GL_FRONT && |
| 813 |
srcXrb->pixmap && |
| 814 |
dstXrb->pixmap && |
| 815 |
type == GL_COLOR && |
| 816 |
(swrast->_RasterMask & ~CLIP_BIT) == 0 && /* no blend, z-test, etc */ |
| 817 |
ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */ |
| 818 |
ctx->Pixel.ZoomX == 1.0 && /* no zooming */ |
| 819 |
ctx->Pixel.ZoomY == 1.0) { |
| 820 |
/* Note: we don't do any special clipping work here. We could, |
| 821 |
* but X will do it for us. |
| 822 |
*/ |
| 823 |
srcy = YFLIP(srcXrb, srcy) - height + 1; |
| 824 |
desty = YFLIP(dstXrb, desty) - height + 1; |
| 825 |
XCopyArea(dpy, srcXrb->pixmap, dstXrb->pixmap, gc, |
| 826 |
srcx, srcy, width, height, destx, desty); |
| 827 |
} |
| 828 |
else { |
| 829 |
_swrast_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type ); |
| 830 |
} |
| 831 |
} |
| 832 |
#endif /* XFree86Server */ |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
/* |
| 837 |
* Every driver should implement a GetString function in order to |
| 838 |
* return a meaningful GL_RENDERER string. |
| 839 |
*/ |
| 840 |
static const GLubyte * |
| 841 |
get_string( GLcontext *ctx, GLenum name ) |
| 842 |
{ |
| 843 |
(void) ctx; |
| 844 |
switch (name) { |
| 845 |
case GL_RENDERER: |
| 846 |
#ifdef XFree86Server |
| 847 |
return (const GLubyte *) "Mesa GLX Indirect"; |
| 848 |
#else |
| 849 |
return (const GLubyte *) "Mesa X11"; |
| 850 |
#endif |
| 851 |
case GL_VENDOR: |
| 852 |
#ifdef XFree86Server |
| 853 |
return (const GLubyte *) "Mesa project: www.mesa3d.org"; |
| 854 |
#else |
| 855 |
return NULL; |
| 856 |
#endif |
| 857 |
default: |
| 858 |
return NULL; |
| 859 |
} |
| 860 |
} |
| 861 |
|
| 862 |
|
| 863 |
/* |
| 864 |
* We implement the glEnable function only because we care about |
| 865 |
* dither enable/disable. |
| 866 |
*/ |
| 867 |
static void |
| 868 |
enable( GLcontext *ctx, GLenum pname, GLboolean state ) |
| 869 |
{ |
| 870 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 871 |
|
| 872 |
switch (pname) { |
| 873 |
case GL_DITHER: |
| 874 |
if (state) |
| 875 |
xmesa->pixelformat = xmesa->xm_visual->dithered_pf; |
| 876 |
else |
| 877 |
xmesa->pixelformat = xmesa->xm_visual->undithered_pf; |
| 878 |
break; |
| 879 |
default: |
| 880 |
; /* silence compiler warning */ |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
|
| 885 |
static void |
| 886 |
clear_color_HPCR_ximage( GLcontext *ctx, const GLfloat color[4] ) |
| 887 |
{ |
| 888 |
int i; |
| 889 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 890 |
|
| 891 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]); |
| 892 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]); |
| 893 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]); |
| 894 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]); |
| 895 |
|
| 896 |
if (color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0) { |
| 897 |
/* black is black */ |
| 898 |
MEMSET( xmesa->xm_visual->hpcr_clear_ximage_pattern, 0x0 , |
| 899 |
sizeof(xmesa->xm_visual->hpcr_clear_ximage_pattern)); |
| 900 |
} |
| 901 |
else { |
| 902 |
/* build clear pattern */ |
| 903 |
for (i=0; i<16; i++) { |
| 904 |
xmesa->xm_visual->hpcr_clear_ximage_pattern[0][i] = |
| 905 |
DITHER_HPCR(i, 0, |
| 906 |
xmesa->clearcolor[0], |
| 907 |
xmesa->clearcolor[1], |
| 908 |
xmesa->clearcolor[2]); |
| 909 |
xmesa->xm_visual->hpcr_clear_ximage_pattern[1][i] = |
| 910 |
DITHER_HPCR(i, 1, |
| 911 |
xmesa->clearcolor[0], |
| 912 |
xmesa->clearcolor[1], |
| 913 |
xmesa->clearcolor[2]); |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
|
| 919 |
static void |
| 920 |
clear_color_HPCR_pixmap( GLcontext *ctx, const GLfloat color[4] ) |
| 921 |
{ |
| 922 |
int i; |
| 923 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 924 |
|
| 925 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]); |
| 926 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]); |
| 927 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]); |
| 928 |
CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]); |
| 929 |
|
| 930 |
if (color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0) { |
| 931 |
/* black is black */ |
| 932 |
for (i=0; i<16; i++) { |
| 933 |
XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0, 0); |
| 934 |
XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1, 0); |
| 935 |
} |
| 936 |
} |
| 937 |
else { |
| 938 |
for (i=0; i<16; i++) { |
| 939 |
XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0, |
| 940 |
DITHER_HPCR(i, 0, |
| 941 |
xmesa->clearcolor[0], |
| 942 |
xmesa->clearcolor[1], |
| 943 |
xmesa->clearcolor[2])); |
| 944 |
XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1, |
| 945 |
DITHER_HPCR(i, 1, |
| 946 |
xmesa->clearcolor[0], |
| 947 |
xmesa->clearcolor[1], |
| 948 |
xmesa->clearcolor[2])); |
| 949 |
} |
| 950 |
} |
| 951 |
/* change tile pixmap content */ |
| 952 |
XMesaPutImage(xmesa->display, |
| 953 |
(XMesaDrawable)xmesa->xm_visual->hpcr_clear_pixmap, |
| 954 |
XMESA_BUFFER(ctx->DrawBuffer)->cleargc, |
| 955 |
xmesa->xm_visual->hpcr_clear_ximage, 0, 0, 0, 0, 16, 2); |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
/** |
| 960 |
* Called when the driver should update it's state, based on the new_state |
| 961 |
* flags. |
| 962 |
*/ |
| 963 |
void |
| 964 |
xmesa_update_state( GLcontext *ctx, GLuint new_state ) |
| 965 |
{ |
| 966 |
const XMesaContext xmesa = XMESA_CONTEXT(ctx); |
| 967 |
struct xmesa_renderbuffer *front_xrb, *back_xrb; |
| 968 |
|
| 969 |
/* Propagate statechange information to swrast and swrast_setup |
| 970 |
* modules. The X11 driver has no internal GL-dependent state. |
| 971 |
*/ |
| 972 |
_swrast_InvalidateState( ctx, new_state ); |
| 973 |
_ac_InvalidateState( ctx, new_state ); |
| 974 |
_tnl_InvalidateState( ctx, new_state ); |
| 975 |
_swsetup_InvalidateState( ctx, new_state ); |
| 976 |
|
| 977 |
if (ctx->DrawBuffer->Name != 0) |
| 978 |
return; |
| 979 |
|
| 980 |
front_xrb = XMESA_BUFFER(ctx->DrawBuffer)->frontxrb; |
| 981 |
if (front_xrb) { |
| 982 |
/* XXX check for relevant new_state flags */ |
| 983 |
xmesa_set_renderbuffer_funcs(front_xrb, xmesa->pixelformat, |
| 984 |
xmesa->xm_visual->BitsPerPixel); |
| 985 |
/* setup pointers to front and back buffer clear functions */ |
| 986 |
front_xrb->clearFunc = clear_pixmap; |
| 987 |
} |
| 988 |
|
| 989 |
back_xrb = XMESA_BUFFER(ctx->DrawBuffer)->backxrb; |
| 990 |
if (back_xrb) { |
| 991 |
XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); |
| 992 |
|
| 993 |
/* XXX check for relevant new_state flags */ |
| 994 |
xmesa_set_renderbuffer_funcs(back_xrb, xmesa->pixelformat, |
| 995 |
xmesa->xm_visual->BitsPerPixel); |
| 996 |
|
| 997 |
if (xmbuf->backxrb->pixmap) { |
| 998 |
back_xrb->clearFunc = clear_pixmap; |
| 999 |
} |
| 1000 |
else { |
| 1001 |
switch (xmesa->xm_visual->BitsPerPixel) { |
| 1002 |
case 8: |
| 1003 |
if (xmesa->xm_visual->hpcr_clear_flag) { |
| 1004 |
back_xrb->clearFunc = clear_HPCR_ximage; |
| 1005 |
} |
| 1006 |
else { |
| 1007 |
back_xrb->clearFunc = clear_8bit_ximage; |
| 1008 |
} |
| 1009 |
break; |
| 1010 |
case 16: |
| 1011 |
back_xrb->clearFunc = clear_16bit_ximage; |
| 1012 |
break; |
| 1013 |
case 24: |
| 1014 |
back_xrb->clearFunc = clear_24bit_ximage; |
| 1015 |
break; |
| 1016 |
case 32: |
| 1017 |
back_xrb->clearFunc = clear_32bit_ximage; |
| 1018 |
break; |
| 1019 |
default: |
| 1020 |
back_xrb->clearFunc = clear_nbit_ximage; |
| 1021 |
break; |
| 1022 |
} |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
if (xmesa->xm_visual->hpcr_clear_flag) { |
| 1027 |
/* this depends on whether we're drawing to the front or back buffer */ |
| 1028 |
/* XXX FIX THIS! */ |
| 1029 |
#if 0 |
| 1030 |
if (pixmap) { |
| 1031 |
ctx->Driver.ClearColor = clear_color_HPCR_pixmap; |
| 1032 |
} |
| 1033 |
else { |
| 1034 |
ctx->Driver.ClearColor = clear_color_HPCR_ximage; |
| 1035 |
} |
| 1036 |
#else |
| 1037 |
(void) clear_color_HPCR_pixmap; |
| 1038 |
(void) clear_color_HPCR_ximage; |
| 1039 |
#endif |
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
/** |
| 1046 |
* Called via ctx->Driver.TestProxyTeximage(). Normally, we'd just use |
| 1047 |
* the _mesa_test_proxy_teximage() fallback function, but we're going to |
| 1048 |
* special-case the 3D texture case to allow textures up to 512x512x32 |
| 1049 |
* texels. |
| 1050 |
*/ |
| 1051 |
static GLboolean |
| 1052 |
test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, |
| 1053 |
GLint internalFormat, GLenum format, GLenum type, |
| 1054 |
GLint width, GLint height, GLint depth, GLint border) |
| 1055 |
{ |
| 1056 |
if (target == GL_PROXY_TEXTURE_3D) { |
| 1057 |
/* special case for 3D textures */ |
| 1058 |
if (width * height * depth > 512 * 512 * 64 || |
| 1059 |
width < 2 * border || |
| 1060 |
(!ctx->Extensions.ARB_texture_non_power_of_two && |
| 1061 |
_mesa_bitcount(width - 2 * border) != 1) || |
| 1062 |
height < 2 * border || |
| 1063 |
(!ctx->Extensions.ARB_texture_non_power_of_two && |
| 1064 |
_mesa_bitcount(height - 2 * border) != 1) || |
| 1065 |
depth < 2 * border || |
| 1066 |
(!ctx->Extensions.ARB_texture_non_power_of_two && |
| 1067 |
_mesa_bitcount(depth - 2 * border) != 1)) { |
| 1068 |
/* Bad size, or too many texels */ |
| 1069 |
return GL_FALSE; |
| 1070 |
} |
| 1071 |
return GL_TRUE; |
| 1072 |
} |
| 1073 |
else { |
| 1074 |
/* use the fallback routine for 1D, 2D, cube and rect targets */ |
| 1075 |
return _mesa_test_proxy_teximage(ctx, target, level, internalFormat, |
| 1076 |
format, type, width, height, depth, |
| 1077 |
border); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
/** |
| 1083 |
* In SW, we don't really compress GL_COMPRESSED_RGB[A] textures! |
| 1084 |
*/ |
| 1085 |
static const struct gl_texture_format * |
| 1086 |
choose_tex_format( GLcontext *ctx, GLint internalFormat, |
| 1087 |
GLenum format, GLenum type ) |
| 1088 |
{ |
| 1089 |
switch (internalFormat) { |
| 1090 |
case GL_COMPRESSED_RGB_ARB: |
| 1091 |
return &_mesa_texformat_rgb; |
| 1092 |
case GL_COMPRESSED_RGBA_ARB: |
| 1093 |
return &_mesa_texformat_rgba; |
| 1094 |
default: |
| 1095 |
return _mesa_choose_tex_format(ctx, internalFormat, format, type); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
/** |
| 1101 |
* Called by glViewport. |
| 1102 |
* This is a good time for us to poll the current X window size and adjust |
| 1103 |
* our renderbuffers to match the current window size. |
| 1104 |
* Remember, we have no opportunity to respond to conventional |
| 1105 |
* X Resize/StructureNotify events since the X driver has no event loop. |
| 1106 |
* Thus, we poll. |
| 1107 |
* Note that this trick isn't fool-proof. If the application never calls |
| 1108 |
* glViewport, our notion of the current window size may be incorrect. |
| 1109 |
*/ |
| 1110 |
static void |
| 1111 |
xmesa_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) |
| 1112 |
{ |
| 1113 |
#if 1 |
| 1114 |
struct gl_framebuffer *fb = ctx->WinSysDrawBuffer; |
| 1115 |
GLuint newWidth, newHeight; |
| 1116 |
|
| 1117 |
get_buffer_size(fb, &newWidth, &newHeight); |
| 1118 |
if (newWidth != fb->Width || newHeight != fb->Height) { |
| 1119 |
xmesa_resize_buffers(ctx, fb, newWidth, newHeight); |
| 1120 |
} |
| 1121 |
#else |
| 1122 |
/* This also works: */ |
| 1123 |
_mesa_ResizeBuffersMESA(); |
| 1124 |
#endif |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
/** |
| 1129 |
* Initialize the device driver function table with the functions |
| 1130 |
* we implement in this driver. |
| 1131 |
*/ |
| 1132 |
void |
| 1133 |
xmesa_init_driver_functions( XMesaVisual xmvisual, |
| 1134 |
struct dd_function_table *driver ) |
| 1135 |
{ |
| 1136 |
driver->GetString = get_string; |
| 1137 |
driver->UpdateState = xmesa_update_state; |
| 1138 |
driver->GetBufferSize = get_buffer_size; |
| 1139 |
driver->Flush = finish_or_flush; |
| 1140 |
driver->Finish = finish_or_flush; |
| 1141 |
driver->ClearIndex = clear_index; |
| 1142 |
driver->ClearColor = clear_color; |
| 1143 |
driver->IndexMask = index_mask; |
| 1144 |
driver->ColorMask = color_mask; |
| 1145 |
driver->Enable = enable; |
| 1146 |
driver->Clear = clear_buffers; |
| 1147 |
driver->ResizeBuffers = xmesa_resize_buffers; |
| 1148 |
driver->Viewport = xmesa_viewport; |
| 1149 |
#ifndef XFree86Server |
| 1150 |
driver->CopyPixels = xmesa_CopyPixels; |
| 1151 |
if (xmvisual->undithered_pf == PF_8R8G8B && |
| 1152 |
xmvisual->dithered_pf == PF_8R8G8B) { |
| 1153 |
driver->DrawPixels = xmesa_DrawPixels_8R8G8B; |
| 1154 |
} |
| 1155 |
else if (xmvisual->undithered_pf == PF_5R6G5B) { |
| 1156 |
driver->DrawPixels = xmesa_DrawPixels_5R6G5B; |
| 1157 |
} |
| 1158 |
#endif |
| 1159 |
driver->TestProxyTexImage = test_proxy_teximage; |
| 1160 |
#if SWTC |
| 1161 |
driver->ChooseTextureFormat = choose_tex_format; |
| 1162 |
#else |
| 1163 |
(void) choose_tex_format; |
| 1164 |
#endif |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
#define XMESA_NEW_POINT (_NEW_POINT | \ |
| 1169 |
_NEW_RENDERMODE | \ |
| 1170 |
_SWRAST_NEW_RASTERMASK) |
| 1171 |
|
| 1172 |
#define XMESA_NEW_LINE (_NEW_LINE | \ |
| 1173 |
_NEW_TEXTURE | \ |
| 1174 |
_NEW_LIGHT | \ |
| 1175 |
_NEW_DEPTH | \ |
| 1176 |
_NEW_RENDERMODE | \ |
| 1177 |
_SWRAST_NEW_RASTERMASK) |
| 1178 |
|
| 1179 |
#define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \ |
| 1180 |
_NEW_TEXTURE | \ |
| 1181 |
_NEW_LIGHT | \ |
| 1182 |
_NEW_DEPTH | \ |
| 1183 |
_NEW_RENDERMODE | \ |
| 1184 |
_SWRAST_NEW_RASTERMASK) |
| 1185 |
|
| 1186 |
|
| 1187 |
/* Extend the software rasterizer with our line/point/triangle |
| 1188 |
* functions. |
| 1189 |
*/ |
| 1190 |
void xmesa_register_swrast_functions( GLcontext *ctx ) |
| 1191 |
{ |
| 1192 |
SWcontext *swrast = SWRAST_CONTEXT( ctx ); |
| 1193 |
|
| 1194 |
swrast->choose_point = xmesa_choose_point; |
| 1195 |
swrast->choose_line = xmesa_choose_line; |
| 1196 |
swrast->choose_triangle = xmesa_choose_triangle; |
| 1197 |
|
| 1198 |
swrast->invalidate_point |= XMESA_NEW_POINT; |
| 1199 |
swrast->invalidate_line |= XMESA_NEW_LINE; |
| 1200 |
swrast->invalidate_triangle |= XMESA_NEW_TRIANGLE; |
| 1201 |
} |