1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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.
27 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
30 * Thank you for your contribution, David!
32 * Please make note of the above copyright/license statement. If you
33 * contributed code or bug fixes to this code under the previous (GNU
34 * Library) license and object to the new license, your code will be
35 * removed at your request. Please see the Mesa docs/COPYRIGHT file
36 * for more information.
38 * Additional Mesa/3Dfx driver developers:
39 * Daryll Strauss <daryll@precisioninsight.com>
40 * Keith Whitwell <keith@precisioninsight.com>
42 * See fxapi.h for more revision/author details.
46 #ifndef __FX_GLIDE_WARPER__
47 #define __FX_GLIDE_WARPER__
54 #if !defined(FX_GLIDE3)
55 typedef FxU32 FX_GrContext_t
; /* Not used in Glide2 */
57 typedef GrContext_t FX_GrContext_t
;
61 * Glide3 emulation on Glide2:
63 #if !defined(FX_GLIDE3)
64 /* Constanst for FX_grGetInteger( ) */
65 #define FX_FOG_TABLE_ENTRIES 0x0004 /* The number of entries in the hardware fog table. */
66 #define FX_GLIDE_STATE_SIZE 0x0006 /* Size of buffer, in bytes, needed to save Glide state. */
67 #define FX_LFB_PIXEL_PIPE 0x0009 /* 1 if LFB writes can go through the 3D pixel pipe. */
68 #define FX_PENDING_BUFFERSWAPS 0x0014 /* The number of buffer swaps pending. */
70 #define FX_FOG_TABLE_ENTRIES GR_FOG_TABLE_ENTRIES
71 #define FX_GLIDE_STATE_SIZE GR_GLIDE_STATE_SIZE
72 #define FX_LFB_PIXEL_PIPE GR_LFB_PIXEL_PIPE
73 #define FX_PENDING_BUFFERSWAPS GR_PENDING_BUFFERSWAPS
77 * Genral warper functions for Glide2/Glide3:
79 extern FxI32
FX_grGetInteger(FxU32 pname
);
82 * Glide2 emulation on Glide3:
84 #if defined(FX_GLIDE3)
86 #define GR_ASPECT_1x1 GR_ASPECT_LOG2_1x1
87 #define GR_ASPECT_2x1 GR_ASPECT_LOG2_2x1
88 #define GR_ASPECT_4x1 GR_ASPECT_LOG2_4x1
89 #define GR_ASPECT_8x1 GR_ASPECT_LOG2_8x1
90 #define GR_ASPECT_1x2 GR_ASPECT_LOG2_1x2
91 #define GR_ASPECT_1x4 GR_ASPECT_LOG2_1x4
92 #define GR_ASPECT_1x8 GR_ASPECT_LOG2_1x8
94 #define GR_LOD_256 GR_LOD_LOG2_256
95 #define GR_LOD_128 GR_LOD_LOG2_128
96 #define GR_LOD_64 GR_LOD_LOG2_64
97 #define GR_LOD_32 GR_LOD_LOG2_32
98 #define GR_LOD_16 GR_LOD_LOG2_16
99 #define GR_LOD_8 GR_LOD_LOG2_8
100 #define GR_LOD_4 GR_LOD_LOG2_4
101 #define GR_LOD_2 GR_LOD_LOG2_2
102 #define GR_LOD_1 GR_LOD_LOG2_1
104 #define GR_FOG_WITH_TABLE GR_FOG_WITH_TABLE_ON_Q
106 typedef int GrSstType
;
108 #define MAX_NUM_SST 4
110 #define GR_SSTTYPE_VOODOO 0
111 #define GR_SSTTYPE_SST96 1
112 #define GR_SSTTYPE_AT3D 2
113 #define GR_SSTTYPE_Voodoo2 3
115 typedef struct GrTMUConfig_St
{
116 int tmuRev
; /* Rev of Texelfx chip */
117 int tmuRam
; /* 1, 2, or 4 MB */
120 typedef struct GrVoodooConfig_St
{
121 int fbRam
; /* 1, 2, or 4 MB */
122 int fbiRev
; /* Rev of Pixelfx chip */
123 int nTexelfx
; /* How many texelFX chips are there? */
124 FxBool sliDetect
; /* Is it a scan-line interleaved board? */
125 GrTMUConfig_t tmuConfig
[GLIDE_NUM_TMU
]; /* Configuration of the Texelfx chips */
128 typedef struct GrSst96Config_St
{
129 int fbRam
; /* How much? */
131 GrTMUConfig_t tmuConfig
;
134 typedef GrVoodooConfig_t GrVoodoo2Config_t
;
136 typedef struct GrAT3DConfig_St
{
141 int num_sst
; /* # of HW units in the system */
143 GrSstType type
; /* Which hardware is it? */
145 GrVoodooConfig_t VoodooConfig
;
146 GrSst96Config_t SST96Config
;
147 GrAT3DConfig_t AT3DConfig
;
148 GrVoodoo2Config_t Voodoo2Config
;
150 } SSTs
[MAX_NUM_SST
]; /* configuration for each board */
153 typedef FxU32 GrHint_t
;
154 #define GR_HINTTYPE_MIN 0
155 #define GR_HINT_STWHINT 0
157 typedef FxU32 GrSTWHint_t
;
158 #define GR_STWHINT_W_DIFF_FBI FXBIT(0)
159 #define GR_STWHINT_W_DIFF_TMU0 FXBIT(1)
160 #define GR_STWHINT_ST_DIFF_TMU0 FXBIT(2)
161 #define GR_STWHINT_W_DIFF_TMU1 FXBIT(3)
162 #define GR_STWHINT_ST_DIFF_TMU1 FXBIT(4)
163 #define GR_STWHINT_W_DIFF_TMU2 FXBIT(5)
164 #define GR_STWHINT_ST_DIFF_TMU2 FXBIT(6)
166 #define GR_CONTROL_ACTIVATE 1
167 #define GR_CONTROL_DEACTIVATE 0
172 ** move the vertex layout defintion to application
175 float sow
; /* s texture ordinate (s over w) */
176 float tow
; /* t texture ordinate (t over w) */
177 float oow
; /* 1/w (used mipmapping - really 0xfff/w) */
185 float x
, y
; /* X and Y in screen space */
186 float ooz
; /* 65535/Z (used for Z-buffering) */
187 float oow
; /* 1/W (used for W-buffering, texturing) */
188 FxU32 argb
; /* R, G, B, A [0..255.0] */
189 GrTmuVertex tmuvtx
[GLIDE_NUM_TMU
];
190 float z
; /* Z is ignored */
193 #define GR_VERTEX_X_OFFSET 0
194 #define GR_VERTEX_Y_OFFSET 1
195 #define GR_VERTEX_OOZ_OFFSET 2
196 #define GR_VERTEX_OOW_OFFSET 3
197 #define GR_VERTEX_PARGB_OFFSET 4
198 #define GR_VERTEX_SOW_TMU0_OFFSET 5
199 #define GR_VERTEX_TOW_TMU0_OFFSET 6
200 #define GR_VERTEX_OOW_TMU0_OFFSET 7
201 #define GR_VERTEX_SOW_TMU1_OFFSET 8
202 #define GR_VERTEX_TOW_TMU1_OFFSET 9
203 #define GR_VERTEX_OOW_TMU1_OFFSET 10
204 #define GR_VERTEX_Z_OFFSET 11
206 #define GET_PARGB(v) ((FxU32*)(v))[GR_VERTEX_PARGB_OFFSET]
207 /* GET_PA: returns the alpha component */
208 #if GLIDE_ENDIAN == GLIDE_ENDIAN_BIG
209 #define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4]
211 #define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+3]
213 #define MESACOLOR2PARGB(c) (c[ACOMP] << 24 | c[GCOMP] << 16 | c[GCOMP] << 8 | c[BCOMP])
214 #define PACK_4F_ARGB(dest,a,r,g,b) { \
215 const GLuint cr = (int)r; \
216 const GLuint cg = (int)g; \
217 const GLuint ca = (int)a; \
218 const GLuint cb = (int)b; \
219 dest = ca << 24 | cr << 16 | cg << 8 | cb; \
222 #else /* FX_USE_PARGB */
226 float x
, y
, z
; /* X, Y, and Z of scrn space -- Z is ignored */
227 float r
, g
, b
; /* R, G, B, ([0..255.0]) */
228 float ooz
; /* 65535/Z (used for Z-buffering) */
229 float a
; /* Alpha [0..255.0] */
230 float oow
; /* 1/W (used for W-buffering, texturing) */
231 GrTmuVertex tmuvtx
[GLIDE_NUM_TMU
];
234 #define GR_VERTEX_X_OFFSET 0
235 #define GR_VERTEX_Y_OFFSET 1
236 #define GR_VERTEX_Z_OFFSET 2
237 #define GR_VERTEX_R_OFFSET 3
238 #define GR_VERTEX_G_OFFSET 4
239 #define GR_VERTEX_B_OFFSET 5
240 #define GR_VERTEX_OOZ_OFFSET 6
241 #define GR_VERTEX_A_OFFSET 7
242 #define GR_VERTEX_OOW_OFFSET 8
243 #define GR_VERTEX_SOW_TMU0_OFFSET 9
244 #define GR_VERTEX_TOW_TMU0_OFFSET 10
245 #define GR_VERTEX_OOW_TMU0_OFFSET 11
246 #define GR_VERTEX_SOW_TMU1_OFFSET 12
247 #define GR_VERTEX_TOW_TMU1_OFFSET 13
248 #define GR_VERTEX_OOW_TMU1_OFFSET 14
249 #endif /* FX_USE_PARGB */
255 * Glide2 functions for Glide3
257 #if defined(FX_GLIDE3)
258 #define FX_grTexDownloadTable(TMU,type,data) \
260 BEGIN_BOARD_LOCK(); \
261 grTexDownloadTable(type,data); \
264 #define FX_grTexDownloadTable_NoLock(TMU,type,data) \
265 grTexDownloadTable(type, data)
267 #define FX_grTexDownloadTable(TMU,type,data) \
269 BEGIN_BOARD_LOCK(); \
270 grTexDownloadTable(TMU,type,data); \
273 #define FX_grTexDownloadTable_NoLock grTexDownloadTable
279 #if defined(FX_GLIDE3)
280 #define FX_grFlush() \
282 BEGIN_BOARD_LOCK(); \
287 #define FX_grFlush() \
289 BEGIN_BOARD_LOCK(); \
295 #define FX_grFinish() \
297 BEGIN_BOARD_LOCK(); \
303 * Write region: ToDo possible exploit the PixelPipe parameter.
305 #if defined(FX_GLIDE3)
306 #define FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
308 BEGIN_BOARD_LOCK(); \
309 grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,FXFALSE,src_stride,src_data); \
313 #define FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \
315 BEGIN_BOARD_LOCK(); \
316 grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data); \
324 #define FX_grLfbReadRegion(src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data) \
326 BEGIN_BOARD_LOCK(); \
327 grLfbReadRegion(src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data); \
334 #define FX_grDrawTriangle(a,b,c) \
337 grDrawTriangle(a,b,c); \
342 * For Lod/LodLog2 conversion.
344 #if defined(FX_GLIDE3)
345 #define FX_largeLodLog2(info) (info).largeLodLog2
347 #define FX_largeLodLog2(info) (info).largeLod
350 #if defined(FX_GLIDE3)
351 #define FX_aspectRatioLog2(info) (info).aspectRatioLog2
353 #define FX_aspectRatioLog2(info) (info).aspectRatio
356 #if defined(FX_GLIDE3)
357 #define FX_smallLodLog2(info) (info).smallLodLog2
359 #define FX_smallLodLog2(info) (info).smallLod
362 #if defined(FX_GLIDE3)
363 #define FX_lodToValue(val) ((int)(GR_LOD_256-val))
365 #define FX_lodToValue(val) ((int)(val))
368 #if defined(FX_GLIDE3)
369 #define FX_largeLodValue(info) ((int)(GR_LOD_256-(info).largeLodLog2))
371 #define FX_largeLodValue(info) ((int)(info).largeLod)
373 #define FX_largeLodValue_NoLock FX_largeLodValue
375 #if defined(FX_GLIDE3)
376 #define FX_smallLodValue(info) ((int)(GR_LOD_256-(info).smallLodLog2))
378 #define FX_smallLodValue(info) ((int)(info).smallLod)
380 #define FX_smallLodValue_NoLock FX_smallLodValue
382 #if defined(FX_GLIDE3)
383 #define FX_valueToLod(val) ((GrLOD_t)(GR_LOD_256-val))
385 #define FX_valueToLod(val) ((GrLOD_t)(val))
389 * ScreenWidth/Height stuff.
391 extern int FX_grSstScreenWidth(void);
392 extern int FX_grSstScreenHeight(void);
399 #if defined(FX_GLIDE3)
400 extern void FX_grGlideGetVersion(char *buf
);
402 #define FX_grGlideGetVersion(b) \
404 BEGIN_BOARD_LOCK(); \
405 grGlideGetVersion(b); \
410 * Performance statistics
412 #if defined(FX_GLIDE3)
413 extern void FX_grSstPerfStats(GrSstPerfStats_t
*st
);
415 #define FX_grSstPerfStats(s) \
417 BEGIN_BOARD_LOCK(); \
426 extern int FX_grSstQueryHardware(GrHwConfiguration
*config
);
431 #if defined(FX_GLIDE3)
432 extern void FX_grHints_NoLock(GrHint_t hintType
, FxU32 hintMask
);
433 extern void FX_grHints(GrHint_t hintType
, FxU32 hintMask
);
435 #define FX_grHints(t,m) \
437 BEGIN_BOARD_LOCK(); \
441 #define FX_grHints_NoLock grHints
444 * Antialiashed line+point drawing.
446 #if defined(FX_GLIDE3)
447 extern void FX_grAADrawLine(GrVertex
*a
,GrVertex
*b
);
449 #define FX_grAADrawLine(a,b) \
457 #if defined(FX_GLIDE3)
458 extern void FX_grAADrawPoint(GrVertex
*a
);
460 #define FX_grAADrawPoint(a) \
469 * Needed for Glide3 only, to set up Glide2 compatible vertex layout.
471 #if defined(FX_GLIDE3)
472 extern void FX_setupGrVertexLayout(void);
474 #define FX_setupGrVertexLayout() do {} while (0)
479 extern FxBool
FX_grSstControl(FxU32 code
);
482 * grGammaCorrectionValue
484 #if defined(FX_GLIDE3)
485 extern void FX_grGammaCorrectionValue(float val
);
487 #define FX_grGammaCorrectionValue(v) \
489 BEGIN_BOARD_LOCK(); \
490 grGammaCorrectionValue(v) \
495 #if defined(FX_GLIDE3)
496 #define FX_grSstWinClose(w) \
498 BEGIN_BOARD_LOCK(); \
503 #define FX_grSstWinClose(w) \
505 BEGIN_BOARD_LOCK(); \
512 extern FX_GrContext_t
FX_grSstWinOpen( FxU32 hWnd
,
513 GrScreenResolution_t screen_resolution
,
514 GrScreenRefresh_t refresh_rate
,
515 GrColorFormat_t color_format
,
516 GrOriginLocation_t origin_location
,
521 #define FX_grDrawLine(v1, v2) \
524 grDrawLine(v1, v2); \
528 #define FX_grDrawPoint(p) \
535 #define FX_grDitherMode(m) \
537 BEGIN_BOARD_LOCK(); \
542 #define FX_grRenderBuffer(b) \
544 BEGIN_BOARD_LOCK(); \
549 #define FX_grBufferClear(c, a, d) \
552 grBufferClear(c, a, d); \
556 #define FX_grDepthMask(m) \
558 BEGIN_BOARD_LOCK(); \
563 #define FX_grColorMask(c, a) \
565 BEGIN_BOARD_LOCK(); \
570 extern FxBool
FX_grLfbLock(GrLock_t type
, GrBuffer_t buffer
,
571 GrLfbWriteMode_t writeMode
,
572 GrOriginLocation_t origin
, FxBool pixelPipeline
,
575 #define FX_grLfbUnlock(t, b) \
577 BEGIN_BOARD_LOCK(); \
582 #define FX_grConstantColorValue(v) \
584 BEGIN_BOARD_LOCK(); \
585 grConstantColorValue(v); \
589 #define FX_grConstantColorValue_NoLock grConstantColorValue
591 #define FX_grAADrawTriangle(a, b, c, ab, bc, ca) \
594 grAADrawTriangle(a, b, c, ab, bc, ca); \
598 #define FX_grAlphaBlendFunction(rs, rd, as, ad) \
600 BEGIN_BOARD_LOCK(); \
601 grAlphaBlendFunction(rs, rd, as, ad); \
605 #define FX_grAlphaCombine(func, fact, loc, oth, inv) \
607 BEGIN_BOARD_LOCK(); \
608 grAlphaCombine(func, fact, loc, oth, inv); \
612 #define FX_grAlphaCombine_NoLock grAlphaCombine
614 #define FX_grAlphaTestFunction(f) \
616 BEGIN_BOARD_LOCK(); \
617 grAlphaTestFunction(f); \
621 #define FX_grAlphaTestReferenceValue(v) \
623 BEGIN_BOARD_LOCK(); \
624 grAlphaTestReferenceValue(v); \
628 #define FX_grClipWindow(minx, miny, maxx, maxy) \
630 BEGIN_BOARD_LOCK(); \
631 grClipWindow(minx, miny, maxx, maxy); \
635 #define FX_grClipWindow_NoLock grClipWindow
637 #define FX_grColorCombine(func, fact, loc, oth, inv) \
639 BEGIN_BOARD_LOCK(); \
640 grColorCombine(func, fact, loc, oth, inv); \
644 #define FX_grColorCombine_NoLock grColorCombine
646 #define FX_grCullMode(m) \
648 BEGIN_BOARD_LOCK(); \
653 #define FX_grDepthBiasLevel(lev) \
655 BEGIN_BOARD_LOCK(); \
656 grDepthBiasLevel(lev); \
660 #define FX_grDepthBufferFunction(func) \
662 BEGIN_BOARD_LOCK(); \
663 grDepthBufferFunction(func); \
667 #define FX_grFogColorValue(c) \
669 BEGIN_BOARD_LOCK(); \
670 grFogColorValue(c); \
674 #define FX_grFogMode(m) \
676 BEGIN_BOARD_LOCK(); \
681 #define FX_grFogTable(t) \
683 BEGIN_BOARD_LOCK(); \
688 #define FX_grTexClampMode(t, sc, tc) \
690 BEGIN_BOARD_LOCK(); \
691 grTexClampMode(t, sc, tc); \
695 #define FX_grTexClampMode_NoLock grTexClampMode
697 #define FX_grTexCombine(t, rfunc, rfact, afunc, afact, rinv, ainv) \
699 BEGIN_BOARD_LOCK(); \
700 grTexCombine(t, rfunc, rfact, afunc, afact, rinv, ainv); \
704 #define FX_grTexCombine_NoLock grTexCombine
706 #define FX_grTexDownloadMipMapLevel(t, sa, tlod, llod, ar, f, eo, d) \
708 BEGIN_BOARD_LOCK(); \
709 grTexDownloadMipMapLevel(t, sa, tlod, llod, ar, f, eo, d); \
713 #define FX_grTexDownloadMipMapLevel_NoLock grTexDownloadMipMapLevel
715 #define FX_grTexDownloadMipMapLevelPartial(t, sa, tlod, llod, ar, f, eo, d, s, e); \
717 BEGIN_BOARD_LOCK(); \
718 grTexDownloadMipMapLevelPartial(t, sa, tlod, llod, ar, f, eo, d, s, e); \
722 #define FX_grTexFilterMode(t, minf, magf) \
724 BEGIN_BOARD_LOCK(); \
725 grTexFilterMode(t, minf, magf); \
729 #define FX_grTexFilterMode_NoLock grTexFilterMode
731 extern FxU32
FX_grTexMinAddress(GrChipID_t tmu
);
732 extern FxU32
FX_grTexMaxAddress(GrChipID_t tmu
);
734 #define FX_grTexMipMapMode(t, m, lod) \
736 BEGIN_BOARD_LOCK(); \
737 grTexMipMapMode(t, m, lod); \
741 #define FX_grTexMipMapMode_NoLock grTexMipMapMode
743 #define FX_grTexSource(t, sa, eo, i) \
745 BEGIN_BOARD_LOCK(); \
746 grTexSource(t, sa, eo, i); \
750 #define FX_grTexSource_NoLock grTexSource
752 extern FxU32
FX_grTexTextureMemRequired(FxU32 evenOdd
, GrTexInfo
*info
);
753 #define FX_grTexTextureMemRequired_NoLock grTexTextureMemRequired
755 #define FX_grGlideGetState(s) \
757 BEGIN_BOARD_LOCK(); \
758 grGlideGetState(s); \
762 #define FX_grDRIBufferSwap(i) \
764 BEGIN_BOARD_LOCK(); \
765 grDRIBufferSwap(i); \
769 #define FX_grSstSelect(b) \
771 BEGIN_BOARD_LOCK(); \
776 #define FX_grSstSelect_NoLock grSstSelect
778 #define FX_grGlideSetState(s) \
780 BEGIN_BOARD_LOCK(); \
781 grGlideSetState(s); \
785 #define FX_grDepthBufferMode(m) \
787 BEGIN_BOARD_LOCK(); \
788 grDepthBufferMode(m); \
792 #define FX_grLfbWriteColorFormat(f) \
794 BEGIN_BOARD_LOCK(); \
795 grLfbWriteColorFormat(f); \
799 #define FX_grDrawVertexArray(m, c, p) \
802 grDrawVertexArray(m, c, p); \
806 #define FX_grGlideShutdown() \
813 #define FX_grGlideInit_NoLock grGlideInit
814 #define FX_grSstWinOpen_NoLock grSstWinOpen
816 extern int FX_getFogTableSize(void);
817 extern int FX_getGrStateSize(void);
819 #endif /* __FX_GLIDE_WARPER__ */