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