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"
62 #include "array_cache/acache.h"
64 #include "tnl/t_pipeline.h"
67 float gl_ubyte_to_float_255_color_tab
[256];
69 /* These lookup table are used to extract RGB values in [0,255] from
70 * 16-bit pixel values.
72 GLubyte FX_PixelToR
[0x10000];
73 GLubyte FX_PixelToG
[0x10000];
74 GLubyte FX_PixelToB
[0x10000];
78 * Initialize the FX_PixelTo{RGB} arrays.
79 * Input: bgrOrder - if TRUE, pixels are in BGR order, else RGB order.
81 void fxInitPixelTables(fxMesaContext fxMesa
, GLboolean bgrOrder
)
85 fxMesa
->bgrOrder
=bgrOrder
;
86 for (pixel
= 0; pixel
<= 0xffff; pixel
++) {
89 r
= (pixel
& 0x001F) << 3;
90 g
= (pixel
& 0x07E0) >> 3;
91 b
= (pixel
& 0xF800) >> 8;
94 r
= (pixel
& 0xF800) >> 8;
95 g
= (pixel
& 0x07E0) >> 3;
96 b
= (pixel
& 0x001F) << 3;
98 r
= r
* 255 / 0xF8; /* fill in low-order bits */
101 FX_PixelToR
[pixel
] = r
;
102 FX_PixelToG
[pixel
] = g
;
103 FX_PixelToB
[pixel
] = b
;
108 /**********************************************************************/
109 /***** Miscellaneous functions *****/
110 /**********************************************************************/
112 /* Return buffer size information */
113 static void fxDDBufferSize(GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
115 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
117 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
118 fprintf(stderr
,"fxmesa: fxDDBufferSize(...) Start\n");
121 *width
=fxMesa
->width
;
122 *height
=fxMesa
->height
;
124 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
125 fprintf(stderr
,"fxmesa: fxDDBufferSize(...) End\n");
130 /* Implements glClearColor() */
131 static void fxDDClearColor(GLcontext
*ctx
, const GLchan color
[4])
133 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
136 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
137 fprintf(stderr
,"fxmesa: fxDDClearColor(%d,%d,%d,%d)\n",
138 color
[0], color
[1], color
[2], color
[3]);
141 ASSIGN_4V( col
, color
[0], color
[1], color
[2], 255 );
142 fxMesa
->clearC
= FXCOLOR4( col
);
143 fxMesa
->clearA
= color
[3];
147 /* Clear the color and/or depth buffers */
148 static void fxDDClear(GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
149 GLint x
, GLint y
, GLint width
, GLint height
)
151 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
152 const GLuint colorMask
= *((GLuint
*) &ctx
->Color
.ColorMask
);
153 const FxU16 clearD
= (FxU16
) (ctx
->Depth
.Clear
* 0xffff);
154 GLbitfield softwareMask
= mask
& (DD_STENCIL_BIT
| DD_ACCUM_BIT
);
156 /* we can't clear stencil or accum buffers */
157 mask
&= ~(DD_STENCIL_BIT
| DD_ACCUM_BIT
);
159 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
160 fprintf(stderr
,"fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x
, (int) y
,
161 (int) width
, (int) height
);
164 if (colorMask
!= 0xffffffff) {
165 /* do masked color buffer clears in software */
166 softwareMask
|= (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
167 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
171 * This could probably be done fancier but doing each possible case
172 * explicitly is less error prone.
175 case DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
176 /* back buffer & depth */
177 FX_grDepthMask(FXTRUE
);
178 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
179 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
180 if (!ctx
->Depth
.Mask
) {
181 FX_grDepthMask(FXFALSE
);
184 case DD_FRONT_LEFT_BIT
| DD_DEPTH_BIT
:
185 /* XXX it appears that the depth buffer isn't cleared when
186 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
187 * This is a work-around/
190 FX_grDepthMask(FXTRUE
);
191 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
192 FX_grColorMask(FXFALSE
,FXFALSE
);
193 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
195 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
196 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
197 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
199 case DD_BACK_LEFT_BIT
:
200 /* back buffer only */
201 FX_grDepthMask(FXFALSE
);
202 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
203 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
204 if (ctx
->Depth
.Mask
) {
205 FX_grDepthMask(FXTRUE
);
208 case DD_FRONT_LEFT_BIT
:
209 /* front buffer only */
210 FX_grDepthMask(FXFALSE
);
211 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
212 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
213 if (ctx
->Depth
.Mask
) {
214 FX_grDepthMask(FXTRUE
);
217 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
:
219 FX_grDepthMask(FXFALSE
);
220 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
221 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
222 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
223 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
224 if (ctx
->Depth
.Mask
) {
225 FX_grDepthMask(FXTRUE
);
228 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
230 FX_grDepthMask(FXFALSE
);
231 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
232 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
233 /* clear back and depth */
234 FX_grDepthMask(FXTRUE
);
235 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
236 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
237 if (!ctx
->Depth
.Mask
) {
238 FX_grDepthMask(FXFALSE
);
242 /* just the depth buffer */
243 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
244 FX_grColorMask(FXFALSE
,FXFALSE
);
245 FX_grDepthMask(FXTRUE
);
246 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
247 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
248 if (ctx
->Color
.DrawDestMask
& FRONT_LEFT_BIT
)
249 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
250 if (!ctx
->Depth
.Test
|| !ctx
->Depth
.Mask
)
251 FX_grDepthMask(FXFALSE
);
258 /* Clear any remaining buffers:
261 _swrast_Clear( ctx
, softwareMask
, all
, x
, y
, width
, height
);
265 /* Set the buffer used for drawing */
266 /* XXX support for separate read/draw buffers hasn't been tested */
267 static GLboolean
fxDDSetDrawBuffer(GLcontext
*ctx
, GLenum mode
)
269 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
271 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
272 fprintf(stderr
,"fxmesa: fxDDSetBuffer(%x)\n", (int) mode
);
275 if (mode
== GL_FRONT_LEFT
) {
276 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
277 FX_grRenderBuffer(fxMesa
->currentFB
);
280 else if (mode
== GL_BACK_LEFT
) {
281 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
282 FX_grRenderBuffer(fxMesa
->currentFB
);
285 else if (mode
== GL_NONE
) {
286 FX_grColorMask(FXFALSE
,FXFALSE
);
295 /* Set the buffer used for reading */
296 /* XXX support for separate read/draw buffers hasn't been tested */
297 static void fxDDSetReadBuffer(GLcontext
*ctx
, GLframebuffer
*buffer
,
300 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
303 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
304 fprintf(stderr
,"fxmesa: fxDDSetBuffer(%x)\n", (int) mode
);
307 if (mode
== GL_FRONT_LEFT
) {
308 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
309 FX_grRenderBuffer(fxMesa
->currentFB
);
311 else if (mode
== GL_BACK_LEFT
) {
312 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
313 FX_grRenderBuffer(fxMesa
->currentFB
);
319 static void fxDDDrawBitmap(GLcontext
*ctx
, GLint px
, GLint py
,
320 GLsizei width
, GLsizei height
,
321 const struct gl_pixelstore_attrib
*unpack
,
322 const GLubyte
*bitmap
)
324 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
327 const struct gl_pixelstore_attrib
*finalUnpack
;
328 struct gl_pixelstore_attrib scissoredUnpack
;
330 /* check if there's any raster operations enabled which we can't handle */
331 if (ctx
->Color
.AlphaEnabled
||
332 ctx
->Color
.BlendEnabled
||
335 ctx
->Color
.ColorLogicOpEnabled
||
336 ctx
->Stencil
.Enabled
||
337 ctx
->Scissor
.Enabled
||
338 ( ctx
->DrawBuffer
->UseSoftwareAlphaBuffers
&&
339 ctx
->Color
.ColorMask
[ACOMP
]) ||
340 ctx
->Color
.MultiDrawBuffer
)
342 _swrast_Bitmap( ctx
, px
, py
, width
, height
, unpack
, bitmap
);
347 if (ctx
->Scissor
.Enabled
) {
348 /* This is a bit tricky, but by carefully adjusting the px, py,
349 * width, height, skipPixels and skipRows values we can do
350 * scissoring without special code in the rendering loop.
352 * KW: This code is never reached, see the test above.
355 /* we'll construct a new pixelstore struct */
356 finalUnpack
= &scissoredUnpack
;
357 scissoredUnpack
= *unpack
;
358 if (scissoredUnpack
.RowLength
== 0)
359 scissoredUnpack
.RowLength
= width
;
362 if (px
< ctx
->Scissor
.X
) {
363 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
364 width
-= (ctx
->Scissor
.X
- px
);
368 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
369 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
372 if (py
< ctx
->Scissor
.Y
) {
373 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
374 height
-= (ctx
->Scissor
.Y
- py
);
378 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
379 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
382 if (width
<= 0 || height
<= 0)
386 finalUnpack
= unpack
;
389 /* compute pixel value */
391 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[0] * 255.0f
);
392 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[1] * 255.0f
);
393 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[2] * 255.0f
);
394 /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f);*/
395 if (fxMesa
->bgrOrder
)
397 ( ((FxU16
)0xf8 & b
) << (11-3)) |
398 ( ((FxU16
)0xfc & g
) << (5-3+1)) |
399 ( ((FxU16
)0xf8 & r
) >> 3);
402 ( ((FxU16
)0xf8 & r
) << (11-3)) |
403 ( ((FxU16
)0xfc & g
) << (5-3+1)) |
404 ( ((FxU16
)0xf8 & b
) >> 3);
407 info
.size
= sizeof(info
);
408 if (!FX_grLfbLock(GR_LFB_WRITE_ONLY
,
411 GR_ORIGIN_UPPER_LEFT
,
415 fprintf(stderr
,"fx Driver: error locking the linear frame buffer\n");
421 const GLint winX
= 0;
422 const GLint winY
= fxMesa
->height
- 1;
423 /* The dest stride depends on the hardware and whether we're drawing
424 * to the front or back buffer. This compile-time test seems to do
427 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
430 /* compute dest address of bottom-left pixel in bitmap */
431 GLushort
*dst
= (GLushort
*) info
.lfbPtr
432 + (winY
- py
) * dstStride
435 for (row
= 0; row
< height
; row
++) {
436 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( finalUnpack
,
437 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
438 if (finalUnpack
->LsbFirst
) {
439 /* least significan bit first */
440 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
442 for (col
=0; col
<width
; col
++) {
458 /* most significan bit first */
459 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
461 for (col
=0; col
<width
; col
++) {
480 FX_grLfbUnlock(GR_LFB_WRITE_ONLY
,fxMesa
->currentFB
);
484 static void fxDDReadPixels( GLcontext
*ctx
, GLint x
, GLint y
,
485 GLsizei width
, GLsizei height
,
486 GLenum format
, GLenum type
,
487 const struct gl_pixelstore_attrib
*packing
,
490 if (ctx
->_ImageTransferState
) {
491 _swrast_ReadPixels( ctx
, x
, y
, width
, height
, format
, type
,
496 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
500 if (grLfbLock(GR_LFB_READ_ONLY
,
503 GR_ORIGIN_UPPER_LEFT
,
506 const GLint winX
= 0;
507 const GLint winY
= fxMesa
->height
- 1;
508 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
509 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
510 + (winY
- y
) * srcStride
+ (winX
+ x
);
511 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
512 width
, height
, format
, type
, 0, 0, 0);
513 GLint dstStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
515 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
516 /* convert 5R6G5B into 8R8G8B */
518 const GLint halfWidth
= width
>> 1;
519 const GLint extraPixel
= (width
& 1);
520 for (row
= 0; row
< height
; row
++) {
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
];
534 GLushort pixel
= src
[width
-1];
535 *d
++ = FX_PixelToR
[pixel
];
536 *d
++ = FX_PixelToG
[pixel
];
537 *d
++ = FX_PixelToB
[pixel
];
543 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
544 /* convert 5R6G5B into 8R8G8B8A */
546 const GLint halfWidth
= width
>> 1;
547 const GLint extraPixel
= (width
& 1);
548 for (row
= 0; row
< height
; row
++) {
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
];
558 *d
++ = FX_PixelToR
[pixel1
];
559 *d
++ = FX_PixelToG
[pixel1
];
560 *d
++ = FX_PixelToB
[pixel1
];
564 const GLushort pixel
= src
[width
-1];
565 *d
++ = FX_PixelToR
[pixel
];
566 *d
++ = FX_PixelToG
[pixel
];
567 *d
++ = FX_PixelToB
[pixel
];
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;
578 for (row
= 0; row
< height
; row
++) {
579 MEMCPY(dst
, src
, widthInBytes
);
585 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
587 _swrast_ReadPixels( ctx
, x
, y
, width
, height
, format
, type
,
592 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
600 static void fxDDFinish(GLcontext
*ctx
)
609 /* KW: Put the word Mesa in the render string because quakeworld
610 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
613 static const GLubyte
*fxDDGetString(GLcontext
*ctx
, GLenum name
)
620 if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_VOODOO
) {
621 GrVoodooConfig_t
*vc
=
622 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
;
625 "Mesa Glide v0.30 Voodoo_Graphics %d "
626 "CARD/%d FB/%d TM/%d TMU/%s",
628 (vc
->sliDetect
? (vc
->fbRam
*2) : vc
->fbRam
),
629 (vc
->tmuConfig
[GR_TMU0
].tmuRam
+
630 ((vc
->nTexelfx
>1) ? vc
->tmuConfig
[GR_TMU1
].tmuRam
: 0)),
632 (vc
->sliDetect
? "SLI" : "NOSLI"));
634 else if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_SST96
) {
635 GrSst96Config_t
*sc
=
636 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
;
639 "Glide v0.30 Voodoo_Rush %d "
640 "CARD/%d FB/%d TM/%d TMU/NOSLI",
643 sc
->tmuConfig
.tmuRam
,
647 strcpy(buf
, "Glide v0.30 UNKNOWN");
649 return (GLubyte
*) buf
;
656 static const struct gl_pipeline_stage
*fx_pipeline
[] = {
657 &_tnl_vertex_transform_stage
, /* TODO: Add the fastpath here */
658 &_tnl_normal_transform_stage
,
659 &_tnl_lighting_stage
,
660 &_tnl_fog_coordinate_stage
, /* TODO: Omit fog stage */
662 &_tnl_texture_transform_stage
,
663 &_tnl_point_attenuation_stage
,
671 int fxDDInitFxMesaContext( fxMesaContext fxMesa
)
674 static int firsttime
= 1;
676 for (i
= 0 ; i
< 256 ; i
++) {
677 gl_ubyte_to_float_255_color_tab
[i
] = (float) i
;
686 FX_setupGrVertexLayout();
688 if (getenv("FX_EMULATE_SINGLE_TMU"))
689 fxMesa
->haveTwoTMUs
= GL_FALSE
;
691 fxMesa
->emulateTwoTMUs
= fxMesa
->haveTwoTMUs
;
693 if (!getenv("FX_DONT_FAKE_MULTITEX"))
694 fxMesa
->emulateTwoTMUs
= GL_TRUE
;
696 if(getenv("FX_GLIDE_SWAPINTERVAL"))
697 fxMesa
->swapInterval
=atoi(getenv("FX_GLIDE_SWAPINTERVAL"));
699 fxMesa
->swapInterval
=1;
701 if(getenv("MESA_FX_SWAP_PENDING"))
702 fxMesa
->maxPendingSwapBuffers
=atoi(getenv("MESA_FX_SWAP_PENDING"));
704 fxMesa
->maxPendingSwapBuffers
=2;
706 if(getenv("MESA_FX_INFO"))
707 fxMesa
->verbose
=GL_TRUE
;
709 fxMesa
->verbose
=GL_FALSE
;
711 fxMesa
->color
=0xffffffff;
715 fxMesa
->stats
.swapBuffer
=0;
716 fxMesa
->stats
.reqTexUpload
=0;
717 fxMesa
->stats
.texUpload
=0;
718 fxMesa
->stats
.memTexUpload
=0;
720 fxMesa
->tmuSrc
=FX_TMU_NONE
;
721 fxMesa
->lastUnitsMode
=FX_UM_NONE
;
726 fxMesa
->unitsState
.alphaTestEnabled
=GL_FALSE
;
727 fxMesa
->unitsState
.alphaTestFunc
=GR_CMP_ALWAYS
;
728 fxMesa
->unitsState
.alphaTestRefValue
=0;
730 fxMesa
->unitsState
.blendEnabled
=GL_FALSE
;
731 fxMesa
->unitsState
.blendSrcFuncRGB
=GR_BLEND_ONE
;
732 fxMesa
->unitsState
.blendDstFuncRGB
=GR_BLEND_ZERO
;
733 fxMesa
->unitsState
.blendSrcFuncAlpha
=GR_BLEND_ONE
;
734 fxMesa
->unitsState
.blendDstFuncAlpha
=GR_BLEND_ZERO
;
736 fxMesa
->unitsState
.depthTestEnabled
=GL_FALSE
;
737 fxMesa
->unitsState
.depthMask
=GL_TRUE
;
738 fxMesa
->unitsState
.depthTestFunc
=GR_CMP_LESS
;
740 FX_grColorMask(FXTRUE
, fxMesa
->haveAlphaBuffer
? FXTRUE
: FXFALSE
);
741 if(fxMesa
->haveDoubleBuffer
) {
742 fxMesa
->currentFB
=GR_BUFFER_BACKBUFFER
;
743 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
745 fxMesa
->currentFB
=GR_BUFFER_FRONTBUFFER
;
746 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
749 fxMesa
->state
= malloc(FX_grGetInteger(FX_GLIDE_STATE_SIZE
));
750 fxMesa
->fogTable
= malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES
) *
753 if (!fxMesa
->state
|| !fxMesa
->fogTable
) {
754 if (fxMesa
->state
) free(fxMesa
->state
);
755 if (fxMesa
->fogTable
) free(fxMesa
->fogTable
);
759 if(fxMesa
->haveZBuffer
)
760 FX_grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
762 #if (!FXMESA_USE_ARGB)
763 FX_grLfbWriteColorFormat(GR_COLORFORMAT_ABGR
); /* Not every Glide has this */
766 fxMesa
->textureAlign
=FX_grGetInteger(FX_TEXTURE_ALIGN
);
767 fxMesa
->glCtx
->Const
.MaxTextureLevels
=9;
768 fxMesa
->glCtx
->Const
.MaxTextureSize
=256;
769 fxMesa
->glCtx
->Const
.MaxTextureUnits
=fxMesa
->emulateTwoTMUs
? 2 : 1;
770 fxMesa
->new_state
= _NEW_ALL
;
772 /* Initialize the software rasterizer and helper modules.
774 _swrast_CreateContext( fxMesa
->glCtx
);
775 _ac_CreateContext( fxMesa
->glCtx
);
776 _tnl_CreateContext( fxMesa
->glCtx
);
777 _swsetup_CreateContext( fxMesa
->glCtx
);
779 _tnl_destroy_pipeline( fxMesa
->glCtx
);
780 _tnl_install_pipeline( fxMesa
->glCtx
, fx_pipeline
);
782 fxAllocVB( fxMesa
->glCtx
);
784 fxSetupDDPointers(fxMesa
->glCtx
);
786 /* Tell the software rasterizer to use pixel fog always.
788 _swrast_allow_vertex_fog( fxMesa
->glCtx
, GL_FALSE
);
789 _swrast_allow_pixel_fog( fxMesa
->glCtx
, GL_TRUE
);
791 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
792 * tell render stage not to clip fog coords).
794 /* _tnl_calculate_vertex_fog( fxMesa->glCtx, GL_FALSE ); */
796 fxDDInitExtensions(fxMesa
->glCtx
);
799 fxDDInitVtxfmt(fxMesa
->glCtx
);
802 FX_grGlideGetState((GrState
*)fxMesa
->state
);
804 /* Run the config file */
805 _mesa_context_initialize( fxMesa
->glCtx
);
812 void fxDDDestroyFxMesaContext( fxMesaContext fxMesa
)
814 _swsetup_DestroyContext( fxMesa
->glCtx
);
815 _tnl_DestroyContext( fxMesa
->glCtx
);
816 _ac_DestroyContext( fxMesa
->glCtx
);
817 _swrast_DestroyContext( fxMesa
->glCtx
);
821 if (fxMesa
->fogTable
)
822 free(fxMesa
->fogTable
);
824 fxFreeVB(fxMesa
->glCtx
);
830 void fxDDInitExtensions( GLcontext
*ctx
)
832 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
834 gl_extensions_disable(ctx
, "GL_EXT_blend_logic_op");
835 gl_extensions_disable(ctx
, "GL_EXT_blend_minmax");
836 gl_extensions_disable(ctx
, "GL_EXT_blend_subtract");
837 gl_extensions_disable(ctx
, "GL_EXT_blend_color");
838 gl_extensions_disable(ctx
, "GL_EXT_fog_coord");
841 gl_extensions_disable(ctx
, "GL_EXT_point_parameters");
843 gl_extensions_add(ctx
, GL_TRUE
, "3DFX_set_global_palette", 0);
845 if (!fxMesa
->haveTwoTMUs
)
846 gl_extensions_disable(ctx
, "GL_EXT_texture_env_add");
848 if (!fxMesa
->emulateTwoTMUs
)
849 gl_extensions_disable(ctx
, "GL_ARB_multitexture");
853 /************************************************************************/
854 /************************************************************************/
855 /************************************************************************/
857 /* Check if the hardware supports the current context
859 * Performs similar work to fxDDChooseRenderState() - should be merged.
861 static GLboolean
fxIsInHardware(GLcontext
*ctx
)
863 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
865 if (ctx
->RenderMode
!= GL_RENDER
)
868 if (ctx
->Stencil
.Enabled
||
869 ctx
->Color
.MultiDrawBuffer
||
870 ((ctx
->Color
.BlendEnabled
) && (ctx
->Color
.BlendEquation
!=GL_FUNC_ADD_EXT
)) ||
871 ((ctx
->Color
.ColorLogicOpEnabled
) && (ctx
->Color
.LogicOp
!=GL_COPY
)) ||
872 (ctx
->Light
.Model
.ColorControl
==GL_SEPARATE_SPECULAR_COLOR
) ||
873 (!((ctx
->Color
.ColorMask
[RCOMP
]==ctx
->Color
.ColorMask
[GCOMP
]) &&
874 (ctx
->Color
.ColorMask
[GCOMP
]==ctx
->Color
.ColorMask
[BCOMP
]) &&
875 (ctx
->Color
.ColorMask
[ACOMP
]==ctx
->Color
.ColorMask
[ACOMP
])))
880 /* Unsupported texture/multitexture cases */
882 if (fxMesa
->emulateTwoTMUs
) {
883 if (ctx
->Texture
._ReallyEnabled
& (TEXTURE0_3D
| TEXTURE1_3D
))
884 return GL_FALSE
; /* can't do 3D textures */
885 if (ctx
->Texture
._ReallyEnabled
& (TEXTURE0_1D
| TEXTURE1_1D
))
886 return GL_FALSE
; /* can't do 1D textures */
888 if (ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) {
889 if (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
&&
890 (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
||
891 ctx
->Texture
.Unit
[0].EnvColor
[0] != 0 ||
892 ctx
->Texture
.Unit
[0].EnvColor
[1] != 0 ||
893 ctx
->Texture
.Unit
[0].EnvColor
[2] != 0 ||
894 ctx
->Texture
.Unit
[0].EnvColor
[3] != 1)) {
897 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
901 if (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
) {
902 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_BLEND
)
904 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
908 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
909 fprintf(stderr
, "fxMesa: fxIsInHardware, envmode is %s/%s\n",
910 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
911 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
913 /* KW: This was wrong (I think) and I changed it... which doesn't mean
914 * it is now correct...
916 if((ctx
->_Enabled
& (TEXTURE0_1D
| TEXTURE0_2D
| TEXTURE0_3D
)) &&
917 (ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)))
919 /* Can't use multipass to blend a multitextured triangle - fall
922 if (!fxMesa
->haveTwoTMUs
&& ctx
->Color
.BlendEnabled
) {
926 if ((ctx
->Texture
.Unit
[0].EnvMode
!=ctx
->Texture
.Unit
[1].EnvMode
) &&
927 (ctx
->Texture
.Unit
[0].EnvMode
!=GL_MODULATE
) &&
928 (ctx
->Texture
.Unit
[0].EnvMode
!=GL_REPLACE
)) /* q2, seems ok... */
930 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
931 fprintf(stderr
, "fxMesa: unsupported multitex env mode\n");
936 if((ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)) ||
937 /* Not very well written ... */
938 ((ctx
->_Enabled
& TEXTURE0_1D
) &&
939 (!(ctx
->_Enabled
& TEXTURE0_2D
)))
945 if((ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) &&
946 (ctx
->Texture
.Unit
[0].EnvMode
==GL_BLEND
)) {
954 static void update_texture_scales( GLcontext
*ctx
)
956 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
957 struct gl_texture_unit
*t0
= &ctx
->Texture
.Unit
[fxMesa
->tmu_source
[0]];
958 struct gl_texture_unit
*t1
= &ctx
->Texture
.Unit
[fxMesa
->tmu_source
[1]];
960 if (t0
&& t0
->_Current
&& FX_TEXTURE_DATA(t0
)) {
961 fxMesa
->s0scale
= FX_TEXTURE_DATA(t0
)->sScale
;
962 fxMesa
->t0scale
= FX_TEXTURE_DATA(t0
)->tScale
;
963 fxMesa
->inv_s0scale
= 1.0 / fxMesa
->s0scale
;
964 fxMesa
->inv_t0scale
= 1.0 / fxMesa
->t0scale
;
967 if (t1
&& t1
->_Current
&& FX_TEXTURE_DATA(t1
)) {
968 fxMesa
->s1scale
= FX_TEXTURE_DATA(t1
)->sScale
;
969 fxMesa
->t1scale
= FX_TEXTURE_DATA(t1
)->tScale
;
970 fxMesa
->inv_s1scale
= 1.0 / fxMesa
->s1scale
;
971 fxMesa
->inv_t1scale
= 1.0 / fxMesa
->t1scale
;
975 static void fxDDUpdateDDPointers(GLcontext
*ctx
, GLuint new_state
)
977 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
979 _swrast_InvalidateState( ctx
, new_state
);
980 _ac_InvalidateState( ctx
, new_state
);
981 _tnl_InvalidateState( ctx
, new_state
);
982 _swsetup_InvalidateState( ctx
, new_state
);
984 /* Recalculate fog table on projection matrix changes. This used to
985 * be triggered by the NearFar callback.
987 if (new_state
& _NEW_PROJECTION
)
988 fxMesa
->new_state
|= FX_NEW_FOG
;
990 if (new_state
& (_FX_NEW_IS_IN_HARDWARE
|
991 _FX_NEW_RENDERSTATE
|
992 _FX_NEW_SETUP_FUNCTION
|
995 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
997 if (new_state
& _FX_NEW_IS_IN_HARDWARE
)
998 fxMesa
->is_in_hardware
= fxIsInHardware(ctx
);
1000 if (fxMesa
->new_state
)
1001 fxSetupFXUnits(ctx
);
1003 if (new_state
& _FX_NEW_RENDERSTATE
)
1004 fxDDChooseRenderState( ctx
);
1006 if (new_state
& _FX_NEW_SETUP_FUNCTION
)
1007 ctx
->Driver
.BuildProjectedVertices
= fx_validate_BuildProjVerts
;
1009 if (new_state
& _NEW_TEXTURE
)
1010 update_texture_scales( ctx
);
1015 if (fxMesa
->allow_vfmt
) {
1016 if (new_state
& _NEW_LIGHT
)
1017 fx_update_lighting( ctx
);
1019 if (new_state
& _FX_NEW_VTXFMT
)
1020 fxDDCheckVtxfmt( ctx
);
1025 static void fxDDRenderPrimitive( GLcontext
*ctx
, GLenum mode
)
1027 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1029 if (!fxMesa
->is_in_hardware
) {
1030 _swsetup_RenderPrimitive( ctx
, mode
);
1033 fxMesa
->render_prim
= mode
;
1038 static void fxDDRenderStart( GLcontext
*ctx
)
1040 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1042 _swsetup_RenderStart( ctx
);
1044 if (fxMesa
->new_state
) {
1045 fxSetupFXUnits( ctx
);
1049 static void fxDDRenderFinish( GLcontext
*ctx
)
1051 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1053 if (!fxMesa
->is_in_hardware
) {
1054 _swsetup_RenderFinish( ctx
);
1060 void fxSetupDDPointers(GLcontext
*ctx
)
1062 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1063 fprintf(stderr
,"fxmesa: fxSetupDDPointers()\n");
1066 ctx
->Driver
.UpdateState
=fxDDUpdateDDPointers
;
1068 ctx
->Driver
.WriteDepthSpan
=fxDDWriteDepthSpan
;
1069 ctx
->Driver
.WriteDepthPixels
=fxDDWriteDepthPixels
;
1070 ctx
->Driver
.ReadDepthSpan
=fxDDReadDepthSpan
;
1071 ctx
->Driver
.ReadDepthPixels
=fxDDReadDepthPixels
;
1073 ctx
->Driver
.GetString
=fxDDGetString
;
1075 ctx
->Driver
.ClearIndex
=NULL
;
1076 ctx
->Driver
.ClearColor
=fxDDClearColor
;
1077 ctx
->Driver
.Clear
=fxDDClear
;
1079 ctx
->Driver
.SetDrawBuffer
=fxDDSetDrawBuffer
;
1080 ctx
->Driver
.SetReadBuffer
=fxDDSetReadBuffer
;
1081 ctx
->Driver
.GetBufferSize
=fxDDBufferSize
;
1083 ctx
->Driver
.Accum
= _swrast_Accum
;
1084 ctx
->Driver
.Bitmap
= fxDDDrawBitmap
;
1085 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
1086 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
1087 ctx
->Driver
.ReadPixels
= fxDDReadPixels
;
1088 ctx
->Driver
.ResizeBuffersMESA
= _swrast_alloc_buffers
;
1090 ctx
->Driver
.Finish
=fxDDFinish
;
1091 ctx
->Driver
.Flush
=NULL
;
1093 ctx
->Driver
.RenderStart
=fxDDRenderStart
;
1094 ctx
->Driver
.RenderFinish
=fxDDRenderFinish
;
1095 ctx
->Driver
.ResetLineStipple
=_swrast_ResetLineStipple
;
1096 ctx
->Driver
.RenderPrimitive
=fxDDRenderPrimitive
;
1098 /* Install the oldstyle interp functions:
1100 ctx
->Driver
.RenderInterp
= _swsetup_RenderInterp
;
1101 ctx
->Driver
.RenderCopyPV
= _swsetup_RenderCopyPV
;
1102 ctx
->Driver
.RenderClippedLine
= _swsetup_RenderClippedLine
;
1103 ctx
->Driver
.RenderClippedPolygon
= _swsetup_RenderClippedPolygon
;
1105 ctx
->Driver
.TexImage2D
= fxDDTexImage2D
;
1106 ctx
->Driver
.TexSubImage2D
= fxDDTexSubImage2D
;
1107 ctx
->Driver
.TexEnv
= fxDDTexEnv
;
1108 ctx
->Driver
.TexParameter
= fxDDTexParam
;
1109 ctx
->Driver
.BindTexture
= fxDDTexBind
;
1110 ctx
->Driver
.DeleteTexture
= fxDDTexDel
;
1111 ctx
->Driver
.UpdateTexturePalette
= fxDDTexPalette
;
1113 ctx
->Driver
.AlphaFunc
=fxDDAlphaFunc
;
1114 ctx
->Driver
.BlendFunc
=fxDDBlendFunc
;
1115 ctx
->Driver
.DepthFunc
=fxDDDepthFunc
;
1116 ctx
->Driver
.DepthMask
=fxDDDepthMask
;
1117 ctx
->Driver
.ColorMask
=fxDDColorMask
;
1118 ctx
->Driver
.Fogfv
=fxDDFogfv
;
1119 ctx
->Driver
.Scissor
=fxDDScissor
;
1120 ctx
->Driver
.FrontFace
=fxDDFrontFace
;
1121 ctx
->Driver
.CullFace
=fxDDCullFace
;
1122 ctx
->Driver
.ShadeModel
=fxDDShadeModel
;
1123 ctx
->Driver
.Enable
=fxDDEnable
;
1127 fxSetupDDSpanPointers(ctx
);
1128 fxDDUpdateDDPointers(ctx
,~0);
1136 * Need this to provide at least one external definition.
1139 extern int gl_fx_dummy_function_dd(void);
1140 int gl_fx_dummy_function_dd(void)