1 /* -*- mode: C; tab-width:8; -*-
3 fxdrv.h - 3Dfx VooDoo driver types
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * See the file fxapi.c for more informations about authors
28 /* If you comment out this define, a variable takes its place, letting
29 * you turn debugging on/off from the debugger.
39 #include "GL/xf86glx.h"
43 #if defined(__linux__)
57 #include "GL/fxmesa.h"
59 /* use gl/gl.h GLAPI/GLAPIENTRY/GLCALLBACK in place of WINGDIAPI/APIENTRY/CALLBACK, */
60 /* these are defined in mesa gl/gl.h - tjump@spgs.com */
65 extern void fx_sanity_triangle( GrVertex
*, GrVertex
*, GrVertex
* );
66 #define grDrawTriangle fx_sanity_triangle
70 /* Define some shorter names for these things.
72 #define XCOORD GR_VERTEX_X_OFFSET
73 #define YCOORD GR_VERTEX_Y_OFFSET
74 #define ZCOORD GR_VERTEX_OOZ_OFFSET
75 #define OOWCOORD GR_VERTEX_OOW_OFFSET
77 #define RCOORD GR_VERTEX_R_OFFSET
78 #define GCOORD GR_VERTEX_G_OFFSET
79 #define BCOORD GR_VERTEX_B_OFFSET
80 #define ACOORD GR_VERTEX_A_OFFSET
82 #define S0COORD GR_VERTEX_SOW_TMU0_OFFSET
83 #define T0COORD GR_VERTEX_TOW_TMU0_OFFSET
84 #define S1COORD GR_VERTEX_SOW_TMU1_OFFSET
85 #define T1COORD GR_VERTEX_TOW_TMU1_OFFSET
90 #define CLIP_XCOORD 0 /* normal place */
91 #define CLIP_YCOROD 1 /* normal place */
92 #define CLIP_ZCOORD 2 /* normal place */
93 #define CLIP_WCOORD 3 /* normal place */
94 #define CLIP_GCOORD 4 /* GR_VERTEX_PARGB_OFFSET */
95 #define CLIP_BCOORD 5 /* GR_VERTEX_SOW_TMU0_OFFSET */
96 #define CLIP_RCOORD 6 /* GR_VERTEX_TOW_TMU0_OFFSET */
97 #define CLIP_ACOORD 7 /* GR_VERTEX_OOW_TMU0_OFFSET */
101 #define CLIP_XCOORD 0 /* normal place */
102 #define CLIP_YCOROD 1 /* normal place */
103 #define CLIP_ZCOORD 2 /* GR_VERTEX_Z_OFFSET */
104 #define CLIP_WCOORD 3 /* GR_VERTEX_R_OFFSET */
105 #define CLIP_GCOORD 4 /* normal place */
106 #define CLIP_BCOORD 5 /* normal place */
107 #define CLIP_RCOORD 6 /* GR_VERTEX_OOZ_OFFSET */
108 #define CLIP_ACOORD 7 /* normal place */
113 /* Should have size == 16 * sizeof(float).
116 GLfloat f
[15]; /* Same layout as GrVertex */
117 GLubyte mask
; /* Unsued */
118 GLubyte usermask
; /* Unused */
124 #if defined(FXMESA_USE_ARGB)
125 #define FXCOLOR4( c ) ( \
126 ( ((unsigned int)(c[3]))<<24 ) | \
127 ( ((unsigned int)(c[0]))<<16 ) | \
128 ( ((unsigned int)(c[1]))<<8 ) | \
129 ( (unsigned int)(c[2])) )
133 #define FXCOLOR4( c ) (* (int *)c)
135 #define FXCOLOR4( c ) ( \
136 ( ((unsigned int)(c[3]))<<24 ) | \
137 ( ((unsigned int)(c[2]))<<16 ) | \
138 ( ((unsigned int)(c[1]))<<8 ) | \
139 ( (unsigned int)(c[0])) )
143 #define FX_VB_COLOR(fxm, color) \
145 if (sizeof(GLint) == 4*sizeof(GLubyte)) { \
146 if (fxm->constColor != *(GLuint*)color) { \
147 fxm->constColor = *(GLuint*)color; \
148 grConstantColorValue(FXCOLOR4(color)); \
151 grConstantColorValue(FXCOLOR4(color)); \
155 #define GOURAUD(x) { \
156 GLubyte *col = VB->ColorPtr->data[(x)]; \
157 gWin[(x)].v.r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \
158 gWin[(x)].v.g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \
159 gWin[(x)].v.b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \
160 gWin[(x)].v.a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \
164 #define GOURAUD2(v, c) { \
166 v->argb=MESACOLOR2PARGB(col); \
169 #define GOURAUD2(v, c) { \
171 v->r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \
172 v->g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \
173 v->b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \
174 v->a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \
179 /* Mergable items first
181 #define SETUP_RGBA 0x1
182 #define SETUP_TMU0 0x2
183 #define SETUP_TMU1 0x4
188 #define MAX_MERGABLE 0x8
193 #define FX_TMU0 GR_TMU0
194 #define FX_TMU1 GR_TMU1
195 #define FX_TMU_SPLIT 98
196 #define FX_TMU_BOTH 99
197 #define FX_TMU_NONE 100
199 /* Used for fxMesa->lastUnitsMode */
201 #define FX_UM_NONE 0x00000000
203 #define FX_UM_E0_REPLACE 0x00000001
204 #define FX_UM_E0_MODULATE 0x00000002
205 #define FX_UM_E0_DECAL 0x00000004
206 #define FX_UM_E0_BLEND 0x00000008
207 #define FX_UM_E0_ADD 0x00000010
209 #define FX_UM_E1_REPLACE 0x00000020
210 #define FX_UM_E1_MODULATE 0x00000040
211 #define FX_UM_E1_DECAL 0x00000080
212 #define FX_UM_E1_BLEND 0x00000100
213 #define FX_UM_E1_ADD 0x00000200
215 #define FX_UM_E_ENVMODE 0x000003ff
217 #define FX_UM_E0_ALPHA 0x00001000
218 #define FX_UM_E0_LUMINANCE 0x00002000
219 #define FX_UM_E0_LUMINANCE_ALPHA 0x00004000
220 #define FX_UM_E0_INTENSITY 0x00008000
221 #define FX_UM_E0_RGB 0x00010000
222 #define FX_UM_E0_RGBA 0x00020000
224 #define FX_UM_E1_ALPHA 0x00040000
225 #define FX_UM_E1_LUMINANCE 0x00080000
226 #define FX_UM_E1_LUMINANCE_ALPHA 0x00100000
227 #define FX_UM_E1_INTENSITY 0x00200000
228 #define FX_UM_E1_RGB 0x00400000
229 #define FX_UM_E1_RGBA 0x00800000
231 #define FX_UM_E_IFMT 0x00fff000
233 #define FX_UM_COLOR_ITERATED 0x00100000
234 #define FX_UM_COLOR_CONSTANT 0x00200000
235 #define FX_UM_ALPHA_ITERATED 0x00400000
236 #define FX_UM_ALPHA_CONSTANT 0x00800000
238 typedef void (*tfxRenderVBFunc
)(GLcontext
*);
240 typedef struct tfxTMFreeListNode
{
241 struct tfxTMFreeListNode
*next
;
242 FxU32 startAddress
, endAddress
;
245 typedef struct tfxTMAllocListNode
{
246 struct tfxTMAllocListNode
*next
;
247 FxU32 startAddress
, endAddress
;
248 struct gl_texture_object
*tObj
;
252 GLsizei width
, height
;
255 unsigned short *data
;
256 GLboolean translated
, used
;
264 tfxTMAllocNode
*tm
[FX_NUM_TMU
];
266 tfxMipMapLevel mipmapLevel
[MAX_TEXTURE_LEVELS
];
273 GLint minLevel
, maxLevel
;
274 GLint baseLevelInternalFormat
;
278 GrTextureFilterMode_t minFilt
;
279 GrTextureFilterMode_t maxFilt
;
282 GrTextureClampMode_t sClamp
;
283 GrTextureClampMode_t tClamp
;
285 GrMipMapMode_t mmMode
;
287 GLfloat sScale
, tScale
;
288 GLint int_sScale
, int_tScale
; /* x86 floating point trick for
289 * multiplication by powers of 2.
290 * Used in fxfasttmp.h
293 GuTexPalette palette
;
295 GLboolean fixedPalette
;
307 typedef void (*tfxTriViewClipFunc
)( struct vertex_buffer
*VB
,
311 typedef void (*tfxTriClipFunc
)( struct vertex_buffer
*VB
,
316 typedef void (*tfxLineClipFunc
)( struct vertex_buffer
*VB
,
317 GLuint v1
, GLuint v2
,
321 extern tfxTriViewClipFunc fxTriViewClipTab
[0x8];
322 extern tfxTriClipFunc fxTriClipStrideTab
[0x8];
323 extern tfxLineClipFunc fxLineClipTab
[0x8];
328 GLboolean alphaTestEnabled
;
329 GrCmpFnc_t alphaTestFunc
;
330 GrAlpha_t alphaTestRefValue
;
334 GLboolean blendEnabled
;
335 GrAlphaBlendFnc_t blendSrcFuncRGB
;
336 GrAlphaBlendFnc_t blendDstFuncRGB
;
337 GrAlphaBlendFnc_t blendSrcFuncAlpha
;
338 GrAlphaBlendFnc_t blendDstFuncAlpha
;
342 GLboolean depthTestEnabled
;
344 GrCmpFnc_t depthTestFunc
;
348 /* Flags for render_index.
350 #define FX_OFFSET 0x1
351 #define FX_TWOSIDE 0x2
352 #define FX_FRONT_BACK 0x4
354 #define FX_ANTIALIAS 0x10
355 #define FX_FALLBACK 0x20
358 /* Flags for fxMesa->new_state
360 #define FX_NEW_TEXTURING 0x1
361 #define FX_NEW_BLEND 0x2
362 #define FX_NEW_ALPHA 0x4
363 #define FX_NEW_DEPTH 0x8
364 #define FX_NEW_FOG 0x10
365 #define FX_NEW_SCISSOR 0x20
366 #define FX_NEW_COLOR_MASK 0x40
367 #define FX_NEW_CULL 0x80
369 /* FX struct stored in VB->driver_data.
371 struct tfxMesaVertexBuffer
{
372 GLvector1ui clipped_elements
;
377 #if defined(FX_GLIDE3)
378 GrVertex
**triangle_b
; /* Triangle buffer */
379 GrVertex
**strips_b
; /* Strips buffer */
385 #define FX_DRIVER_DATA(vb) ((struct tfxMesaVertexBuffer *)((vb)->driver_data))
386 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
387 #define FX_TEXTURE_DATA(t) ((tfxTexInfo *) ((t)->Current->DriverData))
389 #if defined(XFree86Server) || defined(GLX_DIRECT_RENDERING)
390 #include "tdfx_init.h"
392 #define DRI_FX_CONTEXT
395 struct tfxMesaContext
{
396 GuTexPalette glbPalette
;
398 GLcontext
*glCtx
; /* the core Mesa context */
399 GLvisual
*glVis
; /* describes the color buffer */
400 GLframebuffer
*glBuffer
; /* the ancillary buffers */
402 GLint board
; /* the board used for this context */
403 GLint width
, height
; /* size of color buffer */
405 GrBuffer_t currentFB
;
412 tfxUnitsState unitsState
;
413 tfxUnitsState restoreUnitsState
; /* saved during multipass */
416 GLuint tmu_source
[FX_NUM_TMU
];
417 GLuint tex_dest
[MAX_TEXTURE_UNITS
];
419 GLuint partial_setup_index
;
424 GLuint last_tri_caps
;
425 GLuint stw_hint_state
; /* for grHints */
426 GLuint is_in_hardware
;
428 GLuint using_fast_path
, passes
, multipass
;
430 tfxLineClipFunc clip_line
;
431 tfxTriClipFunc clip_tri_stride
;
432 tfxTriViewClipFunc view_clip_tri
;
435 /* Texture Memory Manager Data */
437 GLuint texBindNumber
;
439 GLuint lastUnitsMode
;
440 GLuint freeTexMem
[FX_NUM_TMU
];
441 tfxTMFreeNode
*tmFree
[FX_NUM_TMU
];
442 tfxTMAllocNode
*tmAlloc
[FX_NUM_TMU
];
450 points_func PointsFunc
;
452 triangle_func TriangleFunc
;
455 render_func
**RenderVBTables
;
457 render_func
*RenderVBClippedTab
;
458 render_func
*RenderVBCulledTab
;
459 render_func
*RenderVBRawTab
;
469 GLboolean haveTwoTMUs
; /* True if we really have 2 tmu's */
470 GLboolean emulateTwoTMUs
; /* True if we present 2 tmu's to mesa. */
471 GLboolean haveAlphaBuffer
;
472 GLboolean haveZBuffer
;
473 GLboolean haveDoubleBuffer
;
474 GLboolean haveGlobalPaletteTexture
;
476 GLint maxPendingSwapBuffers
;
478 FX_GrContext_t glideContext
;
486 typedef void (*tfxSetupFunc
)(struct vertex_buffer
*, GLuint
, GLuint
);
488 extern GrHwConfiguration glbHWConfig
;
489 extern int glbCurrentBoard
;
491 extern void fxSetupFXUnits(GLcontext
*);
492 extern void fxSetupDDPointers(GLcontext
*);
493 extern void fxDDSetNearFar(GLcontext
*, GLfloat
, GLfloat
);
495 extern void fxDDSetupInit(void);
496 extern void fxDDCvaInit(void);
497 extern void fxDDTrifuncInit(void);
498 extern void fxDDFastPathInit(void);
500 extern void fxDDChooseRenderState( GLcontext
*ctx
);
502 extern void fxRenderClippedLine( struct vertex_buffer
*VB
,
503 GLuint v1
, GLuint v2
);
505 extern void fxRenderClippedTriangle( struct vertex_buffer
*VB
,
506 GLuint n
, GLuint vlist
[] );
509 extern tfxSetupFunc
fxDDChooseSetupFunction(GLcontext
*);
511 extern points_func
fxDDChoosePointsFunction(GLcontext
*);
512 extern line_func
fxDDChooseLineFunction(GLcontext
*);
513 extern triangle_func
fxDDChooseTriangleFunction(GLcontext
*);
514 extern quad_func
fxDDChooseQuadFunction(GLcontext
*);
515 extern render_func
**fxDDChooseRenderVBTables(GLcontext
*);
517 extern void fxDDRenderInit(GLcontext
*);
518 extern void fxDDClipInit(void);
520 extern void fxUpdateDDSpanPointers(GLcontext
*);
521 extern void fxSetupDDSpanPointers(GLcontext
*);
523 extern void fxDDBufferSize(GLcontext
*, GLuint
*, GLuint
*);
525 extern void fxDDTexEnv(GLcontext
*, GLenum
, const GLfloat
*);
526 extern void fxDDTexImg(GLcontext
*, GLenum
, struct gl_texture_object
*,
527 GLint
, GLint
, const struct gl_texture_image
*);
528 extern void fxDDTexParam(GLcontext
*, GLenum
, struct gl_texture_object
*,
529 GLenum
, const GLfloat
*);
530 extern void fxDDTexBind(GLcontext
*, GLenum
, struct gl_texture_object
*);
531 extern void fxDDTexDel(GLcontext
*, struct gl_texture_object
*);
532 extern void fxDDTexPalette(GLcontext
*, struct gl_texture_object
*);
533 extern void fxDDTexuseGlbPalette(GLcontext
*, GLboolean
);
534 extern void fxDDTexSubImg(GLcontext
*, GLenum
, struct gl_texture_object
*, GLint
,
535 GLint
, GLint
, GLint
, GLint
, GLint
, const struct gl_texture_image
*);
536 extern void fxDDTexUseGlbPalette(GLcontext
*, GLboolean
);
538 extern void fxDDEnable(GLcontext
*, GLenum
, GLboolean
);
539 extern void fxDDAlphaFunc(GLcontext
*, GLenum
, GLclampf
);
540 extern void fxDDBlendFunc(GLcontext
*, GLenum
, GLenum
);
541 extern void fxDDDepthMask(GLcontext
*, GLboolean
);
542 extern void fxDDDepthFunc(GLcontext
*, GLenum
);
544 extern void fxDDRegisterVB( struct vertex_buffer
*VB
);
545 extern void fxDDUnregisterVB( struct vertex_buffer
*VB
);
546 extern void fxDDResizeVB( struct vertex_buffer
*VB
, GLuint size
);
548 extern void fxDDCheckMergeAndRender( GLcontext
*ctx
,
549 struct gl_pipeline_stage
*d
);
551 extern void fxDDMergeAndRender( struct vertex_buffer
*VB
);
553 extern void fxDDCheckPartialRasterSetup( GLcontext
*ctx
,
554 struct gl_pipeline_stage
*d
);
556 extern void fxDDPartialRasterSetup( struct vertex_buffer
*VB
);
558 extern void fxDDDoRasterSetup( struct vertex_buffer
*VB
);
560 extern GLuint
fxDDRegisterPipelineStages( struct gl_pipeline_stage
*out
,
561 const struct gl_pipeline_stage
*in
,
564 extern GLboolean
fxDDBuildPrecalcPipeline( GLcontext
*ctx
);
566 extern void fxDDOptimizePrecalcPipeline( GLcontext
*ctx
,
567 struct gl_pipeline
*pipe
);
569 extern void fxDDRenderElementsDirect( struct vertex_buffer
*VB
);
570 extern void fxDDRenderVBIndirectDirect( struct vertex_buffer
*VB
);
572 extern void fxDDInitExtensions( GLcontext
*ctx
);
574 extern void fxTMInit(fxMesaContext ctx
);
575 extern void fxTMClose(fxMesaContext ctx
);
576 extern void fxTMMoveInTM(fxMesaContext
, struct gl_texture_object
*, GLint
);
577 extern void fxTMMoveOutTM(fxMesaContext
, struct gl_texture_object
*);
578 extern void fxTMFreeTexture(fxMesaContext
, struct gl_texture_object
*);
579 extern void fxTMReloadMipMapLevel(fxMesaContext
, struct gl_texture_object
*, GLint
);
580 extern void fxTMReloadSubMipMapLevel(fxMesaContext
, struct gl_texture_object
*,
581 GLint
, GLint
, GLint
);
583 extern void fxTexGetFormat(GLenum
, GrTextureFormat_t
*, GLint
*);
584 extern int fxTexGetInfo(int, int, GrLOD_t
*, GrAspectRatio_t
*,
585 float *, float *, int *, int *, int *, int *);
587 extern void fxDDScissor( GLcontext
*ctx
,
588 GLint x
, GLint y
, GLsizei w
, GLsizei h
);
589 extern void fxDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
);
590 extern GLboolean
fxDDColorMask(GLcontext
*ctx
,
591 GLboolean r
, GLboolean g
,
592 GLboolean b
, GLboolean a
);
594 extern GLuint
fxDDDepthTestSpanGeneric(GLcontext
*ctx
,
595 GLuint n
, GLint x
, GLint y
,
599 extern void fxDDDepthTestPixelsGeneric(GLcontext
* ctx
,
601 const GLint x
[], const GLint y
[],
602 const GLdepth z
[], GLubyte mask
[]);
604 extern void fxDDReadDepthSpanFloat(GLcontext
*ctx
,
605 GLuint n
, GLint x
, GLint y
, GLfloat depth
[]);
607 extern void fxDDReadDepthSpanInt(GLcontext
*ctx
,
608 GLuint n
, GLint x
, GLint y
, GLdepth depth
[]);
611 extern void fxDDFastPath( struct vertex_buffer
*VB
);
613 extern void fxDDShadeModel(GLcontext
*ctx
, GLenum mode
);
615 extern void fxDDCullFace(GLcontext
*ctx
, GLenum mode
);
616 extern void fxDDFrontFace(GLcontext
*ctx
, GLenum mode
);
618 extern void fxPrintRenderState( const char *msg
, GLuint state
);
619 extern void fxPrintHintState( const char *msg
, GLuint state
);
621 extern void fxDDDoRenderVB( struct vertex_buffer
*VB
);
623 extern int fxDDInitFxMesaContext( fxMesaContext fxMesa
);