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