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"
60 #include "swrast/swrast.h"
61 #include "swrast_setup/swrast_setup.h"
63 #include "tnl/t_context.h"
64 #include "tnl/t_pipeline.h"
65 #include "array_cache/acache.h"
69 float gl_ubyte_to_float_255_color_tab
[256];
71 /* These lookup table are used to extract RGB values in [0,255] from
72 * 16-bit pixel values.
74 GLubyte FX_PixelToR
[0x10000];
75 GLubyte FX_PixelToG
[0x10000];
76 GLubyte FX_PixelToB
[0x10000];
80 * Initialize the FX_PixelTo{RGB} arrays.
81 * Input: bgrOrder - if TRUE, pixels are in BGR order, else RGB order.
84 fxInitPixelTables(fxMesaContext fxMesa
, GLboolean bgrOrder
)
88 fxMesa
->bgrOrder
= bgrOrder
;
89 for (pixel
= 0; pixel
<= 0xffff; pixel
++) {
92 r
= (pixel
& 0x001F) << 3;
93 g
= (pixel
& 0x07E0) >> 3;
94 b
= (pixel
& 0xF800) >> 8;
97 r
= (pixel
& 0xF800) >> 8;
98 g
= (pixel
& 0x07E0) >> 3;
99 b
= (pixel
& 0x001F) << 3;
101 r
= r
* 255 / 0xF8; /* fill in low-order bits */
104 FX_PixelToR
[pixel
] = r
;
105 FX_PixelToG
[pixel
] = g
;
106 FX_PixelToB
[pixel
] = b
;
111 /**********************************************************************/
112 /***** Miscellaneous functions *****/
113 /**********************************************************************/
115 /* Return buffer size information */
117 fxDDBufferSize(GLcontext
* ctx
, GLuint
* width
, GLuint
* height
)
119 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
121 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
122 fprintf(stderr
, "fxmesa: fxDDBufferSize(...) Start\n");
125 *width
= fxMesa
->width
;
126 *height
= fxMesa
->height
;
128 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
129 fprintf(stderr
, "fxmesa: fxDDBufferSize(...) End\n");
134 /* Implements glClearColor() */
136 fxDDClearColor(GLcontext
* ctx
, const GLchan color
[4])
138 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
141 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
142 fprintf(stderr
, "fxmesa: fxDDClearColor(%d,%d,%d,%d)\n",
143 color
[0], color
[1], color
[2], color
[3]);
146 ASSIGN_4V(col
, color
[0], color
[1], color
[2], 255);
147 fxMesa
->clearC
= FXCOLOR4(col
);
148 fxMesa
->clearA
= color
[3];
152 /* Clear the color and/or depth buffers */
154 fxDDClear(GLcontext
* ctx
, GLbitfield mask
, GLboolean all
,
155 GLint x
, GLint y
, GLint width
, GLint height
)
157 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
158 const GLuint colorMask
= *((GLuint
*) & ctx
->Color
.ColorMask
);
159 const FxU16 clearD
= (FxU16
) (ctx
->Depth
.Clear
* 0xffff);
160 GLbitfield softwareMask
= mask
& (DD_STENCIL_BIT
| DD_ACCUM_BIT
);
162 /* we can't clear stencil or accum buffers */
163 mask
&= ~(DD_STENCIL_BIT
| DD_ACCUM_BIT
);
165 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
166 fprintf(stderr
, "fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x
, (int) y
,
167 (int) width
, (int) height
);
170 if (colorMask
!= 0xffffffff) {
171 /* do masked color buffer clears in software */
172 softwareMask
|= (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
173 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
177 * This could probably be done fancier but doing each possible case
178 * explicitly is less error prone.
181 case DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
182 /* back buffer & depth */
183 FX_grDepthMask(FXTRUE
);
184 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
185 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
186 if (!ctx
->Depth
.Mask
) {
187 FX_grDepthMask(FXFALSE
);
190 case DD_FRONT_LEFT_BIT
| DD_DEPTH_BIT
:
191 /* XXX it appears that the depth buffer isn't cleared when
192 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
193 * This is a work-around/
196 FX_grDepthMask(FXTRUE
);
197 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
198 FX_grColorMask(FXFALSE
, FXFALSE
);
199 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
201 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
]
202 && fxMesa
->haveAlphaBuffer
);
203 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
204 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
206 case DD_BACK_LEFT_BIT
:
207 /* back buffer only */
208 FX_grDepthMask(FXFALSE
);
209 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
210 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
211 if (ctx
->Depth
.Mask
) {
212 FX_grDepthMask(FXTRUE
);
215 case DD_FRONT_LEFT_BIT
:
216 /* front buffer only */
217 FX_grDepthMask(FXFALSE
);
218 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
219 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
220 if (ctx
->Depth
.Mask
) {
221 FX_grDepthMask(FXTRUE
);
224 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
:
226 FX_grDepthMask(FXFALSE
);
227 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
228 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
229 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
230 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
231 if (ctx
->Depth
.Mask
) {
232 FX_grDepthMask(FXTRUE
);
235 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
237 FX_grDepthMask(FXFALSE
);
238 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
239 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
240 /* clear back and depth */
241 FX_grDepthMask(FXTRUE
);
242 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
243 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
244 if (!ctx
->Depth
.Mask
) {
245 FX_grDepthMask(FXFALSE
);
249 /* just the depth buffer */
250 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
251 FX_grColorMask(FXFALSE
, FXFALSE
);
252 FX_grDepthMask(FXTRUE
);
253 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
254 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
]
255 && fxMesa
->haveAlphaBuffer
);
256 if (ctx
->Color
.DrawDestMask
& FRONT_LEFT_BIT
)
257 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
258 if (!ctx
->Depth
.Test
|| !ctx
->Depth
.Mask
)
259 FX_grDepthMask(FXFALSE
);
266 /* Clear any remaining buffers:
269 _swrast_Clear(ctx
, softwareMask
, all
, x
, y
, width
, height
);
273 /* Set the buffer used for drawing */
274 /* XXX support for separate read/draw buffers hasn't been tested */
276 fxDDSetDrawBuffer(GLcontext
* ctx
, GLenum mode
)
278 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
280 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
281 fprintf(stderr
, "fxmesa: fxDDSetBuffer(%x)\n", (int) mode
);
284 if (mode
== GL_FRONT_LEFT
) {
285 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
286 FX_grRenderBuffer(fxMesa
->currentFB
);
289 else if (mode
== GL_BACK_LEFT
) {
290 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
291 FX_grRenderBuffer(fxMesa
->currentFB
);
294 else if (mode
== GL_NONE
) {
295 FX_grColorMask(FXFALSE
, FXFALSE
);
308 fxDDDrawBitmap(GLcontext
* ctx
, GLint px
, GLint py
,
309 GLsizei width
, GLsizei height
,
310 const struct gl_pixelstore_attrib
*unpack
,
311 const GLubyte
* bitmap
)
313 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
316 const struct gl_pixelstore_attrib
*finalUnpack
;
317 struct gl_pixelstore_attrib scissoredUnpack
;
319 /* check if there's any raster operations enabled which we can't handle */
320 if (ctx
->Color
.AlphaEnabled
||
321 ctx
->Color
.BlendEnabled
||
324 ctx
->Color
.ColorLogicOpEnabled
||
325 ctx
->Stencil
.Enabled
||
326 ctx
->Scissor
.Enabled
||
327 (ctx
->DrawBuffer
->UseSoftwareAlphaBuffers
&&
328 ctx
->Color
.ColorMask
[ACOMP
]) || ctx
->Color
.MultiDrawBuffer
) {
329 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
334 if (ctx
->Scissor
.Enabled
) {
335 /* This is a bit tricky, but by carefully adjusting the px, py,
336 * width, height, skipPixels and skipRows values we can do
337 * scissoring without special code in the rendering loop.
339 * KW: This code is never reached, see the test above.
342 /* we'll construct a new pixelstore struct */
343 finalUnpack
= &scissoredUnpack
;
344 scissoredUnpack
= *unpack
;
345 if (scissoredUnpack
.RowLength
== 0)
346 scissoredUnpack
.RowLength
= width
;
349 if (px
< ctx
->Scissor
.X
) {
350 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
351 width
-= (ctx
->Scissor
.X
- px
);
355 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
356 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
359 if (py
< ctx
->Scissor
.Y
) {
360 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
361 height
-= (ctx
->Scissor
.Y
- py
);
365 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
366 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
369 if (width
<= 0 || height
<= 0)
373 finalUnpack
= unpack
;
376 /* compute pixel value */
378 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[0] * 255.0f
);
379 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[1] * 255.0f
);
380 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[2] * 255.0f
);
381 /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f); */
382 if (fxMesa
->bgrOrder
)
384 (((FxU16
) 0xf8 & b
) << (11 - 3)) |
385 (((FxU16
) 0xfc & g
) << (5 - 3 + 1)) | (((FxU16
) 0xf8 & r
) >> 3);
388 (((FxU16
) 0xf8 & r
) << (11 - 3)) |
389 (((FxU16
) 0xfc & g
) << (5 - 3 + 1)) | (((FxU16
) 0xf8 & b
) >> 3);
392 info
.size
= sizeof(info
);
393 if (!FX_grLfbLock(GR_LFB_WRITE_ONLY
,
396 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
398 fprintf(stderr
, "fx Driver: error locking the linear frame buffer\n");
404 const GLint winX
= 0;
405 const GLint winY
= fxMesa
->height
- 1;
406 /* The dest stride depends on the hardware and whether we're drawing
407 * to the front or back buffer. This compile-time test seems to do
410 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
413 /* compute dest address of bottom-left pixel in bitmap */
414 GLushort
*dst
= (GLushort
*) info
.lfbPtr
415 + (winY
- py
) * dstStride
+ (winX
+ px
);
417 for (row
= 0; row
< height
; row
++) {
419 (const GLubyte
*) _mesa_image_address(finalUnpack
,
420 bitmap
, width
, height
,
421 GL_COLOR_INDEX
, GL_BITMAP
,
423 if (finalUnpack
->LsbFirst
) {
424 /* least significan bit first */
425 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
427 for (col
= 0; col
< width
; col
++) {
443 /* most significan bit first */
444 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
446 for (col
= 0; col
< width
; col
++) {
465 FX_grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
470 fxDDReadPixels(GLcontext
* ctx
, GLint x
, GLint y
,
471 GLsizei width
, GLsizei height
,
472 GLenum format
, GLenum type
,
473 const struct gl_pixelstore_attrib
*packing
, GLvoid
* dstImage
)
475 if (ctx
->_ImageTransferState
) {
476 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
481 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
485 if (grLfbLock(GR_LFB_READ_ONLY
,
488 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
489 const GLint winX
= 0;
490 const GLint winY
= fxMesa
->height
- 1;
491 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
492 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
493 + (winY
- y
) * srcStride
+ (winX
+ x
);
494 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
495 width
, height
, format
,
498 _mesa_image_row_stride(packing
, width
, format
, type
);
500 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
501 /* convert 5R6G5B into 8R8G8B */
503 const GLint halfWidth
= width
>> 1;
504 const GLint extraPixel
= (width
& 1);
505 for (row
= 0; row
< height
; row
++) {
507 for (col
= 0; col
< halfWidth
; col
++) {
508 const GLuint pixel
= ((const GLuint
*) src
)[col
];
509 const GLint pixel0
= pixel
& 0xffff;
510 const GLint pixel1
= pixel
>> 16;
511 *d
++ = FX_PixelToR
[pixel0
];
512 *d
++ = FX_PixelToG
[pixel0
];
513 *d
++ = FX_PixelToB
[pixel0
];
514 *d
++ = FX_PixelToR
[pixel1
];
515 *d
++ = FX_PixelToG
[pixel1
];
516 *d
++ = FX_PixelToB
[pixel1
];
519 GLushort pixel
= src
[width
- 1];
520 *d
++ = FX_PixelToR
[pixel
];
521 *d
++ = FX_PixelToG
[pixel
];
522 *d
++ = FX_PixelToB
[pixel
];
528 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
529 /* convert 5R6G5B into 8R8G8B8A */
531 const GLint halfWidth
= width
>> 1;
532 const GLint extraPixel
= (width
& 1);
533 for (row
= 0; row
< height
; row
++) {
535 for (col
= 0; col
< halfWidth
; col
++) {
536 const GLuint pixel
= ((const GLuint
*) src
)[col
];
537 const GLint pixel0
= pixel
& 0xffff;
538 const GLint pixel1
= pixel
>> 16;
539 *d
++ = FX_PixelToR
[pixel0
];
540 *d
++ = FX_PixelToG
[pixel0
];
541 *d
++ = FX_PixelToB
[pixel0
];
543 *d
++ = FX_PixelToR
[pixel1
];
544 *d
++ = FX_PixelToG
[pixel1
];
545 *d
++ = FX_PixelToB
[pixel1
];
549 const GLushort pixel
= src
[width
- 1];
550 *d
++ = FX_PixelToR
[pixel
];
551 *d
++ = FX_PixelToG
[pixel
];
552 *d
++ = FX_PixelToB
[pixel
];
559 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
560 /* directly memcpy 5R6G5B pixels into client's buffer */
561 const GLint widthInBytes
= width
* 2;
563 for (row
= 0; row
< height
; row
++) {
564 MEMCPY(dst
, src
, widthInBytes
);
570 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
572 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
577 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
586 fxDDFinish(GLcontext
* ctx
)
595 /* KW: Put the word Mesa in the render string because quakeworld
596 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
599 static const GLubyte
*
600 fxDDGetString(GLcontext
* ctx
, GLenum name
)
607 if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
== GR_SSTTYPE_VOODOO
) {
608 GrVoodooConfig_t
*vc
=
609 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
;
612 "Mesa Glide v0.30 Voodoo_Graphics %d "
613 "CARD/%d FB/%d TM/%d TMU/%s",
615 (vc
->sliDetect
? (vc
->fbRam
* 2) : vc
->fbRam
),
616 (vc
->tmuConfig
[GR_TMU0
].tmuRam
+
617 ((vc
->nTexelfx
> 1) ? vc
->tmuConfig
[GR_TMU1
].
618 tmuRam
: 0)), vc
->nTexelfx
,
619 (vc
->sliDetect
? "SLI" : "NOSLI"));
621 else if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
== GR_SSTTYPE_SST96
) {
622 GrSst96Config_t
*sc
=
623 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
;
626 "Glide v0.30 Voodoo_Rush %d "
627 "CARD/%d FB/%d TM/%d TMU/NOSLI",
629 sc
->fbRam
, sc
->tmuConfig
.tmuRam
, sc
->nTexelfx
);
632 strcpy(buf
, "Glide v0.30 UNKNOWN");
634 return (GLubyte
*) buf
;
641 static const struct gl_pipeline_stage
*fx_pipeline
[] = {
642 &_tnl_vertex_transform_stage
, /* TODO: Add the fastpath here */
643 &_tnl_normal_transform_stage
,
644 &_tnl_lighting_stage
,
645 &_tnl_fog_coordinate_stage
, /* TODO: Omit fog stage */
647 &_tnl_texture_transform_stage
,
648 &_tnl_point_attenuation_stage
,
657 fxDDInitFxMesaContext(fxMesaContext fxMesa
)
660 static int firsttime
= 1;
662 for (i
= 0; i
< 256; i
++) {
663 gl_ubyte_to_float_255_color_tab
[i
] = (float) i
;
672 FX_setupGrVertexLayout();
674 if (getenv("FX_EMULATE_SINGLE_TMU"))
675 fxMesa
->haveTwoTMUs
= GL_FALSE
;
677 fxMesa
->emulateTwoTMUs
= fxMesa
->haveTwoTMUs
;
679 if (!getenv("FX_DONT_FAKE_MULTITEX"))
680 fxMesa
->emulateTwoTMUs
= GL_TRUE
;
682 if (getenv("FX_GLIDE_SWAPINTERVAL"))
683 fxMesa
->swapInterval
= atoi(getenv("FX_GLIDE_SWAPINTERVAL"));
685 fxMesa
->swapInterval
= 1;
687 if (getenv("MESA_FX_SWAP_PENDING"))
688 fxMesa
->maxPendingSwapBuffers
= atoi(getenv("MESA_FX_SWAP_PENDING"));
690 fxMesa
->maxPendingSwapBuffers
= 2;
692 if (getenv("MESA_FX_INFO"))
693 fxMesa
->verbose
= GL_TRUE
;
695 fxMesa
->verbose
= GL_FALSE
;
697 fxMesa
->color
= 0xffffffff;
701 fxMesa
->stats
.swapBuffer
= 0;
702 fxMesa
->stats
.reqTexUpload
= 0;
703 fxMesa
->stats
.texUpload
= 0;
704 fxMesa
->stats
.memTexUpload
= 0;
706 fxMesa
->tmuSrc
= FX_TMU_NONE
;
707 fxMesa
->lastUnitsMode
= FX_UM_NONE
;
712 fxMesa
->unitsState
.alphaTestEnabled
= GL_FALSE
;
713 fxMesa
->unitsState
.alphaTestFunc
= GR_CMP_ALWAYS
;
714 fxMesa
->unitsState
.alphaTestRefValue
= 0;
716 fxMesa
->unitsState
.blendEnabled
= GL_FALSE
;
717 fxMesa
->unitsState
.blendSrcFuncRGB
= GR_BLEND_ONE
;
718 fxMesa
->unitsState
.blendDstFuncRGB
= GR_BLEND_ZERO
;
719 fxMesa
->unitsState
.blendSrcFuncAlpha
= GR_BLEND_ONE
;
720 fxMesa
->unitsState
.blendDstFuncAlpha
= GR_BLEND_ZERO
;
722 fxMesa
->unitsState
.depthTestEnabled
= GL_FALSE
;
723 fxMesa
->unitsState
.depthMask
= GL_TRUE
;
724 fxMesa
->unitsState
.depthTestFunc
= GR_CMP_LESS
;
726 FX_grColorMask(FXTRUE
, fxMesa
->haveAlphaBuffer
? FXTRUE
: FXFALSE
);
727 if (fxMesa
->haveDoubleBuffer
) {
728 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
729 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
732 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
733 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
736 fxMesa
->state
= malloc(FX_grGetInteger(FX_GLIDE_STATE_SIZE
));
737 fxMesa
->fogTable
= malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES
) *
740 if (!fxMesa
->state
|| !fxMesa
->fogTable
) {
743 if (fxMesa
->fogTable
)
744 free(fxMesa
->fogTable
);
748 if (fxMesa
->haveZBuffer
)
749 FX_grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
751 #if (!FXMESA_USE_ARGB)
752 FX_grLfbWriteColorFormat(GR_COLORFORMAT_ABGR
); /* Not every Glide has this */
755 fxMesa
->textureAlign
= FX_grGetInteger(FX_TEXTURE_ALIGN
);
756 fxMesa
->glCtx
->Const
.MaxTextureLevels
= 9;
757 fxMesa
->glCtx
->Const
.MaxTextureSize
= 256;
758 fxMesa
->glCtx
->Const
.MaxTextureUnits
= fxMesa
->emulateTwoTMUs
? 2 : 1;
759 fxMesa
->new_state
= _NEW_ALL
;
761 /* Initialize the software rasterizer and helper modules.
763 _swrast_CreateContext(fxMesa
->glCtx
);
764 _ac_CreateContext(fxMesa
->glCtx
);
765 _tnl_CreateContext(fxMesa
->glCtx
);
766 _swsetup_CreateContext(fxMesa
->glCtx
);
768 _tnl_destroy_pipeline(fxMesa
->glCtx
);
769 _tnl_install_pipeline(fxMesa
->glCtx
, fx_pipeline
);
771 fxAllocVB(fxMesa
->glCtx
);
773 fxSetupDDPointers(fxMesa
->glCtx
);
775 /* Tell the software rasterizer to use pixel fog always.
777 _swrast_allow_vertex_fog(fxMesa
->glCtx
, GL_FALSE
);
778 _swrast_allow_pixel_fog(fxMesa
->glCtx
, GL_TRUE
);
780 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
781 * tell render stage not to clip fog coords).
783 /* _tnl_calculate_vertex_fog( fxMesa->glCtx, GL_FALSE ); */
785 fxDDInitExtensions(fxMesa
->glCtx
);
788 fxDDInitVtxfmt(fxMesa
->glCtx
);
791 FX_grGlideGetState((GrState
*) fxMesa
->state
);
793 /* Run the config file */
794 _mesa_context_initialize(fxMesa
->glCtx
);
802 fxDDDestroyFxMesaContext(fxMesaContext fxMesa
)
804 _swsetup_DestroyContext(fxMesa
->glCtx
);
805 _tnl_DestroyContext(fxMesa
->glCtx
);
806 _ac_DestroyContext(fxMesa
->glCtx
);
807 _swrast_DestroyContext(fxMesa
->glCtx
);
811 if (fxMesa
->fogTable
)
812 free(fxMesa
->fogTable
);
814 fxFreeVB(fxMesa
->glCtx
);
821 fxDDInitExtensions(GLcontext
* ctx
)
823 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
825 _mesa_add_extension(ctx
, GL_TRUE
, "3DFX_set_global_palette", 0);
826 _mesa_enable_extension(ctx
, "GL_EXT_point_parameters");
827 _mesa_enable_extension(ctx
, "GL_EXT_paletted_texture");
828 _mesa_enable_extension(ctx
, "GL_EXT_texture_lod_bias");
829 _mesa_enable_extension(ctx
, "GL_EXT_shared_texture_palette");
831 if (fxMesa
->haveTwoTMUs
)
832 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_add");
834 if (fxMesa
->emulateTwoTMUs
)
835 _mesa_enable_extension(ctx
, "GL_ARB_multitexture");
839 /************************************************************************/
840 /************************************************************************/
841 /************************************************************************/
843 /* Check if the hardware supports the current context
845 * Performs similar work to fxDDChooseRenderState() - should be merged.
848 fxIsInHardware(GLcontext
* ctx
)
850 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
852 if (ctx
->RenderMode
!= GL_RENDER
)
855 if (ctx
->Stencil
.Enabled
||
856 ctx
->Color
.MultiDrawBuffer
||
857 ((ctx
->Color
.BlendEnabled
)
858 && (ctx
->Color
.BlendEquation
!= GL_FUNC_ADD_EXT
))
859 || ((ctx
->Color
.ColorLogicOpEnabled
)
860 && (ctx
->Color
.LogicOp
!= GL_COPY
))
861 || (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
864 Color
.ColorMask
[RCOMP
] == ctx
->Color
.ColorMask
[GCOMP
])
865 && (ctx
->Color
.ColorMask
[GCOMP
] == ctx
->Color
.ColorMask
[BCOMP
])
866 && (ctx
->Color
.ColorMask
[ACOMP
] == ctx
->Color
.ColorMask
[ACOMP
])))
870 /* Unsupported texture/multitexture cases */
872 if (fxMesa
->emulateTwoTMUs
) {
873 if (ctx
->Texture
._ReallyEnabled
& (TEXTURE0_3D
| TEXTURE1_3D
))
874 return GL_FALSE
; /* can't do 3D textures */
875 if (ctx
->Texture
._ReallyEnabled
& (TEXTURE0_1D
| TEXTURE1_1D
))
876 return GL_FALSE
; /* can't do 1D textures */
878 if (ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) {
879 if (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
&&
880 (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
||
881 ctx
->Texture
.Unit
[0].EnvColor
[0] != 0 ||
882 ctx
->Texture
.Unit
[0].EnvColor
[1] != 0 ||
883 ctx
->Texture
.Unit
[0].EnvColor
[2] != 0 ||
884 ctx
->Texture
.Unit
[0].EnvColor
[3] != 1)) {
887 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
891 if (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
) {
892 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_BLEND
)
894 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
898 if (MESA_VERBOSE
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
899 fprintf(stderr
, "fxMesa: fxIsInHardware, envmode is %s/%s\n",
900 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
901 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
903 /* KW: This was wrong (I think) and I changed it... which doesn't mean
904 * it is now correct...
906 if ((ctx
->_Enabled
& (TEXTURE0_1D
| TEXTURE0_2D
| TEXTURE0_3D
)) &&
907 (ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
))) {
908 /* Can't use multipass to blend a multitextured triangle - fall
911 if (!fxMesa
->haveTwoTMUs
&& ctx
->Color
.BlendEnabled
) {
915 if ((ctx
->Texture
.Unit
[0].EnvMode
!= ctx
->Texture
.Unit
[1].EnvMode
) &&
916 (ctx
->Texture
.Unit
[0].EnvMode
!= GL_MODULATE
) &&
917 (ctx
->Texture
.Unit
[0].EnvMode
!= GL_REPLACE
)) { /* q2, seems ok... */
918 if (MESA_VERBOSE
& VERBOSE_DRIVER
)
919 fprintf(stderr
, "fxMesa: unsupported multitex env mode\n");
925 if ((ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)) ||
926 /* Not very well written ... */
927 ((ctx
->_Enabled
& TEXTURE0_1D
) && (!(ctx
->_Enabled
& TEXTURE0_2D
)))
933 if ((ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) &&
934 (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
)) {
943 update_texture_scales(GLcontext
* ctx
)
945 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
946 struct gl_texture_unit
*t0
= &ctx
->Texture
.Unit
[fxMesa
->tmu_source
[0]];
947 struct gl_texture_unit
*t1
= &ctx
->Texture
.Unit
[fxMesa
->tmu_source
[1]];
949 if (t0
&& t0
->_Current
&& FX_TEXTURE_DATA(t0
)) {
950 fxMesa
->s0scale
= FX_TEXTURE_DATA(t0
)->sScale
;
951 fxMesa
->t0scale
= FX_TEXTURE_DATA(t0
)->tScale
;
952 fxMesa
->inv_s0scale
= 1.0 / fxMesa
->s0scale
;
953 fxMesa
->inv_t0scale
= 1.0 / fxMesa
->t0scale
;
956 if (t1
&& t1
->_Current
&& FX_TEXTURE_DATA(t1
)) {
957 fxMesa
->s1scale
= FX_TEXTURE_DATA(t1
)->sScale
;
958 fxMesa
->t1scale
= FX_TEXTURE_DATA(t1
)->tScale
;
959 fxMesa
->inv_s1scale
= 1.0 / fxMesa
->s1scale
;
960 fxMesa
->inv_t1scale
= 1.0 / fxMesa
->t1scale
;
965 fxDDUpdateDDPointers(GLcontext
* ctx
, GLuint new_state
)
967 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
968 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
970 _swrast_InvalidateState(ctx
, new_state
);
971 _ac_InvalidateState(ctx
, new_state
);
972 _tnl_InvalidateState(ctx
, new_state
);
973 _swsetup_InvalidateState(ctx
, new_state
);
975 /* Recalculate fog table on projection matrix changes. This used to
976 * be triggered by the NearFar callback.
978 if (new_state
& _NEW_PROJECTION
)
979 fxMesa
->new_state
|= FX_NEW_FOG
;
981 if (new_state
& (_FX_NEW_IS_IN_HARDWARE
|
982 _FX_NEW_RENDERSTATE
|
983 _FX_NEW_SETUP_FUNCTION
| _NEW_TEXTURE
)) {
985 if (new_state
& _FX_NEW_IS_IN_HARDWARE
)
986 fxMesa
->is_in_hardware
= fxIsInHardware(ctx
);
988 if (fxMesa
->new_state
)
991 if (new_state
& _FX_NEW_RENDERSTATE
)
992 fxDDChooseRenderState(ctx
);
994 if (new_state
& _FX_NEW_SETUP_FUNCTION
)
995 tnl
->Driver
.BuildProjectedVertices
= fx_validate_BuildProjVerts
;
997 if (new_state
& _NEW_TEXTURE
)
998 update_texture_scales(ctx
);
1003 if (fxMesa
->allow_vfmt
) {
1004 if (new_state
& _NEW_LIGHT
)
1005 fx_update_lighting(ctx
);
1007 if (new_state
& _FX_NEW_VTXFMT
)
1008 fxDDCheckVtxfmt(ctx
);
1014 fxDDRenderPrimitive(GLcontext
* ctx
, GLenum mode
)
1016 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1018 if (!fxMesa
->is_in_hardware
) {
1019 _swsetup_RenderPrimitive(ctx
, mode
);
1022 fxMesa
->render_prim
= mode
;
1028 fxDDRenderStart(GLcontext
* ctx
)
1030 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1032 _swsetup_RenderStart(ctx
);
1034 if (fxMesa
->new_state
) {
1035 fxSetupFXUnits(ctx
);
1040 fxDDRenderFinish(GLcontext
* ctx
)
1042 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1044 if (!fxMesa
->is_in_hardware
) {
1045 _swsetup_RenderFinish(ctx
);
1052 fxSetupDDPointers(GLcontext
* ctx
)
1054 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1056 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
1057 fprintf(stderr
, "fxmesa: fxSetupDDPointers()\n");
1060 ctx
->Driver
.UpdateState
= fxDDUpdateDDPointers
;
1061 ctx
->Driver
.GetString
= fxDDGetString
;
1062 ctx
->Driver
.ClearIndex
= NULL
;
1063 ctx
->Driver
.ClearColor
= fxDDClearColor
;
1064 ctx
->Driver
.Clear
= fxDDClear
;
1065 ctx
->Driver
.SetDrawBuffer
= fxDDSetDrawBuffer
;
1066 ctx
->Driver
.GetBufferSize
= fxDDBufferSize
;
1067 ctx
->Driver
.Accum
= _swrast_Accum
;
1068 ctx
->Driver
.Bitmap
= fxDDDrawBitmap
;
1069 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
1070 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1071 ctx
->Driver
.ReadPixels
= fxDDReadPixels
;
1072 ctx
->Driver
.ResizeBuffersMESA
= _swrast_alloc_buffers
;
1073 ctx
->Driver
.Finish
= fxDDFinish
;
1074 ctx
->Driver
.Flush
= NULL
;
1075 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
1076 ctx
->Driver
.TexImage2D
= fxDDTexImage2D
;
1077 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
1078 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
1079 ctx
->Driver
.TexSubImage2D
= fxDDTexSubImage2D
;
1080 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
1081 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
1082 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
1083 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
1084 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
1085 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
1086 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
1087 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
1088 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
1089 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
1090 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
1091 ctx
->Driver
.TexEnv
= fxDDTexEnv
;
1092 ctx
->Driver
.TexParameter
= fxDDTexParam
;
1093 ctx
->Driver
.BindTexture
= fxDDTexBind
;
1094 ctx
->Driver
.DeleteTexture
= fxDDTexDel
;
1095 ctx
->Driver
.UpdateTexturePalette
= fxDDTexPalette
;
1096 ctx
->Driver
.AlphaFunc
= fxDDAlphaFunc
;
1097 ctx
->Driver
.BlendFunc
= fxDDBlendFunc
;
1098 ctx
->Driver
.DepthFunc
= fxDDDepthFunc
;
1099 ctx
->Driver
.DepthMask
= fxDDDepthMask
;
1100 ctx
->Driver
.ColorMask
= fxDDColorMask
;
1101 ctx
->Driver
.Fogfv
= fxDDFogfv
;
1102 ctx
->Driver
.Scissor
= fxDDScissor
;
1103 ctx
->Driver
.FrontFace
= fxDDFrontFace
;
1104 ctx
->Driver
.CullFace
= fxDDCullFace
;
1105 ctx
->Driver
.ShadeModel
= fxDDShadeModel
;
1106 ctx
->Driver
.Enable
= fxDDEnable
;
1108 tnl
->Driver
.RenderStart
= fxDDRenderStart
;
1109 tnl
->Driver
.RenderFinish
= fxDDRenderFinish
;
1110 tnl
->Driver
.ResetLineStipple
= _swrast_ResetLineStipple
;
1111 tnl
->Driver
.RenderPrimitive
= fxDDRenderPrimitive
;
1112 tnl
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1113 tnl
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1114 tnl
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1115 tnl
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1117 fxSetupDDSpanPointers(ctx
);
1118 fxDDUpdateDDPointers(ctx
, ~0);
1126 * Need this to provide at least one external definition.
1129 extern int gl_fx_dummy_function_dd(void);
1131 gl_fx_dummy_function_dd(void)