2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 /* fxdd.c - 3Dfx VooDoo Mesa device driver functions */
48 #include "extensions.h"
52 #include "swrast/swrast.h"
53 #include "swrast/s_context.h"
54 #include "swrast_setup/swrast_setup.h"
56 #include "tnl/t_context.h"
57 #include "tnl/t_pipeline.h"
58 #include "array_cache/acache.h"
62 /* lookup table for scaling 4 bit colors up to 8 bits */
63 GLuint FX_rgb_scale_4
[16] = {
64 0, 17, 34, 51, 68, 85, 102, 119,
65 136, 153, 170, 187, 204, 221, 238, 255
68 /* lookup table for scaling 5 bit colors up to 8 bits */
69 GLuint FX_rgb_scale_5
[32] = {
70 0, 8, 16, 25, 33, 41, 49, 58,
71 66, 74, 82, 90, 99, 107, 115, 123,
72 132, 140, 148, 156, 165, 173, 181, 189,
73 197, 206, 214, 222, 230, 239, 247, 255
76 /* lookup table for scaling 6 bit colors up to 8 bits */
77 GLuint FX_rgb_scale_6
[64] = {
78 0, 4, 8, 12, 16, 20, 24, 28,
79 32, 36, 40, 45, 49, 53, 57, 61,
80 65, 69, 73, 77, 81, 85, 89, 93,
81 97, 101, 105, 109, 113, 117, 121, 125,
82 130, 134, 138, 142, 146, 150, 154, 158,
83 162, 166, 170, 174, 178, 182, 186, 190,
84 194, 198, 202, 206, 210, 215, 219, 223,
85 227, 231, 235, 239, 243, 247, 251, 255
90 * Disable color by masking out R, G, B, A
92 static void fxDisableColor (fxMesaContext fxMesa
)
94 if (fxMesa
->colDepth
== 32) {
96 fxMesa
->Glide
.grColorMaskExt(FXFALSE
, FXFALSE
, FXFALSE
, FXFALSE
);
99 grColorMask(FXFALSE
, FXFALSE
);
104 /**********************************************************************/
105 /***** Miscellaneous functions *****/
106 /**********************************************************************/
108 /* Return buffer size information */
110 fxDDGetBufferSize(GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
112 GET_CURRENT_CONTEXT(ctx
);
113 if (ctx
&& FX_CONTEXT(ctx
)) {
114 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
116 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
117 fprintf(stderr
, "fxDDGetBufferSize(...)\n");
120 *width
= fxMesa
->width
;
121 *height
= fxMesa
->height
;
127 fxDDViewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
129 /* poll for window size change and realloc software Z/stencil/etc if needed */
130 _mesa_ResizeBuffersMESA();
134 /* Implements glClearColor() */
136 fxDDClearColor(GLcontext
* ctx
, const GLfloat color
[4])
138 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
141 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
142 fprintf(stderr
, "fxDDClearColor(%f, %f, %f, %f)\n",
143 color
[0], color
[1], color
[2], color
[3]);
146 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
147 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
148 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
149 CLAMPED_FLOAT_TO_UBYTE(col
[3], color
[3]);
151 fxMesa
->clearC
= FXCOLOR4(col
);
152 fxMesa
->clearA
= col
[3];
156 /* Clear the color and/or depth buffers */
157 static void fxDDClear( GLcontext
*ctx
,
158 GLbitfield mask
, GLboolean all
,
159 GLint x
, GLint y
, GLint width
, GLint height
)
161 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
162 GLbitfield softwareMask
= mask
& (DD_ACCUM_BIT
);
163 const GLuint stencil_size
= fxMesa
->haveHwStencil
? ctx
->Visual
.stencilBits
: 0;
164 const FxU32 clearD
= (FxU32
) (ctx
->DepthMaxF
* ctx
->Depth
.Clear
);
165 const FxU8 clearS
= (FxU8
) (ctx
->Stencil
.Clear
& 0xff);
167 if ( TDFX_DEBUG
& MESA_VERBOSE
) {
168 fprintf( stderr
, "fxDDClear( %d, %d, %d, %d )\n",
169 (int) x
, (int) y
, (int) width
, (int) height
);
172 /* we can't clear accum buffers nor stereo */
173 mask
&= ~(DD_ACCUM_BIT
| DD_FRONT_RIGHT_BIT
| DD_BACK_RIGHT_BIT
);
175 /* Need this check to respond to certain HW updates */
176 if (fxMesa
->new_state
& (FX_NEW_SCISSOR
| FX_NEW_COLOR_MASK
)) {
178 fxSetupColorMask(ctx
);
179 fxMesa
->new_state
&= ~(FX_NEW_SCISSOR
| FX_NEW_COLOR_MASK
);
183 * As per GL spec, color masking should be obeyed when clearing
185 if (ctx
->Visual
.greenBits
!= 8) {
186 /* can only do color masking if running in 24/32bpp on Napalm */
187 if (ctx
->Color
.ColorMask
[RCOMP
] != ctx
->Color
.ColorMask
[GCOMP
] ||
188 ctx
->Color
.ColorMask
[GCOMP
] != ctx
->Color
.ColorMask
[BCOMP
]) {
189 softwareMask
|= (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
190 mask
&= ~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
);
194 if (fxMesa
->haveHwStencil
) {
196 * If we want to clear stencil, it must be enabled
197 * in the HW, even if the stencil test is not enabled
201 if (mask
& DD_STENCIL_BIT
) {
202 fxMesa
->Glide
.grStencilMaskExt(fxMesa
->unitsState
.stencilWriteMask
);
203 /* set stencil ref value = desired clear value */
204 fxMesa
->Glide
.grStencilFuncExt(GR_CMP_ALWAYS
, clearS
, 0xff);
205 fxMesa
->Glide
.grStencilOpExt(GR_STENCILOP_REPLACE
,
206 GR_STENCILOP_REPLACE
, GR_STENCILOP_REPLACE
);
207 grEnable(GR_STENCIL_MODE_EXT
);
210 grDisable(GR_STENCIL_MODE_EXT
);
213 } else if (mask
& DD_STENCIL_BIT
) {
214 softwareMask
|= (mask
& (DD_STENCIL_BIT
));
215 mask
&= ~(DD_STENCIL_BIT
);
219 * This may be ugly, but it's needed in order to work around a number
225 * This could probably be done fancier but doing each possible case
226 * explicitly is less error prone.
228 switch (mask
& ~DD_STENCIL_BIT
) {
229 case DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
230 /* back buffer & depth */
232 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
233 if (stencil_size
> 0) {
234 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
239 grBufferClear(fxMesa
->clearC
,
243 case DD_FRONT_LEFT_BIT
| DD_DEPTH_BIT
:
244 /* XXX it appears that the depth buffer isn't cleared when
245 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
246 * This is a work-around/
250 fxDisableColor(fxMesa
);
251 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
252 if (stencil_size
> 0)
253 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
257 grBufferClear(fxMesa
->clearC
,
260 fxSetupColorMask(ctx
);
261 grDepthMask(FXFALSE
);
263 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
264 if (stencil_size
> 0)
265 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
269 grBufferClear(fxMesa
->clearC
,
273 case DD_BACK_LEFT_BIT
:
274 /* back buffer only */
275 grDepthMask(FXFALSE
);
276 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
277 if (stencil_size
> 0)
278 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
282 grBufferClear(fxMesa
->clearC
,
286 case DD_FRONT_LEFT_BIT
:
287 /* front buffer only */
288 grDepthMask(FXFALSE
);
289 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
290 if (stencil_size
> 0)
291 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
295 grBufferClear(fxMesa
->clearC
,
299 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
:
301 grDepthMask(FXFALSE
);
302 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
303 if (stencil_size
> 0)
304 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
308 grBufferClear(fxMesa
->clearC
,
311 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
312 if (stencil_size
> 0)
313 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
317 grBufferClear(fxMesa
->clearC
,
321 case DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
| DD_DEPTH_BIT
:
322 /* clear back and depth */
324 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
325 if (stencil_size
> 0)
326 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
330 grBufferClear(fxMesa
->clearC
,
334 grDepthMask(FXFALSE
);
335 grRenderBuffer(GR_BUFFER_FRONTBUFFER
);
336 if (stencil_size
> 0)
337 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
341 grBufferClear(fxMesa
->clearC
,
346 /* just the depth buffer */
348 fxDisableColor(fxMesa
);
349 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
350 if (stencil_size
> 0)
351 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
355 grBufferClear(fxMesa
->clearC
,
358 fxSetupColorMask(ctx
);
361 /* clear no color buffers or depth buffer but might clear stencil */
362 if ((stencil_size
> 0) && (mask
& DD_STENCIL_BIT
)) {
363 /* XXX need this RenderBuffer call to work around Glide bug */
364 grDepthMask(FXFALSE
);
365 grRenderBuffer(GR_BUFFER_BACKBUFFER
);
366 fxDisableColor(fxMesa
);
367 fxMesa
->Glide
.grBufferClearExt(fxMesa
->clearC
,
370 fxSetupColorMask(ctx
);
376 if (fxMesa
->haveHwStencil
) {
377 /* We changed the stencil state above. Restore it! */
380 fxSetupDepthTest(ctx
);
381 grRenderBuffer(fxMesa
->currentFB
);
384 _swrast_Clear( ctx
, softwareMask
, all
, x
, y
, width
, height
);
388 /* Set the buffer used for drawing */
389 /* XXX support for separate read/draw buffers hasn't been tested */
390 /* XXX GL_NONE disables color, but fails to correctly maintain state */
392 fxDDSetDrawBuffer(GLcontext
* ctx
, GLenum mode
)
394 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
396 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
397 fprintf(stderr
, "fxDDSetDrawBuffer(%x)\n", (int)mode
);
400 if (mode
== GL_FRONT_LEFT
) {
401 fxMesa
->currentFB
= GR_BUFFER_FRONTBUFFER
;
402 grRenderBuffer(fxMesa
->currentFB
);
404 else if (mode
== GL_BACK_LEFT
) {
405 fxMesa
->currentFB
= GR_BUFFER_BACKBUFFER
;
406 grRenderBuffer(fxMesa
->currentFB
);
408 else if (mode
== GL_NONE
) {
409 fxDisableColor(fxMesa
);
412 /* we'll need a software fallback */
413 /* XXX not implemented */
416 /* update s/w fallback state */
417 _swrast_DrawBuffer(ctx
, mode
);
422 fxDDDrawBitmap2 (GLcontext
*ctx
, GLint px
, GLint py
,
423 GLsizei width
, GLsizei height
,
424 const struct gl_pixelstore_attrib
*unpack
,
425 const GLubyte
*bitmap
)
427 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
428 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
430 GrLfbWriteMode_t mode
;
432 const struct gl_pixelstore_attrib
*finalUnpack
;
433 struct gl_pixelstore_attrib scissoredUnpack
;
435 /* check if there's any raster operations enabled which we can't handle */
436 if (swrast
->_RasterMask
& (ALPHATEST_BIT
|
437 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
438 DEPTH_BIT
| /* could be done with RGB:DEPTH */
439 FOG_BIT
| /* could be done with RGB:DEPTH */
441 /*CLIP_BIT |*/ /* clipping ok, below */
444 ALPHABUF_BIT
| /* nope! see 565 span kludge */
446 OCCLUSION_BIT
| /* nope! at least not yet */
449 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
453 /* make sure the pixelpipe is configured correctly */
456 /* FIXME! _RasterMask & CLIP_BIT gets set if we're out of Viewport, also! */
457 if (ctx
->Scissor
.Enabled
) {
458 /* This is a bit tricky, but by carefully adjusting the px, py,
459 * width, height, skipPixels and skipRows values we can do
460 * scissoring without special code in the rendering loop.
463 /* we'll construct a new pixelstore struct */
464 finalUnpack
= &scissoredUnpack
;
465 scissoredUnpack
= *unpack
;
466 if (scissoredUnpack
.RowLength
== 0)
467 scissoredUnpack
.RowLength
= width
;
470 if (px
< ctx
->Scissor
.X
) {
471 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
472 width
-= (ctx
->Scissor
.X
- px
);
476 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
477 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
480 if (py
< ctx
->Scissor
.Y
) {
481 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
482 height
-= (ctx
->Scissor
.Y
- py
);
486 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
487 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
490 if (width
<= 0 || height
<= 0)
494 finalUnpack
= unpack
;
497 /* compute pixel value */
499 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[RCOMP
] * 255.0f
);
500 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[GCOMP
] * 255.0f
);
501 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[BCOMP
] * 255.0f
);
502 GLint a
= (GLint
) (ctx
->Current
.RasterColor
[ACOMP
] * 255.0f
);
503 if (fxMesa
->colDepth
== 15) {
504 color
= TDFXPACKCOLOR1555(b
, g
, r
, a
);
505 mode
= GR_LFBWRITEMODE_1555
;
507 color
= fxMesa
->bgrOrder
? TDFXPACKCOLOR565(r
, g
, b
) : TDFXPACKCOLOR565(b
, g
, r
);
508 mode
= GR_LFBWRITEMODE_565
;
512 info
.size
= sizeof(info
);
513 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
516 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
517 _swrast_Bitmap(ctx
, px
, py
, width
, height
, finalUnpack
, bitmap
);
522 const GLint winX
= 0;
523 const GLint winY
= 0;
524 /* The dest stride depends on the hardware and whether we're drawing
525 * to the front or back buffer. This compile-time test seems to do
528 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
531 /* compute dest address of bottom-left pixel in bitmap */
532 GLushort
*dst
= (GLushort
*) info
.lfbPtr
533 + (winY
+ py
) * dstStride
+ (winX
+ px
);
535 for (row
= 0; row
< height
; row
++) {
537 (const GLubyte
*) _mesa_image_address2d(finalUnpack
,
538 bitmap
, width
, height
,
539 GL_COLOR_INDEX
, GL_BITMAP
,
541 if (finalUnpack
->LsbFirst
) {
542 /* least significan bit first */
543 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
545 for (col
= 0; col
< width
; col
++) {
561 /* most significan bit first */
562 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
564 for (col
= 0; col
< width
; col
++) {
583 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
587 fxDDDrawBitmap4 (GLcontext
*ctx
, GLint px
, GLint py
,
588 GLsizei width
, GLsizei height
,
589 const struct gl_pixelstore_attrib
*unpack
,
590 const GLubyte
*bitmap
)
592 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
593 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
596 const struct gl_pixelstore_attrib
*finalUnpack
;
597 struct gl_pixelstore_attrib scissoredUnpack
;
599 /* check if there's any raster operations enabled which we can't handle */
600 if ((swrast
->_RasterMask
& (/*ALPHATEST_BIT |*/
601 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
602 DEPTH_BIT
| /* could be done with RGB:DEPTH */
603 FOG_BIT
| /* could be done with RGB:DEPTH */
605 /*CLIP_BIT |*/ /* clipping ok, below */
607 /*MASKING_BIT |*/ /* masking ok, we're in 32bpp */
608 /*ALPHABUF_BIT |*//* alpha ok, we're in 32bpp */
610 OCCLUSION_BIT
| /* nope! at least not yet */
614 _swrast_Bitmap(ctx
, px
, py
, width
, height
, unpack
, bitmap
);
618 /* make sure the pixelpipe is configured correctly */
621 /* FIXME! _RasterMask & CLIP_BIT gets set if we're out of Viewport, also! */
622 if (ctx
->Scissor
.Enabled
) {
623 /* This is a bit tricky, but by carefully adjusting the px, py,
624 * width, height, skipPixels and skipRows values we can do
625 * scissoring without special code in the rendering loop.
628 /* we'll construct a new pixelstore struct */
629 finalUnpack
= &scissoredUnpack
;
630 scissoredUnpack
= *unpack
;
631 if (scissoredUnpack
.RowLength
== 0)
632 scissoredUnpack
.RowLength
= width
;
635 if (px
< ctx
->Scissor
.X
) {
636 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- px
);
637 width
-= (ctx
->Scissor
.X
- px
);
641 if (px
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
642 width
-= (px
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
645 if (py
< ctx
->Scissor
.Y
) {
646 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- py
);
647 height
-= (ctx
->Scissor
.Y
- py
);
651 if (py
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
652 height
-= (py
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
655 if (width
<= 0 || height
<= 0)
659 finalUnpack
= unpack
;
662 /* compute pixel value */
664 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[RCOMP
] * 255.0f
);
665 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[GCOMP
] * 255.0f
);
666 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[BCOMP
] * 255.0f
);
667 GLint a
= (GLint
) (ctx
->Current
.RasterColor
[ACOMP
] * 255.0f
);
668 color
= TDFXPACKCOLOR8888(b
, g
, r
, a
);
671 info
.size
= sizeof(info
);
672 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
674 GR_LFBWRITEMODE_8888
,
675 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
676 _swrast_Bitmap(ctx
, px
, py
, width
, height
, finalUnpack
, bitmap
);
681 const GLint winX
= 0;
682 const GLint winY
= 0;
683 /* The dest stride depends on the hardware and whether we're drawing
684 * to the front or back buffer. This compile-time test seems to do
687 const GLint dstStride
= info
.strideInBytes
/ 4; /* stride in GLuints */
690 /* compute dest address of bottom-left pixel in bitmap */
691 GLuint
*dst
= (GLuint
*) info
.lfbPtr
692 + (winY
+ py
) * dstStride
+ (winX
+ px
);
694 for (row
= 0; row
< height
; row
++) {
696 (const GLubyte
*) _mesa_image_address2d(finalUnpack
,
697 bitmap
, width
, height
,
698 GL_COLOR_INDEX
, GL_BITMAP
,
700 if (finalUnpack
->LsbFirst
) {
701 /* least significan bit first */
702 GLubyte mask
= 1U << (finalUnpack
->SkipPixels
& 0x7);
704 for (col
= 0; col
< width
; col
++) {
720 /* most significan bit first */
721 GLubyte mask
= 128U >> (finalUnpack
->SkipPixels
& 0x7);
723 for (col
= 0; col
< width
; col
++) {
742 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
747 fxDDReadPixels565 (GLcontext
* ctx
,
749 GLsizei width
, GLsizei height
,
750 GLenum format
, GLenum type
,
751 const struct gl_pixelstore_attrib
*packing
,
754 if (ctx
->_ImageTransferState
/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
755 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
760 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
764 info
.size
= sizeof(info
);
765 if (grLfbLock(GR_LFB_READ_ONLY
,
768 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
769 const GLint winX
= 0;
770 const GLint winY
= fxMesa
->height
- 1;
771 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
772 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
773 + (winY
- y
) * srcStride
+ (winX
+ x
);
774 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dstImage
,
775 width
, height
, format
,
778 _mesa_image_row_stride(packing
, width
, format
, type
);
780 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
781 /* convert 5R6G5B into 8R8G8B */
783 const GLint halfWidth
= width
>> 1;
784 const GLint extraPixel
= (width
& 1);
785 for (row
= 0; row
< height
; row
++) {
787 for (col
= 0; col
< halfWidth
; col
++) {
788 const GLuint pixel
= ((const GLuint
*) src
)[col
];
789 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
790 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
791 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
792 *d
++ = FX_rgb_scale_5
[(pixel
>> 27) & 0x1f];
793 *d
++ = FX_rgb_scale_6
[(pixel
>> 21) & 0x3f];
794 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
797 GLushort pixel
= src
[width
- 1];
798 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
799 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
800 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
806 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
807 /* convert 5R6G5B into 8R8G8B8A */
809 const GLint halfWidth
= width
>> 1;
810 const GLint extraPixel
= (width
& 1);
811 for (row
= 0; row
< height
; row
++) {
813 for (col
= 0; col
< halfWidth
; col
++) {
814 const GLuint pixel
= ((const GLuint
*) src
)[col
];
815 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
816 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
817 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
819 *d
++ = FX_rgb_scale_5
[(pixel
>> 27) & 0x1f];
820 *d
++ = FX_rgb_scale_6
[(pixel
>> 21) & 0x3f];
821 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
825 const GLushort pixel
= src
[width
- 1];
826 *d
++ = FX_rgb_scale_5
[(pixel
>> 11) & 0x1f];
827 *d
++ = FX_rgb_scale_6
[(pixel
>> 5) & 0x3f];
828 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
835 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
836 /* directly memcpy 5R6G5B pixels into client's buffer */
837 const GLint widthInBytes
= width
* 2;
839 for (row
= 0; row
< height
; row
++) {
840 MEMCPY(dst
, src
, widthInBytes
);
846 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
848 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
853 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
860 fxDDReadPixels555 (GLcontext
* ctx
,
862 GLsizei width
, GLsizei height
,
863 GLenum format
, GLenum type
,
864 const struct gl_pixelstore_attrib
*packing
,
867 if (ctx
->_ImageTransferState
/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
868 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
873 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
877 info
.size
= sizeof(info
);
878 if (grLfbLock(GR_LFB_READ_ONLY
,
881 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
882 const GLint winX
= 0;
883 const GLint winY
= fxMesa
->height
- 1;
884 const GLint srcStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
885 const GLushort
*src
= (const GLushort
*) info
.lfbPtr
886 + (winY
- y
) * srcStride
+ (winX
+ x
);
887 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dstImage
,
888 width
, height
, format
,
891 _mesa_image_row_stride(packing
, width
, format
, type
);
893 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
894 /* convert 5R5G5B into 8R8G8B */
896 const GLint halfWidth
= width
>> 1;
897 const GLint extraPixel
= (width
& 1);
898 for (row
= 0; row
< height
; row
++) {
900 for (col
= 0; col
< halfWidth
; col
++) {
901 const GLuint pixel
= ((const GLuint
*) src
)[col
];
902 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
903 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
904 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
905 *d
++ = FX_rgb_scale_5
[(pixel
>> 26) & 0x1f];
906 *d
++ = FX_rgb_scale_5
[(pixel
>> 21) & 0x1f];
907 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
910 GLushort pixel
= src
[width
- 1];
911 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
912 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
913 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
919 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
920 /* convert 5R6G5B into 8R8G8B8A */
922 const GLint halfWidth
= width
>> 1;
923 const GLint extraPixel
= (width
& 1);
924 for (row
= 0; row
< height
; row
++) {
926 for (col
= 0; col
< halfWidth
; col
++) {
927 const GLuint pixel
= ((const GLuint
*) src
)[col
];
928 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
929 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
930 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
931 *d
++ = (pixel
& 0x8000) ? 255 : 0;
932 *d
++ = FX_rgb_scale_5
[(pixel
>> 26) & 0x1f];
933 *d
++ = FX_rgb_scale_5
[(pixel
>> 21) & 0x1f];
934 *d
++ = FX_rgb_scale_5
[(pixel
>> 16) & 0x1f];
935 *d
++ = (pixel
& 0x80000000) ? 255 : 0;
938 const GLushort pixel
= src
[width
- 1];
939 *d
++ = FX_rgb_scale_5
[(pixel
>> 10) & 0x1f];
940 *d
++ = FX_rgb_scale_5
[(pixel
>> 5) & 0x1f];
941 *d
++ = FX_rgb_scale_5
[ pixel
& 0x1f];
942 *d
++ = (pixel
& 0x8000) ? 255 : 0;
948 else if (format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
949 /* directly memcpy 5R5G5B pixels into client's buffer */
950 const GLint widthInBytes
= width
* 2;
952 for (row
= 0; row
< height
; row
++) {
953 MEMCPY(dst
, src
, widthInBytes
);
959 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
961 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
966 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
973 fxDDReadPixels8888 (GLcontext
* ctx
,
975 GLsizei width
, GLsizei height
,
976 GLenum format
, GLenum type
,
977 const struct gl_pixelstore_attrib
*packing
,
980 if (ctx
->_ImageTransferState
/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
981 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
986 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
990 info
.size
= sizeof(info
);
991 if (grLfbLock(GR_LFB_READ_ONLY
,
994 GR_ORIGIN_UPPER_LEFT
, FXFALSE
, &info
)) {
995 const GLint winX
= 0;
996 const GLint winY
= fxMesa
->height
- 1;
997 const GLint srcStride
= info
.strideInBytes
/ 4; /* stride in GLuints */
998 const GLuint
*src
= (const GLuint
*) info
.lfbPtr
999 + (winY
- y
) * srcStride
+ (winX
+ x
);
1000 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dstImage
,
1001 width
, height
, format
,
1004 _mesa_image_row_stride(packing
, width
, format
, type
);
1006 if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1007 /* convert 8A8R8G8B into 8R8G8B */
1009 for (row
= 0; row
< height
; row
++) {
1011 for (col
= 0; col
< width
; col
++) {
1012 const GLuint pixel
= ((const GLuint
*) src
)[col
];
1021 else if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1022 /* 8A8R8G8B pixels into client's buffer */
1024 for (row
= 0; row
< height
; row
++) {
1026 for (col
= 0; col
< width
; col
++) {
1027 const GLuint pixel
= ((const GLuint
*) src
)[col
];
1037 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) {
1038 /* convert 8A8R8G8B into 5R6G5B */
1040 for (row
= 0; row
< height
; row
++) {
1041 GLushort
*d
= (GLushort
*)dst
;
1042 for (col
= 0; col
< width
; col
++) {
1043 const GLuint pixel
= ((const GLuint
*) src
)[col
];
1044 *d
++ = (((pixel
>> 16) & 0xf8) << 8) |
1045 (((pixel
>> 8) & 0xfc) << 3) |
1046 ((pixel
& 0xf8) >> 3);
1053 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
1055 _swrast_ReadPixels(ctx
, x
, y
, width
, height
, format
, type
,
1060 grLfbUnlock(GR_LFB_READ_ONLY
, fxMesa
->currentFB
);
1068 fxDDDrawPixels555 (GLcontext
* ctx
, GLint x
, GLint y
,
1069 GLsizei width
, GLsizei height
,
1070 GLenum format
, GLenum type
,
1071 const struct gl_pixelstore_attrib
*unpack
,
1072 const GLvoid
* pixels
)
1074 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1075 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1077 const struct gl_pixelstore_attrib
*finalUnpack
;
1078 struct gl_pixelstore_attrib scissoredUnpack
;
1080 if (ctx
->Pixel
.ZoomX
!= 1.0F
||
1081 ctx
->Pixel
.ZoomY
!= 1.0F
||
1082 (ctx
->_ImageTransferState
& (IMAGE_SCALE_BIAS_BIT
|
1083 IMAGE_MAP_COLOR_BIT
)) ||
1084 (swrast
->_RasterMask
& (ALPHATEST_BIT
|
1085 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
1086 DEPTH_BIT
| /* could be done with RGB:DEPTH */
1087 FOG_BIT
| /* could be done with RGB:DEPTH */
1089 /*CLIP_BIT |*/ /* clipping ok, below */
1094 OCCLUSION_BIT
| /* nope! at least not yet */
1099 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
1104 /* make sure the pixelpipe is configured correctly */
1105 fxSetupFXUnits(ctx
);
1107 /* FIXME! _RasterMask & CLIP_BIT gets set if we're out of Viewport, also! */
1108 if (ctx
->Scissor
.Enabled
) {
1109 /* This is a bit tricky, but by carefully adjusting the px, py,
1110 * width, height, skipPixels and skipRows values we can do
1111 * scissoring without special code in the rendering loop.
1114 /* we'll construct a new pixelstore struct */
1115 finalUnpack
= &scissoredUnpack
;
1116 scissoredUnpack
= *unpack
;
1117 if (scissoredUnpack
.RowLength
== 0)
1118 scissoredUnpack
.RowLength
= width
;
1121 if (x
< ctx
->Scissor
.X
) {
1122 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- x
);
1123 width
-= (ctx
->Scissor
.X
- x
);
1127 if (x
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
1128 width
-= (x
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
1131 if (y
< ctx
->Scissor
.Y
) {
1132 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- y
);
1133 height
-= (ctx
->Scissor
.Y
- y
);
1137 if (y
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
1138 height
-= (y
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
1141 if (width
<= 0 || height
<= 0)
1145 finalUnpack
= unpack
;
1148 info
.size
= sizeof(info
);
1149 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
1151 GR_LFBWRITEMODE_1555
,
1152 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
1153 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1158 const GLint winX
= 0;
1159 const GLint winY
= 0;
1161 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
1162 GLushort
*dst
= (GLushort
*) info
.lfbPtr
+ (winY
+ y
) * dstStride
+ (winX
+ x
);
1164 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1166 for (row
= 0; row
< height
; row
++) {
1167 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1168 pixels
, width
, height
, format
, type
, row
, 0);
1170 for (col
= 0; col
< width
; col
++) {
1171 dst
[col
] = TDFXPACKCOLOR1555(src
[2], src
[1], src
[0], src
[3]);
1177 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1179 for (row
= 0; row
< height
; row
++) {
1180 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1181 pixels
, width
, height
, format
, type
, row
, 0);
1183 for (col
= 0; col
< width
; col
++) {
1184 dst
[col
] = TDFXPACKCOLOR1555(src
[2], src
[1], src
[0], 255);
1191 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1192 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1198 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1203 fxDDDrawPixels565 (GLcontext
* ctx
, GLint x
, GLint y
,
1204 GLsizei width
, GLsizei height
,
1205 GLenum format
, GLenum type
,
1206 const struct gl_pixelstore_attrib
*unpack
,
1207 const GLvoid
* pixels
)
1209 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1210 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1212 const struct gl_pixelstore_attrib
*finalUnpack
;
1213 struct gl_pixelstore_attrib scissoredUnpack
;
1215 if (ctx
->Pixel
.ZoomX
!= 1.0F
||
1216 ctx
->Pixel
.ZoomY
!= 1.0F
||
1217 (ctx
->_ImageTransferState
& (IMAGE_SCALE_BIAS_BIT
|
1218 IMAGE_MAP_COLOR_BIT
)) ||
1219 (swrast
->_RasterMask
& (ALPHATEST_BIT
|
1220 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
1221 DEPTH_BIT
| /* could be done with RGB:DEPTH */
1222 FOG_BIT
| /* could be done with RGB:DEPTH */
1224 /*CLIP_BIT |*/ /* clipping ok, below */
1229 OCCLUSION_BIT
| /* nope! at least not yet */
1234 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
1239 /* make sure the pixelpipe is configured correctly */
1240 fxSetupFXUnits(ctx
);
1242 /* FIXME! _RasterMask & CLIP_BIT gets set if we're out of Viewport, also! */
1243 if (ctx
->Scissor
.Enabled
) {
1244 /* This is a bit tricky, but by carefully adjusting the px, py,
1245 * width, height, skipPixels and skipRows values we can do
1246 * scissoring without special code in the rendering loop.
1249 /* we'll construct a new pixelstore struct */
1250 finalUnpack
= &scissoredUnpack
;
1251 scissoredUnpack
= *unpack
;
1252 if (scissoredUnpack
.RowLength
== 0)
1253 scissoredUnpack
.RowLength
= width
;
1256 if (x
< ctx
->Scissor
.X
) {
1257 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- x
);
1258 width
-= (ctx
->Scissor
.X
- x
);
1262 if (x
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
1263 width
-= (x
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
1266 if (y
< ctx
->Scissor
.Y
) {
1267 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- y
);
1268 height
-= (ctx
->Scissor
.Y
- y
);
1272 if (y
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
1273 height
-= (y
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
1276 if (width
<= 0 || height
<= 0)
1280 finalUnpack
= unpack
;
1283 info
.size
= sizeof(info
);
1284 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
1286 GR_LFBWRITEMODE_565
,
1287 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
1288 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1293 const GLint winX
= 0;
1294 const GLint winY
= 0;
1296 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
1297 GLushort
*dst
= (GLushort
*) info
.lfbPtr
+ (winY
+ y
) * dstStride
+ (winX
+ x
);
1299 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1301 for (row
= 0; row
< height
; row
++) {
1302 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1303 pixels
, width
, height
, format
, type
, row
, 0);
1305 for (col
= 0; col
< width
; col
++) {
1306 dst
[col
] = TDFXPACKCOLOR565(src
[2], src
[1], src
[0]);
1312 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1314 for (row
= 0; row
< height
; row
++) {
1315 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1316 pixels
, width
, height
, format
, type
, row
, 0);
1318 for (col
= 0; col
< width
; col
++) {
1319 dst
[col
] = TDFXPACKCOLOR565(src
[2], src
[1], src
[0]);
1326 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1327 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1333 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1338 fxDDDrawPixels565_rev (GLcontext
* ctx
, GLint x
, GLint y
,
1339 GLsizei width
, GLsizei height
,
1340 GLenum format
, GLenum type
,
1341 const struct gl_pixelstore_attrib
*unpack
,
1342 const GLvoid
* pixels
)
1344 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1345 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1347 const struct gl_pixelstore_attrib
*finalUnpack
;
1348 struct gl_pixelstore_attrib scissoredUnpack
;
1350 if (ctx
->Pixel
.ZoomX
!= 1.0F
||
1351 ctx
->Pixel
.ZoomY
!= 1.0F
||
1352 (ctx
->_ImageTransferState
& (IMAGE_SCALE_BIAS_BIT
|
1353 IMAGE_MAP_COLOR_BIT
)) ||
1354 (swrast
->_RasterMask
& (ALPHATEST_BIT
|
1355 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
1356 DEPTH_BIT
| /* could be done with RGB:DEPTH */
1357 FOG_BIT
| /* could be done with RGB:DEPTH */
1359 /*CLIP_BIT |*/ /* clipping ok, below */
1364 OCCLUSION_BIT
| /* nope! at least not yet */
1369 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
1374 /* make sure the pixelpipe is configured correctly */
1375 fxSetupFXUnits(ctx
);
1377 /* FIXME! _RasterMask & CLIP_BIT gets set if we're out of Viewport, also! */
1378 if (ctx
->Scissor
.Enabled
) {
1379 /* This is a bit tricky, but by carefully adjusting the px, py,
1380 * width, height, skipPixels and skipRows values we can do
1381 * scissoring without special code in the rendering loop.
1384 /* we'll construct a new pixelstore struct */
1385 finalUnpack
= &scissoredUnpack
;
1386 scissoredUnpack
= *unpack
;
1387 if (scissoredUnpack
.RowLength
== 0)
1388 scissoredUnpack
.RowLength
= width
;
1391 if (x
< ctx
->Scissor
.X
) {
1392 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- x
);
1393 width
-= (ctx
->Scissor
.X
- x
);
1397 if (x
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
1398 width
-= (x
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
1401 if (y
< ctx
->Scissor
.Y
) {
1402 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- y
);
1403 height
-= (ctx
->Scissor
.Y
- y
);
1407 if (y
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
1408 height
-= (y
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
1411 if (width
<= 0 || height
<= 0)
1415 finalUnpack
= unpack
;
1418 info
.size
= sizeof(info
);
1419 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
1421 GR_LFBWRITEMODE_565
,
1422 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
1423 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1428 const GLint winX
= 0;
1429 const GLint winY
= 0;
1431 const GLint dstStride
= info
.strideInBytes
/ 2; /* stride in GLushorts */
1432 GLushort
*dst
= (GLushort
*) info
.lfbPtr
+ (winY
+ y
) * dstStride
+ (winX
+ x
);
1434 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1436 for (row
= 0; row
< height
; row
++) {
1437 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1438 pixels
, width
, height
, format
, type
, row
, 0);
1440 for (col
= 0; col
< width
; col
++) {
1441 dst
[col
] = TDFXPACKCOLOR565(src
[0], src
[1], src
[2]);
1447 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1449 for (row
= 0; row
< height
; row
++) {
1450 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1451 pixels
, width
, height
, format
, type
, row
, 0);
1453 for (col
= 0; col
< width
; col
++) {
1454 dst
[col
] = TDFXPACKCOLOR565(src
[0], src
[1], src
[2]);
1461 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1462 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1468 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1473 fxDDDrawPixels8888 (GLcontext
* ctx
, GLint x
, GLint y
,
1474 GLsizei width
, GLsizei height
,
1475 GLenum format
, GLenum type
,
1476 const struct gl_pixelstore_attrib
*unpack
,
1477 const GLvoid
* pixels
)
1479 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1480 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1482 const struct gl_pixelstore_attrib
*finalUnpack
;
1483 struct gl_pixelstore_attrib scissoredUnpack
;
1485 if (ctx
->Pixel
.ZoomX
!= 1.0F
||
1486 ctx
->Pixel
.ZoomY
!= 1.0F
||
1487 (ctx
->_ImageTransferState
& (IMAGE_SCALE_BIAS_BIT
|
1488 IMAGE_MAP_COLOR_BIT
)) ||
1489 (swrast
->_RasterMask
& (/*ALPHATEST_BIT |*/
1490 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
1491 DEPTH_BIT
| /* could be done with RGB:DEPTH */
1492 FOG_BIT
| /* could be done with RGB:DEPTH */
1494 /*CLIP_BIT |*/ /* clipping ok, below */
1496 /*MASKING_BIT |*/ /* masking ok, we're in 32bpp */
1497 /*ALPHABUF_BIT |*//* alpha ok, we're in 32bpp */
1499 OCCLUSION_BIT
| /* nope! at least not yet */
1504 _swrast_DrawPixels( ctx
, x
, y
, width
, height
, format
, type
,
1509 /* make sure the pixelpipe is configured correctly */
1510 fxSetupFXUnits(ctx
);
1512 /* FIXME! _RasterMask & CLIP_BIT gets set if we're out of Viewport, also! */
1513 if (ctx
->Scissor
.Enabled
) {
1514 /* This is a bit tricky, but by carefully adjusting the px, py,
1515 * width, height, skipPixels and skipRows values we can do
1516 * scissoring without special code in the rendering loop.
1519 /* we'll construct a new pixelstore struct */
1520 finalUnpack
= &scissoredUnpack
;
1521 scissoredUnpack
= *unpack
;
1522 if (scissoredUnpack
.RowLength
== 0)
1523 scissoredUnpack
.RowLength
= width
;
1526 if (x
< ctx
->Scissor
.X
) {
1527 scissoredUnpack
.SkipPixels
+= (ctx
->Scissor
.X
- x
);
1528 width
-= (ctx
->Scissor
.X
- x
);
1532 if (x
+ width
>= ctx
->Scissor
.X
+ ctx
->Scissor
.Width
) {
1533 width
-= (x
+ width
- (ctx
->Scissor
.X
+ ctx
->Scissor
.Width
));
1536 if (y
< ctx
->Scissor
.Y
) {
1537 scissoredUnpack
.SkipRows
+= (ctx
->Scissor
.Y
- y
);
1538 height
-= (ctx
->Scissor
.Y
- y
);
1542 if (y
+ height
>= ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
) {
1543 height
-= (y
+ height
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
));
1546 if (width
<= 0 || height
<= 0)
1550 finalUnpack
= unpack
;
1553 info
.size
= sizeof(info
);
1554 if (!grLfbLock(GR_LFB_WRITE_ONLY
,
1556 GR_LFBWRITEMODE_8888
,
1557 GR_ORIGIN_LOWER_LEFT
, FXTRUE
, &info
)) {
1558 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1563 const GLint winX
= 0;
1564 const GLint winY
= 0;
1566 const GLint dstStride
= info
.strideInBytes
/ 4; /* stride in GLuints */
1567 GLuint
*dst
= (GLuint
*) info
.lfbPtr
+ (winY
+ y
) * dstStride
+ (winX
+ x
);
1569 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1570 /* directly memcpy 8A8R8G8B pixels to screen */
1571 const GLint widthInBytes
= width
* 4;
1573 for (row
= 0; row
< height
; row
++) {
1574 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1575 pixels
, width
, height
, format
, type
, row
, 0);
1576 MEMCPY(dst
, src
, widthInBytes
);
1580 else if (format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1582 for (row
= 0; row
< height
; row
++) {
1583 GLubyte
*src
= (GLubyte
*) _mesa_image_address2d(finalUnpack
,
1584 pixels
, width
, height
, format
, type
, row
, 0);
1586 for (col
= 0; col
< width
; col
++) {
1587 dst
[col
] = TDFXPACKCOLOR8888(src
[2], src
[1], src
[0], 255);
1594 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1595 _swrast_DrawPixels(ctx
, x
, y
, width
, height
, format
, type
, finalUnpack
, pixels
);
1601 grLfbUnlock(GR_LFB_WRITE_ONLY
, fxMesa
->currentFB
);
1606 fxDDFinish(GLcontext
* ctx
)
1615 /* KW: Put the word Mesa in the render string because quakeworld
1616 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
1619 static const GLubyte
*
1620 fxDDGetString(GLcontext
* ctx
, GLenum name
)
1622 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1626 return (GLubyte
*)fxMesa
->rendererString
;
1627 #if __WIN32__ /* hack to advertise vanilla extension names */
1629 if (ctx
->Extensions
.String
== NULL
) {
1630 GLubyte
*ext
= _mesa_make_extension_string(ctx
);
1632 ctx
->Extensions
.String
= _mesa_malloc(strlen((char *)ext
) + 256);
1633 if (ctx
->Extensions
.String
!= NULL
) {
1634 strcpy((char *)ctx
->Extensions
.String
, (char *)ext
);
1635 /* put any additional extension names here */
1637 strcat((char *)ctx
->Extensions
.String
, " 3DFX_set_global_palette");
1640 strcat((char *)ctx
->Extensions
.String
, " WGL_3DFX_gamma_control");
1641 strcat((char *)ctx
->Extensions
.String
, " WGL_EXT_swap_control");
1642 strcat((char *)ctx
->Extensions
.String
, " WGL_EXT_extensions_string WGL_ARB_extensions_string");
1644 /* put any additional extension names here */
1647 ctx
->Extensions
.String
= ext
;
1651 return ctx
->Extensions
.String
;
1658 static const struct tnl_pipeline_stage
*fx_pipeline
[] = {
1659 &_tnl_vertex_transform_stage
, /* XXX todo - Add the fastpath here */
1660 &_tnl_normal_transform_stage
,
1661 &_tnl_lighting_stage
,
1662 &_tnl_fog_coordinate_stage
,
1664 &_tnl_texture_transform_stage
,
1665 &_tnl_point_attenuation_stage
,
1666 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
1667 &_tnl_vertex_program_stage
,
1677 fxDDInitFxMesaContext(fxMesaContext fxMesa
)
1680 GLcontext
*ctx
= fxMesa
->glCtx
;
1682 FX_setupGrVertexLayout();
1684 fxMesa
->color
= 0xffffffff;
1688 fxMesa
->stats
.swapBuffer
= 0;
1689 fxMesa
->stats
.reqTexUpload
= 0;
1690 fxMesa
->stats
.texUpload
= 0;
1691 fxMesa
->stats
.memTexUpload
= 0;
1693 fxMesa
->tmuSrc
= FX_TMU_NONE
;
1694 fxMesa
->lastUnitsMode
= FX_UM_NONE
;
1697 /* FX units setup */
1699 fxMesa
->unitsState
.alphaTestEnabled
= GL_FALSE
;
1700 fxMesa
->unitsState
.alphaTestFunc
= GL_ALWAYS
;
1701 fxMesa
->unitsState
.alphaTestRefValue
= 0.0;
1703 fxMesa
->unitsState
.blendEnabled
= GL_FALSE
;
1704 fxMesa
->unitsState
.blendSrcFuncRGB
= GR_BLEND_ONE
;
1705 fxMesa
->unitsState
.blendDstFuncRGB
= GR_BLEND_ZERO
;
1706 fxMesa
->unitsState
.blendSrcFuncAlpha
= GR_BLEND_ONE
;
1707 fxMesa
->unitsState
.blendDstFuncAlpha
= GR_BLEND_ZERO
;
1708 fxMesa
->unitsState
.blendEqRGB
= GR_BLEND_OP_ADD
;
1709 fxMesa
->unitsState
.blendEqAlpha
= GR_BLEND_OP_ADD
;
1711 fxMesa
->unitsState
.depthTestEnabled
= GL_FALSE
;
1712 fxMesa
->unitsState
.depthMask
= GL_TRUE
;
1713 fxMesa
->unitsState
.depthTestFunc
= GL_LESS
;
1714 fxMesa
->unitsState
.depthBias
= 0;
1716 fxMesa
->unitsState
.stencilWriteMask
= 0xff;
1718 if (fxMesa
->colDepth
== 32) {
1720 fxMesa
->Glide
.grColorMaskExt(FXTRUE
, FXTRUE
, FXTRUE
, fxMesa
->haveHwAlpha
);
1722 /* 15/16 bpp mode */
1723 grColorMask(FXTRUE
, fxMesa
->haveHwAlpha
);
1726 fxMesa
->currentFB
= fxMesa
->haveDoubleBuffer
? GR_BUFFER_BACKBUFFER
: GR_BUFFER_FRONTBUFFER
;
1727 grRenderBuffer(fxMesa
->currentFB
);
1729 fxMesa
->state
= MALLOC(FX_grGetInteger(GR_GLIDE_STATE_SIZE
));
1730 fxMesa
->fogTable
= (GrFog_t
*) MALLOC(FX_grGetInteger(GR_FOG_TABLE_ENTRIES
) *
1733 if (!fxMesa
->state
|| !fxMesa
->fogTable
) {
1735 FREE(fxMesa
->state
);
1736 if (fxMesa
->fogTable
)
1737 FREE(fxMesa
->fogTable
);
1741 if (fxMesa
->haveZBuffer
) {
1742 grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER
);
1745 if (!fxMesa
->bgrOrder
) {
1746 grLfbWriteColorFormat(GR_COLORFORMAT_ABGR
);
1749 if (fxMesa
->Glide
.grSetNumPendingBuffers
!= NULL
) {
1750 fxMesa
->Glide
.grSetNumPendingBuffers(fxMesa
->maxPendingSwapBuffers
);
1753 fxMesa
->textureAlign
= FX_grGetInteger(GR_TEXTURE_ALIGN
);
1757 int textureLevels
= 0;
1758 int textureSize
= FX_grGetInteger(GR_MAX_TEXTURE_SIZE
);
1761 } while ((textureSize
>>= 0x1) & 0x7ff);
1762 ctx
->Const
.MaxTextureLevels
= textureLevels
;
1763 ctx
->Const
.MaxTextureLodBias
= /*textureLevels - 1*/8; /* Glide bug */
1764 #if FX_RESCALE_BIG_TEXURES_HACK
1765 fxMesa
->textureMaxLod
= textureLevels
- 1;
1766 if ((env
= getenv("MESA_FX_MAXLOD")) != NULL
) {
1767 int maxLevels
= atoi(env
) + 1;
1768 if ((maxLevels
<= MAX_TEXTURE_LEVELS
) && (maxLevels
> textureLevels
)) {
1769 ctx
->Const
.MaxTextureLevels
= maxLevels
;
1774 ctx
->Const
.MaxTextureCoordUnits
=
1775 ctx
->Const
.MaxTextureImageUnits
= fxMesa
->haveTwoTMUs
? 2 : 1;
1776 ctx
->Const
.MaxTextureUnits
= MAX2(ctx
->Const
.MaxTextureImageUnits
, ctx
->Const
.MaxTextureCoordUnits
);
1778 fxMesa
->new_state
= _NEW_ALL
;
1779 if (!fxMesa
->haveHwStencil
) {
1780 /* don't touch stencil if there is none */
1781 fxMesa
->new_state
&= ~FX_NEW_STENCIL
;
1784 /* Initialize the software rasterizer and helper modules.
1786 _swrast_CreateContext(ctx
);
1787 _ac_CreateContext(ctx
);
1788 _tnl_CreateContext(ctx
);
1789 _swsetup_CreateContext(ctx
);
1791 /* Install customized pipeline */
1792 _tnl_destroy_pipeline(ctx
);
1793 _tnl_install_pipeline(ctx
, fx_pipeline
);
1797 fxSetupDDPointers(ctx
);
1798 fxDDInitTriFuncs(ctx
);
1800 /* Tell the software rasterizer to use pixel fog always.
1802 _swrast_allow_vertex_fog(ctx
, GL_FALSE
);
1803 _swrast_allow_pixel_fog(ctx
, GL_TRUE
);
1804 _tnl_allow_vertex_fog( ctx
, GL_FALSE
);
1805 _tnl_allow_pixel_fog( ctx
, GL_TRUE
);
1807 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
1808 * tell render stage not to clip fog coords).
1810 /* _tnl_calculate_vertex_fog( ctx, GL_FALSE ); */
1812 fxDDInitExtensions(ctx
);
1815 /* do we want dither? It just looks bad... */
1816 grEnable(GR_ALLOW_MIPMAP_DITHER
);
1818 grGlideGetState((GrState
*) fxMesa
->state
);
1826 fxDDDestroyFxMesaContext(fxMesaContext fxMesa
)
1828 _swsetup_DestroyContext(fxMesa
->glCtx
);
1829 _tnl_DestroyContext(fxMesa
->glCtx
);
1830 _ac_DestroyContext(fxMesa
->glCtx
);
1831 _swrast_DestroyContext(fxMesa
->glCtx
);
1834 FREE(fxMesa
->state
);
1835 if (fxMesa
->fogTable
)
1836 FREE(fxMesa
->fogTable
);
1837 fxFreeVB(fxMesa
->glCtx
);
1844 fxDDInitExtensions(GLcontext
* ctx
)
1846 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1848 #if 1 /* multipass ColorSum stage */
1849 _mesa_enable_extension(ctx
, "GL_EXT_secondary_color");
1852 _mesa_enable_extension(ctx
, "GL_ARB_point_sprite");
1853 _mesa_enable_extension(ctx
, "GL_EXT_point_parameters");
1854 _mesa_enable_extension(ctx
, "GL_EXT_paletted_texture");
1855 _mesa_enable_extension(ctx
, "GL_EXT_texture_lod_bias");
1856 _mesa_enable_extension(ctx
, "GL_EXT_shared_texture_palette");
1857 _mesa_enable_extension(ctx
, "GL_EXT_blend_func_separate");
1858 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_add");
1859 _mesa_enable_extension(ctx
, "GL_EXT_stencil_wrap");
1860 _mesa_enable_extension(ctx
, "GL_EXT_stencil_two_side");
1862 if (fxMesa
->haveTwoTMUs
) {
1863 _mesa_enable_extension(ctx
, "GL_ARB_multitexture");
1866 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1867 _mesa_enable_extension(ctx
, "GL_ARB_texture_compression");
1868 _mesa_enable_extension(ctx
, "GL_3DFX_texture_compression_FXT1");
1869 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
1870 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
1871 _mesa_enable_extension(ctx
, "GL_NV_blend_square");
1874 * We should enable generic texture compression functions,
1875 * but some poorly written apps automatically assume S3TC.
1876 * Binding NCC to GL_COMPRESSED_RGB[A] is an unnecessary hassle,
1877 * since it's slow and ugly (better with palette textures, then).
1878 * Moreover, NCC is not an OpenGL standard, so we can't use
1879 * precompressed textures. Last, but not least, NCC runs amok
1880 * when multitexturing on a Voodoo3 and up (see POINTCAST vs UMA).
1881 * Note: this is also a problem with palette textures, but
1882 * faking multitex by multipass is evil...
1883 * Implementing NCC requires three stages:
1884 * fxDDChooseTextureFormat:
1885 * bind GL_COMPRESSED_RGB[A] to _mesa_texformat_argb8888,
1886 * so we can quantize properly, at a later time
1888 * if GL_COMPRESSED_RGB
1889 * use _mesa_texformat_l8 to get 1bpt and set GR_TEXFMT_YIQ_422
1890 * if GL_COMPRESSED_RGBA
1891 * use _mesa_texformat_al88 to get 2bpt and set GR_TEXFMT_AYIQ_8422
1892 * txMipQuantize(...);
1894 * txPalToNcc((GuNccTable *)(&(ti->palette)), pxMip.pal);
1896 * fxSetupSingleTMU_NoLock/fxSetupDoubleTMU_NoLock:
1897 * grTexDownloadTable(GR_TEXTABLE_NCC0, &(ti->palette));
1899 /*_mesa_enable_extension(ctx, "GL_ARB_texture_compression");*/
1900 _mesa_enable_extension(ctx
, "GL_SGIS_generate_mipmap");
1903 if (fxMesa
->HaveCmbExt
) {
1904 _mesa_enable_extension(ctx
, "GL_ARB_texture_env_combine");
1905 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_combine");
1908 if (fxMesa
->HavePixExt
) {
1909 _mesa_enable_extension(ctx
, "GL_EXT_blend_subtract");
1910 _mesa_enable_extension(ctx
, "GL_EXT_blend_equation_separate");
1913 if (fxMesa
->HaveMirExt
) {
1914 _mesa_enable_extension(ctx
, "GL_ARB_texture_mirrored_repeat");
1917 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo2
) {
1918 _mesa_enable_extension(ctx
, "GL_EXT_fog_coord");
1921 /* core-level extensions */
1922 _mesa_enable_extension(ctx
, "GL_EXT_multi_draw_arrays");
1923 _mesa_enable_extension(ctx
, "GL_IBM_multimode_draw_arrays");
1924 _mesa_enable_extension(ctx
, "GL_ARB_vertex_buffer_object");
1926 if (getenv("MESA_FX_ALLOW_VP")) {
1927 _mesa_enable_extension(ctx
, "GL_ARB_vertex_program");
1928 _mesa_enable_extension(ctx
, "GL_NV_vertex_program");
1929 _mesa_enable_extension(ctx
, "GL_NV_vertex_program1_1");
1930 _mesa_enable_extension(ctx
, "GL_MESA_program_debug");
1933 /* this requires _tnl_vertex_cull_stage in the pipeline */
1934 _mesa_enable_extension(ctx
, "EXT_cull_vertex");
1939 /************************************************************************/
1940 /************************************************************************/
1941 /************************************************************************/
1943 /* Check if the hardware supports the current context
1945 * Performs similar work to fxDDChooseRenderState() - should be merged.
1948 fx_check_IsInHardware(GLcontext
* ctx
)
1950 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1952 if (ctx
->RenderMode
!= GL_RENDER
) {
1953 return FX_FALLBACK_RENDER_MODE
;
1956 if (ctx
->Stencil
.Enabled
&& !fxMesa
->haveHwStencil
) {
1957 return FX_FALLBACK_STENCIL
;
1960 if (ctx
->Color
._DrawDestMask
[0] != DD_FRONT_LEFT_BIT
&&
1961 ctx
->Color
._DrawDestMask
[0] != DD_BACK_LEFT_BIT
) {
1962 return FX_FALLBACK_DRAW_BUFFER
;
1965 if (ctx
->Color
.BlendEnabled
) {
1966 if (ctx
->Color
.BlendEquationRGB
!= GL_FUNC_ADD
) {
1967 if (!fxMesa
->HavePixExt
||
1968 ((ctx
->Color
.BlendEquationRGB
!= GL_FUNC_SUBTRACT
) &&
1969 (ctx
->Color
.BlendEquationRGB
!= GL_FUNC_REVERSE_SUBTRACT
))) {
1970 return FX_FALLBACK_BLEND
;
1974 if (ctx
->Color
.BlendEquationA
!= GL_FUNC_ADD
) {
1975 if (!fxMesa
->HavePixExt
||
1976 ((ctx
->Color
.BlendEquationA
!= GL_FUNC_SUBTRACT
) &&
1977 (ctx
->Color
.BlendEquationA
!= GL_FUNC_REVERSE_SUBTRACT
))) {
1978 return FX_FALLBACK_BLEND
;
1984 * We fail the spec here, unless certain blending modes:
1985 * RGB: (GL_ONE + GL_*) or (GL_ZERO + GL_*) or ...
1987 if (NEED_SECONDARY_COLOR(ctx
)) {
1988 if ((ctx
->Color
.BlendEquationRGB
!= GL_FUNC_ADD
) &&
1989 (ctx
->Color
.BlendSrcRGB
!= GL_ONE
)) {
1990 /* Can't use multipass to blend ColorSum stage */
1991 return FX_FALLBACK_SPECULAR
;
1998 * We could avoid this for certain `sfactor/dfactor'
1999 * I do not think that is even worthwhile to check
2000 * because if someone is using blending they use more
2001 * interesting settings and also it would add more
2002 * state tracking to a lot of the code.
2004 if (ctx
->Color
.ColorLogicOpEnabled
&& (ctx
->Color
.LogicOp
!= GL_COPY
)) {
2005 return FX_FALLBACK_LOGICOP
;
2008 if ((fxMesa
->colDepth
!= 32) &&
2009 ((ctx
->Color
.ColorMask
[RCOMP
] != ctx
->Color
.ColorMask
[GCOMP
]) ||
2010 (ctx
->Color
.ColorMask
[GCOMP
] != ctx
->Color
.ColorMask
[BCOMP
]))) {
2011 return FX_FALLBACK_COLORMASK
;
2014 /* Unsupported texture/multitexture cases */
2016 /* we can only do 1D/2D textures */
2017 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
2018 return FX_FALLBACK_TEXTURE_MAP
;
2020 if (fxMesa
->haveTwoTMUs
) {
2021 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
2022 return FX_FALLBACK_TEXTURE_MAP
;
2024 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
) {
2025 if (fxMesa
->type
< GR_SSTTYPE_Voodoo2
)
2026 if (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
&&
2027 (ctx
->Texture
.Unit
[1]._ReallyEnabled
||
2028 ctx
->Texture
.Unit
[0].EnvColor
[0] != 0 ||
2029 ctx
->Texture
.Unit
[0].EnvColor
[1] != 0 ||
2030 ctx
->Texture
.Unit
[0].EnvColor
[2] != 0 ||
2031 ctx
->Texture
.Unit
[0].EnvColor
[3] != 1)) {
2032 return FX_FALLBACK_TEXTURE_ENV
;
2034 if (ctx
->Texture
.Unit
[0]._Current
->Image
[0][0]->Border
> 0)
2035 return FX_FALLBACK_TEXTURE_BORDER
;
2038 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
) {
2039 if (fxMesa
->type
< GR_SSTTYPE_Voodoo2
)
2040 if (ctx
->Texture
.Unit
[1].EnvMode
== GL_BLEND
)
2041 return FX_FALLBACK_TEXTURE_ENV
;
2042 if (ctx
->Texture
.Unit
[1]._Current
->Image
[0][0]->Border
> 0)
2043 return FX_FALLBACK_TEXTURE_BORDER
;
2046 if (TDFX_DEBUG
& (VERBOSE_DRIVER
| VERBOSE_TEXTURE
))
2047 fprintf(stderr
, "fx_check_IsInHardware: envmode is %s/%s\n",
2048 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[0].EnvMode
),
2049 _mesa_lookup_enum_by_nr(ctx
->Texture
.Unit
[1].EnvMode
));
2051 /* KW: This was wrong (I think) and I changed it... which doesn't mean
2052 * it is now correct...
2053 * BP: The old condition just seemed to test if both texture units
2054 * were enabled. That's easy!
2056 if (ctx
->Texture
._EnabledUnits
== 0x3) {
2058 /* Can't use multipass to blend a multitextured triangle - fall
2061 if (!fxMesa
->haveTwoTMUs
&& ctx
->Color
.BlendEnabled
) {
2062 return FX_FALLBACK_TEXTURE_MULTI
;
2066 if (!fxMesa
->HaveCmbExt
&&
2067 (ctx
->Texture
.Unit
[0].EnvMode
!= ctx
->Texture
.Unit
[1].EnvMode
) &&
2068 (ctx
->Texture
.Unit
[0].EnvMode
!= GL_MODULATE
) &&
2069 (ctx
->Texture
.Unit
[0].EnvMode
!= GL_REPLACE
)) { /* q2, seems ok... */
2070 if (TDFX_DEBUG
& VERBOSE_DRIVER
)
2071 fprintf(stderr
, "fx_check_IsInHardware: unsupported multitex env mode\n");
2072 return FX_FALLBACK_TEXTURE_MULTI
;
2077 /* we have just one texture unit */
2078 if (ctx
->Texture
._EnabledUnits
> 0x1) {
2079 return FX_FALLBACK_TEXTURE_MULTI
;
2082 if (fxMesa
->type
< GR_SSTTYPE_Voodoo2
)
2083 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
2084 (ctx
->Texture
.Unit
[0].EnvMode
== GL_BLEND
)) {
2085 return FX_FALLBACK_TEXTURE_ENV
;
2095 fxDDUpdateDDPointers(GLcontext
* ctx
, GLuint new_state
)
2097 /* TNLcontext *tnl = TNL_CONTEXT(ctx);*/
2098 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
2100 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
2101 fprintf(stderr
, "fxDDUpdateDDPointers(%08x)\n", new_state
);
2104 _swrast_InvalidateState(ctx
, new_state
);
2105 _ac_InvalidateState(ctx
, new_state
);
2106 _tnl_InvalidateState(ctx
, new_state
);
2107 _swsetup_InvalidateState(ctx
, new_state
);
2109 fxMesa
->new_gl_state
|= new_state
;
2116 fxSetupDDPointers(GLcontext
* ctx
)
2118 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
2119 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
2121 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
2122 fprintf(stderr
, "fxSetupDDPointers()\n");
2125 ctx
->Driver
.UpdateState
= fxDDUpdateDDPointers
;
2126 ctx
->Driver
.GetString
= fxDDGetString
;
2127 ctx
->Driver
.ClearIndex
= NULL
;
2128 ctx
->Driver
.ClearColor
= fxDDClearColor
;
2129 ctx
->Driver
.Clear
= fxDDClear
;
2130 ctx
->Driver
.DrawBuffer
= fxDDSetDrawBuffer
;
2131 ctx
->Driver
.GetBufferSize
= fxDDGetBufferSize
;
2132 ctx
->Driver
.Viewport
= fxDDViewport
;
2133 switch (fxMesa
->colDepth
) {
2135 ctx
->Driver
.DrawPixels
= fxDDDrawPixels555
;
2136 ctx
->Driver
.ReadPixels
= fxDDReadPixels555
;
2137 ctx
->Driver
.Bitmap
= fxDDDrawBitmap2
;
2140 ctx
->Driver
.DrawPixels
= !fxMesa
->bgrOrder
? fxDDDrawPixels565
: fxDDDrawPixels565_rev
;
2141 ctx
->Driver
.ReadPixels
= fxDDReadPixels565
;
2142 ctx
->Driver
.Bitmap
= fxDDDrawBitmap2
;
2145 ctx
->Driver
.DrawPixels
= fxDDDrawPixels8888
;
2146 ctx
->Driver
.ReadPixels
= fxDDReadPixels8888
;
2147 ctx
->Driver
.Bitmap
= fxDDDrawBitmap4
;
2150 ctx
->Driver
.Finish
= fxDDFinish
;
2151 ctx
->Driver
.Flush
= NULL
;
2152 ctx
->Driver
.ChooseTextureFormat
= fxDDChooseTextureFormat
;
2153 ctx
->Driver
.TexImage1D
= fxDDTexImage1D
;
2154 ctx
->Driver
.TexImage2D
= fxDDTexImage2D
;
2155 ctx
->Driver
.TexSubImage1D
= fxDDTexSubImage1D
;
2156 ctx
->Driver
.TexSubImage2D
= fxDDTexSubImage2D
;
2157 ctx
->Driver
.CompressedTexImage2D
= fxDDCompressedTexImage2D
;
2158 ctx
->Driver
.CompressedTexSubImage2D
= fxDDCompressedTexSubImage2D
;
2159 ctx
->Driver
.TestProxyTexImage
= fxDDTestProxyTexImage
;
2160 ctx
->Driver
.TexEnv
= fxDDTexEnv
;
2161 ctx
->Driver
.TexParameter
= fxDDTexParam
;
2162 ctx
->Driver
.BindTexture
= fxDDTexBind
;
2163 ctx
->Driver
.DeleteTexture
= fxDDTexDel
;
2164 ctx
->Driver
.IsTextureResident
= fxDDIsTextureResident
;
2165 ctx
->Driver
.UpdateTexturePalette
= fxDDTexPalette
;
2166 ctx
->Driver
.AlphaFunc
= fxDDAlphaFunc
;
2167 ctx
->Driver
.BlendFuncSeparate
= fxDDBlendFuncSeparate
;
2168 ctx
->Driver
.BlendEquationSeparate
= fxDDBlendEquationSeparate
;
2169 ctx
->Driver
.DepthFunc
= fxDDDepthFunc
;
2170 ctx
->Driver
.DepthMask
= fxDDDepthMask
;
2171 ctx
->Driver
.ColorMask
= fxDDColorMask
;
2172 ctx
->Driver
.Fogfv
= fxDDFogfv
;
2173 ctx
->Driver
.Scissor
= fxDDScissor
;
2174 ctx
->Driver
.FrontFace
= fxDDFrontFace
;
2175 ctx
->Driver
.CullFace
= fxDDCullFace
;
2176 ctx
->Driver
.ShadeModel
= fxDDShadeModel
;
2177 ctx
->Driver
.Enable
= fxDDEnable
;
2178 if (fxMesa
->haveHwStencil
) {
2179 ctx
->Driver
.StencilFunc
= fxDDStencilFunc
;
2180 ctx
->Driver
.StencilMask
= fxDDStencilMask
;
2181 ctx
->Driver
.StencilOp
= fxDDStencilOp
;
2184 fxSetupDDSpanPointers(ctx
);
2185 fxDDUpdateDDPointers(ctx
, ~0);
2193 * Need this to provide at least one external definition.
2196 extern int gl_fx_dummy_function_dd(void);
2198 gl_fx_dummy_function_dd(void)