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 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
33 * Gareth Hughes <gareth@valinux.com>
37 #ifndef __TDFX_CONTEXT_H__
38 #define __TDFX_CONTEXT_H__
40 #ifdef GLX_DIRECT_RENDERING
45 #include "GL/xf86glx.h"
49 #if defined(__linux__)
53 #include "tdfx_glide.h"
62 #include "tdfx_screen.h"
67 #define TDFX_TMU0 GR_TMU0
68 #define TDFX_TMU1 GR_TMU1
69 #define TDFX_TMU_SPLIT 98
70 #define TDFX_TMU_BOTH 99
71 #define TDFX_TMU_NONE 100
75 /* Flags for fxMesa->new_state
77 #define TDFX_NEW_COLOR 0x0001
78 #define TDFX_NEW_ALPHA 0x0002
79 #define TDFX_NEW_DEPTH 0x0004
80 #define TDFX_NEW_FOG 0x0008
81 #define TDFX_NEW_STENCIL 0x0010
82 #define TDFX_NEW_CLIP 0x0020
83 #define TDFX_NEW_VIEWPORT 0x0040
84 #define TDFX_NEW_CULL 0x0080
85 #define TDFX_NEW_GLIDE 0x0100
86 #define TDFX_NEW_TEXTURE 0x0200
87 #define TDFX_NEW_CONTEXT 0x0400
88 #define TDFX_NEW_LINE 0x0800
89 #define TDFX_NEW_RENDER 0x1000
90 #define TDFX_NEW_STIPPLE 0x2000
91 #define TDFX_NEW_TEXTURE_BIND 0x4000 /* experimental */
94 /* Flags for fxMesa->dirty
96 #define TDFX_UPLOAD_COLOR_COMBINE 0x00000001
97 #define TDFX_UPLOAD_ALPHA_COMBINE 0x00000002
98 #define TDFX_UPLOAD_RENDER_BUFFER 0x00000004
99 #define TDFX_UPLOAD_ALPHA_TEST 0x00000008
100 #define TDFX_UPLOAD_ALPHA_REF 0x00000010
101 #define TDFX_UPLOAD_BLEND_FUNC 0x00000020
102 #define TDFX_UPLOAD_DEPTH_MODE 0x00000040
103 #define TDFX_UPLOAD_DEPTH_BIAS 0x00000080
104 #define TDFX_UPLOAD_DEPTH_FUNC 0x00000100
105 #define TDFX_UPLOAD_DEPTH_MASK 0x00000200
106 #define TDFX_UPLOAD_FOG_MODE 0x00000400
107 #define TDFX_UPLOAD_FOG_COLOR 0x00000800
108 #define TDFX_UPLOAD_FOG_TABLE 0x00001000
110 #define TDFX_UPLOAD_CLIP 0x00002000
111 #define TDFX_UPLOAD_CULL 0x00004000
112 #define TDFX_UPLOAD_VERTEX_LAYOUT 0x00008000
113 #define TDFX_UPLOAD_COLOR_MASK 0x00010000
114 #define TDFX_UPLOAD_DITHER 0x00040000
115 #define TDFX_UPLOAD_STENCIL 0x00080000
117 #define TDFX_UPLOAD_TEXTURE_SOURCE 0x00100000
118 #define TDFX_UPLOAD_TEXTURE_PARAMS 0x00200000
119 #define TDFX_UPLOAD_TEXTURE_PALETTE 0x00400000
120 #define TDFX_UPLOAD_TEXTURE_ENV 0x00800000
121 #define TDFX_UPLOAD_TEXTURE_IMAGES 0x01000000
123 #define TDFX_UPLOAD_LINE 0x02000000
125 #define TDFX_UPLOAD_STIPPLE 0x04000000
127 /* Flags for software fallback cases */
128 /* See correponding strings in tdfx_tris.c */
129 #define TDFX_FALLBACK_TEXTURE_1D_3D 0x0001
130 #define TDFX_FALLBACK_DRAW_BUFFER 0x0002
131 #define TDFX_FALLBACK_SPECULAR 0x0004
132 #define TDFX_FALLBACK_STENCIL 0x0008
133 #define TDFX_FALLBACK_RENDER_MODE 0x0010
134 #define TDFX_FALLBACK_LOGICOP 0x0020
135 #define TDFX_FALLBACK_TEXTURE_ENV 0x0040
136 #define TDFX_FALLBACK_TEXTURE_BORDER 0x0080
137 #define TDFX_FALLBACK_COLORMASK 0x0100
138 #define TDFX_FALLBACK_BLEND 0x0200
139 #define TDFX_FALLBACK_LINE_STIPPLE 0x0400
141 /* Different Glide vertex layouts
143 #define TDFX_LAYOUT_TINY 0
144 #define TDFX_LAYOUT_NOTEX 1
145 #define TDFX_LAYOUT_SINGLE 2
146 #define TDFX_LAYOUT_MULTI 3
147 #define TDFX_LAYOUT_PROJECT 4
148 #define TDFX_NUM_LAYOUTS 5
150 #define TDFX_XY_OFFSET 0
151 #define TDFX_Z_OFFSET 8
152 #define TDFX_Q_OFFSET 12
153 #define TDFX_ARGB_OFFSET 16
154 #define TDFX_PAD_OFFSET 20
155 #define TDFX_FOG_OFFSET 20 /* experimental */
156 #define TDFX_ST0_OFFSET 24
157 #define TDFX_ST1_OFFSET 32
158 #define TDFX_Q0_OFFSET 40
159 #define TDFX_Q1_OFFSET 44
162 /* Flags for buffer clears
164 #define TDFX_FRONT 0x1
165 #define TDFX_BACK 0x2
166 #define TDFX_DEPTH 0x4
167 #define TDFX_STENCIL 0x8
170 * Subpixel offsets to adjust Mesa's (true) window coordinates to
171 * Glide coordinates. We need these to ensure precise rasterization.
172 * Otherwise, we'll fail a bunch of conformance tests.
174 #define TRI_X_OFFSET ( 0.0F)
175 #define TRI_Y_OFFSET ( 0.0F)
176 #define LINE_X_OFFSET ( 0.0F)
177 #define LINE_Y_OFFSET ( 0.125F)
178 #define PNT_X_OFFSET ( 0.375F)
179 #define PNT_Y_OFFSET ( 0.375F)
182 #define TDFX_DEPTH_BIAS_SCALE 128
184 /* Including xf86PciInfo.h causes a bunch of errors
186 #ifndef PCI_CHIP_BANSHEE
187 #define PCI_CHIP_BANSHEE 0x0003
188 #define PCI_CHIP_VOODOO3 0x0005
189 #define PCI_CHIP_VOODOO4 0x0009
190 #define PCI_CHIP_VOODOO5 0x0009
193 #define TDFX_IS_BANSHEE( fxMesa ) \
194 ( fxMesa->fxScreen->deviceID == PCI_CHIP_BANSHEE )
195 #define TDFX_IS_VOODOO3( fxMesa ) \
196 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO3 )
197 #define TDFX_IS_VOODOO4( fxMesa ) \
198 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4 )
199 #define TDFX_IS_VOODOO5( fxMesa ) \
200 ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5 )
201 #define TDFX_IS_NAPALM( fxMesa ) \
202 ( (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4) || \
203 (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5) )
206 #define PACK_BGRA32(R, G, B, A) \
207 ( (((GLuint) (R)) << 16) | \
208 (((GLuint) (G)) << 8) | \
209 (((GLuint) (B)) ) | \
210 (((GLuint) (A)) << 24) )
212 #define PACK_RGBA32(R, G, B, A) \
213 ( (((GLuint) (R)) ) | \
214 (((GLuint) (G)) << 8) | \
215 (((GLuint) (B)) << 16) | \
216 (((GLuint) (A)) << 24) )
219 * The first two macros are to pack 8 bit color
220 * channel values into a 565 format.
222 #define PACK_RGB16(R, G, B) \
223 ((((GLuint) (R) & 0xF8) << 8) | \
224 (((GLuint) (G) & 0xFC) << 3) | \
225 (((GLuint) (B) & 0xFF) >> 3))
226 #define PACK_BGR16(R, G, B) \
227 ((((GLuint) (B) & 0xF8) << 8) | \
228 (((GLuint) (G) & 0xFC) << 3) | \
229 (((GLuint) (R) & 0xFF) >> 3))
231 * The second two macros pack 8 bit color channel values
234 #define PACK_RGBA16(R, G, B, A) \
235 (((((GLuint) (A) & 0xFF) > 0) << 15)| \
236 (((GLuint) (R) & 0xF8) << 7) | \
237 (((GLuint) (G) & 0xF8) << 2) | \
238 (((GLuint) (B) & 0xF8) >> 3))
239 #define PACK_BGRA16(R, G, B, A) \
240 (((((GLuint) (A) & 0xFF) > 0) << 15)| \
241 (((GLuint) (B) & 0xF8) << 7) | \
242 (((GLuint) (G) & 0xF8) << 2) | \
243 (((GLuint) (R) & 0xF8) >> 3))
245 /* Used in calls to grColorMaskv()...
247 extern const GLboolean false4
[4];
248 extern const GLboolean true4
[4];
251 typedef struct tdfx_context tdfxContextRec
;
252 typedef struct tdfx_context
*tdfxContextPtr
;
256 volatile int fifoPtr
;
257 volatile int fifoRead
;
258 volatile int fifoOwner
;
259 volatile int ctxOwner
;
260 volatile int texOwner
;
276 * Memory range from startAddr to endAddr-1
278 typedef struct mem_range
{
279 struct mem_range
*next
;
280 FxU32 startAddr
, endAddr
;
286 GLsizei width
, height
; /* image size */
287 GLint wScale
, hScale
; /* scale factors */
288 GrTextureFormat_t glideFormat
; /* Glide image format */
293 #define TDFX_NUM_TMU 2
296 typedef struct tdfxTexInfo_t
299 GLboolean reloadImages
; /* if true, resend images to Glide */
304 GrAspectRatio_t aspectRatio
;
305 tdfxMemRange
*tm
[TDFX_NUM_TMU
];
307 GLint minLevel
, maxLevel
;
308 GrTextureFilterMode_t minFilt
;
309 GrTextureFilterMode_t magFilt
;
310 GrTextureClampMode_t sClamp
;
311 GrTextureClampMode_t tClamp
;
313 GrMipMapMode_t mmMode
;
315 GLfloat sScale
, tScale
; /* texcoord scale factor */
317 GuTexPalette palette
;
322 #define TDFX_TEXTURE_DATA(mesaObj) ((tdfxTexInfo *)((mesaObj)->DriverData))
324 #define TDFX_TEXIMAGE_DATA(mesaImg) ((tdfxMipMapLevel *)((mesaImg)->DriverData))
329 * This is state which may be shared by several tdfx contexts.
330 * It hangs off of Mesa's gl_shared_state object (ctx->Shared->DriverData).
332 struct tdfxSharedState
{
333 GLboolean umaTexMemory
;
334 GLuint totalTexMem
[TDFX_NUM_TMU
]; /* constant */
335 GLuint freeTexMem
[TDFX_NUM_TMU
]; /* changes as we go */
336 tdfxMemRange
*tmPool
;
337 tdfxMemRange
*tmFree
[TDFX_NUM_TMU
];
342 /* ================================================================
343 * The vertex structures.
353 GLfloat x
, y
, z
; /* Coordinates in screen space */
354 GLfloat rhw
; /* Reciprocal homogeneous w */
355 tdfx_color_t color
; /* Diffuse color */
357 GLfloat tu0
, tv0
; /* Texture 0 coordinates */
358 GLfloat tu1
, tv1
; /* Texture 1 coordinates */
362 GLfloat x
, y
, z
; /* Coordinates in screen space */
363 GLfloat rhw
; /* Reciprocal homogeneous w */
364 tdfx_color_t color
; /* Diffuse color */
366 GLfloat tu0
, tv0
; /* Texture 0 coordinates */
367 GLfloat tu1
, tv1
; /* Texture 1 coordinates */
368 GLfloat tq0
, tq1
; /* Texture 0/1 q coords */
372 GLfloat x
, y
, z
; /* Coordinates in screen space */
373 tdfx_color_t color
; /* Diffuse color */
376 /* The size of this union is not of relevence:
378 union tdfx_vertex_t
{
387 typedef union tdfx_vertex_t tdfxVertex
, *tdfxVertexPtr
;
390 /* ================================================================
392 * We want to keep a mirror of the Glide function call parameters so we
393 * can avoid updating our state too often.
395 * Each of these broad groups will typically have a new state flag
396 * associated with it, and will be updated together. The individual
397 * Glide function calls each have a dirty flag and will only be called
398 * when absolutely necessary.
401 /* for grTexSource() */
402 struct tdfx_texsource
{
408 /* Texture object params */
409 struct tdfx_texparams
{
410 GrTextureClampMode_t sClamp
;
411 GrTextureClampMode_t tClamp
;
412 GrTextureFilterMode_t minFilt
;
413 GrTextureFilterMode_t magFilt
;
414 GrMipMapMode_t mmMode
;
419 /* for grTexDownloadTable() texture palettes */
420 struct tdfx_texpalette
{
425 /* for Voodoo3/Banshee's grColorCombine() and grAlphaCombine() */
426 struct tdfx_combine
{
427 GrCombineFunction_t Function
; /* Combine function */
428 GrCombineFactor_t Factor
; /* Combine scale factor */
429 GrCombineLocal_t Local
; /* Local combine source */
430 GrCombineOther_t Other
; /* Other combine source */
431 FxBool Invert
; /* Combine result inversion flag */
434 /* for Voodoo3's grTexCombine() */
435 struct tdfx_texcombine
{
436 GrCombineFunction_t FunctionRGB
;
437 GrCombineFactor_t FactorRGB
;
438 GrCombineFunction_t FunctionAlpha
;
439 GrCombineFactor_t FactorAlpha
;
445 /* for Voodoo5's grColorCombineExt() */
446 struct tdfx_combine_color_ext
{
447 GrCCUColor_t SourceA
;
448 GrCombineMode_t ModeA
;
449 GrCCUColor_t SourceB
;
450 GrCombineMode_t ModeB
;
451 GrCCUColor_t SourceC
;
453 GrCCUColor_t SourceD
;
459 /* for Voodoo5's grAlphaCombineExt() */
460 struct tdfx_combine_alpha_ext
{
461 GrACUColor_t SourceA
;
462 GrCombineMode_t ModeA
;
463 GrACUColor_t SourceB
;
464 GrCombineMode_t ModeB
;
465 GrACUColor_t SourceC
;
467 GrACUColor_t SourceD
;
473 /* for Voodoo5's grTexColorCombineExt() */
474 struct tdfx_color_texenv
{
475 GrTCCUColor_t SourceA
;
476 GrCombineMode_t ModeA
;
477 GrTCCUColor_t SourceB
;
478 GrCombineMode_t ModeB
;
479 GrTCCUColor_t SourceC
;
481 GrTCCUColor_t SourceD
;
487 /* for Voodoo5's grTexAlphaCombineExt() */
488 struct tdfx_alpha_texenv
{
489 GrTACUColor_t SourceA
;
490 GrCombineMode_t ModeA
;
491 GrTACUColor_t SourceB
;
492 GrCombineMode_t ModeB
;
493 GrTACUColor_t SourceC
;
495 GrTCCUColor_t SourceD
;
501 /* Voodoo5's texture combine environment */
502 struct tdfx_texcombine_ext
{
503 struct tdfx_alpha_texenv Alpha
;
504 struct tdfx_color_texenv Color
;
508 /* Used to track changes between Glide's state and Mesa's */
509 struct tdfx_texstate
{
510 GLuint Enabled
[2]; /* values ala ctx->Texture.Unit[i]._ReallyEnabled */
511 GLenum EnvMode
[TDFX_NUM_TMU
]; /* index is Glide index, not OpenGL */
512 GLenum TexFormat
[TDFX_NUM_TMU
]; /* index is Glide index, not OpenGL */
516 GrColor_t ClearColor
; /* Buffer clear color value */
517 GrAlpha_t ClearAlpha
; /* Buffer clear alpha value */
518 FxBool ColorMask
[4]; /* Per-channel write enable flags */
520 GrColor_t MonoColor
; /* Constant color value */
523 GrCmpFnc_t AlphaFunc
; /* Alpha test function */
524 GrAlpha_t AlphaRef
; /* Alpha ref value in range [0,255] */
527 GrAlphaBlendFnc_t BlendSrcRGB
; /* Blend source RGB factor */
528 GrAlphaBlendFnc_t BlendDstRGB
; /* Blend destination RGB factor */
529 GrAlphaBlendFnc_t BlendSrcA
; /* Blend source alpha factor */
530 GrAlphaBlendFnc_t BlendDstA
; /* Blend destination alpha factor */
532 GrDitherMode_t Dither
; /* Dither enable */
536 GrDepthBufferMode_t Mode
; /* Fixed-point Z or floating-point W */
537 FxI32 Bias
; /* Polygon offset factor */
538 GrCmpFnc_t Func
; /* Depth test function */
539 FxU32 Clear
; /* Buffer clear value */
540 FxBool Mask
; /* Write enable flag */
543 struct tdfx_stipple
{
544 GrStippleMode_t Mode
; /* Stipple enable/disable */
545 FxU32 Pattern
; /* 8x4 Stipple Pattern */
549 GrFogMode_t Mode
; /* Glide fog mode */
550 GrColor_t Color
; /* Fog color value */
551 GLenum TableMode
; /* GL fog mode currently in table */
552 GrFog_t
*Table
; /* Fog value table */
553 FxFloat Density
; /* Density >= 0 */
554 FxFloat Near
; /* Start distance in eye coords */
555 FxFloat Far
; /* End distance in eye coords */
558 struct tdfx_stencil
{
559 GrCmpFnc_t Function
; /* Stencil function */
560 GrStencil_t RefValue
; /* Stencil reference value */
561 GrStencil_t ValueMask
; /* Value mask */
562 GrStencil_t WriteMask
; /* Write mask */
563 GrStencil_t FailFunc
; /* Stencil fail function */
564 GrStencil_t ZFailFunc
; /* Stencil pass, depth fail function */
565 GrStencil_t ZPassFunc
; /* Stencil pass, depth pass function */
566 GrStencil_t Clear
; /* Buffer clear value */
569 struct tdfx_scissor
{
570 FxU32 minX
, minY
; /* Lower left corner */
571 FxU32 maxX
, maxY
; /* Upper right corner */
574 struct tdfx_viewport
{
575 GrCoordinateSpaceMode_t Mode
; /* Coordinate space */
576 FxI32 X
, Y
; /* Position */
577 FxI32 Width
, Height
; /* Size */
578 FxFloat Near
, Far
; /* Depth buffer range */
582 void *State
; /* Mirror of internal Glide state */
583 GrContext_t Context
; /* Glide context identifier */
584 FxI32 Board
; /* Current graphics subsystem */
585 GrColorFormat_t ColorFormat
; /* Framebuffer format */
586 GrOriginLocation_t Origin
; /* Location of screen space origin */
588 FxBool Initialized
; /* Glide initialization done? */
590 FxI32 SwapInterval
; /* SwapBuffers interval */
591 FxI32 MaxPendingSwaps
; /* Maximum outstanding SwapBuffers */
595 FxBool HaveCombineExt
; /* COMBINE */
596 FxBool HaveCommandTransportExt
; /* COMMAND_TRANSPORT */
597 FxBool HaveFogCoordExt
; /* FOGCOORD */
598 FxBool HavePixelExt
; /* PIXEXT */
599 FxBool HaveTextureBufferExt
; /* TEXTUREBUFFER */
600 FxBool HaveTexFmtExt
; /* TEXFMT */
601 FxBool HaveTexUMAExt
; /* TEXUMA */
602 FxBool HaveTexus2
; /* Texus 2 - FXT1 */
604 /* Glide library function pointers */
605 void (*grDrawPoint
)( const void *pt
);
606 void (*grDrawLine
)( const void *v1
, const void *v2
);
607 void (*grDrawTriangle
)( const void *a
, const void *b
, const void *c
);
608 void (*grVertexLayout
)(FxU32 param
, FxI32 offset
, FxU32 mode
);
609 void (*grDrawVertexArray
)(FxU32 mode
, FxU32 Count
, void *pointers
);
610 void (*grDrawVertexArrayContiguous
)(FxU32 mode
, FxU32 Count
,
611 void *pointers
, FxU32 stride
);
612 void (*grBufferClear
)( GrColor_t color
, GrAlpha_t alpha
, FxU32 depth
);
613 void (*grBufferSwap
)( FxU32 swap_interval
);
614 void (*grRenderBuffer
)( GrBuffer_t buffer
);
615 void (*grErrorSetCallback
)( GrErrorCallbackFnc_t fnc
);
616 void (*grFinish
)(void);
617 void (*grFlush
)(void);
618 GrContext_t (*grSstWinOpen
)(FxU32 hWnd
,
619 GrScreenResolution_t screen_resolution
,
620 GrScreenRefresh_t refresh_rate
,
621 GrColorFormat_t color_format
,
622 GrOriginLocation_t origin_location
,
625 void (*grSstWinClose
)( GrContext_t context
);
628 void (*grSetNumPendingBuffers
)(FxI32 NumPendingBuffers
);
630 void (*grSelectContext
)( GrContext_t context
);
631 void (*grSstOrigin
)(GrOriginLocation_t origin
);
632 void (*grSstSelect
)( int which_sst
);
633 void (*grAlphaBlendFunction
)(GrAlphaBlendFnc_t rgb_sf
,
634 GrAlphaBlendFnc_t rgb_df
,
635 GrAlphaBlendFnc_t alpha_sf
,
636 GrAlphaBlendFnc_t alpha_df
);
637 void (*grAlphaCombine
)(GrCombineFunction_t function
,
638 GrCombineFactor_t factor
,
639 GrCombineLocal_t local
, GrCombineOther_t other
,
641 void (*grAlphaControlsITRGBLighting
)( FxBool enable
);
642 void (*grAlphaTestFunction
)( GrCmpFnc_t function
);
643 void (*grAlphaTestReferenceValue
)( GrAlpha_t value
);
644 void (*grChromakeyMode
)( GrChromakeyMode_t mode
);
645 void (*grChromakeyValue
)( GrColor_t value
);
646 void (*grClipWindow
)( FxU32 minx
, FxU32 miny
, FxU32 maxx
, FxU32 maxy
);
647 void (*grColorCombine
)( GrCombineFunction_t function
,
648 GrCombineFactor_t factor
,
649 GrCombineLocal_t local
,
650 GrCombineOther_t other
,
652 void (*grColorMask
)( FxBool rgb
, FxBool a
);
653 void (*grCullMode
)( GrCullMode_t mode
);
654 void (*grConstantColorValue
)( GrColor_t value
);
655 void (*grDepthBiasLevel
)( FxI32 level
);
656 void (*grDepthBufferFunction
)( GrCmpFnc_t function
);
657 void (*grDepthBufferMode
)( GrDepthBufferMode_t mode
);
658 void (*grDepthMask
)( FxBool mask
);
659 void (*grDisableAllEffects
)( void );
660 void (*grDitherMode
)( GrDitherMode_t mode
);
661 void (*grFogColorValue
)( GrColor_t fogcolor
);
662 void (*grFogMode
)( GrFogMode_t mode
);
663 void (*grFogTable
)( const GrFog_t ft
[] );
664 void (*grLoadGammaTable
)( FxU32 nentries
, FxU32
*red
, FxU32
*green
, FxU32
*blue
);
665 void (*grSplash
)(float x
, float y
, float width
, float height
, FxU32 frame
);
666 FxU32 (*grGet
)( FxU32 pname
, FxU32 plength
, FxI32
*params
);
667 const char * (*grGetString
)( FxU32 pname
);
668 FxI32 (*grQueryResolutions
)( const GrResolution
*resTemplate
,
669 GrResolution
*output
);
670 FxBool (*grReset
)( FxU32 what
);
671 GrProc (*grGetProcAddress
)( char *procName
);
672 void (*grEnable
)( GrEnableMode_t mode
);
673 void (*grDisable
)( GrEnableMode_t mode
);
674 void (*grCoordinateSpace
)( GrCoordinateSpaceMode_t mode
);
675 void (*grDepthRange
)( FxFloat n
, FxFloat f
);
676 void (*grStippleMode
)( GrStippleMode_t mode
);
677 void (*grStipplePattern
)( GrStipplePattern_t mode
);
678 void (*grViewport
)( FxI32 x
, FxI32 y
, FxI32 width
, FxI32 height
);
679 FxU32 (*grTexCalcMemRequired
)(GrLOD_t lodmin
, GrLOD_t lodmax
,
680 GrAspectRatio_t aspect
, GrTextureFormat_t fmt
);
681 FxU32 (*grTexTextureMemRequired
)( FxU32 evenOdd
, GrTexInfo
*info
);
682 FxU32 (*grTexMinAddress
)( GrChipID_t tmu
);
683 FxU32 (*grTexMaxAddress
)( GrChipID_t tmu
);
684 void (*grTexNCCTable
)( GrNCCTable_t table
);
685 void (*grTexSource
)( GrChipID_t tmu
, FxU32 startAddress
,
686 FxU32 evenOdd
, GrTexInfo
*info
);
687 void (*grTexClampMode
)( GrChipID_t tmu
,
688 GrTextureClampMode_t s_clampmode
,
689 GrTextureClampMode_t t_clampmode
);
690 void (*grTexCombine
)( GrChipID_t tmu
,
691 GrCombineFunction_t rgb_function
,
692 GrCombineFactor_t rgb_factor
,
693 GrCombineFunction_t alpha_function
,
694 GrCombineFactor_t alpha_factor
,
696 FxBool alpha_invert
);
697 void (*grTexDetailControl
)( GrChipID_t tmu
, int lod_bias
,
698 FxU8 detail_scale
, float detail_max
);
699 void (*grTexFilterMode
)( GrChipID_t tmu
,
700 GrTextureFilterMode_t minfilter_mode
,
701 GrTextureFilterMode_t magfilter_mode
);
702 void (*grTexLodBiasValue
)(GrChipID_t tmu
, float bias
);
703 void (*grTexDownloadMipMap
)( GrChipID_t tmu
, FxU32 startAddress
,
704 FxU32 evenOdd
, GrTexInfo
*info
);
705 void (*grTexDownloadMipMapLevel
)( GrChipID_t tmu
,
709 GrAspectRatio_t aspectRatio
,
710 GrTextureFormat_t format
,
713 FxBool (*grTexDownloadMipMapLevelPartial
)( GrChipID_t tmu
,
717 GrAspectRatio_t aspectRatio
,
718 GrTextureFormat_t format
,
723 void (*grTexDownloadTable
)( GrTexTable_t type
, void *data
);
724 void (*grTexDownloadTablePartial
)( GrTexTable_t type
,
725 void *data
, int start
, int end
);
726 void (*grTexMipMapMode
)( GrChipID_t tmu
, GrMipMapMode_t mode
,
728 void (*grTexMultibase
)( GrChipID_t tmu
, FxBool enable
);
729 void (*grTexMultibaseAddress
)( GrChipID_t tmu
,
730 GrTexBaseRange_t range
,
734 FxBool (*grLfbLock
)( GrLock_t type
, GrBuffer_t buffer
,
735 GrLfbWriteMode_t writeMode
,
736 GrOriginLocation_t origin
, FxBool pixelPipeline
,
738 FxBool (*grLfbUnlock
)( GrLock_t type
, GrBuffer_t buffer
);
739 void (*grLfbConstantAlpha
)( GrAlpha_t alpha
);
740 void (*grLfbConstantDepth
)( FxU32 depth
);
741 void (*grLfbWriteColorSwizzle
)(FxBool swizzleBytes
, FxBool swapWords
);
742 void (*grLfbWriteColorFormat
)(GrColorFormat_t colorFormat
);
743 FxBool (*grLfbWriteRegion
)( GrBuffer_t dst_buffer
,
744 FxU32 dst_x
, FxU32 dst_y
,
745 GrLfbSrcFmt_t src_format
,
746 FxU32 src_width
, FxU32 src_height
,
747 FxBool pixelPipeline
,
748 FxI32 src_stride
, void *src_data
);
749 FxBool (*grLfbReadRegion
)( GrBuffer_t src_buffer
,
750 FxU32 src_x
, FxU32 src_y
,
751 FxU32 src_width
, FxU32 src_height
,
752 FxU32 dst_stride
, void *dst_data
);
753 void (*grGlideInit
)( void );
754 void (*grGlideShutdown
)( void );
755 void (*grGlideGetState
)( void *state
);
756 void (*grGlideSetState
)( const void *state
);
757 void (*grGlideGetVertexLayout
)( void *layout
);
758 void (*grGlideSetVertexLayout
)( const void *layout
);
759 /* Glide utility functions */
760 void (*guFogGenerateExp
)( GrFog_t
*fogtable
, float density
);
761 void (*guFogGenerateExp2
)( GrFog_t
*fogtable
, float density
);
762 void (*guFogGenerateLinear
)(GrFog_t
*fogtable
, float nearZ
, float farZ
);
764 void (*grDRIOpen
)( char *pFB
, char *pRegs
, int deviceID
,
765 int width
, int height
,
766 int mem
, int cpp
, int stride
,
767 int fifoOffset
, int fifoSize
,
768 int fbOffset
, int backOffset
, int depthOffset
,
769 int textureOffset
, int textureSize
,
770 volatile int *fifoPtr
, volatile int *fifoRead
);
771 void (*grDRIPosition
)( int x
, int y
, int w
, int h
,
772 int numClip
, XF86DRIClipRectPtr pClip
);
773 void (*grDRILostContext
)( void );
774 void (*grDRIImportFifo
)( int fifoPtr
, int fifoRead
);
775 void (*grDRIInvalidateAll
)( void );
776 void (*grDRIResetSAREA
)( void );
777 void (*grDRIBufferSwap
)( FxU32 swapInterval
);
778 /* Glide extensions */
779 /* PIXEXT extension */
780 void (*grStencilFunc
)( GrCmpFnc_t func
, GrStencil_t ref
, GrStencil_t mask
);
781 void (*grStencilMask
)( GrStencil_t mask
);
782 void (*grStencilOp
)( GrStencilOp_t fail
, GrStencilOp_t zfail
,
783 GrStencilOp_t zpass
);
784 void (*grBufferClearExt
)( GrColor_t color
, GrAlpha_t alpha
,
785 FxU32 depth
, GrStencil_t stencil
);
786 void (*grColorMaskExt
)( FxBool r
, FxBool g
, FxBool b
, FxBool a
);
787 /* COMBINE extension */
788 void (*grColorCombineExt
)( GrCCUColor_t a
, GrCombineMode_t a_mode
,
789 GrCCUColor_t b
, GrCombineMode_t b_mode
,
790 GrCCUColor_t c
, FxBool c_invert
,
791 GrCCUColor_t d
, FxBool d_invert
,
792 FxU32 shift
, FxBool invert
);
793 void (*grTexColorCombineExt
)( FxU32 tmu
,
794 GrTCCUColor_t a
, GrCombineMode_t a_mode
,
795 GrTCCUColor_t b
, GrCombineMode_t b_mode
,
796 GrTCCUColor_t c
, FxBool c_invert
,
797 GrTCCUColor_t d
, FxBool d_invert
,
798 FxU32 shift
, FxBool invert
);
799 void (*grAlphaCombineExt
)( GrACUColor_t a
, GrCombineMode_t a_mode
,
800 GrACUColor_t b
, GrCombineMode_t b_mode
,
801 GrACUColor_t c
, FxBool c_invert
,
802 GrACUColor_t d
, FxBool d_invert
,
803 FxU32 shift
, FxBool invert
);
804 void (*grTexAlphaCombineExt
)( FxU32 tmu
,
805 GrTACUColor_t a
, GrCombineMode_t a_mode
,
806 GrTACUColor_t b
, GrCombineMode_t b_mode
,
807 GrTACUColor_t c
, FxBool c_invert
,
808 GrTACUColor_t d
, FxBool d_invert
,
809 FxU32 shift
, FxBool invert
);
810 void (*grAlphaBlendFunctionExt
)( GrAlphaBlendFnc_t rgb_sf
,
811 GrAlphaBlendFnc_t rgb_df
,
812 GrAlphaBlendOp_t rgb_op
,
813 GrAlphaBlendFnc_t alpha_sf
,
814 GrAlphaBlendFnc_t alpha_df
,
815 GrAlphaBlendOp_t alpha_op
);
816 void (*grConstantColorValueExt
)( FxU32 tmu
, GrColor_t value
);
818 void (*txImgQuantize
)( void *xxx_unknown_arguments
);
819 void (*txImgDequantizeFXT1
)( void *txMip
, void *pxMip
);
820 void (*txErrorSetCallback
)( void *fnc
);
823 typedef void (*tdfx_tri_func
)( tdfxContextPtr
, tdfxVertex
*, tdfxVertex
*,
825 typedef void (*tdfx_line_func
)( tdfxContextPtr
, tdfxVertex
*, tdfxVertex
* );
826 typedef void (*tdfx_point_func
)( tdfxContextPtr
, tdfxVertex
* );
828 struct tdfx_context
{
829 /* Set once and never changed:
831 GLcontext
*glCtx
; /* The core Mesa context */
837 /* Mirror of hardware state, Glide parameters
839 struct tdfx_texsource TexSource
[TDFX_NUM_TMU
];
840 struct tdfx_texparams TexParams
[TDFX_NUM_TMU
];
841 struct tdfx_texpalette TexPalette
;
843 /* Voodoo3 texture/color combine state */
844 struct tdfx_combine ColorCombine
;
845 struct tdfx_combine AlphaCombine
;
846 struct tdfx_texcombine TexCombine
[TDFX_NUM_TMU
];
848 /* Voodoo5 texture/color combine state */
849 struct tdfx_combine_color_ext ColorCombineExt
;
850 struct tdfx_combine_alpha_ext AlphaCombineExt
;
851 struct tdfx_texcombine_ext TexCombineExt
[TDFX_NUM_TMU
];
853 /* Tracks tex state difference between Glide and Mesa */
854 struct tdfx_texstate TexState
;
856 GrBuffer_t DrawBuffer
; /* Current draw buffer */
857 GrBuffer_t ReadBuffer
; /* Current read buffer */
859 struct tdfx_color Color
;
860 struct tdfx_depth Depth
;
862 struct tdfx_stencil Stencil
;
863 struct tdfx_scissor Scissor
;
864 struct tdfx_viewport Viewport
;
865 struct tdfx_stipple Stipple
;
867 GrCullMode_t CullMode
;
869 struct tdfx_glide Glide
;
872 /* Temporaries for translating away float colors:
874 struct gl_client_array UbyteColor
;
876 /* Fallback rasterization functions
878 tdfx_point_func draw_point
;
879 tdfx_line_func draw_line
;
880 tdfx_tri_func draw_triangle
;
883 /* Variable-size Glide vertex formats
885 GLuint vertexFormat
; /* the current format */
886 GLuint vertex_stride_shift
;
887 void *layout
[TDFX_NUM_LAYOUTS
];
888 GLubyte
*verts
; /* tdfxVertices, arbitarily packed */
890 GLfloat hw_viewport
[16];
893 GLuint SetupNewInputs
;
896 GLenum render_primitive
; /* what GL thinks */
897 GLenum raster_primitive
; /* what the hardware thinks */
899 GLfloat sScale0
, tScale0
;
900 GLfloat sScale1
, tScale1
;
902 GLuint texBindNumber
;
908 GLboolean haveTwoTMUs
; /* True if we have 2 tmu's */
909 GLboolean haveHwStencil
;
910 GLboolean haveHwStipple
;
912 GLint maxPendingSwapBuffers
;
914 char rendererString
[100];
916 /* stuff added for DRI */
917 __DRIscreenPrivate
*driScreen
;
918 __DRIcontextPrivate
*driContext
;
919 __DRIdrawablePrivate
*driDrawable
;
920 drmContext hHWContext
;
923 tdfxScreenPrivate
*fxScreen
;
924 TDFXSAREAPriv
*sarea
;
928 * Changes during execution:
930 int width
, height
; /* size of window */
931 int x_offset
; /* distance from window left to screen left */
932 int y_offset
; /* distance from window top to screen top */
933 int y_delta
; /* distance from window bottom to screen bottom */
936 XF86DRIClipRectPtr pClipRects
;
937 GLboolean scissoredClipRects
; /* if true, pClipRects is private storage */
939 GuTexPalette glbPalette
; /* global texture palette */
943 GLboolean debugFallbacks
;
946 #define TDFX_CONTEXT(ctx) ((tdfxContextPtr)((ctx)->DriverCtx))
950 tdfxCreateContext( const __GLcontextModes
*mesaVis
,
951 __DRIcontextPrivate
*driContextPriv
,
952 void *sharedContextPrivate
);
955 tdfxDestroyContext( __DRIcontextPrivate
*driContextPriv
);
958 tdfxUnbindContext( __DRIcontextPrivate
*driContextPriv
);
961 tdfxMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
962 __DRIdrawablePrivate
*driDrawPriv
,
963 __DRIdrawablePrivate
*driReadPriv
);
966 tdfxInitGlide( tdfxContextPtr tmesa
);
969 FX_grColorMaskv(GLcontext
*ctx
, const GLboolean rgba
[4]);
972 FX_grColorMaskv_NoLock(GLcontext
*ctx
, const GLboolean rgba
[4]);
975 /* Color packing utilities
977 #define TDFXPACKCOLOR332( r, g, b ) \
978 (((b) & 0xe0) | (((g) & 0xe0) >> 3) | (((r) & 0xc0) >> 6))
980 #define TDFXPACKCOLOR1555( r, g, b, a ) \
981 ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \
984 #define TDFXPACKCOLOR565( r, g, b ) \
985 ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
987 #define TDFXPACKCOLOR888( r, g, b ) \
988 (((b) << 16) | ((g) << 8) | (r))
990 #define TDFXPACKCOLOR8888( r, g, b, a ) \
991 (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
993 #define TDFXPACKCOLOR4444( r, g, b, a ) \
994 ((((a) & 0xf0) << 8) | (((b) & 0xf0) << 4) | ((g) & 0xf0) | ((r) >> 4))
996 static __inline__ GrColor_t
tdfxPackColor( GLuint cpp
,
997 GLubyte r
, GLubyte g
,
998 GLubyte b
, GLubyte a
)
1002 return TDFXPACKCOLOR565( r
, g
, b
);
1004 return TDFXPACKCOLOR8888( r
, g
, b
, a
);
1012 extern int TDFX_DEBUG
;
1014 #define TDFX_DEBUG 0
1017 #define DEBUG_ALWAYS_SYNC 0x01
1018 #define DEBUG_VERBOSE_API 0x02
1019 #define DEBUG_VERBOSE_MSG 0x04
1020 #define DEBUG_VERBOSE_LRU 0x08
1021 #define DEBUG_VERBOSE_DRI 0x10
1022 #define DEBUG_VERBOSE_IOCTL 0x20
1023 #define DEBUG_VERBOSE_2D 0x40
1025 #endif /* GLX_DIRECT_RENDERING */
1027 #endif /* __TDFX_CONTEXT_H__ */