DOS and glide driver updates from Daniel Borca
[mesa.git] / src / mesa / drivers / glide / fxdd.c
1 /* Hack alert:
2 * fxDDReadPixels888 does not convert 8A8R8G8B into 5R5G5B
3 */
4
5 /* $Id: fxdd.c,v 1.99 2003/08/19 15:52:53 brianp Exp $ */
6
7 /*
8 * Mesa 3-D graphics library
9 * Version: 5.1
10 *
11 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
27 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31 /* Authors:
32 * David Bucciarelli
33 * Brian Paul
34 * Daryll Strauss
35 * Keith Whitwell
36 * Daniel Borca
37 * Hiroshi Morii
38 */
39
40 /* fxdd.c - 3Dfx VooDoo Mesa device driver functions */
41
42
43 #ifdef HAVE_CONFIG_H
44 #include "conf.h"
45 #endif
46
47 #if defined(FX)
48
49 #include "image.h"
50 #include "mtypes.h"
51 #include "fxdrv.h"
52 #include "enums.h"
53 #include "extensions.h"
54 #include "macros.h"
55 #include "texstore.h"
56 #include "teximage.h"
57 #include "swrast/swrast.h"
58 #include "swrast_setup/swrast_setup.h"
59 #include "tnl/tnl.h"
60 #include "tnl/t_context.h"
61 #include "tnl/t_pipeline.h"
62 #include "array_cache/acache.h"
63
64
65
66 float gl_ubyte_to_float_255_color_tab[256];
67
68 /* These lookup table are used to extract RGB values in [0,255] from
69 * 16-bit pixel values.
70 */
71 GLubyte FX_PixelToR[0x10000];
72 GLubyte FX_PixelToG[0x10000];
73 GLubyte FX_PixelToB[0x10000];
74
75 /* lookup table for scaling 5 bit colors up to 8 bits */
76 GLuint FX_rgb_scale_5[32] = {
77 0, 8, 16, 25, 33, 41, 49, 58,
78 66, 74, 82, 90, 99, 107, 115, 123,
79 132, 140, 148, 156, 165, 173, 181, 189,
80 197, 206, 214, 222, 230, 239, 247, 255
81 };
82
83
84 /*
85 * Initialize the FX_PixelTo{RGB} arrays.
86 * Input: bgrOrder - if TRUE, pixels are in BGR order, else RGB order.
87 */
88 void
89 fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder)
90 {
91 GLuint pixel;
92
93 fxMesa->bgrOrder = bgrOrder;
94 for (pixel = 0; pixel <= 0xffff; pixel++) {
95 GLuint r, g, b;
96 if (bgrOrder) {
97 r = (pixel & 0x001F) << 3;
98 g = (pixel & 0x07E0) >> 3;
99 b = (pixel & 0xF800) >> 8;
100 }
101 else {
102 r = (pixel & 0xF800) >> 8;
103 g = (pixel & 0x07E0) >> 3;
104 b = (pixel & 0x001F) << 3;
105 }
106 /* fill in low-order bits with proper rounding */
107 r = (GLuint)(((double)r * 255. / 0xF8) + 0.5);
108 g = (GLuint)(((double)g * 255. / 0xFC) + 0.5);
109 b = (GLuint)(((double)b * 255. / 0xF8) + 0.5);
110 FX_PixelToR[pixel] = r;
111 FX_PixelToG[pixel] = g;
112 FX_PixelToB[pixel] = b;
113 }
114 }
115
116
117 /**********************************************************************/
118 /***** Miscellaneous functions *****/
119 /**********************************************************************/
120
121 /* Return buffer size information */
122 static void
123 fxDDBufferSize(GLframebuffer *buffer, GLuint * width, GLuint * height)
124 {
125 GET_CURRENT_CONTEXT(ctx);
126 if (ctx && ctx->DriverCtx) {
127 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
128
129 if (MESA_VERBOSE & VERBOSE_DRIVER) {
130 fprintf(stderr, "fxmesa: fxDDBufferSize(...) Start\n");
131 }
132
133 *width = fxMesa->width;
134 *height = fxMesa->height;
135
136 if (MESA_VERBOSE & VERBOSE_DRIVER) {
137 fprintf(stderr, "fxmesa: fxDDBufferSize(...) End\n");
138 }
139 }
140 }
141
142
143 /* Implements glClearColor() */
144 static void
145 fxDDClearColor(GLcontext * ctx, const GLfloat color[4])
146 {
147 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
148 GLubyte col[4];
149
150 if (MESA_VERBOSE & VERBOSE_DRIVER) {
151 fprintf(stderr, "fxmesa: fxDDClearColor(%f,%f,%f,%f)\n",
152 color[0], color[1], color[2], color[3]);
153 }
154
155 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
156 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
157 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
158 CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]);
159
160 fxMesa->clearC = FXCOLOR4(col);
161 fxMesa->clearA = col[3];
162 }
163
164
165 /* Clear the color and/or depth buffers */
166 static void
167 fxDDClear(GLcontext * ctx, GLbitfield mask, GLboolean all,
168 GLint x, GLint y, GLint width, GLint height)
169 {
170 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
171 const GLuint colorMask = *((GLuint *) & ctx->Color.ColorMask);
172 /* [dBorca] should use an adequate scaler for 16 vs 32bit (GR_ZDEPTH_MIN_MAX) */
173 const FxU32 clearD = (FxU32) (ctx->Depth.Clear * 0x00ffffff);
174 GLbitfield softwareMask = mask & (DD_STENCIL_BIT | DD_ACCUM_BIT);
175
176 /* we can't clear stencil or accum buffers */
177 mask &= ~(DD_STENCIL_BIT | DD_ACCUM_BIT);
178
179 if (MESA_VERBOSE & VERBOSE_DRIVER) {
180 fprintf(stderr, "fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x, (int) y,
181 (int) width, (int) height);
182 }
183
184 if (colorMask != 0xffffffff) {
185 /* do masked color buffer clears in software */
186 softwareMask |= (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
187 mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
188 }
189
190 /*
191 * This could probably be done fancier but doing each possible case
192 * explicitly is less error prone.
193 */
194 switch (mask) {
195 case DD_BACK_LEFT_BIT | DD_DEPTH_BIT:
196 /* back buffer & depth */
197 grDepthMask(FXTRUE);
198 grRenderBuffer(GR_BUFFER_BACKBUFFER);
199 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
200 if (!ctx->Depth.Mask) {
201 grDepthMask(FXFALSE);
202 }
203 break;
204 case DD_FRONT_LEFT_BIT | DD_DEPTH_BIT:
205 /* XXX it appears that the depth buffer isn't cleared when
206 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
207 * This is a work-around/
208 */
209 /* clear depth */
210 grDepthMask(FXTRUE);
211 grRenderBuffer(GR_BUFFER_BACKBUFFER);
212 grColorMask(FXFALSE, FXFALSE);
213 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
214 /* clear front */
215 grColorMask(FXTRUE, ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer);
216 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
217 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
218 break;
219 case DD_BACK_LEFT_BIT:
220 /* back buffer only */
221 grDepthMask(FXFALSE);
222 grRenderBuffer(GR_BUFFER_BACKBUFFER);
223 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
224 if (ctx->Depth.Mask) {
225 grDepthMask(FXTRUE);
226 }
227 break;
228 case DD_FRONT_LEFT_BIT:
229 /* front buffer only */
230 grDepthMask(FXFALSE);
231 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
232 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
233 if (ctx->Depth.Mask) {
234 grDepthMask(FXTRUE);
235 }
236 break;
237 case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT:
238 /* front and back */
239 grDepthMask(FXFALSE);
240 grRenderBuffer(GR_BUFFER_BACKBUFFER);
241 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
242 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
243 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
244 if (ctx->Depth.Mask) {
245 grDepthMask(FXTRUE);
246 }
247 break;
248 case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT:
249 /* clear front */
250 grDepthMask(FXFALSE);
251 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
252 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
253 /* clear back and depth */
254 grDepthMask(FXTRUE);
255 grRenderBuffer(GR_BUFFER_BACKBUFFER);
256 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
257 if (!ctx->Depth.Mask) {
258 grDepthMask(FXFALSE);
259 }
260 break;
261 case DD_DEPTH_BIT:
262 /* just the depth buffer */
263 grRenderBuffer(GR_BUFFER_BACKBUFFER);
264 grColorMask(FXFALSE, FXFALSE);
265 grDepthMask(FXTRUE);
266 FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD);
267 grColorMask(FXTRUE, ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer);
268 if (ctx->Color._DrawDestMask & FRONT_LEFT_BIT)
269 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
270 if (!ctx->Depth.Test || !ctx->Depth.Mask)
271 grDepthMask(FXFALSE);
272 break;
273 default:
274 /* error */
275 ;
276 }
277
278 /* Clear any remaining buffers:
279 */
280 if (softwareMask)
281 _swrast_Clear(ctx, softwareMask, all, x, y, width, height);
282 }
283
284
285 /* Set the buffer used for drawing */
286 /* XXX support for separate read/draw buffers hasn't been tested */
287 static void
288 fxDDSetDrawBuffer(GLcontext * ctx, GLenum mode)
289 {
290 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
291
292 if (MESA_VERBOSE & VERBOSE_DRIVER) {
293 fprintf(stderr, "fxmesa: fxDDSetBuffer(%x)\n", (int) mode);
294 }
295
296 if (mode == GL_FRONT_LEFT) {
297 fxMesa->currentFB = GR_BUFFER_FRONTBUFFER;
298 grRenderBuffer(fxMesa->currentFB);
299 }
300 else if (mode == GL_BACK_LEFT) {
301 fxMesa->currentFB = GR_BUFFER_BACKBUFFER;
302 grRenderBuffer(fxMesa->currentFB);
303 }
304 else if (mode == GL_NONE) {
305 grColorMask(FXFALSE, FXFALSE);
306 }
307 else {
308 /* we'll need a software fallback */
309 /* XXX not implemented */
310 }
311
312 /* update s/w fallback state */
313 _swrast_DrawBuffer(ctx, mode);
314 }
315
316
317
318
319
320 static void
321 fxDDDrawBitmap(GLcontext * ctx, GLint px, GLint py,
322 GLsizei width, GLsizei height,
323 const struct gl_pixelstore_attrib *unpack,
324 const GLubyte * bitmap)
325 {
326 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
327 GrLfbInfo_t info;
328 FxU16 color;
329 const struct gl_pixelstore_attrib *finalUnpack;
330 struct gl_pixelstore_attrib scissoredUnpack;
331
332 /* check if there's any raster operations enabled which we can't handle */
333 if (ctx->Color.AlphaEnabled ||
334 ctx->Color.BlendEnabled ||
335 ctx->Depth.Test ||
336 ctx->Fog.Enabled ||
337 ctx->Color.ColorLogicOpEnabled ||
338 ctx->Stencil.Enabled ||
339 ctx->Scissor.Enabled ||
340 (ctx->DrawBuffer->UseSoftwareAlphaBuffers &&
341 ctx->Color.ColorMask[ACOMP]) ||
342 (ctx->Color._DrawDestMask != FRONT_LEFT_BIT &&
343 ctx->Color._DrawDestMask != BACK_LEFT_BIT)) {
344 _swrast_Bitmap(ctx, px, py, width, height, unpack, bitmap);
345 return;
346 }
347
348
349 if (ctx->Scissor.Enabled) {
350 /* This is a bit tricky, but by carefully adjusting the px, py,
351 * width, height, skipPixels and skipRows values we can do
352 * scissoring without special code in the rendering loop.
353 *
354 * KW: This code is never reached, see the test above.
355 */
356
357 /* we'll construct a new pixelstore struct */
358 finalUnpack = &scissoredUnpack;
359 scissoredUnpack = *unpack;
360 if (scissoredUnpack.RowLength == 0)
361 scissoredUnpack.RowLength = width;
362
363 /* clip left */
364 if (px < ctx->Scissor.X) {
365 scissoredUnpack.SkipPixels += (ctx->Scissor.X - px);
366 width -= (ctx->Scissor.X - px);
367 px = ctx->Scissor.X;
368 }
369 /* clip right */
370 if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) {
371 width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width));
372 }
373 /* clip bottom */
374 if (py < ctx->Scissor.Y) {
375 scissoredUnpack.SkipRows += (ctx->Scissor.Y - py);
376 height -= (ctx->Scissor.Y - py);
377 py = ctx->Scissor.Y;
378 }
379 /* clip top */
380 if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) {
381 height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height));
382 }
383
384 if (width <= 0 || height <= 0)
385 return;
386 }
387 else {
388 finalUnpack = unpack;
389 }
390
391 /* compute pixel value */
392 {
393 GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f);
394 GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f);
395 GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f);
396 /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f); */
397 if (fxMesa->bgrOrder)
398 color = (FxU16)
399 (((FxU16) 0xf8 & b) << (11 - 3)) |
400 (((FxU16) 0xfc & g) << (5 - 3 + 1)) | (((FxU16) 0xf8 & r) >> 3);
401 else
402 color = (FxU16)
403 (((FxU16) 0xf8 & r) << (11 - 3)) |
404 (((FxU16) 0xfc & g) << (5 - 3 + 1)) | (((FxU16) 0xf8 & b) >> 3);
405 }
406
407 info.size = sizeof(info);
408 if (!grLfbLock(GR_LFB_WRITE_ONLY,
409 fxMesa->currentFB,
410 GR_LFBWRITEMODE_565,
411 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
412 #ifndef FX_SILENT
413 fprintf(stderr, "fx Driver: error locking the linear frame buffer\n");
414 #endif
415 return;
416 }
417
418 {
419 const GLint winX = 0;
420 const GLint winY = fxMesa->height - 1;
421 /* The dest stride depends on the hardware and whether we're drawing
422 * to the front or back buffer. This compile-time test seems to do
423 * the job for now.
424 */
425 const GLint dstStride = info.strideInBytes / 2; /* stride in GLushorts */
426
427 GLint row;
428 /* compute dest address of bottom-left pixel in bitmap */
429 GLushort *dst = (GLushort *) info.lfbPtr
430 + (winY - py) * dstStride + (winX + px);
431
432 for (row = 0; row < height; row++) {
433 const GLubyte *src =
434 (const GLubyte *) _mesa_image_address(finalUnpack,
435 bitmap, width, height,
436 GL_COLOR_INDEX, GL_BITMAP,
437 0, row, 0);
438 if (finalUnpack->LsbFirst) {
439 /* least significan bit first */
440 GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7);
441 GLint col;
442 for (col = 0; col < width; col++) {
443 if (*src & mask) {
444 dst[col] = color;
445 }
446 if (mask == 128U) {
447 src++;
448 mask = 1U;
449 }
450 else {
451 mask = mask << 1;
452 }
453 }
454 if (mask != 1)
455 src++;
456 }
457 else {
458 /* most significan bit first */
459 GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7);
460 GLint col;
461 for (col = 0; col < width; col++) {
462 if (*src & mask) {
463 dst[col] = color;
464 }
465 if (mask == 1U) {
466 src++;
467 mask = 128U;
468 }
469 else {
470 mask = mask >> 1;
471 }
472 }
473 if (mask != 128)
474 src++;
475 }
476 dst -= dstStride;
477 }
478 }
479
480 grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB);
481 }
482
483
484 static void
485 fxDDReadPixels(GLcontext * ctx, GLint x, GLint y,
486 GLsizei width, GLsizei height,
487 GLenum format, GLenum type,
488 const struct gl_pixelstore_attrib *packing, GLvoid * dstImage)
489 {
490 if (ctx->_ImageTransferState) {
491 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
492 packing, dstImage);
493 return;
494 }
495 else {
496 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
497 GrLfbInfo_t info;
498
499 BEGIN_BOARD_LOCK();
500 if (grLfbLock(GR_LFB_READ_ONLY,
501 fxMesa->currentFB,
502 GR_LFBWRITEMODE_ANY,
503 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
504 const GLint winX = 0;
505 const GLint winY = fxMesa->height - 1;
506 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
507 const GLushort *src = (const GLushort *) info.lfbPtr
508 + (winY - y) * srcStride + (winX + x);
509 GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage,
510 width, height, format,
511 type, 0, 0, 0);
512 GLint dstStride =
513 _mesa_image_row_stride(packing, width, format, type);
514
515 if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
516 /* convert 5R6G5B into 8R8G8B */
517 GLint row, col;
518 const GLint halfWidth = width >> 1;
519 const GLint extraPixel = (width & 1);
520 for (row = 0; row < height; row++) {
521 GLubyte *d = dst;
522 for (col = 0; col < halfWidth; col++) {
523 const GLuint pixel = ((const GLuint *) src)[col];
524 const GLint pixel0 = pixel & 0xffff;
525 const GLint pixel1 = pixel >> 16;
526 *d++ = FX_PixelToR[pixel0];
527 *d++ = FX_PixelToG[pixel0];
528 *d++ = FX_PixelToB[pixel0];
529 *d++ = FX_PixelToR[pixel1];
530 *d++ = FX_PixelToG[pixel1];
531 *d++ = FX_PixelToB[pixel1];
532 }
533 if (extraPixel) {
534 GLushort pixel = src[width - 1];
535 *d++ = FX_PixelToR[pixel];
536 *d++ = FX_PixelToG[pixel];
537 *d++ = FX_PixelToB[pixel];
538 }
539 dst += dstStride;
540 src -= srcStride;
541 }
542 }
543 else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
544 /* convert 5R6G5B into 8R8G8B8A */
545 GLint row, col;
546 const GLint halfWidth = width >> 1;
547 const GLint extraPixel = (width & 1);
548 for (row = 0; row < height; row++) {
549 GLubyte *d = dst;
550 for (col = 0; col < halfWidth; col++) {
551 const GLuint pixel = ((const GLuint *) src)[col];
552 const GLint pixel0 = pixel & 0xffff;
553 const GLint pixel1 = pixel >> 16;
554 *d++ = FX_PixelToR[pixel0];
555 *d++ = FX_PixelToG[pixel0];
556 *d++ = FX_PixelToB[pixel0];
557 *d++ = 255;
558 *d++ = FX_PixelToR[pixel1];
559 *d++ = FX_PixelToG[pixel1];
560 *d++ = FX_PixelToB[pixel1];
561 *d++ = 255;
562 }
563 if (extraPixel) {
564 const GLushort pixel = src[width - 1];
565 *d++ = FX_PixelToR[pixel];
566 *d++ = FX_PixelToG[pixel];
567 *d++ = FX_PixelToB[pixel];
568 *d++ = 255;
569 }
570 dst += dstStride;
571 src -= srcStride;
572 }
573 }
574 else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
575 /* directly memcpy 5R6G5B pixels into client's buffer */
576 const GLint widthInBytes = width * 2;
577 GLint row;
578 for (row = 0; row < height; row++) {
579 MEMCPY(dst, src, widthInBytes);
580 dst += dstStride;
581 src -= srcStride;
582 }
583 }
584 else {
585 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
586 END_BOARD_LOCK();
587 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
588 packing, dstImage);
589 return;
590 }
591
592 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
593 }
594 END_BOARD_LOCK();
595 }
596 }
597
598 static void fxDDReadPixels555 (GLcontext * ctx,
599 GLint x, GLint y,
600 GLsizei width, GLsizei height,
601 GLenum format, GLenum type,
602 const struct gl_pixelstore_attrib *packing,
603 GLvoid *dstImage)
604 {
605 if (ctx->_ImageTransferState) {
606 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
607 packing, dstImage);
608 return;
609 }
610 else {
611 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
612 GrLfbInfo_t info;
613
614 BEGIN_BOARD_LOCK();
615 if (grLfbLock(GR_LFB_READ_ONLY,
616 fxMesa->currentFB,
617 GR_LFBWRITEMODE_ANY,
618 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
619 const GLint winX = 0;
620 const GLint winY = fxMesa->height - 1;
621 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
622 const GLushort *src = (const GLushort *) info.lfbPtr
623 + (winY - y) * srcStride + (winX + x);
624 GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage,
625 width, height, format,
626 type, 0, 0, 0);
627 GLint dstStride =
628 _mesa_image_row_stride(packing, width, format, type);
629
630 if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
631 /* convert 5R5G5B into 8R8G8B */
632 GLint row, col;
633 const GLint halfWidth = width >> 1;
634 const GLint extraPixel = (width & 1);
635 for (row = 0; row < height; row++) {
636 GLubyte *d = dst;
637 for (col = 0; col < halfWidth; col++) {
638 const GLuint pixel = ((const GLuint *) src)[col];
639 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
640 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
641 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
642 *d++ = FX_rgb_scale_5[(pixel >> 16) & 0x1f];
643 *d++ = FX_rgb_scale_5[(pixel >> 21) & 0x1f];
644 *d++ = FX_rgb_scale_5[(pixel >> 26) & 0x1f];
645 }
646 if (extraPixel) {
647 GLushort pixel = src[width - 1];
648 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
649 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
650 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
651 }
652 dst += dstStride;
653 src -= srcStride;
654 }
655 }
656 else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
657 /* convert 5R6G5B into 8R8G8B8A */
658 GLint row, col;
659 const GLint halfWidth = width >> 1;
660 const GLint extraPixel = (width & 1);
661 for (row = 0; row < height; row++) {
662 GLubyte *d = dst;
663 for (col = 0; col < halfWidth; col++) {
664 const GLuint pixel = ((const GLuint *) src)[col];
665 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
666 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
667 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
668 *d++ = (pixel & 0x8000) ? 255 : 0;
669 *d++ = FX_rgb_scale_5[(pixel >> 16) & 0x1f];
670 *d++ = FX_rgb_scale_5[(pixel >> 21) & 0x1f];
671 *d++ = FX_rgb_scale_5[(pixel >> 26) & 0x1f];
672 *d++ = (pixel & 0x80000000) ? 255 : 0;
673 }
674 if (extraPixel) {
675 const GLushort pixel = src[width - 1];
676 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
677 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
678 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
679 *d++ = (pixel & 0x8000) ? 255 : 0;
680 }
681 dst += dstStride;
682 src -= srcStride;
683 }
684 }
685 else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
686 /* directly memcpy 5R5G5B pixels into client's buffer */
687 const GLint widthInBytes = width * 2;
688 GLint row;
689 for (row = 0; row < height; row++) {
690 MEMCPY(dst, src, widthInBytes);
691 dst += dstStride;
692 src -= srcStride;
693 }
694 }
695 else {
696 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
697 END_BOARD_LOCK();
698 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
699 packing, dstImage);
700 return;
701 }
702
703 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
704 }
705 END_BOARD_LOCK();
706 }
707 }
708
709 static void fxDDReadPixels888 (GLcontext * ctx,
710 GLint x, GLint y,
711 GLsizei width, GLsizei height,
712 GLenum format, GLenum type,
713 const struct gl_pixelstore_attrib *packing,
714 GLvoid *dstImage)
715 {
716 if (ctx->_ImageTransferState) {
717 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
718 packing, dstImage);
719 return;
720 }
721 else {
722 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
723 GrLfbInfo_t info;
724
725 BEGIN_BOARD_LOCK();
726 if (grLfbLock(GR_LFB_READ_ONLY,
727 fxMesa->currentFB,
728 GR_LFBWRITEMODE_ANY,
729 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
730 const GLint winX = 0;
731 const GLint winY = fxMesa->height - 1;
732 const GLint srcStride = info.strideInBytes / 4; /* stride in GLuints */
733 const GLuint *src = (const GLuint *) info.lfbPtr
734 + (winY - y) * srcStride + (winX + x);
735 GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage,
736 width, height, format,
737 type, 0, 0, 0);
738 GLint dstStride =
739 _mesa_image_row_stride(packing, width, format, type);
740
741 if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
742 /* convert 8A8R8G8B into 8R8G8B */
743 GLint row, col;
744 for (row = 0; row < height; row++) {
745 GLubyte *d = dst;
746 for (col = 0; col < width; col++) {
747 const GLuint pixel = ((const GLuint *) src)[col];
748 *d++ = pixel >> 16;
749 *d++ = pixel >> 8;
750 *d++ = pixel;
751 }
752 dst += dstStride;
753 src -= srcStride;
754 }
755 }
756 else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
757 /* directly memcpy 8A8R8G8B pixels into client's buffer */
758 const GLint widthInBytes = width * 4;
759 GLint row;
760 for (row = 0; row < height; row++) {
761 MEMCPY(dst, src, widthInBytes);
762 dst += dstStride;
763 src -= srcStride;
764 }
765 }
766 else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
767 /* convert 8A8R8G8B into 5R5G5B */
768 }
769 else {
770 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
771 END_BOARD_LOCK();
772 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
773 packing, dstImage);
774 return;
775 }
776
777 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
778 }
779 END_BOARD_LOCK();
780 }
781 }
782
783
784 static void
785 fxDDFinish(GLcontext * ctx)
786 {
787 grFlush();
788 }
789
790
791
792
793
794 /* KW: Put the word Mesa in the render string because quakeworld
795 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
796 * Why?
797 */
798 static const GLubyte *
799 fxDDGetString(GLcontext * ctx, GLenum name)
800 {
801 switch (name) {
802 case GL_RENDERER:
803 {
804 static char buf[80];
805 GrVoodooConfig_t *vc = &glbHWConfig.SSTs[glbCurrentBoard].VoodooConfig;
806 sprintf(buf, "Mesa %s v0.31 %s %dMB FB, %dMB TM, %d TMU, %s",
807 grGetString(GR_RENDERER),
808 grGetString(GR_HARDWARE),
809 vc->fbRam,
810 (vc->tmuConfig[GR_TMU0].tmuRam + ((vc->nTexelfx > 1) ? vc->tmuConfig[GR_TMU1].tmuRam : 0)),
811 (vc->nTexelfx * vc->numChips),
812 (vc->numChips > 1) ? "SLI" : "NOSLI");
813 return (GLubyte *)buf;
814 }
815 default:
816 return NULL;
817 }
818 }
819
820 static const struct gl_pipeline_stage *fx_pipeline[] = {
821 &_tnl_vertex_transform_stage, /* TODO: Add the fastpath here */
822 &_tnl_normal_transform_stage,
823 &_tnl_lighting_stage,
824 &_tnl_fog_coordinate_stage, /* TODO: Omit fog stage */
825 &_tnl_texgen_stage,
826 &_tnl_texture_transform_stage,
827 &_tnl_point_attenuation_stage,
828 &_tnl_render_stage,
829 0,
830 };
831
832
833
834
835 int
836 fxDDInitFxMesaContext(fxMesaContext fxMesa)
837 {
838 int i;
839
840 for (i = 0; i < 256; i++) {
841 gl_ubyte_to_float_255_color_tab[i] = (float) i;
842 }
843
844 FX_setupGrVertexLayout();
845
846 if (getenv("FX_EMULATE_SINGLE_TMU"))
847 fxMesa->haveTwoTMUs = GL_FALSE;
848
849 if (getenv("FX_GLIDE_SWAPINTERVAL"))
850 fxMesa->swapInterval = atoi(getenv("FX_GLIDE_SWAPINTERVAL"));
851 else
852 fxMesa->swapInterval = 1;
853
854 if (getenv("MESA_FX_SWAP_PENDING"))
855 fxMesa->maxPendingSwapBuffers = atoi(getenv("MESA_FX_SWAP_PENDING"));
856 else
857 fxMesa->maxPendingSwapBuffers = 2;
858
859 if (getenv("MESA_FX_INFO"))
860 fxMesa->verbose = GL_TRUE;
861 else
862 fxMesa->verbose = GL_FALSE;
863
864 fxMesa->color = 0xffffffff;
865 fxMesa->clearC = 0;
866 fxMesa->clearA = 0;
867
868 fxMesa->stats.swapBuffer = 0;
869 fxMesa->stats.reqTexUpload = 0;
870 fxMesa->stats.texUpload = 0;
871 fxMesa->stats.memTexUpload = 0;
872
873 fxMesa->tmuSrc = FX_TMU_NONE;
874 fxMesa->lastUnitsMode = FX_UM_NONE;
875 fxTMInit(fxMesa);
876
877 /* FX units setup */
878
879 fxMesa->unitsState.alphaTestEnabled = GL_FALSE;
880 fxMesa->unitsState.alphaTestFunc = GR_CMP_ALWAYS;
881 fxMesa->unitsState.alphaTestRefValue = 0.0;
882
883 fxMesa->unitsState.blendEnabled = GL_FALSE;
884 fxMesa->unitsState.blendSrcFuncRGB = GR_BLEND_ONE;
885 fxMesa->unitsState.blendDstFuncRGB = GR_BLEND_ZERO;
886 fxMesa->unitsState.blendSrcFuncAlpha = GR_BLEND_ONE;
887 fxMesa->unitsState.blendDstFuncAlpha = GR_BLEND_ZERO;
888
889 fxMesa->unitsState.depthTestEnabled = GL_FALSE;
890 fxMesa->unitsState.depthMask = GL_TRUE;
891 fxMesa->unitsState.depthTestFunc = GR_CMP_LESS;
892
893 grColorMask(FXTRUE, fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
894 if (fxMesa->haveDoubleBuffer) {
895 fxMesa->currentFB = GR_BUFFER_BACKBUFFER;
896 grRenderBuffer(GR_BUFFER_BACKBUFFER);
897 }
898 else {
899 fxMesa->currentFB = GR_BUFFER_FRONTBUFFER;
900 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
901 }
902
903 fxMesa->state = malloc(FX_grGetInteger(GR_GLIDE_STATE_SIZE));
904 fxMesa->fogTable = (GrFog_t *) malloc(FX_grGetInteger(GR_FOG_TABLE_ENTRIES) *
905 sizeof(GrFog_t));
906
907 if (!fxMesa->state || !fxMesa->fogTable) {
908 if (fxMesa->state)
909 free(fxMesa->state);
910 if (fxMesa->fogTable)
911 free(fxMesa->fogTable);
912 return 0;
913 }
914
915 if (fxMesa->haveZBuffer)
916 grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER);
917
918 grLfbWriteColorFormat(GR_COLORFORMAT_ABGR);
919
920 fxMesa->textureAlign = FX_grGetInteger(GR_TEXTURE_ALIGN);
921 /* [koolsmoky] */
922 {
923 int textureSize = ((fxMesa->maxTextureSize > 2048) ? 2048 : fxMesa->maxTextureSize);
924 fxMesa->glCtx->Const.MaxTextureLevels = 0;
925 do {
926 fxMesa->glCtx->Const.MaxTextureLevels++;
927 } while ((textureSize >>= 0x1) & 0x7ff);
928 }
929 fxMesa->glCtx->Const.MaxTextureUnits = fxMesa->haveTwoTMUs ? 2 : 1;
930 fxMesa->new_state = _NEW_ALL;
931
932 /* Initialize the software rasterizer and helper modules.
933 */
934 _swrast_CreateContext(fxMesa->glCtx);
935 _ac_CreateContext(fxMesa->glCtx);
936 _tnl_CreateContext(fxMesa->glCtx);
937 _swsetup_CreateContext(fxMesa->glCtx);
938
939 /* Install customized pipeline */
940 _tnl_destroy_pipeline(fxMesa->glCtx);
941 _tnl_install_pipeline(fxMesa->glCtx, fx_pipeline);
942
943 fxAllocVB(fxMesa->glCtx);
944
945 fxSetupDDPointers(fxMesa->glCtx);
946 fxDDInitTriFuncs(fxMesa->glCtx);
947
948 /* Tell the software rasterizer to use pixel fog always.
949 */
950 _swrast_allow_vertex_fog(fxMesa->glCtx, GL_FALSE);
951 _swrast_allow_pixel_fog(fxMesa->glCtx, GL_TRUE);
952
953 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
954 * tell render stage not to clip fog coords).
955 */
956 /* _tnl_calculate_vertex_fog( fxMesa->glCtx, GL_FALSE ); */
957
958 fxDDInitExtensions(fxMesa->glCtx);
959
960 grGlideGetState((GrState *) fxMesa->state);
961
962 return 1;
963 }
964
965 /* Undo the above.
966 */
967 void
968 fxDDDestroyFxMesaContext(fxMesaContext fxMesa)
969 {
970 _swsetup_DestroyContext(fxMesa->glCtx);
971 _tnl_DestroyContext(fxMesa->glCtx);
972 _ac_DestroyContext(fxMesa->glCtx);
973 _swrast_DestroyContext(fxMesa->glCtx);
974
975 if (fxMesa->state)
976 free(fxMesa->state);
977 if (fxMesa->fogTable)
978 free(fxMesa->fogTable);
979 fxTMClose(fxMesa);
980 fxFreeVB(fxMesa->glCtx);
981 }
982
983
984
985
986 void
987 fxDDInitExtensions(GLcontext * ctx)
988 {
989 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
990
991 /*_mesa_add_extension(ctx, GL_TRUE, "3DFX_set_global_palette", 0);*/
992 _mesa_enable_extension(ctx, "GL_EXT_point_parameters");
993 _mesa_enable_extension(ctx, "GL_EXT_paletted_texture");
994 _mesa_enable_extension(ctx, "GL_EXT_texture_lod_bias");
995 _mesa_enable_extension(ctx, "GL_EXT_shared_texture_palette");
996
997 if (fxMesa->haveTwoTMUs)
998 _mesa_enable_extension(ctx, "GL_EXT_texture_env_add");
999
1000 if (fxMesa->haveTwoTMUs)
1001 _mesa_enable_extension(ctx, "GL_ARB_multitexture");
1002 }
1003
1004
1005 /************************************************************************/
1006 /************************************************************************/
1007 /************************************************************************/
1008
1009 /* Check if the hardware supports the current context
1010 *
1011 * Performs similar work to fxDDChooseRenderState() - should be merged.
1012 */
1013 GLboolean
1014 fx_check_IsInHardware(GLcontext * ctx)
1015 {
1016 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
1017
1018 if (ctx->RenderMode != GL_RENDER)
1019 return GL_FALSE;
1020
1021 if (ctx->Stencil.Enabled ||
1022 (ctx->Color._DrawDestMask != FRONT_LEFT_BIT &&
1023 ctx->Color._DrawDestMask != BACK_LEFT_BIT) ||
1024 ((ctx->Color.BlendEnabled)
1025 && (ctx->Color.BlendEquation != GL_FUNC_ADD_EXT))
1026 || ((ctx->Color.ColorLogicOpEnabled)
1027 && (ctx->Color.LogicOp != GL_COPY))
1028 || (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
1029 ||
1030 (!((ctx->
1031 Color.ColorMask[RCOMP] == ctx->Color.ColorMask[GCOMP])
1032 && (ctx->Color.ColorMask[GCOMP] == ctx->Color.ColorMask[BCOMP])
1033 && (ctx->Color.ColorMask[ACOMP] == ctx->Color.ColorMask[ACOMP])))
1034 ) {
1035 return GL_FALSE;
1036 }
1037 /* Unsupported texture/multitexture cases */
1038
1039 if (fxMesa->haveTwoTMUs) {
1040 /* we can only do 2D textures */
1041 if (ctx->Texture.Unit[0]._ReallyEnabled & ~TEXTURE_2D_BIT)
1042 return GL_FALSE;
1043 if (ctx->Texture.Unit[1]._ReallyEnabled & ~TEXTURE_2D_BIT)
1044 return GL_FALSE;
1045
1046 if (ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_2D_BIT) {
1047 if (ctx->Texture.Unit[0].EnvMode == GL_BLEND &&
1048 (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_2D_BIT ||
1049 ctx->Texture.Unit[0].EnvColor[0] != 0 ||
1050 ctx->Texture.Unit[0].EnvColor[1] != 0 ||
1051 ctx->Texture.Unit[0].EnvColor[2] != 0 ||
1052 ctx->Texture.Unit[0].EnvColor[3] != 1)) {
1053 return GL_FALSE;
1054 }
1055 if (ctx->Texture.Unit[0]._Current->Image[0]->Border > 0)
1056 return GL_FALSE;
1057 }
1058
1059 if (ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_2D_BIT) {
1060 if (ctx->Texture.Unit[1].EnvMode == GL_BLEND)
1061 return GL_FALSE;
1062 if (ctx->Texture.Unit[1]._Current->Image[0]->Border > 0)
1063 return GL_FALSE;
1064 }
1065
1066 if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_TEXTURE))
1067 fprintf(stderr, "fxMesa: fxIsInHardware, envmode is %s/%s\n",
1068 _mesa_lookup_enum_by_nr(ctx->Texture.Unit[0].EnvMode),
1069 _mesa_lookup_enum_by_nr(ctx->Texture.Unit[1].EnvMode));
1070
1071 /* KW: This was wrong (I think) and I changed it... which doesn't mean
1072 * it is now correct...
1073 * BP: The old condition just seemed to test if both texture units
1074 * were enabled. That's easy!
1075 */
1076 if (ctx->Texture._EnabledUnits == 0x3) {
1077 /* Can't use multipass to blend a multitextured triangle - fall
1078 * back to software.
1079 */
1080 if (!fxMesa->haveTwoTMUs && ctx->Color.BlendEnabled) {
1081 return GL_FALSE;
1082 }
1083
1084 if ((ctx->Texture.Unit[0].EnvMode != ctx->Texture.Unit[1].EnvMode) &&
1085 (ctx->Texture.Unit[0].EnvMode != GL_MODULATE) &&
1086 (ctx->Texture.Unit[0].EnvMode != GL_REPLACE)) { /* q2, seems ok... */
1087 if (MESA_VERBOSE & VERBOSE_DRIVER)
1088 fprintf(stderr, "fxMesa: unsupported multitex env mode\n");
1089 return GL_FALSE;
1090 }
1091 }
1092 }
1093 else {
1094 /* we have just one texture unit */
1095 if (ctx->Texture._EnabledUnits > 0x1) {
1096 return GL_FALSE;
1097 }
1098
1099 if ((ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_2D_BIT) &&
1100 (ctx->Texture.Unit[0].EnvMode == GL_BLEND)) {
1101 return GL_FALSE;
1102 }
1103 }
1104
1105 return GL_TRUE;
1106 }
1107
1108
1109
1110 static void
1111 update_texture_scales(GLcontext * ctx)
1112 {
1113 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1114 struct gl_texture_unit *t0 = &ctx->Texture.Unit[fxMesa->tmu_source[0]];
1115 struct gl_texture_unit *t1 = &ctx->Texture.Unit[fxMesa->tmu_source[1]];
1116
1117 if (t0 && t0->_Current && FX_TEXTURE_DATA(t0)) {
1118 fxMesa->s0scale = FX_TEXTURE_DATA(t0)->sScale;
1119 fxMesa->t0scale = FX_TEXTURE_DATA(t0)->tScale;
1120 fxMesa->inv_s0scale = 1.0 / fxMesa->s0scale;
1121 fxMesa->inv_t0scale = 1.0 / fxMesa->t0scale;
1122 }
1123
1124 if (t1 && t1->_Current && FX_TEXTURE_DATA(t1)) {
1125 fxMesa->s1scale = FX_TEXTURE_DATA(t1)->sScale;
1126 fxMesa->t1scale = FX_TEXTURE_DATA(t1)->tScale;
1127 fxMesa->inv_s1scale = 1.0 / fxMesa->s1scale;
1128 fxMesa->inv_t1scale = 1.0 / fxMesa->t1scale;
1129 }
1130 }
1131
1132 static void
1133 fxDDUpdateDDPointers(GLcontext * ctx, GLuint new_state)
1134 {
1135 /* TNLcontext *tnl = TNL_CONTEXT(ctx);*/
1136 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1137
1138 _swrast_InvalidateState(ctx, new_state);
1139 _ac_InvalidateState(ctx, new_state);
1140 _tnl_InvalidateState(ctx, new_state);
1141 _swsetup_InvalidateState(ctx, new_state);
1142
1143 /* Recalculate fog table on projection matrix changes. This used to
1144 * be triggered by the NearFar callback.
1145 */
1146 if (new_state & _NEW_PROJECTION)
1147 fxMesa->new_state |= FX_NEW_FOG;
1148
1149 if (new_state & (_FX_NEW_IS_IN_HARDWARE |
1150 _FX_NEW_RENDERSTATE |
1151 _FX_NEW_SETUP_FUNCTION |
1152 _NEW_TEXTURE)) {
1153
1154 if (new_state & _FX_NEW_IS_IN_HARDWARE)
1155 fxCheckIsInHardware(ctx);
1156
1157 if (fxMesa->new_state)
1158 fxSetupFXUnits(ctx);
1159
1160 if (fxMesa->is_in_hardware) {
1161 if (new_state & _FX_NEW_RENDERSTATE)
1162 fxDDChooseRenderState(ctx);
1163
1164 if (new_state & _FX_NEW_SETUP_FUNCTION)
1165 fxChooseVertexState(ctx);
1166 }
1167
1168 if (new_state & _NEW_TEXTURE)
1169 update_texture_scales(ctx);
1170 }
1171 }
1172
1173
1174
1175
1176 void
1177 fxSetupDDPointers(GLcontext * ctx)
1178 {
1179 TNLcontext *tnl = TNL_CONTEXT(ctx);
1180
1181 if (MESA_VERBOSE & VERBOSE_DRIVER) {
1182 fprintf(stderr, "fxmesa: fxSetupDDPointers()\n");
1183 }
1184
1185 ctx->Driver.UpdateState = fxDDUpdateDDPointers;
1186 ctx->Driver.GetString = fxDDGetString;
1187 ctx->Driver.ClearIndex = NULL;
1188 ctx->Driver.ClearColor = fxDDClearColor;
1189 ctx->Driver.Clear = fxDDClear;
1190 ctx->Driver.DrawBuffer = fxDDSetDrawBuffer;
1191 ctx->Driver.GetBufferSize = fxDDBufferSize;
1192 ctx->Driver.Accum = _swrast_Accum;
1193 ctx->Driver.Bitmap = fxDDDrawBitmap;
1194 ctx->Driver.CopyPixels = _swrast_CopyPixels;
1195 ctx->Driver.DrawPixels = _swrast_DrawPixels;
1196 {
1197 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
1198 switch (fxMesa->colDepth) {
1199 case 15:
1200 ctx->Driver.ReadPixels = fxDDReadPixels555;
1201 break;
1202 case 16:
1203 ctx->Driver.ReadPixels = fxDDReadPixels;
1204 break;
1205 case 32:
1206 ctx->Driver.ReadPixels = fxDDReadPixels888;
1207 break;
1208 }
1209 }
1210 ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
1211 ctx->Driver.Finish = fxDDFinish;
1212 ctx->Driver.Flush = NULL;
1213 ctx->Driver.ChooseTextureFormat = fxDDChooseTextureFormat;
1214 ctx->Driver.TexImage1D = _mesa_store_teximage1d;
1215 ctx->Driver.TexImage2D = fxDDTexImage2D;
1216 ctx->Driver.TexImage3D = _mesa_store_teximage3d;
1217 ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
1218 ctx->Driver.TexSubImage2D = fxDDTexSubImage2D;
1219 ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
1220 ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
1221 ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
1222 ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
1223 ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
1224 ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
1225 ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
1226 ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
1227 ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
1228 ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
1229 ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
1230 ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
1231 ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
1232 ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
1233 ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
1234 ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
1235 ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
1236 ctx->Driver.TexEnv = fxDDTexEnv;
1237 ctx->Driver.TexParameter = fxDDTexParam;
1238 ctx->Driver.BindTexture = fxDDTexBind;
1239 ctx->Driver.DeleteTexture = fxDDTexDel;
1240 ctx->Driver.UpdateTexturePalette = fxDDTexPalette;
1241 ctx->Driver.AlphaFunc = fxDDAlphaFunc;
1242 ctx->Driver.BlendFunc = fxDDBlendFunc;
1243 ctx->Driver.DepthFunc = fxDDDepthFunc;
1244 ctx->Driver.DepthMask = fxDDDepthMask;
1245 ctx->Driver.ColorMask = fxDDColorMask;
1246 ctx->Driver.Fogfv = fxDDFogfv;
1247 ctx->Driver.Scissor = fxDDScissor;
1248 ctx->Driver.FrontFace = fxDDFrontFace;
1249 ctx->Driver.CullFace = fxDDCullFace;
1250 ctx->Driver.ShadeModel = fxDDShadeModel;
1251 ctx->Driver.Enable = fxDDEnable;
1252
1253 tnl->Driver.RunPipeline = _tnl_run_pipeline;
1254
1255 fxSetupDDSpanPointers(ctx);
1256 fxDDUpdateDDPointers(ctx, ~0);
1257 }
1258
1259
1260 #else
1261
1262
1263 /*
1264 * Need this to provide at least one external definition.
1265 */
1266
1267 extern int gl_fx_dummy_function_dd(void);
1268 int
1269 gl_fx_dummy_function_dd(void)
1270 {
1271 return 0;
1272 }
1273
1274 #endif /* FX */