1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
30 * Thank you for your contribution, David!
32 * Please make note of the above copyright/license statement. If you
33 * contributed code or bug fixes to this code under the previous (GNU
34 * Library) license and object to the new license, your code will be
35 * removed at your request. Please see the Mesa docs/COPYRIGHT file
36 * for more information.
38 * Additional Mesa/3Dfx driver developers:
39 * Daryll Strauss <daryll@precisioninsight.com>
40 * Keith Whitwell <keith@precisioninsight.com>
42 * See fxapi.h for more revision/author details.
49 /* If you comment out this define, a variable takes its place, letting
50 * you turn debugging on/off from the debugger.
54 #include "GL/xf86glx.h"
60 #if defined(__linux__)
76 typedef struct tfxMesaContext
*fxMesaContext
;
78 #include "GL/fxmesa.h"
81 /* use gl/gl.h GLAPI/GLAPIENTRY/GLCALLBACK in place of WINGDIAPI/APIENTRY/CALLBACK, */
82 /* these are defined in mesa gl/gl.h - tjump@spgs.com */
86 extern void fx_sanity_triangle( GrVertex
*, GrVertex
*, GrVertex
* );
87 #if defined(MESA_DEBUG) && 0
88 #define grDrawTriangle fx_sanity_triangle
92 /* Define some shorter names for these things.
94 #define XCOORD GR_VERTEX_X_OFFSET
95 #define YCOORD GR_VERTEX_Y_OFFSET
96 #define ZCOORD GR_VERTEX_OOZ_OFFSET
97 #define OOWCOORD GR_VERTEX_OOW_OFFSET
99 #define RCOORD GR_VERTEX_R_OFFSET
100 #define GCOORD GR_VERTEX_G_OFFSET
101 #define BCOORD GR_VERTEX_B_OFFSET
102 #define ACOORD GR_VERTEX_A_OFFSET
104 #define S0COORD GR_VERTEX_SOW_TMU0_OFFSET
105 #define T0COORD GR_VERTEX_TOW_TMU0_OFFSET
106 #define S1COORD GR_VERTEX_SOW_TMU1_OFFSET
107 #define T1COORD GR_VERTEX_TOW_TMU1_OFFSET
112 #define CLIP_XCOORD 0 /* normal place */
113 #define CLIP_YCOROD 1 /* normal place */
114 #define CLIP_ZCOORD 2 /* normal place */
115 #define CLIP_WCOORD 3 /* normal place */
116 #define CLIP_GCOORD 4 /* GR_VERTEX_PARGB_OFFSET */
117 #define CLIP_BCOORD 5 /* GR_VERTEX_SOW_TMU0_OFFSET */
118 #define CLIP_RCOORD 6 /* GR_VERTEX_TOW_TMU0_OFFSET */
119 #define CLIP_ACOORD 7 /* GR_VERTEX_OOW_TMU0_OFFSET */
123 #define CLIP_XCOORD 0 /* normal place */
124 #define CLIP_YCOROD 1 /* normal place */
125 #define CLIP_ZCOORD 2 /* GR_VERTEX_Z_OFFSET */
126 #define CLIP_WCOORD 3 /* GR_VERTEX_R_OFFSET */
127 #define CLIP_GCOORD 4 /* normal place */
128 #define CLIP_BCOORD 5 /* normal place */
129 #define CLIP_RCOORD 6 /* GR_VERTEX_OOZ_OFFSET */
130 #define CLIP_ACOORD 7 /* normal place */
135 /* Should have size == 16 * sizeof(float).
138 GLfloat f
[15]; /* Same layout as GrVertex */
139 GLubyte mask
; /* Unsued */
140 GLubyte usermask
; /* Unused */
146 #if defined(FXMESA_USE_ARGB)
147 #define FXCOLOR4( c ) ( \
148 ( ((unsigned int)(c[3]))<<24 ) | \
149 ( ((unsigned int)(c[0]))<<16 ) | \
150 ( ((unsigned int)(c[1]))<<8 ) | \
151 ( (unsigned int)(c[2])) )
155 #define FXCOLOR4( c ) (* (int *)c)
157 #define FXCOLOR4( c ) ( \
158 ( ((unsigned int)(c[3]))<<24 ) | \
159 ( ((unsigned int)(c[2]))<<16 ) | \
160 ( ((unsigned int)(c[1]))<<8 ) | \
161 ( (unsigned int)(c[0])) )
165 #define FX_VB_COLOR(fxm, color) \
167 if (sizeof(GLint) == 4*sizeof(GLubyte)) { \
168 if (fxm->constColor != *(GLuint*)color) { \
169 fxm->constColor = *(GLuint*)color; \
170 FX_grConstantColorValue(FXCOLOR4(color)); \
173 FX_grConstantColorValue(FXCOLOR4(color)); \
177 #define GOURAUD(x) { \
178 GLubyte *col = VB->ColorPtr->data[(x)]; \
179 gWin[(x)].v.r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \
180 gWin[(x)].v.g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \
181 gWin[(x)].v.b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \
182 gWin[(x)].v.a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \
186 #define GOURAUD2(v, c) { \
188 v->argb=MESACOLOR2PARGB(col); \
191 #define GOURAUD2(v, c) { \
193 v->r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \
194 v->g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \
195 v->b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \
196 v->a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \
201 /* Mergable items first
203 #define SETUP_RGBA 0x1
204 #define SETUP_TMU0 0x2
205 #define SETUP_TMU1 0x4
210 #define MAX_MERGABLE 0x8
215 #define FX_TMU0 GR_TMU0
216 #define FX_TMU1 GR_TMU1
217 #define FX_TMU_SPLIT 98
218 #define FX_TMU_BOTH 99
219 #define FX_TMU_NONE 100
221 /* Used for fxMesa->lastUnitsMode */
223 #define FX_UM_NONE 0x00000000
225 #define FX_UM_E0_REPLACE 0x00000001
226 #define FX_UM_E0_MODULATE 0x00000002
227 #define FX_UM_E0_DECAL 0x00000004
228 #define FX_UM_E0_BLEND 0x00000008
229 #define FX_UM_E0_ADD 0x00000010
231 #define FX_UM_E1_REPLACE 0x00000020
232 #define FX_UM_E1_MODULATE 0x00000040
233 #define FX_UM_E1_DECAL 0x00000080
234 #define FX_UM_E1_BLEND 0x00000100
235 #define FX_UM_E1_ADD 0x00000200
237 #define FX_UM_E_ENVMODE 0x000003ff
239 #define FX_UM_E0_ALPHA 0x00001000
240 #define FX_UM_E0_LUMINANCE 0x00002000
241 #define FX_UM_E0_LUMINANCE_ALPHA 0x00004000
242 #define FX_UM_E0_INTENSITY 0x00008000
243 #define FX_UM_E0_RGB 0x00010000
244 #define FX_UM_E0_RGBA 0x00020000
246 #define FX_UM_E1_ALPHA 0x00040000
247 #define FX_UM_E1_LUMINANCE 0x00080000
248 #define FX_UM_E1_LUMINANCE_ALPHA 0x00100000
249 #define FX_UM_E1_INTENSITY 0x00200000
250 #define FX_UM_E1_RGB 0x00400000
251 #define FX_UM_E1_RGBA 0x00800000
253 #define FX_UM_E_IFMT 0x00fff000
255 #define FX_UM_COLOR_ITERATED 0x01000000
256 #define FX_UM_COLOR_CONSTANT 0x02000000
257 #define FX_UM_ALPHA_ITERATED 0x04000000
258 #define FX_UM_ALPHA_CONSTANT 0x08000000
260 typedef void (*tfxRenderVBFunc
)(GLcontext
*);
263 Memory range from startAddr to endAddr-1
265 typedef struct MemRange_t
{
266 struct MemRange_t
*next
;
267 FxU32 startAddr
, endAddr
;
271 GLsizei width
, height
; /* image size */
272 GrTextureFormat_t glideFormat
; /* Glide image format */
273 unsigned short *data
; /* Glide-formated texture image */
276 typedef struct tfxTexInfo_t
{
277 struct tfxTexInfo
*next
;
278 struct gl_texture_object
*tObj
;
284 tfxMipMapLevel mipmapLevel
[MAX_TEXTURE_LEVELS
];
286 MemRange
*tm
[FX_NUM_TMU
];
288 GLint minLevel
, maxLevel
;
289 GLint baseLevelInternalFormat
;
293 GrTextureFilterMode_t minFilt
;
294 GrTextureFilterMode_t maxFilt
;
297 GrTextureClampMode_t sClamp
;
298 GrTextureClampMode_t tClamp
;
300 GrMipMapMode_t mmMode
;
302 GLfloat sScale
, tScale
;
303 GLint int_sScale
, int_tScale
; /* x86 floating point trick for
304 * multiplication by powers of 2.
305 * Used in fxfasttmp.h
308 GuTexPalette palette
;
310 GLboolean fixedPalette
;
322 typedef void (*tfxTriViewClipFunc
)( struct vertex_buffer
*VB
,
326 typedef void (*tfxTriClipFunc
)( struct vertex_buffer
*VB
,
331 typedef void (*tfxLineClipFunc
)( struct vertex_buffer
*VB
,
332 GLuint v1
, GLuint v2
,
336 extern tfxTriViewClipFunc fxTriViewClipTab
[0x8];
337 extern tfxTriClipFunc fxTriClipStrideTab
[0x8];
338 extern tfxLineClipFunc fxLineClipTab
[0x8];
343 GLboolean alphaTestEnabled
;
344 GrCmpFnc_t alphaTestFunc
;
345 GrAlpha_t alphaTestRefValue
;
349 GLboolean blendEnabled
;
350 GrAlphaBlendFnc_t blendSrcFuncRGB
;
351 GrAlphaBlendFnc_t blendDstFuncRGB
;
352 GrAlphaBlendFnc_t blendSrcFuncAlpha
;
353 GrAlphaBlendFnc_t blendDstFuncAlpha
;
357 GLboolean depthTestEnabled
;
359 GrCmpFnc_t depthTestFunc
;
363 /* Flags for render_index.
365 #define FX_OFFSET 0x1
366 #define FX_TWOSIDE 0x2
367 #define FX_FRONT_BACK 0x4
369 #define FX_ANTIALIAS 0x10
370 #define FX_FALLBACK 0x20
373 /* Flags for fxMesa->new_state
375 #define FX_NEW_TEXTURING 0x1
376 #define FX_NEW_BLEND 0x2
377 #define FX_NEW_ALPHA 0x4
378 #define FX_NEW_DEPTH 0x8
379 #define FX_NEW_FOG 0x10
380 #define FX_NEW_SCISSOR 0x20
381 #define FX_NEW_COLOR_MASK 0x40
382 #define FX_NEW_CULL 0x80
384 /* FX struct stored in VB->driver_data.
386 struct tfxMesaVertexBuffer
{
387 GLvector1ui clipped_elements
;
392 #if defined(FX_GLIDE3)
393 GrVertex
**triangle_b
; /* Triangle buffer */
394 GrVertex
**strips_b
; /* Strips buffer */
400 #define FX_DRIVER_DATA(vb) ((struct tfxMesaVertexBuffer *)((vb)->driver_data))
401 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
402 #define FX_TEXTURE_DATA(t) fxTMGetTexInfo((t)->Current)
404 #if defined(XFree86Server) || defined(GLX_DIRECT_RENDERING)
405 #include "tdfx_init.h"
407 #define DRI_FX_CONTEXT
408 #define BEGIN_BOARD_LOCK()
409 #define END_BOARD_LOCK()
410 #define BEGIN_CLIP_LOOP()
411 #define END_CLIP_LOOP()
415 /* These lookup table are used to extract RGB values in [0,255] from
416 * 16-bit pixel values.
418 extern GLubyte FX_PixelToR
[0x10000];
419 extern GLubyte FX_PixelToG
[0x10000];
420 extern GLubyte FX_PixelToB
[0x10000];
423 struct tfxMesaContext
{
424 GuTexPalette glbPalette
;
426 GLcontext
*glCtx
; /* the core Mesa context */
427 #if !defined(XFree86Server) && !defined(GLX_DIRECT_RENDERING)
428 GLvisual
*glVis
; /* describes the color buffer */
429 GLframebuffer
*glBuffer
; /* the ancillary buffers */
432 GLint board
; /* the board used for this context */
433 GLint width
, height
; /* size of color buffer */
435 GrBuffer_t currentFB
;
442 GrCullMode_t cullMode
;
444 tfxUnitsState unitsState
;
445 tfxUnitsState restoreUnitsState
; /* saved during multipass */
447 GLuint tmu_source
[FX_NUM_TMU
];
448 GLuint tex_dest
[MAX_TEXTURE_UNITS
];
450 GLuint partial_setup_index
;
455 GLuint last_tri_caps
;
456 GLuint stw_hint_state
; /* for grHints */
457 GLuint is_in_hardware
;
459 GLuint using_fast_path
, passes
, multipass
;
461 tfxLineClipFunc clip_line
;
462 tfxTriClipFunc clip_tri_stride
;
463 tfxTriViewClipFunc view_clip_tri
;
466 /* Texture Memory Manager Data */
468 GLuint texBindNumber
;
470 GLuint lastUnitsMode
;
471 GLuint freeTexMem
[FX_NUM_TMU
];
473 MemRange
*tmFree
[FX_NUM_TMU
];
477 GLfloat fogStart
, fogEnd
;
483 points_func PointsFunc
;
485 triangle_func TriangleFunc
;
488 render_func
**RenderVBTables
;
490 render_func
*RenderVBClippedTab
;
491 render_func
*RenderVBCulledTab
;
492 render_func
*RenderVBRawTab
;
502 GLboolean haveTwoTMUs
; /* True if we really have 2 tmu's */
503 GLboolean emulateTwoTMUs
; /* True if we present 2 tmu's to mesa. */
504 GLboolean haveAlphaBuffer
;
505 GLboolean haveZBuffer
;
506 GLboolean haveDoubleBuffer
;
507 GLboolean haveGlobalPaletteTexture
;
509 GLint maxPendingSwapBuffers
;
511 FX_GrContext_t glideContext
;
528 typedef void (*tfxSetupFunc
)(struct vertex_buffer
*, GLuint
, GLuint
);
530 extern GrHwConfiguration glbHWConfig
;
531 extern int glbCurrentBoard
;
533 extern void fxPrintSetupFlags( const char *msg
, GLuint flags
);
534 extern void fxSetupFXUnits(GLcontext
*);
535 extern void fxSetupDDPointers(GLcontext
*);
536 extern void fxDDSetNearFar(GLcontext
*, GLfloat
, GLfloat
);
538 extern void fxDDSetupInit(void);
539 extern void fxDDCvaInit(void);
540 extern void fxDDTrifuncInit(void);
541 extern void fxDDFastPathInit(void);
543 extern void fxDDChooseRenderState( GLcontext
*ctx
);
545 extern void fxRenderClippedLine( struct vertex_buffer
*VB
,
546 GLuint v1
, GLuint v2
);
548 extern void fxRenderClippedTriangle( struct vertex_buffer
*VB
,
549 GLuint n
, GLuint vlist
[] );
552 extern tfxSetupFunc
fxDDChooseSetupFunction(GLcontext
*);
554 extern points_func
fxDDChoosePointsFunction(GLcontext
*);
555 extern line_func
fxDDChooseLineFunction(GLcontext
*);
556 extern triangle_func
fxDDChooseTriangleFunction(GLcontext
*);
557 extern quad_func
fxDDChooseQuadFunction(GLcontext
*);
558 extern render_func
**fxDDChooseRenderVBTables(GLcontext
*);
560 extern void fxDDRenderInit(GLcontext
*);
561 extern void fxDDClipInit(void);
563 extern void fxUpdateDDSpanPointers(GLcontext
*);
564 extern void fxSetupDDSpanPointers(GLcontext
*);
566 extern void fxPrintTextureData(tfxTexInfo
*ti
);
567 extern GLboolean
fxDDTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
568 GLenum format
, GLenum type
, const GLvoid
*pixels
,
569 const struct gl_pixelstore_attrib
*packing
,
570 struct gl_texture_object
*texObj
,
571 struct gl_texture_image
*texImage
,
572 GLboolean
*retainInternalCopy
);
573 extern GLboolean
fxDDTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
574 GLint xoffset
, GLint yoffset
,
575 GLsizei width
, GLsizei height
,
576 GLenum format
, GLenum type
, const GLvoid
*pixels
,
577 const struct gl_pixelstore_attrib
*packing
,
578 struct gl_texture_object
*texObj
,
579 struct gl_texture_image
*texImage
);
580 extern GLvoid
*fxDDGetTexImage(GLcontext
*ctx
, GLenum target
, GLint level
,
581 const struct gl_texture_object
*texObj
,
582 GLenum
*formatOut
, GLenum
*typeOut
,
583 GLboolean
*freeImageOut
);
584 extern void fxDDTexEnv(GLcontext
*, GLenum
, GLenum
, const GLfloat
*);
585 extern void fxDDTexParam(GLcontext
*, GLenum
, struct gl_texture_object
*,
586 GLenum
, const GLfloat
*);
587 extern void fxDDTexBind(GLcontext
*, GLenum
, struct gl_texture_object
*);
588 extern void fxDDTexDel(GLcontext
*, struct gl_texture_object
*);
589 extern void fxDDTexPalette(GLcontext
*, struct gl_texture_object
*);
590 extern void fxDDTexUseGlbPalette(GLcontext
*, GLboolean
);
592 extern void fxDDEnable(GLcontext
*, GLenum
, GLboolean
);
593 extern void fxDDAlphaFunc(GLcontext
*, GLenum
, GLclampf
);
594 extern void fxDDBlendFunc(GLcontext
*, GLenum
, GLenum
);
595 extern void fxDDDepthMask(GLcontext
*, GLboolean
);
596 extern void fxDDDepthFunc(GLcontext
*, GLenum
);
598 extern void fxDDRegisterVB( struct vertex_buffer
*VB
);
599 extern void fxDDUnregisterVB( struct vertex_buffer
*VB
);
600 extern void fxDDResizeVB( struct vertex_buffer
*VB
, GLuint size
);
602 extern void fxDDCheckMergeAndRender( GLcontext
*ctx
,
603 struct gl_pipeline_stage
*d
);
605 extern void fxDDMergeAndRender( struct vertex_buffer
*VB
);
607 extern void fxDDCheckPartialRasterSetup( GLcontext
*ctx
,
608 struct gl_pipeline_stage
*d
);
610 extern void fxDDPartialRasterSetup( struct vertex_buffer
*VB
);
612 extern void fxDDDoRasterSetup( struct vertex_buffer
*VB
);
614 extern GLuint
fxDDRegisterPipelineStages( struct gl_pipeline_stage
*out
,
615 const struct gl_pipeline_stage
*in
,
618 extern GLboolean
fxDDBuildPrecalcPipeline( GLcontext
*ctx
);
620 extern void fxDDOptimizePrecalcPipeline( GLcontext
*ctx
,
621 struct gl_pipeline
*pipe
);
623 extern void fxDDRenderElementsDirect( struct vertex_buffer
*VB
);
624 extern void fxDDRenderVBIndirectDirect( struct vertex_buffer
*VB
);
626 extern void fxDDInitExtensions( GLcontext
*ctx
);
628 #define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData))
629 extern void fxTMInit(fxMesaContext ctx
);
630 extern void fxTMClose(fxMesaContext ctx
);
631 extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx
);
632 extern void fxTMMoveInTM(fxMesaContext
, struct gl_texture_object
*, GLint
);
633 extern void fxTMMoveOutTM(fxMesaContext
, struct gl_texture_object
*);
634 #define fxTMMoveOutTM_NoLock fxTMMoveOutTM
635 extern void fxTMFreeTexture(fxMesaContext
, struct gl_texture_object
*);
636 extern void fxTMReloadMipMapLevel(fxMesaContext
, struct gl_texture_object
*, GLint
);
637 extern void fxTMReloadSubMipMapLevel(fxMesaContext
, struct gl_texture_object
*,
638 GLint
, GLint
, GLint
);
640 extern void fxTexGetFormat(GLenum
, GrTextureFormat_t
*, GLint
*);
641 extern int fxTexGetInfo(int, int, GrLOD_t
*, GrAspectRatio_t
*,
642 float *, float *, int *, int *, int *, int *);
644 extern void fxDDScissor( GLcontext
*ctx
,
645 GLint x
, GLint y
, GLsizei w
, GLsizei h
);
646 extern void fxDDFogfv( GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
);
647 extern GLboolean
fxDDColorMask(GLcontext
*ctx
,
648 GLboolean r
, GLboolean g
,
649 GLboolean b
, GLboolean a
);
651 extern void fxDDWriteDepthSpan(GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
652 const GLdepth depth
[], const GLubyte mask
[]);
654 extern void fxDDReadDepthSpan(GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
657 extern void fxDDWriteDepthPixels(GLcontext
*ctx
, GLuint n
,
658 const GLint x
[], const GLint y
[],
659 const GLdepth depth
[], const GLubyte mask
[]);
661 extern void fxDDReadDepthPixels(GLcontext
*ctx
, GLuint n
,
662 const GLint x
[], const GLint y
[],
665 extern void fxDDFastPath( struct vertex_buffer
*VB
);
667 extern void fxDDShadeModel(GLcontext
*ctx
, GLenum mode
);
669 extern void fxDDCullFace(GLcontext
*ctx
, GLenum mode
);
670 extern void fxDDFrontFace(GLcontext
*ctx
, GLenum mode
);
672 extern void fxPrintRenderState( const char *msg
, GLuint state
);
673 extern void fxPrintHintState( const char *msg
, GLuint state
);
675 extern void fxDDDoRenderVB( struct vertex_buffer
*VB
);
677 extern int fxDDInitFxMesaContext( fxMesaContext fxMesa
);
680 extern void fxSetScissorValues(GLcontext
*ctx
);
681 extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa
,
682 struct gl_texture_object
*tObj
,
684 extern void fxInitPixelTables(fxMesaContext fxMesa
, GLboolean bgrOrder
);