Fix FX driver to the point where gears & morph3d work.
[mesa.git] / src / mesa / drivers / glide / fxdrv.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.3
5 *
6 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
27 * terms stated above.
28 *
29 * Thank you for your contribution, David!
30 *
31 * Please make note of the above copyright/license statement. If you
32 * contributed code or bug fixes to this code under the previous (GNU
33 * Library) license and object to the new license, your code will be
34 * removed at your request. Please see the Mesa docs/COPYRIGHT file
35 * for more information.
36 *
37 * Additional Mesa/3Dfx driver developers:
38 * Daryll Strauss <daryll@precisioninsight.com>
39 * Keith Whitwell <keith@precisioninsight.com>
40 *
41 * See fxapi.h for more revision/author details.
42 */
43
44
45 #ifndef FXDRV_H
46 #define FXDRV_H
47
48 /* If you comment out this define, a variable takes its place, letting
49 * you turn debugging on/off from the debugger.
50 */
51
52 #include "glheader.h"
53
54
55 #if defined(__linux__)
56 #include <signal.h>
57 #endif
58
59 #include "context.h"
60 #include "macros.h"
61 #include "matrix.h"
62 #include "mem.h"
63 #include "mtypes.h"
64
65 #include "GL/fxmesa.h"
66 #include "fxglidew.h"
67
68 #include "math/m_vector.h"
69
70
71 /* Define some shorter names for these things.
72 */
73 #define XCOORD GR_VERTEX_X_OFFSET
74 #define YCOORD GR_VERTEX_Y_OFFSET
75 #define ZCOORD GR_VERTEX_OOZ_OFFSET
76 #define OOWCOORD GR_VERTEX_OOW_OFFSET
77
78 #define RCOORD GR_VERTEX_R_OFFSET
79 #define GCOORD GR_VERTEX_G_OFFSET
80 #define BCOORD GR_VERTEX_B_OFFSET
81 #define ACOORD GR_VERTEX_A_OFFSET
82
83 #define S0COORD GR_VERTEX_SOW_TMU0_OFFSET
84 #define T0COORD GR_VERTEX_TOW_TMU0_OFFSET
85 #define S1COORD GR_VERTEX_SOW_TMU1_OFFSET
86 #define T1COORD GR_VERTEX_TOW_TMU1_OFFSET
87
88
89 extern float gl_ubyte_to_float_255_color_tab[256];
90 #define UBYTE_COLOR_TO_FLOAT_255_COLOR(c) gl_ubyte_to_float_255_color_tab[c]
91 #define UBYTE_COLOR_TO_FLOAT_255_COLOR2(f,c) \
92 (*(int *)&(f)) = ((int *)gl_ubyte_to_float_255_color_tab)[c]
93
94
95
96
97
98 #if defined(FXMESA_USE_ARGB)
99 #define FXCOLOR4( c ) ( \
100 ( ((unsigned int)(c[3]))<<24 ) | \
101 ( ((unsigned int)(c[0]))<<16 ) | \
102 ( ((unsigned int)(c[1]))<<8 ) | \
103 ( (unsigned int)(c[2])) )
104
105 #else
106 #ifdef __i386__
107 #define FXCOLOR4( c ) (* (int *)c)
108 #else
109 #define FXCOLOR4( c ) ( \
110 ( ((unsigned int)(c[3]))<<24 ) | \
111 ( ((unsigned int)(c[2]))<<16 ) | \
112 ( ((unsigned int)(c[1]))<<8 ) | \
113 ( (unsigned int)(c[0])) )
114 #endif
115 #endif
116
117
118
119 /* fastpath flags first
120 */
121 #define SETUP_TMU0 0x1
122 #define SETUP_TMU1 0x2
123 #define SETUP_RGBA 0x4
124 #define SETUP_SNAP 0x8
125 #define SETUP_XYZW 0x10
126 #define SETUP_PTEX 0x20
127 #define MAX_SETUP 0x40
128
129
130 #define FX_NUM_TMU 2
131
132 #define FX_TMU0 GR_TMU0
133 #define FX_TMU1 GR_TMU1
134 #define FX_TMU_SPLIT 98
135 #define FX_TMU_BOTH 99
136 #define FX_TMU_NONE 100
137
138 /* Used for fxMesa->lastUnitsMode */
139
140 #define FX_UM_NONE 0x00000000
141
142 #define FX_UM_E0_REPLACE 0x00000001
143 #define FX_UM_E0_MODULATE 0x00000002
144 #define FX_UM_E0_DECAL 0x00000004
145 #define FX_UM_E0_BLEND 0x00000008
146 #define FX_UM_E0_ADD 0x00000010
147
148 #define FX_UM_E1_REPLACE 0x00000020
149 #define FX_UM_E1_MODULATE 0x00000040
150 #define FX_UM_E1_DECAL 0x00000080
151 #define FX_UM_E1_BLEND 0x00000100
152 #define FX_UM_E1_ADD 0x00000200
153
154 #define FX_UM_E_ENVMODE 0x000003ff
155
156 #define FX_UM_E0_ALPHA 0x00001000
157 #define FX_UM_E0_LUMINANCE 0x00002000
158 #define FX_UM_E0_LUMINANCE_ALPHA 0x00004000
159 #define FX_UM_E0_INTENSITY 0x00008000
160 #define FX_UM_E0_RGB 0x00010000
161 #define FX_UM_E0_RGBA 0x00020000
162
163 #define FX_UM_E1_ALPHA 0x00040000
164 #define FX_UM_E1_LUMINANCE 0x00080000
165 #define FX_UM_E1_LUMINANCE_ALPHA 0x00100000
166 #define FX_UM_E1_INTENSITY 0x00200000
167 #define FX_UM_E1_RGB 0x00400000
168 #define FX_UM_E1_RGBA 0x00800000
169
170 #define FX_UM_E_IFMT 0x00fff000
171
172 #define FX_UM_COLOR_ITERATED 0x01000000
173 #define FX_UM_COLOR_CONSTANT 0x02000000
174 #define FX_UM_ALPHA_ITERATED 0x04000000
175 #define FX_UM_ALPHA_CONSTANT 0x08000000
176
177
178 /*
179 Memory range from startAddr to endAddr-1
180 */
181 typedef struct MemRange_t
182 {
183 struct MemRange_t *next;
184 FxU32 startAddr, endAddr;
185 }
186 MemRange;
187
188 typedef struct
189 {
190 GLsizei width, height; /* image size */
191 GLint wScale, hScale; /* image scale factor */
192 GrTextureFormat_t glideFormat; /* Glide image format */
193 }
194 tfxMipMapLevel;
195
196 /*
197 * TDFX-specific texture object data. This hangs off of the
198 * struct gl_texture_object DriverData pointer.
199 */
200 typedef struct tfxTexInfo_t
201 {
202 struct tfxTexInfo_t *next;
203 struct gl_texture_object *tObj;
204
205 GLuint lastTimeUsed;
206 FxU32 whichTMU;
207 GLboolean isInTM;
208
209 MemRange *tm[FX_NUM_TMU];
210
211 GLint minLevel, maxLevel;
212 GLint baseLevelInternalFormat;
213
214 GrTexInfo info;
215
216 GrTextureFilterMode_t minFilt;
217 GrTextureFilterMode_t maxFilt;
218 FxBool LODblend;
219
220 GrTextureClampMode_t sClamp;
221 GrTextureClampMode_t tClamp;
222
223 GrMipMapMode_t mmMode;
224
225 GLfloat sScale, tScale;
226 GLint int_sScale, int_tScale; /* x86 floating point trick for
227 * multiplication by powers of 2.
228 * Used in fxfasttmp.h
229 */
230
231 GuTexPalette palette;
232
233 GLboolean fixedPalette;
234 GLboolean validated;
235 }
236 tfxTexInfo;
237
238 typedef struct
239 {
240 GLuint swapBuffer;
241 GLuint reqTexUpload;
242 GLuint texUpload;
243 GLuint memTexUpload;
244 }
245 tfxStats;
246
247
248
249 typedef struct
250 {
251 /* Alpha test */
252
253 GLboolean alphaTestEnabled;
254 GrCmpFnc_t alphaTestFunc;
255 GrAlpha_t alphaTestRefValue;
256
257 /* Blend function */
258
259 GLboolean blendEnabled;
260 GrAlphaBlendFnc_t blendSrcFuncRGB;
261 GrAlphaBlendFnc_t blendDstFuncRGB;
262 GrAlphaBlendFnc_t blendSrcFuncAlpha;
263 GrAlphaBlendFnc_t blendDstFuncAlpha;
264
265 /* Depth test */
266
267 GLboolean depthTestEnabled;
268 GLboolean depthMask;
269 GrCmpFnc_t depthTestFunc;
270 }
271 tfxUnitsState;
272
273
274
275
276 /* Flags for fxMesa->new_state
277 */
278 #define FX_NEW_TEXTURING 0x1
279 #define FX_NEW_BLEND 0x2
280 #define FX_NEW_ALPHA 0x4
281 #define FX_NEW_DEPTH 0x8
282 #define FX_NEW_FOG 0x10
283 #define FX_NEW_SCISSOR 0x20
284 #define FX_NEW_COLOR_MASK 0x40
285 #define FX_NEW_CULL 0x80
286
287
288 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
289
290 #define FX_TEXTURE_DATA(texUnit) fxTMGetTexInfo((texUnit)->_Current)
291
292 #define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData))
293
294 #define FX_MIPMAP_DATA(img) ((tfxMipMapLevel *) (img)->DriverData)
295
296 #define BEGIN_BOARD_LOCK()
297 #define END_BOARD_LOCK()
298 #define BEGIN_CLIP_LOOP()
299 #define END_CLIP_LOOP()
300
301
302
303
304 /* Covers the state referenced by IsInHardware:
305 */
306 #define _FX_NEW_IS_IN_HARDWARE (_NEW_TEXTURE| \
307 _NEW_HINT| \
308 _NEW_STENCIL| \
309 _NEW_BUFFERS| \
310 _NEW_COLOR| \
311 _NEW_LIGHT)
312
313 /* Covers the state referenced by fxDDChooseRenderState
314 */
315 #define _FX_NEW_RENDERSTATE (_FX_NEW_IS_IN_HARDWARE | \
316 _DD_NEW_FLATSHADE | \
317 _DD_NEW_TRI_LIGHT_TWOSIDE| \
318 _DD_NEW_TRI_OFFSET | \
319 _DD_NEW_TRI_UNFILLED | \
320 _DD_NEW_TRI_SMOOTH | \
321 _DD_NEW_TRI_STIPPLE | \
322 _DD_NEW_LINE_SMOOTH | \
323 _DD_NEW_LINE_STIPPLE | \
324 _DD_NEW_LINE_WIDTH | \
325 _DD_NEW_POINT_SMOOTH | \
326 _DD_NEW_POINT_SIZE | \
327 _NEW_LINE)
328
329
330 /* Covers the state referenced by fxDDChooseSetupFunction.
331 */
332 #define _FX_NEW_SETUP_FUNCTION (_NEW_LIGHT| \
333 _NEW_FOG| \
334 _NEW_TEXTURE| \
335 _NEW_COLOR) \
336
337
338 /* These lookup table are used to extract RGB values in [0,255] from
339 * 16-bit pixel values.
340 */
341 extern GLubyte FX_PixelToR[0x10000];
342 extern GLubyte FX_PixelToG[0x10000];
343 extern GLubyte FX_PixelToB[0x10000];
344
345
346 typedef void (*fx_tri_func) (fxMesaContext, GrVertex *, GrVertex *, GrVertex *);
347 typedef void (*fx_line_func) (fxMesaContext, GrVertex *, GrVertex *);
348 typedef void (*fx_point_func) (fxMesaContext, GrVertex *);
349
350 struct tfxMesaContext
351 {
352 GuTexPalette glbPalette;
353
354 GLcontext *glCtx; /* the core Mesa context */
355 GLvisual *glVis; /* describes the color buffer */
356 GLframebuffer *glBuffer; /* the ancillary buffers */
357
358 GLint board; /* the board used for this context */
359 GLint width, height; /* size of color buffer */
360
361 GrBuffer_t currentFB;
362
363 GLboolean bgrOrder;
364 GrColor_t color;
365 GrColor_t clearC;
366 GrAlpha_t clearA;
367 GLuint constColor;
368 GrCullMode_t cullMode;
369
370 tfxUnitsState unitsState;
371 tfxUnitsState restoreUnitsState; /* saved during multipass */
372
373
374 GLuint new_state;
375
376 /* Texture Memory Manager Data
377 */
378 GLuint texBindNumber;
379 GLint tmuSrc;
380 GLuint lastUnitsMode;
381 GLuint freeTexMem[FX_NUM_TMU];
382 MemRange *tmPool;
383 MemRange *tmFree[FX_NUM_TMU];
384
385 GLenum fogTableMode;
386 GLfloat fogDensity;
387 GLfloat fogStart, fogEnd;
388 GrFog_t *fogTable;
389 GLint textureAlign;
390
391 /* Vertex building and storage:
392 */
393 GLuint tmu_source[FX_NUM_TMU];
394 GLuint SetupIndex;
395 GLuint stw_hint_state; /* for grHints */
396 GrVertex *verts;
397 GLboolean snapVertices; /* needed for older Voodoo hardware */
398 struct gl_client_array UbyteColor;
399
400 /* Rasterization:
401 */
402 GLuint render_index;
403 GLuint is_in_hardware;
404 GLenum render_primitive;
405 GLenum raster_primitive;
406
407 /* Current rasterization functions
408 */
409 fx_point_func draw_point;
410 fx_line_func draw_line;
411 fx_tri_func draw_tri;
412
413
414 /* Keep texture scales somewhere handy:
415 */
416 GLfloat s0scale;
417 GLfloat s1scale;
418 GLfloat t0scale;
419 GLfloat t1scale;
420
421 GLfloat inv_s0scale;
422 GLfloat inv_s1scale;
423 GLfloat inv_t0scale;
424 GLfloat inv_t1scale;
425
426 /* Glide stuff
427 */
428 tfxStats stats;
429 void *state;
430
431 /* Options */
432
433 GLboolean verbose;
434 GLboolean haveTwoTMUs; /* True if we really have 2 tmu's */
435 GLboolean haveAlphaBuffer;
436 GLboolean haveZBuffer;
437 GLboolean haveDoubleBuffer;
438 GLboolean haveGlobalPaletteTexture;
439 GLint swapInterval;
440 GLint maxPendingSwapBuffers;
441
442 FX_GrContext_t glideContext;
443
444 int screen_width;
445 int screen_height;
446 int initDone;
447 int clipMinX;
448 int clipMaxX;
449 int clipMinY;
450 int clipMaxY;
451 };
452
453
454 extern GrHwConfiguration glbHWConfig;
455 extern int glbCurrentBoard;
456
457 extern void fxSetupFXUnits(GLcontext *);
458 extern void fxSetupDDPointers(GLcontext *);
459
460 /* fxvb.c:
461 */
462 extern void fxAllocVB(GLcontext * ctx);
463 extern void fxFreeVB(GLcontext * ctx);
464 extern void fxPrintSetupFlags(char *msg, GLuint flags );
465 extern void fxCheckTexSizes( GLcontext *ctx );
466 extern void fxBuildVertices( GLcontext *ctx, GLuint start, GLuint count,
467 GLuint newinputs );
468 extern void fxChooseVertexState( GLcontext *ctx );
469
470
471
472
473
474
475 /* fxtrifuncs:
476 */
477 extern void fxDDInitTriFuncs(GLcontext *);
478 extern void fxDDChooseRenderState(GLcontext * ctx);
479
480
481 extern void fxUpdateDDSpanPointers(GLcontext *);
482 extern void fxSetupDDSpanPointers(GLcontext *);
483
484 extern void fxPrintTextureData(tfxTexInfo * ti);
485
486 extern const struct gl_texture_format *
487 fxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
488 GLenum srcFormat, GLenum srcType );
489 extern void fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level,
490 GLint internalFormat, GLint width, GLint height,
491 GLint border, GLenum format, GLenum type,
492 const GLvoid * pixels,
493 const struct gl_pixelstore_attrib *packing,
494 struct gl_texture_object *texObj,
495 struct gl_texture_image *texImage);
496
497 extern void fxDDTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
498 GLint xoffset, GLint yoffset,
499 GLsizei width, GLsizei height,
500 GLenum format, GLenum type,
501 const GLvoid * pixels,
502 const struct gl_pixelstore_attrib *packing,
503 struct gl_texture_object *texObj,
504 struct gl_texture_image *texImage);
505 extern void fxDDTexEnv(GLcontext *, GLenum, GLenum, const GLfloat *);
506 extern void fxDDTexParam(GLcontext *, GLenum, struct gl_texture_object *,
507 GLenum, const GLfloat *);
508 extern void fxDDTexBind(GLcontext *, GLenum, struct gl_texture_object *);
509 extern void fxDDTexDel(GLcontext *, struct gl_texture_object *);
510 extern void fxDDTexPalette(GLcontext *, struct gl_texture_object *);
511 extern void fxDDTexUseGlbPalette(GLcontext *, GLboolean);
512
513 extern void fxDDEnable(GLcontext *, GLenum, GLboolean);
514 extern void fxDDAlphaFunc(GLcontext *, GLenum, GLchan);
515 extern void fxDDBlendFunc(GLcontext *, GLenum, GLenum);
516 extern void fxDDDepthMask(GLcontext *, GLboolean);
517 extern void fxDDDepthFunc(GLcontext *, GLenum);
518
519 extern void fxDDInitExtensions(GLcontext * ctx);
520
521 extern void fxTMInit(fxMesaContext ctx);
522 extern void fxTMClose(fxMesaContext ctx);
523 extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx);
524 extern void fxTMMoveInTM(fxMesaContext, struct gl_texture_object *, GLint);
525 extern void fxTMMoveOutTM(fxMesaContext, struct gl_texture_object *);
526 #define fxTMMoveOutTM_NoLock fxTMMoveOutTM
527 extern void fxTMFreeTexture(fxMesaContext, struct gl_texture_object *);
528 extern void fxTMReloadMipMapLevel(fxMesaContext, struct gl_texture_object *,
529 GLint);
530 extern void fxTMReloadSubMipMapLevel(fxMesaContext,
531 struct gl_texture_object *, GLint, GLint,
532 GLint);
533
534 extern void fxTexGetFormat(GLenum, GrTextureFormat_t *, GLint *);
535 extern int fxTexGetInfo(int, int, GrLOD_t *, GrAspectRatio_t *,
536 float *, float *, int *, int *, int *, int *);
537
538 extern void fxDDScissor(GLcontext * ctx,
539 GLint x, GLint y, GLsizei w, GLsizei h);
540 extern void fxDDFogfv(GLcontext * ctx, GLenum pname, const GLfloat * params);
541 extern void fxDDColorMask(GLcontext * ctx,
542 GLboolean r, GLboolean g, GLboolean b, GLboolean a);
543
544 extern void fxDDWriteDepthSpan(GLcontext * ctx, GLuint n, GLint x, GLint y,
545 const GLdepth depth[], const GLubyte mask[]);
546
547 extern void fxDDReadDepthSpan(GLcontext * ctx, GLuint n, GLint x, GLint y,
548 GLdepth depth[]);
549
550 extern void fxDDWriteDepthPixels(GLcontext * ctx, GLuint n,
551 const GLint x[], const GLint y[],
552 const GLdepth depth[], const GLubyte mask[]);
553
554 extern void fxDDReadDepthPixels(GLcontext * ctx, GLuint n,
555 const GLint x[], const GLint y[],
556 GLdepth depth[]);
557
558 extern void fxDDShadeModel(GLcontext * ctx, GLenum mode);
559
560 extern void fxDDCullFace(GLcontext * ctx, GLenum mode);
561 extern void fxDDFrontFace(GLcontext * ctx, GLenum mode);
562
563 extern void fxPrintRenderState(const char *msg, GLuint state);
564 extern void fxPrintHintState(const char *msg, GLuint state);
565
566 extern int fxDDInitFxMesaContext(fxMesaContext fxMesa);
567 extern void fxDDDestroyFxMesaContext(fxMesaContext fxMesa);
568
569
570
571
572 extern void fxSetScissorValues(GLcontext * ctx);
573 extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa,
574 struct gl_texture_object *tObj, GLint where);
575 extern void fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder);
576
577 extern void fxCheckIsInHardware(GLcontext *ctx);
578
579 extern GLboolean fx_check_IsInHardware(GLcontext *ctx);
580
581 #endif