1 /* $Id: fxdrv.h,v 1.53 2002/06/13 04:28:30 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__)
58 #include "GL/fxmesa.h"
61 #include "math/m_vector.h"
64 /* Define some shorter names for these things.
66 #define XCOORD GR_VERTEX_X_OFFSET
67 #define YCOORD GR_VERTEX_Y_OFFSET
68 #define ZCOORD GR_VERTEX_OOZ_OFFSET
69 #define OOWCOORD GR_VERTEX_OOW_OFFSET
71 #define RCOORD GR_VERTEX_R_OFFSET
72 #define GCOORD GR_VERTEX_G_OFFSET
73 #define BCOORD GR_VERTEX_B_OFFSET
74 #define ACOORD GR_VERTEX_A_OFFSET
76 #define S0COORD GR_VERTEX_SOW_TMU0_OFFSET
77 #define T0COORD GR_VERTEX_TOW_TMU0_OFFSET
78 #define S1COORD GR_VERTEX_SOW_TMU1_OFFSET
79 #define T1COORD GR_VERTEX_TOW_TMU1_OFFSET
82 extern float gl_ubyte_to_float_255_color_tab
[256];
83 #define UBYTE_COLOR_TO_FLOAT_255_COLOR(c) gl_ubyte_to_float_255_color_tab[c]
84 #define UBYTE_COLOR_TO_FLOAT_255_COLOR2(f,c) \
85 (*(int *)&(f)) = ((int *)gl_ubyte_to_float_255_color_tab)[c]
91 #if defined(FXMESA_USE_ARGB)
92 #define FXCOLOR4( c ) ( \
93 ( ((unsigned int)(c[3]))<<24 ) | \
94 ( ((unsigned int)(c[0]))<<16 ) | \
95 ( ((unsigned int)(c[1]))<<8 ) | \
96 ( (unsigned int)(c[2])) )
100 #define FXCOLOR4( c ) (* (int *)c)
102 #define FXCOLOR4( c ) ( \
103 ( ((unsigned int)(c[3]))<<24 ) | \
104 ( ((unsigned int)(c[2]))<<16 ) | \
105 ( ((unsigned int)(c[1]))<<8 ) | \
106 ( (unsigned int)(c[0])) )
112 /* fastpath flags first
114 #define SETUP_TMU0 0x1
115 #define SETUP_TMU1 0x2
116 #define SETUP_RGBA 0x4
117 #define SETUP_SNAP 0x8
118 #define SETUP_XYZW 0x10
119 #define SETUP_PTEX 0x20
120 #define MAX_SETUP 0x40
125 #define FX_TMU0 GR_TMU0
126 #define FX_TMU1 GR_TMU1
127 #define FX_TMU_SPLIT 98
128 #define FX_TMU_BOTH 99
129 #define FX_TMU_NONE 100
131 /* Used for fxMesa->lastUnitsMode */
133 #define FX_UM_NONE 0x00000000
135 #define FX_UM_E0_REPLACE 0x00000001
136 #define FX_UM_E0_MODULATE 0x00000002
137 #define FX_UM_E0_DECAL 0x00000004
138 #define FX_UM_E0_BLEND 0x00000008
139 #define FX_UM_E0_ADD 0x00000010
141 #define FX_UM_E1_REPLACE 0x00000020
142 #define FX_UM_E1_MODULATE 0x00000040
143 #define FX_UM_E1_DECAL 0x00000080
144 #define FX_UM_E1_BLEND 0x00000100
145 #define FX_UM_E1_ADD 0x00000200
147 #define FX_UM_E_ENVMODE 0x000003ff
149 #define FX_UM_E0_ALPHA 0x00001000
150 #define FX_UM_E0_LUMINANCE 0x00002000
151 #define FX_UM_E0_LUMINANCE_ALPHA 0x00004000
152 #define FX_UM_E0_INTENSITY 0x00008000
153 #define FX_UM_E0_RGB 0x00010000
154 #define FX_UM_E0_RGBA 0x00020000
156 #define FX_UM_E1_ALPHA 0x00040000
157 #define FX_UM_E1_LUMINANCE 0x00080000
158 #define FX_UM_E1_LUMINANCE_ALPHA 0x00100000
159 #define FX_UM_E1_INTENSITY 0x00200000
160 #define FX_UM_E1_RGB 0x00400000
161 #define FX_UM_E1_RGBA 0x00800000
163 #define FX_UM_E_IFMT 0x00fff000
165 #define FX_UM_COLOR_ITERATED 0x01000000
166 #define FX_UM_COLOR_CONSTANT 0x02000000
167 #define FX_UM_ALPHA_ITERATED 0x04000000
168 #define FX_UM_ALPHA_CONSTANT 0x08000000
172 Memory range from startAddr to endAddr-1
174 typedef struct MemRange_t
176 struct MemRange_t
*next
;
177 FxU32 startAddr
, endAddr
;
183 GLsizei width
, height
; /* image size */
184 GLint wScale
, hScale
; /* image scale factor */
185 GrTextureFormat_t glideFormat
; /* Glide image format */
190 * TDFX-specific texture object data. This hangs off of the
191 * struct gl_texture_object DriverData pointer.
193 typedef struct tfxTexInfo_t
195 struct tfxTexInfo_t
*next
;
196 struct gl_texture_object
*tObj
;
202 MemRange
*tm
[FX_NUM_TMU
];
204 GLint minLevel
, maxLevel
;
205 GLint baseLevelInternalFormat
;
209 GrTextureFilterMode_t minFilt
;
210 GrTextureFilterMode_t maxFilt
;
213 GrTextureClampMode_t sClamp
;
214 GrTextureClampMode_t tClamp
;
216 GrMipMapMode_t mmMode
;
218 GLfloat sScale
, tScale
;
219 GLint int_sScale
, int_tScale
; /* x86 floating point trick for
220 * multiplication by powers of 2.
221 * Used in fxfasttmp.h
224 GuTexPalette palette
;
226 GLboolean fixedPalette
;
246 GLboolean alphaTestEnabled
;
247 GrCmpFnc_t alphaTestFunc
;
248 GrAlpha_t alphaTestRefValue
;
252 GLboolean blendEnabled
;
253 GrAlphaBlendFnc_t blendSrcFuncRGB
;
254 GrAlphaBlendFnc_t blendDstFuncRGB
;
255 GrAlphaBlendFnc_t blendSrcFuncAlpha
;
256 GrAlphaBlendFnc_t blendDstFuncAlpha
;
260 GLboolean depthTestEnabled
;
262 GrCmpFnc_t depthTestFunc
;
269 /* Flags for fxMesa->new_state
271 #define FX_NEW_TEXTURING 0x1
272 #define FX_NEW_BLEND 0x2
273 #define FX_NEW_ALPHA 0x4
274 #define FX_NEW_DEPTH 0x8
275 #define FX_NEW_FOG 0x10
276 #define FX_NEW_SCISSOR 0x20
277 #define FX_NEW_COLOR_MASK 0x40
278 #define FX_NEW_CULL 0x80
281 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
283 #define FX_TEXTURE_DATA(texUnit) fxTMGetTexInfo((texUnit)->_Current)
285 #define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData))
287 #define FX_MIPMAP_DATA(img) ((tfxMipMapLevel *) (img)->DriverData)
289 #define BEGIN_BOARD_LOCK()
290 #define END_BOARD_LOCK()
291 #define BEGIN_CLIP_LOOP()
292 #define END_CLIP_LOOP()
297 /* Covers the state referenced by IsInHardware:
299 #define _FX_NEW_IS_IN_HARDWARE (_NEW_TEXTURE| \
306 /* Covers the state referenced by fxDDChooseRenderState
308 #define _FX_NEW_RENDERSTATE (_FX_NEW_IS_IN_HARDWARE | \
309 _DD_NEW_FLATSHADE | \
310 _DD_NEW_TRI_LIGHT_TWOSIDE| \
311 _DD_NEW_TRI_OFFSET | \
312 _DD_NEW_TRI_UNFILLED | \
313 _DD_NEW_TRI_SMOOTH | \
314 _DD_NEW_TRI_STIPPLE | \
315 _DD_NEW_LINE_SMOOTH | \
316 _DD_NEW_LINE_STIPPLE | \
317 _DD_NEW_LINE_WIDTH | \
318 _DD_NEW_POINT_SMOOTH | \
319 _DD_NEW_POINT_SIZE | \
323 /* Covers the state referenced by fxDDChooseSetupFunction.
325 #define _FX_NEW_SETUP_FUNCTION (_NEW_LIGHT| \
331 /* These lookup table are used to extract RGB values in [0,255] from
332 * 16-bit pixel values.
334 extern GLubyte FX_PixelToR
[0x10000];
335 extern GLubyte FX_PixelToG
[0x10000];
336 extern GLubyte FX_PixelToB
[0x10000];
339 typedef void (*fx_tri_func
) (fxMesaContext
, GrVertex
*, GrVertex
*, GrVertex
*);
340 typedef void (*fx_line_func
) (fxMesaContext
, GrVertex
*, GrVertex
*);
341 typedef void (*fx_point_func
) (fxMesaContext
, GrVertex
*);
343 struct tfxMesaContext
345 GuTexPalette glbPalette
;
347 GLcontext
*glCtx
; /* the core Mesa context */
348 GLvisual
*glVis
; /* describes the color buffer */
349 GLframebuffer
*glBuffer
; /* the ancillary buffers */
351 GLint board
; /* the board used for this context */
352 GLint width
, height
; /* size of color buffer */
354 GrBuffer_t currentFB
;
361 GrCullMode_t cullMode
;
363 tfxUnitsState unitsState
;
364 tfxUnitsState restoreUnitsState
; /* saved during multipass */
369 /* Texture Memory Manager Data
371 GLuint texBindNumber
;
373 GLuint lastUnitsMode
;
374 GLuint freeTexMem
[FX_NUM_TMU
];
376 MemRange
*tmFree
[FX_NUM_TMU
];
380 GLfloat fogStart
, fogEnd
;
384 /* Vertex building and storage:
386 GLuint tmu_source
[FX_NUM_TMU
];
388 GLuint stw_hint_state
; /* for grHints */
390 GLboolean snapVertices
; /* needed for older Voodoo hardware */
391 struct gl_client_array UbyteColor
;
396 GLuint is_in_hardware
;
397 GLenum render_primitive
;
398 GLenum raster_primitive
;
400 /* Current rasterization functions
402 fx_point_func draw_point
;
403 fx_line_func draw_line
;
404 fx_tri_func draw_tri
;
407 /* Keep texture scales somewhere handy:
427 GLboolean haveTwoTMUs
; /* True if we really have 2 tmu's */
428 GLboolean haveAlphaBuffer
;
429 GLboolean haveZBuffer
;
430 GLboolean haveDoubleBuffer
;
431 GLboolean haveGlobalPaletteTexture
;
433 GLint maxPendingSwapBuffers
;
435 FX_GrContext_t glideContext
;
447 extern GrHwConfiguration glbHWConfig
;
448 extern int glbCurrentBoard
;
450 extern void fxSetupFXUnits(GLcontext
*);
451 extern void fxSetupDDPointers(GLcontext
*);
455 extern void fxAllocVB(GLcontext
* ctx
);
456 extern void fxFreeVB(GLcontext
* ctx
);
457 extern void fxPrintSetupFlags(char *msg
, GLuint flags
);
458 extern void fxCheckTexSizes( GLcontext
*ctx
);
459 extern void fxBuildVertices( GLcontext
*ctx
, GLuint start
, GLuint count
,
461 extern void fxChooseVertexState( GLcontext
*ctx
);
470 extern void fxDDInitTriFuncs(GLcontext
*);
471 extern void fxDDChooseRenderState(GLcontext
* ctx
);
474 extern void fxUpdateDDSpanPointers(GLcontext
*);
475 extern void fxSetupDDSpanPointers(GLcontext
*);
477 extern void fxPrintTextureData(tfxTexInfo
* ti
);
479 extern const struct gl_texture_format
*
480 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
481 GLenum srcFormat
, GLenum srcType
);
482 extern void fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
483 GLint internalFormat
, GLint width
, GLint height
,
484 GLint border
, GLenum format
, GLenum type
,
485 const GLvoid
* pixels
,
486 const struct gl_pixelstore_attrib
*packing
,
487 struct gl_texture_object
*texObj
,
488 struct gl_texture_image
*texImage
);
490 extern void fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
491 GLint xoffset
, GLint yoffset
,
492 GLsizei width
, GLsizei height
,
493 GLenum format
, GLenum type
,
494 const GLvoid
* pixels
,
495 const struct gl_pixelstore_attrib
*packing
,
496 struct gl_texture_object
*texObj
,
497 struct gl_texture_image
*texImage
);
498 extern void fxDDTexEnv(GLcontext
*, GLenum
, GLenum
, const GLfloat
*);
499 extern void fxDDTexParam(GLcontext
*, GLenum
, struct gl_texture_object
*,
500 GLenum
, const GLfloat
*);
501 extern void fxDDTexBind(GLcontext
*, GLenum
, struct gl_texture_object
*);
502 extern void fxDDTexDel(GLcontext
*, struct gl_texture_object
*);
503 extern void fxDDTexPalette(GLcontext
*, struct gl_texture_object
*);
504 extern void fxDDTexUseGlbPalette(GLcontext
*, GLboolean
);
506 extern void fxDDEnable(GLcontext
*, GLenum
, GLboolean
);
507 extern void fxDDAlphaFunc(GLcontext
*, GLenum
, GLchan
);
508 extern void fxDDBlendFunc(GLcontext
*, GLenum
, GLenum
);
509 extern void fxDDDepthMask(GLcontext
*, GLboolean
);
510 extern void fxDDDepthFunc(GLcontext
*, GLenum
);
512 extern void fxDDInitExtensions(GLcontext
* ctx
);
514 extern void fxTMInit(fxMesaContext ctx
);
515 extern void fxTMClose(fxMesaContext ctx
);
516 extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx
);
517 extern void fxTMMoveInTM(fxMesaContext
, struct gl_texture_object
*, GLint
);
518 extern void fxTMMoveOutTM(fxMesaContext
, struct gl_texture_object
*);
519 #define fxTMMoveOutTM_NoLock fxTMMoveOutTM
520 extern void fxTMFreeTexture(fxMesaContext
, struct gl_texture_object
*);
521 extern void fxTMReloadMipMapLevel(fxMesaContext
, struct gl_texture_object
*,
523 extern void fxTMReloadSubMipMapLevel(fxMesaContext
,
524 struct gl_texture_object
*, GLint
, GLint
,
527 extern void fxTexGetFormat(GLenum
, GrTextureFormat_t
*, GLint
*);
528 extern int fxTexGetInfo(int, int, GrLOD_t
*, GrAspectRatio_t
*,
529 float *, float *, int *, int *, int *, int *);
531 extern void fxDDScissor(GLcontext
* ctx
,
532 GLint x
, GLint y
, GLsizei w
, GLsizei h
);
533 extern void fxDDFogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* params
);
534 extern void fxDDColorMask(GLcontext
* ctx
,
535 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
);
537 extern void fxDDWriteDepthSpan(GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
,
538 const GLdepth depth
[], const GLubyte mask
[]);
540 extern void fxDDReadDepthSpan(GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
,
543 extern void fxDDWriteDepthPixels(GLcontext
* ctx
, GLuint n
,
544 const GLint x
[], const GLint y
[],
545 const GLdepth depth
[], const GLubyte mask
[]);
547 extern void fxDDReadDepthPixels(GLcontext
* ctx
, GLuint n
,
548 const GLint x
[], const GLint y
[],
551 extern void fxDDShadeModel(GLcontext
* ctx
, GLenum mode
);
553 extern void fxDDCullFace(GLcontext
* ctx
, GLenum mode
);
554 extern void fxDDFrontFace(GLcontext
* ctx
, GLenum mode
);
556 extern void fxPrintRenderState(const char *msg
, GLuint state
);
557 extern void fxPrintHintState(const char *msg
, GLuint state
);
559 extern int fxDDInitFxMesaContext(fxMesaContext fxMesa
);
560 extern void fxDDDestroyFxMesaContext(fxMesaContext fxMesa
);
565 extern void fxSetScissorValues(GLcontext
* ctx
);
566 extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa
,
567 struct gl_texture_object
*tObj
, GLint where
);
568 extern void fxInitPixelTables(fxMesaContext fxMesa
, GLboolean bgrOrder
);
570 extern void fxCheckIsInHardware(GLcontext
*ctx
);
572 extern GLboolean
fx_check_IsInHardware(GLcontext
*ctx
);