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
, GLubyte red
, GLubyte green
,
132 GLubyte blue
, GLubyte alpha
)
134 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
139 ASSIGN_4V( col
, red
, green
, blue
, 255 );
141 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
142 fprintf(stderr
,"fxmesa: fxDDClearColor(%d,%d,%d,%d)\n",red
,green
,blue
,alpha
);
145 fxMesa
->clearC
=FXCOLOR4( col
);
146 fxMesa
->clearA
=alpha
;
150 /* Clear the color and/or depth buffers */
151 static GLbitfield
fxDDClear(GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
152 GLint x
, GLint y
, GLint width
, GLint height
)
154 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
155 const GLuint colorMask
= *((GLuint
*) &ctx
->Color
.ColorMask
);
156 const FxU16 clearD
= (FxU16
) (ctx
->Depth
.Clear
* 0xffff);
157 GLbitfield softwareMask
= mask
& (DD_STENCIL_BIT
| DD_ACCUM_BIT
);
159 /* we can't clear stencil or accum buffers */
160 mask
&= ~(DD_STENCIL_BIT
| DD_ACCUM_BIT
);
162 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
163 fprintf(stderr
,"fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x
, (int) y
,
164 (int) width
, (int) height
);
167 if (colorMask
!= 0xffffffff) {
168 /* do masked color buffer clears in software */
169 softwareMask
|= (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
170 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
174 * This could probably be done fancier but doing each possible case
175 * explicitly is less error prone.
178 case DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
179 /* back buffer & depth */
180 FX_grDepthMask(FXTRUE
);
181 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
182 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
183 if (!ctx
->Depth
.Mask
) {
184 FX_grDepthMask(FXFALSE
);
187 case DD_FRONT_LEFT_BIT
| DD_DEPTH_BIT
:
188 /* XXX it appears that the depth buffer isn't cleared when
189 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
190 * This is a work-around/
193 FX_grDepthMask(FXTRUE
);
194 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
195 FX_grColorMask(FXFALSE
,FXFALSE
);
196 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
198 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
199 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
200 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
202 case DD_BACK_LEFT_BIT
:
203 /* back buffer only */
204 FX_grDepthMask(FXFALSE
);
205 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
206 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
207 if (ctx
->Depth
.Mask
) {
208 FX_grDepthMask(FXTRUE
);
211 case DD_FRONT_LEFT_BIT
:
212 /* front buffer only */
213 FX_grDepthMask(FXFALSE
);
214 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
215 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
216 if (ctx
->Depth
.Mask
) {
217 FX_grDepthMask(FXTRUE
);
220 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
:
222 FX_grDepthMask(FXFALSE
);
223 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
224 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
225 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
226 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
227 if (ctx
->Depth
.Mask
) {
228 FX_grDepthMask(FXTRUE
);
231 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
233 FX_grDepthMask(FXFALSE
);
234 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
235 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
236 /* clear back and depth */
237 FX_grDepthMask(FXTRUE
);
238 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
239 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
240 if (!ctx
->Depth
.Mask
) {
241 FX_grDepthMask(FXFALSE
);
245 /* just the depth buffer */
246 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
247 FX_grColorMask(FXFALSE
,FXFALSE
);
248 FX_grDepthMask(FXTRUE
);
249 FX_grBufferClear(fxMesa
->clearC
, fxMesa
->clearA
, clearD
);
250 FX_grColorMask(FXTRUE
, ctx
->Color
.ColorMask
[ACOMP
] && fxMesa
->haveAlphaBuffer
);
251 if (ctx
->Color
.DrawDestMask
& FRONT_LEFT_BIT
)
252 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
253 if (!ctx
->Depth
.Test
|| !ctx
->Depth
.Mask
)
254 FX_grDepthMask(FXFALSE
);
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 GLboolean
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
)
344 if (ctx
->Scissor
.Enabled
) {
345 /* This is a bit tricky, but by carefully adjusting the px, py,
346 * width, height, skipPixels and skipRows values we can do
347 * scissoring without special code in the rendering loop.
349 * KW: This code is never reached, see the test above.
352 /* we'll construct a new pixelstore struct */
353 finalUnpack
= &scissoredUnpack
;
354 scissoredUnpack
= *unpack
;
355 if (scissoredUnpack
.RowLength
== 0)
356 scissoredUnpack
.RowLength
= width
;
359 if (px
< ctx
->Scissor
.X
) {
360 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
361 width
-= (ctx
->Scissor
.X
- px
);
365 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
366 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
369 if (py
< ctx
->Scissor
.Y
) {
370 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
371 height
-= (ctx
->Scissor
.Y
- py
);
375 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
376 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
379 if (width
<= 0 || height
<= 0)
380 return GL_TRUE
; /* totally scissored away */
383 finalUnpack
= unpack
;
386 /* compute pixel value */
388 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[0] * 255.0f
);
389 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[1] * 255.0f
);
390 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[2] * 255.0f
);
391 /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f);*/
392 if (fxMesa
->bgrOrder
)
394 ( ((FxU16
)0xf8 & b
) << (11-3)) |
395 ( ((FxU16
)0xfc & g
) << (5-3+1)) |
396 ( ((FxU16
)0xf8 & r
) >> 3);
399 ( ((FxU16
)0xf8 & r
) << (11-3)) |
400 ( ((FxU16
)0xfc & g
) << (5-3+1)) |
401 ( ((FxU16
)0xf8 & b
) >> 3);
404 info
.size
= sizeof(info
);
405 if (!FX_grLfbLock(GR_LFB_WRITE_ONLY
,
408 GR_ORIGIN_UPPER_LEFT
,
412 fprintf(stderr
,"fx Driver: error locking the linear frame buffer\n");
418 const GLint winX
= 0;
419 const GLint winY
= fxMesa
->height
- 1;
420 /* The dest stride depends on the hardware and whether we're drawing
421 * to the front or back buffer. This compile-time test seems to do
424 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
427 /* compute dest address of bottom-left pixel in bitmap */
428 GLushort
*dst
= (GLushort
*) info
.lfbPtr
429 + (winY
- py
) * dstStride
432 for (row
= 0; row
< height
; row
++) {
433 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address( finalUnpack
,
434 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
435 if (finalUnpack
->LsbFirst
) {
436 /* least significan bit first */
437 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
439 for (col
=0; col
<width
; col
++) {
455 /* most significan bit first */
456 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
458 for (col
=0; col
<width
; col
++) {
477 FX_grLfbUnlock(GR_LFB_WRITE_ONLY
,fxMesa
->currentFB
);
482 static GLboolean
fxDDReadPixels( GLcontext
*ctx
, GLint x
, GLint y
,
483 GLsizei width
, GLsizei height
,
484 GLenum format
, GLenum type
,
485 const struct gl_pixelstore_attrib
*packing
,
488 if (ctx
->_ImageTransferState
) {
489 return GL_FALSE
; /* can't do this */
492 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
494 GLboolean result
= GL_FALSE
;
497 if (grLfbLock(GR_LFB_READ_ONLY
,
500 GR_ORIGIN_UPPER_LEFT
,
503 const GLint winX
= 0;
504 const GLint winY
= fxMesa
->height
- 1;
505 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
506 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
507 + (winY
- y
) * srcStride
+ (winX
+ x
);
508 GLubyte
*dst
= (GLubyte
*) _mesa_image_address(packing
, dstImage
,
509 width
, height
, format
, type
, 0, 0, 0);
510 GLint dstStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
512 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
513 /* convert 5R6G5B into 8R8G8B */
515 const GLint halfWidth
= width
>> 1;
516 const GLint extraPixel
= (width
& 1);
517 for (row
= 0; row
< height
; row
++) {
519 for (col
= 0; col
< halfWidth
; col
++) {
520 const GLuint pixel
= ((const GLuint
*) src
)[col
];
521 const GLint pixel0
= pixel
& 0xffff;
522 const GLint pixel1
= pixel
>> 16;
523 *d
++ = FX_PixelToR
[pixel0
];
524 *d
++ = FX_PixelToG
[pixel0
];
525 *d
++ = FX_PixelToB
[pixel0
];
526 *d
++ = FX_PixelToR
[pixel1
];
527 *d
++ = FX_PixelToG
[pixel1
];
528 *d
++ = FX_PixelToB
[pixel1
];
531 GLushort pixel
= src
[width
-1];
532 *d
++ = FX_PixelToR
[pixel
];
533 *d
++ = FX_PixelToG
[pixel
];
534 *d
++ = FX_PixelToB
[pixel
];
541 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
542 /* convert 5R6G5B into 8R8G8B8A */
544 const GLint halfWidth
= width
>> 1;
545 const GLint extraPixel
= (width
& 1);
546 for (row
= 0; row
< height
; row
++) {
548 for (col
= 0; col
< halfWidth
; col
++) {
549 const GLuint pixel
= ((const GLuint
*) src
)[col
];
550 const GLint pixel0
= pixel
& 0xffff;
551 const GLint pixel1
= pixel
>> 16;
552 *d
++ = FX_PixelToR
[pixel0
];
553 *d
++ = FX_PixelToG
[pixel0
];
554 *d
++ = FX_PixelToB
[pixel0
];
556 *d
++ = FX_PixelToR
[pixel1
];
557 *d
++ = FX_PixelToG
[pixel1
];
558 *d
++ = FX_PixelToB
[pixel1
];
562 const GLushort pixel
= src
[width
-1];
563 *d
++ = FX_PixelToR
[pixel
];
564 *d
++ = FX_PixelToG
[pixel
];
565 *d
++ = FX_PixelToB
[pixel
];
573 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
574 /* directly memcpy 5R6G5B pixels into client's buffer */
575 const GLint widthInBytes
= width
* 2;
577 for (row
= 0; row
< height
; row
++) {
578 MEMCPY(dst
, src
, widthInBytes
);
588 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
597 static void fxDDFinish(GLcontext
*ctx
)
606 /* KW: Put the word Mesa in the render string because quakeworld
607 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
610 static const GLubyte
*fxDDGetString(GLcontext
*ctx
, GLenum name
)
617 if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_VOODOO
) {
618 GrVoodooConfig_t
*vc
=
619 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
;
622 "Mesa Glide v0.30 Voodoo_Graphics %d "
623 "CARD/%d FB/%d TM/%d TMU/%s",
625 (vc
->sliDetect
? (vc
->fbRam
*2) : vc
->fbRam
),
626 (vc
->tmuConfig
[GR_TMU0
].tmuRam
+
627 ((vc
->nTexelfx
>1) ? vc
->tmuConfig
[GR_TMU1
].tmuRam
: 0)),
629 (vc
->sliDetect
? "SLI" : "NOSLI"));
631 else if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_SST96
) {
632 GrSst96Config_t
*sc
=
633 &glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
;
636 "Glide v0.30 Voodoo_Rush %d "
637 "CARD/%d FB/%d TM/%d TMU/NOSLI",
640 sc
->tmuConfig
.tmuRam
,
644 strcpy(buf
, "Glide v0.30 UNKNOWN");
646 return (GLubyte
*) buf
;
653 static const struct gl_pipeline_stage
*fx_pipeline
[] = {
654 &_tnl_update_material_stage
, /* TODO: Add the fastpath here */
655 &_tnl_vertex_transform_stage
,
656 &_tnl_normal_transform_stage
,
657 &_tnl_lighting_stage
,
658 &_tnl_fog_coordinate_stage
, /* TODO: Omit fog stage */
660 &_tnl_texture_transform_stage
,
661 &_tnl_point_attenuation_stage
,
669 int fxDDInitFxMesaContext( fxMesaContext fxMesa
)
672 static int firsttime
= 1;
674 for (i
= 0 ; i
< 256 ; i
++) {
675 gl_ubyte_to_float_255_color_tab
[i
] = (float) i
;
684 FX_setupGrVertexLayout();
686 if (getenv("FX_EMULATE_SINGLE_TMU"))
687 fxMesa
->haveTwoTMUs
= GL_FALSE
;
689 fxMesa
->emulateTwoTMUs
= fxMesa
->haveTwoTMUs
;
691 if (!getenv("FX_DONT_FAKE_MULTITEX"))
692 fxMesa
->emulateTwoTMUs
= GL_TRUE
;
694 if(getenv("FX_GLIDE_SWAPINTERVAL"))
695 fxMesa
->swapInterval
=atoi(getenv("FX_GLIDE_SWAPINTERVAL"));
697 fxMesa
->swapInterval
=1;
699 if(getenv("MESA_FX_SWAP_PENDING"))
700 fxMesa
->maxPendingSwapBuffers
=atoi(getenv("MESA_FX_SWAP_PENDING"));
702 fxMesa
->maxPendingSwapBuffers
=2;
704 if(getenv("MESA_FX_INFO"))
705 fxMesa
->verbose
=GL_TRUE
;
707 fxMesa
->verbose
=GL_FALSE
;
709 fxMesa
->color
=0xffffffff;
713 fxMesa
->stats
.swapBuffer
=0;
714 fxMesa
->stats
.reqTexUpload
=0;
715 fxMesa
->stats
.texUpload
=0;
716 fxMesa
->stats
.memTexUpload
=0;
718 fxMesa
->tmuSrc
=FX_TMU_NONE
;
719 fxMesa
->lastUnitsMode
=FX_UM_NONE
;
724 fxMesa
->unitsState
.alphaTestEnabled
=GL_FALSE
;
725 fxMesa
->unitsState
.alphaTestFunc
=GR_CMP_ALWAYS
;
726 fxMesa
->unitsState
.alphaTestRefValue
=0;
728 fxMesa
->unitsState
.blendEnabled
=GL_FALSE
;
729 fxMesa
->unitsState
.blendSrcFuncRGB
=GR_BLEND_ONE
;
730 fxMesa
->unitsState
.blendDstFuncRGB
=GR_BLEND_ZERO
;
731 fxMesa
->unitsState
.blendSrcFuncAlpha
=GR_BLEND_ONE
;
732 fxMesa
->unitsState
.blendDstFuncAlpha
=GR_BLEND_ZERO
;
734 fxMesa
->unitsState
.depthTestEnabled
=GL_FALSE
;
735 fxMesa
->unitsState
.depthMask
=GL_TRUE
;
736 fxMesa
->unitsState
.depthTestFunc
=GR_CMP_LESS
;
738 FX_grColorMask(FXTRUE
, fxMesa
->haveAlphaBuffer
? FXTRUE
: FXFALSE
);
739 if(fxMesa
->haveDoubleBuffer
) {
740 fxMesa
->currentFB
=GR_BUFFER_BACKBUFFER
;
741 FX_grRenderBuffer(GR_BUFFER_BACKBUFFER
);
743 fxMesa
->currentFB
=GR_BUFFER_FRONTBUFFER
;
744 FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
747 fxMesa
->state
= malloc(FX_grGetInteger(FX_GLIDE_STATE_SIZE
));
748 fxMesa
->fogTable
= malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES
) *
751 if (!fxMesa
->state
|| !fxMesa
->fogTable
) {
752 if (fxMesa
->state
) free(fxMesa
->state
);
753 if (fxMesa
->fogTable
) free(fxMesa
->fogTable
);
757 if(fxMesa
->haveZBuffer
)
758 FX_grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
760 #if (!FXMESA_USE_ARGB)
761 FX_grLfbWriteColorFormat(GR_COLORFORMAT_ABGR
); /* Not every Glide has this */
764 fxMesa
->textureAlign
=FX_grGetInteger(FX_TEXTURE_ALIGN
);
765 fxMesa
->glCtx
->Const
.MaxTextureLevels
=9;
766 fxMesa
->glCtx
->Const
.MaxTextureSize
=256;
767 fxMesa
->glCtx
->Const
.MaxTextureUnits
=fxMesa
->emulateTwoTMUs
? 2 : 1;
768 fxMesa
->new_state
= _NEW_ALL
;
770 /* Initialize the software rasterizer and helper modules.
772 _swrast_CreateContext( fxMesa
->glCtx
);
773 _ac_CreateContext( fxMesa
->glCtx
);
774 _tnl_CreateContext( fxMesa
->glCtx
);
775 _swsetup_CreateContext( fxMesa
->glCtx
);
777 _tnl_destroy_pipeline( fxMesa
->glCtx
);
778 _tnl_install_pipeline( fxMesa
->glCtx
, fx_pipeline
);
780 fxAllocVB( fxMesa
->glCtx
);
782 fxSetupDDPointers(fxMesa
->glCtx
);
784 /* Tell the software rasterizer to use pixel fog always.
786 _swrast_allow_vertex_fog( fxMesa
->glCtx
, GL_FALSE
);
787 _swrast_allow_pixel_fog( fxMesa
->glCtx
, GL_TRUE
);
789 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
790 * tell render stage not to clip fog coords).
792 /* _tnl_calculate_vertex_fog( fxMesa->glCtx, GL_FALSE ); */
794 fxDDInitExtensions(fxMesa
->glCtx
);
797 fxDDInitVtxfmt(fxMesa
->glCtx
);
800 FX_grGlideGetState((GrState
*)fxMesa
->state
);
802 /* Run the config file */
803 _mesa_context_initialize( fxMesa
->glCtx
);
810 void fxDDDestroyFxMesaContext( fxMesaContext fxMesa
)
812 _swsetup_DestroyContext( fxMesa
->glCtx
);
813 _tnl_DestroyContext( fxMesa
->glCtx
);
814 _ac_DestroyContext( fxMesa
->glCtx
);
815 _swrast_DestroyContext( fxMesa
->glCtx
);
819 if (fxMesa
->fogTable
)
820 free(fxMesa
->fogTable
);
822 fxFreeVB(fxMesa
->glCtx
);
828 void fxDDInitExtensions( GLcontext
*ctx
)
830 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
832 gl_extensions_disable(ctx
, "GL_EXT_blend_logic_op");
833 gl_extensions_disable(ctx
, "GL_EXT_blend_minmax");
834 gl_extensions_disable(ctx
, "GL_EXT_blend_subtract");
835 gl_extensions_disable(ctx
, "GL_EXT_blend_color");
836 gl_extensions_disable(ctx
, "GL_EXT_fog_coord");
839 gl_extensions_disable(ctx
, "GL_EXT_point_parameters");
841 gl_extensions_add(ctx
, GL_TRUE
, "3DFX_set_global_palette", 0);
843 if (!fxMesa
->haveTwoTMUs
)
844 gl_extensions_disable(ctx
, "GL_EXT_texture_env_add");
846 if (!fxMesa
->emulateTwoTMUs
)
847 gl_extensions_disable(ctx
, "GL_ARB_multitexture");
851 /************************************************************************/
852 /************************************************************************/
853 /************************************************************************/
855 /* Check if the hardware supports the current context
857 * Performs similar work to fxDDChooseRenderState() - should be merged.
859 static GLboolean
fxIsInHardware(GLcontext
*ctx
)
861 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
863 if (ctx
->RenderMode
!= GL_RENDER
)
866 if (!ctx
->Hint
.AllowDrawMem
)
867 return GL_TRUE
; /* you'll take it and like it */
869 if (ctx
->Stencil
.Enabled
||
870 ctx
->Color
.MultiDrawBuffer
||
871 ((ctx
->Color
.BlendEnabled
) && (ctx
->Color
.BlendEquation
!=GL_FUNC_ADD_EXT
)) ||
872 ((ctx
->Color
.ColorLogicOpEnabled
) && (ctx
->Color
.LogicOp
!=GL_COPY
)) ||
873 (ctx
->Light
.Model
.ColorControl
==GL_SEPARATE_SPECULAR_COLOR
) ||
874 (!((ctx
->Color
.ColorMask
[RCOMP
]==ctx
->Color
.ColorMask
[GCOMP
]) &&
875 (ctx
->Color
.ColorMask
[GCOMP
]==ctx
->Color
.ColorMask
[BCOMP
]) &&
876 (ctx
->Color
.ColorMask
[ACOMP
]==ctx
->Color
.ColorMask
[ACOMP
])))
881 /* Unsupported texture/multitexture cases */
883 if(fxMesa
->emulateTwoTMUs
) {
884 if((ctx
->_Enabled
& (TEXTURE0_3D
| TEXTURE1_3D
)) ||
885 /* Not very well written ... */
886 ((ctx
->_Enabled
& (TEXTURE0_1D
| TEXTURE1_1D
)) &&
887 ((ctx
->_Enabled
& (TEXTURE0_2D
| TEXTURE1_2D
))!=(TEXTURE0_2D
| TEXTURE1_2D
)))
892 if (ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) {
893 if (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
&&
894 (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
||
895 ctx
->Texture
.Unit
[0].EnvColor
[0] != 0 ||
896 ctx
->Texture
.Unit
[0].EnvColor
[1] != 0 ||
897 ctx
->Texture
.Unit
[0].EnvColor
[2] != 0 ||
898 ctx
->Texture
.Unit
[0].EnvColor
[3] != 1)) {
901 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
905 if (ctx
->Texture
._ReallyEnabled
& TEXTURE1_2D
) {
906 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_BLEND
)
908 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0]->Border
> 0)
912 if (MESA_VERBOSE
& (VERBOSE_DRIVER
|VERBOSE_TEXTURE
))
913 fprintf(stderr
, "fxMesa: fxIsInHardware, envmode is %s/%s\n",
914 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
915 gl_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
917 /* KW: This was wrong (I think) and I changed it... which doesn't mean
918 * it is now correct...
920 if((ctx
->_Enabled
& (TEXTURE0_1D
| TEXTURE0_2D
| TEXTURE0_3D
)) &&
921 (ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)))
923 /* Can't use multipass to blend a multitextured triangle - fall
926 if (!fxMesa
->haveTwoTMUs
&& ctx
->Color
.BlendEnabled
) {
930 if ((ctx
->Texture
.Unit
[0].EnvMode
!=ctx
->Texture
.Unit
[1].EnvMode
) &&
931 (ctx
->Texture
.Unit
[0].EnvMode
!=GL_MODULATE
) &&
932 (ctx
->Texture
.Unit
[0].EnvMode
!=GL_REPLACE
)) /* q2, seems ok... */
934 if (MESA_VERBOSE
&VERBOSE_DRIVER
)
935 fprintf(stderr
, "fxMesa: unsupported multitex env mode\n");
940 if((ctx
->_Enabled
& (TEXTURE1_1D
| TEXTURE1_2D
| TEXTURE1_3D
)) ||
941 /* Not very well written ... */
942 ((ctx
->_Enabled
& TEXTURE0_1D
) &&
943 (!(ctx
->_Enabled
& TEXTURE0_2D
)))
949 if((ctx
->Texture
._ReallyEnabled
& TEXTURE0_2D
) &&
950 (ctx
->Texture
.Unit
[0].EnvMode
==GL_BLEND
)) {
958 static void update_texture_scales( GLcontext
*ctx
)
960 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
961 struct gl_texture_unit
*t0
= &ctx
->Texture
.Unit
[fxMesa
->tmu_source
[0]];
962 struct gl_texture_unit
*t1
= &ctx
->Texture
.Unit
[fxMesa
->tmu_source
[1]];
964 if (t0
&& t0
->_Current
&& FX_TEXTURE_DATA(t0
)) {
965 fxMesa
->s0scale
= FX_TEXTURE_DATA(t0
)->sScale
;
966 fxMesa
->t0scale
= FX_TEXTURE_DATA(t0
)->tScale
;
967 fxMesa
->inv_s0scale
= 1.0 / fxMesa
->s0scale
;
968 fxMesa
->inv_t0scale
= 1.0 / fxMesa
->t0scale
;
971 if (t1
&& t1
->_Current
&& FX_TEXTURE_DATA(t1
)) {
972 fxMesa
->s1scale
= FX_TEXTURE_DATA(t1
)->sScale
;
973 fxMesa
->t1scale
= FX_TEXTURE_DATA(t1
)->tScale
;
974 fxMesa
->inv_s1scale
= 1.0 / fxMesa
->s1scale
;
975 fxMesa
->inv_t1scale
= 1.0 / fxMesa
->t1scale
;
979 static void fxDDUpdateDDPointers(GLcontext
*ctx
, GLuint new_state
)
981 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
983 _swrast_InvalidateState( ctx
, new_state
);
984 _ac_InvalidateState( ctx
, new_state
);
985 _tnl_InvalidateState( ctx
, new_state
);
986 _swsetup_InvalidateState( ctx
, new_state
);
988 /* Recalculate fog table on projection matrix changes. This used to
989 * be triggered by the NearFar callback.
991 if (new_state
& _NEW_PROJECTION
)
992 fxMesa
->new_state
|= FX_NEW_FOG
;
994 if (new_state
& (_FX_NEW_IS_IN_HARDWARE
|
995 _FX_NEW_RENDERSTATE
|
996 _FX_NEW_SETUP_FUNCTION
|
999 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1001 if (new_state
& _FX_NEW_IS_IN_HARDWARE
)
1002 fxMesa
->is_in_hardware
= fxIsInHardware(ctx
);
1004 if (fxMesa
->new_state
)
1005 fxSetupFXUnits(ctx
);
1007 if (new_state
& _FX_NEW_RENDERSTATE
)
1008 fxDDChooseRenderState( ctx
);
1010 if (new_state
& _FX_NEW_SETUP_FUNCTION
)
1011 ctx
->Driver
.BuildProjectedVertices
= fx_validate_BuildProjVerts
;
1013 if (new_state
& _NEW_TEXTURE
)
1014 update_texture_scales( ctx
);
1019 if (fxMesa
->allow_vfmt
) {
1020 if (new_state
& _NEW_LIGHT
)
1021 fx_update_lighting( ctx
);
1023 if (new_state
& _FX_NEW_VTXFMT
)
1024 fxDDCheckVtxfmt( ctx
);
1029 static void fxDDRenderPrimitive( GLcontext
*ctx
, GLenum mode
)
1031 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1033 if (!fxMesa
->is_in_hardware
) {
1034 _swsetup_RenderPrimitive( ctx
, mode
);
1037 fxMesa
->render_prim
= mode
;
1042 static void fxDDRenderStart( GLcontext
*ctx
)
1044 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1046 if (!fxMesa
->is_in_hardware
) {
1047 _swsetup_RenderStart( ctx
);
1049 else if (fxMesa
->new_state
) {
1050 fxSetupFXUnits( ctx
);
1054 static void fxDDRenderFinish( GLcontext
*ctx
)
1056 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1058 if (!fxMesa
->is_in_hardware
) {
1059 _swsetup_RenderFinish( ctx
);
1065 void fxSetupDDPointers(GLcontext
*ctx
)
1067 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1068 fprintf(stderr
,"fxmesa: fxSetupDDPointers()\n");
1071 ctx
->Driver
.UpdateState
=fxDDUpdateDDPointers
;
1073 ctx
->Driver
.WriteDepthSpan
=fxDDWriteDepthSpan
;
1074 ctx
->Driver
.WriteDepthPixels
=fxDDWriteDepthPixels
;
1075 ctx
->Driver
.ReadDepthSpan
=fxDDReadDepthSpan
;
1076 ctx
->Driver
.ReadDepthPixels
=fxDDReadDepthPixels
;
1078 ctx
->Driver
.GetString
=fxDDGetString
;
1080 ctx
->Driver
.ClearIndex
=NULL
;
1081 ctx
->Driver
.ClearColor
=fxDDClearColor
;
1082 ctx
->Driver
.Clear
=fxDDClear
;
1084 ctx
->Driver
.SetDrawBuffer
=fxDDSetDrawBuffer
;
1085 ctx
->Driver
.SetReadBuffer
=fxDDSetReadBuffer
;
1086 ctx
->Driver
.GetBufferSize
=fxDDBufferSize
;
1088 ctx
->Driver
.Bitmap
=fxDDDrawBitmap
;
1089 ctx
->Driver
.DrawPixels
=NULL
;
1090 ctx
->Driver
.ReadPixels
=fxDDReadPixels
;
1092 ctx
->Driver
.Finish
=fxDDFinish
;
1093 ctx
->Driver
.Flush
=NULL
;
1095 ctx
->Driver
.RenderStart
=fxDDRenderStart
;
1096 ctx
->Driver
.RenderFinish
=fxDDRenderFinish
;
1097 ctx
->Driver
.ResetLineStipple
=_swrast_ResetLineStipple
;
1098 ctx
->Driver
.RenderPrimitive
=fxDDRenderPrimitive
;
1100 ctx
->Driver
.TexImage2D
= fxDDTexImage2D
;
1101 ctx
->Driver
.TexSubImage2D
= fxDDTexSubImage2D
;
1102 ctx
->Driver
.GetTexImage
= fxDDGetTexImage
;
1103 ctx
->Driver
.TexEnv
=fxDDTexEnv
;
1104 ctx
->Driver
.TexParameter
=fxDDTexParam
;
1105 ctx
->Driver
.BindTexture
=fxDDTexBind
;
1106 ctx
->Driver
.DeleteTexture
=fxDDTexDel
;
1107 ctx
->Driver
.UpdateTexturePalette
=fxDDTexPalette
;
1109 ctx
->Driver
.AlphaFunc
=fxDDAlphaFunc
;
1110 ctx
->Driver
.BlendFunc
=fxDDBlendFunc
;
1111 ctx
->Driver
.DepthFunc
=fxDDDepthFunc
;
1112 ctx
->Driver
.DepthMask
=fxDDDepthMask
;
1113 ctx
->Driver
.ColorMask
=fxDDColorMask
;
1114 ctx
->Driver
.Fogfv
=fxDDFogfv
;
1115 ctx
->Driver
.Scissor
=fxDDScissor
;
1116 ctx
->Driver
.FrontFace
=fxDDFrontFace
;
1117 ctx
->Driver
.CullFace
=fxDDCullFace
;
1118 ctx
->Driver
.ShadeModel
=fxDDShadeModel
;
1119 ctx
->Driver
.Enable
=fxDDEnable
;
1123 fxSetupDDSpanPointers(ctx
);
1124 fxDDUpdateDDPointers(ctx
,~0);
1132 * Need this to provide at least one external definition.
1135 extern int gl_fx_dummy_function_dd(void);
1136 int gl_fx_dummy_function_dd(void)