1 /* -*- mode: C; tab-width:8; -*- */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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 /* fxapi.c - 3Dfx VooDoo/Mesa interface */
49 /********************************************************************
52 * fxMesa.... (The driver API)
53 * fxDD.... (Mesa device driver functions)
54 * fxTM.... (Texture manager functions)
55 * fxSetup.... (Voodoo units setup functions)
56 * fx.... (Internal driver functions)
59 * fxMesa.... (Public driver data types)
60 * tfx.... (Private driver data types)
62 ********************************************************************
64 * V0.30 - David Bucciarelli (davibu@tin.it) Humanware s.r.l.
65 * - introduced a new MESA_GLX_FX related behavior
66 * - the Glide fog table was built in a wrong way (using
67 * gu* Glide function). Added the code for building the
68 * table following the OpenGL specs. Thanks to Steve Baker
69 * for highlighting the problem.
70 * - fixed few problems in my and Keith's fxDDClear code
71 * - merged my code with the Keith's one
72 * - used the new BlendFunc Mesa device driver function
73 * - used the new AlphaFunc Mesa device driver function
74 * - used the new Enable Mesa device driver function
75 * - fixed a bug related to fog in the Mesa core. Fog
76 * were applied two times: at vertex level and at fragment
77 * level (thanks to Steve Baker for reporting the problem)
78 * - glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE) now works
79 * (thanks to Jiri Pop for reporting the problem)
80 * - the driver works fine with OpenGL Unreal
81 * - fixed a bug in the Mesa core clipping code (related
82 * to the q texture coordinate)
83 * - introduced the support for the q texture coordinate
85 * Keith Whitwell (keithw@cableinet.co.uk)
86 * - optimized the driver and written all the new code
87 * required by the new Mesa-3.1 device driver API
88 * and by the new Mesa-3.1 core changes
89 * - written the cva support and many other stuff
91 * Brian Paul (brian_paul@avid.com) Avid Technology
92 * - fixed display list share bug for MESA_GLX_FX = window/fullscreen
93 * - fixed glClear/gl...Mask related problem
95 * Bert Schoenwaelder (bert@prinz-atm.CS.Uni-Magdeburg.De)
96 * - the driver is now able to sleep when waiting for the completation
97 * of multiple swapbuffer operations instead of wasting
98 * CPU time (NOTE: you must uncomment the lines in the
99 * fxMesaSwapBuffers function in order to enable this option)
101 * Eero Pajarre (epajarre@koti.tpo.fi)
102 * - enabled the macro FLOAT_COLOR_TO_UBYTE_COLOR under
104 * - written an asm x86 optimized float->integer conversions
107 * Theodore Jump (tjump@cais.com)
108 * - fixed a small problem in the __wglMonitor function of the
110 * - written the in-window-rendering hack support for windows
111 * and Vooodoo1/2 cards
113 * V0.29 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
114 * - included in Mesa-3.0
115 * - now glGetString(GL_RENDERER) returns more information
116 * about the hardware configuration: "Mesa Glide <version>
117 * <Voodoo_Graphics|Voodoo_Rush|UNKNOWN> <num> CARD/<num> FB/
118 * <num> TM/<num> TMU/<NOSLI|SLI>"
119 * where: <num> CARD is the card used for the current context,
120 * <num> FB is the number of MB for the framebuffer,
121 * <num> TM is the number of MB for the texture memory,
122 * <num> TMU is the number of TMU. You can try to run
123 * Mesa/demos/glinfo in order to have an example of the
125 * - fixed a problem of the WGL emulator with the
126 * OpenGL Optimizer 1.1 (thanks to Erwin Coumans for
128 * - fixed some bug in the fxwgl.c code (thanks to
129 * Peter Pettersson for a patch and a bug report)
131 * Theodore Jump (tjump@cais.com)
132 * - written the SST_DUALHEAD support in the WGL emulator
134 * Daryll Strauss (daryll@harlot.rb.ca.us)
135 * - fixed the Voodoo Rush support for the in window rendering
137 * V0.28 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
138 * - the only supported multitexture functions are GL_MODULATE
139 * for texture set 0 and GL_MODULATE for texture set 1. In
140 * all other cases, the driver falls back to pure software
142 * - written the support for the new GL_EXT_multitexture
143 * - written the DD_MAX_TEXTURE_COORD_SETS support in the
144 * fxDDGetParameteri() function
145 * - the driver falls back to pure software rendering when
146 * texture mapping function is GL_BLEND
148 * V0.27 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
149 * - inluded in the Mesa-3.0beta5
150 * - written a smal extension (GL_FXMESA_global_texture_lod_bias) in
151 * order to expose the LOD bias related Glide function
152 * - fixed a bug fxDDWriteMonoRGBAPixels()
153 * - the driver is now able to fallback to software rendering in
154 * any case not directly supported by the hardware
155 * - written the support for enabling/disabling dithering
156 * - the in-window-rendering hack now works with any X11 screen
158 * - fixed a problem related to color/depth/alpha buffer clears
159 * - fixed a problem when clearing buffer for a context with the
161 * - fixed a problem in the fxTMReloadSubMipMapLevel() function,
162 * I have forget a "break;" (thanks to Joe Waters for the bug report)
163 * - fixed a problem in the color format for the in window
165 * - written the fxDDReadRGBAPixels function
166 * - written the fxDDDepthTestPixelsGeneric function
167 * - written the fxDDDepthTestSpanGeneric function
168 * - written the fxDDWriteMonoRGBAPixels function
169 * - written the fxDDWriteRGBAPixels function
170 * - removed the multitexture emulation code for Voodoo board
173 * Chris Prince <cprince@cs.washington.edu>
174 * - fixed a new bug in the wglUseFontBitmaps code
176 * Ralf Knoesel (rknoesel@Stormfront.com)
177 * - fixed a bug in the wglUseFontBitmaps code
179 * Rune Hasvold (runeh@ifi.uio.no)
180 * - fixed a problem related to the aux usage in the fxBestResolution
182 * - fixed the order of pixel formats in the WGL emulator
184 * Fredrik Hubinette (hubbe@hubbe.net)
185 * - the driver shutdown the Glide for most common signals
187 * V0.26 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
188 * - included in the Mesa-3.0beta4
189 * - fixed a problem related to a my optimization for the Rune's
190 * pixel-span optimization
191 * - fixed a problem related to fxDDSetNearFar() and ctx->ProjectionMatrixType
192 * (thanks to Ben "Ctrl-Alt-Delete" and the Raul Alonso's ssystem)
193 * - fixed a small bug in the Rune's pixel-span optimization
194 * - fixed a problem with GL_CCW (thanks to Curt Olson for and example
196 * - grVertex setup code is now ready for the internal thread support
197 * - fixed a no used optimization with clipped vertices in
198 * grVertex setup code
199 * - fixed a problem in the GL_LIGHT_MODEL_TWO_SIDE support (thanks
200 * to Patrick H. Madden for a complete example of the bug)
202 * Rune Hasvold (runeh@ifi.uio.no)
203 * - highly optimized the driver functions for writing pixel
204 * span (2-3 times faster !)
206 * Axel W. Volley (volley@acm.org) Krauss-Maffei Wehrtechnik
207 * - written the fxDDReadDepthSpanFloat() and fxDDReadDepthSpanInt()
210 * V0.25 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
211 * - fixed a problem with Voodoo boards with only one TMU
212 * - fixed a bug in the fxMesaCreateContext()
213 * - now the GL_FRONT_AND_BACK works fine also with
214 * the alpha buffer and/or antialiasing
215 * - written the support for GL_FRONT_AND_BACK drawing but
216 * it doesn't works with the alpha buffer and/or antialiasing
217 * - fixed some bug in the Mesa core for glCopyTexSubImage
218 * and glCopyTexImage functions (thanks to Mike Connell
219 * for an example of the problem)
220 * - make some small optimizations in the Mesa core in order
221 * to save same driver call and state change for not very
222 * well written applications
223 * - introduced the NEW_DRVSTATE and make other optimizations
224 * for minimizing state changes
225 * - made a lot of optimizations in order to minimize state
227 * - it isn't more possible to create a context with the
228 * depth buffer and the stancil buffer (it isn't yet supported)
229 * - now the partial support for the Multitexture extension
230 * works with Quake2 for windows
231 * - vertex snap is not longer used for the Voodoo2 (FX_V2
233 * - done a lot of cleanup in the fxsetup.c file
234 * - now the partial support for the Multitexture extension
235 * works with GLQuake for windows
237 * Dieter Nuetzel (nuetzel@kogs.informatik.uni-hamburg.de) University of Hamburg
238 * - fixed a problem in the asm code for Linux of the fxvsetup.c file
239 * highlighted by the binutils-2.8.1.0.29. 'fildw' asm instruction
242 * Kevin Hester (kevinh@glassworks.net)
243 * - written the wglUseFontBitmaps() function in the WGL emulator
245 * V0.24 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
246 * - now the drive always uses per fragment fog
247 * - written a small optimization in the points drawing function
248 * - written the support for trilinear filtering with 2 TMUs
249 * - written the first partial support for the Multitexture extension.
250 * This task is quite hard because the color combine units work after
251 * the two texture combine units and not before as required by the
252 * Multitexture extension
253 * - written a workaround in fxBestResolution() in order to solve a
254 * problem with bzflag (it asks for 1x1 window !)
255 * - changed the fxBestResolution() behavior. It now returns the larger
256 * screen resolution supported by the hardware (instead of 640x480)
257 * when it is unable to find an appropriate resolution that is large
258 * enough for the requested size
259 * - the driver is now able to use also the texture memory attached to
261 * - the texture memory manager is now able to work with two TMUs and
262 * store texture maps in the memory attached to TMU0, TMU1 or to split
263 * the mimpmap levels across TMUs in order to support trilinear filtering
264 * - I have bought a Voodoo2 board !
265 * - the amount of frambuffer ram is now doubled when an SLI configuration
267 * - solved a problem related to the fxDDTexParam() and fxTexInvalidate()
268 * functions (thanks to Rune Hasvold for highlighting the problem)
269 * - done some cleanup in the fxvsetup.c file, written
270 * the FXVSETUP_FUNC macro
271 * - done a lot of cleanup in data types and field names
273 * Rune Hasvold (runeh@ifi.uio.no)
274 * - written the support for a right management of the auxiliary buffer.
275 * You can now use an 800x600 screen without the depth and alpha
277 * - written the support for a new pixel format (without the depth
278 * and alpha buffer) in the WGL emulator
279 * - fixed a bug in the window version of the GLUT (it was ever asking
282 * V0.23 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
283 * - included in the Mesa-3.0beta2 release
284 * - written the support for the OpenGL 1.2 GL_TEXTURE_BASE_LEVEL
285 * and GL_TEXTURE_MAX_LEVEL
286 * - rewritten several functions for a more clean support of texture
287 * mapping and in order to solve some bug
288 * - the accumulation buffer works (it is bit slow beacuase it requires
289 * to read/write from/to the Voodoo frame buffer but it works)
290 * - fixed a bug in the fxDDReadRGBASpan driver function (the R and
291 * B channels were read in the wrong order). Thanks to Jason Heym
292 * for highlighting the problem
293 * - written the support for multiple contexts on multiple boards.
294 * you can now use the Mesa/Voodoo with multiple Voodoo Graphics
295 * boards (for example with multiple screens or an HMD)
296 * - the fxBestResolution() now check all available resolutions
297 * and it is able to check the amount of framebuffer memory
298 * before return a resolution
299 * - modified the GLX/X11 driver in order to support all the
300 * resolution available
301 * - changed all function names. They should be now a bit more
303 * - written the Glide grVertex setup code for two TMU or
304 * for Multitexture support with emulationa dn one TMU
305 * - written the support for the new Mesa driver
306 * function GetParametri
307 * - small optimization/clean up in the texbind() function
308 * - fixed a FPU precision problem for glOrtho and texture
309 * mapping (thanks to Antti Juhani Huovilainen for an example
311 * - written some small SGI OpenGL emulation code for the wgl,
312 * the OpenGL Optimizer and Cosmo3D work fine under windows !
313 * - moved the point/line/triangle/quad support in the fxmesa7.c
314 * - fixed a bug in the clear_color_depth() (thanks to Henk Kok
315 * for an example of the problem)
316 * - written a small workaround for Linux GLQuake, it asks
317 * for the alpha buffer and the depth buffer at the some time
318 * (but it never uses the alpha buffer)
319 * - checked the antialiasing points, lines and polygons support.
321 * - written the support for standard OpenGL antialiasing using
322 * blending. Lines support works fine (tested with BZflag)
323 * while I have still to check the polygons and points support
324 * - written the support for the alpha buffer. The driver is now
325 * able to use the Voodoo auxiliary buffer as an alpha buffer
326 * instead of a depth buffer. Also all the OpenGL blending
327 * modes are now supported. But you can't request a context
328 * with an alpha buffer AND a depth buffer at the some time
329 * (this is an hardware limitation)
330 * - written the support for switching between the fullscreen
331 * rendering and the in-window-rendering hack on the fly
333 * Rune Hasvold (runeh@ifi.uio.no)
334 * - fixed a bug in the texparam() function
336 * Brian Paul (brianp@elastic.avid.com) Avid Technology
337 * - sources accomodated for the new Mesa 3.0beta1
339 * V0.22 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
340 * - included with some v0.23 bug fix in the final release
342 * - written the support for the MESA_WGL_FX env. var. but
343 * not tested because I have only Voodoo Graphics boards
344 * - fixed a bug in the backface culling code
345 * (thanks to David Farrell for an example of the problem)
346 * - fixed the "Quake2 elevator" bug
347 * - GL_POLYGONS with 3/4 vertices are now drawn as
348 * GL_TRIANLGES/GL_QUADS (a small optimization for GLQuake)
349 * - fixed a bug in fxmesa6.h for GL_LINE_LOOP
350 * - fixed a NearFarStack bug in the Mesa when applications
351 * directly call glLoadMatrix to load a projection matrix
352 * - done some cleanup in the fxmesa2.c file
353 * - the driver no longer translates the texture maps
354 * when the Mesa internal format and the Voodoo
355 * format are the some (usefull for 1 byte texture maps
356 * where the driver can directly use the Mesa texture
357 * map). Also the amount of used memory is halfed
358 * - fixed a bug for GL_DECAL and GL_RGBA
359 * - fixed a bug in the clear_color_depth()
360 * - tested the v0.22 with the Mesa-2.6beta2. Impressive
361 * performances improvement thanks to the new Josh's
362 * asm code (+10fps in the isosurf demo, +5fps in GLQuake
364 * - written a optimized version of the RenderVB Mesa driver
365 * function. The Voodoo driver is now able to upload polygons
366 * in the most common cases at a very good speed. Good
367 * performance improvement for large set of small polygons
368 * - optimized the asm code for setting up the color information
369 * in the Glide grVertex structure
370 * - fixed a bug in the fxmesa2.c asm code (the ClipMask[]
373 * Josh Vanderhoof (joshv@planet.net)
374 * - removed the flush() function because it isn't required
375 * - limited the maximum number of swapbuffers in the Voodoo
376 * commands FIFO (controlled by the env. var. MESA_FX_SWAP_PENDING)
378 * Holger Kleemiss (holger.kleemiss@metronet.de) STN Atlas Elektronik GmbH
379 * - applied some patch for the Voodoo Rush
381 * V0.21 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
382 * - the driver is now able to take advantage of the ClipMask[],
383 * ClipOrMask and ClipAndMask information also under Windows
384 * - introduced a new function in the Mesa driver interface
385 * ClearColorAndDepth(). Now the glClear() function is
386 * 2 times faster (!) when you have to clear the color buffer
387 * and the depth buffer at some time
388 * - written the first version of the fxRenderVB() driver
390 * - optimized the glTexImage() path
391 * - removed the fxMesaTextureUsePalette() support
392 * - fixed a bug in the points support (thanks to David Farrell
393 * for an example of the problem)
394 * - written the optimized path for glSubTexImage(),
395 * introduced a new function in the Mesa driver interface
397 * - fixed a bug for glColorMask and glDepthMask
398 * - the wbuffer is not more used. The Voodoo driver uses
399 * a standard 16bit zbuffer in all cases. It is more consistent
400 * and now GLQuake and GLQuake2test work also with a GL_ZTRICK 0
401 * - the driver is now able to take advantage of the ClipMask[],
402 * ClipOrMask and ClipAndMask information (under Linux);
403 * - rewritten the setup_fx_units() function, now the texture
404 * mapping support is compliant to the OpenGL specs (GL_BLEND
405 * support is still missing). The LinuxGLQuake console correctly
406 * fade in/out and transparent water of GLQuake2test works fine
407 * - written the support for the env. var. FX_GLIDE_SWAPINTERVAL
408 * - found a bug in the Mesa core. There is a roundup problem for
409 * color values out of the [0.0,1.0] range
411 * Wonko <matt@khm.de>
412 * - fixed a Voodoo Rush related problem in the fxwgl.c
414 * Daryll Strauss <daryll@harlot.rb.ca.us>
415 * - written the scissor test support
417 * V0.20 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
418 * - written the closetmmanger() function in order to free all the memory
419 * allocated by the Texture Memory Manager (it will be useful
420 * when the support for multiple contexts/boards will be ready)
421 * - now the Voodoo driver runs without printing any information,
422 * define the env. var. MESA_FX_INFO if you want to read some
423 * information about the hardware and some statistic
424 * - written a small workaround for the "GLQuake multiplayer white box bug"
425 * in the setup_fx_units() funxtions. I'm already rewriting
426 * this function because it is the source of nearly all the current
427 * Voodoo driver problems
428 * - fixed the GLQuake texture misalignment problem (the texture
429 * coordinates must be scaled between 0.0 and 256.0 and not
430 * between 0.0 and 255.0)
431 * - written the support for the GL_EXT_shared_texture_palette
432 * - some small change for supporting the automatic building of the
433 * OpenGL32.dll under the Windows platform
434 * - the redefinition of a mipmap level is now a LOT faster. This path
435 * is used by GLQuake for dynamic lighting with some call to glTexSubImage2D()
436 * - the texture memory is now managed a set of 2MB blocks so
437 * texture maps can't be allocated on a 2MB boundary. The new Pure3D
438 * needs this kind of support (and probably any other Voodoo Graphics
439 * board with more than 2MB of texture memory)
441 * Brian Paul (brianp@elastic.avid.com) Avid Technology
442 * - added write_monocolor_span(), fixed bug in write_color_span()
443 * - added test for stenciling in choosepoint/line/triangle functions
445 * Joe Waters (falc@attila.aegistech.com) Aegis
446 * - written the support for the env. var. SST_SCREENREFRESH
448 * V0.19 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
449 * - written the 3Dfx Global Palette extension for GLQuake
450 * - written the support for the GL_EXT_paletted_texture (it works only with GL_RGBA
451 * palettes and the alpha value is ignored ... this is a limitation of the
452 * the current Glide version and Voodoo hardware)
453 * - fixed the amount of memory allocated for 8bit textures
454 * - merged the under construction v0.19 driver with the Mesa 2.5
455 * - finally written the support for deleting textures
456 * - introduced a new powerful texture memory manager: the texture memory
457 * is used as a cache of the set of all defined texture maps. You can
458 * now define several MB of texture maps also with a 2MB of texture memory
459 * (the texture memory manager will do automatically all the swap out/swap in
460 * work). The new texture memory manager has also
461 * solved a lot of other bugs/no specs compliance/problems
462 * related to the texture memory usage. The texture
463 * manager code is inside the new fxmesa3.c file
464 * - broken the fxmesa.c file in two files (fxmesa1.c and fxmesa2.c)
465 * and done some code cleanup
466 * - now is possible to redefine texture mipmap levels already defined
467 * - fixed a problem with the amount of texture memory allocated for textures
468 * with not all mipmap levels defined
469 * - fixed a small problem with single buffer rendering
471 * Brian Paul (brianp@elastic.avid.com) Avid Technology
472 * - read/write_color_span() now use front/back buffer correctly
473 * - create GLvisual with 5,6,5 bits per pixel, not 8,8,8
474 * - removed a few ^M characters from fxmesa2.c file
476 * V0.18 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
477 * - the Mesa-2.4beta3 is finally using the driver quads support (the
478 * previous Mesa versions have never taken any advantage from the quads support !)
479 * - tested with the Glide 2.4 for Win
480 * - ported all asm code to Linux
481 * - ported the v0.18 to Linux (without asm code)
482 * - back to Linux !!!
483 * - optimized the SETUP macro (no more vertex snap for points and lines)
484 * - optimized the SETUP macro (added one argument)
485 * - the Mesa/Voodoo is now 20/30% for points, lines and small triangles !
486 * - performance improvement setting VBSIZE to 72
487 * - the GrVertex texture code is now written in asm
488 * - the GrVertex zbuffer code is now written in asm
489 * - the GrVertex wbuffer code is now written in asm
490 * - the GrVertex gouraud code is now written in asm
491 * - the GrVertex snap code is now written in asm
492 * - changed the 8bit compressed texture maps in 8bit palette texture maps
493 * support (it has the some advantage of compressed texture maps without the
494 * problem of a fixed NCC table for all mipmap levels)
495 * - written the support for 8bit compressed texture maps (but texture maps with
496 * more than one mipmap level aren't working fine)
497 * - finnaly everthing is working fine in MesaQuake !
498 * - fixed a bug in the computation of texture mapping coordinates (I have found
499 * the bug thanks to MesaQuake !)
500 * - written the GL_REPLACE support (mainly for MesaQuake)
501 * - written the support for textures with not all mipmap levels defined
502 * - rewritten all the Texture memory stuff
503 * - written the MesaQuake support (define MESAQUAKE)
504 * - working with a ZBuffer if glOrtho or not int the default glDepthRange,
505 * otherwise working with the WBuffer
506 * written the glDepthRange support
508 * Diego Picciani (d.picciani@novacomp.it) Nova Computer s.r.l.
509 * - written the fxCloseHardware() and the fxQuaryHardware() (mainly
510 * for the VoodooWGL emulator)
512 * Brian Paul (brianp@elastic.avid.com) Avid Technology
513 * - implemented read/write_color_span() so glRead/DrawPixels() works
514 * - now needs Glide 2.3 or later. Removed GLIDE_FULL_SCREEN and call to grSstOpen()
516 * V0.17 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
517 * - optimized the bitmap support (66% faster)
518 * - tested with the Mesa 2.3beta2
520 * Diego Picciani (d.picciani@novacomp.it) Nova Computer s.r.l.
521 * - solved a problem with the drawbitmap() and the Voodoo Rush
522 * (GR_ORIGIN_LOWER_LEFT did not work with the Stingray)
524 * Brian Paul (brianp@elastic.avid.com) Avid Technology
526 * - general code clean-up
527 * - added attribList parameter to fxMesaCreateContext()
528 * - single buffering works now
529 * - VB colors are now GLubytes, removed ColorShift stuff
534 * V0.16 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
535 * - written the quadfunc support (no performance improvement)
536 * - written the support for the new Mesa 2.3beta1 driver interface (Wow ! It is faaaster)
537 * - rewritten the glBitmap support for the Glide 2.3 (~35% slower !)
538 * - written the glBitmap support for the most common case (fonts)
541 * - Glide 2.3 porting
543 * Diego Picciani (d.picciani@novacomp.it) Nova Computer s.r.l.
544 * - extended the fxMesaCreateContext() and fxMesaCreateBestContext()
545 * functions in order to support also the Voodoo Rush
546 * - tested with the Hercules Stingray 128/3D (The rendering in a window works !)
548 * V0.15 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
549 * - written the GL_LUMINANCE_ALPHA support
550 * - written the GL_ALPHA support
551 * - written the GL_LUMINANCE support
552 * - now SETUP correctly set color for mono color sequences
553 * - written the 9x1,10x1,...,1x9,1x10,... texture map ratio support
554 * - written the no square texture map support
555 * - the fog table is no more rebuilt inside setup_fx_units() each time
557 * Henri Fousse (arnaud@pobox.oleane.com) Thomson Training & Simulation
558 * - written (not yet finished: no texture mapping) support for glOrtho
559 * - some change to setup functions
560 * - the fog support is now fully compatible with the standard OpenGL
561 * - rewritten several parts of the driver in order to take
562 * advantage of meshes (40% faster !!!)
564 * V0.14 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
565 * - now glAlphaFunc() works
566 * - now glDepthMask() works
567 * - solved a mipmap problem when using more than one texture
568 * - moved ti, texid and wscale inside the fxMesaContext (now we can
569 * easy support more ctx and more boards)
570 * - the management of the fxMesaContext was completly broken !
571 * - solved several problems about Alpha and texture Alpha
572 * - 4 (RGBA) texture channels supported
573 * - setting the default color to white
575 * Henri Fousse (arnaud@pobox.oleane.com) Thomson Training & Simulation
576 * - small change to fxMesaCreateContext() and fxMesaMakeCurrent()
577 * - written the fog support
578 * - setting the default clear color to black
579 * - written cleangraphics() for the onexit() function
580 * - written fxMesaCreateBestContext()
582 * V0.13 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
583 * - now glBlendFunc() works for all glBlendFunc without DST_ALPHA
584 * (because the alpha buffer is not yet implemented)
585 * - now fxMesaCreateContext() accept resolution and refresh rate
586 * - fixed a bug for texture mapping: the w (alias z) must be set
587 * also without depth buffer
588 * - fixed a bug for texture image with width!=256
589 * - written texparam()
590 * - written all point, line and triangle functions for all possible supported
591 * contexts and the driver is slight faster with points, lines and small triangles
592 * - fixed a small bug in fx/fxmesa.h (glOrtho)
594 * V0.12 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
595 * - glDepthFunc supported
596 * - introduced a trick to discover the far plane distance
597 * (see fxMesaSetFar and fx/fxmesa.h)
598 * - now the wbuffer works with homogeneous coordinate (and it
599 * doesn't work with a glOrtho projection :)
600 * - solved several problems with homogeneous coordinate and texture mapping
601 * - fixed a bug in all line functions
602 * - fixed a clear framebuffer bug
603 * - solved a display list/teximg problem (but use
604 * glBindTexture: it is several times faster)
606 * V0.11 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
607 * - introduced texture mapping support (not yet finished !)
608 * - tested with Mesa2.2b6
609 * - the driver is faster
610 * - written glFlush/glFinish
611 * - the driver print a lot of info about the Glide lib
613 * v0.1 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l.
626 fxMesaContext fxMesaCurrentCtx
=NULL
;
629 * Status of 3Dfx hardware initialization
632 static int glbGlideInitialized
=0;
633 static int glb3DfxPresent
=0;
634 static int glbTotNumCtx
=0;
636 GrHwConfiguration glbHWConfig
;
637 int glbCurrentBoard
=0;
640 #if defined(__WIN32__)
641 static int cleangraphics(void)
644 fxMesaDestroyContext(fxMesaCurrentCtx
);
648 #elif defined(__linux__)
649 static void cleangraphics(void)
652 fxMesaDestroyContext(fxMesaCurrentCtx
);
655 static void cleangraphics_handler(int s
)
657 fprintf(stderr
,"fxmesa: Received a not handled signal %d\n",s
);
667 * Select the Voodoo board to use when creating
670 GLboolean GLAPIENTRY
fxMesaSelectCurrentBoard(int n
)
674 if((n
<0) || (n
>=glbHWConfig
.num_sst
))
683 fxMesaContext GLAPIENTRY
fxMesaGetCurrentContext(void)
685 return fxMesaCurrentCtx
;
689 void GLAPIENTRY
fxMesaSetNearFar(GLfloat n
, GLfloat f
)
692 fxDDSetNearFar(fxMesaCurrentCtx
->glCtx
,n
,f
);
697 * The extension GL_FXMESA_global_texture_lod_bias
699 void GLAPIENTRY
glGlobalTextureLODBiasFXMESA(GLfloat biasVal
)
701 grTexLodBiasValue(GR_TMU0
,biasVal
);
703 if(fxMesaCurrentCtx
->haveTwoTMUs
)
704 grTexLodBiasValue(GR_TMU1
,biasVal
);
709 * The 3Dfx Global Palette extension for GLQuake.
710 * More a trick than a real extesion, use the shared global
713 void GLAPIENTRY
gl3DfxSetPaletteEXT(GLuint
*pal
)
715 fxMesaContext fxMesa
=fxMesaCurrentCtx
;
717 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
720 fprintf(stderr
,"fxmesa: gl3DfxSetPaletteEXT()\n");
723 fprintf(stderr
,"%x\n",pal
[i
]);
727 fxMesa
->haveGlobalPaletteTexture
=1;
729 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
,(GuTexPalette
*)pal
);
730 if (fxMesa
->haveTwoTMUs
)
731 FX_grTexDownloadTable(GR_TMU1
,GR_TEXTABLE_PALETTE
,(GuTexPalette
*)pal
);
736 static GrScreenResolution_t
fxBestResolution(int width
, int height
, int aux
)
738 static int resolutions
[][5]={
739 { 512, 384, GR_RESOLUTION_512x384
, 2, 2 },
740 { 640, 400, GR_RESOLUTION_640x400
, 2, 2 },
741 { 640, 480, GR_RESOLUTION_640x480
, 2, 2 },
742 { 800, 600, GR_RESOLUTION_800x600
, 4, 2 },
743 { 960, 720, GR_RESOLUTION_960x720
, 6, 4 }
744 #ifdef GR_RESOLUTION_1024x768
745 ,{ 1024, 768, GR_RESOLUTION_1024x768
, 8, 4 }
747 #ifdef GR_RESOLUTION_1280x1024
748 ,{ 1024, 768, GR_RESOLUTION_1280x1024
, 8, 8 }
750 #ifdef GR_RESOLUTION_1600x1200
751 ,{ 1024, 768, GR_RESOLUTION_1600x1200
, 16, 8 }
754 int NUM_RESOLUTIONS
= sizeof(resolutions
) / (sizeof(int)*5);
756 GrScreenResolution_t lastvalidres
=resolutions
[1][2];
760 if(glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_VOODOO
) {
761 fbmem
=glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.fbRam
;
763 if(glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.sliDetect
)
765 } else if(glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_SST96
)
766 fbmem
=glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
.fbRam
;
770 /* A work around for BZFlag */
772 if((width
==1) && (height
==1)) {
777 for(i
=0;i
<NUM_RESOLUTIONS
;i
++)
778 if(resolutions
[i
][4-aux
]<=fbmem
) {
779 if((width
<=resolutions
[i
][0]) && (height
<=resolutions
[i
][1]))
780 return resolutions
[i
][2];
782 lastvalidres
=resolutions
[i
][2];
789 fxMesaContext GLAPIENTRY
fxMesaCreateBestContext(GLuint win
,GLint width
, GLint height
,
790 const GLint attribList
[])
792 GrScreenRefresh_t refresh
;
795 refresh
=GR_REFRESH_75Hz
;
797 if(getenv("SST_SCREENREFRESH")) {
798 if(!strcmp(getenv("SST_SCREENREFRESH"),"60"))
799 refresh
=GR_REFRESH_60Hz
;
800 if(!strcmp(getenv("SST_SCREENREFRESH"),"70"))
801 refresh
=GR_REFRESH_70Hz
;
802 if(!strcmp(getenv("SST_SCREENREFRESH"),"72"))
803 refresh
=GR_REFRESH_72Hz
;
804 if(!strcmp(getenv("SST_SCREENREFRESH"),"75"))
805 refresh
=GR_REFRESH_75Hz
;
806 if(!strcmp(getenv("SST_SCREENREFRESH"),"80"))
807 refresh
=GR_REFRESH_80Hz
;
808 if(!strcmp(getenv("SST_SCREENREFRESH"),"85"))
809 refresh
=GR_REFRESH_85Hz
;
810 if(!strcmp(getenv("SST_SCREENREFRESH"),"90"))
811 refresh
=GR_REFRESH_90Hz
;
812 if(!strcmp(getenv("SST_SCREENREFRESH"),"100"))
813 refresh
=GR_REFRESH_100Hz
;
814 if(!strcmp(getenv("SST_SCREENREFRESH"),"120"))
815 refresh
=GR_REFRESH_120Hz
;
819 for(i
=0;attribList
[i
]!=FXMESA_NONE
;i
++)
820 if((attribList
[i
]==FXMESA_ALPHA_SIZE
) ||
821 (attribList
[i
]==FXMESA_DEPTH_SIZE
)) {
822 if(attribList
[++i
]>0) {
828 res
=fxBestResolution(width
,height
,aux
);
830 return fxMesaCreateContext(win
,res
,refresh
,attribList
);
837 signal(SIGINT
,SIG_IGN
);
838 signal(SIGHUP
,SIG_IGN
);
839 signal(SIGPIPE
,SIG_IGN
);
840 signal(SIGFPE
,SIG_IGN
);
841 signal(SIGBUS
,SIG_IGN
);
842 signal(SIGILL
,SIG_IGN
);
843 signal(SIGSEGV
,SIG_IGN
);
844 signal(SIGTERM
,SIG_IGN
);
849 * Create a new FX/Mesa context and return a handle to it.
851 fxMesaContext GLAPIENTRY
fxMesaCreateContext(GLuint win
,
852 GrScreenResolution_t res
,
853 GrScreenRefresh_t ref
,
854 const GLint attribList
[])
856 fxMesaContext fxMesa
= NULL
;
859 GLboolean doubleBuffer
=GL_FALSE
;
860 GLboolean alphaBuffer
=GL_FALSE
;
861 GLboolean verbose
=GL_FALSE
;
865 GLcontext
*shareCtx
= NULL
;
867 /*FX_GrContext_t glideContext = 0;*/
870 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
871 fprintf(stderr
,"fxmesa: fxMesaCreateContext() Start\n");
874 if(getenv("MESA_FX_INFO"))
879 while(attribList
[i
]!=FXMESA_NONE
) {
880 switch (attribList
[i
]) {
881 case FXMESA_DOUBLEBUFFER
:
882 doubleBuffer
=GL_TRUE
;
884 case FXMESA_ALPHA_SIZE
:
886 alphaBuffer
=attribList
[i
]>0;
890 case FXMESA_DEPTH_SIZE
:
892 depthSize
=attribList
[i
];
896 case FXMESA_STENCIL_SIZE
:
898 stencilSize
=attribList
[i
];
900 case FXMESA_ACCUM_SIZE
:
902 accumSize
=attribList
[i
];
904 /* XXX ugly hack here for sharing display lists */
905 #define FXMESA_SHARE_CONTEXT 990099 /* keep in sync with xmesa1.c! */
906 case FXMESA_SHARE_CONTEXT
:
909 const void *vPtr
= &attribList
[i
];
910 GLcontext
**ctx
= (GLcontext
**) vPtr
;
915 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
916 fprintf(stderr
,"fxmesa: fxMesaCreateContext() End (defualt)\n");
923 /* A workaround for Linux GLQuake */
924 if(depthSize
&& alphaBuffer
)
928 fprintf(stderr
,"Mesa fx Voodoo Device Driver v0.30\nWritten by David Bucciarelli (davibu@tin.it.it)\n");
930 if((type
=fxQueryHardware()) < 0) {
931 fprintf(stderr
,"fx Driver: ERROR no Voodoo1/2 Graphics or Voodoo Rush !\n");
935 if(type
==GR_SSTTYPE_VOODOO
)
938 grSstSelect(glbCurrentBoard
);
940 fxMesa
=(fxMesaContext
)calloc(1,sizeof(struct tfxMesaContext
));
946 if(glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_VOODOO
)
947 fxMesa
->haveTwoTMUs
=(glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.nTexelfx
> 1);
948 else if(glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_SST96
)
949 fxMesa
->haveTwoTMUs
=(glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
.nTexelfx
> 1);
951 fxMesa
->haveTwoTMUs
=GL_FALSE
;
953 fxMesa
->haveDoubleBuffer
=doubleBuffer
;
954 fxMesa
->haveAlphaBuffer
=alphaBuffer
;
955 fxMesa
->haveGlobalPaletteTexture
=GL_FALSE
;
956 fxMesa
->haveZBuffer
=depthSize
? 1 : 0;
957 fxMesa
->verbose
=verbose
;
958 fxMesa
->board
=glbCurrentBoard
;
961 fxMesa
->glideContext
= FX_grSstWinOpen((FxU32
)win
,res
,ref
,
967 GR_ORIGIN_LOWER_LEFT
,
969 if (!fxMesa
->glideContext
){
970 errorstr
= "grSstWinOpen";
974 /* Pixel tables are use during pixel read-back */
976 fxInitPixelTables(fxMesa
, GL_FALSE
); /* Force RGB pixel order */
978 if (glbHWConfig
.SSTs
[glbCurrentBoard
].type
== GR_SSTTYPE_VOODOO
) {
979 /* jk991130 - GROSS HACK!!! - Voodoo 3s don't use BGR!!
980 * the only way to tell if it's a Voodoo 3 at this stage of the
981 * ballgame (no Glide 3.x for linux *yet*) is to query the # of TMUs
982 * as Voodoo3s have 2 TMUs on board, Banshee has only 1
983 * Thanks to Joseph Kain for that one
985 if (glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.nTexelfx
== 2) {
986 fxInitPixelTables(fxMesa
, GL_FALSE
); /* use RGB pixel order (Voodoo3) */
989 fxInitPixelTables(fxMesa
, GL_TRUE
); /* use BGR pixel order on Voodoo1/2 */
993 fxInitPixelTables(fxMesa
, GL_FALSE
); /* use RGB pixel order otherwise */
997 fxMesa
->width
=FX_grSstScreenWidth();
998 fxMesa
->height
=FX_grSstScreenHeight();
1000 fxMesa
->clipMinX
= 0;
1001 fxMesa
->clipMaxX
= fxMesa
->width
;
1002 fxMesa
->clipMinY
= 0;
1003 fxMesa
->clipMaxY
= fxMesa
->height
;
1005 fxMesa
->screen_width
= fxMesa
->width
;
1006 fxMesa
->screen_height
= fxMesa
->height
;
1007 fxMesa
->x_offset
= 0;
1008 fxMesa
->y_offset
= 0;
1009 fxMesa
->y_delta
= 0;
1011 fxMesa
->needClip
= 0;
1014 fprintf(stderr
,"Glide screen size: %dx%d\n",
1015 (int)FX_grSstScreenWidth(),(int)FX_grSstScreenHeight());
1017 fxMesa
->glVis
=gl_create_visual(GL_TRUE
, /* RGB mode */
1020 GL_FALSE
, /* stereo */
1021 depthSize
, /* depth_size */
1022 stencilSize
, /* stencil_size */
1023 accumSize
, /* accum_size */
1025 5,6,5,0); /* RGBA bits */
1026 if (!fxMesa
->glVis
) {
1027 errorstr
= "gl_create_visual";
1031 ctx
= fxMesa
->glCtx
=gl_create_context(fxMesa
->glVis
,
1032 shareCtx
, /* share list context */
1033 (void *) fxMesa
, GL_TRUE
);
1035 errorstr
= "gl_create_context";
1040 if (!fxDDInitFxMesaContext( fxMesa
)) {
1041 errorstr
= "fxDDInitFxMesaContext failed";
1046 fxMesa
->glBuffer
=gl_create_framebuffer(fxMesa
->glVis
,
1047 GL_FALSE
, /* no software depth */
1048 fxMesa
->glVis
->StencilBits
> 0,
1049 fxMesa
->glVis
->AccumBits
> 0,
1050 fxMesa
->glVis
->AlphaBits
> 0 );
1051 if (!fxMesa
->glBuffer
) {
1052 errorstr
= "gl_create_framebuffer";
1058 /* install signal handlers */
1059 #if defined(__linux__)
1060 if (fxMesa
->glCtx
->CatchSignals
) {
1061 signal(SIGINT
,cleangraphics_handler
);
1062 signal(SIGHUP
,cleangraphics_handler
);
1063 signal(SIGPIPE
,cleangraphics_handler
);
1064 signal(SIGFPE
,cleangraphics_handler
);
1065 signal(SIGBUS
,cleangraphics_handler
);
1066 signal(SIGILL
,cleangraphics_handler
);
1067 signal(SIGSEGV
,cleangraphics_handler
);
1068 signal(SIGTERM
,cleangraphics_handler
);
1072 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1073 fprintf(stderr
,"fxmesa: fxMesaCreateContext() End\n");
1080 if (fxMesa
->glideContext
)
1081 FX_grSstWinClose(fxMesa
->glideContext
);
1082 fxMesa
->glideContext
= 0;
1085 free(fxMesa
->state
);
1086 if (fxMesa
->fogTable
)
1087 free(fxMesa
->fogTable
);
1088 if (fxMesa
->glBuffer
)
1089 gl_destroy_framebuffer(fxMesa
->glBuffer
);
1091 gl_destroy_visual(fxMesa
->glVis
);
1093 gl_destroy_context(fxMesa
->glCtx
);
1097 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1098 fprintf(stderr
,"fxmesa: fxMesaCreateContext() End (%s)\n",errorstr
);
1105 * Function to set the new window size in the context (mainly for the Voodoo Rush)
1107 void GLAPIENTRY
fxMesaUpdateScreenSize(fxMesaContext fxMesa
)
1109 fxMesa
->width
=FX_grSstScreenWidth();
1110 fxMesa
->height
=FX_grSstScreenHeight();
1115 * Destroy the given FX/Mesa context.
1117 void GLAPIENTRY
fxMesaDestroyContext(fxMesaContext fxMesa
)
1119 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1120 fprintf(stderr
,"fxmesa: fxMesaDestroyContext()\n");
1124 gl_destroy_visual(fxMesa
->glVis
);
1125 gl_destroy_context(fxMesa
->glCtx
);
1126 gl_destroy_framebuffer(fxMesa
->glBuffer
);
1131 FX_grSstWinClose(fxMesa
->glideContext
);
1133 if(fxMesa
->verbose
) {
1134 fprintf(stderr
,"Misc Stats:\n");
1135 fprintf(stderr
," # swap buffer: %u\n",fxMesa
->stats
.swapBuffer
);
1137 if(!fxMesa
->stats
.swapBuffer
)
1138 fxMesa
->stats
.swapBuffer
=1;
1140 fprintf(stderr
,"Textures Stats:\n");
1141 fprintf(stderr
," Free texture memory on TMU0: %d:\n",fxMesa
->freeTexMem
[FX_TMU0
]);
1142 if(fxMesa
->haveTwoTMUs
)
1143 fprintf(stderr
," Free texture memory on TMU1: %d:\n",fxMesa
->freeTexMem
[FX_TMU1
]);
1144 fprintf(stderr
," # request to TMM to upload a texture objects: %u\n",
1145 fxMesa
->stats
.reqTexUpload
);
1146 fprintf(stderr
," # request to TMM to upload a texture objects per swapbuffer: %.2f\n",
1147 fxMesa
->stats
.reqTexUpload
/(float)fxMesa
->stats
.swapBuffer
);
1148 fprintf(stderr
," # texture objects uploaded: %u\n",
1149 fxMesa
->stats
.texUpload
);
1150 fprintf(stderr
," # texture objects uploaded per swapbuffer: %.2f\n",
1151 fxMesa
->stats
.texUpload
/(float)fxMesa
->stats
.swapBuffer
);
1152 fprintf(stderr
," # MBs uploaded to texture memory: %.2f\n",
1153 fxMesa
->stats
.memTexUpload
/(float)(1<<20));
1154 fprintf(stderr
," # MBs uploaded to texture memory per swapbuffer: %.2f\n",
1155 (fxMesa
->stats
.memTexUpload
/(float)fxMesa
->stats
.swapBuffer
)/(float)(1<<20));
1158 free(fxMesa
->state
);
1159 if (fxMesa
->fogTable
)
1160 free(fxMesa
->fogTable
);
1166 if(fxMesa
==fxMesaCurrentCtx
)
1167 fxMesaCurrentCtx
=NULL
;
1172 * Make the specified FX/Mesa context the current one.
1174 void GLAPIENTRY
fxMesaMakeCurrent(fxMesaContext fxMesa
)
1176 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1177 fprintf(stderr
,"fxmesa: fxMesaMakeCurrent(...) Start\n");
1181 gl_make_current(NULL
,NULL
);
1182 fxMesaCurrentCtx
=NULL
;
1184 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1185 fprintf(stderr
,"fxmesa: fxMesaMakeCurrent(NULL) End\n");
1191 /* if this context is already the current one, we can return early */
1192 if (fxMesaCurrentCtx
== fxMesa
1193 && fxMesaCurrentCtx
->glCtx
== gl_get_current_context()) {
1194 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1195 fprintf(stderr
,"fxmesa: fxMesaMakeCurrent(fxMesaCurrentCtx==fxMesa) End\n");
1201 if(fxMesaCurrentCtx
)
1202 grGlideGetState((GrState
*)fxMesaCurrentCtx
->state
);
1204 fxMesaCurrentCtx
=fxMesa
;
1206 grSstSelect(fxMesa
->board
);
1207 grGlideSetState((GrState
*)fxMesa
->state
);
1209 gl_make_current(fxMesa
->glCtx
,fxMesa
->glBuffer
);
1211 fxSetupDDPointers(fxMesa
->glCtx
);
1213 /* The first time we call MakeCurrent we set the initial viewport size */
1214 if(fxMesa
->glCtx
->Viewport
.Width
==0)
1215 gl_Viewport(fxMesa
->glCtx
,0,0,fxMesa
->width
,fxMesa
->height
);
1217 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1218 fprintf(stderr
,"fxmesa: fxMesaMakeCurrent(...) End\n");
1224 * Swap front/back buffers for current context if double buffered.
1226 void GLAPIENTRY
fxMesaSwapBuffers(void)
1228 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1229 fprintf(stderr
,"fxmesa: ------------------------------- fxMesaSwapBuffers() -------------------------------\n");
1232 if(fxMesaCurrentCtx
) {
1233 FLUSH_VB( fxMesaCurrentCtx
->glCtx
, "swap buffers" );
1235 if(fxMesaCurrentCtx
->haveDoubleBuffer
) {
1237 grBufferSwap(fxMesaCurrentCtx
->swapInterval
);
1240 * Don't allow swap buffer commands to build up!
1242 while(FX_grGetInteger(FX_PENDING_BUFFERSWAPS
)>fxMesaCurrentCtx
->maxPendingSwapBuffers
)
1243 /* The driver is able to sleep when waiting for the completation
1244 of multiple swapbuffer operations instead of wasting
1245 CPU time (NOTE: you must uncomment the following line in the
1246 in order to enable this option) */
1247 /* usleep(10000); */
1250 fxMesaCurrentCtx
->stats
.swapBuffer
++;
1257 * Query 3Dfx hardware presence/kind
1259 int GLAPIENTRY
fxQueryHardware(void)
1261 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1262 fprintf(stderr
,"fxmesa: fxQueryHardware() Start\n");
1265 if(!glbGlideInitialized
) {
1267 if(FX_grSstQueryHardware(&glbHWConfig
)) {
1268 grSstSelect(glbCurrentBoard
);
1271 if(getenv("MESA_FX_INFO")) {
1274 FX_grGlideGetVersion(buf
);
1275 fprintf(stderr
,"Using Glide V%s\n","");
1276 fprintf(stderr
,"Number of boards: %d\n",glbHWConfig
.num_sst
);
1278 if(glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_VOODOO
) {
1279 fprintf(stderr
,"Framebuffer RAM: %d\n",
1280 glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.sliDetect
?
1281 (glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.fbRam
*2) :
1282 glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.fbRam
);
1283 fprintf(stderr
,"Number of TMUs: %d\n",
1284 glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.nTexelfx
);
1285 fprintf(stderr
,"SLI detected: %d\n",
1286 glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.VoodooConfig
.sliDetect
);
1287 } else if(glbHWConfig
.SSTs
[glbCurrentBoard
].type
==GR_SSTTYPE_SST96
) {
1288 fprintf(stderr
,"Framebuffer RAM: %d\n",
1289 glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
.fbRam
);
1290 fprintf(stderr
,"Number of TMUs: %d\n",
1291 glbHWConfig
.SSTs
[glbCurrentBoard
].sstBoard
.SST96Config
.nTexelfx
);
1298 glbGlideInitialized
=1;
1300 #if defined(__WIN32__)
1301 onexit((_onexit_t
)cleangraphics
);
1302 #elif defined(__linux__)
1303 atexit(cleangraphics
);
1307 if(!glb3DfxPresent
) {
1308 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1309 fprintf(stderr
,"fxmesa: fxQueryHardware() End (-1)\n");
1314 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1315 fprintf(stderr
,"fxmesa: fxQueryHardware() End (voodooo)\n");
1317 return(glbHWConfig
.SSTs
[glbCurrentBoard
].type
);
1322 * Shutdown Glide library
1324 void GLAPIENTRY
fxCloseHardware(void)
1326 if(glbGlideInitialized
) {
1327 if(getenv("MESA_FX_INFO")) {
1328 GrSstPerfStats_t st
;
1330 FX_grSstPerfStats(&st
);
1331 fprintf(stderr
,"Pixels Stats:\n");
1332 fprintf(stderr
," # pixels processed (minus buffer clears): %u\n",(unsigned)st
.pixelsIn
);
1333 fprintf(stderr
," # pixels not drawn due to chroma key test failure: %u\n",(unsigned)st
.chromaFail
);
1334 fprintf(stderr
," # pixels not drawn due to depth test failure: %u\n",(unsigned)st
.zFuncFail
);
1335 fprintf(stderr
," # pixels not drawn due to alpha test failure: %u\n",(unsigned)st
.aFuncFail
);
1336 fprintf(stderr
," # pixels drawn (including buffer clears and LFB writes): %u\n",(unsigned)st
.pixelsOut
);
1339 if(glbTotNumCtx
==0) {
1341 glbGlideInitialized
=0;
1351 * Need this to provide at least one external definition.
1354 int gl_fx_dummy_function_api(void)