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