3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
29 * Thank you for your contribution, David!
31 * Please make note of the above copyright/license statement. If you
32 * contributed code or bug fixes to this code under the previous (GNU
33 * Library) license and object to the new license, your code will be
34 * removed at your request. Please see the Mesa docs/COPYRIGHT file
35 * for more information.
37 * Additional Mesa/3Dfx driver developers:
38 * Daryll Strauss <daryll@precisioninsight.com>
39 * Keith Whitwell <keith@precisioninsight.com>
41 * See fxapi.h for more revision/author details.
45 /* fxdd.c - 3Dfx VooDoo Mesa device driver functions */
58 #include "extensions.h"
59 #include "swrast/swrast.h"
60 #include "swrast_setup/swrast_setup.h"
63 /* These lookup table are used to extract RGB values in [0,255] from
64 * 16-bit pixel values.
66 GLubyte FX_PixelToR
[0x10000];
67 GLubyte FX_PixelToG
[0x10000];
68 GLubyte FX_PixelToB
[0x10000];
72 * Initialize the FX_PixelTo{RGB} arrays.
73 * Input: bgrOrder - if TRUE, pixels are in BGR order, else RGB order.
75 void fxInitPixelTables(fxMesaContext fxMesa
, GLboolean bgrOrder
)
79 fxMesa
->bgrOrder
=bgrOrder
;
80 for (pixel
= 0; pixel
<= 0xffff; pixel
++) {
83 r
= (pixel
& 0x001F) << 3;
84 g
= (pixel
& 0x07E0) >> 3;
85 b
= (pixel
& 0xF800) >> 8;
88 r
= (pixel
& 0xF800) >> 8;
89 g
= (pixel
& 0x07E0) >> 3;
90 b
= (pixel
& 0x001F) << 3;
92 r
= r
* 255 / 0xF8; /* fill in low-order bits */
95 FX_PixelToR
[pixel
] = r
;
96 FX_PixelToG
[pixel
] = g
;
97 FX_PixelToB
[pixel
] = b
;
102 /**********************************************************************/
103 /***** Miscellaneous functions *****/
104 /**********************************************************************/
106 /* Return buffer size information */
107 static void fxDDBufferSize(GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
109 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
111 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
112 fprintf(stderr
,"fxmesa: fxDDBufferSize(...) Start\n");
115 *width
=fxMesa
->width
;
116 *height
=fxMesa
->height
;
118 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
119 fprintf(stderr
,"fxmesa: fxDDBufferSize(...) End\n");
124 /* Set current drawing color */
125 static void fxDDSetColor(GLcontext
*ctx
, GLubyte red
, GLubyte green
,
126 GLubyte blue
, GLubyte alpha
)
128 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
130 ASSIGN_4V( col
, red
, green
, blue
, alpha
);
132 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
133 fprintf(stderr
,"fxmesa: fxDDSetColor(%d,%d,%d,%d)\n",red
,green
,blue
,alpha
);
136 fxMesa
->color
=FXCOLOR4(col
);
140 /* Implements glClearColor() */
141 static void fxDDClearColor(GLcontext
*ctx
, GLubyte red
, GLubyte green
,
142 GLubyte blue
, GLubyte alpha
)
144 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
149 ASSIGN_4V( col
, red
, green
, blue
, 255 );
151 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
152 fprintf(stderr
,"fxmesa: fxDDClearColor(%d,%d,%d,%d)\n",red
,green
,blue
,alpha
);
155 fxMesa
->clearC
=FXCOLOR4( col
);
156 fxMesa
->clearA
=alpha
;
160 /* Clear the color and/or depth buffers */
161 static GLbitfield
fxDDClear(GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
162 GLint x
, GLint y
, GLint width
, GLint height
)
164 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
165 const GLuint colorMask
= *((GLuint
*) &ctx
->Color
.ColorMask
);
166 const FxU16 clearD
= (FxU16
) (ctx
->Depth
.Clear
* 0xffff);
167 GLbitfield softwareMask
= mask
& (DD_STENCIL_BIT
| DD_ACCUM_BIT
);
169 /* we can't clear stencil or accum buffers */
170 mask
&= ~(DD_STENCIL_BIT
| DD_ACCUM_BIT
);
172 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
173 fprintf(stderr
,"fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x
, (int) y
,
174 (int) width
, (int) height
);
177 if (colorMask
!= 0xffffffff) {
178 /* do masked color buffer clears in software */
179 softwareMask
|= (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
180 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
184 * This could probably be done fancier but doing each possible case
185 * explicitly is less error prone.
188 case DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
189 /* back buffer & depth */
190 FX_grDepthMask(FXTRUE
);
191 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
192 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
193 if (!ctx
->Depth
.Mask
) {
194 FX_grDepthMask(FXFALSE
);
197 case DD_FRONT_LEFT_BIT
| DD_DEPTH_BIT
:
198 /* XXX it appears that the depth buffer isn't cleared when
199 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
200 * This is a work-around/
203 FX_grDepthMask(FXTRUE
);
204 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
205 FX_grColorMask(FXFALSE
,FXFALSE
);
206 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
208 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
209 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
210 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
212 case DD_BACK_LEFT_BIT
:
213 /* back buffer only */
214 FX_grDepthMask(FXFALSE
);
215 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
216 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
217 if (ctx
->Depth
.Mask
) {
218 FX_grDepthMask(FXTRUE
);
221 case DD_FRONT_LEFT_BIT
:
222 /* front buffer only */
223 FX_grDepthMask(FXFALSE
);
224 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
225 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
226 if (ctx
->Depth
.Mask
) {
227 FX_grDepthMask(FXTRUE
);
230 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
:
232 FX_grDepthMask(FXFALSE
);
233 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
234 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
235 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
236 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
237 if (ctx
->Depth
.Mask
) {
238 FX_grDepthMask(FXTRUE
);
241 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
243 FX_grDepthMask(FXFALSE
);
244 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
245 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
246 /* clear back and depth */
247 FX_grDepthMask(FXTRUE
);
248 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
249 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
250 if (!ctx
->Depth
.Mask
) {
251 FX_grDepthMask(FXFALSE
);
255 /* just the depth buffer */
256 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
257 FX_grColorMask(FXFALSE
,FXFALSE
);
258 FX_grDepthMask(FXTRUE
);
259 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
260 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
261 if (ctx
->Color
.DrawDestMask
& FRONT_LEFT_BIT
)
262 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
263 if (!ctx
->Depth
.Test
|| !ctx
->Depth
.Mask
)
264 FX_grDepthMask(FXFALSE
);
275 /* Set the buffer used for drawing */
276 /* XXX support for separate read/draw buffers hasn't been tested */
277 static GLboolean
fxDDSetDrawBuffer(GLcontext
*ctx
, GLenum mode
)
279 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
281 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
282 fprintf(stderr
,"fxmesa: fxDDSetBuffer(%x)\n", (int) mode
);
285 if (mode
== GL_FRONT_LEFT
) {
286 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
287 FX_grRenderBuffer(fxMesa
->currentFB
);
290 else if (mode
== GL_BACK_LEFT
) {
291 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
292 FX_grRenderBuffer(fxMesa
->currentFB
);
295 else if (mode
== GL_NONE
) {
296 FX_grColorMask(FXFALSE
,FXFALSE
);
305 /* Set the buffer used for reading */
306 /* XXX support for separate read/draw buffers hasn't been tested */
307 static void fxDDSetReadBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
310 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
313 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
314 fprintf(stderr
,"fxmesa: fxDDSetBuffer(%x)\n", (int) mode
);
317 if (mode
== GL_FRONT_LEFT
) {
318 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
319 FX_grRenderBuffer(fxMesa
->currentFB
);
321 else if (mode
== GL_BACK_LEFT
) {
322 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
323 FX_grRenderBuffer(fxMesa
->currentFB
);
329 static GLboolean
fxDDDrawBitmap(GLcontext
*ctx
, GLint px
, GLint py
,
330 GLsizei width
, GLsizei height
,
331 const struct gl_pixelstore_attrib
*unpack
,
332 const GLubyte
*bitmap
)
334 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
337 const struct gl_pixelstore_attrib
*finalUnpack
;
338 struct gl_pixelstore_attrib scissoredUnpack
;
340 /* check if there's any raster operations enabled which we can't handle */
341 if (ctx
->Color
.AlphaEnabled
||
342 ctx
->Color
.BlendEnabled
||
345 ctx
->Color
.ColorLogicOpEnabled
||
346 ctx
->Stencil
.Enabled
||
347 ctx
->Scissor
.Enabled
||
348 ( ctx
->DrawBuffer
->UseSoftwareAlphaBuffers
&&
349 ctx
->Color
.ColorMask
[ACOMP
]) ||
350 ctx
->Color
.MultiDrawBuffer
)
354 if (ctx
->Scissor
.Enabled
) {
355 /* This is a bit tricky, but by carefully adjusting the px, py,
356 * width, height, skipPixels and skipRows values we can do
357 * scissoring without special code in the rendering loop.
359 * KW: This code is never reached, see the test above.
362 /* we'll construct a new pixelstore struct */
363 finalUnpack
= &scissoredUnpack
;
364 scissoredUnpack
= *unpack
;
365 if (scissoredUnpack
.RowLength
== 0)
366 scissoredUnpack
.RowLength
= width
;
369 if (px
< ctx
->Scissor
.X
) {
370 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
371 width
-= (ctx
->Scissor
.X
- px
);
375 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
376 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
379 if (py
< ctx
->Scissor
.Y
) {
380 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
381 height
-= (ctx
->Scissor
.Y
- py
);
385 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
386 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
389 if (width
<= 0 || height
<= 0)
390 return GL_TRUE
; /* totally scissored away */
393 finalUnpack
= unpack
;
396 /* compute pixel value */
398 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[0] * 255.0f
);
399 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[1] * 255.0f
);
400 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[2] * 255.0f
);
401 /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f);*/
402 if (fxMesa
->bgrOrder
)
404 ( ((FxU16
)0xf8 & b
) << (11-3)) |
405 ( ((FxU16
)0xfc & g
) << (5-3+1)) |
406 ( ((FxU16
)0xf8 & r
) >> 3);
409 ( ((FxU16
)0xf8 & r
) << (11-3)) |
410 ( ((FxU16
)0xfc & g
) << (5-3+1)) |
411 ( ((FxU16
)0xf8 & b
) >> 3);
414 info
.size
= sizeof(info
);
415 if (!FX_grLfbLock(GR_LFB_WRITE_ONLY
,
418 GR_ORIGIN_UPPER_LEFT
,
422 fprintf(stderr
,"fx Driver: error locking the linear frame buffer\n");
428 const GLint winX
= 0;
429 const GLint winY
= fxMesa
->height
- 1;
430 /* The dest stride depends on the hardware and whether we're drawing
431 * to the front or back buffer. This compile-time test seems to do
434 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
437 /* compute dest address of bottom-left pixel in bitmap */
438 GLushort
*dst
= (GLushort
*) info
.lfbPtr
439 + (winY
- py
) * dstStride
442 for (row
= 0; row
< height
; row
++) {
443 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( finalUnpack
,
444 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
445 if (finalUnpack
->LsbFirst
) {
446 /* least significan bit first */
447 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
449 for (col
=0; col
<width
; col
++) {
465 /* most significan bit first */
466 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
468 for (col
=0; col
<width
; col
++) {
487 FX_grLfbUnlock(GR_LFB_WRITE_ONLY
,fxMesa
->currentFB
);
492 static GLboolean
fxDDReadPixels( GLcontext
*ctx
, GLint x
, GLint y
,
493 GLsizei width
, GLsizei height
,
494 GLenum format
, GLenum type
,
495 const struct gl_pixelstore_attrib
*packing
,
498 if (ctx
->_ImageTransferState
) {
499 return GL_FALSE
; /* can't do this */
502 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
504 GLboolean result
= GL_FALSE
;
507 if (grLfbLock(GR_LFB_READ_ONLY
,
510 GR_ORIGIN_UPPER_LEFT
,
513 const GLint winX
= 0;
514 const GLint winY
= fxMesa
->height
- 1;
515 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
516 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
517 + (winY
- y
) * srcStride
+ (winX
+ x
);
518 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
519 width
, height
, format
, type
, 0, 0, 0);
520 GLint dstStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
522 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
523 /* convert 5R6G5B into 8R8G8B */
525 const GLint halfWidth
= width
>> 1;
526 const GLint extraPixel
= (width
& 1);
527 for (row
= 0; row
< height
; row
++) {
529 for (col
= 0; col
< halfWidth
; col
++) {
530 const GLuint pixel
= ((const GLuint
*) src
)[col
];
531 const GLint pixel0
= pixel
& 0xffff;
532 const GLint pixel1
= pixel
>> 16;
533 *d
++ = FX_PixelToR
[pixel0
];
534 *d
++ = FX_PixelToG
[pixel0
];
535 *d
++ = FX_PixelToB
[pixel0
];
536 *d
++ = FX_PixelToR
[pixel1
];
537 *d
++ = FX_PixelToG
[pixel1
];
538 *d
++ = FX_PixelToB
[pixel1
];
541 GLushort pixel
= src
[width
-1];
542 *d
++ = FX_PixelToR
[pixel
];
543 *d
++ = FX_PixelToG
[pixel
];
544 *d
++ = FX_PixelToB
[pixel
];
551 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
552 /* convert 5R6G5B into 8R8G8B8A */
554 const GLint halfWidth
= width
>> 1;
555 const GLint extraPixel
= (width
& 1);
556 for (row
= 0; row
< height
; row
++) {
558 for (col
= 0; col
< halfWidth
; col
++) {
559 const GLuint pixel
= ((const GLuint
*) src
)[col
];
560 const GLint pixel0
= pixel
& 0xffff;
561 const GLint pixel1
= pixel
>> 16;
562 *d
++ = FX_PixelToR
[pixel0
];
563 *d
++ = FX_PixelToG
[pixel0
];
564 *d
++ = FX_PixelToB
[pixel0
];
566 *d
++ = FX_PixelToR
[pixel1
];
567 *d
++ = FX_PixelToG
[pixel1
];
568 *d
++ = FX_PixelToB
[pixel1
];
572 const GLushort pixel
= src
[width
-1];
573 *d
++ = FX_PixelToR
[pixel
];
574 *d
++ = FX_PixelToG
[pixel
];
575 *d
++ = FX_PixelToB
[pixel
];
583 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
584 /* directly memcpy 5R6G5B pixels into client's buffer */
585 const GLint widthInBytes
= width
* 2;
587 for (row
= 0; row
< height
; row
++) {
588 MEMCPY(dst
, src
, widthInBytes
);
598 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
607 static void fxDDFinish(GLcontext
*ctx
)
616 /* KW: Put the word Mesa in the render string because quakeworld
617 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
620 static const GLubyte
*fxDDGetString(GLcontext
*ctx
, GLenum name
)
627 if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_VOODOO
) {
628 GrVoodooConfig_t
*vc
=
629 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
;
632 "Mesa Glide v0.30 Voodoo_Graphics %d "
633 "CARD/%d FB/%d TM/%d TMU/%s",
635 (vc
->sliDetect
? (vc
->fbRam
*2) : vc
->fbRam
),
636 (vc
->tmuConfig
[GR_TMU0
].tmuRam
+
637 ((vc
->nTexelfx
>1) ? vc
->tmuConfig
[GR_TMU1
].tmuRam
: 0)),
639 (vc
->sliDetect
? "SLI" : "NOSLI"));
641 else if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_SST96
) {
642 GrSst96Config_t
*sc
=
643 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
;
646 "Glide v0.30 Voodoo_Rush %d "
647 "CARD/%d FB/%d TM/%d TMU/NOSLI",
650 sc
->tmuConfig
.tmuRam
,
654 strcpy(buf
, "Glide v0.30 UNKNOWN");
656 return (GLubyte
*) buf
;
664 int fxDDInitFxMesaContext( fxMesaContext fxMesa
)
667 FX_setupGrVertexLayout();
669 if (getenv("FX_EMULATE_SINGLE_TMU"))
670 fxMesa
->haveTwoTMUs
= GL_FALSE
;
672 fxMesa
->emulateTwoTMUs
= fxMesa
->haveTwoTMUs
;
674 if (!getenv("FX_DONT_FAKE_MULTITEX"))
675 fxMesa
->emulateTwoTMUs
= GL_TRUE
;
677 if(getenv("FX_GLIDE_SWAPINTERVAL"))
678 fxMesa
->swapInterval
=atoi(getenv("FX_GLIDE_SWAPINTERVAL"));
680 fxMesa
->swapInterval
=1;
682 if(getenv("MESA_FX_SWAP_PENDING"))
683 fxMesa
->maxPendingSwapBuffers
=atoi(getenv("MESA_FX_SWAP_PENDING"));
685 fxMesa
->maxPendingSwapBuffers
=2;
687 if(getenv("MESA_FX_INFO"))
688 fxMesa
->verbose
=GL_TRUE
;
690 fxMesa
->verbose
=GL_FALSE
;
692 fxMesa
->color
=0xffffffff;
696 fxMesa
->stats
.swapBuffer
=0;
697 fxMesa
->stats
.reqTexUpload
=0;
698 fxMesa
->stats
.texUpload
=0;
699 fxMesa
->stats
.memTexUpload
=0;
701 fxMesa
->tmuSrc
=FX_TMU_NONE
;
702 fxMesa
->lastUnitsMode
=FX_UM_NONE
;
707 fxMesa
->unitsState
.alphaTestEnabled
=GL_FALSE
;
708 fxMesa
->unitsState
.alphaTestFunc
=GR_CMP_ALWAYS
;
709 fxMesa
->unitsState
.alphaTestRefValue
=0;
711 fxMesa
->unitsState
.blendEnabled
=GL_FALSE
;
712 fxMesa
->unitsState
.blendSrcFuncRGB
=GR_BLEND_ONE
;
713 fxMesa
->unitsState
.blendDstFuncRGB
=GR_BLEND_ZERO
;
714 fxMesa
->unitsState
.blendSrcFuncAlpha
=GR_BLEND_ONE
;
715 fxMesa
->unitsState
.blendDstFuncAlpha
=GR_BLEND_ZERO
;
717 fxMesa
->unitsState
.depthTestEnabled
=GL_FALSE
;
718 fxMesa
->unitsState
.depthMask
=GL_TRUE
;
719 fxMesa
->unitsState
.depthTestFunc
=GR_CMP_LESS
;
721 FX_grColorMask(FXTRUE
, fxMesa
->haveAlphaBuffer
? FXTRUE
: FXFALSE
);
722 if(fxMesa
->haveDoubleBuffer
) {
723 fxMesa
->currentFB
=GR_BUFFER_BACKBUFFER
;
724 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
726 fxMesa
->currentFB
=GR_BUFFER_FRONTBUFFER
;
727 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
730 fxMesa
->state
= NULL
;
731 fxMesa
->fogTable
= NULL
;
733 fxMesa
->state
= malloc(FX_grGetInteger(FX_GLIDE_STATE_SIZE
));
734 fxMesa
->fogTable
= malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES
)*sizeof(GrFog_t
));
736 if (!fxMesa
->state
|| !fxMesa
->fogTable
) {
737 if (fxMesa
->state
) free(fxMesa
->state
);
738 if (fxMesa
->fogTable
) free(fxMesa
->fogTable
);
742 if(fxMesa
->haveZBuffer
)
743 FX_grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
745 #if (!FXMESA_USE_ARGB)
746 FX_grLfbWriteColorFormat(GR_COLORFORMAT_ABGR
); /* Not every Glide has this */
749 fxMesa
->textureAlign
=FX_grGetInteger(FX_TEXTURE_ALIGN
);
750 fxMesa
->glCtx
->Const
.MaxTextureLevels
=9;
751 fxMesa
->glCtx
->Const
.MaxTextureSize
=256;
752 fxMesa
->glCtx
->Const
.MaxTextureUnits
=fxMesa
->emulateTwoTMUs
? 2 : 1;
753 fxMesa
->new_state
= _NEW_ALL
;
760 /* Initialize the software rasterizer and helper modules.
762 fxMesa
->glCtx
->Driver
.RegisterVB
= fxDDRegisterVB
;
764 _swrast_CreateContext( fxMesa
->glCtx
);
765 _swsetup_CreateContext( fxMesa
->glCtx
);
766 _tnl_CreateContext( fxMesa
->glCtx
);
768 fxSetupDDPointers(fxMesa
->glCtx
);
770 /* Tell the software rasterizer to use pixel fog always.
772 _swrast_allow_vertex_fog( fxMesa
->glCtx
, GL_FALSE
);
773 _swrast_allow_pixel_fog( fxMesa
->glCtx
, GL_TRUE
);
775 fxDDInitExtensions(fxMesa
->glCtx
);
777 FX_grGlideGetState((GrState
*)fxMesa
->state
);
779 /* XXX Fix me too: need to have the 'struct dd' prepared prior to
780 * creating the context... The below is broken if you try to insert
783 fxDDRegisterPipelineStages( fxMesa
->glCtx
);
785 /* Run the config file */
786 _mesa_context_initialize( fxMesa
->glCtx
);
794 void fxDDInitExtensions( GLcontext
*ctx
)
796 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
798 gl_extensions_disable(ctx
, "GL_EXT_blend_logic_op");
799 gl_extensions_disable(ctx
, "GL_EXT_blend_minmax");
800 gl_extensions_disable(ctx
, "GL_EXT_blend_subtract");
801 gl_extensions_disable(ctx
, "GL_EXT_blend_color");
802 gl_extensions_disable(ctx
, "GL_EXT_fog_coord");
804 gl_extensions_add(ctx
, GL_TRUE
, "3DFX_set_global_palette", 0);
806 if (!fxMesa
->haveTwoTMUs
)
807 gl_extensions_disable(ctx
, "GL_EXT_texture_env_add");
809 if (!fxMesa
->emulateTwoTMUs
)
810 gl_extensions_disable(ctx
, "GL_ARB_multitexture");
814 /************************************************************************/
815 /************************************************************************/
816 /************************************************************************/
818 /* Check if the hardware supports the current context
820 * Performs similar work to fxDDChooseRenderState() - should be merged.
822 static GLboolean
fxIsInHardware(GLcontext
*ctx
)
824 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
826 if (ctx
->RenderMode
!= GL_RENDER
)
829 if (!ctx
->Hint
.AllowDrawMem
)
830 return GL_TRUE
; /* you'll take it and like it */
832 if (ctx
->Stencil
.Enabled
||
833 ctx
->Color
.MultiDrawBuffer
||
834 ((ctx
->Color
.BlendEnabled
) && (ctx
->Color
.BlendEquation
!=GL_FUNC_ADD_EXT
)) ||
835 ((ctx
->Color
.ColorLogicOpEnabled
) && (ctx
->Color
.LogicOp
!=GL_COPY
)) ||
836 (ctx
->Light
.Model
.ColorControl
==GL_SEPARATE_SPECULAR_COLOR
) ||
837 (!((ctx
->Color
.ColorMask
[RCOMP
]==ctx
->Color
.ColorMask
[GCOMP
]) &&
838 (ctx
->Color
.ColorMask
[GCOMP
]==ctx
->Color
.ColorMask
[BCOMP
]) &&
839 (ctx
->Color
.ColorMask
[ACOMP
]==ctx
->Color
.ColorMask
[ACOMP
])))
844 /* Unsupported texture/multitexture cases */
846 if(fxMesa
->emulateTwoTMUs
) {
847 if((ctx
->_Enabled
& (TEXTURE0_3D
| TEXTURE1_3D
)) ||
848 /* Not very well written ... */
849 ((ctx
->_Enabled
& (TEXTURE0_1D
| TEXTURE1_1D
)) &&
850 ((ctx
->_Enabled
& (TEXTURE0_2D
| TEXTURE1_2D
))!=(TEXTURE0_2D
| TEXTURE1_2D
)))
855 if (ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) {
856 if (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
&&
857 (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
||
858 ctx
->Texture
.Unit
[0].EnvColor
[0] != 0 ||
859 ctx
->Texture
.Unit
[0].EnvColor
[1] != 0 ||
860 ctx
->Texture
.Unit
[0].EnvColor
[2] != 0 ||
861 ctx
->Texture
.Unit
[0].EnvColor
[3] != 1)) {
864 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
868 if (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
) {
869 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_BLEND
)
871 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
875 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
876 fprintf(stderr
, "fxMesa: fxIsInHardware, envmode is %s/%s\n",
877 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
878 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
880 /* KW: This was wrong (I think) and I changed it... which doesn't mean
881 * it is now correct...
883 if((ctx
->_Enabled
& (TEXTURE0_1D
| TEXTURE0_2D
| TEXTURE0_3D
)) &&
884 (ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)))
886 /* Can't use multipass to blend a multitextured triangle - fall
889 if (!fxMesa
->haveTwoTMUs
&& ctx
->Color
.BlendEnabled
) {
893 if ((ctx
->Texture
.Unit
[0].EnvMode
!=ctx
->Texture
.Unit
[1].EnvMode
) &&
894 (ctx
->Texture
.Unit
[0].EnvMode
!=GL_MODULATE
) &&
895 (ctx
->Texture
.Unit
[0].EnvMode
!=GL_REPLACE
)) /* q2, seems ok... */
897 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
898 fprintf(stderr
, "fxMesa: unsupported multitex env mode\n");
903 if((ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)) ||
904 /* Not very well written ... */
905 ((ctx
->_Enabled
& TEXTURE0_1D
) &&
906 (!(ctx
->_Enabled
& TEXTURE0_2D
)))
912 if((ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) &&
913 (ctx
->Texture
.Unit
[0].EnvMode
==GL_BLEND
)) {
922 static void fxDDUpdateDDPointers(GLcontext
*ctx
)
924 GLuint new_state
= ctx
->NewState
;
926 _swrast_InvalidateState( ctx
, new_state
);
927 _swsetup_InvalidateState( ctx
, new_state
);
928 _tnl_InvalidateState( ctx
, new_state
);
930 /* Recalculate fog table on projection matrix changes. This used to
931 * be triggered by the NearFar callback.
933 if (new_state
& _NEW_PROJECTION
) {
934 FX_CONTEXT(ctx
)->new_state
|= FX_NEW_FOG
;
935 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
938 if (new_state
& (_FX_NEW_IS_IN_HARDWARE
|
939 _FX_NEW_RENDERSTATE
|
940 _FX_NEW_SETUP_FUNCTION
))
942 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
944 if (new_state
& _FX_NEW_IS_IN_HARDWARE
)
945 fxMesa
->is_in_hardware
= fxIsInHardware(ctx
);
947 if (fxMesa
->new_state
)
950 if (new_state
& _FX_NEW_RENDERSTATE
)
951 fxDDChooseRenderState( ctx
);
953 if (new_state
& _FX_NEW_SETUP_FUNCTION
)
954 ctx
->Driver
.RasterSetup
= fxDDChooseSetupFunction(ctx
);
960 void fxSetupDDPointers(GLcontext
*ctx
)
962 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
963 fprintf(stderr
,"fxmesa: fxSetupDDPointers()\n");
966 ctx
->Driver
.UpdateState
=fxDDUpdateDDPointers
;
968 ctx
->Driver
.WriteDepthSpan
=fxDDWriteDepthSpan
;
969 ctx
->Driver
.WriteDepthPixels
=fxDDWriteDepthPixels
;
970 ctx
->Driver
.ReadDepthSpan
=fxDDReadDepthSpan
;
971 ctx
->Driver
.ReadDepthPixels
=fxDDReadDepthPixels
;
973 ctx
->Driver
.GetString
=fxDDGetString
;
975 ctx
->Driver
.ClearIndex
=NULL
;
976 ctx
->Driver
.ClearColor
=fxDDClearColor
;
977 ctx
->Driver
.Clear
=fxDDClear
;
980 ctx
->Driver
.Index
=NULL
;
981 ctx
->Driver
.Color
=fxDDSetColor
;
984 ctx
->Driver
.SetDrawBuffer
=fxDDSetDrawBuffer
;
985 ctx
->Driver
.SetReadBuffer
=fxDDSetReadBuffer
;
986 ctx
->Driver
.GetBufferSize
=fxDDBufferSize
;
988 ctx
->Driver
.Bitmap
=fxDDDrawBitmap
;
989 ctx
->Driver
.DrawPixels
=NULL
;
990 ctx
->Driver
.ReadPixels
=fxDDReadPixels
;
992 ctx
->Driver
.Finish
=fxDDFinish
;
993 ctx
->Driver
.Flush
=NULL
;
995 ctx
->Driver
.RenderStart
=NULL
;
996 ctx
->Driver
.RenderFinish
=_swrast_flush
;
998 ctx
->Driver
.TexImage2D
= fxDDTexImage2D
;
999 ctx
->Driver
.TexSubImage2D
= fxDDTexSubImage2D
;
1000 ctx
->Driver
.GetTexImage
= fxDDGetTexImage
;
1001 ctx
->Driver
.TexEnv
=fxDDTexEnv
;
1002 ctx
->Driver
.TexParameter
=fxDDTexParam
;
1003 ctx
->Driver
.BindTexture
=fxDDTexBind
;
1004 ctx
->Driver
.DeleteTexture
=fxDDTexDel
;
1005 ctx
->Driver
.UpdateTexturePalette
=fxDDTexPalette
;
1007 ctx
->Driver
.AlphaFunc
=fxDDAlphaFunc
;
1008 ctx
->Driver
.BlendFunc
=fxDDBlendFunc
;
1009 ctx
->Driver
.DepthFunc
=fxDDDepthFunc
;
1010 ctx
->Driver
.DepthMask
=fxDDDepthMask
;
1011 ctx
->Driver
.ColorMask
=fxDDColorMask
;
1012 ctx
->Driver
.Fogfv
=fxDDFogfv
;
1013 ctx
->Driver
.Scissor
=fxDDScissor
;
1014 ctx
->Driver
.FrontFace
=fxDDFrontFace
;
1015 ctx
->Driver
.CullFace
=fxDDCullFace
;
1016 ctx
->Driver
.ShadeModel
=fxDDShadeModel
;
1017 ctx
->Driver
.Enable
=fxDDEnable
;
1019 ctx
->Driver
.RegisterVB
=fxDDRegisterVB
;
1020 ctx
->Driver
.UnregisterVB
=fxDDUnregisterVB
;
1022 if (!getenv("FX_NO_FAST"))
1023 ctx
->Driver
.BuildPrecalcPipeline
= fxDDBuildPrecalcPipeline
;
1025 fxSetupDDSpanPointers(ctx
);
1026 fxDDUpdateDDPointers(ctx
);
1034 * Need this to provide at least one external definition.
1037 int gl_fx_dummy_function_dd(void)