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