1 /* -*- mode: c; c-basic-offset: 3 -*-
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.h,v 1.5 2002/02/24 21:51:10 dawes Exp $ */
30 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
33 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
36 * Gareth Hughes <gareth@valinux.com>
40 #ifndef __TDFX_CONTEXT_H__
41 #define __TDFX_CONTEXT_H__
43 #ifdef GLX_DIRECT_RENDERING
48 #include "GL/xf86glx.h"
52 #if defined(__linux__)
57 #include "drm_sarea.h"
58 #include "tdfx_glide.h"
67 #include "tdfx_screen.h"
72 #define TDFX_TMU0 GR_TMU0
73 #define TDFX_TMU1 GR_TMU1
74 #define TDFX_TMU_SPLIT 98
75 #define TDFX_TMU_BOTH 99
76 #define TDFX_TMU_NONE 100
80 /* Flags for fxMesa->new_state
82 #define TDFX_NEW_COLOR 0x0001
83 #define TDFX_NEW_ALPHA 0x0002
84 #define TDFX_NEW_DEPTH 0x0004
85 #define TDFX_NEW_FOG 0x0008
86 #define TDFX_NEW_STENCIL 0x0010
87 #define TDFX_NEW_CLIP 0x0020
88 #define TDFX_NEW_VIEWPORT 0x0040
89 #define TDFX_NEW_CULL 0x0080
90 #define TDFX_NEW_GLIDE 0x0100
91 #define TDFX_NEW_TEXTURE 0x0200
92 #define TDFX_NEW_CONTEXT 0x0400
93 #define TDFX_NEW_LINE 0x0800
94 #define TDFX_NEW_RENDER 0x1000
95 #define TDFX_NEW_STIPPLE 0x2000
96 #define TDFX_NEW_TEXTURE_BIND 0x4000 /* experimental */
99 /* Flags for fxMesa->dirty
101 #define TDFX_UPLOAD_COLOR_COMBINE 0x00000001
102 #define TDFX_UPLOAD_ALPHA_COMBINE 0x00000002
103 #define TDFX_UPLOAD_RENDER_BUFFER 0x00000004
104 #define TDFX_UPLOAD_ALPHA_TEST 0x00000008
105 #define TDFX_UPLOAD_ALPHA_REF 0x00000010
106 #define TDFX_UPLOAD_BLEND_FUNC 0x00000020
107 #define TDFX_UPLOAD_DEPTH_MODE 0x00000040
108 #define TDFX_UPLOAD_DEPTH_BIAS 0x00000080
109 #define TDFX_UPLOAD_DEPTH_FUNC 0x00000100
110 #define TDFX_UPLOAD_DEPTH_MASK 0x00000200
111 #define TDFX_UPLOAD_FOG_MODE 0x00000400
112 #define TDFX_UPLOAD_FOG_COLOR 0x00000800
113 #define TDFX_UPLOAD_FOG_TABLE 0x00001000
114 #define TDFX_UPLOAD_CONSTANT_COLOR 0x00002000
116 #define TDFX_UPLOAD_CLIP 0x00002000
117 #define TDFX_UPLOAD_CULL 0x00004000
118 #define TDFX_UPLOAD_VERTEX_LAYOUT 0x00008000
119 #define TDFX_UPLOAD_COLOR_MASK 0x00010000
120 #define TDFX_UPLOAD_DITHER 0x00040000
121 #define TDFX_UPLOAD_STENCIL 0x00080000
123 #define TDFX_UPLOAD_TEXTURE_SOURCE 0x00100000
124 #define TDFX_UPLOAD_TEXTURE_PARAMS 0x00200000
125 #define TDFX_UPLOAD_TEXTURE_PALETTE 0x00400000
126 #define TDFX_UPLOAD_TEXTURE_ENV 0x00800000
127 #define TDFX_UPLOAD_TEXTURE_IMAGES 0x01000000
129 #define TDFX_UPLOAD_LINE 0x02000000
131 #define TDFX_UPLOAD_STIPPLE 0x04000000
133 /* Flags for software fallback cases */
134 /* See correponding strings in tdfx_tris.c */
135 #define TDFX_FALLBACK_TEXTURE_MAP 0x0001
136 #define TDFX_FALLBACK_DRAW_BUFFER 0x0002
137 #define TDFX_FALLBACK_SPECULAR 0x0004
138 #define TDFX_FALLBACK_STENCIL 0x0008
139 #define TDFX_FALLBACK_RENDER_MODE 0x0010
140 #define TDFX_FALLBACK_LOGICOP 0x0020
141 #define TDFX_FALLBACK_TEXTURE_ENV 0x0040
142 #define TDFX_FALLBACK_TEXTURE_BORDER 0x0080
143 #define TDFX_FALLBACK_COLORMASK 0x0100
144 #define TDFX_FALLBACK_BLEND 0x0200
145 #define TDFX_FALLBACK_LINE_STIPPLE 0x0400
147 /* Different Glide vertex layouts
149 #define TDFX_LAYOUT_TINY 0
150 #define TDFX_LAYOUT_NOTEX 1
151 #define TDFX_LAYOUT_SINGLE 2
152 #define TDFX_LAYOUT_MULTI 3
153 #define TDFX_LAYOUT_PROJ1 4
154 #define TDFX_LAYOUT_PROJ2 5
155 #define TDFX_NUM_LAYOUTS 6
157 #define TDFX_XY_OFFSET 0
158 #define TDFX_Z_OFFSET 8
159 #define TDFX_Q_OFFSET 12
160 #define TDFX_ARGB_OFFSET 16
161 #define TDFX_FOG_OFFSET 20
162 #define TDFX_ST0_OFFSET 24
163 #define TDFX_ST1_OFFSET 32
164 #define TDFX_Q0_OFFSET 40
165 #define TDFX_Q1_OFFSET 44
168 /* Flags for buffer clears
170 #define TDFX_FRONT 0x1
171 #define TDFX_BACK 0x2
172 #define TDFX_DEPTH 0x4
173 #define TDFX_STENCIL 0x8
176 * Subpixel offsets to adjust Mesa's (true) window coordinates to
177 * Glide coordinates. We need these to ensure precise rasterization.
178 * Otherwise, we'll fail a bunch of conformance tests.
180 #define TRI_X_OFFSET ( 0.0F)
181 #define TRI_Y_OFFSET ( 0.0F)
182 #define LINE_X_OFFSET ( 0.0F)
183 #define LINE_Y_OFFSET ( 0.125F)
184 #define PNT_X_OFFSET ( 0.375F)
185 #define PNT_Y_OFFSET ( 0.375F)
188 #define TDFX_DEPTH_BIAS_SCALE 128
190 /* Including xf86PciInfo.h causes a bunch of errors
192 #ifndef PCI_CHIP_BANSHEE
193 #define PCI_CHIP_BANSHEE 0x0003
194 #define PCI_CHIP_VOODOO3 0x0005
195 #define PCI_CHIP_VOODOO4 0x0009
196 #define PCI_CHIP_VOODOO5 0x0009
199 #define TDFX_IS_BANSHEE( fxMesa ) \
200 ( fxMesa->fxScreen->deviceID == PCI_CHIP_BANSHEE )
201 #define TDFX_IS_VOODOO3( fxMesa ) \
202 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO3 )
203 #define TDFX_IS_VOODOO4( fxMesa ) \
204 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4 )
205 #define TDFX_IS_VOODOO5( fxMesa ) \
206 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5 )
207 #define TDFX_IS_NAPALM( fxMesa ) \
208 ( (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4) || \
209 (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5) )
212 #define PACK_BGRA32(R, G, B, A) \
213 ( (((GLuint) (R)) << 16) | \
214 (((GLuint) (G)) << 8) | \
215 (((GLuint) (B)) ) | \
216 (((GLuint) (A)) << 24) )
218 #define PACK_RGBA32(R, G, B, A) \
219 ( (((GLuint) (R)) ) | \
220 (((GLuint) (G)) << 8) | \
221 (((GLuint) (B)) << 16) | \
222 (((GLuint) (A)) << 24) )
225 * The first two macros are to pack 8 bit color
226 * channel values into a 565 format.
228 #define PACK_RGB16(R, G, B) \
229 ((((GLuint) (R) & 0xF8) << 8) | \
230 (((GLuint) (G) & 0xFC) << 3) | \
231 (((GLuint) (B) & 0xFF) >> 3))
232 #define PACK_BGR16(R, G, B) \
233 ((((GLuint) (B) & 0xF8) << 8) | \
234 (((GLuint) (G) & 0xFC) << 3) | \
235 (((GLuint) (R) & 0xFF) >> 3))
237 * The second two macros pack 8 bit color channel values
240 #define PACK_RGBA16(R, G, B, A) \
241 (((((GLuint) (A) & 0xFF) > 0) << 15)| \
242 (((GLuint) (R) & 0xF8) << 7) | \
243 (((GLuint) (G) & 0xF8) << 2) | \
244 (((GLuint) (B) & 0xF8) >> 3))
245 #define PACK_BGRA16(R, G, B, A) \
246 (((((GLuint) (A) & 0xFF) > 0) << 15)| \
247 (((GLuint) (B) & 0xF8) << 7) | \
248 (((GLuint) (G) & 0xF8) << 2) | \
249 (((GLuint) (R) & 0xF8) >> 3))
251 /* Used in calls to grColorMaskv()...
253 extern const GLboolean false4
[4];
254 extern const GLboolean true4
[4];
257 typedef struct tdfx_context tdfxContextRec
;
258 typedef struct tdfx_context
*tdfxContextPtr
;
262 volatile int fifoPtr
;
263 volatile int fifoRead
;
264 volatile int fifoOwner
;
265 volatile int ctxOwner
;
266 volatile int texOwner
;
282 * Memory range from startAddr to endAddr-1
284 typedef struct mem_range
{
285 struct mem_range
*next
;
286 FxU32 startAddr
, endAddr
;
292 GLsizei width
, height
; /* image size */
293 GLint wScale
, hScale
; /* scale factors */
294 GrTextureFormat_t glideFormat
; /* Glide image format */
299 #define TDFX_NUM_TMU 2
302 typedef struct tdfxTexInfo_t
305 GLboolean reloadImages
; /* if true, resend images to Glide */
310 GrAspectRatio_t aspectRatio
;
311 tdfxMemRange
*tm
[TDFX_NUM_TMU
];
313 GLint minLevel
, maxLevel
;
314 GrTextureFilterMode_t minFilt
;
315 GrTextureFilterMode_t magFilt
;
316 GrTextureClampMode_t sClamp
;
317 GrTextureClampMode_t tClamp
;
319 GrMipMapMode_t mmMode
;
321 GLfloat sScale
, tScale
; /* texcoord scale factor */
323 GrTexTable_t paltype
;
324 GuTexPalette palette
;
331 #define TDFX_TEXTURE_DATA(mesaObj) ((tdfxTexInfo *)((mesaObj)->DriverData))
333 #define TDFX_TEXIMAGE_DATA(mesaImg) ((tdfxMipMapLevel *)((mesaImg)->DriverData))
338 * This is state which may be shared by several tdfx contexts.
339 * It hangs off of Mesa's gl_shared_state object (ctx->Shared->DriverData).
341 struct tdfxSharedState
{
342 GLboolean umaTexMemory
;
343 GLuint totalTexMem
[TDFX_NUM_TMU
]; /* constant */
344 GLuint freeTexMem
[TDFX_NUM_TMU
]; /* changes as we go */
345 tdfxMemRange
*tmPool
;
346 tdfxMemRange
*tmFree
[TDFX_NUM_TMU
];
351 /* ================================================================
352 * The vertex structures.
354 /* The size of this union is not of relevence:
356 typedef struct tdfx_vertex_t
{
357 GLfloat x
, y
, z
; /* Coordinates in screen space */
358 GLfloat rhw
; /* Reciprocal homogeneous w */
359 GLubyte color
[4]; /* Diffuse color */
361 GLfloat tu0
, tv0
; /* Texture 0 coordinates */
362 GLfloat tu1
, tv1
; /* Texture 1 coordinates */
363 GLfloat tq0
, tq1
; /* Texture 0/1 q coords */
364 unsigned char pspec
[4]; /* B, G, R, A [0..255] */
365 float psize
; /* point size */
366 long pad
[16 - 14]; /* ensure 64b structure */
367 } tdfxVertex
, *tdfxVertexPtr
;
370 /* ================================================================
372 * We want to keep a mirror of the Glide function call parameters so we
373 * can avoid updating our state too often.
375 * Each of these broad groups will typically have a new state flag
376 * associated with it, and will be updated together. The individual
377 * Glide function calls each have a dirty flag and will only be called
378 * when absolutely necessary.
381 /* for grTexSource() */
382 struct tdfx_texsource
{
388 /* Texture object params */
389 struct tdfx_texparams
{
390 GrTextureClampMode_t sClamp
;
391 GrTextureClampMode_t tClamp
;
392 GrTextureFilterMode_t minFilt
;
393 GrTextureFilterMode_t magFilt
;
394 GrMipMapMode_t mmMode
;
399 /* for grTexDownloadTable() texture palettes */
400 struct tdfx_texpalette
{
405 /* for Voodoo3/Banshee's grColorCombine() and grAlphaCombine() */
406 struct tdfx_combine
{
407 GrCombineFunction_t Function
; /* Combine function */
408 GrCombineFactor_t Factor
; /* Combine scale factor */
409 GrCombineLocal_t Local
; /* Local combine source */
410 GrCombineOther_t Other
; /* Other combine source */
411 FxBool Invert
; /* Combine result inversion flag */
414 /* for Voodoo3's grTexCombine() */
415 struct tdfx_texcombine
{
416 GrCombineFunction_t FunctionRGB
;
417 GrCombineFactor_t FactorRGB
;
418 GrCombineFunction_t FunctionAlpha
;
419 GrCombineFactor_t FactorAlpha
;
425 /* for Voodoo5's grColorCombineExt() */
426 struct tdfx_combine_color_ext
{
427 GrCCUColor_t SourceA
;
428 GrCombineMode_t ModeA
;
429 GrCCUColor_t SourceB
;
430 GrCombineMode_t ModeB
;
431 GrCCUColor_t SourceC
;
433 GrCCUColor_t SourceD
;
439 /* for Voodoo5's grAlphaCombineExt() */
440 struct tdfx_combine_alpha_ext
{
441 GrACUColor_t SourceA
;
442 GrCombineMode_t ModeA
;
443 GrACUColor_t SourceB
;
444 GrCombineMode_t ModeB
;
445 GrACUColor_t SourceC
;
447 GrACUColor_t SourceD
;
453 /* for Voodoo5's grTexColorCombineExt() */
454 struct tdfx_color_texenv
{
455 GrTCCUColor_t SourceA
;
456 GrCombineMode_t ModeA
;
457 GrTCCUColor_t SourceB
;
458 GrCombineMode_t ModeB
;
459 GrTCCUColor_t SourceC
;
461 GrTCCUColor_t SourceD
;
467 /* for Voodoo5's grTexAlphaCombineExt() */
468 struct tdfx_alpha_texenv
{
469 GrTACUColor_t SourceA
;
470 GrCombineMode_t ModeA
;
471 GrTACUColor_t SourceB
;
472 GrCombineMode_t ModeB
;
473 GrTACUColor_t SourceC
;
475 GrTCCUColor_t SourceD
;
481 /* Voodoo5's texture combine environment */
482 struct tdfx_texcombine_ext
{
483 struct tdfx_alpha_texenv Alpha
;
484 struct tdfx_color_texenv Color
;
488 /* Used to track changes between Glide's state and Mesa's */
489 struct tdfx_texstate
{
490 GLuint Enabled
[2]; /* values ala ctx->Texture.Unit[i]._ReallyEnabled */
491 GLenum EnvMode
[TDFX_NUM_TMU
]; /* index is Glide index, not OpenGL */
492 GLenum TexFormat
[TDFX_NUM_TMU
]; /* index is Glide index, not OpenGL */
496 GrColor_t ClearColor
; /* Buffer clear color value */
497 GrAlpha_t ClearAlpha
; /* Buffer clear alpha value */
498 FxBool ColorMask
[4]; /* Per-channel write enable flags */
500 GrColor_t MonoColor
; /* Constant color value */
503 GrCmpFnc_t AlphaFunc
; /* Alpha test function */
504 GrAlpha_t AlphaRef
; /* Alpha ref value in range [0,255] */
507 GrAlphaBlendFnc_t BlendSrcRGB
; /* Blend source RGB factor */
508 GrAlphaBlendFnc_t BlendDstRGB
; /* Blend destination RGB factor */
509 GrAlphaBlendOp_t BlendEqRGB
; /* Blend source RGB op */
510 GrAlphaBlendFnc_t BlendSrcA
; /* Blend source alpha factor */
511 GrAlphaBlendFnc_t BlendDstA
; /* Blend destination alpha factor */
512 GrAlphaBlendOp_t BlendEqA
; /* Blend source alpha op */
514 GrDitherMode_t Dither
; /* Dither enable */
518 GrDepthBufferMode_t Mode
; /* Fixed-point Z or floating-point W */
519 FxI32 Bias
; /* Polygon offset factor */
520 GrCmpFnc_t Func
; /* Depth test function */
521 FxU32 Clear
; /* Buffer clear value */
522 FxBool Mask
; /* Write enable flag */
525 struct tdfx_stipple
{
526 GrStippleMode_t Mode
; /* Stipple enable/disable */
527 FxU32 Pattern
; /* 8x4 Stipple Pattern */
531 GrFogMode_t Mode
; /* Glide fog mode */
532 GrColor_t Color
; /* Fog color value */
533 GLenum TableMode
; /* GL fog mode currently in table */
534 GrFog_t
*Table
; /* Fog value table */
535 FxFloat Density
; /* Density >= 0 */
536 FxFloat Near
; /* Start distance in eye coords */
537 FxFloat Far
; /* End distance in eye coords */
540 struct tdfx_stencil
{
541 GrCmpFnc_t Function
; /* Stencil function */
542 GrStencil_t RefValue
; /* Stencil reference value */
543 GrStencil_t ValueMask
; /* Value mask */
544 GrStencil_t WriteMask
; /* Write mask */
545 GrStencil_t FailFunc
; /* Stencil fail function */
546 GrStencil_t ZFailFunc
; /* Stencil pass, depth fail function */
547 GrStencil_t ZPassFunc
; /* Stencil pass, depth pass function */
548 GrStencil_t Clear
; /* Buffer clear value */
551 struct tdfx_scissor
{
552 FxU32 minX
, minY
; /* Lower left corner */
553 FxU32 maxX
, maxY
; /* Upper right corner */
556 struct tdfx_viewport
{
557 GrCoordinateSpaceMode_t Mode
; /* Coordinate space */
558 FxI32 X
, Y
; /* Position */
559 FxI32 Width
, Height
; /* Size */
560 FxFloat Near
, Far
; /* Depth buffer range */
564 void *State
; /* Mirror of internal Glide state */
565 GrContext_t Context
; /* Glide context identifier */
566 FxI32 Board
; /* Current graphics subsystem */
567 GrColorFormat_t ColorFormat
; /* Framebuffer format */
568 GrOriginLocation_t Origin
; /* Location of screen space origin */
570 FxBool Initialized
; /* Glide initialization done? */
572 FxI32 SwapInterval
; /* SwapBuffers interval */
573 FxI32 MaxPendingSwaps
; /* Maximum outstanding SwapBuffers */
577 FxBool HaveCombineExt
; /* COMBINE */
578 FxBool HaveCommandTransportExt
; /* COMMAND_TRANSPORT */
579 FxBool HaveFogCoordExt
; /* FOGCOORD */
580 FxBool HavePixelExt
; /* PIXEXT */
581 FxBool HaveTextureBufferExt
; /* TEXTUREBUFFER */
582 FxBool HaveTexFmtExt
; /* TEXFMT */
583 FxBool HaveTexUMAExt
; /* TEXUMA */
584 FxBool HaveMirrorExt
; /* MIRROR */
585 FxBool HaveTexus2
; /* Texus 2 - FXT1 */
587 /* Glide library function pointers */
588 void (*grDrawPoint
)( const void *pt
);
589 void (*grDrawLine
)( const void *v1
, const void *v2
);
590 void (*grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
591 void (*grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
592 void (*grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
593 void (*grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
594 void *pointers
, FxU32 stride
);
595 void (*grBufferClear
)( GrColor_t color
, GrAlpha_t alpha
, FxU32 depth
);
596 void (*grBufferSwap
)( FxU32 swap_interval
);
597 void (*grRenderBuffer
)( GrBuffer_t buffer
);
598 void (*grErrorSetCallback
)( GrErrorCallbackFnc_t fnc
);
599 void (*grFinish
)(void);
600 void (*grFlush
)(void);
601 GrContext_t (*grSstWinOpen
)(FxU32 hWnd
,
602 GrScreenResolution_t screen_resolution
,
603 GrScreenRefresh_t refresh_rate
,
604 GrColorFormat_t color_format
,
605 GrOriginLocation_t origin_location
,
608 void (*grSstWinClose
)( GrContext_t context
);
611 void (*grSetNumPendingBuffers
)(FxI32 NumPendingBuffers
);
613 void (*grSelectContext
)( GrContext_t context
);
614 void (*grSstOrigin
)(GrOriginLocation_t origin
);
615 void (*grSstSelect
)( int which_sst
);
616 void (*grAlphaBlendFunction
)(GrAlphaBlendFnc_t rgb_sf
,
617 GrAlphaBlendFnc_t rgb_df
,
618 GrAlphaBlendFnc_t alpha_sf
,
619 GrAlphaBlendFnc_t alpha_df
);
620 void (*grAlphaCombine
)(GrCombineFunction_t function
,
621 GrCombineFactor_t factor
,
622 GrCombineLocal_t local
, GrCombineOther_t other
,
624 void (*grAlphaControlsITRGBLighting
)( FxBool enable
);
625 void (*grAlphaTestFunction
)( GrCmpFnc_t function
);
626 void (*grAlphaTestReferenceValue
)( GrAlpha_t value
);
627 void (*grChromakeyMode
)( GrChromakeyMode_t mode
);
628 void (*grChromakeyValue
)( GrColor_t value
);
629 void (*grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
630 void (*grColorCombine
)( GrCombineFunction_t function
,
631 GrCombineFactor_t factor
,
632 GrCombineLocal_t local
,
633 GrCombineOther_t other
,
635 void (*grColorMask
)( FxBool rgb
, FxBool a
);
636 void (*grCullMode
)( GrCullMode_t mode
);
637 void (*grConstantColorValue
)( GrColor_t value
);
638 void (*grDepthBiasLevel
)( FxI32 level
);
639 void (*grDepthBufferFunction
)( GrCmpFnc_t function
);
640 void (*grDepthBufferMode
)( GrDepthBufferMode_t mode
);
641 void (*grDepthMask
)( FxBool mask
);
642 void (*grDisableAllEffects
)( void );
643 void (*grDitherMode
)( GrDitherMode_t mode
);
644 void (*grFogColorValue
)( GrColor_t fogcolor
);
645 void (*grFogMode
)( GrFogMode_t mode
);
646 void (*grFogTable
)( const GrFog_t ft
[] );
647 void (*grLoadGammaTable
)( FxU32 nentries
, FxU32
*red
, FxU32
*green
, FxU32
*blue
);
648 void (*grSplash
)(float x
, float y
, float width
, float height
, FxU32 frame
);
649 FxU32 (*grGet
)( FxU32 pname
, FxU32 plength
, FxI32
*params
);
650 const char * (*grGetString
)( FxU32 pname
);
651 FxI32 (*grQueryResolutions
)( const GrResolution
*resTemplate
,
652 GrResolution
*output
);
653 FxBool (*grReset
)( FxU32 what
);
654 GrProc (*grGetProcAddress
)( char *procName
);
655 void (*grEnable
)( GrEnableMode_t mode
);
656 void (*grDisable
)( GrEnableMode_t mode
);
657 void (*grCoordinateSpace
)( GrCoordinateSpaceMode_t mode
);
658 void (*grDepthRange
)( FxFloat n
, FxFloat f
);
659 void (*grStippleMode
)( GrStippleMode_t mode
);
660 void (*grStipplePattern
)( GrStipplePattern_t mode
);
661 void (*grViewport
)( FxI32 x
, FxI32 y
, FxI32 width
, FxI32 height
);
662 FxU32 (*grTexCalcMemRequired
)(GrLOD_t lodmin
, GrLOD_t lodmax
,
663 GrAspectRatio_t aspect
, GrTextureFormat_t fmt
);
664 FxU32 (*grTexTextureMemRequired
)( FxU32 evenOdd
, GrTexInfo
*info
);
665 FxU32 (*grTexMinAddress
)( GrChipID_t tmu
);
666 FxU32 (*grTexMaxAddress
)( GrChipID_t tmu
);
667 void (*grTexNCCTable
)( GrNCCTable_t table
);
668 void (*grTexSource
)( GrChipID_t tmu
, FxU32 startAddress
,
669 FxU32 evenOdd
, GrTexInfo
*info
);
670 void (*grTexClampMode
)( GrChipID_t tmu
,
671 GrTextureClampMode_t s_clampmode
,
672 GrTextureClampMode_t t_clampmode
);
673 void (*grTexCombine
)( GrChipID_t tmu
,
674 GrCombineFunction_t rgb_function
,
675 GrCombineFactor_t rgb_factor
,
676 GrCombineFunction_t alpha_function
,
677 GrCombineFactor_t alpha_factor
,
679 FxBool alpha_invert
);
680 void (*grTexDetailControl
)( GrChipID_t tmu
, int lod_bias
,
681 FxU8 detail_scale
, float detail_max
);
682 void (*grTexFilterMode
)( GrChipID_t tmu
,
683 GrTextureFilterMode_t minfilter_mode
,
684 GrTextureFilterMode_t magfilter_mode
);
685 void (*grTexLodBiasValue
)(GrChipID_t tmu
, float bias
);
686 void (*grTexDownloadMipMap
)( GrChipID_t tmu
, FxU32 startAddress
,
687 FxU32 evenOdd
, GrTexInfo
*info
);
688 void (*grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
692 GrAspectRatio_t aspectRatio
,
693 GrTextureFormat_t format
,
696 FxBool (*grTexDownloadMipMapLevelPartial
)( GrChipID_t tmu
,
700 GrAspectRatio_t aspectRatio
,
701 GrTextureFormat_t format
,
706 void (*grTexDownloadTable
)( GrTexTable_t type
, void *data
);
707 void (*grTexDownloadTablePartial
)( GrTexTable_t type
,
708 void *data
, int start
, int end
);
709 void (*grTexMipMapMode
)( GrChipID_t tmu
, GrMipMapMode_t mode
,
711 void (*grTexMultibase
)( GrChipID_t tmu
, FxBool enable
);
712 void (*grTexMultibaseAddress
)( GrChipID_t tmu
,
713 GrTexBaseRange_t range
,
717 FxBool (*grLfbLock
)( GrLock_t type
, GrBuffer_t buffer
,
718 GrLfbWriteMode_t writeMode
,
719 GrOriginLocation_t origin
, FxBool pixelPipeline
,
721 FxBool (*grLfbUnlock
)( GrLock_t type
, GrBuffer_t buffer
);
722 void (*grLfbConstantAlpha
)( GrAlpha_t alpha
);
723 void (*grLfbConstantDepth
)( FxU32 depth
);
724 void (*grLfbWriteColorSwizzle
)(FxBool swizzleBytes
, FxBool swapWords
);
725 void (*grLfbWriteColorFormat
)(GrColorFormat_t colorFormat
);
726 FxBool (*grLfbWriteRegion
)( GrBuffer_t dst_buffer
,
727 FxU32 dst_x
, FxU32 dst_y
,
728 GrLfbSrcFmt_t src_format
,
729 FxU32 src_width
, FxU32 src_height
,
730 FxBool pixelPipeline
,
731 FxI32 src_stride
, void *src_data
);
732 FxBool (*grLfbReadRegion
)( GrBuffer_t src_buffer
,
733 FxU32 src_x
, FxU32 src_y
,
734 FxU32 src_width
, FxU32 src_height
,
735 FxU32 dst_stride
, void *dst_data
);
736 void (*grGlideInit
)( void );
737 void (*grGlideShutdown
)( void );
738 void (*grGlideGetState
)( void *state
);
739 void (*grGlideSetState
)( const void *state
);
740 void (*grGlideGetVertexLayout
)( void *layout
);
741 void (*grGlideSetVertexLayout
)( const void *layout
);
742 /* Glide utility functions */
743 void (*guFogGenerateExp
)( GrFog_t
*fogtable
, float density
);
744 void (*guFogGenerateExp2
)( GrFog_t
*fogtable
, float density
);
745 void (*guFogGenerateLinear
)(GrFog_t
*fogtable
, float nearZ
, float farZ
);
747 void (*grDRIOpen
)( char *pFB
, char *pRegs
, int deviceID
,
748 int width
, int height
,
749 int mem
, int cpp
, int stride
,
750 int fifoOffset
, int fifoSize
,
751 int fbOffset
, int backOffset
, int depthOffset
,
752 int textureOffset
, int textureSize
,
753 volatile int *fifoPtr
, volatile int *fifoRead
);
754 void (*grDRIPosition
)( int x
, int y
, int w
, int h
,
755 int numClip
, drm_clip_rect_t
*pClip
);
756 void (*grDRILostContext
)( void );
757 void (*grDRIImportFifo
)( int fifoPtr
, int fifoRead
);
758 void (*grDRIInvalidateAll
)( void );
759 void (*grDRIResetSAREA
)( void );
760 void (*grDRIBufferSwap
)( FxU32 swapInterval
);
761 /* Glide extensions */
762 /* PIXEXT extension */
763 void (*grStencilFunc
)( GrCmpFnc_t func
, GrStencil_t ref
, GrStencil_t mask
);
764 void (*grStencilMask
)( GrStencil_t mask
);
765 void (*grStencilOp
)( GrStencilOp_t fail
, GrStencilOp_t zfail
,
766 GrStencilOp_t zpass
);
767 void (*grBufferClearExt
)( GrColor_t color
, GrAlpha_t alpha
,
768 FxU32 depth
, GrStencil_t stencil
);
769 void (*grColorMaskExt
)( FxBool r
, FxBool g
, FxBool b
, FxBool a
);
770 /* COMBINE extension */
771 void (*grColorCombineExt
)( GrCCUColor_t a
, GrCombineMode_t a_mode
,
772 GrCCUColor_t b
, GrCombineMode_t b_mode
,
773 GrCCUColor_t c
, FxBool c_invert
,
774 GrCCUColor_t d
, FxBool d_invert
,
775 FxU32 shift
, FxBool invert
);
776 void (*grTexColorCombineExt
)( FxU32 tmu
,
777 GrTCCUColor_t a
, GrCombineMode_t a_mode
,
778 GrTCCUColor_t b
, GrCombineMode_t b_mode
,
779 GrTCCUColor_t c
, FxBool c_invert
,
780 GrTCCUColor_t d
, FxBool d_invert
,
781 FxU32 shift
, FxBool invert
);
782 void (*grAlphaCombineExt
)( GrACUColor_t a
, GrCombineMode_t a_mode
,
783 GrACUColor_t b
, GrCombineMode_t b_mode
,
784 GrACUColor_t c
, FxBool c_invert
,
785 GrACUColor_t d
, FxBool d_invert
,
786 FxU32 shift
, FxBool invert
);
787 void (*grTexAlphaCombineExt
)( FxU32 tmu
,
788 GrTACUColor_t a
, GrCombineMode_t a_mode
,
789 GrTACUColor_t b
, GrCombineMode_t b_mode
,
790 GrTACUColor_t c
, FxBool c_invert
,
791 GrTACUColor_t d
, FxBool d_invert
,
792 FxU32 shift
, FxBool invert
);
793 void (*grAlphaBlendFunctionExt
)( GrAlphaBlendFnc_t rgb_sf
,
794 GrAlphaBlendFnc_t rgb_df
,
795 GrAlphaBlendOp_t rgb_op
,
796 GrAlphaBlendFnc_t alpha_sf
,
797 GrAlphaBlendFnc_t alpha_df
,
798 GrAlphaBlendOp_t alpha_op
);
799 void (*grConstantColorValueExt
)( FxU32 tmu
, GrColor_t value
);
801 void (*txImgQuantize
)( void *xxx_unknown_arguments
);
802 void (*txImgDequantizeFXT1
)( void *txMip
, void *pxMip
);
803 void (*txErrorSetCallback
)( void *fnc
);
806 typedef void (*tdfx_tri_func
)( tdfxContextPtr
, tdfxVertex
*, tdfxVertex
*,
808 typedef void (*tdfx_line_func
)( tdfxContextPtr
, tdfxVertex
*, tdfxVertex
* );
809 typedef void (*tdfx_point_func
)( tdfxContextPtr
, tdfxVertex
* );
811 struct tdfx_context
{
812 /* Set once and never changed:
814 GLcontext
*glCtx
; /* The core Mesa context */
820 /* Mirror of hardware state, Glide parameters
822 GLuint tmu_source
[TDFX_NUM_TMU
];
823 struct tdfx_texsource TexSource
[TDFX_NUM_TMU
];
824 struct tdfx_texparams TexParams
[TDFX_NUM_TMU
];
825 struct tdfx_texpalette TexPalette
;
827 /* Voodoo3 texture/color combine state */
828 struct tdfx_combine ColorCombine
;
829 struct tdfx_combine AlphaCombine
;
830 struct tdfx_texcombine TexCombine
[TDFX_NUM_TMU
];
832 /* Voodoo5 texture/color combine state */
833 struct tdfx_combine_color_ext ColorCombineExt
;
834 struct tdfx_combine_alpha_ext AlphaCombineExt
;
835 struct tdfx_texcombine_ext TexCombineExt
[TDFX_NUM_TMU
];
837 /* Tracks tex state difference between Glide and Mesa */
838 struct tdfx_texstate TexState
;
840 GrBuffer_t DrawBuffer
; /* Current draw buffer */
841 GrBuffer_t ReadBuffer
; /* Current read buffer */
843 struct tdfx_color Color
;
844 struct tdfx_depth Depth
;
846 struct tdfx_stencil Stencil
;
847 struct tdfx_scissor Scissor
;
848 struct tdfx_viewport Viewport
;
849 struct tdfx_stipple Stipple
;
851 GrCullMode_t CullMode
;
853 struct tdfx_glide Glide
;
855 /* Fallback rasterization functions
857 tdfx_point_func draw_point
;
858 tdfx_line_func draw_line
;
859 tdfx_tri_func draw_triangle
;
862 /* Variable-size Glide vertex formats
864 GLuint vertexFormat
; /* the current format */
865 void *layout
[TDFX_NUM_LAYOUTS
];
868 GLfloat hw_viewport
[16];
871 GLuint SetupNewInputs
;
874 GLenum render_primitive
; /* what GL thinks */
875 GLenum raster_primitive
; /* what the hardware thinks */
877 GLfloat sScale0
, tScale0
;
878 GLfloat sScale1
, tScale1
;
880 GLuint texBindNumber
;
886 GLboolean haveTwoTMUs
; /* True if we have 2 tmu's */
887 GLboolean haveHwAlpha
;
888 GLboolean haveHwStencil
;
889 GLboolean haveHwStipple
;
891 GLint maxPendingSwapBuffers
;
893 char rendererString
[100];
895 /* stuff added for DRI */
896 __DRIscreenPrivate
*driScreen
;
897 __DRIcontextPrivate
*driContext
;
898 __DRIdrawablePrivate
*driDrawable
;
899 drm_context_t hHWContext
;
900 drm_hw_lock_t
*driHwLock
;
902 tdfxScreenPrivate
*fxScreen
;
903 TDFXSAREAPriv
*sarea
;
907 * Changes during execution:
909 int width
, height
; /* size of window */
910 int x_offset
; /* distance from window left to screen left */
911 int y_offset
; /* distance from window top to screen top */
912 int y_delta
; /* distance from window bottom to screen bottom */
915 drm_clip_rect_t
*pClipRects
;
916 GLboolean scissoredClipRects
; /* if true, pClipRects is private storage */
918 GuTexPalette glbPalette
; /* global texture palette */
922 GLboolean debugFallbacks
;
925 #define TDFX_CONTEXT(ctx) ((tdfxContextPtr)((ctx)->DriverCtx))
929 tdfxCreateContext( const __GLcontextModes
*mesaVis
,
930 __DRIcontextPrivate
*driContextPriv
,
931 void *sharedContextPrivate
);
934 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
);
937 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
);
940 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
941 __DRIdrawablePrivate
*driDrawPriv
,
942 __DRIdrawablePrivate
*driReadPriv
);
945 tdfxInitGlide( tdfxContextPtr tmesa
);
948 FX_grColorMaskv(GLcontext
*ctx
, const GLboolean rgba
[4]);
951 FX_grColorMaskv_NoLock(GLcontext
*ctx
, const GLboolean rgba
[4]);
954 /* Color packing utilities
956 #define TDFXPACKCOLOR332( r, g, b ) \
957 (((b) & 0xe0) | (((g) & 0xe0) >> 3) | (((r) & 0xc0) >> 6))
959 #define TDFXPACKCOLOR1555( r, g, b, a ) \
960 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
963 #define TDFXPACKCOLOR565( r, g, b ) \
964 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
966 #define TDFXPACKCOLOR888( r, g, b ) \
967 (((b) << 16) | ((g) << 8) | (r))
969 #define TDFXPACKCOLOR8888( r, g, b, a ) \
970 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
972 #define TDFXPACKCOLOR4444( r, g, b, a ) \
973 ((((a) & 0xf0) << 8) | (((b) & 0xf0) << 4) | ((g) & 0xf0) | ((r) >> 4))
975 static __inline__ GrColor_t
tdfxPackColor( GLuint cpp
,
976 GLubyte r
, GLubyte g
,
977 GLubyte b
, GLubyte a
)
981 return TDFXPACKCOLOR565( r
, g
, b
);
983 return TDFXPACKCOLOR8888( r
, g
, b
, a
);
991 extern int TDFX_DEBUG
;
996 #define DEBUG_ALWAYS_SYNC 0x01
997 #define DEBUG_VERBOSE_API 0x02
998 #define DEBUG_VERBOSE_MSG 0x04
999 #define DEBUG_VERBOSE_LRU 0x08
1000 #define DEBUG_VERBOSE_DRI 0x10
1001 #define DEBUG_VERBOSE_IOCTL 0x20
1002 #define DEBUG_VERBOSE_2D 0x40
1005 #define FX_COMPRESS_S3TC_AS_FXT1_HACK 1
1006 #define FX_TC_NAPALM 0
1008 #endif /* GLX_DIRECT_RENDERING */
1010 #endif /* __TDFX_CONTEXT_H__ */