fixed pixelpiped DrawBitmap / DrawPixels (clipping was upside-down)
[mesa.git] / src / mesa / drivers / glide / fxdd.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /* Authors:
26 * David Bucciarelli
27 * Brian Paul
28 * Daryll Strauss
29 * Keith Whitwell
30 * Daniel Borca
31 * Hiroshi Morii
32 */
33
34 /* fxdd.c - 3Dfx VooDoo Mesa device driver functions */
35
36
37 #ifdef HAVE_CONFIG_H
38 #include "conf.h"
39 #endif
40
41 #if defined(FX)
42
43 #include "image.h"
44 #include "mtypes.h"
45 #include "fxdrv.h"
46 #include "enums.h"
47 #include "extensions.h"
48 #include "macros.h"
49 #include "texstore.h"
50 #include "teximage.h"
51 #include "swrast/swrast.h"
52 #include "swrast/s_context.h"
53 #include "swrast_setup/swrast_setup.h"
54 #include "tnl/tnl.h"
55 #include "tnl/t_context.h"
56 #include "tnl/t_pipeline.h"
57 #include "array_cache/acache.h"
58
59
60
61 /* lookup table for scaling 4 bit colors up to 8 bits */
62 GLuint FX_rgb_scale_4[16] = {
63 0, 17, 34, 51, 68, 85, 102, 119,
64 136, 153, 170, 187, 204, 221, 238, 255
65 };
66
67 /* lookup table for scaling 5 bit colors up to 8 bits */
68 GLuint FX_rgb_scale_5[32] = {
69 0, 8, 16, 25, 33, 41, 49, 58,
70 66, 74, 82, 90, 99, 107, 115, 123,
71 132, 140, 148, 156, 165, 173, 181, 189,
72 197, 206, 214, 222, 230, 239, 247, 255
73 };
74
75 /* lookup table for scaling 6 bit colors up to 8 bits */
76 GLuint FX_rgb_scale_6[64] = {
77 0, 4, 8, 12, 16, 20, 24, 28,
78 32, 36, 40, 45, 49, 53, 57, 61,
79 65, 69, 73, 77, 81, 85, 89, 93,
80 97, 101, 105, 109, 113, 117, 121, 125,
81 130, 134, 138, 142, 146, 150, 154, 158,
82 162, 166, 170, 174, 178, 182, 186, 190,
83 194, 198, 202, 206, 210, 215, 219, 223,
84 227, 231, 235, 239, 243, 247, 251, 255
85 };
86
87
88 /*
89 * Disable color by masking out R, G, B, A
90 */
91 static void fxDisableColor (fxMesaContext fxMesa)
92 {
93 if (fxMesa->colDepth == 32) {
94 /* 32bpp mode */
95 fxMesa->Glide.grColorMaskExt(FXFALSE, FXFALSE, FXFALSE, FXFALSE);
96 } else {
97 /* 15/16 bpp mode */
98 grColorMask(FXFALSE, FXFALSE);
99 }
100 }
101
102
103 /**********************************************************************/
104 /***** Miscellaneous functions *****/
105 /**********************************************************************/
106
107 /* Return buffer size information */
108 static void
109 fxDDBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
110 {
111 GET_CURRENT_CONTEXT(ctx);
112 if (ctx && FX_CONTEXT(ctx)) {
113 fxMesaContext fxMesa = FX_CONTEXT(ctx);
114
115 if (TDFX_DEBUG & VERBOSE_DRIVER) {
116 fprintf(stderr, "fxDDBufferSize(...)\n");
117 }
118
119 *width = fxMesa->width;
120 *height = fxMesa->height;
121 }
122 }
123
124
125 /* Implements glClearColor() */
126 static void
127 fxDDClearColor(GLcontext * ctx, const GLfloat color[4])
128 {
129 fxMesaContext fxMesa = FX_CONTEXT(ctx);
130 GLubyte col[4];
131
132 if (TDFX_DEBUG & VERBOSE_DRIVER) {
133 fprintf(stderr, "fxDDClearColor(%f, %f, %f, %f)\n",
134 color[0], color[1], color[2], color[3]);
135 }
136
137 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
138 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
139 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
140 CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]);
141
142 fxMesa->clearC = FXCOLOR4(col);
143 fxMesa->clearA = col[3];
144 }
145
146
147 /* Clear the color and/or depth buffers */
148 static void fxDDClear( GLcontext *ctx,
149 GLbitfield mask, GLboolean all,
150 GLint x, GLint y, GLint width, GLint height )
151 {
152 fxMesaContext fxMesa = FX_CONTEXT(ctx);
153 GLbitfield softwareMask = mask & (DD_ACCUM_BIT);
154 const GLuint stencil_size = fxMesa->haveHwStencil ? ctx->Visual.stencilBits : 0;
155 const FxU32 clearD = (FxU32) (ctx->DepthMaxF * ctx->Depth.Clear);
156 const FxU8 clearS = (FxU8) (ctx->Stencil.Clear & 0xff);
157
158 if ( TDFX_DEBUG & MESA_VERBOSE ) {
159 fprintf( stderr, "fxDDClear( %d, %d, %d, %d )\n",
160 (int) x, (int) y, (int) width, (int) height );
161 }
162
163 /* Need this check to respond to glScissor and clipping updates */
164 /* should also take care of FX_NEW_COLOR_MASK, FX_NEW_STENCIL, depth? */
165 if (fxMesa->new_state & FX_NEW_SCISSOR) {
166 fxSetupScissor(ctx);
167 fxMesa->new_state &= ~FX_NEW_SCISSOR;
168 }
169
170 /* we can't clear accum buffers */
171 mask &= ~(DD_ACCUM_BIT);
172
173 /*
174 * As per GL spec, stencil masking should be obeyed when clearing
175 */
176 if (mask & DD_STENCIL_BIT) {
177 if (!fxMesa->haveHwStencil || fxMesa->unitsState.stencilWriteMask != 0xff) {
178 /* Napalm seems to have trouble with stencil write masks != 0xff */
179 /* do stencil clear in software */
180 softwareMask |= DD_STENCIL_BIT;
181 mask &= ~(DD_STENCIL_BIT);
182 }
183 }
184
185 /*
186 * As per GL spec, color masking should be obeyed when clearing
187 */
188 if (ctx->Visual.greenBits != 8) {
189 /* can only do color masking if running in 24/32bpp on Napalm */
190 if (ctx->Color.ColorMask[RCOMP] != ctx->Color.ColorMask[GCOMP] ||
191 ctx->Color.ColorMask[GCOMP] != ctx->Color.ColorMask[BCOMP]) {
192 softwareMask |= (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
193 mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
194 }
195 }
196
197 if (fxMesa->haveHwStencil) {
198 /*
199 * If we want to clear stencil, it must be enabled
200 * in the HW, even if the stencil test is not enabled
201 * in the OGL state.
202 */
203 BEGIN_BOARD_LOCK();
204 if (mask & DD_STENCIL_BIT) {
205 fxMesa->Glide.grStencilMaskExt(0xff /*fxMesa->unitsState.stencilWriteMask*/);
206 /* set stencil ref value = desired clear value */
207 fxMesa->Glide.grStencilFuncExt(GR_CMP_ALWAYS, clearS, 0xff);
208 fxMesa->Glide.grStencilOpExt(GR_STENCILOP_REPLACE,
209 GR_STENCILOP_REPLACE, GR_STENCILOP_REPLACE);
210 grEnable(GR_STENCIL_MODE_EXT);
211 }
212 else {
213 grDisable(GR_STENCIL_MODE_EXT);
214 }
215 END_BOARD_LOCK();
216 }
217
218 /*
219 * This may be ugly, but it's needed in order to work around a number
220 * of Glide bugs.
221 */
222 BEGIN_CLIP_LOOP();
223 {
224 /*
225 * This could probably be done fancier but doing each possible case
226 * explicitly is less error prone.
227 */
228 switch (mask & ~DD_STENCIL_BIT) {
229 case DD_BACK_LEFT_BIT | DD_DEPTH_BIT:
230 /* back buffer & depth */
231 /* FX_grColorMaskv_NoLock(ctx, true4); */ /* work around Voodoo3 bug */
232 grDepthMask(FXTRUE);
233 grRenderBuffer(GR_BUFFER_BACKBUFFER);
234 if (stencil_size > 0) {
235 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
236 fxMesa->clearA,
237 clearD, clearS);
238 }
239 else
240 grBufferClear(fxMesa->clearC,
241 fxMesa->clearA,
242 clearD);
243 if (!fxMesa->unitsState.depthTestEnabled) {
244 grDepthMask(FXFALSE);
245 }
246 break;
247 case DD_FRONT_LEFT_BIT | DD_DEPTH_BIT:
248 /* XXX it appears that the depth buffer isn't cleared when
249 * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set.
250 * This is a work-around/
251 */
252 /* clear depth */
253 grDepthMask(FXTRUE);
254 grRenderBuffer(GR_BUFFER_BACKBUFFER);
255 fxDisableColor(fxMesa);
256 if (stencil_size > 0)
257 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
258 fxMesa->clearA,
259 clearD, clearS);
260 else
261 grBufferClear(fxMesa->clearC,
262 fxMesa->clearA,
263 clearD);
264 /* clear front */
265 fxSetupColorMask(ctx);
266 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
267 if (stencil_size > 0)
268 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
269 fxMesa->clearA,
270 clearD, clearS);
271 else
272 grBufferClear(fxMesa->clearC,
273 fxMesa->clearA,
274 clearD);
275 if (!fxMesa->unitsState.depthTestEnabled) {
276 grDepthMask(FXFALSE);
277 }
278 break;
279 case DD_BACK_LEFT_BIT:
280 /* back buffer only */
281 grDepthMask(FXFALSE);
282 grRenderBuffer(GR_BUFFER_BACKBUFFER);
283 if (stencil_size > 0)
284 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
285 fxMesa->clearA,
286 clearD, clearS);
287 else
288 grBufferClear(fxMesa->clearC,
289 fxMesa->clearA,
290 clearD);
291 if (fxMesa->unitsState.depthTestEnabled) {
292 grDepthMask(FXTRUE);
293 }
294 break;
295 case DD_FRONT_LEFT_BIT:
296 /* front buffer only */
297 grDepthMask(FXFALSE);
298 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
299 if (stencil_size > 0)
300 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
301 fxMesa->clearA,
302 clearD, clearS);
303 else
304 grBufferClear(fxMesa->clearC,
305 fxMesa->clearA,
306 clearD);
307 if (fxMesa->unitsState.depthTestEnabled) {
308 grDepthMask(FXTRUE);
309 }
310 break;
311 case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT:
312 /* front and back */
313 grDepthMask(FXFALSE);
314 grRenderBuffer(GR_BUFFER_BACKBUFFER);
315 if (stencil_size > 0)
316 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
317 fxMesa->clearA,
318 clearD, clearS);
319 else
320 grBufferClear(fxMesa->clearC,
321 fxMesa->clearA,
322 clearD);
323 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
324 if (stencil_size > 0)
325 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
326 fxMesa->clearA,
327 clearD, clearS);
328 else
329 grBufferClear(fxMesa->clearC,
330 fxMesa->clearA,
331 clearD);
332 if (fxMesa->unitsState.depthTestEnabled) {
333 grDepthMask(FXTRUE);
334 }
335 break;
336 case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT:
337 /* clear front */
338 grDepthMask(FXFALSE);
339 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
340 if (stencil_size > 0)
341 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
342 fxMesa->clearA,
343 clearD, clearS);
344 else
345 grBufferClear(fxMesa->clearC,
346 fxMesa->clearA,
347 clearD);
348 /* clear back and depth */
349 grDepthMask(FXTRUE);
350 grRenderBuffer(GR_BUFFER_BACKBUFFER);
351 if (stencil_size > 0)
352 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
353 fxMesa->clearA,
354 clearD, clearS);
355 else
356 grBufferClear(fxMesa->clearC,
357 fxMesa->clearA,
358 clearD);
359 if (!fxMesa->unitsState.depthTestEnabled) {
360 grDepthMask(FXFALSE);
361 }
362 break;
363 case DD_DEPTH_BIT:
364 /* just the depth buffer */
365 grRenderBuffer(GR_BUFFER_BACKBUFFER);
366 fxDisableColor(fxMesa);
367 grDepthMask(FXTRUE);
368 if (stencil_size > 0)
369 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
370 fxMesa->clearA,
371 clearD, clearS);
372 else
373 grBufferClear(fxMesa->clearC,
374 fxMesa->clearA,
375 clearD);
376 fxSetupColorMask(ctx);
377 if (ctx->Color._DrawDestMask & DD_FRONT_LEFT_BIT) {
378 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
379 }
380 if (!fxMesa->unitsState.depthTestEnabled) {
381 grDepthMask(FXFALSE);
382 }
383 break;
384 default:
385 /* clear no color buffers or depth buffer but might clear stencil */
386 if (stencil_size > 0 && (mask & DD_STENCIL_BIT)) {
387 /* XXX need this RenderBuffer call to work around Glide bug */
388 grRenderBuffer(GR_BUFFER_BACKBUFFER);
389 grDepthMask(FXFALSE);
390 fxDisableColor(fxMesa);
391 fxMesa->Glide.grBufferClearExt(fxMesa->clearC,
392 fxMesa->clearA,
393 clearD, clearS);
394 if (fxMesa->unitsState.depthTestEnabled) {
395 grDepthMask(FXTRUE);
396 }
397 fxSetupColorMask(ctx);
398 if (ctx->Color._DrawDestMask & DD_FRONT_LEFT_BIT) {
399 grRenderBuffer(GR_BUFFER_FRONTBUFFER);
400 }
401 }
402 }
403 }
404 END_CLIP_LOOP();
405
406 if (fxMesa->haveHwStencil && (mask & DD_STENCIL_BIT)) {
407 /* We changed the stencil state above. Signal that we need to
408 * upload it again.
409 */
410 fxMesa->new_state |= FX_NEW_STENCIL;
411 }
412
413 if (softwareMask)
414 _swrast_Clear( ctx, softwareMask, all, x, y, width, height );
415 }
416
417
418 /* Set the buffer used for drawing */
419 /* XXX support for separate read/draw buffers hasn't been tested */
420 static void
421 fxDDSetDrawBuffer(GLcontext * ctx, GLenum mode)
422 {
423 fxMesaContext fxMesa = FX_CONTEXT(ctx);
424
425 if (TDFX_DEBUG & VERBOSE_DRIVER) {
426 fprintf(stderr, "fxDDSetDrawBuffer(%x)\n", (int)mode);
427 }
428
429 if (mode == GL_FRONT_LEFT) {
430 fxMesa->currentFB = GR_BUFFER_FRONTBUFFER;
431 grRenderBuffer(fxMesa->currentFB);
432 }
433 else if (mode == GL_BACK_LEFT) {
434 fxMesa->currentFB = GR_BUFFER_BACKBUFFER;
435 grRenderBuffer(fxMesa->currentFB);
436 }
437 else if (mode == GL_NONE) {
438 fxDisableColor(fxMesa);
439 }
440 else {
441 /* we'll need a software fallback */
442 /* XXX not implemented */
443 }
444
445 /* update s/w fallback state */
446 _swrast_DrawBuffer(ctx, mode);
447 }
448
449
450 static void
451 fxDDDrawBitmap2 (GLcontext *ctx, GLint px, GLint py,
452 GLsizei width, GLsizei height,
453 const struct gl_pixelstore_attrib *unpack,
454 const GLubyte *bitmap)
455 {
456 fxMesaContext fxMesa = FX_CONTEXT(ctx);
457 SWcontext *swrast = SWRAST_CONTEXT(ctx);
458 GrLfbInfo_t info;
459 GrLfbWriteMode_t mode;
460 FxU16 color;
461 const struct gl_pixelstore_attrib *finalUnpack;
462 struct gl_pixelstore_attrib scissoredUnpack;
463
464 /* check if there's any raster operations enabled which we can't handle */
465 if (swrast->_RasterMask & (ALPHATEST_BIT |
466 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
467 DEPTH_BIT | /* could be done with RGB:DEPTH */
468 FOG_BIT | /* could be done with RGB:DEPTH */
469 LOGIC_OP_BIT |
470 /*CLIP_BIT |*/ /* clipping ok, below */
471 STENCIL_BIT |
472 MASKING_BIT |
473 ALPHABUF_BIT | /* nope! see 565 span kludge */
474 MULTI_DRAW_BIT |
475 OCCLUSION_BIT | /* nope! at least not yet */
476 TEXTURE_BIT |
477 FRAGPROG_BIT)) {
478 _swrast_Bitmap(ctx, px, py, width, height, unpack, bitmap);
479 return;
480 }
481
482 /* make sure the pixelpipe is configured correctly */
483 fxSetupFXUnits(ctx);
484
485 if (ctx->Scissor.Enabled) {
486 /* This is a bit tricky, but by carefully adjusting the px, py,
487 * width, height, skipPixels and skipRows values we can do
488 * scissoring without special code in the rendering loop.
489 */
490
491 /* we'll construct a new pixelstore struct */
492 finalUnpack = &scissoredUnpack;
493 scissoredUnpack = *unpack;
494 if (scissoredUnpack.RowLength == 0)
495 scissoredUnpack.RowLength = width;
496
497 /* clip left */
498 if (px < ctx->Scissor.X) {
499 scissoredUnpack.SkipPixels += (ctx->Scissor.X - px);
500 width -= (ctx->Scissor.X - px);
501 px = ctx->Scissor.X;
502 }
503 /* clip right */
504 if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) {
505 width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width));
506 }
507 /* clip bottom */
508 if (py < ctx->Scissor.Y) {
509 scissoredUnpack.SkipRows += (ctx->Scissor.Y - py);
510 height -= (ctx->Scissor.Y - py);
511 py = ctx->Scissor.Y;
512 }
513 /* clip top */
514 if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) {
515 height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height));
516 }
517
518 if (width <= 0 || height <= 0)
519 return;
520 }
521 else {
522 finalUnpack = unpack;
523 }
524
525 /* compute pixel value */
526 {
527 GLint r = (GLint) (ctx->Current.RasterColor[RCOMP] * 255.0f);
528 GLint g = (GLint) (ctx->Current.RasterColor[GCOMP] * 255.0f);
529 GLint b = (GLint) (ctx->Current.RasterColor[BCOMP] * 255.0f);
530 GLint a = (GLint) (ctx->Current.RasterColor[ACOMP] * 255.0f);
531 if (fxMesa->colDepth == 15) {
532 color = TDFXPACKCOLOR1555(b, g, r, a);
533 mode = GR_LFBWRITEMODE_1555;
534 } else {
535 color = fxMesa->bgrOrder ? TDFXPACKCOLOR565(r, g, b) : TDFXPACKCOLOR565(b, g, r);
536 mode = GR_LFBWRITEMODE_565;
537 }
538 }
539
540 info.size = sizeof(info);
541 if (!grLfbLock(GR_LFB_WRITE_ONLY,
542 fxMesa->currentFB,
543 mode,
544 GR_ORIGIN_LOWER_LEFT, FXTRUE, &info)) {
545 _swrast_Bitmap(ctx, px, py, width, height, unpack, bitmap);
546 return;
547 }
548
549 {
550 const GLint winX = 0;
551 const GLint winY = 0;
552 /* The dest stride depends on the hardware and whether we're drawing
553 * to the front or back buffer. This compile-time test seems to do
554 * the job for now.
555 */
556 const GLint dstStride = info.strideInBytes / 2; /* stride in GLushorts */
557
558 GLint row;
559 /* compute dest address of bottom-left pixel in bitmap */
560 GLushort *dst = (GLushort *) info.lfbPtr
561 + (winY + py) * dstStride + (winX + px);
562
563 for (row = 0; row < height; row++) {
564 const GLubyte *src =
565 (const GLubyte *) _mesa_image_address(finalUnpack,
566 bitmap, width, height,
567 GL_COLOR_INDEX, GL_BITMAP,
568 0, row, 0);
569 if (finalUnpack->LsbFirst) {
570 /* least significan bit first */
571 GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7);
572 GLint col;
573 for (col = 0; col < width; col++) {
574 if (*src & mask) {
575 dst[col] = color;
576 }
577 if (mask == 128U) {
578 src++;
579 mask = 1U;
580 }
581 else {
582 mask = mask << 1;
583 }
584 }
585 if (mask != 1)
586 src++;
587 }
588 else {
589 /* most significan bit first */
590 GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7);
591 GLint col;
592 for (col = 0; col < width; col++) {
593 if (*src & mask) {
594 dst[col] = color;
595 }
596 if (mask == 1U) {
597 src++;
598 mask = 128U;
599 }
600 else {
601 mask = mask >> 1;
602 }
603 }
604 if (mask != 128)
605 src++;
606 }
607 dst += dstStride;
608 }
609 }
610
611 grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB);
612 }
613
614 static void
615 fxDDDrawBitmap4 (GLcontext *ctx, GLint px, GLint py,
616 GLsizei width, GLsizei height,
617 const struct gl_pixelstore_attrib *unpack,
618 const GLubyte *bitmap)
619 {
620 fxMesaContext fxMesa = FX_CONTEXT(ctx);
621 SWcontext *swrast = SWRAST_CONTEXT(ctx);
622 GrLfbInfo_t info;
623 FxU32 color;
624 const struct gl_pixelstore_attrib *finalUnpack;
625 struct gl_pixelstore_attrib scissoredUnpack;
626
627 /* check if there's any raster operations enabled which we can't handle */
628 if ((swrast->_RasterMask & (/*ALPHATEST_BIT |*/
629 /*BLEND_BIT |*/ /* blending ok, through pixpipe */
630 DEPTH_BIT | /* could be done with RGB:DEPTH */
631 FOG_BIT | /* could be done with RGB:DEPTH */
632 LOGIC_OP_BIT |
633 /*CLIP_BIT |*/ /* clipping ok, below */
634 STENCIL_BIT |
635 /*MASKING_BIT |*/ /* masking ok, we're in 32bpp */
636 /*ALPHABUF_BIT |*//* alpha ok, we're in 32bpp */
637 MULTI_DRAW_BIT |
638 OCCLUSION_BIT | /* nope! at least not yet */
639 TEXTURE_BIT |
640 FRAGPROG_BIT))
641 ) {
642 _swrast_Bitmap(ctx, px, py, width, height, unpack, bitmap);
643 return;
644 }
645
646 /* make sure the pixelpipe is configured correctly */
647 fxSetupFXUnits(ctx);
648
649 if (ctx->Scissor.Enabled) {
650 /* This is a bit tricky, but by carefully adjusting the px, py,
651 * width, height, skipPixels and skipRows values we can do
652 * scissoring without special code in the rendering loop.
653 */
654
655 /* we'll construct a new pixelstore struct */
656 finalUnpack = &scissoredUnpack;
657 scissoredUnpack = *unpack;
658 if (scissoredUnpack.RowLength == 0)
659 scissoredUnpack.RowLength = width;
660
661 /* clip left */
662 if (px < ctx->Scissor.X) {
663 scissoredUnpack.SkipPixels += (ctx->Scissor.X - px);
664 width -= (ctx->Scissor.X - px);
665 px = ctx->Scissor.X;
666 }
667 /* clip right */
668 if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) {
669 width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width));
670 }
671 /* clip bottom */
672 if (py < ctx->Scissor.Y) {
673 scissoredUnpack.SkipRows += (ctx->Scissor.Y - py);
674 height -= (ctx->Scissor.Y - py);
675 py = ctx->Scissor.Y;
676 }
677 /* clip top */
678 if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) {
679 height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height));
680 }
681
682 if (width <= 0 || height <= 0)
683 return;
684 }
685 else {
686 finalUnpack = unpack;
687 }
688
689 /* compute pixel value */
690 {
691 GLint r = (GLint) (ctx->Current.RasterColor[RCOMP] * 255.0f);
692 GLint g = (GLint) (ctx->Current.RasterColor[GCOMP] * 255.0f);
693 GLint b = (GLint) (ctx->Current.RasterColor[BCOMP] * 255.0f);
694 GLint a = (GLint) (ctx->Current.RasterColor[ACOMP] * 255.0f);
695 color = TDFXPACKCOLOR8888(b, g, r, a);
696 }
697
698 info.size = sizeof(info);
699 if (!grLfbLock(GR_LFB_WRITE_ONLY,
700 fxMesa->currentFB,
701 GR_LFBWRITEMODE_8888,
702 GR_ORIGIN_LOWER_LEFT, FXTRUE, &info)) {
703 _swrast_Bitmap(ctx, px, py, width, height, unpack, bitmap);
704 return;
705 }
706
707 {
708 const GLint winX = 0;
709 const GLint winY = 0;
710 /* The dest stride depends on the hardware and whether we're drawing
711 * to the front or back buffer. This compile-time test seems to do
712 * the job for now.
713 */
714 const GLint dstStride = info.strideInBytes / 4; /* stride in GLuints */
715
716 GLint row;
717 /* compute dest address of bottom-left pixel in bitmap */
718 GLuint *dst = (GLuint *) info.lfbPtr
719 + (winY + py) * dstStride + (winX + px);
720
721 for (row = 0; row < height; row++) {
722 const GLubyte *src =
723 (const GLubyte *) _mesa_image_address(finalUnpack,
724 bitmap, width, height,
725 GL_COLOR_INDEX, GL_BITMAP,
726 0, row, 0);
727 if (finalUnpack->LsbFirst) {
728 /* least significan bit first */
729 GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7);
730 GLint col;
731 for (col = 0; col < width; col++) {
732 if (*src & mask) {
733 dst[col] = color;
734 }
735 if (mask == 128U) {
736 src++;
737 mask = 1U;
738 }
739 else {
740 mask = mask << 1;
741 }
742 }
743 if (mask != 1)
744 src++;
745 }
746 else {
747 /* most significan bit first */
748 GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7);
749 GLint col;
750 for (col = 0; col < width; col++) {
751 if (*src & mask) {
752 dst[col] = color;
753 }
754 if (mask == 1U) {
755 src++;
756 mask = 128U;
757 }
758 else {
759 mask = mask >> 1;
760 }
761 }
762 if (mask != 128)
763 src++;
764 }
765 dst += dstStride;
766 }
767 }
768
769 grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB);
770 }
771
772
773 static void
774 fxDDReadPixels565 (GLcontext * ctx,
775 GLint x, GLint y,
776 GLsizei width, GLsizei height,
777 GLenum format, GLenum type,
778 const struct gl_pixelstore_attrib *packing,
779 GLvoid *dstImage)
780 {
781 if (ctx->_ImageTransferState/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
782 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
783 packing, dstImage);
784 return;
785 }
786 else {
787 fxMesaContext fxMesa = FX_CONTEXT(ctx);
788 GrLfbInfo_t info;
789
790 BEGIN_BOARD_LOCK();
791 info.size = sizeof(info);
792 if (grLfbLock(GR_LFB_READ_ONLY,
793 fxMesa->currentFB,
794 GR_LFBWRITEMODE_ANY,
795 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
796 const GLint winX = 0;
797 const GLint winY = fxMesa->height - 1;
798 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
799 const GLushort *src = (const GLushort *) info.lfbPtr
800 + (winY - y) * srcStride + (winX + x);
801 GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage,
802 width, height, format,
803 type, 0, 0, 0);
804 GLint dstStride =
805 _mesa_image_row_stride(packing, width, format, type);
806
807 if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
808 /* convert 5R6G5B into 8R8G8B */
809 GLint row, col;
810 const GLint halfWidth = width >> 1;
811 const GLint extraPixel = (width & 1);
812 for (row = 0; row < height; row++) {
813 GLubyte *d = dst;
814 for (col = 0; col < halfWidth; col++) {
815 const GLuint pixel = ((const GLuint *) src)[col];
816 *d++ = FX_rgb_scale_5[(pixel >> 11) & 0x1f];
817 *d++ = FX_rgb_scale_6[(pixel >> 5) & 0x3f];
818 *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];
822 }
823 if (extraPixel) {
824 GLushort pixel = src[width - 1];
825 *d++ = FX_rgb_scale_5[(pixel >> 11) & 0x1f];
826 *d++ = FX_rgb_scale_6[(pixel >> 5) & 0x3f];
827 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
828 }
829 dst += dstStride;
830 src -= srcStride;
831 }
832 }
833 else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
834 /* convert 5R6G5B into 8R8G8B8A */
835 GLint row, col;
836 const GLint halfWidth = width >> 1;
837 const GLint extraPixel = (width & 1);
838 for (row = 0; row < height; row++) {
839 GLubyte *d = dst;
840 for (col = 0; col < halfWidth; col++) {
841 const GLuint pixel = ((const GLuint *) src)[col];
842 *d++ = FX_rgb_scale_5[(pixel >> 11) & 0x1f];
843 *d++ = FX_rgb_scale_6[(pixel >> 5) & 0x3f];
844 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
845 *d++ = 255;
846 *d++ = FX_rgb_scale_5[(pixel >> 27) & 0x1f];
847 *d++ = FX_rgb_scale_6[(pixel >> 21) & 0x3f];
848 *d++ = FX_rgb_scale_5[(pixel >> 16) & 0x1f];
849 *d++ = 255;
850 }
851 if (extraPixel) {
852 const GLushort pixel = src[width - 1];
853 *d++ = FX_rgb_scale_5[(pixel >> 11) & 0x1f];
854 *d++ = FX_rgb_scale_6[(pixel >> 5) & 0x3f];
855 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
856 *d++ = 255;
857 }
858 dst += dstStride;
859 src -= srcStride;
860 }
861 }
862 else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
863 /* directly memcpy 5R6G5B pixels into client's buffer */
864 const GLint widthInBytes = width * 2;
865 GLint row;
866 for (row = 0; row < height; row++) {
867 MEMCPY(dst, src, widthInBytes);
868 dst += dstStride;
869 src -= srcStride;
870 }
871 }
872 else {
873 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
874 END_BOARD_LOCK();
875 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
876 packing, dstImage);
877 return;
878 }
879
880 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
881 }
882 END_BOARD_LOCK();
883 }
884 }
885
886 static void
887 fxDDReadPixels555 (GLcontext * ctx,
888 GLint x, GLint y,
889 GLsizei width, GLsizei height,
890 GLenum format, GLenum type,
891 const struct gl_pixelstore_attrib *packing,
892 GLvoid *dstImage)
893 {
894 if (ctx->_ImageTransferState/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
895 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
896 packing, dstImage);
897 return;
898 }
899 else {
900 fxMesaContext fxMesa = FX_CONTEXT(ctx);
901 GrLfbInfo_t info;
902
903 BEGIN_BOARD_LOCK();
904 info.size = sizeof(info);
905 if (grLfbLock(GR_LFB_READ_ONLY,
906 fxMesa->currentFB,
907 GR_LFBWRITEMODE_ANY,
908 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
909 const GLint winX = 0;
910 const GLint winY = fxMesa->height - 1;
911 const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
912 const GLushort *src = (const GLushort *) info.lfbPtr
913 + (winY - y) * srcStride + (winX + x);
914 GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage,
915 width, height, format,
916 type, 0, 0, 0);
917 GLint dstStride =
918 _mesa_image_row_stride(packing, width, format, type);
919
920 if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
921 /* convert 5R5G5B into 8R8G8B */
922 GLint row, col;
923 const GLint halfWidth = width >> 1;
924 const GLint extraPixel = (width & 1);
925 for (row = 0; row < height; row++) {
926 GLubyte *d = dst;
927 for (col = 0; col < halfWidth; col++) {
928 const GLuint pixel = ((const GLuint *) src)[col];
929 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
930 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
931 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
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 }
936 if (extraPixel) {
937 GLushort pixel = src[width - 1];
938 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
939 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
940 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
941 }
942 dst += dstStride;
943 src -= srcStride;
944 }
945 }
946 else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
947 /* convert 5R6G5B into 8R8G8B8A */
948 GLint row, col;
949 const GLint halfWidth = width >> 1;
950 const GLint extraPixel = (width & 1);
951 for (row = 0; row < height; row++) {
952 GLubyte *d = dst;
953 for (col = 0; col < halfWidth; col++) {
954 const GLuint pixel = ((const GLuint *) src)[col];
955 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
956 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
957 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
958 *d++ = (pixel & 0x8000) ? 255 : 0;
959 *d++ = FX_rgb_scale_5[(pixel >> 26) & 0x1f];
960 *d++ = FX_rgb_scale_5[(pixel >> 21) & 0x1f];
961 *d++ = FX_rgb_scale_5[(pixel >> 16) & 0x1f];
962 *d++ = (pixel & 0x80000000) ? 255 : 0;
963 }
964 if (extraPixel) {
965 const GLushort pixel = src[width - 1];
966 *d++ = FX_rgb_scale_5[(pixel >> 10) & 0x1f];
967 *d++ = FX_rgb_scale_5[(pixel >> 5) & 0x1f];
968 *d++ = FX_rgb_scale_5[ pixel & 0x1f];
969 *d++ = (pixel & 0x8000) ? 255 : 0;
970 }
971 dst += dstStride;
972 src -= srcStride;
973 }
974 }
975 else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
976 /* directly memcpy 5R5G5B pixels into client's buffer */
977 const GLint widthInBytes = width * 2;
978 GLint row;
979 for (row = 0; row < height; row++) {
980 MEMCPY(dst, src, widthInBytes);
981 dst += dstStride;
982 src -= srcStride;
983 }
984 }
985 else {
986 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
987 END_BOARD_LOCK();
988 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
989 packing, dstImage);
990 return;
991 }
992
993 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
994 }
995 END_BOARD_LOCK();
996 }
997 }
998
999 static void
1000 fxDDReadPixels8888 (GLcontext * ctx,
1001 GLint x, GLint y,
1002 GLsizei width, GLsizei height,
1003 GLenum format, GLenum type,
1004 const struct gl_pixelstore_attrib *packing,
1005 GLvoid *dstImage)
1006 {
1007 if (ctx->_ImageTransferState/* & (IMAGE_SCALE_BIAS_BIT|IMAGE_MAP_COLOR_BIT)*/) {
1008 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
1009 packing, dstImage);
1010 return;
1011 }
1012 else {
1013 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1014 GrLfbInfo_t info;
1015
1016 BEGIN_BOARD_LOCK();
1017 info.size = sizeof(info);
1018 if (grLfbLock(GR_LFB_READ_ONLY,
1019 fxMesa->currentFB,
1020 GR_LFBWRITEMODE_ANY,
1021 GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) {
1022 const GLint winX = 0;
1023 const GLint winY = fxMesa->height - 1;
1024 const GLint srcStride = info.strideInBytes / 4; /* stride in GLuints */
1025 const GLuint *src = (const GLuint *) info.lfbPtr
1026 + (winY - y) * srcStride + (winX + x);
1027 GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage,
1028 width, height, format,
1029 type, 0, 0, 0);
1030 GLint dstStride =
1031 _mesa_image_row_stride(packing, width, format, type);
1032
1033 if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
1034 /* convert 8A8R8G8B into 8R8G8B */
1035 GLint row, col;
1036 for (row = 0; row < height; row++) {
1037 GLubyte *d = dst;
1038 for (col = 0; col < width; col++) {
1039 const GLuint pixel = ((const GLuint *) src)[col];
1040 *d++ = pixel >> 16;
1041 *d++ = pixel >> 8;
1042 *d++ = pixel;
1043 }
1044 dst += dstStride;
1045 src -= srcStride;
1046 }
1047 }
1048 else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
1049 /* 8A8R8G8B pixels into client's buffer */
1050 GLint row, col;
1051 for (row = 0; row < height; row++) {
1052 GLubyte *d = dst;
1053 for (col = 0; col < width; col++) {
1054 const GLuint pixel = ((const GLuint *) src)[col];
1055 *d++ = pixel >> 16;
1056 *d++ = pixel >> 8;
1057 *d++ = pixel;
1058 *d++ = pixel >> 24;
1059 }
1060 dst += dstStride;
1061 src -= srcStride;
1062 }
1063 }
1064 else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
1065 /* convert 8A8R8G8B into 5R6G5B */
1066 GLint row, col;
1067 for (row = 0; row < height; row++) {
1068 GLushort *d = (GLushort *)dst;
1069 for (col = 0; col < width; col++) {
1070 const GLuint pixel = ((const GLuint *) src)[col];
1071 *d++ = (((pixel >> 16) & 0xf8) << 8) |
1072 (((pixel >> 8) & 0xfc) << 3) |
1073 ((pixel & 0xf8) >> 3);
1074 }
1075 dst += dstStride;
1076 src -= srcStride;
1077 }
1078 }
1079 else {
1080 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
1081 END_BOARD_LOCK();
1082 _swrast_ReadPixels(ctx, x, y, width, height, format, type,
1083 packing, dstImage);
1084 return;
1085 }
1086
1087 grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
1088 }
1089 END_BOARD_LOCK();
1090 }
1091 }
1092
1093
1094 /* [dBorca] Hack alert:
1095 * not finished!!!
1096 * revise fallback tests and fix scissor; implement new formats
1097 * also write its siblings: 565 and 1555
1098 */
1099 void
1100 fxDDDrawPixels8888 (GLcontext * ctx, GLint x, GLint y,
1101 GLsizei width, GLsizei height,
1102 GLenum format, GLenum type,
1103 const struct gl_pixelstore_attrib *unpack,
1104 const GLvoid * pixels)
1105 {
1106 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1107 GrLfbInfo_t info;
1108
1109 if (ctx->Pixel.ZoomX != 1.0F ||
1110 ctx->Pixel.ZoomY != 1.0F ||
1111 (ctx->_ImageTransferState & (IMAGE_SCALE_BIAS_BIT|
1112 IMAGE_MAP_COLOR_BIT)) ||
1113 /*ctx->Color.AlphaEnabled ||*/
1114 ctx->Depth.Test ||
1115 ctx->Fog.Enabled ||
1116 ctx->Scissor.Enabled ||
1117 ctx->Stencil.Enabled ||
1118 /*!ctx->Color.ColorMask[0] ||
1119 !ctx->Color.ColorMask[1] ||
1120 !ctx->Color.ColorMask[2] ||
1121 !ctx->Color.ColorMask[3] ||*/
1122 ctx->Color.ColorLogicOpEnabled ||
1123 ctx->Texture._EnabledUnits ||
1124 ctx->Depth.OcclusionTest ||
1125 fxMesa->fallback)
1126 {
1127 _swrast_DrawPixels( ctx, x, y, width, height, format, type,
1128 unpack, pixels );
1129 return;
1130 }
1131
1132 /* lock early to make sure cliprects are right */
1133 BEGIN_BOARD_LOCK();
1134
1135 /* make sure the pixelpipe is configured correctly */
1136 fxSetupFXUnits(ctx);
1137
1138 /* look for clipmasks, giveup if region obscured */
1139 #if 0
1140 if (ctx->Color.DrawBuffer == GL_FRONT) {
1141 if (!inClipRects_Region(fxMesa, scrX, scrY, width, height)) {
1142 END_BOARD_LOCK(fxMesa);
1143 _swrast_DrawPixels(ctx, x, y, width, height, format, type, unpack, pixels);
1144 return;
1145 }
1146 }
1147 #endif
1148
1149 info.size = sizeof(info);
1150 if (!grLfbLock(GR_LFB_WRITE_ONLY,
1151 fxMesa->currentFB,
1152 GR_LFBWRITEMODE_8888,
1153 GR_ORIGIN_LOWER_LEFT, FXTRUE, &info)) {
1154 _swrast_DrawPixels(ctx, x, y, width, height, format, type, unpack, pixels);
1155 return;
1156 }
1157
1158 {
1159 const GLint winX = 0;
1160 const GLint winY = 0;
1161
1162 const GLint dstStride = info.strideInBytes / 4; /* stride in GLuints */
1163 GLuint *dst = (GLuint *) info.lfbPtr + (winY + y) * dstStride + (winX + x);
1164 const GLubyte *src = (GLubyte *)_mesa_image_address(unpack, pixels,
1165 width, height, format,
1166 type, 0, 0, 0);
1167 const GLint srcStride = _mesa_image_row_stride(unpack, width, format, type);
1168
1169 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
1170 /* directly memcpy 8A8R8G8B pixels to screen */
1171 const GLint widthInBytes = width * 4;
1172 GLint row;
1173 for (row = 0; row < height; row++) {
1174 MEMCPY(dst, src, widthInBytes);
1175 dst += dstStride;
1176 src += srcStride;
1177 }
1178 }
1179 else {
1180 grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB);
1181 END_BOARD_LOCK();
1182 _swrast_DrawPixels(ctx, x, y, width, height, format, type, unpack, pixels);
1183 return;
1184 }
1185
1186 }
1187
1188 grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB);
1189 END_BOARD_LOCK();
1190 }
1191
1192
1193 static void
1194 fxDDFinish(GLcontext * ctx)
1195 {
1196 grFlush();
1197 }
1198
1199
1200
1201
1202
1203 /* KW: Put the word Mesa in the render string because quakeworld
1204 * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE).
1205 * Why?
1206 */
1207 static const GLubyte *
1208 fxDDGetString(GLcontext * ctx, GLenum name)
1209 {
1210 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1211
1212 switch (name) {
1213 case GL_RENDERER:
1214 return (GLubyte *)fxMesa->rendererString;
1215 #if __WIN32__ /* hack to advertise vanilla extension names */
1216 case GL_EXTENSIONS:
1217 if (ctx->Extensions.String == NULL) {
1218 GLubyte *ext = _mesa_make_extension_string(ctx);
1219 if (ext != NULL) {
1220 ctx->Extensions.String = _mesa_malloc(strlen((char *)ext) + 256);
1221 if (ctx->Extensions.String != NULL) {
1222 strcpy((char *)ctx->Extensions.String, (char *)ext);
1223 /* put any additional extension names here */
1224 #if 0
1225 strcat((char *)ctx->Extensions.String, " 3DFX_set_global_palette");
1226 #endif
1227 #if __WIN32__
1228 strcat((char *)ctx->Extensions.String, " WGL_3DFX_gamma_control");
1229 strcat((char *)ctx->Extensions.String, " WGL_EXT_swap_control");
1230 strcat((char *)ctx->Extensions.String, " WGL_EXT_extensions_string WGL_ARB_extensions_string");
1231 #endif
1232 /* put any additional extension names here */
1233 _mesa_free(ext);
1234 } else {
1235 ctx->Extensions.String = ext;
1236 }
1237 }
1238 }
1239 return ctx->Extensions.String;
1240 #endif
1241 default:
1242 return NULL;
1243 }
1244 }
1245
1246 static const struct tnl_pipeline_stage *fx_pipeline[] = {
1247 &_tnl_vertex_transform_stage, /* TODO: Add the fastpath here */
1248 &_tnl_normal_transform_stage,
1249 &_tnl_lighting_stage,
1250 &_tnl_fog_coordinate_stage,
1251 &_tnl_texgen_stage,
1252 &_tnl_texture_transform_stage,
1253 &_tnl_point_attenuation_stage,
1254 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
1255 &_tnl_vertex_program_stage,
1256 #endif
1257 &_tnl_render_stage,
1258 0,
1259 };
1260
1261
1262
1263
1264 int
1265 fxDDInitFxMesaContext(fxMesaContext fxMesa)
1266 {
1267 int i;
1268 GLcontext *ctx = fxMesa->glCtx;
1269
1270 FX_setupGrVertexLayout();
1271
1272 fxMesa->color = 0xffffffff;
1273 fxMesa->clearC = 0;
1274 fxMesa->clearA = 0;
1275
1276 fxMesa->stats.swapBuffer = 0;
1277 fxMesa->stats.reqTexUpload = 0;
1278 fxMesa->stats.texUpload = 0;
1279 fxMesa->stats.memTexUpload = 0;
1280
1281 fxMesa->tmuSrc = FX_TMU_NONE;
1282 fxMesa->lastUnitsMode = FX_UM_NONE;
1283 fxTMInit(fxMesa);
1284
1285 /* FX units setup */
1286
1287 fxMesa->unitsState.alphaTestEnabled = GL_FALSE;
1288 fxMesa->unitsState.alphaTestFunc = GL_ALWAYS;
1289 fxMesa->unitsState.alphaTestRefValue = 0.0;
1290
1291 fxMesa->unitsState.blendEnabled = GL_FALSE;
1292 fxMesa->unitsState.blendSrcFuncRGB = GR_BLEND_ONE;
1293 fxMesa->unitsState.blendDstFuncRGB = GR_BLEND_ZERO;
1294 fxMesa->unitsState.blendSrcFuncAlpha = GR_BLEND_ONE;
1295 fxMesa->unitsState.blendDstFuncAlpha = GR_BLEND_ZERO;
1296 fxMesa->unitsState.blendEqRGB = GR_BLEND_OP_ADD;
1297 fxMesa->unitsState.blendEqAlpha = GR_BLEND_OP_ADD;
1298
1299 fxMesa->unitsState.depthTestEnabled = GL_FALSE;
1300 fxMesa->unitsState.depthMask = GL_TRUE;
1301 fxMesa->unitsState.depthTestFunc = GL_LESS;
1302 fxMesa->unitsState.depthBias = 0;
1303
1304 fxMesa->unitsState.stencilWriteMask = 0xff;
1305
1306 if (fxMesa->colDepth == 32) {
1307 /* 32bpp */
1308 fxMesa->Glide.grColorMaskExt(FXTRUE, FXTRUE, FXTRUE, fxMesa->haveHwAlpha);
1309 } else {
1310 /* 15/16 bpp mode */
1311 grColorMask(FXTRUE, fxMesa->haveHwAlpha);
1312 }
1313
1314 fxMesa->currentFB = fxMesa->haveDoubleBuffer ? GR_BUFFER_BACKBUFFER : GR_BUFFER_FRONTBUFFER;
1315 grRenderBuffer(fxMesa->currentFB);
1316
1317 fxMesa->state = MALLOC(FX_grGetInteger(GR_GLIDE_STATE_SIZE));
1318 fxMesa->fogTable = (GrFog_t *) MALLOC(FX_grGetInteger(GR_FOG_TABLE_ENTRIES) *
1319 sizeof(GrFog_t));
1320
1321 if (!fxMesa->state || !fxMesa->fogTable) {
1322 if (fxMesa->state)
1323 FREE(fxMesa->state);
1324 if (fxMesa->fogTable)
1325 FREE(fxMesa->fogTable);
1326 return 0;
1327 }
1328
1329 /* [dBorca] Hack alert:
1330 * Unlike the rest of the Voodoo family, the Rush
1331 * doesn't support ZBUFFER with WBUFFER-like depth functions!
1332 * I guess we could use WBUFFER, which is better, but we can't
1333 * because the depth span functions would need to translate
1334 * depth values to 4.12 floating point...
1335 */
1336 if (fxMesa->haveZBuffer) {
1337 grDepthBufferMode((fxMesa->type == GR_SSTTYPE_SST96)
1338 ? GR_DEPTHBUFFER_WBUFFER
1339 : GR_DEPTHBUFFER_ZBUFFER);
1340 }
1341
1342 if (!fxMesa->bgrOrder) {
1343 grLfbWriteColorFormat(GR_COLORFORMAT_ABGR);
1344 }
1345
1346 if (fxMesa->Glide.grSetNumPendingBuffers != NULL) {
1347 fxMesa->Glide.grSetNumPendingBuffers(fxMesa->maxPendingSwapBuffers);
1348 }
1349
1350 fxMesa->textureAlign = FX_grGetInteger(GR_TEXTURE_ALIGN);
1351 /* [koolsmoky] */
1352 {
1353 char *env;
1354 int textureLevels = 0;
1355 int textureSize = FX_grGetInteger(GR_MAX_TEXTURE_SIZE);
1356 do {
1357 textureLevels++;
1358 } while ((textureSize >>= 0x1) & 0x7ff);
1359 ctx->Const.MaxTextureLevels = textureLevels;
1360 ctx->Const.MaxTextureLodBias = /*textureLevels - 1*/8; /* Glide bug */
1361 #if FX_RESCALE_BIG_TEXURES_HACK
1362 fxMesa->textureMaxLod = textureLevels - 1;
1363 if ((env = getenv("MESA_FX_MAXLOD")) != NULL) {
1364 int maxLevels = atoi(env) + 1;
1365 if ((maxLevels <= MAX_TEXTURE_LEVELS) && (maxLevels > textureLevels)) {
1366 ctx->Const.MaxTextureLevels = maxLevels;
1367 }
1368 }
1369 #endif
1370 }
1371 ctx->Const.MaxTextureCoordUnits =
1372 ctx->Const.MaxTextureImageUnits = fxMesa->haveTwoTMUs ? 2 : 1;
1373 ctx->Const.MaxTextureUnits = MAX2(ctx->Const.MaxTextureImageUnits, ctx->Const.MaxTextureCoordUnits);
1374
1375 fxMesa->new_state = _NEW_ALL;
1376 if (!fxMesa->haveHwStencil) {
1377 /* don't touch stencil if there is none */
1378 fxMesa->new_state &= ~FX_NEW_STENCIL;
1379 }
1380
1381 /* Initialize the software rasterizer and helper modules.
1382 */
1383 _swrast_CreateContext(ctx);
1384 _ac_CreateContext(ctx);
1385 _tnl_CreateContext(ctx);
1386 _swsetup_CreateContext(ctx);
1387
1388 /* Install customized pipeline */
1389 _tnl_destroy_pipeline(ctx);
1390 _tnl_install_pipeline(ctx, fx_pipeline);
1391
1392 fxAllocVB(ctx);
1393
1394 fxSetupDDPointers(ctx);
1395 fxDDInitTriFuncs(ctx);
1396
1397 /* Tell the software rasterizer to use pixel fog always.
1398 */
1399 _swrast_allow_vertex_fog(ctx, GL_FALSE);
1400 _swrast_allow_pixel_fog(ctx, GL_TRUE);
1401 _tnl_allow_vertex_fog( ctx, GL_FALSE );
1402 _tnl_allow_pixel_fog( ctx, GL_TRUE );
1403
1404 /* Tell tnl not to calculate or use vertex fog factors. (Needed to
1405 * tell render stage not to clip fog coords).
1406 */
1407 /* _tnl_calculate_vertex_fog( ctx, GL_FALSE ); */
1408
1409 fxDDInitExtensions(ctx);
1410
1411 #if 0
1412 /* [dBorca] Hack alert:
1413 * do we want dither? It just looks bad...
1414 */
1415 grEnable(GR_ALLOW_MIPMAP_DITHER);
1416 grTexNccTable(GR_NCCTABLE_NCC0); /* set this once... no multipass */
1417 #endif
1418 grGlideGetState((GrState *) fxMesa->state);
1419
1420 return 1;
1421 }
1422
1423 /* Undo the above.
1424 */
1425 void
1426 fxDDDestroyFxMesaContext(fxMesaContext fxMesa)
1427 {
1428 _swsetup_DestroyContext(fxMesa->glCtx);
1429 _tnl_DestroyContext(fxMesa->glCtx);
1430 _ac_DestroyContext(fxMesa->glCtx);
1431 _swrast_DestroyContext(fxMesa->glCtx);
1432
1433 if (fxMesa->state)
1434 FREE(fxMesa->state);
1435 if (fxMesa->fogTable)
1436 FREE(fxMesa->fogTable);
1437 fxFreeVB(fxMesa->glCtx);
1438 }
1439
1440
1441
1442
1443 void
1444 fxDDInitExtensions(GLcontext * ctx)
1445 {
1446 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1447
1448 #if 1 /* multipass ColorSum stage */
1449 _mesa_enable_extension(ctx, "GL_EXT_secondary_color");
1450 #endif
1451
1452 _mesa_enable_extension(ctx, "GL_ARB_point_sprite");
1453 _mesa_enable_extension(ctx, "GL_EXT_point_parameters");
1454 _mesa_enable_extension(ctx, "GL_EXT_paletted_texture");
1455 _mesa_enable_extension(ctx, "GL_EXT_texture_lod_bias");
1456 _mesa_enable_extension(ctx, "GL_EXT_shared_texture_palette");
1457 _mesa_enable_extension(ctx, "GL_EXT_blend_func_separate");
1458 _mesa_enable_extension(ctx, "GL_EXT_texture_env_add");
1459
1460 if (fxMesa->haveTwoTMUs) {
1461 _mesa_enable_extension(ctx, "GL_ARB_multitexture");
1462 }
1463
1464 if (fxMesa->haveHwStencil) {
1465 _mesa_enable_extension( ctx, "GL_EXT_stencil_wrap" );
1466 }
1467
1468 /* [dBorca] Hack alert:
1469 * True texture compression can be done only on Napalm.
1470 * We will advertise, however, generic texture compression
1471 * on all Voodoo cards; the Mesa logic allows us to eventually
1472 * fallback to uncompressed. This will fix those dumb applications
1473 * which refuse to run w/o texture compression! We actually _can_
1474 * do texture compression for pre-Napalm cores, through NCC. But
1475 * NCC poses many issues:
1476 * 1) NCC w/o DITHER_ERR has poor quality and NCC w/ DITHER_ERR is
1477 * damn slow!
1478 * 2) NCC compression cannot be used with multitexturing, because
1479 * the decompression tables are not per TMU anymore (bear in mind
1480 * that earlier Voodoos could handle 2 NCC tables for each TMU --
1481 * just look for POINTCAST_PALETTE). As a last resort, we could
1482 * fake NCC multitexturing through multipass rendering, but...
1483 * ohwell, it's not worth the effort...
1484 * This stand true for multitexturing palletized textures.
1485 * 3) since NCC is not an OpenGL standard (as opposed to FXT1/DXTC), we
1486 * can't use precompressed textures!
1487 */
1488 if (fxMesa->type >= GR_SSTTYPE_Voodoo4) {
1489 _mesa_enable_extension(ctx, "GL_ARB_texture_compression");
1490 _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
1491 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
1492 _mesa_enable_extension(ctx, "GL_S3_s3tc");
1493 _mesa_enable_extension(ctx, "GL_NV_blend_square");
1494 } else {
1495 if (fxMesa->HaveTexus2) {
1496 _mesa_enable_extension(ctx, "GL_ARB_texture_compression");
1497 }
1498 #if FX_TC_NCC
1499 else
1500 #endif
1501 /* doesn't like texture compression */
1502 _mesa_enable_extension(ctx, "GL_SGIS_generate_mipmap");
1503 }
1504
1505 if (fxMesa->HaveCmbExt) {
1506 _mesa_enable_extension(ctx, "GL_EXT_texture_env_combine");
1507 }
1508
1509 if (fxMesa->HavePixExt) {
1510 _mesa_enable_extension(ctx, "GL_EXT_blend_subtract");
1511 _mesa_enable_extension(ctx, "GL_EXT_blend_equation_separate");
1512 }
1513
1514 if (fxMesa->HaveMirExt) {
1515 _mesa_enable_extension(ctx, "GL_ARB_texture_mirrored_repeat");
1516 }
1517
1518 if (fxMesa->type >= GR_SSTTYPE_Voodoo2) {
1519 _mesa_enable_extension(ctx, "GL_EXT_fog_coord");
1520 }
1521
1522 /* core-level extensions */
1523 _mesa_enable_extension(ctx, "GL_EXT_multi_draw_arrays");
1524 _mesa_enable_extension(ctx, "GL_IBM_multimode_draw_arrays");
1525 _mesa_enable_extension(ctx, "GL_ARB_vertex_buffer_object");
1526 #if 1
1527 /* not just yet */
1528 _mesa_enable_extension(ctx, "GL_ARB_vertex_program");
1529 _mesa_enable_extension(ctx, "GL_NV_vertex_program");
1530 _mesa_enable_extension(ctx, "GL_NV_vertex_program1_1");
1531 _mesa_enable_extension(ctx, "GL_MESA_program_debug");
1532 #endif
1533 }
1534
1535
1536 /************************************************************************/
1537 /************************************************************************/
1538 /************************************************************************/
1539
1540 /* Check if the hardware supports the current context
1541 *
1542 * Performs similar work to fxDDChooseRenderState() - should be merged.
1543 */
1544 GLuint
1545 fx_check_IsInHardware(GLcontext * ctx)
1546 {
1547 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1548
1549 if (ctx->RenderMode != GL_RENDER) {
1550 return FX_FALLBACK_RENDER_MODE;
1551 }
1552
1553 if (ctx->Stencil.Enabled && !fxMesa->haveHwStencil) {
1554 return FX_FALLBACK_STENCIL;
1555 }
1556
1557 if (ctx->Color._DrawDestMask != DD_FRONT_LEFT_BIT &&
1558 ctx->Color._DrawDestMask != DD_BACK_LEFT_BIT) {
1559 return FX_FALLBACK_DRAW_BUFFER;
1560 }
1561
1562 if (ctx->Color.BlendEnabled) {
1563 if (ctx->Color.BlendEquationRGB != GL_FUNC_ADD) {
1564 if (!fxMesa->HavePixExt ||
1565 ((ctx->Color.BlendEquationRGB != GL_FUNC_SUBTRACT) &&
1566 (ctx->Color.BlendEquationRGB != GL_FUNC_REVERSE_SUBTRACT))) {
1567 return FX_FALLBACK_BLEND;
1568 }
1569 }
1570
1571 if (ctx->Color.BlendEquationA != GL_FUNC_ADD) {
1572 if (!fxMesa->HavePixExt ||
1573 ((ctx->Color.BlendEquationA != GL_FUNC_SUBTRACT) &&
1574 (ctx->Color.BlendEquationA != GL_FUNC_REVERSE_SUBTRACT))) {
1575 return FX_FALLBACK_BLEND;
1576 }
1577 }
1578
1579 #if 0
1580 /* [dBorca]
1581 * We fail the spec here, unless certain blending modes:
1582 * (c1 + c2) * 1 + d * 1 = c1 * 1 + d * 1 + c2 * 1
1583 * (c1 + c2) * 1 + d * 0 = c1 * 1 + d * 0 + c2 * 1
1584 */
1585 if (NEED_SECONDARY_COLOR(ctx)) {
1586 if ((ctx->Color.BlendEquationRGB != GL_FUNC_ADD) &&
1587 (ctx->Color.BlendSrcRGB != GL_ONE)) {
1588 /* Can't use multipass to blend ColorSum stage */
1589 return FX_FALLBACK_SPECULAR;
1590 }
1591 }
1592 #endif
1593 }
1594
1595 /* [dBorca]
1596 * We could avoid this for certain `sfactor/dfactor'
1597 * I do not think that is even worthwhile to check
1598 * because if someone is using blending they use more
1599 * interesting settings and also it would add more
1600 * state tracking to a lot of the code.
1601 */
1602 if (ctx->Color.ColorLogicOpEnabled && (ctx->Color.LogicOp != GL_COPY)) {
1603 return FX_FALLBACK_LOGICOP;
1604 }
1605
1606 if ((fxMesa->colDepth != 32) &&
1607 ((ctx->Color.ColorMask[RCOMP] != ctx->Color.ColorMask[GCOMP]) ||
1608 (ctx->Color.ColorMask[GCOMP] != ctx->Color.ColorMask[BCOMP]))) {
1609 return FX_FALLBACK_COLORMASK;
1610 }
1611
1612 /* Unsupported texture/multitexture cases */
1613
1614 /* we can only do 1D/2D textures */
1615 if (ctx->Texture.Unit[0]._ReallyEnabled & ~(TEXTURE_1D_BIT|TEXTURE_2D_BIT))
1616 return FX_FALLBACK_TEXTURE_MAP;
1617
1618 if (fxMesa->haveTwoTMUs) {
1619 if (ctx->Texture.Unit[1]._ReallyEnabled & ~(TEXTURE_1D_BIT|TEXTURE_2D_BIT))
1620 return FX_FALLBACK_TEXTURE_MAP;
1621
1622 if (ctx->Texture.Unit[0]._ReallyEnabled) {
1623 if (fxMesa->type < GR_SSTTYPE_Voodoo2)
1624 if (ctx->Texture.Unit[0].EnvMode == GL_BLEND &&
1625 (ctx->Texture.Unit[1]._ReallyEnabled ||
1626 ctx->Texture.Unit[0].EnvColor[0] != 0 ||
1627 ctx->Texture.Unit[0].EnvColor[1] != 0 ||
1628 ctx->Texture.Unit[0].EnvColor[2] != 0 ||
1629 ctx->Texture.Unit[0].EnvColor[3] != 1)) {
1630 return FX_FALLBACK_TEXTURE_ENV;
1631 }
1632 if (ctx->Texture.Unit[0]._Current->Image[0][0]->Border > 0)
1633 return FX_FALLBACK_TEXTURE_BORDER;
1634 }
1635
1636 if (ctx->Texture.Unit[1]._ReallyEnabled) {
1637 if (fxMesa->type < GR_SSTTYPE_Voodoo2)
1638 if (ctx->Texture.Unit[1].EnvMode == GL_BLEND)
1639 return FX_FALLBACK_TEXTURE_ENV;
1640 if (ctx->Texture.Unit[1]._Current->Image[0][0]->Border > 0)
1641 return FX_FALLBACK_TEXTURE_BORDER;
1642 }
1643
1644 if (TDFX_DEBUG & (VERBOSE_DRIVER | VERBOSE_TEXTURE))
1645 fprintf(stderr, "fx_check_IsInHardware: envmode is %s/%s\n",
1646 _mesa_lookup_enum_by_nr(ctx->Texture.Unit[0].EnvMode),
1647 _mesa_lookup_enum_by_nr(ctx->Texture.Unit[1].EnvMode));
1648
1649 /* KW: This was wrong (I think) and I changed it... which doesn't mean
1650 * it is now correct...
1651 * BP: The old condition just seemed to test if both texture units
1652 * were enabled. That's easy!
1653 */
1654 if (ctx->Texture._EnabledUnits == 0x3) {
1655 /* Can't use multipass to blend a multitextured triangle - fall
1656 * back to software.
1657 * [dBorca] we hit this case only when we try to emulate
1658 * multitexture by multipass!
1659 */
1660 if (!fxMesa->haveTwoTMUs && ctx->Color.BlendEnabled) {
1661 return FX_FALLBACK_TEXTURE_MULTI;
1662 }
1663
1664 if ((ctx->Texture.Unit[0].EnvMode != ctx->Texture.Unit[1].EnvMode) &&
1665 (ctx->Texture.Unit[0].EnvMode != GL_MODULATE) &&
1666 (ctx->Texture.Unit[0].EnvMode != GL_REPLACE)) { /* q2, seems ok... */
1667 if (TDFX_DEBUG & VERBOSE_DRIVER)
1668 fprintf(stderr, "fx_check_IsInHardware: unsupported multitex env mode\n");
1669 return FX_FALLBACK_TEXTURE_MULTI;
1670 }
1671 }
1672 }
1673 else {
1674 /* we have just one texture unit */
1675 if (ctx->Texture._EnabledUnits > 0x1) {
1676 return FX_FALLBACK_TEXTURE_MULTI;
1677 }
1678
1679 if (fxMesa->type < GR_SSTTYPE_Voodoo2)
1680 if (ctx->Texture.Unit[0]._ReallyEnabled &&
1681 (ctx->Texture.Unit[0].EnvMode == GL_BLEND)) {
1682 return FX_FALLBACK_TEXTURE_ENV;
1683 }
1684 }
1685
1686 return 0;
1687 }
1688
1689
1690
1691 static void
1692 fxDDUpdateDDPointers(GLcontext * ctx, GLuint new_state)
1693 {
1694 /* TNLcontext *tnl = TNL_CONTEXT(ctx);*/
1695 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1696
1697 if (TDFX_DEBUG & VERBOSE_DRIVER) {
1698 fprintf(stderr, "fxDDUpdateDDPointers(%08x)\n", new_state);
1699 }
1700
1701 _swrast_InvalidateState(ctx, new_state);
1702 _ac_InvalidateState(ctx, new_state);
1703 _tnl_InvalidateState(ctx, new_state);
1704 _swsetup_InvalidateState(ctx, new_state);
1705
1706 fxMesa->new_gl_state |= new_state;
1707 }
1708
1709
1710
1711
1712 void
1713 fxSetupDDPointers(GLcontext * ctx)
1714 {
1715 fxMesaContext fxMesa = FX_CONTEXT(ctx);
1716 TNLcontext *tnl = TNL_CONTEXT(ctx);
1717
1718 if (TDFX_DEBUG & VERBOSE_DRIVER) {
1719 fprintf(stderr, "fxSetupDDPointers()\n");
1720 }
1721
1722 ctx->Driver.UpdateState = fxDDUpdateDDPointers;
1723 ctx->Driver.GetString = fxDDGetString;
1724 ctx->Driver.ClearIndex = NULL;
1725 ctx->Driver.ClearColor = fxDDClearColor;
1726 ctx->Driver.Clear = fxDDClear;
1727 ctx->Driver.DrawBuffer = fxDDSetDrawBuffer;
1728 ctx->Driver.GetBufferSize = fxDDBufferSize;
1729 switch (fxMesa->colDepth) {
1730 case 15:
1731 ctx->Driver.ReadPixels = fxDDReadPixels555;
1732 ctx->Driver.Bitmap = fxDDDrawBitmap2;
1733 break;
1734 case 16:
1735 ctx->Driver.ReadPixels = fxDDReadPixels565;
1736 ctx->Driver.Bitmap = fxDDDrawBitmap2;
1737 break;
1738 case 32:
1739 ctx->Driver.DrawPixels = fxDDDrawPixels8888;
1740 ctx->Driver.ReadPixels = fxDDReadPixels8888;
1741 ctx->Driver.Bitmap = fxDDDrawBitmap4;
1742 break;
1743 }
1744 ctx->Driver.Finish = fxDDFinish;
1745 ctx->Driver.Flush = NULL;
1746 ctx->Driver.ChooseTextureFormat = fxDDChooseTextureFormat;
1747 ctx->Driver.TexImage1D = fxDDTexImage1D;
1748 ctx->Driver.TexImage2D = fxDDTexImage2D;
1749 ctx->Driver.TexSubImage1D = fxDDTexSubImage1D;
1750 ctx->Driver.TexSubImage2D = fxDDTexSubImage2D;
1751 ctx->Driver.CompressedTexImage2D = fxDDCompressedTexImage2D;
1752 ctx->Driver.CompressedTexSubImage2D = fxDDCompressedTexSubImage2D;
1753 ctx->Driver.TestProxyTexImage = fxDDTestProxyTexImage;
1754 ctx->Driver.TexEnv = fxDDTexEnv;
1755 ctx->Driver.TexParameter = fxDDTexParam;
1756 ctx->Driver.BindTexture = fxDDTexBind;
1757 ctx->Driver.DeleteTexture = fxDDTexDel;
1758 ctx->Driver.IsTextureResident = fxDDIsTextureResident;
1759 ctx->Driver.UpdateTexturePalette = fxDDTexPalette;
1760 ctx->Driver.AlphaFunc = fxDDAlphaFunc;
1761 ctx->Driver.BlendFuncSeparate = fxDDBlendFuncSeparate;
1762 ctx->Driver.BlendEquationSeparate = fxDDBlendEquationSeparate;
1763 ctx->Driver.DepthFunc = fxDDDepthFunc;
1764 ctx->Driver.DepthMask = fxDDDepthMask;
1765 ctx->Driver.ColorMask = fxDDColorMask;
1766 ctx->Driver.Fogfv = fxDDFogfv;
1767 ctx->Driver.Scissor = fxDDScissor;
1768 ctx->Driver.FrontFace = fxDDFrontFace;
1769 ctx->Driver.CullFace = fxDDCullFace;
1770 ctx->Driver.ShadeModel = fxDDShadeModel;
1771 ctx->Driver.Enable = fxDDEnable;
1772 if (fxMesa->haveHwStencil) {
1773 ctx->Driver.StencilFunc = fxDDStencilFunc;
1774 ctx->Driver.StencilMask = fxDDStencilMask;
1775 ctx->Driver.StencilOp = fxDDStencilOp;
1776 }
1777
1778 fxSetupDDSpanPointers(ctx);
1779 fxDDUpdateDDPointers(ctx, ~0);
1780 }
1781
1782
1783 #else
1784
1785
1786 /*
1787 * Need this to provide at least one external definition.
1788 */
1789
1790 extern int gl_fx_dummy_function_dd(void);
1791 int
1792 gl_fx_dummy_function_dd(void)
1793 {
1794 return 0;
1795 }
1796
1797 #endif /* FX */