summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.c
blob: c88d7ca3f5ca8706e01103e5e267a40f9e141e4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxglidew.c,v 1.1 2000/09/24 13:51:15 alanh Exp $ */
/*
 * Mesa 3-D graphics library
 * Version:  3.3
 *
 * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *
 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
 * terms stated above.
 *
 * Thank you for your contribution, David!
 *
 * Please make note of the above copyright/license statement.  If you
 * contributed code or bug fixes to this code under the previous (GNU
 * Library) license and object to the new license, your code will be
 * removed at your request.  Please see the Mesa docs/COPYRIGHT file
 * for more information.
 *
 * Additional Mesa/3Dfx driver developers:
 *   Daryll Strauss <daryll@precisioninsight.com>
 *   Keith Whitwell <keith@precisioninsight.com>
 *
 * See fxapi.h for more revision/author details.
 */


#include <stdlib.h>
#include <string.h>
#include "glide.h"
#include "fxdrv.h"
#include "fxglidew.h"


grStencilFunc_t grStencilFuncPtr = NULL;
grStencilMask_t grStencilMaskPtr = NULL;
grStencilOp_t grStencilOpPtr = NULL;
grBufferClearExt_t grBufferClearExtPtr = NULL;
grColorMaskExt_t grColorMaskExtPtr = NULL;
txImgQuantize_t  txImgQuantizePtr = NULL;
txImgDeQuantize_t txImgDequantizeFXT1Ptr = NULL;
txErrorSetCallback_t txErrorSetCallbackPtr = NULL;

FxI32
FX_grGetInteger_NoLock(FxU32 pname)
{
    switch (pname) {
    case FX_FOG_TABLE_ENTRIES:
    case FX_GLIDE_STATE_SIZE:
    case FX_LFB_PIXEL_PIPE:
    case FX_PENDING_BUFFERSWAPS:
    case FX_TEXTURE_ALIGN:
    case GR_STATS_PIXELS_DEPTHFUNC_FAIL:
    case GR_STATS_PIXELS_IN:
    case GR_STATS_PIXELS_OUT:
        {
            FxI32 result;
            FxU32 grname = pname;
            grGet(grname, 4, &result);
            return result;
        }
    case FX_ZDEPTH_MAX:
        {
            FxI32 zvals[2];
            grGet(GR_ZDEPTH_MIN_MAX, 8, zvals);
            return zvals[0];
        }
    default:
        if (MESA_VERBOSE & VERBOSE_DRIVER) {
            fprintf(stderr, "Wrong parameter in FX_grGetInteger!\n");
        }
    }

    return 0;
}


FxI32
FX_grGetInteger(fxMesaContext fxMesa, FxU32 pname)
{
    int result;
    BEGIN_BOARD_LOCK(fxMesa);
    result = FX_grGetInteger_NoLock(pname);
    END_BOARD_LOCK(fxMesa);
    return result;
}


const char *
FX_grGetString(fxMesaContext fxMesa, FxU32 pname)
{
    const char *s;
    BEGIN_BOARD_LOCK(fxMesa);
    s = grGetString(pname);
    END_BOARD_LOCK(fxMesa);
    return s;
}



/* Wrapper for grColorMask() and grColorMaskExt().
 */
void
FX_grColorMask(GLcontext *ctx, GLboolean r, GLboolean g,
               GLboolean b, GLboolean a)
{
    fxMesaContext fxMesa = FX_CONTEXT(ctx);
    BEGIN_BOARD_LOCK(fxMesa);
    if (ctx->Visual->RedBits == 8) {
        /* 32bpp mode */
        ASSERT(grColorMaskExtPtr);
        (*grColorMaskExtPtr)(r, g, b, a);
    }
    else {
        /* 16 bpp mode */
        /* we never have an alpha buffer */
        grColorMask(r || g || b, GL_FALSE);
    }
    END_BOARD_LOCK(fxMesa);
}


/* As above, but pass the mask as an array
 */
void
FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4])
{
    fxMesaContext fxMesa = FX_CONTEXT(ctx);
    BEGIN_BOARD_LOCK(fxMesa);
    if (ctx->Visual->RedBits == 8) {
        /* 32bpp mode */
        ASSERT(grColorMaskExtPtr);
        (*grColorMaskExtPtr)(rgba[RCOMP], rgba[GCOMP],
                             rgba[BCOMP], rgba[ACOMP]);
    }
    else {
        /* 16 bpp mode */
        /* we never have an alpha buffer */
        grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP], GL_FALSE);
    }
    END_BOARD_LOCK(fxMesa);
}



FxBool
FX_grLfbLock(fxMesaContext fxMesa, GrLock_t type, GrBuffer_t buffer,
             GrLfbWriteMode_t writeMode, GrOriginLocation_t origin,
             FxBool pixelPipeline, GrLfbInfo_t * info)
{
    FxBool result;

    BEGIN_BOARD_LOCK(fxMesa);
    result = grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info);
    END_BOARD_LOCK(fxMesa);
    return result;
}

FxU32
FX_grTexTextureMemRequired(fxMesaContext fxMesa, FxU32 evenOdd, GrTexInfo * info)
{
    FxU32 result;

    BEGIN_BOARD_LOCK(fxMesa);
    result = grTexTextureMemRequired(evenOdd, info);
    END_BOARD_LOCK(fxMesa);
    return result;
}

FxU32
FX_grTexMinAddress(fxMesaContext fxMesa, GrChipID_t tmu)
{
    FxU32 result;

    BEGIN_BOARD_LOCK(fxMesa);
    result = grTexMinAddress(tmu);
    END_BOARD_LOCK(fxMesa);
    return result;
}

extern FxU32
FX_grTexMaxAddress(fxMesaContext fxMesa, GrChipID_t tmu)
{
    FxU32 result;

    BEGIN_BOARD_LOCK(fxMesa);
    result = grTexMaxAddress(tmu);
    END_BOARD_LOCK(fxMesa);
    return result;
}


#if defined(FX_GLIDE3)

void
FX_grGammaCorrectionValue(float val)
{
    (void) val;
/* ToDo */
}

int
FX_getFogTableSize(fxMesaContext fxMesa)
{
    int result;
    BEGIN_BOARD_LOCK(fxMesa);
    grGet(GR_FOG_TABLE_ENTRIES, sizeof(int), (void *) &result);
    END_BOARD_LOCK(fxMesa);
    return result;
}

int
FX_getGrStateSize(fxMesaContext fxMesa)
{
    int result;
    BEGIN_BOARD_LOCK(fxMesa);
    grGet(GR_GLIDE_STATE_SIZE, sizeof(int), (void *) &result);
    END_BOARD_LOCK(fxMesa);
    return result;
}


void
FX_grGlideGetVersion(fxMesaContext fxMesa, char *buf)
{
    BEGIN_BOARD_LOCK(fxMesa);
    strcpy(buf, grGetString(GR_VERSION));
    END_BOARD_LOCK(fxMesa);
}

void
FX_grSstPerfStats(GrSstPerfStats_t * st)
{
    FxI32 n;
    grGet(GR_STATS_PIXELS_IN, 4, &n);
    st->pixelsIn = n;
    grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n);
    st->chromaFail = n;
    grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n);
    st->zFuncFail = n;
    grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n);
    st->aFuncFail = n;
    grGet(GR_STATS_PIXELS_OUT, 4, &n);
    st->pixelsOut = n;
}

void
FX_grAADrawLine(fxMesaContext fxMesa, GrVertex * a, GrVertex * b)
{
    /* ToDo */
    BEGIN_CLIP_LOOP(fxMesa);
    grDrawLine(a, b);
    END_CLIP_LOOP(fxMesa);
}

void
FX_grAADrawPoint(fxMesaContext fxMesa, GrVertex * a)
{
    BEGIN_CLIP_LOOP(fxMesa);
    grDrawPoint(a);
    END_CLIP_LOOP(fxMesa);
}

void
FX_grDrawPolygonVertexList(fxMesaContext fxMesa, int n, GrVertex * verts)
{
    BEGIN_CLIP_LOOP(fxMesa);
    grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex));
    END_CLIP_LOOP(fxMesa);
}

#if FX_USE_PARGB
void
FX_setupGrVertexLayout(void)
{
    BEGIN_BOARD_LOCK(fxMesa);
    grReset(GR_VERTEX_PARAMETER);

    grCoordinateSpace(GR_WINDOW_COORDS);
    grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_PARGB, GR_VERTEX_PARGB_OFFSET << 2,
                   GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2,
                   GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
                   GR_PARAM_DISABLE);
    grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
                   GR_PARAM_DISABLE);
    grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
                   GR_PARAM_DISABLE);
    END_BOARD_LOCK(fxMesa);
}
#else /* FX_USE_PARGB */
void
FX_setupGrVertexLayout(fxMesaContext fxMesa)
{
    BEGIN_BOARD_LOCK(fxMesa);
    grReset(GR_VERTEX_PARAMETER);

    grCoordinateSpace(GR_WINDOW_COORDS);
    grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2,
                   GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
                   GR_PARAM_DISABLE);
    grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
                   GR_PARAM_DISABLE);
    grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
                   GR_PARAM_DISABLE);
    END_BOARD_LOCK(fxMesa);
}
#endif

void
FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask)
{
    switch (hintType) {
    case GR_HINT_STWHINT:
        {
            if (hintMask & GR_STWHINT_W_DIFF_TMU0)
                grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
                               GR_PARAM_ENABLE);
            else
                grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2,
                               GR_PARAM_DISABLE);

            if (hintMask & GR_STWHINT_ST_DIFF_TMU1)
                grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
                               GR_PARAM_ENABLE);
            else
                grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2,
                               GR_PARAM_DISABLE);

            if (hintMask & GR_STWHINT_W_DIFF_TMU1)
                grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
                               GR_PARAM_ENABLE);
            else
                grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2,
                               GR_PARAM_DISABLE);

        }
    }
}

void
FX_grHints(fxMesaContext fxMesa, GrHint_t hintType, FxU32 hintMask)
{
    BEGIN_BOARD_LOCK(fxMesa);
    FX_grHints_NoLock(hintType, hintMask);
    END_BOARD_LOCK(fxMesa);
}

int
FX_grSstQueryHardware(fxMesaContext fxMesa, GrHwConfiguration * config)
{
    int i, j;
    int numFB;

    BEGIN_BOARD_LOCK(fxMesa);
    grGet(GR_NUM_BOARDS, 4, (void *) &(config->num_sst));
    if (config->num_sst == 0)
        return 0;
    for (i = 0; i < config->num_sst; i++) {
        config->SSTs[i].type = GR_SSTTYPE_VOODOO;
        grSstSelect(i);
        grGet(GR_MEMORY_FB, 4,
              (void *) &(config->SSTs[i].sstBoard.VoodooConfig.fbRam));
        config->SSTs[i].sstBoard.VoodooConfig.fbRam /= 1024 * 1024;

        grGet(GR_NUM_TMU, 4,
              (void *) &(config->SSTs[i].sstBoard.VoodooConfig.nTexelfx));


        grGet(GR_NUM_FB, 4, (void *) &numFB);
        if (numFB > 1)
            config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXTRUE;
        else
            config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXFALSE;
        for (j = 0; j < config->SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++) {
            grGet(GR_MEMORY_TMU, 4,
                  (void *) &(config->SSTs[i].sstBoard.
                             VoodooConfig.tmuConfig[j].tmuRam));
            config->SSTs[i].sstBoard.VoodooConfig.
                tmuConfig[j].tmuRam /= 1024 * 1024;
        }
    }
    END_BOARD_LOCK(fxMesa);
    return 1;
}

#else

int
FX_grSstScreenWidth()
{
    int i;
    BEGIN_BOARD_LOCK(fxMesa);
    i = grSstScreenWidth();
    END_BOARD_LOCK(fxMesa);
    return i;
}

int
FX_grSstScreenHeight()
{
    int i;
    BEGIN_BOARD_LOCK(fxMesa);
    i = grSstScreenHeight();
    END_BOARD_LOCK(fxMesa);
    return i;
}

int
FX_grSstQueryHardware(GrHwConfiguration * c)
{
    int i;
    BEGIN_BOARD_LOCK(fxMesa);
    i = grSstQueryHardware(c);
    END_BOARD_LOCK(fxMesa);
    return i;
}


#endif /* FX_GLIDE3 */

/* It appears to me that this function is needed either way. */
FX_GrContext_t
FX_grSstWinOpen(fxMesaContext fxMesa,
                FxU32 hWnd,
                GrScreenResolution_t screen_resolution,
                GrScreenRefresh_t refresh_rate,
                GrColorFormat_t color_format,
                GrOriginLocation_t origin_location,
                int nColBuffers, int nAuxBuffers)
{
    FX_GrContext_t i;
    BEGIN_BOARD_LOCK(fxMesa);
    i = grSstWinOpen(hWnd,
                     screen_resolution,
                     refresh_rate,
                     color_format, origin_location, nColBuffers, nAuxBuffers);

    /*
       fprintf(stderr, 
       "grSstWinOpen( win %d res %d ref %d fmt %d\n"
       "              org %d ncol %d naux %d )\n"
       " ==> %d\n",
       hWnd,
       screen_resolution,
       refresh_rate,
       color_format,
       origin_location,
       nColBuffers,
       nAuxBuffers,
       i);
     */
    END_BOARD_LOCK(fxMesa);
    return i;
}