3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
26 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
29 * Thank you for your contribution, David!
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.
37 * Additional Mesa/3Dfx driver developers:
38 * Daryll Strauss <daryll@precisioninsight.com>
39 * Keith Whitwell <keith@precisioninsight.com>
41 * See fxapi.h for more revision/author details.
48 /* If you comment out this define, a variable takes its place, letting
49 * you turn debugging on/off from the debugger.
55 #if defined(__linux__)
65 #include "GL/fxmesa.h"
68 #include "math/m_vector.h"
71 /* Define some shorter names for these things.
73 #define XCOORD GR_VERTEX_X_OFFSET
74 #define YCOORD GR_VERTEX_Y_OFFSET
75 #define ZCOORD GR_VERTEX_OOZ_OFFSET
76 #define OOWCOORD GR_VERTEX_OOW_OFFSET
78 #define RCOORD GR_VERTEX_R_OFFSET
79 #define GCOORD GR_VERTEX_G_OFFSET
80 #define BCOORD GR_VERTEX_B_OFFSET
81 #define ACOORD GR_VERTEX_A_OFFSET
83 #define S0COORD GR_VERTEX_SOW_TMU0_OFFSET
84 #define T0COORD GR_VERTEX_TOW_TMU0_OFFSET
85 #define S1COORD GR_VERTEX_SOW_TMU1_OFFSET
86 #define T1COORD GR_VERTEX_TOW_TMU1_OFFSET
89 extern float gl_ubyte_to_float_255_color_tab
[256];
90 #define UBYTE_COLOR_TO_FLOAT_255_COLOR(c) gl_ubyte_to_float_255_color_tab[c]
91 #define UBYTE_COLOR_TO_FLOAT_255_COLOR2(f,c) \
92 (*(int *)&(f)) = ((int *)gl_ubyte_to_float_255_color_tab)[c]
98 #if defined(FXMESA_USE_ARGB)
99 #define FXCOLOR4( c ) ( \
100 ( ((unsigned int)(c[3]))<<24 ) | \
101 ( ((unsigned int)(c[0]))<<16 ) | \
102 ( ((unsigned int)(c[1]))<<8 ) | \
103 ( (unsigned int)(c[2])) )
107 #define FXCOLOR4( c ) (* (int *)c)
109 #define FXCOLOR4( c ) ( \
110 ( ((unsigned int)(c[3]))<<24 ) | \
111 ( ((unsigned int)(c[2]))<<16 ) | \
112 ( ((unsigned int)(c[1]))<<8 ) | \
113 ( (unsigned int)(c[0])) )
119 /* fastpath flags first
121 #define SETUP_TMU0 0x1
122 #define SETUP_TMU1 0x2
123 #define SETUP_RGBA 0x4
124 #define SETUP_SNAP 0x8
125 #define SETUP_XYZW 0x10
126 #define SETUP_PTEX 0x20
127 #define MAX_SETUP 0x40
132 #define FX_TMU0 GR_TMU0
133 #define FX_TMU1 GR_TMU1
134 #define FX_TMU_SPLIT 98
135 #define FX_TMU_BOTH 99
136 #define FX_TMU_NONE 100
138 /* Used for fxMesa->lastUnitsMode */
140 #define FX_UM_NONE 0x00000000
142 #define FX_UM_E0_REPLACE 0x00000001
143 #define FX_UM_E0_MODULATE 0x00000002
144 #define FX_UM_E0_DECAL 0x00000004
145 #define FX_UM_E0_BLEND 0x00000008
146 #define FX_UM_E0_ADD 0x00000010
148 #define FX_UM_E1_REPLACE 0x00000020
149 #define FX_UM_E1_MODULATE 0x00000040
150 #define FX_UM_E1_DECAL 0x00000080
151 #define FX_UM_E1_BLEND 0x00000100
152 #define FX_UM_E1_ADD 0x00000200
154 #define FX_UM_E_ENVMODE 0x000003ff
156 #define FX_UM_E0_ALPHA 0x00001000
157 #define FX_UM_E0_LUMINANCE 0x00002000
158 #define FX_UM_E0_LUMINANCE_ALPHA 0x00004000
159 #define FX_UM_E0_INTENSITY 0x00008000
160 #define FX_UM_E0_RGB 0x00010000
161 #define FX_UM_E0_RGBA 0x00020000
163 #define FX_UM_E1_ALPHA 0x00040000
164 #define FX_UM_E1_LUMINANCE 0x00080000
165 #define FX_UM_E1_LUMINANCE_ALPHA 0x00100000
166 #define FX_UM_E1_INTENSITY 0x00200000
167 #define FX_UM_E1_RGB 0x00400000
168 #define FX_UM_E1_RGBA 0x00800000
170 #define FX_UM_E_IFMT 0x00fff000
172 #define FX_UM_COLOR_ITERATED 0x01000000
173 #define FX_UM_COLOR_CONSTANT 0x02000000
174 #define FX_UM_ALPHA_ITERATED 0x04000000
175 #define FX_UM_ALPHA_CONSTANT 0x08000000
179 Memory range from startAddr to endAddr-1
181 typedef struct MemRange_t
183 struct MemRange_t
*next
;
184 FxU32 startAddr
, endAddr
;
190 GLsizei width
, height
; /* image size */
191 GLint wScale
, hScale
; /* image scale factor */
192 GrTextureFormat_t glideFormat
; /* Glide image format */
197 * TDFX-specific texture object data. This hangs off of the
198 * struct gl_texture_object DriverData pointer.
200 typedef struct tfxTexInfo_t
202 struct tfxTexInfo_t
*next
;
203 struct gl_texture_object
*tObj
;
209 MemRange
*tm
[FX_NUM_TMU
];
211 GLint minLevel
, maxLevel
;
212 GLint baseLevelInternalFormat
;
216 GrTextureFilterMode_t minFilt
;
217 GrTextureFilterMode_t maxFilt
;
220 GrTextureClampMode_t sClamp
;
221 GrTextureClampMode_t tClamp
;
223 GrMipMapMode_t mmMode
;
225 GLfloat sScale
, tScale
;
226 GLint int_sScale
, int_tScale
; /* x86 floating point trick for
227 * multiplication by powers of 2.
228 * Used in fxfasttmp.h
231 GuTexPalette palette
;
233 GLboolean fixedPalette
;
253 GLboolean alphaTestEnabled
;
254 GrCmpFnc_t alphaTestFunc
;
255 GrAlpha_t alphaTestRefValue
;
259 GLboolean blendEnabled
;
260 GrAlphaBlendFnc_t blendSrcFuncRGB
;
261 GrAlphaBlendFnc_t blendDstFuncRGB
;
262 GrAlphaBlendFnc_t blendSrcFuncAlpha
;
263 GrAlphaBlendFnc_t blendDstFuncAlpha
;
267 GLboolean depthTestEnabled
;
269 GrCmpFnc_t depthTestFunc
;
276 /* Flags for fxMesa->new_state
278 #define FX_NEW_TEXTURING 0x1
279 #define FX_NEW_BLEND 0x2
280 #define FX_NEW_ALPHA 0x4
281 #define FX_NEW_DEPTH 0x8
282 #define FX_NEW_FOG 0x10
283 #define FX_NEW_SCISSOR 0x20
284 #define FX_NEW_COLOR_MASK 0x40
285 #define FX_NEW_CULL 0x80
288 #define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx))
290 #define FX_TEXTURE_DATA(texUnit) fxTMGetTexInfo((texUnit)->_Current)
292 #define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData))
294 #define FX_MIPMAP_DATA(img) ((tfxMipMapLevel *) (img)->DriverData)
296 #define BEGIN_BOARD_LOCK()
297 #define END_BOARD_LOCK()
298 #define BEGIN_CLIP_LOOP()
299 #define END_CLIP_LOOP()
304 /* Covers the state referenced by IsInHardware:
306 #define _FX_NEW_IS_IN_HARDWARE (_NEW_TEXTURE| \
313 /* Covers the state referenced by fxDDChooseRenderState
315 #define _FX_NEW_RENDERSTATE (_FX_NEW_IS_IN_HARDWARE | \
316 _DD_NEW_FLATSHADE | \
317 _DD_NEW_TRI_LIGHT_TWOSIDE| \
318 _DD_NEW_TRI_OFFSET | \
319 _DD_NEW_TRI_UNFILLED | \
320 _DD_NEW_TRI_SMOOTH | \
321 _DD_NEW_TRI_STIPPLE | \
322 _DD_NEW_LINE_SMOOTH | \
323 _DD_NEW_LINE_STIPPLE | \
324 _DD_NEW_LINE_WIDTH | \
325 _DD_NEW_POINT_SMOOTH | \
326 _DD_NEW_POINT_SIZE | \
330 /* Covers the state referenced by fxDDChooseSetupFunction.
332 #define _FX_NEW_SETUP_FUNCTION (_NEW_LIGHT| \
338 /* These lookup table are used to extract RGB values in [0,255] from
339 * 16-bit pixel values.
341 extern GLubyte FX_PixelToR
[0x10000];
342 extern GLubyte FX_PixelToG
[0x10000];
343 extern GLubyte FX_PixelToB
[0x10000];
346 typedef void (*fx_tri_func
) (fxMesaContext
, GrVertex
*, GrVertex
*, GrVertex
*);
347 typedef void (*fx_line_func
) (fxMesaContext
, GrVertex
*, GrVertex
*);
348 typedef void (*fx_point_func
) (fxMesaContext
, GrVertex
*);
350 struct tfxMesaContext
352 GuTexPalette glbPalette
;
354 GLcontext
*glCtx
; /* the core Mesa context */
355 GLvisual
*glVis
; /* describes the color buffer */
356 GLframebuffer
*glBuffer
; /* the ancillary buffers */
358 GLint board
; /* the board used for this context */
359 GLint width
, height
; /* size of color buffer */
361 GrBuffer_t currentFB
;
368 GrCullMode_t cullMode
;
370 tfxUnitsState unitsState
;
371 tfxUnitsState restoreUnitsState
; /* saved during multipass */
376 /* Texture Memory Manager Data
378 GLuint texBindNumber
;
380 GLuint lastUnitsMode
;
381 GLuint freeTexMem
[FX_NUM_TMU
];
383 MemRange
*tmFree
[FX_NUM_TMU
];
387 GLfloat fogStart
, fogEnd
;
391 /* Vertex building and storage:
393 GLuint tmu_source
[FX_NUM_TMU
];
395 GLuint stw_hint_state
; /* for grHints */
397 GLboolean snapVertices
; /* needed for older Voodoo hardware */
398 struct gl_client_array UbyteColor
;
403 GLuint is_in_hardware
;
404 GLenum render_primitive
;
405 GLenum raster_primitive
;
407 /* Current rasterization functions
409 fx_point_func draw_point
;
410 fx_line_func draw_line
;
411 fx_tri_func draw_tri
;
414 /* Keep texture scales somewhere handy:
434 GLboolean haveTwoTMUs
; /* True if we really have 2 tmu's */
435 GLboolean haveAlphaBuffer
;
436 GLboolean haveZBuffer
;
437 GLboolean haveDoubleBuffer
;
438 GLboolean haveGlobalPaletteTexture
;
440 GLint maxPendingSwapBuffers
;
442 FX_GrContext_t glideContext
;
454 extern GrHwConfiguration glbHWConfig
;
455 extern int glbCurrentBoard
;
457 extern void fxSetupFXUnits(GLcontext
*);
458 extern void fxSetupDDPointers(GLcontext
*);
462 extern void fxAllocVB(GLcontext
* ctx
);
463 extern void fxFreeVB(GLcontext
* ctx
);
464 extern void fxPrintSetupFlags(char *msg
, GLuint flags
);
465 extern void fxCheckTexSizes( GLcontext
*ctx
);
466 extern void fxBuildVertices( GLcontext
*ctx
, GLuint start
, GLuint count
,
468 extern void fxChooseVertexState( GLcontext
*ctx
);
477 extern void fxDDInitTriFuncs(GLcontext
*);
478 extern void fxDDChooseRenderState(GLcontext
* ctx
);
481 extern void fxUpdateDDSpanPointers(GLcontext
*);
482 extern void fxSetupDDSpanPointers(GLcontext
*);
484 extern void fxPrintTextureData(tfxTexInfo
* ti
);
486 extern const struct gl_texture_format
*
487 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
488 GLenum srcFormat
, GLenum srcType
);
489 extern void fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
490 GLint internalFormat
, GLint width
, GLint height
,
491 GLint border
, GLenum format
, GLenum type
,
492 const GLvoid
* pixels
,
493 const struct gl_pixelstore_attrib
*packing
,
494 struct gl_texture_object
*texObj
,
495 struct gl_texture_image
*texImage
);
497 extern void fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
498 GLint xoffset
, GLint yoffset
,
499 GLsizei width
, GLsizei height
,
500 GLenum format
, GLenum type
,
501 const GLvoid
* pixels
,
502 const struct gl_pixelstore_attrib
*packing
,
503 struct gl_texture_object
*texObj
,
504 struct gl_texture_image
*texImage
);
505 extern void fxDDTexEnv(GLcontext
*, GLenum
, GLenum
, const GLfloat
*);
506 extern void fxDDTexParam(GLcontext
*, GLenum
, struct gl_texture_object
*,
507 GLenum
, const GLfloat
*);
508 extern void fxDDTexBind(GLcontext
*, GLenum
, struct gl_texture_object
*);
509 extern void fxDDTexDel(GLcontext
*, struct gl_texture_object
*);
510 extern void fxDDTexPalette(GLcontext
*, struct gl_texture_object
*);
511 extern void fxDDTexUseGlbPalette(GLcontext
*, GLboolean
);
513 extern void fxDDEnable(GLcontext
*, GLenum
, GLboolean
);
514 extern void fxDDAlphaFunc(GLcontext
*, GLenum
, GLchan
);
515 extern void fxDDBlendFunc(GLcontext
*, GLenum
, GLenum
);
516 extern void fxDDDepthMask(GLcontext
*, GLboolean
);
517 extern void fxDDDepthFunc(GLcontext
*, GLenum
);
519 extern void fxDDInitExtensions(GLcontext
* ctx
);
521 extern void fxTMInit(fxMesaContext ctx
);
522 extern void fxTMClose(fxMesaContext ctx
);
523 extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx
);
524 extern void fxTMMoveInTM(fxMesaContext
, struct gl_texture_object
*, GLint
);
525 extern void fxTMMoveOutTM(fxMesaContext
, struct gl_texture_object
*);
526 #define fxTMMoveOutTM_NoLock fxTMMoveOutTM
527 extern void fxTMFreeTexture(fxMesaContext
, struct gl_texture_object
*);
528 extern void fxTMReloadMipMapLevel(fxMesaContext
, struct gl_texture_object
*,
530 extern void fxTMReloadSubMipMapLevel(fxMesaContext
,
531 struct gl_texture_object
*, GLint
, GLint
,
534 extern void fxTexGetFormat(GLenum
, GrTextureFormat_t
*, GLint
*);
535 extern int fxTexGetInfo(int, int, GrLOD_t
*, GrAspectRatio_t
*,
536 float *, float *, int *, int *, int *, int *);
538 extern void fxDDScissor(GLcontext
* ctx
,
539 GLint x
, GLint y
, GLsizei w
, GLsizei h
);
540 extern void fxDDFogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* params
);
541 extern void fxDDColorMask(GLcontext
* ctx
,
542 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
);
544 extern void fxDDWriteDepthSpan(GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
,
545 const GLdepth depth
[], const GLubyte mask
[]);
547 extern void fxDDReadDepthSpan(GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
,
550 extern void fxDDWriteDepthPixels(GLcontext
* ctx
, GLuint n
,
551 const GLint x
[], const GLint y
[],
552 const GLdepth depth
[], const GLubyte mask
[]);
554 extern void fxDDReadDepthPixels(GLcontext
* ctx
, GLuint n
,
555 const GLint x
[], const GLint y
[],
558 extern void fxDDShadeModel(GLcontext
* ctx
, GLenum mode
);
560 extern void fxDDCullFace(GLcontext
* ctx
, GLenum mode
);
561 extern void fxDDFrontFace(GLcontext
* ctx
, GLenum mode
);
563 extern void fxPrintRenderState(const char *msg
, GLuint state
);
564 extern void fxPrintHintState(const char *msg
, GLuint state
);
566 extern int fxDDInitFxMesaContext(fxMesaContext fxMesa
);
567 extern void fxDDDestroyFxMesaContext(fxMesaContext fxMesa
);
572 extern void fxSetScissorValues(GLcontext
* ctx
);
573 extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa
,
574 struct gl_texture_object
*tObj
, GLint where
);
575 extern void fxInitPixelTables(fxMesaContext fxMesa
, GLboolean bgrOrder
);
577 extern void fxCheckIsInHardware(GLcontext
*ctx
);
579 extern GLboolean
fx_check_IsInHardware(GLcontext
*ctx
);