1 /* $Id: fxdrv.h,v 1.55 2002/11/04 20:29:04 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
34 /* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */
40 /* If you comment out this define, a variable takes its place, letting
41 * you turn debugging on/off from the debugger.
47 #if defined(__linux__)
57 #include "GL/fxmesa.h"
60 #include "math/m_vector.h"
63 /* Define some shorter names for these things.
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
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
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
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]
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])) )
99 #define FXCOLOR4( c ) (* (int *)c)
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])) )
111 /* fastpath flags first
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
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
130 /* Used for fxMesa->lastUnitsMode */
132 #define FX_UM_NONE 0x00000000
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
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
146 #define FX_UM_E_ENVMODE 0x000003ff
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
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
162 #define FX_UM_E_IFMT 0x00fff000
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
171 Memory range from startAddr to endAddr-1
173 typedef struct MemRange_t
175 struct MemRange_t
*next
;
176 FxU32 startAddr
, endAddr
;
182 GLsizei width
, height
; /* image size */
183 GLint wScale
, hScale
; /* image scale factor */
184 GrTextureFormat_t glideFormat
; /* Glide image format */
189 * TDFX-specific texture object data. This hangs off of the
190 * struct gl_texture_object DriverData pointer.
192 typedef struct tfxTexInfo_t
194 struct tfxTexInfo_t
*next
;
195 struct gl_texture_object
*tObj
;
201 MemRange
*tm
[FX_NUM_TMU
];
203 GLint minLevel
, maxLevel
;
204 GLint baseLevelInternalFormat
;
208 GrTextureFilterMode_t minFilt
;
209 GrTextureFilterMode_t maxFilt
;
212 GrTextureClampMode_t sClamp
;
213 GrTextureClampMode_t tClamp
;
215 GrMipMapMode_t mmMode
;
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
223 GuTexPalette palette
;
225 GLboolean fixedPalette
;
245 GLboolean alphaTestEnabled
;
246 GrCmpFnc_t alphaTestFunc
;
247 GrAlpha_t alphaTestRefValue
;
251 GLboolean blendEnabled
;
252 GrAlphaBlendFnc_t blendSrcFuncRGB
;
253 GrAlphaBlendFnc_t blendDstFuncRGB
;
254 GrAlphaBlendFnc_t blendSrcFuncAlpha
;
255 GrAlphaBlendFnc_t blendDstFuncAlpha
;
259 GLboolean depthTestEnabled
;
261 GrCmpFnc_t depthTestFunc
;
268 /* Flags for fxMesa->new_state
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
280 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
282 #define FX_TEXTURE_DATA(texUnit) fxTMGetTexInfo((texUnit)->_Current)
284 #define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData))
286 #define FX_MIPMAP_DATA(img) ((tfxMipMapLevel *) (img)->DriverData)
288 #define BEGIN_BOARD_LOCK()
289 #define END_BOARD_LOCK()
290 #define BEGIN_CLIP_LOOP()
291 #define END_CLIP_LOOP()
296 /* Covers the state referenced by IsInHardware:
298 #define _FX_NEW_IS_IN_HARDWARE (_NEW_TEXTURE| \
305 /* Covers the state referenced by fxDDChooseRenderState
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 | \
322 /* Covers the state referenced by fxDDChooseSetupFunction.
324 #define _FX_NEW_SETUP_FUNCTION (_NEW_LIGHT| \
330 /* These lookup table are used to extract RGB values in [0,255] from
331 * 16-bit pixel values.
333 extern GLubyte FX_PixelToR
[0x10000];
334 extern GLubyte FX_PixelToG
[0x10000];
335 extern GLubyte FX_PixelToB
[0x10000];
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
*);
342 struct tfxMesaContext
344 GuTexPalette glbPalette
;
346 GLcontext
*glCtx
; /* the core Mesa context */
347 GLvisual
*glVis
; /* describes the color buffer */
348 GLframebuffer
*glBuffer
; /* the ancillary buffers */
350 GLint board
; /* the board used for this context */
351 GLint width
, height
; /* size of color buffer */
353 GrBuffer_t currentFB
;
360 GrCullMode_t cullMode
;
362 tfxUnitsState unitsState
;
363 tfxUnitsState restoreUnitsState
; /* saved during multipass */
368 /* Texture Memory Manager Data
370 GLuint texBindNumber
;
372 GLuint lastUnitsMode
;
373 GLuint freeTexMem
[FX_NUM_TMU
];
375 MemRange
*tmFree
[FX_NUM_TMU
];
379 GLfloat fogStart
, fogEnd
;
383 /* Vertex building and storage:
385 GLuint tmu_source
[FX_NUM_TMU
];
387 GLuint stw_hint_state
; /* for grHints */
389 GLboolean snapVertices
; /* needed for older Voodoo hardware */
390 struct gl_client_array UbyteColor
;
395 GLuint is_in_hardware
;
396 GLenum render_primitive
;
397 GLenum raster_primitive
;
399 /* Current rasterization functions
401 fx_point_func draw_point
;
402 fx_line_func draw_line
;
403 fx_tri_func draw_tri
;
406 /* Keep texture scales somewhere handy:
426 GLboolean haveTwoTMUs
; /* True if we really have 2 tmu's */
427 GLboolean haveAlphaBuffer
;
428 GLboolean haveZBuffer
;
429 GLboolean haveDoubleBuffer
;
430 GLboolean haveGlobalPaletteTexture
;
432 GLint maxPendingSwapBuffers
;
434 FX_GrContext_t glideContext
;
446 extern GrHwConfiguration glbHWConfig
;
447 extern int glbCurrentBoard
;
449 extern void fxSetupFXUnits(GLcontext
*);
450 extern void fxSetupDDPointers(GLcontext
*);
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
,
460 extern void fxChooseVertexState( GLcontext
*ctx
);
469 extern void fxDDInitTriFuncs(GLcontext
*);
470 extern void fxDDChooseRenderState(GLcontext
* ctx
);
473 extern void fxUpdateDDSpanPointers(GLcontext
*);
474 extern void fxSetupDDSpanPointers(GLcontext
*);
476 extern void fxPrintTextureData(tfxTexInfo
* ti
);
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
);
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
);
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
);
511 extern void fxDDInitExtensions(GLcontext
* ctx
);
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
*,
522 extern void fxTMReloadSubMipMapLevel(fxMesaContext
,
523 struct gl_texture_object
*, GLint
, GLint
,
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 *);
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
);
536 extern void fxDDWriteDepthSpan(GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
,
537 const GLdepth depth
[], const GLubyte mask
[]);
539 extern void fxDDReadDepthSpan(GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
,
542 extern void fxDDWriteDepthPixels(GLcontext
* ctx
, GLuint n
,
543 const GLint x
[], const GLint y
[],
544 const GLdepth depth
[], const GLubyte mask
[]);
546 extern void fxDDReadDepthPixels(GLcontext
* ctx
, GLuint n
,
547 const GLint x
[], const GLint y
[],
550 extern void fxDDShadeModel(GLcontext
* ctx
, GLenum mode
);
552 extern void fxDDCullFace(GLcontext
* ctx
, GLenum mode
);
553 extern void fxDDFrontFace(GLcontext
* ctx
, GLenum mode
);
555 extern void fxPrintRenderState(const char *msg
, GLuint state
);
556 extern void fxPrintHintState(const char *msg
, GLuint state
);
558 extern int fxDDInitFxMesaContext(fxMesaContext fxMesa
);
559 extern void fxDDDestroyFxMesaContext(fxMesaContext fxMesa
);
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
);
569 extern void fxCheckIsInHardware(GLcontext
*ctx
);
571 extern GLboolean
fx_check_IsInHardware(GLcontext
*ctx
);