diff options
author | alanh <alanh> | 2000-09-07 12:40:20 +0000 |
---|---|---|
committer | alanh <alanh> | 2000-09-07 12:40:20 +0000 |
commit | fee7ff6c1570ea50355b9978b4df0c81230c86ae (patch) | |
tree | a600784270f03a92ab14fe7fe4f9dc59495e546e | |
parent | c40835a30a8a4e928bf607e4dfbf8be5e893642a (diff) |
Merged tdfx-2-1-branchtdfx-2-1-20000907-merge
175 files changed, 18964 insertions, 17225 deletions
diff --git a/xc/config/cf/host.def b/xc/config/cf/host.def index ebb4d7d6e..989f19e16 100644 --- a/xc/config/cf/host.def +++ b/xc/config/cf/host.def @@ -13,6 +13,10 @@ #define BuildXF86DRI YES #define HasGlide3 YES +#ifdef i386Architecture +#define MesaUse3DNow +#endif + /* To do profiling turn on this plus one of the builtin drivers*/ /* #define ProfileLibGlx YES */ @@ -33,3 +37,4 @@ #define XnestServer NO #define XVirtualFramebufferServer NO #define XprtServer NO + diff --git a/xc/config/cf/linux.cf b/xc/config/cf/linux.cf index 69ebca6b7..555c4339e 100644 --- a/xc/config/cf/linux.cf +++ b/xc/config/cf/linux.cf @@ -180,6 +180,8 @@ XCOMM binutils: (LinuxBinUtilsMajorVersion) # endif # elif defined(SparcArchitecture) # define BuildXF86DRI YES +# elif defined(AlphaArchitecture) +# define BuildXF86DRI YES # else # define BuildXF86DRI NO # endif diff --git a/xc/config/cf/xfree86.cf b/xc/config/cf/xfree86.cf index ee207fae7..dc84604f0 100644 --- a/xc/config/cf/xfree86.cf +++ b/xc/config/cf/xfree86.cf @@ -611,10 +611,15 @@ IPLAN2P8_DEFS = -DUSE_IPLAN2P8 # define GlxCoreLibDefines /**/ # endif -# if defined(SparcArchitecture) +# if defined(SparcArchitecture) # define GlxArchDefines -D__GLX_ALIGN64 # else -# define GlxArchDefines /**/ +# if defined(AlphaArchitecture) +/* On the Alpha we need to ensure floating point accuracy for 3D */ +# define GlxArchDefines -mieee +# else +# define GlxArchDefines /**/ +# endif # endif # ifndef GlxExtraDefines diff --git a/xc/extras/Mesa/include/GL/gl.h b/xc/extras/Mesa/include/GL/gl.h index 7266dbc29..78c5efbd5 100644 --- a/xc/extras/Mesa/include/GL/gl.h +++ b/xc/extras/Mesa/include/GL/gl.h @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -851,7 +851,7 @@ typedef double GLclampd; /* double precision float in [0,1] */ #define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 #define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 -#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF +#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF diff --git a/xc/extras/Mesa/include/GL/glext.h b/xc/extras/Mesa/include/GL/glext.h index 3ee1cef05..f721a9fd7 100644 --- a/xc/extras/Mesa/include/GL/glext.h +++ b/xc/extras/Mesa/include/GL/glext.h @@ -2712,6 +2712,12 @@ extern void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, GLenum, extern void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, GLenum); extern void APIENTRY glGetCombinerInputParameterfvNV (GLenum, GLenum, GLenum, GLenum, GLfloat *); extern void APIENTRY glGetCombinerInputParameterivNV (GLenum, GLenum, GLenum, GLenum, GLint *); +#ifdef VMS + #define glGetCombinerOutputParameterfvNV glGetCombinerOutputParameterfvN + #define glGetCombinerOutputParameterivNV glGetCombinerOutputParameterivN + #define glGetFinalCombinerInputParameterfvNV glGetFinalCombinerInputParafvNV + #define glGetFinalCombinerInputParameterivNV glGetFinalCombinerInputParaivNV +#endif extern void APIENTRY glGetCombinerOutputParameterfvNV (GLenum, GLenum, GLenum, GLfloat *); extern void APIENTRY glGetCombinerOutputParameterivNV (GLenum, GLenum, GLenum, GLint *); extern void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum, GLenum, GLfloat *); diff --git a/xc/extras/Mesa/src/FX/fxapi.c b/xc/extras/Mesa/src/FX/fxapi.c deleted file mode 100644 index 6d680bcb9..000000000 --- a/xc/extras/Mesa/src/FX/fxapi.c +++ /dev/null @@ -1,1424 +0,0 @@ -/* -*- mode: C; tab-width:8; -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxapi.c - 3Dfx VooDoo/Mesa interface */ - - -/******************************************************************** - * - * Function names: - * fxMesa.... (The driver API) - * fxDD.... (Mesa device driver functions) - * fxTM.... (Texture manager functions) - * fxSetup.... (Voodoo units setup functions) - * fx.... (Internal driver functions) - * - * Data type names: - * fxMesa.... (Public driver data types) - * tfx.... (Private driver data types) - * - ******************************************************************** - * - * V0.30 - David Bucciarelli (davibu@tin.it) Humanware s.r.l. - * - introduced a new MESA_GLX_FX related behavior - * - the Glide fog table was built in a wrong way (using - * gu* Glide function). Added the code for building the - * table following the OpenGL specs. Thanks to Steve Baker - * for highlighting the problem. - * - fixed few problems in my and Keith's fxDDClear code - * - merged my code with the Keith's one - * - used the new BlendFunc Mesa device driver function - * - used the new AlphaFunc Mesa device driver function - * - used the new Enable Mesa device driver function - * - fixed a bug related to fog in the Mesa core. Fog - * were applied two times: at vertex level and at fragment - * level (thanks to Steve Baker for reporting the problem) - * - glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE) now works - * (thanks to Jiri Pop for reporting the problem) - * - the driver works fine with OpenGL Unreal - * - fixed a bug in the Mesa core clipping code (related - * to the q texture coordinate) - * - introduced the support for the q texture coordinate - * - * Keith Whitwell (keithw@cableinet.co.uk) - * - optimized the driver and written all the new code - * required by the new Mesa-3.1 device driver API - * and by the new Mesa-3.1 core changes - * - written the cva support and many other stuff - * - * Brian Paul (brian_paul@avid.com) Avid Technology - * - fixed display list share bug for MESA_GLX_FX = window/fullscreen - * - fixed glClear/gl...Mask related problem - * - * Bert Schoenwaelder (bert@prinz-atm.CS.Uni-Magdeburg.De) - * - the driver is now able to sleep when waiting for the completation - * of multiple swapbuffer operations instead of wasting - * CPU time (NOTE: you must uncomment the lines in the - * fxMesaSwapBuffers function in order to enable this option) - * - * Eero Pajarre (epajarre@koti.tpo.fi) - * - enabled the macro FLOAT_COLOR_TO_UBYTE_COLOR under - * windows - * - written an asm x86 optimized float->integer conversions - * for windows - * - * Theodore Jump (tjump@cais.com) - * - fixed a small problem in the __wglMonitor function of the - * wgl emulator - * - written the in-window-rendering hack support for windows - * and Vooodoo1/2 cards - * - * V0.29 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - included in Mesa-3.0 - * - now glGetString(GL_RENDERER) returns more information - * about the hardware configuration: "Mesa Glide <version> - * <Voodoo_Graphics|Voodoo_Rush|UNKNOWN> <num> CARD/<num> FB/ - * <num> TM/<num> TMU/<NOSLI|SLI>" - * where: <num> CARD is the card used for the current context, - * <num> FB is the number of MB for the framebuffer, - * <num> TM is the number of MB for the texture memory, - * <num> TMU is the number of TMU. You can try to run - * Mesa/demos/glinfo in order to have an example of the - * output - * - fixed a problem of the WGL emulator with the - * OpenGL Optimizer 1.1 (thanks to Erwin Coumans for - * the bug report) - * - fixed some bug in the fxwgl.c code (thanks to - * Peter Pettersson for a patch and a bug report) - * - * Theodore Jump (tjump@cais.com) - * - written the SST_DUALHEAD support in the WGL emulator - * - * Daryll Strauss (daryll@harlot.rb.ca.us) - * - fixed the Voodoo Rush support for the in window rendering - * - * V0.28 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - the only supported multitexture functions are GL_MODULATE - * for texture set 0 and GL_MODULATE for texture set 1. In - * all other cases, the driver falls back to pure software - * rendering - * - written the support for the new GL_EXT_multitexture - * - written the DD_MAX_TEXTURE_COORD_SETS support in the - * fxDDGetParameteri() function - * - the driver falls back to pure software rendering when - * texture mapping function is GL_BLEND - * - * V0.27 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - inluded in the Mesa-3.0beta5 - * - written a smal extension (GL_FXMESA_global_texture_lod_bias) in - * order to expose the LOD bias related Glide function - * - fixed a bug fxDDWriteMonoRGBAPixels() - * - the driver is now able to fallback to software rendering in - * any case not directly supported by the hardware - * - written the support for enabling/disabling dithering - * - the in-window-rendering hack now works with any X11 screen - * depth - * - fixed a problem related to color/depth/alpha buffer clears - * - fixed a problem when clearing buffer for a context with the - * alpha buffer - * - fixed a problem in the fxTMReloadSubMipMapLevel() function, - * I have forget a "break;" (thanks to Joe Waters for the bug report) - * - fixed a problem in the color format for the in window - * rendering hack - * - written the fxDDReadRGBAPixels function - * - written the fxDDDepthTestPixelsGeneric function - * - written the fxDDDepthTestSpanGeneric function - * - written the fxDDWriteMonoRGBAPixels function - * - written the fxDDWriteRGBAPixels function - * - removed the multitexture emulation code for Voodoo board - * with only one TMU - * - * Chris Prince <cprince@cs.washington.edu> - * - fixed a new bug in the wglUseFontBitmaps code - * - * Ralf Knoesel (rknoesel@Stormfront.com) - * - fixed a bug in the wglUseFontBitmaps code - * - * Rune Hasvold (runeh@ifi.uio.no) - * - fixed a problem related to the aux usage in the fxBestResolution - * function - * - fixed the order of pixel formats in the WGL emulator - * - * Fredrik Hubinette (hubbe@hubbe.net) - * - the driver shutdown the Glide for most common signals - * - * V0.26 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - included in the Mesa-3.0beta4 - * - fixed a problem related to a my optimization for the Rune's - * pixel-span optimization - * - fixed a problem related to fxDDSetNearFar() and ctx->ProjectionMatrixType - * (thanks to Ben "Ctrl-Alt-Delete" and the Raul Alonso's ssystem) - * - fixed a small bug in the Rune's pixel-span optimization - * - fixed a problem with GL_CCW (thanks to Curt Olson for and example - * of the problem) - * - grVertex setup code is now ready for the internal thread support - * - fixed a no used optimization with clipped vertices in - * grVertex setup code - * - fixed a problem in the GL_LIGHT_MODEL_TWO_SIDE support (thanks - * to Patrick H. Madden for a complete example of the bug) - * - * Rune Hasvold (runeh@ifi.uio.no) - * - highly optimized the driver functions for writing pixel - * span (2-3 times faster !) - * - * Axel W. Volley (volley@acm.org) Krauss-Maffei Wehrtechnik - * - written the fxDDReadDepthSpanFloat() and fxDDReadDepthSpanInt() - * functions - * - * V0.25 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - fixed a problem with Voodoo boards with only one TMU - * - fixed a bug in the fxMesaCreateContext() - * - now the GL_FRONT_AND_BACK works fine also with - * the alpha buffer and/or antialiasing - * - written the support for GL_FRONT_AND_BACK drawing but - * it doesn't works with the alpha buffer and/or antialiasing - * - fixed some bug in the Mesa core for glCopyTexSubImage - * and glCopyTexImage functions (thanks to Mike Connell - * for an example of the problem) - * - make some small optimizations in the Mesa core in order - * to save same driver call and state change for not very - * well written applications - * - introduced the NEW_DRVSTATE and make other optimizations - * for minimizing state changes - * - made a lot of optimizations in order to minimize state - * changes - * - it isn't more possible to create a context with the - * depth buffer and the stancil buffer (it isn't yet supported) - * - now the partial support for the Multitexture extension - * works with Quake2 for windows - * - vertex snap is not longer used for the Voodoo2 (FX_V2 - * must be defined) - * - done a lot of cleanup in the fxsetup.c file - * - now the partial support for the Multitexture extension - * works with GLQuake for windows - * - * Dieter Nuetzel (nuetzel@kogs.informatik.uni-hamburg.de) University of Hamburg - * - fixed a problem in the asm code for Linux of the fxvsetup.c file - * highlighted by the binutils-2.8.1.0.29. 'fildw' asm instruction - * changed in 'fild' - * - * Kevin Hester (kevinh@glassworks.net) - * - written the wglUseFontBitmaps() function in the WGL emulator - * - * V0.24 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - now the drive always uses per fragment fog - * - written a small optimization in the points drawing function - * - written the support for trilinear filtering with 2 TMUs - * - written the first partial support for the Multitexture extension. - * This task is quite hard because the color combine units work after - * the two texture combine units and not before as required by the - * Multitexture extension - * - written a workaround in fxBestResolution() in order to solve a - * problem with bzflag (it asks for 1x1 window !) - * - changed the fxBestResolution() behavior. It now returns the larger - * screen resolution supported by the hardware (instead of 640x480) - * when it is unable to find an appropriate resolution that is large - * enough for the requested size - * - the driver is now able to use also the texture memory attached to - * second TMU - * - the texture memory manager is now able to work with two TMUs and - * store texture maps in the memory attached to TMU0, TMU1 or to split - * the mimpmap levels across TMUs in order to support trilinear filtering - * - I have bought a Voodoo2 board ! - * - the amount of frambuffer ram is now doubled when an SLI configuration - * is detected - * - solved a problem related to the fxDDTexParam() and fxTexInvalidate() - * functions (thanks to Rune Hasvold for highlighting the problem) - * - done some cleanup in the fxvsetup.c file, written - * the FXVSETUP_FUNC macro - * - done a lot of cleanup in data types and field names - * - * Rune Hasvold (runeh@ifi.uio.no) - * - written the support for a right management of the auxiliary buffer. - * You can now use an 800x600 screen without the depth and alpha - * buffer - * - written the support for a new pixel format (without the depth - * and alpha buffer) in the WGL emulator - * - fixed a bug in the window version of the GLUT (it was ever asking - * for depth buffer) - * - * V0.23 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - included in the Mesa-3.0beta2 release - * - written the support for the OpenGL 1.2 GL_TEXTURE_BASE_LEVEL - * and GL_TEXTURE_MAX_LEVEL - * - rewritten several functions for a more clean support of texture - * mapping and in order to solve some bug - * - the accumulation buffer works (it is bit slow beacuase it requires - * to read/write from/to the Voodoo frame buffer but it works) - * - fixed a bug in the fxDDReadRGBASpan driver function (the R and - * B channels were read in the wrong order). Thanks to Jason Heym - * for highlighting the problem - * - written the support for multiple contexts on multiple boards. - * you can now use the Mesa/Voodoo with multiple Voodoo Graphics - * boards (for example with multiple screens or an HMD) - * - the fxBestResolution() now check all available resolutions - * and it is able to check the amount of framebuffer memory - * before return a resolution - * - modified the GLX/X11 driver in order to support all the - * resolution available - * - changed all function names. They should be now a bit more - * readable - * - written the Glide grVertex setup code for two TMU or - * for Multitexture support with emulationa dn one TMU - * - written the support for the new Mesa driver - * function GetParametri - * - small optimization/clean up in the texbind() function - * - fixed a FPU precision problem for glOrtho and texture - * mapping (thanks to Antti Juhani Huovilainen for an example - * of the problem) - * - written some small SGI OpenGL emulation code for the wgl, - * the OpenGL Optimizer and Cosmo3D work fine under windows ! - * - moved the point/line/triangle/quad support in the fxmesa7.c - * - fixed a bug in the clear_color_depth() (thanks to Henk Kok - * for an example of the problem) - * - written a small workaround for Linux GLQuake, it asks - * for the alpha buffer and the depth buffer at the some time - * (but it never uses the alpha buffer) - * - checked the antialiasing points, lines and polygons support. - * It works fine - * - written the support for standard OpenGL antialiasing using - * blending. Lines support works fine (tested with BZflag) - * while I have still to check the polygons and points support - * - written the support for the alpha buffer. The driver is now - * able to use the Voodoo auxiliary buffer as an alpha buffer - * instead of a depth buffer. Also all the OpenGL blending - * modes are now supported. But you can't request a context - * with an alpha buffer AND a depth buffer at the some time - * (this is an hardware limitation) - * - written the support for switching between the fullscreen - * rendering and the in-window-rendering hack on the fly - * - * Rune Hasvold (runeh@ifi.uio.no) - * - fixed a bug in the texparam() function - * - * Brian Paul (brianp@elastic.avid.com) Avid Technology - * - sources accomodated for the new Mesa 3.0beta1 - * - * V0.22 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - included with some v0.23 bug fix in the final release - * of the Mesa-2.6 - * - written the support for the MESA_WGL_FX env. var. but - * not tested because I have only Voodoo Graphics boards - * - fixed a bug in the backface culling code - * (thanks to David Farrell for an example of the problem) - * - fixed the "Quake2 elevator" bug - * - GL_POLYGONS with 3/4 vertices are now drawn as - * GL_TRIANLGES/GL_QUADS (a small optimization for GLQuake) - * - fixed a bug in fxmesa6.h for GL_LINE_LOOP - * - fixed a NearFarStack bug in the Mesa when applications - * directly call glLoadMatrix to load a projection matrix - * - done some cleanup in the fxmesa2.c file - * - the driver no longer translates the texture maps - * when the Mesa internal format and the Voodoo - * format are the some (usefull for 1 byte texture maps - * where the driver can directly use the Mesa texture - * map). Also the amount of used memory is halfed - * - fixed a bug for GL_DECAL and GL_RGBA - * - fixed a bug in the clear_color_depth() - * - tested the v0.22 with the Mesa-2.6beta2. Impressive - * performances improvement thanks to the new Josh's - * asm code (+10fps in the isosurf demo, +5fps in GLQuake - * TIMEREFRESH) - * - written a optimized version of the RenderVB Mesa driver - * function. The Voodoo driver is now able to upload polygons - * in the most common cases at a very good speed. Good - * performance improvement for large set of small polygons - * - optimized the asm code for setting up the color information - * in the Glide grVertex structure - * - fixed a bug in the fxmesa2.c asm code (the ClipMask[] - * wasn't working) - * - * Josh Vanderhoof (joshv@planet.net) - * - removed the flush() function because it isn't required - * - limited the maximum number of swapbuffers in the Voodoo - * commands FIFO (controlled by the env. var. MESA_FX_SWAP_PENDING) - * - * Holger Kleemiss (holger.kleemiss@metronet.de) STN Atlas Elektronik GmbH - * - applied some patch for the Voodoo Rush - * - * V0.21 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - the driver is now able to take advantage of the ClipMask[], - * ClipOrMask and ClipAndMask information also under Windows - * - introduced a new function in the Mesa driver interface - * ClearColorAndDepth(). Now the glClear() function is - * 2 times faster (!) when you have to clear the color buffer - * and the depth buffer at some time - * - written the first version of the fxRenderVB() driver - * function - * - optimized the glTexImage() path - * - removed the fxMesaTextureUsePalette() support - * - fixed a bug in the points support (thanks to David Farrell - * for an example of the problem) - * - written the optimized path for glSubTexImage(), - * introduced a new function in the Mesa driver interface - * TexSubImage(...) - * - fixed a bug for glColorMask and glDepthMask - * - the wbuffer is not more used. The Voodoo driver uses - * a standard 16bit zbuffer in all cases. It is more consistent - * and now GLQuake and GLQuake2test work also with a GL_ZTRICK 0 - * - the driver is now able to take advantage of the ClipMask[], - * ClipOrMask and ClipAndMask information (under Linux); - * - rewritten the setup_fx_units() function, now the texture - * mapping support is compliant to the OpenGL specs (GL_BLEND - * support is still missing). The LinuxGLQuake console correctly - * fade in/out and transparent water of GLQuake2test works fine - * - written the support for the env. var. FX_GLIDE_SWAPINTERVAL - * - found a bug in the Mesa core. There is a roundup problem for - * color values out of the [0.0,1.0] range - * - * Wonko <matt@khm.de> - * - fixed a Voodoo Rush related problem in the fxwgl.c - * - * Daryll Strauss <daryll@harlot.rb.ca.us> - * - written the scissor test support - * - * V0.20 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - written the closetmmanger() function in order to free all the memory - * allocated by the Texture Memory Manager (it will be useful - * when the support for multiple contexts/boards will be ready) - * - now the Voodoo driver runs without printing any information, - * define the env. var. MESA_FX_INFO if you want to read some - * information about the hardware and some statistic - * - written a small workaround for the "GLQuake multiplayer white box bug" - * in the setup_fx_units() funxtions. I'm already rewriting - * this function because it is the source of nearly all the current - * Voodoo driver problems - * - fixed the GLQuake texture misalignment problem (the texture - * coordinates must be scaled between 0.0 and 256.0 and not - * between 0.0 and 255.0) - * - written the support for the GL_EXT_shared_texture_palette - * - some small change for supporting the automatic building of the - * OpenGL32.dll under the Windows platform - * - the redefinition of a mipmap level is now a LOT faster. This path - * is used by GLQuake for dynamic lighting with some call to glTexSubImage2D() - * - the texture memory is now managed a set of 2MB blocks so - * texture maps can't be allocated on a 2MB boundary. The new Pure3D - * needs this kind of support (and probably any other Voodoo Graphics - * board with more than 2MB of texture memory) - * - * Brian Paul (brianp@elastic.avid.com) Avid Technology - * - added write_monocolor_span(), fixed bug in write_color_span() - * - added test for stenciling in choosepoint/line/triangle functions - * - * Joe Waters (falc@attila.aegistech.com) Aegis - * - written the support for the env. var. SST_SCREENREFRESH - * - * V0.19 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - written the 3Dfx Global Palette extension for GLQuake - * - written the support for the GL_EXT_paletted_texture (it works only with GL_RGBA - * palettes and the alpha value is ignored ... this is a limitation of the - * the current Glide version and Voodoo hardware) - * - fixed the amount of memory allocated for 8bit textures - * - merged the under construction v0.19 driver with the Mesa 2.5 - * - finally written the support for deleting textures - * - introduced a new powerful texture memory manager: the texture memory - * is used as a cache of the set of all defined texture maps. You can - * now define several MB of texture maps also with a 2MB of texture memory - * (the texture memory manager will do automatically all the swap out/swap in - * work). The new texture memory manager has also - * solved a lot of other bugs/no specs compliance/problems - * related to the texture memory usage. The texture - * manager code is inside the new fxmesa3.c file - * - broken the fxmesa.c file in two files (fxmesa1.c and fxmesa2.c) - * and done some code cleanup - * - now is possible to redefine texture mipmap levels already defined - * - fixed a problem with the amount of texture memory allocated for textures - * with not all mipmap levels defined - * - fixed a small problem with single buffer rendering - * - * Brian Paul (brianp@elastic.avid.com) Avid Technology - * - read/write_color_span() now use front/back buffer correctly - * - create GLvisual with 5,6,5 bits per pixel, not 8,8,8 - * - removed a few ^M characters from fxmesa2.c file - * - * V0.18 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - the Mesa-2.4beta3 is finally using the driver quads support (the - * previous Mesa versions have never taken any advantage from the quads support !) - * - tested with the Glide 2.4 for Win - * - ported all asm code to Linux - * - ported the v0.18 to Linux (without asm code) - * - back to Linux !!! - * - optimized the SETUP macro (no more vertex snap for points and lines) - * - optimized the SETUP macro (added one argument) - * - the Mesa/Voodoo is now 20/30% for points, lines and small triangles ! - * - performance improvement setting VBSIZE to 72 - * - the GrVertex texture code is now written in asm - * - the GrVertex zbuffer code is now written in asm - * - the GrVertex wbuffer code is now written in asm - * - the GrVertex gouraud code is now written in asm - * - the GrVertex snap code is now written in asm - * - changed the 8bit compressed texture maps in 8bit palette texture maps - * support (it has the some advantage of compressed texture maps without the - * problem of a fixed NCC table for all mipmap levels) - * - written the support for 8bit compressed texture maps (but texture maps with - * more than one mipmap level aren't working fine) - * - finnaly everthing is working fine in MesaQuake ! - * - fixed a bug in the computation of texture mapping coordinates (I have found - * the bug thanks to MesaQuake !) - * - written the GL_REPLACE support (mainly for MesaQuake) - * - written the support for textures with not all mipmap levels defined - * - rewritten all the Texture memory stuff - * - written the MesaQuake support (define MESAQUAKE) - * - working with a ZBuffer if glOrtho or not int the default glDepthRange, - * otherwise working with the WBuffer - * written the glDepthRange support - * - * Diego Picciani (d.picciani@novacomp.it) Nova Computer s.r.l. - * - written the fxCloseHardware() and the fxQuaryHardware() (mainly - * for the VoodooWGL emulator) - * - * Brian Paul (brianp@elastic.avid.com) Avid Technology - * - implemented read/write_color_span() so glRead/DrawPixels() works - * - now needs Glide 2.3 or later. Removed GLIDE_FULL_SCREEN and call to grSstOpen() - * - * V0.17 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - optimized the bitmap support (66% faster) - * - tested with the Mesa 2.3beta2 - * - * Diego Picciani (d.picciani@novacomp.it) Nova Computer s.r.l. - * - solved a problem with the drawbitmap() and the Voodoo Rush - * (GR_ORIGIN_LOWER_LEFT did not work with the Stingray) - * - * Brian Paul (brianp@elastic.avid.com) Avid Technology - * - linux stuff - * - general code clean-up - * - added attribList parameter to fxMesaCreateContext() - * - single buffering works now - * - VB colors are now GLubytes, removed ColorShift stuff - * - * Paul Metzger - * - linux stuff - * - * V0.16 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - written the quadfunc support (no performance improvement) - * - written the support for the new Mesa 2.3beta1 driver interface (Wow ! It is faaaster) - * - rewritten the glBitmap support for the Glide 2.3 (~35% slower !) - * - written the glBitmap support for the most common case (fonts) - * - * Jack Palevich - * - Glide 2.3 porting - * - * Diego Picciani (d.picciani@novacomp.it) Nova Computer s.r.l. - * - extended the fxMesaCreateContext() and fxMesaCreateBestContext() - * functions in order to support also the Voodoo Rush - * - tested with the Hercules Stingray 128/3D (The rendering in a window works !) - * - * V0.15 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - written the GL_LUMINANCE_ALPHA support - * - written the GL_ALPHA support - * - written the GL_LUMINANCE support - * - now SETUP correctly set color for mono color sequences - * - written the 9x1,10x1,...,1x9,1x10,... texture map ratio support - * - written the no square texture map support - * - the fog table is no more rebuilt inside setup_fx_units() each time - * - * Henri Fousse (arnaud@pobox.oleane.com) Thomson Training & Simulation - * - written (not yet finished: no texture mapping) support for glOrtho - * - some change to setup functions - * - the fog support is now fully compatible with the standard OpenGL - * - rewritten several parts of the driver in order to take - * advantage of meshes (40% faster !!!) - * - * V0.14 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - now glAlphaFunc() works - * - now glDepthMask() works - * - solved a mipmap problem when using more than one texture - * - moved ti, texid and wscale inside the fxMesaContext (now we can - * easy support more ctx and more boards) - * - the management of the fxMesaContext was completly broken ! - * - solved several problems about Alpha and texture Alpha - * - 4 (RGBA) texture channels supported - * - setting the default color to white - * - * Henri Fousse (arnaud@pobox.oleane.com) Thomson Training & Simulation - * - small change to fxMesaCreateContext() and fxMesaMakeCurrent() - * - written the fog support - * - setting the default clear color to black - * - written cleangraphics() for the onexit() function - * - written fxMesaCreateBestContext() - * - * V0.13 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - now glBlendFunc() works for all glBlendFunc without DST_ALPHA - * (because the alpha buffer is not yet implemented) - * - now fxMesaCreateContext() accept resolution and refresh rate - * - fixed a bug for texture mapping: the w (alias z) must be set - * also without depth buffer - * - fixed a bug for texture image with width!=256 - * - written texparam() - * - written all point, line and triangle functions for all possible supported - * contexts and the driver is slight faster with points, lines and small triangles - * - fixed a small bug in fx/fxmesa.h (glOrtho) - * - * V0.12 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - glDepthFunc supported - * - introduced a trick to discover the far plane distance - * (see fxMesaSetFar and fx/fxmesa.h) - * - now the wbuffer works with homogeneous coordinate (and it - * doesn't work with a glOrtho projection :) - * - solved several problems with homogeneous coordinate and texture mapping - * - fixed a bug in all line functions - * - fixed a clear framebuffer bug - * - solved a display list/teximg problem (but use - * glBindTexture: it is several times faster) - * - * V0.11 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - introduced texture mapping support (not yet finished !) - * - tested with Mesa2.2b6 - * - the driver is faster - * - written glFlush/glFinish - * - the driver print a lot of info about the Glide lib - * - * v0.1 - David Bucciarelli (tech.hmw@plus.it) Humanware s.r.l. - * - Initial revision - * - */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) -#include "fxdrv.h" - -static fxMesaContext fxMesaCurrentCtx=NULL; - -/* - * Status of 3Dfx hardware initialization - */ - -static int glbGlideInitialized=0; -static int glb3DfxPresent=0; -static int glbTotNumCtx=0; - -GrHwConfiguration glbHWConfig; -int glbCurrentBoard=0; - - -#if defined(__WIN32__) -static int cleangraphics(void) -{ - glbTotNumCtx=1; - fxMesaDestroyContext(fxMesaCurrentCtx); - - return 0; -} -#elif defined(__linux__) -static void cleangraphics(void) -{ - glbTotNumCtx=1; - fxMesaDestroyContext(fxMesaCurrentCtx); -} - -static void cleangraphics_handler(int s) -{ - fprintf(stderr,"fxmesa: Received a not handled signal %d\n",s); - - cleangraphics(); -/* abort(); */ - exit(1); -} -#endif - - -/* - * Select the Voodoo board to use when creating - * a new context. - */ -GLboolean GLAPIENTRY fxMesaSelectCurrentBoard(int n) -{ - fxQueryHardware(); - - if((n<0) || (n>=glbHWConfig.num_sst)) - return GL_FALSE; - - glbCurrentBoard=n; - - return GL_TRUE; -} - - -fxMesaContext GLAPIENTRY fxMesaGetCurrentContext(void) -{ - return fxMesaCurrentCtx; -} - - -void GLAPIENTRY fxMesaSetNearFar(GLfloat n, GLfloat f) -{ - if(fxMesaCurrentCtx) - fxDDSetNearFar(fxMesaCurrentCtx->glCtx,n,f); -} - - -/* - * The 3Dfx Global Palette extension for GLQuake. - * More a trick than a real extesion, use the shared global - * palette extension. - */ -extern void GLAPIENTRY gl3DfxSetPaletteEXT(GLuint *pal); /* silence warning */ -void GLAPIENTRY gl3DfxSetPaletteEXT(GLuint *pal) -{ - fxMesaContext fxMesa =fxMesaCurrentCtx; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - int i; - - fprintf(stderr,"fxmesa: gl3DfxSetPaletteEXT()\n"); - - for(i=0;i<256;i++) - fprintf(stderr,"%x\n",pal[i]); - } - - if(fxMesa) { - fxMesa->haveGlobalPaletteTexture=1; - - FX_grTexDownloadTable(GR_TMU0,GR_TEXTABLE_PALETTE,(GuTexPalette *)pal); - if (fxMesa->haveTwoTMUs) - FX_grTexDownloadTable(GR_TMU1,GR_TEXTABLE_PALETTE,(GuTexPalette *)pal); - } -} - - -static GrScreenResolution_t fxBestResolution(int width, int height, int aux) -{ - static int resolutions[][5]={ - { 512, 384, GR_RESOLUTION_512x384, 2, 2 }, - { 640, 400, GR_RESOLUTION_640x400, 2, 2 }, - { 640, 480, GR_RESOLUTION_640x480, 2, 2 }, - { 800, 600, GR_RESOLUTION_800x600, 4, 2 }, - { 960, 720, GR_RESOLUTION_960x720, 6, 4 } -#ifdef GR_RESOLUTION_1024x768 - ,{ 1024, 768, GR_RESOLUTION_1024x768, 8, 4 } -#endif -#ifdef GR_RESOLUTION_1280x1024 - ,{ 1024, 768, GR_RESOLUTION_1280x1024, 8, 8 } -#endif -#ifdef GR_RESOLUTION_1600x1200 - ,{ 1024, 768, GR_RESOLUTION_1600x1200, 16, 8 } -#endif - }; - int NUM_RESOLUTIONS = sizeof(resolutions) / (sizeof(int)*5); - int i,fbmem; - GrScreenResolution_t lastvalidres=resolutions[1][2]; - - fxQueryHardware(); - - if(glbHWConfig.SSTs[glbCurrentBoard].type==GR_SSTTYPE_VOODOO) { - fbmem=glbHWConfig.SSTs[glbCurrentBoard].sstBoard.VoodooConfig.fbRam; - - if(glbHWConfig.SSTs[glbCurrentBoard].sstBoard.VoodooConfig.sliDetect) - fbmem*=2; - } else if(glbHWConfig.SSTs[glbCurrentBoard].type==GR_SSTTYPE_SST96) - fbmem=glbHWConfig.SSTs[glbCurrentBoard].sstBoard.SST96Config.fbRam; - else - fbmem=2; - - /* A work around for BZFlag */ - - if((width==1) && (height==1)) { - width=640; - height=480; - } - - for(i=0;i<NUM_RESOLUTIONS;i++) - if(resolutions[i][4-aux]<=fbmem) { - if((width<=resolutions[i][0]) && (height<=resolutions[i][1])) - return resolutions[i][2]; - - lastvalidres=resolutions[i][2]; - } - - return lastvalidres; -} - - -fxMesaContext GLAPIENTRY fxMesaCreateBestContext(GLuint win,GLint width, GLint height, - const GLint attribList[]) -{ - GrScreenRefresh_t refresh; - int i; - int res,aux; - refresh=GR_REFRESH_75Hz; - - if(getenv("SST_SCREENREFRESH")) { - if(!strcmp(getenv("SST_SCREENREFRESH"),"60")) - refresh=GR_REFRESH_60Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"70")) - refresh=GR_REFRESH_70Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"72")) - refresh=GR_REFRESH_72Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"75")) - refresh=GR_REFRESH_75Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"80")) - refresh=GR_REFRESH_80Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"85")) - refresh=GR_REFRESH_85Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"90")) - refresh=GR_REFRESH_90Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"100")) - refresh=GR_REFRESH_100Hz; - if(!strcmp(getenv("SST_SCREENREFRESH"),"120")) - refresh=GR_REFRESH_120Hz; - } - - aux=0; - for(i=0;attribList[i]!=FXMESA_NONE;i++) - if((attribList[i]==FXMESA_ALPHA_SIZE) || - (attribList[i]==FXMESA_DEPTH_SIZE)) { - if(attribList[++i]>0) { - aux=1; - break; - } - } - - res=fxBestResolution(width,height,aux); - - return fxMesaCreateContext(win,res,refresh,attribList); -} - - -#if 0 -void fxsignals() -{ - signal(SIGINT,SIG_IGN); - signal(SIGHUP,SIG_IGN); - signal(SIGPIPE,SIG_IGN); - signal(SIGFPE,SIG_IGN); - signal(SIGBUS,SIG_IGN); - signal(SIGILL,SIG_IGN); - signal(SIGSEGV,SIG_IGN); - signal(SIGTERM,SIG_IGN); -} -#endif - -/* - * Create a new FX/Mesa context and return a handle to it. - */ -fxMesaContext GLAPIENTRY fxMesaCreateContext(GLuint win, - GrScreenResolution_t res, - GrScreenRefresh_t ref, - const GLint attribList[]) -{ - fxMesaContext fxMesa = NULL; - int i,type; - int aux; - GLboolean doubleBuffer=GL_FALSE; - GLboolean alphaBuffer=GL_FALSE; - GLboolean verbose=GL_FALSE; - GLint depthSize=0; - GLint stencilSize=0; - GLint accumSize=0; - GLcontext *shareCtx = NULL; - GLcontext *ctx = 0; - /*FX_GrContext_t glideContext = 0;*/ - char *errorstr; - GLboolean useBGR; - char *system = NULL; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaCreateContext() Start\n"); - } - - if(getenv("MESA_FX_INFO")) - verbose=GL_TRUE; - - aux=0; - i=0; - while(attribList[i]!=FXMESA_NONE) { - switch (attribList[i]) { - case FXMESA_DOUBLEBUFFER: - doubleBuffer=GL_TRUE; - break; - case FXMESA_ALPHA_SIZE: - i++; - alphaBuffer=attribList[i]>0; - if(alphaBuffer) - aux=1; - break; - case FXMESA_DEPTH_SIZE: - i++; - depthSize=attribList[i]; - if(depthSize) { - aux=1; - depthSize = 16; - } - break; - case FXMESA_STENCIL_SIZE: - i++; - stencilSize=attribList[i]; - break; - case FXMESA_ACCUM_SIZE: - i++; - accumSize=attribList[i]; - break; - /* XXX ugly hack here for sharing display lists */ -#define FXMESA_SHARE_CONTEXT 990099 /* keep in sync with xmesa1.c! */ - case FXMESA_SHARE_CONTEXT: - i++; - { - const void *vPtr = &attribList[i]; - GLcontext **ctx = (GLcontext **) vPtr; - shareCtx = *ctx; - } - break; - default: - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaCreateContext() End (defualt)\n"); - } - return NULL; - } - i++; - } - - /* A workaround for Linux GLQuake */ - if(depthSize && alphaBuffer) - alphaBuffer=0; - - if ((type=fxQueryHardware()) < 0) { - fprintf(stderr,"fx Driver: ERROR no Voodoo1/2 Graphics or Voodoo Rush !\n"); - return NULL; - } - - if(type==GR_SSTTYPE_VOODOO) - win=0; - - grSstSelect(glbCurrentBoard); - - fxMesa=(fxMesaContext)calloc(1,sizeof(struct tfxMesaContext)); - if(!fxMesa) { - errorstr = "malloc"; - goto errorhandler; - } - - if(glbHWConfig.SSTs[glbCurrentBoard].type==GR_SSTTYPE_VOODOO) - fxMesa->haveTwoTMUs=(glbHWConfig.SSTs[glbCurrentBoard].sstBoard.VoodooConfig.nTexelfx > 1); - else if(glbHWConfig.SSTs[glbCurrentBoard].type==GR_SSTTYPE_SST96) - fxMesa->haveTwoTMUs=(glbHWConfig.SSTs[glbCurrentBoard].sstBoard.SST96Config.nTexelfx > 1); - else - fxMesa->haveTwoTMUs=GL_FALSE; - - fxMesa->haveAlphaBuffer=alphaBuffer; - fxMesa->haveGlobalPaletteTexture=GL_FALSE; - fxMesa->verbose=verbose; - fxMesa->board=glbCurrentBoard; - - - fxMesa->glideContext = FX_grSstWinOpen((FxU32)win,res,ref, -#if FXMESA_USE_ARGB - GR_COLORFORMAT_ARGB, -#else - GR_COLORFORMAT_ABGR, -#endif - GR_ORIGIN_LOWER_LEFT, - 2,aux); - if (!fxMesa->glideContext){ - errorstr = "grSstWinOpen"; - goto errorhandler; - } - - /* - * Pixel tables are use during pixel read-back - * Either initialize them for RGB or BGR order. - */ -#if FXMESA_USE_ARGB - useBGR = GL_FALSE; /* Force RGB pixel order */ - system = "FXMESA_USE_ARGB"; -#else - if (glbHWConfig.SSTs[glbCurrentBoard].type == GR_SSTTYPE_VOODOO) { - /* jk991130 - Voodoo 3s don't use BGR. Query the # of TMUs - * as Voodoo3s have 2 TMUs on board, Banshee has only 1 - * bk000413 - another suggestion from Joseph Kain is using - * VendorID 0x121a for all 3dfx boards - * DeviceID VG 1/V2 2/VB 3/V3 5 - * For now we cehck for known BGR devices, and presume - * everything else to be a V3/RGB. - */ - GrVoodooConfig_t *voodoo; - voodoo = &glbHWConfig.SSTs[glbCurrentBoard].sstBoard.VoodooConfig; - - if (voodoo->nTexelfx == 1) { - /* Voodoo1 or Banshee */ - useBGR = GL_TRUE; - system = "Voodoo1"; - } - else if (voodoo->nTexelfx == 2 && - voodoo->fbiRev == 260 && - voodoo->tmuConfig[0].tmuRev == 4 && - (voodoo->tmuConfig[0].tmuRam == 2 || - voodoo->tmuConfig[0].tmuRam == 4)) { - /* Voodoo 2 */ - useBGR = GL_TRUE; - system = "Voodoo2"; - } - else if (voodoo->nTexelfx == 2 && - voodoo->fbiRev == 2 && - voodoo->tmuConfig[0].tmuRev == 1 && - voodoo->tmuConfig[0].tmuRam == 4) { - /* Quantum3D Obsidian 50/100 */ - useBGR = GL_TRUE; - system = "Quantum3D Obsidian"; - } - else - /* Brian - * (voodoo->nTexelfx == 2 && - * voodoo->fbiRev == 0 && - * voodoo->tmuConfig[0].tmuRev == 148441048 && - * voodoo->tmuConfig[0].tmuRam == 3) - * Bernd - * (voodoo->nTexelfx == 2 && - * voodoo->fbiRev == 69634 && - * voodoo->tmuConfig[0].tmuRev == 69634 && - * voodoo->tmuConfig[0].tmuRam == 2 ) - */ - { - /* Presumed Voodoo3 */ - useBGR = GL_FALSE; - system = "Voodoo3"; - } - if (getenv("MESA_FX_INFO")) { - printf("Voodoo: Texelfx: %d / FBI Rev.: %d / TMU Rev.: %d / TMU RAM: %d\n", - voodoo->nTexelfx, - voodoo->fbiRev, - voodoo->tmuConfig[0].tmuRev, - voodoo->tmuConfig[0].tmuRam ); - } - } - else { - useBGR = GL_FALSE; /* use RGB pixel order otherwise */ - system = "non-voodoo"; - } -#endif /*FXMESA_USE_ARGB*/ - - if (getenv("MESA_FX_INFO")) - printf("Voodoo pixel order: %s (%s)\n", useBGR ? "BGR" : "RGB", system); - - fxInitPixelTables(fxMesa, useBGR); - - fxMesa->width=FX_grSstScreenWidth(); - fxMesa->height=FX_grSstScreenHeight(); - - fxMesa->clipMinX = 0; - fxMesa->clipMaxX = fxMesa->width; - fxMesa->clipMinY = 0; - fxMesa->clipMaxY = fxMesa->height; - - fxMesa->screen_width = fxMesa->width; - fxMesa->screen_height = fxMesa->height; - fxMesa->x_offset = 0; - fxMesa->y_offset = 0; - fxMesa->y_delta = 0; - - fxMesa->needClip = 0; - - if(verbose) - fprintf(stderr,"Voodoo Glide screen size: %dx%d\n", - (int)FX_grSstScreenWidth(),(int)FX_grSstScreenHeight()); - - fxMesa->glVis=gl_create_visual(GL_TRUE, /* RGB mode */ - alphaBuffer, - doubleBuffer, - GL_FALSE, /* stereo */ - depthSize, /* depth_size */ - stencilSize, /* stencil_size */ - accumSize, /* accum_size */ - 0, /* index bits */ - 5,6,5,0); /* RGBA bits */ - if (!fxMesa->glVis) { - errorstr = "gl_create_visual"; - goto errorhandler; - } - - ctx = fxMesa->glCtx=gl_create_context(fxMesa->glVis, - shareCtx, /* share list context */ - (void *) fxMesa, GL_TRUE); - if (!ctx) { - errorstr = "gl_create_context"; - goto errorhandler; - } - - - if (!fxDDInitFxMesaContext( fxMesa )) { - errorstr = "fxDDInitFxMesaContext failed"; - goto errorhandler; - } - - - fxMesa->glBuffer=gl_create_framebuffer(fxMesa->glVis, - GL_FALSE, /* no software depth */ - fxMesa->glVis->StencilBits > 0, - fxMesa->glVis->AccumRedBits > 0, - fxMesa->glVis->AlphaBits > 0 ); - if (!fxMesa->glBuffer) { - errorstr = "gl_create_framebuffer"; - goto errorhandler; - } - - glbTotNumCtx++; - - /* install signal handlers */ -#if defined(__linux__) - /* Only install if environment var. is not set. */ - if (fxMesa->glCtx->CatchSignals && !getenv("MESA_FX_NO_SIGNALS")) { - signal(SIGINT,cleangraphics_handler); - signal(SIGHUP,cleangraphics_handler); - signal(SIGPIPE,cleangraphics_handler); - signal(SIGFPE,cleangraphics_handler); - signal(SIGBUS,cleangraphics_handler); - signal(SIGILL,cleangraphics_handler); - signal(SIGSEGV,cleangraphics_handler); - signal(SIGTERM,cleangraphics_handler); - } -#endif - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaCreateContext() End\n"); - } - - return fxMesa; - - errorhandler: - if (fxMesa) { - if (fxMesa->glideContext) - FX_grSstWinClose(fxMesa->glideContext); - fxMesa->glideContext = 0; - - if (fxMesa->state) - free(fxMesa->state); - if (fxMesa->fogTable) - free(fxMesa->fogTable); - if (fxMesa->glBuffer) - gl_destroy_framebuffer(fxMesa->glBuffer); - if (fxMesa->glVis) - gl_destroy_visual(fxMesa->glVis); - if (fxMesa->glCtx) - gl_destroy_context(fxMesa->glCtx); - free(fxMesa); - } - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaCreateContext() End (%s)\n",errorstr); - } - return NULL; -} - - -/* - * Function to set the new window size in the context (mainly for the Voodoo Rush) - */ -void GLAPIENTRY fxMesaUpdateScreenSize(fxMesaContext fxMesa) -{ - fxMesa->width=FX_grSstScreenWidth(); - fxMesa->height=FX_grSstScreenHeight(); -} - - -/* - * Destroy the given FX/Mesa context. - */ -void GLAPIENTRY fxMesaDestroyContext(fxMesaContext fxMesa) -{ - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaDestroyContext()\n"); - } - - if(fxMesa) { - gl_destroy_visual(fxMesa->glVis); - gl_destroy_context(fxMesa->glCtx); - gl_destroy_framebuffer(fxMesa->glBuffer); - - glbTotNumCtx--; - - fxCloseHardware(); - FX_grSstWinClose(fxMesa->glideContext); - - if(fxMesa->verbose) { - fprintf(stderr,"Misc Stats:\n"); - fprintf(stderr," # swap buffer: %u\n",fxMesa->stats.swapBuffer); - - if(!fxMesa->stats.swapBuffer) - fxMesa->stats.swapBuffer=1; - - fprintf(stderr,"Textures Stats:\n"); - fprintf(stderr," Free texture memory on TMU0: %d:\n",fxMesa->freeTexMem[FX_TMU0]); - if(fxMesa->haveTwoTMUs) - fprintf(stderr," Free texture memory on TMU1: %d:\n",fxMesa->freeTexMem[FX_TMU1]); - fprintf(stderr," # request to TMM to upload a texture objects: %u\n", - fxMesa->stats.reqTexUpload); - fprintf(stderr," # request to TMM to upload a texture objects per swapbuffer: %.2f\n", - fxMesa->stats.reqTexUpload/(float)fxMesa->stats.swapBuffer); - fprintf(stderr," # texture objects uploaded: %u\n", - fxMesa->stats.texUpload); - fprintf(stderr," # texture objects uploaded per swapbuffer: %.2f\n", - fxMesa->stats.texUpload/(float)fxMesa->stats.swapBuffer); - fprintf(stderr," # MBs uploaded to texture memory: %.2f\n", - fxMesa->stats.memTexUpload/(float)(1<<20)); - fprintf(stderr," # MBs uploaded to texture memory per swapbuffer: %.2f\n", - (fxMesa->stats.memTexUpload/(float)fxMesa->stats.swapBuffer)/(float)(1<<20)); - } - if (fxMesa->state) - free(fxMesa->state); - if (fxMesa->fogTable) - free(fxMesa->fogTable); - fxTMClose(fxMesa); - - free(fxMesa); - } - - if(fxMesa==fxMesaCurrentCtx) - fxMesaCurrentCtx=NULL; -} - - -/* - * Make the specified FX/Mesa context the current one. - */ -void GLAPIENTRY fxMesaMakeCurrent(fxMesaContext fxMesa) -{ - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaMakeCurrent(...) Start\n"); - } - - if(!fxMesa) { - gl_make_current(NULL,NULL); - fxMesaCurrentCtx=NULL; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaMakeCurrent(NULL) End\n"); - } - - return; - } - - /* if this context is already the current one, we can return early */ - if (fxMesaCurrentCtx == fxMesa - && fxMesaCurrentCtx->glCtx == gl_get_current_context()) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaMakeCurrent(fxMesaCurrentCtx==fxMesa) End\n"); - } - - return; - } - - if(fxMesaCurrentCtx) - grGlideGetState((GrState*)fxMesaCurrentCtx->state); - - fxMesaCurrentCtx=fxMesa; - - grSstSelect(fxMesa->board); - grGlideSetState((GrState*)fxMesa->state); - - gl_make_current(fxMesa->glCtx,fxMesa->glBuffer); - - fxSetupDDPointers(fxMesa->glCtx); - - /* The first time we call MakeCurrent we set the initial viewport size */ - if(fxMesa->glCtx->Viewport.Width==0) - gl_Viewport(fxMesa->glCtx,0,0,fxMesa->width,fxMesa->height); - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxMesaMakeCurrent(...) End\n"); - } -} - - -#if 0 -static void QueryCounters(void) -{ - static GLuint prevPassed = 0; - static GLuint prevFailed = 0; - GLuint failed, passed; - GrSstPerfStats_t st; - - FX_grSstPerfStats(&st); - failed = st.zFuncFail - st.aFuncFail - st.chromaFail; - passed = st.pixelsIn - failed; - printf("failed: %d passed: %d\n", failed - prevFailed, passed - prevPassed); - - prevPassed = passed; - prevFailed = failed; -} -#endif - - -/* - * Swap front/back buffers for current context if double buffered. - */ -void GLAPIENTRY fxMesaSwapBuffers(void) -{ - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: ------------------------------- fxMesaSwapBuffers() -------------------------------\n"); - } - - if(fxMesaCurrentCtx) { - FLUSH_VB( fxMesaCurrentCtx->glCtx, "swap buffers" ); - - if (fxMesaCurrentCtx->glVis->DBflag) { - - grBufferSwap(fxMesaCurrentCtx->swapInterval); - - /* - * Don't allow swap buffer commands to build up! - */ - while(FX_grGetInteger(FX_PENDING_BUFFERSWAPS)>fxMesaCurrentCtx->maxPendingSwapBuffers) - /* The driver is able to sleep when waiting for the completation - of multiple swapbuffer operations instead of wasting - CPU time (NOTE: you must uncomment the following line in the - in order to enable this option) */ - /* usleep(10000); */ - ; - - fxMesaCurrentCtx->stats.swapBuffer++; - } - } -} - - -/* - * Query 3Dfx hardware presence/kind - */ -int GLAPIENTRY fxQueryHardware(void) -{ - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxQueryHardware() Start\n"); - } - - if (!glbGlideInitialized) { - grGlideInit(); - if (FX_grSstQueryHardware(&glbHWConfig)) { - grSstSelect(glbCurrentBoard); - glb3DfxPresent = 1; - - if (getenv("MESA_FX_INFO")) { - char buf[80]; - - FX_grGlideGetVersion(buf); - fprintf(stderr, "Voodoo Using Glide V%s\n", buf); - fprintf(stderr, "Voodoo Number of boards: %d\n", glbHWConfig.num_sst); - - if (glbHWConfig.SSTs[glbCurrentBoard].type == GR_SSTTYPE_VOODOO) { - GrVoodooConfig_t *voodoo; - voodoo = &glbHWConfig.SSTs[glbCurrentBoard].sstBoard.VoodooConfig; - - fprintf(stderr, "Voodoo Framebuffer RAM: %d\n", - voodoo->sliDetect ? (voodoo->fbRam*2) : voodoo->fbRam); - fprintf(stderr, "Voodoo Number of TMUs: %d\n", voodoo->nTexelfx); - fprintf(stderr, "Voodoo fbRam: %d\n", voodoo->fbRam); - fprintf(stderr, "Voodoo fbiRev: %d\n", voodoo->fbiRev); - - fprintf(stderr,"Voodoo SLI detected: %d\n", voodoo->sliDetect); - } - else if (glbHWConfig.SSTs[glbCurrentBoard].type == GR_SSTTYPE_SST96) { - GrSst96Config_t *sst96; - sst96 = &glbHWConfig.SSTs[glbCurrentBoard].sstBoard.SST96Config; - fprintf(stderr, "Voodoo Framebuffer RAM: %d\n", sst96->fbRam); - fprintf(stderr, "Voodoo Number of TMUs: %d\n", sst96->nTexelfx); - } - - } - } - else { - glb3DfxPresent = 0; - } - - glbGlideInitialized = 1; - -#if defined(__WIN32__) - onexit((_onexit_t)cleangraphics); -#elif defined(__linux__) - /* Only register handler if environment variable is not defined. */ - if (!getenv("MESA_FX_NO_SIGNALS")) { - atexit(cleangraphics); - } -#endif - } - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxQueryHardware() End (voodooo)\n"); - } - - return glbHWConfig.SSTs[glbCurrentBoard].type; -} - - -/* - * Shutdown Glide library - */ -void GLAPIENTRY fxCloseHardware(void) -{ - if (glbGlideInitialized) { - if (getenv("MESA_FX_INFO")) { - GrSstPerfStats_t st; - - FX_grSstPerfStats(&st); - fprintf(stderr,"Pixels Stats:\n"); - fprintf(stderr," # pixels processed (minus buffer clears): %u\n",(unsigned)st.pixelsIn); - fprintf(stderr," # pixels not drawn due to chroma key test failure: %u\n",(unsigned)st.chromaFail); - fprintf(stderr," # pixels not drawn due to depth test failure: %u\n",(unsigned)st.zFuncFail); - fprintf(stderr," # pixels not drawn due to alpha test failure: %u\n",(unsigned)st.aFuncFail); - fprintf(stderr," # pixels drawn (including buffer clears and LFB writes): %u\n",(unsigned)st.pixelsOut); - } - - if (glbTotNumCtx == 0) { - grGlideShutdown(); - glbGlideInitialized = 0; - } - } -} - - -#else - - -/* - * Need this to provide at least one external definition. - */ -extern int gl_fx_dummy_function_api(void); -int gl_fx_dummy_function_api(void) -{ - return 0; -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxcliptmp.h b/xc/extras/Mesa/src/FX/fxcliptmp.h deleted file mode 100644 index 82beeda6a..000000000 --- a/xc/extras/Mesa/src/FX/fxcliptmp.h +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#define V1 VARS_XYZW -#define S1 DO_SETUP_XYZW -#define T1 COPY_XYZW_STRIDE -#define Z1 4 - -#if (IND & SETUP_RGBA) -#define V2 V1 VARS_RGBA -#define S2 S1 DO_SETUP_RGBA -#define T2 T1 COPY_RGBA_STRIDE -#define Z2 (Z1 + 4) -#else -#define V2 V1 -#define S2 S1 -#define T2 T1 -#define Z2 Z1 -#endif - -#if (IND & SETUP_TMU0) -#define V3 V2 VARS_TMU0 -#define S3 S2 DO_SETUP_TMU0(Z2) -#define T3 T2 COPY_TMU0_STRIDE(Z2) -#define Z3 (Z2 + 2) -#else -#define V3 V2 -#define S3 S2 -#define T3 T2 -#define Z3 Z2 -#endif - -#if (IND & SETUP_TMU1) -#define V4 V3 VARS_TMU1 -#define S4 S3 DO_SETUP_TMU1(Z3) -#define T4 T3 COPY_TMU1_STRIDE(Z3) -#define Z4 (Z3 + 2) -#else -#define V4 V3 -#define S4 S3 -#define T4 T3 -#define Z4 Z3 -#endif - -#if (Z4 & 2) -#define SIZE (Z4+2) -#define COPY_STRIDE T4 COPY_NIL(Z4) -#else -#define SIZE Z4 -#define COPY_STRIDE T4 -#endif - -#define VARS V4 -#define SETUP S4 - -#define DRAW_LINE(tmp0, tmp1, width) \ - do { \ - GrVertex verts[4]; \ - float dx, dy, ix, iy; \ - \ - dx = tmp0->x - tmp1->x; \ - dy = tmp0->y - tmp1->y; \ - \ - if (dx * dx > dy * dy) { \ - iy = width * .5; \ - ix = 0; \ - } else { \ - iy = 0; \ - ix = width * .5; \ - } \ - \ - verts[0] = *tmp0; \ - verts[1] = *tmp0; \ - verts[2] = *tmp1; \ - verts[3] = *tmp1; \ - \ - verts[0].x = tmp0->x - ix; \ - verts[0].y = tmp0->y - iy; \ - \ - verts[1].x = tmp0->x + ix; \ - verts[1].y = tmp0->y + iy; \ - \ - verts[2].x = tmp1->x + ix; \ - verts[2].y = tmp1->y + iy; \ - \ - verts[3].x = tmp1->x - ix; \ - verts[3].y = tmp1->y - iy; \ - \ - FX_grDrawPolygonVertexList(4, verts); \ - } while (0) - -static void TAG(fx_tri_view_clip)( struct vertex_buffer *VB, - GLuint v[], - GLubyte mask ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLfloat data[VB_MAX_CLIPPED_VERTS*12]; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GrVertex *verts[VB_MAX_CLIPPED_VERTS]; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLfloat *out = data; - GLfloat *mat = ctx->Viewport.WindowMap.m; - GLuint i, n; - GLubyte *clipmask = VB->ClipMask; - - GLuint tmu0_source = fxMesa->tmu_source[0]; - GLuint tmu1_source = fxMesa->tmu_source[1]; - GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; - GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; - - (void) fxMesa; - (void) tmu0_source; (void) tc0_vec; - (void) tmu1_source; (void) tc1_vec; - - for (i = 0 ; i < 3 ; i++) { - GLuint e = v[i]; - verts[i] = 0; - if (!clipmask[e]) verts[i] = (GrVertex *)gWin[e].f; - vlist[i] = out; - COPY_STRIDE; - out += SIZE; - } - - if ((n = fx_view_clip_triangle( ctx, vlist, verts, SIZE, mask )) >= 3) - { - GrVertex tmp[VB_MAX_CLIPPED_VERTS]; - GrVertex *v = tmp, *v2, *v3; - VARS; - - for (i = 0 ; i < n ; i++) - if (!verts[i]) { - GLfloat *data = vlist[i]; - SETUP; - verts[i] = v++; - } - - v = verts[0]; - v2 = verts[1]; - v3 = verts[2]; - - for (i = 2 ; i < n ; v2 = v3, v3=verts[++i]) - FX_grDrawTriangle(v, v2, v3); - } -} - - - - - -static void TAG(fx_tri_clip_stride)( struct vertex_buffer *VB, - GLuint v[], - GLuint mask ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLfloat data[VB_MAX_CLIPPED_VERTS*12]; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GrVertex *verts[VB_MAX_CLIPPED_VERTS]; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLfloat *out = data; - GLfloat *mat = ctx->Viewport.WindowMap.m; - GLuint i, n; - GLubyte *clipmask = VB->ClipMask; - - GLuint tmu0_source = fxMesa->tmu_source[0]; - GLuint tmu1_source = fxMesa->tmu_source[1]; - GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; - GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; - - (void) fxMesa; - (void) tmu0_source; (void) tc0_vec; - (void) tmu1_source; (void) tc1_vec; - - for (i = 0 ; i < 3 ; i++) { - GLuint e = v[i]; - verts[i] = 0; - if (!clipmask[e]) verts[i] = (GrVertex *)gWin[e].f; - vlist[i] = out; - COPY_STRIDE; - out += SIZE; - } - - if (VB->ClipPtr->size < 4) { - vlist[0][3] = vlist[1][3] = vlist[2][3] = 1.0; - if (VB->ClipPtr->size == 2) - vlist[0][2] = vlist[1][2] = vlist[2][2] = 0.0; - } - - if ((n = fx_clip_triangle( ctx, vlist, verts, SIZE, mask )) >= 3) - { - GrVertex tmp[VB_MAX_CLIPPED_VERTS]; - GrVertex *v = tmp, *v2, *v3; - VARS; - - for (i = 0 ; i < n ; i++) - if (!verts[i]) { - GLfloat *data = vlist[i]; - SETUP; - verts[i] = v++; - } - - v = verts[0]; - v2 = verts[1]; - v3 = verts[2]; - - for (i = 2 ; i < n ; v2 = v3, v3=verts[++i]) - FX_grDrawTriangle(v, v2, v3); - } -} - - - -static void TAG(fx_line_clip)( struct vertex_buffer *VB, - GLuint v1, GLuint v2, - GLubyte mask ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLfloat data[VB_MAX_CLIPPED_VERTS*12]; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GLfloat *out = data; - GLfloat *mat = ctx->Viewport.WindowMap.m; - GLfloat w = ctx->Line.Width*.5; - GLuint e, n; - - GLuint tmu0_source = fxMesa->tmu_source[0]; - GLuint tmu1_source = fxMesa->tmu_source[1]; - GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; - GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; - - VARS; - - (void) fxMesa; - (void) tmu0_source; (void) tc0_vec; - (void) tmu1_source; (void) tc1_vec; - - vlist[0] = out; - e = v1; - COPY_STRIDE; - out += SIZE; - - vlist[1] = out; - e = v2; - COPY_STRIDE; - out += SIZE; - - if (VB->ClipPtr->size < 4) { - vlist[0][3] = vlist[1][3] = 1.0; - if (VB->ClipPtr->size == 2) - vlist[0][2] = vlist[1][2] = 0.0; - } - - if ((n = fx_clip_line( ctx, vlist, SIZE, mask )) != 0) - { - GrVertex gWin[2]; - GrVertex *v; - GLfloat *data; - - v = gWin; - data = vlist[0]; - SETUP; - - v++; - data = vlist[1]; - SETUP; - - DRAW_LINE(gWin, v, w); - } -} - - - -#undef V1 -#undef S1 -#undef C1 -#undef Z1 -#undef T1 - -#undef V2 -#undef S2 -#undef C2 -#undef Z2 -#undef T2 - -#undef V3 -#undef S3 -#undef C3 -#undef Z3 -#undef T3 - -#undef V4 -#undef S4 -#undef C4 -#undef Z4 -#undef T4 - -#undef VARS -#undef SETUP -#undef COPY -#undef COPY_STRIDE -#undef SIZE -#undef IND -#undef TAG diff --git a/xc/extras/Mesa/src/FX/fxcvatmp.h b/xc/extras/Mesa/src/FX/fxcvatmp.h deleted file mode 100644 index 801dc0edd..000000000 --- a/xc/extras/Mesa/src/FX/fxcvatmp.h +++ /dev/null @@ -1,262 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -static void TAG(cva_render_points)( struct vertex_buffer *cvaVB, - struct vertex_buffer *VB, - const struct gl_prim_state *state, - GLuint start, - GLuint count ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; - const GLuint *elt = VB->EltPtr->data; - GLuint i; - - VARS; - INIT; - (void) fxMesa; - - if (cvaVB->ClipOrMask) { - const GLubyte *clip = cvaVB->ClipMask; - for (i = start ; i < count ; i++ INCR) { - GLuint e = elt[i]; - if (!clip[e]) { - GLfloat *v = gWin[e].f; (void) v; - if (!DIRECT) { MERGE_VB; } - MERGE_RAST; - DRAW_POINT; - } - } - } else { - for (i = start ; i < count ; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[e].f; (void) v; - if (!DIRECT) { MERGE_VB; } - MERGE_RAST; - DRAW_POINT; - } - } -} - -static void TAG(cva_render_lines)( struct vertex_buffer *cvaVB, - struct vertex_buffer *VB, - const struct gl_prim_state *state, - GLuint start, - GLuint count ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; - const GLuint *elt = VB->EltPtr->data; - GLuint i; - - VARS; - INIT; - (void) fxMesa; - - if (cvaVB->ClipOrMask) { - const GLubyte *clip = cvaVB->ClipMask; - GLuint prev = 0; - GLfloat *prev_v = 0; - - (void) ctx; - - for (i = start ; i < count ; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[e].f; - - MERGE_VB; - - if (!clip[e]) - MERGE_RAST; - - if (state->draw) { - if (clip[e] | clip[prev]) - CLIP_LINE; - else - DRAW_LINE; - } - - prev = e; - prev_v = v; - state = state->next; - } - if (state->finish_loop) { - GLuint e = elt[start]; - GLfloat *v = gWin[e].f; (void) v; - - if (!DIRECT) { MERGE_VB; } - MERGE_RAST; - - if (clip[e] | clip[prev]) - CLIP_LINE; - else - DRAW_LINE; - } - } else { - GLuint prev = 0; - GLfloat *prev_v = 0; - - for (i = start ; i < count ; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[e].f; - - if (!DIRECT) { MERGE_VB; } - MERGE_RAST; - if (state->draw) DRAW_LINE; - prev = e; - prev_v = v; - state = state->next; - } - if (state->finish_loop) { - GLuint e = elt[start]; - GLfloat *v = gWin[e].f; (void) v; - - if (!DIRECT) { MERGE_VB; } - MERGE_RAST; - DRAW_LINE; - } - } -} - - -static void TAG(cva_render_tris)( struct vertex_buffer *cvaVB, - struct vertex_buffer *VB, - const struct gl_prim_state *state, - GLuint start, - GLuint count ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; - const GLuint *elt = VB->EltPtr->data; - GLuint i; - VARS; - INIT; - (void) fxMesa; - - if (cvaVB->ClipOrMask) { - GLuint vlist[VB_MAX_CLIPPED_VERTS]; - GLuint l[3]; - const GLubyte *clip = cvaVB->ClipMask; - - (void) vlist; - - for (i = start ; i < count ; i++ INCR) { - GLuint e = l[2] = elt[i]; - GLfloat *v = gWin[e].f; (void) v; - - MERGE_VB; /* needed for clip-interp */ - - if (!clip[e]) { - MERGE_RAST; - } - - if (state->draw) - CLIP_OR_DRAW_TRI; - - - l[0] = l[state->v0]; - l[1] = l[state->v1]; - state = state->next; - } - } else if (DIRECT) { - GrVertex *vl[3]; - for (i = start ; i < count ; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[elt[i]].f; - - vl[2] = (GrVertex *)v; - - (void) v; - (void) e; - - MERGE_RAST; - - if (state->draw) - DRAW_TRI2; - - vl[0] = vl[state->v0]; - vl[1] = vl[state->v1]; - state = state->next; - } - } else { - GLuint l[3]; - for (i = start ; i < count ; i++ INCR) { - GLuint e = l[2] = elt[i]; - GLfloat *v = gWin[e].f; (void) v; - - MERGE_VB; /* needed for ctx->trianglefunc? */ - MERGE_RAST; - - if (state->draw) - DRAW_TRI; - - l[0] = l[state->v0]; - l[1] = l[state->v1]; - state = state->next; - } - } -} - - -static void TAG(init_cva)( void ) -{ - merge_and_render_tab[DIRECT][IDX][PRIM_POINTS] = TAG(cva_render_points); - merge_and_render_tab[DIRECT][IDX][PRIM_LINES] = TAG(cva_render_lines); - merge_and_render_tab[DIRECT][IDX][PRIM_TRIS] = TAG(cva_render_tris); - merge_and_render_tab[DIRECT][IDX][PRIM_CULLED] = fxCvaRenderNoop; -} - - -#undef IDX -#undef MERGE_RAST -#undef MERGE_VB -#undef VARS -#undef INIT -#undef INCR -#undef TAG - diff --git a/xc/extras/Mesa/src/FX/fxdd.c b/xc/extras/Mesa/src/FX/fxdd.c deleted file mode 100644 index a21ed31df..000000000 --- a/xc/extras/Mesa/src/FX/fxdd.c +++ /dev/null @@ -1,1491 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxdd.c - 3Dfx VooDoo Mesa device driver functions */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - -#include <dlfcn.h> -#include "image.h" -#include "types.h" -#include "fxdrv.h" -#include "enums.h" -#include "extensions.h" -#include "pb.h" - -/* These lookup table are used to extract RGB values in [0,255] from - * 16-bit pixel values. - */ -GLubyte FX_PixelToR[0x10000]; -GLubyte FX_PixelToG[0x10000]; -GLubyte FX_PixelToB[0x10000]; - - -/* - * Initialize the FX_PixelTo{RGB} arrays. - * Input: bgrOrder - if TRUE, pixels are in BGR order, else RGB order. - */ -void fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder) -{ - GLuint pixel; - - fxMesa->bgrOrder=bgrOrder; - for (pixel = 0; pixel <= 0xffff; pixel++) { - GLuint r, g, b; - if (bgrOrder) { - r = (pixel & 0x001F) << 3; - g = (pixel & 0x07E0) >> 3; - b = (pixel & 0xF800) >> 8; - } - else { - r = (pixel & 0xF800) >> 8; - g = (pixel & 0x07E0) >> 3; - b = (pixel & 0x001F) << 3; - } - r = r * 255 / 0xF8; /* fill in low-order bits */ - g = g * 255 / 0xFC; - b = b * 255 / 0xF8; - FX_PixelToR[pixel] = r; - FX_PixelToG[pixel] = g; - FX_PixelToB[pixel] = b; - } -} - - -/**********************************************************************/ -/***** Miscellaneous functions *****/ -/**********************************************************************/ - - -/* Return buffer size information */ -static void fxDDBufferSize(GLcontext *ctx, GLuint *width, GLuint *height) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDBufferSize(...) Start\n"); - } - - *width = fxMesa->width; - *height = fxMesa->height; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDBufferSize(...) End\n"); - } -} - - -/* Set current drawing color */ -static void fxDDSetColor(GLcontext *ctx, GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha ) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GLubyte col[4]; - ASSIGN_4V( col, red, green, blue, alpha ); - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDSetColor(%d,%d,%d,%d)\n",red,green,blue,alpha); - } - fxMesa->color = FXCOLOR4(col); -} - - -/* Implements glClearColor() */ -static void fxDDClearColor(GLcontext *ctx, GLubyte red, GLubyte green, - GLubyte blue, GLubyte alpha ) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GLubyte col[4]; - ASSIGN_4V( col, red, green, blue, 255 ); - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDClearColor(%d,%d,%d,%d)\n",red,green,blue,alpha); - } - fxMesa->clearC = FXCOLOR4( col ); - fxMesa->clearA = alpha; -} - - -/* Clear the color and/or depth buffers */ -static GLbitfield fxDDClear(GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint x, GLint y, GLint width, GLint height ) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); - const FxU32 clearD = (FxU32) (ctx->Depth.Clear * fxMesa->depthClear); - const FxU32 clearS = (FxU32) (ctx->Stencil.Clear); - GLbitfield softwareMask = mask & (DD_ACCUM_BIT); - - /* we can't clear accum buffers */ - mask &= ~(DD_ACCUM_BIT); - - if ((mask & DD_STENCIL_BIT) && !fxMesa->haveHwStencil) { - /* software stencil buffer */ - mask &= ~(DD_STENCIL_BIT); - softwareMask |= DD_STENCIL_BIT; - } - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x, (int) y, - (int) width, (int) height); - } - - if (colorMask != 0xffffffff) { - /* do masked color buffer clears in software */ - softwareMask |= (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)); - mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); - } - - - /* disable stencil ops if enabled (it screws up clearing) */ - if (fxMesa->haveHwStencil) { - if (ctx->Stencil.Enabled) - FX_grDisable(GR_STENCIL_MODE_EXT); - - if (mask & DD_STENCIL_BIT) { - FX_grStencilMask(0xff); - /* set stencil ref value = desired clear value */ - FX_grStencilFunc(GR_CMP_ALWAYS, ctx->Stencil.Clear, 0xff); - } - else { - FX_grStencilMask(0x00); - } - } - - /* - * This could probably be done fancier but doing each possible case - * explicitly is less error prone. - */ - switch (mask & ~DD_STENCIL_BIT) { - case DD_BACK_LEFT_BIT | DD_DEPTH_BIT: - /* back buffer & depth */ - FX_grDepthMask(FXTRUE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - if (!ctx->Depth.Mask) { - FX_grDepthMask(FXFALSE); - } - break; - case DD_FRONT_LEFT_BIT | DD_DEPTH_BIT: - /* XXX it appears that the depth buffer isn't cleared when - * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set. - * This is a work-around/ - */ - /* clear depth */ - FX_grDepthMask(FXTRUE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - FX_grColorMask(FXFALSE,FXFALSE); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - /* clear front */ - FX_grColorMask(FXTRUE, ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - break; - case DD_BACK_LEFT_BIT: - /* back buffer only */ - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - if (ctx->Depth.Mask) { - FX_grDepthMask(FXTRUE); - } - break; - case DD_FRONT_LEFT_BIT: - /* front buffer only */ - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - if (ctx->Depth.Mask) { - FX_grDepthMask(FXTRUE); - } - break; - case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT: - /* front and back */ - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - if (ctx->Depth.Mask) { - FX_grDepthMask(FXTRUE); - } - break; - case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT: - /* clear front */ - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - /* clear back and depth */ - FX_grDepthMask(FXTRUE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - if (!ctx->Depth.Mask) { - FX_grDepthMask(FXFALSE); - } - break; - case DD_DEPTH_BIT: - /* just the depth buffer */ - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - FX_grColorMask(FXFALSE,FXFALSE); - FX_grDepthMask(FXTRUE); - if (mask & DD_STENCIL_BIT) - FX_grBufferClearExt(fxMesa->clearC, fxMesa->clearA, clearD, clearS); - else - FX_grBufferClear(fxMesa->clearC, fxMesa->clearA, clearD); - FX_grColorMask(FXTRUE, ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - if (ctx->Color.DrawDestMask & FRONT_LEFT_BIT) - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - break; - default: - /* error */ - ; - } - - if (fxMesa->haveHwStencil && ctx->Stencil.Enabled) { - /* restore stencil state to as it was before the clear */ - FX_grEnable(GR_STENCIL_MODE_EXT); - FX_grStencilMask(ctx->Stencil.WriteMask); - FX_grStencilFunc(ctx->Stencil.Function - GL_NEVER, - ctx->Stencil.Ref, ctx->Stencil.ValueMask); - } - - return softwareMask; -} - - -/* Set the buffer used for drawing */ -/* XXX support for separate read/draw buffers hasn't been tested */ -static GLboolean fxDDSetDrawBuffer(GLcontext *ctx, GLenum mode) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDSetBuffer(%x)\n", (int) mode); - } - - if (mode == GL_FRONT_LEFT) { - fxMesa->currentFB = GR_BUFFER_FRONTBUFFER; - FX_grRenderBuffer(fxMesa->currentFB); - return GL_TRUE; - } - else if (mode == GL_BACK_LEFT) { - fxMesa->currentFB = GR_BUFFER_BACKBUFFER; - FX_grRenderBuffer(fxMesa->currentFB); - return GL_TRUE; - } - else if (mode == GL_NONE) { - FX_grColorMask(FXFALSE,FXFALSE); - return GL_TRUE; - } - else { - return GL_FALSE; - } -} - - -/* Set the buffer used for reading */ -/* XXX support for separate read/draw buffers hasn't been tested */ -static void fxDDSetReadBuffer(GLcontext *ctx, GLframebuffer *buffer, - GLenum mode ) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - (void) buffer; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDSetBuffer(%x)\n", (int) mode); - } - - if (mode == GL_FRONT_LEFT) { - fxMesa->currentFB = GR_BUFFER_FRONTBUFFER; - FX_grRenderBuffer(fxMesa->currentFB); - } - else if (mode == GL_BACK_LEFT) { - fxMesa->currentFB = GR_BUFFER_BACKBUFFER; - FX_grRenderBuffer(fxMesa->currentFB); - } -} - - -/* - * These functions just set new-state flags. The exact state - * values will be evaluated later. - */ -static void -fxDDStencilFunc(GLcontext *ctx, GLenum func, GLint ref, GLuint mask) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - (void) func; (void) ref; (void) mask; - fxMesa->new_state |= FX_NEW_STENCIL; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -static void -fxDDStencilMask(GLcontext *ctx, GLuint mask) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - (void) mask; - fxMesa->new_state |= FX_NEW_STENCIL; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -static void -fxDDStencilOp(GLcontext *ctx, GLenum sfail, GLenum zfail, GLenum zpass) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - (void) sfail; (void) zfail; (void) zpass; - fxMesa->new_state |= FX_NEW_STENCIL; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -static void -fxDDDepthFunc(GLcontext *ctx, GLenum func) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - (void) func; - fxMesa->new_state |= FX_NEW_DEPTH; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -static void -fxDDDepthMask(GLcontext *ctx, GLboolean mask) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - (void) mask; - fxMesa->new_state |= FX_NEW_DEPTH; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - - - - -#ifdef XF86DRI -/* test if window coord (px,py) is visible */ -static GLboolean inClipRects(fxMesaContext fxMesa, int px, int py) -{ - int i; - for (i=0; i<fxMesa->numClipRects; i++) { - if ((px>=fxMesa->pClipRects[i].x1) && - (px<fxMesa->pClipRects[i].x2) && - (py>=fxMesa->pClipRects[i].y1) && - (py<fxMesa->pClipRects[i].y2)) return GL_TRUE; - } - return GL_FALSE; -} -#endif - - - -static GLboolean -bitmap_R5G6B5(GLcontext *ctx, GLint px, GLint py, - GLsizei width, GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GrLfbInfo_t info; - FxU16 color; - const struct gl_pixelstore_attrib *finalUnpack; - struct gl_pixelstore_attrib scissoredUnpack; - - /* check if there's any raster operations enabled which we can't handle */ - if (ctx->RasterMask & (ALPHATEST_BIT | - BLEND_BIT | - DEPTH_BIT | - FOG_BIT | - LOGIC_OP_BIT | - SCISSOR_BIT | - STENCIL_BIT | - MASKING_BIT | - ALPHABUF_BIT | - MULTI_DRAW_BIT)) - return GL_FALSE; - - if (ctx->Scissor.Enabled) { - /* This is a bit tricky, but by carefully adjusting the px, py, - * width, height, skipPixels and skipRows values we can do - * scissoring without special code in the rendering loop. - */ - - /* we'll construct a new pixelstore struct */ - finalUnpack = &scissoredUnpack; - scissoredUnpack = *unpack; - if (scissoredUnpack.RowLength == 0) - scissoredUnpack.RowLength = width; - - /* clip left */ - if (px < ctx->Scissor.X) { - scissoredUnpack.SkipPixels += (ctx->Scissor.X - px); - width -= (ctx->Scissor.X - px); - px = ctx->Scissor.X; - } - /* clip right */ - if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) { - width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width)); - } - /* clip bottom */ - if (py < ctx->Scissor.Y) { - scissoredUnpack.SkipRows += (ctx->Scissor.Y - py); - height -= (ctx->Scissor.Y - py); - py = ctx->Scissor.Y; - } - /* clip top */ - if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) { - height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height)); - } - - if (width <= 0 || height <= 0) - return GL_TRUE; /* totally scissored away */ - } - else { - finalUnpack = unpack; - } - - /* compute pixel value */ - { - GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f); - GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f); - GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f); - /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f);*/ - if (fxMesa->bgrOrder) - color = (FxU16) - ( ((FxU16)0xf8 & b) << (11-3)) | - ( ((FxU16)0xfc & g) << (5-3+1)) | - ( ((FxU16)0xf8 & r) >> 3); - else - color = (FxU16) - ( ((FxU16)0xf8 & r) << (11-3)) | - ( ((FxU16)0xfc & g) << (5-3+1)) | - ( ((FxU16)0xf8 & b) >> 3); - } - - info.size = sizeof(info); - if (!FX_grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - GR_LFBWRITEMODE_565, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: error locking the linear frame buffer\n"); -#endif - return GL_TRUE; - } - -#ifdef XF86DRI -#define INSIDE(c, x, y) inClipRects((c), (x), (y)) -#else -#define INSIDE(c, x, y) (1) -#endif - - { - const GLint winX = fxMesa->x_offset; - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - /* The dest stride depends on the hardware and whether we're drawing - * to the front or back buffer. This compile-time test seems to do - * the job for now. - */ -#ifdef XF86DRI - const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - ? (fxMesa->screen_width) : (info.strideInBytes / 2); -#else - const GLint dstStride = info.strideInBytes / 2; /* stride in GLushorts */ -#endif - GLint row; - /* compute dest address of bottom-left pixel in bitmap */ - GLushort *dst = (GLushort *) info.lfbPtr - + (winY - py) * dstStride - + (winX + px); - - for (row = 0; row < height; row++) { - const GLubyte *src = (const GLubyte *) _mesa_image_address( finalUnpack, - bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 ); - if (finalUnpack->LsbFirst) { - /* least significan bit first */ - GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7); - GLint col; - for (col=0; col<width; col++) { - if (*src & mask) { - if (INSIDE(fxMesa, winX + px + col, winY - py - row)) - dst[col] = color; - } - if (mask == 128U) { - src++; - mask = 1U; - } - else { - mask = mask << 1; - } - } - if (mask != 1) - src++; - } - else { - /* most significan bit first */ - GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7); - GLint col; - for (col=0; col<width; col++) { - if (*src & mask) { - if (INSIDE(fxMesa, winX + px + col, winY - py - row)) - dst[col] = color; - } - if (mask == 1U) { - src++; - mask = 128U; - } - else { - mask = mask >> 1; - } - } - if (mask != 128) - src++; - } - dst -= dstStride; - } - } - -#undef INSIDE - - FX_grLfbUnlock(GR_LFB_WRITE_ONLY,fxMesa->currentFB); - return GL_TRUE; -} - - -static GLboolean -bitmap_R8G8B8A8(GLcontext *ctx, GLint px, GLint py, - GLsizei width, GLsizei height, - const struct gl_pixelstore_attrib *unpack, - const GLubyte *bitmap) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GrLfbInfo_t info; - GrLfbWriteMode_t mode; - /*FxU16 color;*/ - GLuint color; - const struct gl_pixelstore_attrib *finalUnpack; - struct gl_pixelstore_attrib scissoredUnpack; - - /* check if there's any raster operations enabled which we can't handle */ - if (ctx->RasterMask & (ALPHATEST_BIT | - BLEND_BIT | - DEPTH_BIT | - FOG_BIT | - LOGIC_OP_BIT | - SCISSOR_BIT | - STENCIL_BIT | - MASKING_BIT | - ALPHABUF_BIT | - MULTI_DRAW_BIT)) - return GL_FALSE; - - if (ctx->Scissor.Enabled) { - /* This is a bit tricky, but by carefully adjusting the px, py, - * width, height, skipPixels and skipRows values we can do - * scissoring without special code in the rendering loop. - */ - - /* we'll construct a new pixelstore struct */ - finalUnpack = &scissoredUnpack; - scissoredUnpack = *unpack; - if (scissoredUnpack.RowLength == 0) - scissoredUnpack.RowLength = width; - - /* clip left */ - if (px < ctx->Scissor.X) { - scissoredUnpack.SkipPixels += (ctx->Scissor.X - px); - width -= (ctx->Scissor.X - px); - px = ctx->Scissor.X; - } - /* clip right */ - if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) { - width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width)); - } - /* clip bottom */ - if (py < ctx->Scissor.Y) { - scissoredUnpack.SkipRows += (ctx->Scissor.Y - py); - height -= (ctx->Scissor.Y - py); - py = ctx->Scissor.Y; - } - /* clip top */ - if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) { - height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height)); - } - - if (width <= 0 || height <= 0) - return GL_TRUE; /* totally scissored away */ - } - else { - finalUnpack = unpack; - } - - /* compute pixel value */ - { - GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f); - GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f); - GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f); - GLint a = (GLint) (ctx->Current.RasterColor[3] * 255.0f); - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - color = PACK_BGRA32(r, g, b, a); - else - color = PACK_RGBA32(r, g, b, a); - } - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_8888; - else - mode = GR_LFBWRITEMODE_888; - - info.size = sizeof(info); - if (!FX_grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: error locking the linear frame buffer\n"); -#endif - return GL_TRUE; - } - -#ifdef XF86DRI -#define INSIDE(c, x, y) inClipRects((c), (x), (y)) -#else -#define INSIDE(c, x, y) (1) -#endif - - { - const GLint winX = fxMesa->x_offset; - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - GLint dstStride; - GLuint *dst; - GLint row; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - dstStride = fxMesa->screen_width; - dst = (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX + px); - } - else { - dstStride = info.strideInBytes / 4; - dst = (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX + px); - } - - /* compute dest address of bottom-left pixel in bitmap */ - for (row = 0; row < height; row++) { - const GLubyte *src = (const GLubyte *) _mesa_image_address( finalUnpack, - bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 ); - if (finalUnpack->LsbFirst) { - /* least significan bit first */ - GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7); - GLint col; - for (col=0; col<width; col++) { - if (*src & mask) { - if (INSIDE(fxMesa, winX + px + col, winY - py - row)) - dst[col] = color; - } - if (mask == 128U) { - src++; - mask = 1U; - } - else { - mask = mask << 1; - } - } - if (mask != 1) - src++; - } - else { - /* most significan bit first */ - GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7); - GLint col; - for (col=0; col<width; col++) { - if (*src & mask) { - if (INSIDE(fxMesa, winX + px + col, winY - py - row)) - dst[col] = color; - } - if (mask == 1U) { - src++; - mask = 128U; - } - else { - mask = mask >> 1; - } - } - if (mask != 128) - src++; - } - dst -= dstStride; - } - } - -#undef INSIDE - - FX_grLfbUnlock(GR_LFB_WRITE_ONLY,fxMesa->currentFB); - return GL_TRUE; -} - - -static GLboolean -readpixels_R5G6B5( GLcontext *ctx, GLint x, GLint y, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *packing, - GLvoid *dstImage ) -{ - if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { - return GL_FALSE; /* can't do this */ - } - else { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GrLfbInfo_t info; - GLboolean result = GL_FALSE; - - BEGIN_BOARD_LOCK(); - info.size=sizeof(info); - if (grLfbLock(GR_LFB_READ_ONLY, - fxMesa->currentFB, - GR_LFBWRITEMODE_ANY, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winX = fxMesa->x_offset; - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; -#ifdef XF86DRI - const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - ? (fxMesa->screen_width) : (info.strideInBytes / 2); -#else - const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */ -#endif - const GLushort *src = (const GLushort *) info.lfbPtr - + (winY - y) * srcStride + (winX + x); - GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage, - width, height, format, type, 0, 0, 0); - GLint dstStride = _mesa_image_row_stride(packing, width, format, type); - - if (format == GL_RGB && type == GL_UNSIGNED_BYTE) { - /* convert 5R6G5B into 8R8G8B */ - GLint row, col; - const GLint halfWidth = width >> 1; - const GLint extraPixel = (width & 1); - for (row = 0; row < height; row++) { - GLubyte *d = dst; - for (col = 0; col < halfWidth; col++) { - const GLuint pixel = ((const GLuint *) src)[col]; - const GLint pixel0 = pixel & 0xffff; - const GLint pixel1 = pixel >> 16; - *d++ = FX_PixelToR[pixel0]; - *d++ = FX_PixelToG[pixel0]; - *d++ = FX_PixelToB[pixel0]; - *d++ = FX_PixelToR[pixel1]; - *d++ = FX_PixelToG[pixel1]; - *d++ = FX_PixelToB[pixel1]; - } - if (extraPixel) { - GLushort pixel = src[width-1]; - *d++ = FX_PixelToR[pixel]; - *d++ = FX_PixelToG[pixel]; - *d++ = FX_PixelToB[pixel]; - } - dst += dstStride; - src -= srcStride; - } - result = GL_TRUE; - } - else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { - /* convert 5R6G5B into 8R8G8B8A */ - GLint row, col; - const GLint halfWidth = width >> 1; - const GLint extraPixel = (width & 1); - for (row = 0; row < height; row++) { - GLubyte *d = dst; - for (col = 0; col < halfWidth; col++) { - const GLuint pixel = ((const GLuint *) src)[col]; - const GLint pixel0 = pixel & 0xffff; - const GLint pixel1 = pixel >> 16; - *d++ = FX_PixelToR[pixel0]; - *d++ = FX_PixelToG[pixel0]; - *d++ = FX_PixelToB[pixel0]; - *d++ = 255; - *d++ = FX_PixelToR[pixel1]; - *d++ = FX_PixelToG[pixel1]; - *d++ = FX_PixelToB[pixel1]; - *d++ = 255; - } - if (extraPixel) { - const GLushort pixel = src[width-1]; - *d++ = FX_PixelToR[pixel]; - *d++ = FX_PixelToG[pixel]; - *d++ = FX_PixelToB[pixel]; - *d++ = 255; - } - dst += dstStride; - src -= srcStride; - } - result = GL_TRUE; - } - else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - /* directly memcpy 5R6G5B pixels into client's buffer */ - const GLint widthInBytes = width * 2; - GLint row; - for (row = 0; row < height; row++) { - MEMCPY(dst, src, widthInBytes); - dst += dstStride; - src -= srcStride; - } - result = GL_TRUE; - } - else { - result = GL_FALSE; - } - - grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); - return result; - } -} - - - -static void fxDDFinish(GLcontext *ctx) -{ - FX_grFlush(); -} - - -static GLint fxDDGetParameteri(const GLcontext *ctx, GLint param) -{ - switch(param) { - case DD_HAVE_HARDWARE_FOG: - return 1; - default: - fprintf(stderr,"fx Driver: internal error in fxDDGetParameteri(): %x\n", (int) param); - fxCloseHardware(); - exit(-1); - return 0; - } -} - - -void fxDDSetNearFar(GLcontext *ctx, GLfloat n, GLfloat f) -{ - FX_CONTEXT(ctx)->new_state |= FX_NEW_FOG; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -/* KW: Put the word Mesa in the render string because quakeworld - * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE). - * Why? - */ -static const GLubyte *fxDDGetString(GLcontext *ctx, GLenum name) -{ -#if defined(GLX_DIRECT_RENDERING) - /* Building for DRI driver */ - switch (name) { - case GL_RENDERER: - { - static char buffer[100]; - char hardware[100]; - strcpy(hardware, grGetString(GR_HARDWARE)); - if (strcmp(hardware, "Voodoo3 (tm)") == 0) - strcpy(hardware, "Voodoo3"); - else if (strcmp(hardware, "Voodoo Banshee (tm)") == 0) - strcpy(hardware, "VoodooBanshee"); - else { - /* unexpected result: replace spaces with hyphens */ - int i; - for (i = 0; hardware[i]; i++) { - if (hardware[i] == ' ' || hardware[i] == '\t') - hardware[i] = '-'; - } - } - /* now make the GL_RENDERER string */ - sprintf(buffer, "Mesa DRI %s 20000616", hardware); - return buffer; - } - case GL_VENDOR: - return "Precision Insight, Inc."; - default: - return NULL; - } - -#else - - /* Building for Voodoo1/2 stand-alone Mesa */ - switch (name) { - case GL_RENDERER: - { - static char buf[80]; - - if (glbHWConfig.SSTs[glbCurrentBoard].type==GR_SSTTYPE_VOODOO) { - GrVoodooConfig_t *vc = - &glbHWConfig.SSTs[glbCurrentBoard].sstBoard.VoodooConfig; - - sprintf(buf, - "Mesa Glide v0.30 Voodoo_Graphics %d " - "CARD/%d FB/%d TM/%d TMU/%s", - glbCurrentBoard, - (vc->sliDetect ? (vc->fbRam*2) : vc->fbRam), - (vc->tmuConfig[GR_TMU0].tmuRam + - ((vc->nTexelfx>1) ? vc->tmuConfig[GR_TMU1].tmuRam : 0)), - vc->nTexelfx, - (vc->sliDetect ? "SLI" : "NOSLI")); - } - else if (glbHWConfig.SSTs[glbCurrentBoard].type==GR_SSTTYPE_SST96) { - GrSst96Config_t *sc = - &glbHWConfig.SSTs[glbCurrentBoard].sstBoard.SST96Config; - - sprintf(buf, - "Glide v0.30 Voodoo_Rush %d " - "CARD/%d FB/%d TM/%d TMU/NOSLI", - glbCurrentBoard, - sc->fbRam, - sc->tmuConfig.tmuRam, - sc->nTexelfx); - } - else { - strcpy(buf, "Glide v0.30 UNKNOWN"); - } - return (GLubyte *) buf; - } - default: - return NULL; - } -#endif -} - - -int fxDDInitFxMesaContext( fxMesaContext fxMesa ) -{ - /* Get Glide3vn function pointers */ - { - void *handle; - handle = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL); - if (!handle) - return 0; - grStencilFuncPtr = dlsym(handle, "grStencilFunc"); - grStencilMaskPtr = dlsym(handle, "grStencilMask"); - grStencilOpPtr = dlsym(handle, "grStencilOp"); - grBufferClearExtPtr = dlsym(handle, "grBufferClearExt"); - /* call dlclose()? */ - } - - - FX_setupGrVertexLayout(); - - if (getenv("FX_EMULATE_SINGLE_TMU")) - fxMesa->haveTwoTMUs = GL_FALSE; - - fxMesa->emulateTwoTMUs = fxMesa->haveTwoTMUs; - - if (!getenv("FX_DONT_FAKE_MULTITEX")) - fxMesa->emulateTwoTMUs = GL_TRUE; - - if(getenv("FX_GLIDE_SWAPINTERVAL")) - fxMesa->swapInterval=atoi(getenv("FX_GLIDE_SWAPINTERVAL")); - else - fxMesa->swapInterval=1; - - if(getenv("MESA_FX_SWAP_PENDING")) - fxMesa->maxPendingSwapBuffers=atoi(getenv("MESA_FX_SWAP_PENDING")); - else - fxMesa->maxPendingSwapBuffers=2; - - if(getenv("MESA_FX_INFO")) - fxMesa->verbose=GL_TRUE; - else - fxMesa->verbose=GL_FALSE; - - fxMesa->depthClear = FX_grGetInteger(FX_ZDEPTH_MAX); - - fxMesa->color=0xffffffff; - fxMesa->clearC=0; - fxMesa->clearA=0; - - fxMesa->stats.swapBuffer=0; - fxMesa->stats.reqTexUpload=0; - fxMesa->stats.texUpload=0; - fxMesa->stats.memTexUpload=0; - - fxMesa->tmuSrc=FX_TMU_NONE; - fxTMInit(fxMesa); - - /* FX units setup */ - - fxMesa->unitsState.alphaTestEnabled=GL_FALSE; - fxMesa->unitsState.alphaTestFunc=GR_CMP_ALWAYS; - fxMesa->unitsState.alphaTestRefValue=0; - - fxMesa->unitsState.blendEnabled=GL_FALSE; - fxMesa->unitsState.blendSrcFuncRGB=GR_BLEND_ONE; - fxMesa->unitsState.blendDstFuncRGB=GR_BLEND_ZERO; - fxMesa->unitsState.blendSrcFuncAlpha=GR_BLEND_ONE; - fxMesa->unitsState.blendDstFuncAlpha=GR_BLEND_ZERO; - - /* - fxMesa->unitsState.depthTestEnabled =GL_FALSE; - fxMesa->unitsState.depthMask =GL_TRUE; - fxMesa->unitsState.depthTestFunc =GR_CMP_LESS; - */ - - FX_grColorMask(FXTRUE, fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE); - if (fxMesa->glVis->DBflag) { - fxMesa->currentFB = GR_BUFFER_BACKBUFFER; - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - } - else { - fxMesa->currentFB = GR_BUFFER_FRONTBUFFER; - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - } - - fxMesa->state = NULL; - fxMesa->fogTable = NULL; - - fxMesa->state = malloc(FX_grGetInteger(FX_GLIDE_STATE_SIZE)); - fxMesa->fogTable = malloc(FX_grGetInteger(FX_FOG_TABLE_ENTRIES)*sizeof(GrFog_t)); - - if (!fxMesa->state || !fxMesa->fogTable) { - if (fxMesa->state) free(fxMesa->state); - if (fxMesa->fogTable) free(fxMesa->fogTable); - return 0; - } - - if (fxMesa->glVis->DepthBits > 0) - FX_grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER); - -#if (!FXMESA_USE_ARGB) - FX_grLfbWriteColorFormat(GR_COLORFORMAT_ABGR); /* Not every Glide has this */ -#endif - - fxMesa->textureAlign=FX_grGetInteger(FX_TEXTURE_ALIGN); - fxMesa->glCtx->Const.MaxTextureLevels=9; - fxMesa->glCtx->Const.MaxTextureSize=256; - fxMesa->glCtx->Const.MaxTextureUnits=fxMesa->emulateTwoTMUs ? 2 : 1; - fxMesa->glCtx->NewState|=NEW_DRVSTATE1; - fxMesa->new_state = NEW_ALL; - - fxDDSetupInit(); - fxDDCvaInit(); - fxDDClipInit(); - fxDDTrifuncInit(); - fxDDFastPathInit(); - - fxSetupDDPointers(fxMesa->glCtx); - fxDDRenderInit(fxMesa->glCtx); - fxDDInitExtensions(fxMesa->glCtx); - - fxDDSetNearFar(fxMesa->glCtx,1.0,100.0); - - FX_grGlideGetState((GrState*)fxMesa->state); - - /* XXX Fix me: callback not registered when main VB is created. - */ - if (fxMesa->glCtx->VB) - fxDDRegisterVB( fxMesa->glCtx->VB ); - - /* XXX Fix me too: need to have the 'struct dd' prepared prior to - * creating the context... The below is broken if you try to insert - * new stages. - */ - if (fxMesa->glCtx->NrPipelineStages) - fxMesa->glCtx->NrPipelineStages = fxDDRegisterPipelineStages( - fxMesa->glCtx->PipelineStage, - fxMesa->glCtx->PipelineStage, - fxMesa->glCtx->NrPipelineStages); - - /* this little bit ensures that all Glide state gets initialized */ - fxMesa->new_state = NEW_ALL; - fxMesa->glCtx->Driver.RenderStart = fxSetupFXUnits; - - /* Run the config file */ - gl_context_initialize( fxMesa->glCtx ); - - return 1; -} - - -#if 0 -/* Example extension function */ -static void fxFooBarEXT(GLint i) -{ - printf("You called glFooBarEXT(%d)\n", i); -} -#endif - - -void fxDDInitExtensions( GLcontext *ctx ) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - - gl_extensions_disable(ctx, "GL_EXT_blend_logic_op"); - gl_extensions_disable(ctx, "GL_EXT_blend_minmax"); - gl_extensions_disable(ctx, "GL_EXT_blend_subtract"); - gl_extensions_disable(ctx, "GL_EXT_blend_color"); - - gl_extensions_add(ctx, DEFAULT_ON, "3DFX_set_global_palette", 0); - - if (!fxMesa->haveTwoTMUs) - gl_extensions_disable(ctx, "GL_EXT_texture_env_add"); - - if (!fxMesa->emulateTwoTMUs) - gl_extensions_disable(ctx, "GL_ARB_multitexture"); - - - /* Example of hooking in an extension function. - * For DRI-based drivers, also see __driRegisterExtensions in the - * tdfx_xmesa.c file. - */ -#if 0 - { - void **dispatchTable = (void **) ctx->Exec; - const int _gloffset_FooBarEXT = 555; /* just an example number! */ - const int tabSize = _glapi_get_dispatch_table_size(); - assert(_gloffset_FooBarEXT < tabSize); - dispatchTable[_gloffset_FooBarEXT] = (void *) fxFooBarEXT; - /* XXX You would also need to hook into the display list dispatch - * table. Really, the implementation of extensions might as well - * be in the core of Mesa since core Mesa and the device driver - * is one big shared lib. - */ - } -#endif -} - - -/************************************************************************/ -/************************************************************************/ -/************************************************************************/ - -/* Check if the hardware supports the current context - * - * Performs similar work to fxDDChooseRenderState() - should be merged. - */ -static GLboolean fxIsInHardware(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - - if (!ctx->Hint.AllowDrawMem) - return GL_TRUE; /* you'll take it and like it */ - - if(((ctx->Color.BlendEnabled) && (ctx->Color.BlendEquation!=GL_FUNC_ADD_EXT)) || - ((ctx->Color.ColorLogicOpEnabled) && (ctx->Color.LogicOp!=GL_COPY)) || - (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) || - (!((ctx->Color.ColorMask[RCOMP]==ctx->Color.ColorMask[GCOMP]) && - (ctx->Color.ColorMask[GCOMP]==ctx->Color.ColorMask[BCOMP]) && - (ctx->Color.ColorMask[ACOMP]==ctx->Color.ColorMask[ACOMP]))) - ) - { - return GL_FALSE; - } - /* Unsupported texture/multitexture cases */ - - if(fxMesa->emulateTwoTMUs) { - if((ctx->Enabled & (TEXTURE0_3D | TEXTURE1_3D)) || - /* Not very well written ... */ - ((ctx->Enabled & (TEXTURE0_1D | TEXTURE1_1D)) && - ((ctx->Enabled & (TEXTURE0_2D | TEXTURE1_2D))!=(TEXTURE0_2D | TEXTURE1_2D))) - ) { - return GL_FALSE; - } - - if (ctx->Texture.ReallyEnabled & TEXTURE0_2D) { - if (ctx->Texture.Unit[0].EnvMode == GL_BLEND && - (ctx->Texture.ReallyEnabled & TEXTURE1_2D || - ctx->Texture.Unit[0].EnvColor[0] != 0 || - ctx->Texture.Unit[0].EnvColor[1] != 0 || - ctx->Texture.Unit[0].EnvColor[2] != 0 || - ctx->Texture.Unit[0].EnvColor[3] != 1)) { - return GL_FALSE; - } - if (ctx->Texture.Unit[0].Current->Image[0]->Border > 0) - return GL_FALSE; - } - - if (ctx->Texture.ReallyEnabled & TEXTURE1_2D) { - if (ctx->Texture.Unit[1].EnvMode == GL_BLEND) - return GL_FALSE; - if (ctx->Texture.Unit[0].Current->Image[0]->Border > 0) - return GL_FALSE; - } - - if (MESA_VERBOSE & (VERBOSE_DRIVER|VERBOSE_TEXTURE)) - fprintf(stderr, "fxMesa: fxIsInHardware, envmode is %s/%s\n", - gl_lookup_enum_by_nr(ctx->Texture.Unit[0].EnvMode), - gl_lookup_enum_by_nr(ctx->Texture.Unit[1].EnvMode)); - - /* KW: This was wrong (I think) and I changed it... which doesn't mean - * it is now correct... - */ - if((ctx->Enabled & (TEXTURE0_1D | TEXTURE0_2D | TEXTURE0_3D)) && - (ctx->Enabled & (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D))) - { - /* Can't use multipass to blend a multitextured triangle - fall - * back to software. - */ - if (!fxMesa->haveTwoTMUs && ctx->Color.BlendEnabled) { - return GL_FALSE; - } - - if ((ctx->Texture.Unit[0].EnvMode!=ctx->Texture.Unit[1].EnvMode) && - (ctx->Texture.Unit[0].EnvMode!=GL_MODULATE) && - (ctx->Texture.Unit[0].EnvMode!=GL_REPLACE)) /* q2, seems ok... */ - { - if (MESA_VERBOSE&VERBOSE_DRIVER) - fprintf(stderr, "fxMesa: unsupported multitex env mode\n"); - return GL_FALSE; - } - } - } else { - if((ctx->Enabled & (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D)) || - /* Not very well written ... */ - ((ctx->Enabled & TEXTURE0_1D) && - (!(ctx->Enabled & TEXTURE0_2D))) - ) { - return GL_FALSE; - } - - - if((ctx->Texture.ReallyEnabled & TEXTURE0_2D) && - (ctx->Texture.Unit[0].EnvMode==GL_BLEND)) { - return GL_FALSE; - } - } - - if (ctx->Stencil.Enabled && !fxMesa->haveHwStencil) - return GL_FALSE; - - return GL_TRUE; -} - - - -#define INTERESTED (~(NEW_MODELVIEW|NEW_PROJECTION|NEW_PROJECTION|NEW_TEXTURE_MATRIX|NEW_USER_CLIP|NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE)) - -static void fxDDUpdateDDPointers(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint new_state = ctx->NewState; - - if (MESA_VERBOSE&(VERBOSE_DRIVER|VERBOSE_STATE)) - fprintf(stderr,"fxmesa: fxDDUpdateDDPointers(...)\n"); - - if (new_state & (NEW_RASTER_OPS|NEW_TEXTURING)) - fxMesa->is_in_hardware = fxIsInHardware(ctx); - - if (fxMesa->is_in_hardware) { - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - if(new_state & INTERESTED) { - fxDDChooseRenderState( ctx ); - fxMesa->RenderVBTables=fxDDChooseRenderVBTables(ctx); - fxMesa->RenderVBClippedTab=fxMesa->RenderVBTables[0]; - fxMesa->RenderVBCulledTab=fxMesa->RenderVBTables[1]; - fxMesa->RenderVBRawTab=fxMesa->RenderVBTables[2]; - - ctx->Driver.RasterSetup=fxDDChooseSetupFunction(ctx); - } - - ctx->Driver.PointsFunc=fxMesa->PointsFunc; - ctx->Driver.LineFunc=fxMesa->LineFunc; - ctx->Driver.TriangleFunc=fxMesa->TriangleFunc; - ctx->Driver.QuadFunc=fxMesa->QuadFunc; - } else { - fxMesa->render_index = FX_FALLBACK; - } -} - -static void fxDDReducedPrimitiveChange(GLcontext *ctx, GLenum prim) -{ - if (ctx->Polygon.CullFlag) { - if (ctx->PB->primitive != GL_POLYGON) { /* Lines or Points */ - FX_grCullMode(GR_CULL_DISABLE); - FX_CONTEXT(ctx)->cullMode=GR_CULL_DISABLE; - } - } -} - - -void fxSetupDDPointers(GLcontext *ctx) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxSetupDDPointers()\n"); - } - ctx->Driver.UpdateState = fxDDUpdateDDPointers; - ctx->Driver.ClearIndex = NULL; - ctx->Driver.ClearColor = fxDDClearColor; - ctx->Driver.Clear = fxDDClear; - ctx->Driver.Index = NULL; - ctx->Driver.Color = fxDDSetColor; - ctx->Driver.SetDrawBuffer = fxDDSetDrawBuffer; - ctx->Driver.SetReadBuffer = fxDDSetReadBuffer; - ctx->Driver.GetBufferSize = fxDDBufferSize; - ctx->Driver.Finish = fxDDFinish; - ctx->Driver.Flush = NULL; - ctx->Driver.GetString = fxDDGetString; - ctx->Driver.NearFar = fxDDSetNearFar; - ctx->Driver.GetParameteri = fxDDGetParameteri; - - ctx->Driver.WriteDepthSpan=fxDDWriteDepthSpan; - ctx->Driver.WriteDepthPixels=fxDDWriteDepthPixels; - ctx->Driver.ReadDepthSpan=fxDDReadDepthSpan; - ctx->Driver.ReadDepthPixels=fxDDReadDepthPixels; - - if (ctx->Visual->RedBits == 8 && - ctx->Visual->GreenBits == 8 && - ctx->Visual->BlueBits == 8 && - ctx->Visual->AlphaBits == 8) { - ctx->Driver.Bitmap = bitmap_R8G8B8A8; - ctx->Driver.DrawPixels = NULL; - ctx->Driver.ReadPixels = NULL; - } - else { - ctx->Driver.Bitmap = bitmap_R5G6B5; - ctx->Driver.DrawPixels = NULL; - ctx->Driver.ReadPixels = readpixels_R5G6B5; - } - - ctx->Driver.RenderStart=NULL; - ctx->Driver.RenderFinish=NULL; - - ctx->Driver.TexImage2D = fxDDTexImage2D; - ctx->Driver.TexSubImage2D = fxDDTexSubImage2D; - ctx->Driver.GetTexImage = fxDDGetTexImage; - ctx->Driver.TexEnv=fxDDTexEnv; - ctx->Driver.TexParameter=fxDDTexParam; - ctx->Driver.BindTexture=fxDDTexBind; - ctx->Driver.DeleteTexture=fxDDTexDel; - ctx->Driver.UpdateTexturePalette=fxDDTexPalette; - - ctx->Driver.RectFunc=NULL; - - if (fxMesa->haveHwStencil) { - ctx->Driver.StencilFunc = fxDDStencilFunc; - ctx->Driver.StencilMask = fxDDStencilMask; - ctx->Driver.StencilOp = fxDDStencilOp; - } - - ctx->Driver.AlphaFunc=fxDDAlphaFunc; - ctx->Driver.BlendFunc=fxDDBlendFunc; - ctx->Driver.DepthFunc=fxDDDepthFunc; - ctx->Driver.DepthMask=fxDDDepthMask; - ctx->Driver.ColorMask=fxDDColorMask; - ctx->Driver.Fogfv=fxDDFogfv; - ctx->Driver.Scissor=fxDDScissor; - ctx->Driver.FrontFace=fxDDFrontFace; - ctx->Driver.CullFace=fxDDCullFace; - ctx->Driver.ShadeModel=fxDDShadeModel; - ctx->Driver.Enable=fxDDEnable; - ctx->Driver.ReducedPrimitiveChange=fxDDReducedPrimitiveChange; - - ctx->Driver.RegisterVB=fxDDRegisterVB; - ctx->Driver.UnregisterVB=fxDDUnregisterVB; - - ctx->Driver.RegisterPipelineStages = fxDDRegisterPipelineStages; - - ctx->Driver.OptimizeImmediatePipeline = 0; /* nothing done yet */ - ctx->Driver.OptimizePrecalcPipeline = 0; - -/* if (getenv("MESA_USE_FAST") || getenv("FX_USE_FAST")) */ -/* ctx->Driver.OptimizePrecalcPipeline = fxDDOptimizePrecalcPipeline; */ - - if (!getenv("FX_NO_FAST")) - ctx->Driver.BuildPrecalcPipeline = fxDDBuildPrecalcPipeline; - - ctx->Driver.TriangleCaps = DD_TRI_CULL|DD_TRI_OFFSET|DD_TRI_LIGHT_TWOSIDE; - - fxSetupDDSpanPointers(ctx); - - FX_CONTEXT(ctx)->render_index = 1; /* force an update */ - fxDDUpdateDDPointers(ctx); -} - - - -#else - - -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_dd(void) -{ - return 0; -} - -#endif /* FX */ - diff --git a/xc/extras/Mesa/src/FX/fxddspan.c b/xc/extras/Mesa/src/FX/fxddspan.c deleted file mode 100644 index 1a273785a..000000000 --- a/xc/extras/Mesa/src/FX/fxddspan.c +++ /dev/null @@ -1,1825 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */ - - -#include "fxdrv.h" - - - -/* - * Examine the cliprects to generate an array of flags to indicate - * which pixels in a span are visible. Note: (x,y) is a screen - * coordinate. - */ -static void -generate_vismask(const fxMesaContext fxMesa, GLint x, GLint y, GLint n, - GLubyte vismask[]) -{ - GLboolean initialized = GL_FALSE; - GLint i, j; - - /* turn on flags for all visible pixels */ - for (i = 0; i < fxMesa->numClipRects; i++) { - const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; - - if (y >= rect->y1 && y < rect->y2) { - if (x >= rect->x1 && x + n <= rect->x2) { - /* common case, whole span inside cliprect */ - MEMSET(vismask, 1, n); - return; - } - if (x < rect->x2 && x + n >= rect->x1) { - /* some of the span is inside the rect */ - GLint start, end; - if (!initialized) { - MEMSET(vismask, 0, n); - initialized = GL_TRUE; - } - if (x < rect->x1) - start = rect->x1 - x; - else - start = 0; - if (x + n > rect->x2) - end = rect->x2 - x; - else - end = n; - assert(start >= 0); - assert(end <= n); - for (j = start; j < end; j++) - vismask[j] = 1; - } - } - } -} - - -/* - * Examine cliprects and determine if the given screen pixel is visible. - */ -static GLboolean -visible_pixel(const fxMesaContext fxMesa, int scrX, int scrY) -{ - int i; - for (i = 0; i < fxMesa->numClipRects; i++) { - const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; - if (scrX >= rect->x1 && - scrX < rect->x2 && - scrY >= rect->y1 && - scrY < rect->y2) - return GL_TRUE; - } - return GL_FALSE; -} - - - -typedef enum { FBS_READ, FBS_WRITE } FBS_DIRECTION; -/* - * Read or write a single span from the frame buffer. - * Input Parameters: - * fxMesa: The context - * target_buffer: Which buffer to read from. - * xpos, ypos: Starting Coordinates. - * xlength: Length of the span. - * data_size: Size of data elements: 1, 2, or 4. - * buffer: Pointer to the buffer to read - * to or write from. This needs - * to be turned into a pointer. - * direction: Read or Write. - */ -static void -rw_fb_span(fxMesaContext fxMesa, - GrBuffer_t target_buffer, - FxU32 xpos, - FxU32 ypos, - FxU32 xlength, - FxU32 data_size, - void *buffer, - FBS_DIRECTION direction) -{ - GrLfbInfo_t info; - BEGIN_BOARD_LOCK(); - info.size=sizeof(info); - - if (grLfbLock(direction == FBS_READ ? GR_LFB_READ_ONLY : GR_LFB_WRITE_ONLY, - target_buffer, - GR_LFBWRITEMODE_ANY, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winX = fxMesa->x_offset; - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; -#ifdef XF86DRI - /* stride in data elements */ - const GLint srcStride = - (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - ? (fxMesa->screen_width) - : (info.strideInBytes / data_size); -#else - /* stride in data elements */ - const GLint srcStride = info.strideInBytes / data_size; -#endif - GLushort *data16 = (GLushort *) info.lfbPtr - + (winY - ypos) * srcStride - + (winX + xpos); - GLubyte *target16 = (GLubyte *) buffer; - GLubyte *data8 = (GLubyte *) data16; - GLubyte *target8 = (GLubyte *) buffer; - GLuint *data32 = (GLuint *) data16; - GLuint *target32 = (GLuint *) buffer; - GLuint i, j; - - for (i = j = 0; i < xlength; i += 1, j += 1) { - switch (data_size) { - case 1: - switch (direction) { - case FBS_READ: - *target8++ = *data8++; - break; - case FBS_WRITE: - *data8++ = *target8++; - break; - } - break; - case 2: - switch (direction) { - case FBS_READ: - *target16++ = *data16++; - break; - case FBS_WRITE: - *data16++ = *target16++; - break; - } - break; - case 4: - switch (direction) { - case FBS_READ: - *target32++ = *data32++; - break; - case FBS_WRITE: - *data32++ = *target32++; - break; - } - break; - } - } - grLfbUnlock(direction == FBS_READ ? GR_LFB_READ_ONLY : GR_LFB_WRITE_ONLY, - target_buffer); - } - END_BOARD_LOCK(); -} - -static FxBool -fb_point_is_clipped(fxMesaContext fxMesa, - FxU32 dst_x, FxU32 dst_y) -{ - int i; - for (i=0; i<fxMesa->numClipRects; i++) { - if ((dst_x>=fxMesa->pClipRects[i].x1) && - (dst_x<fxMesa->pClipRects[i].x2) && - (dst_y>=fxMesa->pClipRects[i].y1) && - (dst_y<fxMesa->pClipRects[i].y2)) { - return GL_FALSE; - } - } - return GL_TRUE; -} - -static FxBool writeRegionClipped(fxMesaContext fxMesa, GrBuffer_t dst_buffer, - FxU32 dst_x, FxU32 dst_y, GrLfbSrcFmt_t src_format, - FxU32 src_width, FxU32 src_height, FxI32 src_stride, - void *src_data) -{ - int i, x, w, srcElt; - void *data; - - if (src_width==1 && src_height==1) { /* Easy case writing a point */ - for (i=0; i<fxMesa->numClipRects; i++) { - if ((dst_x>=fxMesa->pClipRects[i].x1) && - (dst_x<fxMesa->pClipRects[i].x2) && - (dst_y>=fxMesa->pClipRects[i].y1) && - (dst_y<fxMesa->pClipRects[i].y2)) { - FX_grLfbWriteRegion(dst_buffer, dst_x, dst_y, src_format, - 1, 1, src_stride, src_data); - return GL_TRUE; - } - } - } else if (src_height==1) { /* Writing a span */ - if (src_format==GR_LFB_SRC_FMT_8888) srcElt=4; - else if (src_format==GR_LFB_SRC_FMT_ZA16) srcElt=2; - else { - fprintf(stderr, "Unknown src_format passed to writeRegionClipped\n"); - return GL_FALSE; - } - for (i=0; i<fxMesa->numClipRects; i++) { - if (dst_y>=fxMesa->pClipRects[i].y1 && dst_y<fxMesa->pClipRects[i].y2) { - if (dst_x<fxMesa->pClipRects[i].x1) { - x=fxMesa->pClipRects[i].x1; - data=((char*)src_data)+srcElt*(x - dst_x); - w=src_width-(x-dst_x); - } else { - x=dst_x; - data=src_data; - w=src_width; - } - if (x+w>fxMesa->pClipRects[i].x2) { - w=fxMesa->pClipRects[i].x2-x; - } - FX_grLfbWriteRegion(dst_buffer, x, dst_y, src_format, w, 1, - src_stride, data); - } - } - } else { /* Punt on the case of arbitrary rectangles */ - return GL_FALSE; - } - return GL_TRUE; -} - - - -/* KW: Rearranged the args in the call to grLfbWriteRegion(). - */ -#define LFB_WRITE_SPAN_MESA(dst_buffer, \ - dst_x, \ - dst_y, \ - src_width, \ - src_stride, \ - src_data) \ - writeRegionClipped(fxMesa, dst_buffer, \ - dst_x, \ - dst_y, \ - GR_LFB_SRC_FMT_8888, \ - src_width, \ - 1, \ - src_stride, \ - src_data) \ - - - - -/* - * 16bpp span/pixel functions - */ - -static void -write_R5G6B5_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgba[][4], const GLubyte mask[]) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDWriteRGBASpan(...)\n"); - } - - x+=fxMesa->x_offset; - if (mask) { - int span=0; - - for (i=0;i<n;i++) { - if (mask[i]) { - ++span; - } else { - if (span > 0) { - LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+i-span, bottom-y, - /* GR_LFB_SRC_FMT_8888,*/ span, /*1,*/ 0, (void *) rgba[i-span] ); - span = 0; - } - } - } - - if (span > 0) - LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+n-span, bottom-y, - /* GR_LFB_SRC_FMT_8888, */ span, /*1,*/ 0, (void *) rgba[n-span] ); - } else - LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x, bottom-y,/* GR_LFB_SRC_FMT_8888,*/ - n,/* 1,*/ 0, (void *) rgba ); -} - - -static void -write_R5G6B5_rgb_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], const GLubyte mask[]) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; - GLubyte rgba[MAX_WIDTH][4]; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDWriteRGBSpan()\n"); - } - - x+=fxMesa->x_offset; - if (mask) { - int span=0; - - for (i=0;i<n;i++) { - if (mask[i]) { - rgba[span][RCOMP] = rgb[i][0]; - rgba[span][GCOMP] = rgb[i][1]; - rgba[span][BCOMP] = rgb[i][2]; - rgba[span][ACOMP] = 255; - ++span; - } else { - if (span > 0) { - LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+i-span, bottom-y, - /*GR_LFB_SRC_FMT_8888,*/ span,/* 1,*/ 0, (void *) rgba ); - span = 0; - } - } - } - - if (span > 0) - LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x+n-span, bottom-y, - /*GR_LFB_SRC_FMT_8888,*/ span,/* 1,*/ 0, (void *) rgba ); - } else { - for (i=0;i<n;i++) { - rgba[i][RCOMP]=rgb[i][0]; - rgba[i][GCOMP]=rgb[i][1]; - rgba[i][BCOMP]=rgb[i][2]; - rgba[i][ACOMP]=255; - } - - LFB_WRITE_SPAN_MESA( fxMesa->currentFB, x, bottom-y,/* GR_LFB_SRC_FMT_8888,*/ - n,/* 1,*/ 0, (void *) rgba ); - } -} - - -static void -write_R5G6B5_mono_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte mask[]) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; - GLuint data[MAX_WIDTH]; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDWriteMonoRGBASpan(...)\n"); - } - - x+=fxMesa->x_offset; - if (mask) { - int span=0; - - for (i=0;i<n;i++) { - if (mask[i]) { - data[span] = (GLuint) fxMesa->color; - ++span; - } else { - if (span > 0) { - writeRegionClipped(fxMesa, fxMesa->currentFB, x+i-span, bottom-y, - GR_LFB_SRC_FMT_8888, span, 1, 0, - (void *) data ); - span = 0; - } - } - } - - if (span > 0) - writeRegionClipped(fxMesa, fxMesa->currentFB, x+n-span, bottom-y, - GR_LFB_SRC_FMT_8888, span, 1, 0, - (void *) data ); - } else { - for (i=0;i<n;i++) { - data[i]=(GLuint) fxMesa->color; - } - - writeRegionClipped(fxMesa, fxMesa->currentFB, x, bottom-y, GR_LFB_SRC_FMT_8888, - n, 1, 0, (void *) data ); - } -} - - -/* - * Read a span of 16-bit RGB pixels. Note, we don't worry about cliprects - * since OpenGL says obscured pixels have undefined values. - */ -static void -read_R5G6B5_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - GLubyte rgba[][4]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbInfo_t info; - BEGIN_BOARD_LOCK(); - info.size=sizeof(info); - if (grLfbLock(GR_LFB_READ_ONLY, - fxMesa->currentFB, - GR_LFBWRITEMODE_ANY, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winX = fxMesa->x_offset; - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; -#ifdef XF86DRI - const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - ? (fxMesa->screen_width) : (info.strideInBytes / 2); -#else - const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */ -#endif - const GLushort *data16 = (const GLushort *) info.lfbPtr - + (winY - y) * srcStride - + (winX + x); - const GLuint *data32 = (const GLuint *) data16; - GLuint i, j; - GLuint extraPixel = (n & 1); - n -= extraPixel; - for (i = j = 0; i < n; i += 2, j++) { - GLuint pixel = data32[j]; - GLuint pixel0 = pixel & 0xffff; - GLuint pixel1 = pixel >> 16; - rgba[i][RCOMP] = FX_PixelToR[pixel0]; - rgba[i][GCOMP] = FX_PixelToG[pixel0]; - rgba[i][BCOMP] = FX_PixelToB[pixel0]; - rgba[i][ACOMP] = 255; - rgba[i+1][RCOMP] = FX_PixelToR[pixel1]; - rgba[i+1][GCOMP] = FX_PixelToG[pixel1]; - rgba[i+1][BCOMP] = FX_PixelToB[pixel1]; - rgba[i+1][ACOMP] = 255; - } - if (extraPixel) { - GLushort pixel = data16[n]; - rgba[n][RCOMP] = FX_PixelToR[pixel]; - rgba[n][GCOMP] = FX_PixelToG[pixel]; - rgba[n][BCOMP] = FX_PixelToB[pixel]; - rgba[n][ACOMP] = 255; - } - - grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -} - - -static void -write_R5G6B5_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], const GLubyte mask[]) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDWriteRGBAPixels(...)\n"); - } - - for(i=0;i<n;i++) - if(mask[i]) - LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x[i]+fxMesa->x_offset, bottom-y[i], - 1, 1, (void *)rgba[i]); -} - - -static void -write_R5G6B5_mono_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLubyte mask[]) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDWriteMonoRGBAPixels(...)\n"); - } - - for(i=0;i<n;i++) - if(mask[i]) - writeRegionClipped(fxMesa, fxMesa->currentFB,x[i]+fxMesa->x_offset,bottom-y[i], - GR_LFB_SRC_FMT_8888,1,1,0,(void *) &fxMesa->color); -} - -static void -read_R5G6B5_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[]) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDReadRGBAPixels(...)\n"); - } - - for(i=0;i<n;i++) { - if(mask[i]) { - GLushort pixel; - FX_grLfbReadRegion(fxMesa->currentFB,x[i],bottom-y[i],1,1,0,&pixel); - rgba[i][RCOMP] = FX_PixelToR[pixel]; - rgba[i][GCOMP] = FX_PixelToG[pixel]; - rgba[i][BCOMP] = FX_PixelToB[pixel]; - rgba[i][ACOMP] = 255; - } - } -} - - -/* - * 24bpp span/pixel functions - */ - -static void -write_R8G8B8_rgb_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_888; - else - mode = GR_LFBWRITEMODE_888; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x; - const GLint scrY = winY - y; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - /*GLint dstStride = fxMesa->screen_width * 3;*/ - GLint dstStride = info.strideInBytes / 1; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 1; - GLuint *dst32 = (GLuint *) dst; - GLubyte visMask[MAX_WIDTH]; - GLuint i; - generate_vismask(fxMesa, scrX, scrY, n, visMask); - for (i = 0; i < n; i++) { - if (visMask[i] && (!mask || mask[i])) { - dst32[i] = PACK_BGRA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); - } - } - } - else { - /* back buffer */ - GLint dstStride = info.strideInBytes; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - GLuint *dst32 = (GLuint *) dst; - if (mask) { - GLuint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - dst32[i] = PACK_RGBA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); - } - } - } - else { - GLuint i; - for (i = 0; i < n; i++) { - dst32[i] = PACK_RGBA32(rgb[i][2], rgb[i][1], rgb[i][0], 255); - } - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -} - - - -static void -write_R8G8B8_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgba[][4], const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_8888; - else - mode = GR_LFBWRITEMODE_888 /*565*/; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x; - const GLint scrY = winY - y; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - /* XXX have to do cliprect clipping! */ - GLint dstStride = fxMesa->screen_width * 4; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - GLuint *dst32 = (GLuint *) dst; - GLubyte visMask[MAX_WIDTH]; - GLuint i; - generate_vismask(fxMesa, scrX, scrY, n, visMask); - for (i = 0; i < n; i++) { - if (visMask[i] && (!mask || mask[i])) { - dst32[i] = PACK_BGRA32(rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3]); - } - } - } - else { - /* back buffer */ - GLint dstStride = info.strideInBytes; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - if (mask) { - const GLuint *src32 = (const GLuint *) rgba; - GLuint *dst32 = (GLuint *) dst; - GLuint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - dst32[i] = src32[i]; - } - } - } - else { - /* no mask, write all pixels */ - MEMCPY(dst, rgba, 4 * n); - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -} - - -static void -write_R8G8B8_mono_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GLubyte rgba[MAX_WIDTH][4]; - GLuint *data = (GLuint *) rgba; - GLuint i; - - /* XXX this is a simple-minded implementation but good enough for now */ - for (i = 0; i < n; i++) { - data[i] = (GLuint) fxMesa->color; - } - write_R8G8B8_rgba_span(ctx, n, x, y, (const GLubyte (*)[4]) rgba, mask); -} - - -static void -read_R8G8B8_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - GLubyte rgba[][4]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (1 || fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - mode = GR_LFBWRITEMODE_8888; - } - else { - mode = GR_LFBWRITEMODE_565; /*888*/ /*565*/; - } - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_READ_ONLY, - fxMesa->currentFB, - mode, /*GR_LFBWRITEMODE_ANY,*/ - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - GLint srcStride = fxMesa->screen_width * 4; - const GLubyte *src = (const GLubyte *) info.lfbPtr - + (winY - y) * srcStride + (winX + x) * 4; - GLuint i; - for (i = 0; i < n; i++) { - rgba[i][0] = src[i * 4 + 2]; - rgba[i][1] = src[i * 4 + 1]; - rgba[i][2] = src[i * 4 + 0]; - rgba[i][3] = src[i * 4 + 3]; - } - } - else { - /* back buffer */ - GLint srcStride = /*info.strideInBytes;*/ 8192 / 2; /* XXX a hack! */ - const GLubyte *src = (const GLubyte *) info.lfbPtr - + (winY - y) * srcStride + (winX + x) * 4; - GLuint i; - for (i = 0; i < n; i++) { - rgba[i][0] = src[i * 4 + 2]; - rgba[i][1] = src[i * 4 + 1]; - rgba[i][2] = src[i * 4 + 0]; - rgba[i][3] = src[i * 4 + 3]; - } - } - grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -} - - -static void -write_R8G8B8_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], const GLubyte mask[]) -{ -#if 00 - GLuint i; - for (i = 0; i < n; i++) { - write_R8G8B8_rgba_span(ctx, 1, x[i], y[i], rgba + i, mask + i); - } - -#else - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_8888; - else - mode = GR_LFBWRITEMODE_888 /*565*/; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - GLuint i; - for (i = 0; i < n; i++) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x[i]; - const GLint scrY = winY - y[i]; - if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { - GLint dstStride = fxMesa->screen_width * 4; - GLubyte *dst = (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; - GLuint *dst32 = (GLuint *) dst; - *dst32 = PACK_BGRA32(rgba[i][0], rgba[i][1], - rgba[i][2], rgba[i][3]); - } - } - } - else { - /* back buffer */ - GLuint i; - for (i = 0; i < n; i++) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x[i]; - const GLint scrY = winY - y[i]; - if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { - GLint dstStride = info.strideInBytes; - GLubyte *dst = (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; - GLuint *dst32 = (GLuint *) dst; - const GLuint *src32 = (const GLuint *) rgba; - *dst32 = src32[i]; - } - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -#endif -} - - -static void -write_R8G8B8_mono_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLubyte mask[]) -{ -} - - -static void -read_R8G8B8_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[]) -{ - printf("read_R8G8B8_pixels %d\n", n); -} - - - -/* - * 32bpp span/pixel functions - */ - -static void -write_R8G8B8A8_rgb_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_8888; - else - mode = GR_LFBWRITEMODE_888 /*565*/; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x; - const GLint scrY = winY - y; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - GLint dstStride = fxMesa->screen_width * 4; - GLubyte * dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - GLuint *dst32 = (GLuint *) dst; - GLubyte visMask[MAX_WIDTH]; - GLuint i; - generate_vismask(fxMesa, scrX, scrY, n, visMask); - for (i = 0; i < n; i++) { - if (visMask[i] && (!mask || mask[i])) { - dst32[i] = PACK_BGRA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); - } - } - } - else { - /* back buffer */ - GLint dstStride = info.strideInBytes; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - if (mask) { - GLuint *dst32 = (GLuint *) dst; - GLuint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - dst32[i] = PACK_RGBA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); - } - } - } - else { - GLuint *dst32 = (GLuint *) dst; - GLuint i; - for (i = 0; i < n; i++) { - dst32[i] = PACK_RGBA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); - } - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -} - - -/* - *XXX test of grLfbWriteRegion in 32bpp mode. Doesn't seem to work! - */ -#if 0 -static void -write_R8G8B8A8_rgb_span2(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLint x2 = fxMesa->x_offset +x; - GLint y2 = bottom - y; - - FX_grLfbWriteRegion(fxMesa->currentFB, x2, y2, GR_LFB_SRC_FMT_888, - n, 1, 0, rgb); -} -#endif - - -static void -write_R8G8B8A8_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgba[][4], const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_8888; - else - mode = GR_LFBWRITEMODE_888 /*565*/; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x; - const GLint scrY = winY - y; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - GLint dstStride = fxMesa->screen_width * 4; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - GLuint *dst32 = (GLuint *) dst; - GLubyte visMask[MAX_WIDTH]; - GLuint i; - generate_vismask(fxMesa, scrX, scrY, n, visMask); - for (i = 0; i < n; i++) { - if (visMask[i] && (!mask || mask[i])) { - dst32[i] = PACK_BGRA32(rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3]); - } - } - } - else { - /* back buffer */ - GLint dstStride = 8192; /* XXX a hack info.strideInBytes; */ - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - if (mask) { - const GLuint *src32 = (const GLuint *) rgba; - GLuint *dst32 = (GLuint *) dst; - GLuint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - dst32[i] = src32[i]; - } - } - } - else { - /* no mask, write all pixels */ - MEMCPY(dst, rgba, 4 * n); - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); - } - else { - info.strideInBytes = -1; - } - END_BOARD_LOCK(); -} - - -static void -write_R8G8B8A8_mono_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte mask[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GLubyte rgba[MAX_WIDTH][4]; - GLuint *data = (GLuint *) rgba; - GLuint i; - - /* XXX this is a simple-minded implementation but good enough for now */ - for (i = 0; i < n; i++) { - data[i] = (GLuint) fxMesa->color; - } - write_R8G8B8A8_rgba_span(ctx, n, x, y, (const GLubyte (*)[4]) rgba, mask); -} - - -static void -read_R8G8B8A8_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, - GLubyte rgba[][4]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - mode = GR_LFBWRITEMODE_8888; - } - else { - mode = GR_LFBWRITEMODE_8888; /*565;*/ - } - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_READ_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - GLint srcStride = fxMesa->screen_width; - const GLuint *src32 = (const GLuint *) info.lfbPtr - + (winY - y) * srcStride + (winX + x); - GLuint i; - for (i = 0; i < n; i++) { - const GLuint p = src32[i]; - rgba[i][0] = (p >> 16) & 0xff; - rgba[i][1] = (p >> 8) & 0xff; - rgba[i][2] = (p >> 0) & 0xff; - rgba[i][3] = (p >> 24) & 0xff; - } - } - else { - /* back buffer */ - GLint srcStride = 1024; /* XXX a hack */ - const GLuint *src32 = (const GLuint *) info.lfbPtr - + (winY - y) * srcStride + (winX + x); - GLuint i; - for (i = 0; i < n; i++) { - GLuint p = src32[i]; - rgba[i][0] = (p >> 16) & 0xff; - rgba[i][1] = (p >> 8) & 0xff; - rgba[i][2] = (p >> 0) & 0xff; - rgba[i][3] = (p >> 24) & 0xff; - } - } - grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); - } - else - info.strideInBytes = -1; - END_BOARD_LOCK(); -} - - -static void -write_R8G8B8A8_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], const GLubyte mask[]) -{ -#if 00 - GLuint i; - for (i = 0; i < n; i++) { - write_R8G8B8A8_rgba_span(ctx, 1, x[i], y[i], rgba + i, mask + i); - } - -#else - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbWriteMode_t mode; - GrLfbInfo_t info; - - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) - mode = GR_LFBWRITEMODE_8888; - else - mode = GR_LFBWRITEMODE_888 /*565*/; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - fxMesa->currentFB, - mode, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { - GLuint i; - for (i = 0; i < n; i++) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x[i]; - const GLint scrY = winY - y[i]; - if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { - GLint dstStride = fxMesa->screen_width * 4; - GLubyte *dst = (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; - GLuint *dst32 = (GLuint *) dst; - *dst32 = PACK_BGRA32(rgba[i][0], rgba[i][1], - rgba[i][2], rgba[i][3]); - } - } - } - else { - /* back buffer */ - GLuint i; - for (i = 0; i < n; i++) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x[i]; - const GLint scrY = winY - y[i]; - if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { - GLint dstStride = info.strideInBytes; - GLubyte *dst = (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; - GLuint *dst32 = (GLuint *) dst; - const GLuint *src32 = (const GLuint *) rgba; - *dst32 = src32[i]; - } - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); - } - END_BOARD_LOCK(); -#endif -} - - -static void -write_R8G8B8A8_mono_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLubyte mask[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLuint i; - GLuint color = fxMesa->color; - for (i = 0; i < n; i++) { - if (mask[i]) { - write_R8G8B8A8_rgba_span(ctx, 1, x[i], y[i], - (const GLubyte (*)[4]) &color, mask + i); - } - } -} - - - -static void -read_R8G8B8A8_pixels(const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[]) -{ - GLuint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - read_R8G8B8A8_span(ctx, 1, x[i], y[i], rgba + i); - } - } - printf("read_R8G8B8A8_pixels %d\n", n); -} - - - -/* - * Depth buffer read/write functions. - */ - -void fxDDWriteDepthSpan(GLcontext *ctx, - GLuint n, GLint x, GLint y, const GLdepth depth[], - const GLubyte mask[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint depth_size = fxMesa->glVis->DepthBits; - GLuint stencil_size = fxMesa->glVis->StencilBits; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDWriteDepthSpan(...)\n"); - } - - x += fxMesa->x_offset; - - if (mask) { - GLint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - GLshort d16; - GLuint d32; - switch (depth_size) { - case 16: - d16 = depth[i]; - writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y, - GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d16); - break; - case 32: - if (!fb_point_is_clipped(fxMesa, x+i, bottom-y)) { - if (stencil_size > 0) { - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - x + i, bottom - y, - 1, - sizeof(GLdepth), - &d32, - FBS_READ); - d32 = depth[i] & 0xFF000000; - break; - } else { - d32 = depth[i]; - } - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - x + i, bottom - y, - 1, - sizeof(GLdepth), - &d32, - FBS_WRITE); - } - } - } - } - } else { - GLushort depth16[MAX_WIDTH]; - GLint i; - GLuint d32; - switch (depth_size) { - case 16: - for (i = 0; i < n; i++) { - depth16[i] = depth[i]; - } - writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y, - GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth16); - break; - case 32: - for (i = 0; i < n; i++) { - if (fb_point_is_clipped(fxMesa, x+i, bottom-y)) { - if (stencil_size > 0) { - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - x + i, bottom - y, - 1, - sizeof(GLdepth), - &d32, - FBS_READ); - d32 = (d32 & 0xFF0000) | (depth[i] & 0x00FFFFFF); - } else { - d32 = depth[i]; - } - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - x + i, bottom - y, - 1, - sizeof(GLdepth), - &d32, - FBS_WRITE); - } - } - } - } -} - - -void fxDDReadDepthSpan(GLcontext *ctx, - GLuint n, GLint x, GLint y, GLdepth depth[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLushort depth16[MAX_WIDTH]; - GLuint i; - GLuint depth_size = fxMesa->glVis->DepthBits; - GLuint stencil_size = fxMesa->glVis->StencilBits; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDReadDepthSpan(...)\n"); - } - - x += fxMesa->x_offset; - switch (depth_size) { - case 16: - FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth16); - for (i = 0; i < n; i++) { - depth[i] = depth16[i]; - } - break; - case 32: - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - x, bottom - y, - n, - sizeof(GLdepth), - depth, - FBS_READ); - if (stencil_size > 0) { - for (i = 0; i < n; i++) { - depth[i] &= 0xFFFFFF; - } - } - } -} - - - -void fxDDWriteDepthPixels(GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLdepth depth[], const GLubyte mask[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint i; - GLuint d32; - GLuint depth_size = fxMesa->glVis->DepthBits; - GLuint stencil_size = fxMesa->glVis->StencilBits; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDWriteDepthPixels(...)\n"); - } - - for (i = 0; i < n; i++) { - if (mask[i]) { - int xpos = x[i] + fxMesa->x_offset; - int ypos = bottom - y[i]; - GLushort d16 = depth[i]; - switch (depth_size) { - case 16: - writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos, - GR_LFB_SRC_FMT_ZA16, 1, 1, 0, - (void *) &d16); - break; - case 32: - if (!fb_point_is_clipped(fxMesa, xpos, ypos)) { - if (stencil_size > 0) { - /* - * Should I sign extend this? I don't - * believe so, since GLdepth is unsigned. - */ - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d32, - FBS_READ); - d32 = (d32 &~ 0xFF000000) | (depth[i] & 0x00FFFFFF); - } else { - d32 = depth[i]; - } - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d32, - FBS_WRITE); - } - break; - } - } - } -} - - -void fxDDReadDepthPixels(GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], GLdepth depth[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint i; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDReadDepthPixels(...)\n"); - } - - for (i = 0; i < n; i++) { - int xpos = x[i] + fxMesa->x_offset; - int ypos = bottom - y[i]; - GLushort d16; - GLuint d32; - GLuint depth_size = fxMesa->glVis->DepthBits; - GLuint stencil_size = fxMesa->glVis->StencilBits; - - assert((depth_size == 16) || (depth_size == 24) || (depth_size == 32)); - switch (depth_size) { - case 16: - FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &d16); - depth[i] = d16; - break; - case 24: - case 32: - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - depth_size/8, - &d32, - FBS_READ); - /* - * Get rid of the stencil bits. Should I sign - * extend this? I don't believe so, since GLdepth - * is unsigned. - */ - if (stencil_size > 0) { - d32 &= 0xFFFFFF; - } - depth[i] = d32; - break; - default: - assert(0); - } - } -} - - -/* - * Stencil buffer read/write functions. - */ - -#define DEPTH_VALUE_TO_STENCIL_VALUE(d) (((d) >> 24) & 0xFF) -#define STENCIL_VALUE_TO_DEPTH_VALUE(s,d) \ - ((((s) & 0xFF) << 24) | ((d) & 0xFFFFFF)) -#define ASSEMBLE_STENCIL_VALUE(os, ns, mask) \ - (((os) &~ (mask)) | ((ns) & (mask))) - -#if 00 -/* - * Read a horizontal span of stencil values from the stencil buffer. - */ -void -fxDDReadStencilSpan( GLcontext *ctx, - GLuint n, - GLint x, - GLint y, - GLstencil stencil[] ) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint i; - int xpos = x + fxMesa->x_offset; - int ypos = bottom - y; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDReadStencilSpan(...)\n"); - } - - for (i = 0; i < n; i++, ypos += 1) { - GLuint d; - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d, - FBS_READ); - stencil[i] = DEPTH_VALUE_TO_STENCIL_VALUE(d); - } -} - -/* - * Write a horizontal span of stencil values into the stencil buffer. - * If mask is NULL, write all stencil values. - * Else, only write stencil[i] if mask[i] is non-zero. - */ -void -fxDDWriteStencilSpan( GLcontext *ctx, - GLuint n, - GLint x, - GLint y, - const GLstencil stencil[], - const GLubyte mask[] ) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint i; - int xpos = x + fxMesa->x_offset; - int ypos = bottom - y; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDWriteStencilSpan(...)\n"); - } - - for (i = 0; i < n; i++, ypos += 1) { - GLdepth d; - GLstencil ns; - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d, - FBS_READ); - /* - * Find the old stencil value, and strip off the bits - * we are going to write. - */ - ns = ASSEMBLE_STENCIL_VALUE(DEPTH_VALUE_TO_STENCIL_VALUE(d), - stencil[i], - mask[i]); - /* - * Now, assemble the new StenDepth value, with the old - * depth value, the old stencil value in the bits - * where mask is 0, and the new stencil value in the bits - * where mask is 1. - */ - d = STENCIL_VALUE_TO_DEPTH_VALUE(ns, d); - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d, - FBS_WRITE); - } -} - -/* Write an array of stencil values into the stencil buffer. - * If mask is NULL, write all stencil values. - * Else, only write stencil[i] if mask[i] is non-zero. - */ -void -fxDDReadStencilPixels( GLcontext *ctx, - GLuint n, - const GLint x[], - const GLint y[], - GLstencil stencil[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint i; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDReadStencilPixels(...)\n"); - } - - for (i = 0; i < n; i++) { - int xpos = x[i] + fxMesa->x_offset; - int ypos = bottom - y[i]; - GLuint d; - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d, - FBS_READ); - stencil[i] = DEPTH_VALUE_TO_STENCIL_VALUE(d); - } -} - -/* - * Read an array of stencil values from the stencil buffer. - */ -void -fxDDWriteStencilPixels( GLcontext *ctx, - GLuint n, - const GLint x[], - const GLint y[], - const GLstencil stencil[], - const GLstencil mask[]) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - GLuint i; - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDWriteStencilPixels(...)\n"); - } - - for (i = 0; i < n; i++) { - int xpos = x[i] + fxMesa->x_offset; - int ypos = bottom - y[i]; - GLuint d; - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d, - FBS_READ); - d = STENCIL_VALUE_TO_DEPTH_VALUE(stencil[i], d); - rw_fb_span(fxMesa, - GR_BUFFER_AUXBUFFER, - xpos, ypos, - 1, - sizeof(GLdepth), - &d, - FBS_WRITE); - } -} -#endif /* disable fxddStencil* funcs */ - - -#define EXTRACT_S_FROM_ZS(zs) (((zs) >> 24) & 0xFF) -#define EXTRACT_Z_FROM_ZS(zs) ((zs) & 0xffffff) -#define BUILD_ZS(z, s) (((s) << 24) | (z)) - -static void write_stencil_span(GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLstencil stencil[], - const GLubyte mask[] ) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbInfo_t info; - int s; - void *d; - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_WRITE_ONLY, - GR_BUFFER_AUXBUFFER, - GR_LFBWRITEMODE_Z32, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - const GLint scrX = winX + x; - const GLint scrY = winY - y; - - GLint dstStride = info.strideInBytes; - GLubyte *dst = (GLubyte *) info.lfbPtr - + (winY - y) * dstStride + (winX + x) * 4; - GLuint *dst32 = (GLuint *) dst; - GLubyte visMask[MAX_WIDTH]; - GLuint i; - generate_vismask(fxMesa, scrX, scrY, n, visMask); - s = dstStride; - d = dst32; - for (i = 0; i < n; i++) { - if (visMask[i] && (!mask || mask[i])) { - GLuint zs = dst32[i]; - GLuint z = EXTRACT_Z_FROM_ZS(zs); - zs = BUILD_ZS(z, stencil[i]); - dst32[i] = /*zs;*/ stencil[i]; - } - } - grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_AUXBUFFER); - } - else { - s = -1; - d = 0; - } - END_BOARD_LOCK(); - /* - printf("write stencil span %d %p\n", s, d); - printf("info: size=%d lfbPtr=%p stride=%x writeMode=%x origin=%x\n", - info.size, info.lfbPtr, info.strideInBytes, info.writeMode, info.origin); - */ -} - - -static void -read_stencil_span(GLcontext *ctx, GLuint n, GLint x, GLint y, - GLstencil stencil[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - GrLfbInfo_t info; - /* - int s; - void *d; - */ - - BEGIN_BOARD_LOCK(); - info.size = sizeof(info); - if (grLfbLock(GR_LFB_READ_ONLY, - GR_BUFFER_AUXBUFFER, - GR_LFBWRITEMODE_Z32, - GR_ORIGIN_UPPER_LEFT, - FXFALSE, - &info)) { - const GLint winY = fxMesa->y_offset + fxMesa->height - 1; - const GLint winX = fxMesa->x_offset; - GLint srcStride = /*info.strideInBytes;*/ 8192 ; /* XXX a hack! */ - const GLubyte *src = (const GLubyte *) info.lfbPtr - + (winY - y) * srcStride + (winX + x) * 4; - const GLuint *src32 = (const GLuint *) src; - GLuint i; - /* - s = srcStride; - d = src32; - */ - for (i = 0; i < n; i++) { - stencil[i] = EXTRACT_S_FROM_ZS(src32[i]); - } - grLfbUnlock(GR_LFB_READ_ONLY, GR_BUFFER_AUXBUFFER); - } - END_BOARD_LOCK(); - /* - printf("read stencil span %d %p\n", s, d); - printf("info: size=%d lfbPtr=%p stride=%x writeMode=%x origin=%x\n", - info.size, info.lfbPtr, info.strideInBytes, info.writeMode, info.origin); - */ -} - - -static void -write_stencil_pixels( GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - const GLstencil stencil[], const GLubyte mask[]) -{ - /* XXX optimize this */ - GLuint i; - for (i = 0; i < n; i++) { - if (mask[i]) { - write_stencil_span(ctx, 1, x[i], y[i], stencil + i, mask + i); - } - } -} - - -static void -read_stencil_pixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], - GLstencil stencil[]) -{ - /* XXX optimize this */ - GLuint i; - for (i = 0; i < n; i++) { - read_stencil_span(ctx, 1, x[i], y[i], stencil + i); - } -} - - - -void fxSetupDDSpanPointers(GLcontext *ctx) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (ctx->Visual->RedBits == 5 && - ctx->Visual->GreenBits == 6 && - ctx->Visual->BlueBits == 5 && - ctx->Visual->AlphaBits == 0) { - /* 16bpp mode */ - ctx->Driver.WriteRGBASpan = write_R5G6B5_rgba_span; - ctx->Driver.WriteRGBSpan = write_R5G6B5_rgb_span; - ctx->Driver.WriteMonoRGBASpan = write_R5G6B5_mono_span; - ctx->Driver.WriteRGBAPixels = write_R5G6B5_pixels; - ctx->Driver.WriteMonoRGBAPixels = write_R5G6B5_mono_pixels; - ctx->Driver.ReadRGBASpan = read_R5G6B5_span; - ctx->Driver.ReadRGBAPixels = read_R5G6B5_pixels; - } - else if (ctx->Visual->RedBits == 8 && - ctx->Visual->GreenBits == 8 && - ctx->Visual->BlueBits == 8 && - ctx->Visual->AlphaBits == 0) { - /* 24bpp mode */ - ctx->Driver.WriteRGBASpan = write_R8G8B8_rgba_span; - ctx->Driver.WriteRGBSpan = write_R8G8B8_rgb_span; - ctx->Driver.WriteMonoRGBASpan = write_R8G8B8_mono_span; - ctx->Driver.WriteRGBAPixels = write_R8G8B8_pixels; - ctx->Driver.WriteMonoRGBAPixels = write_R8G8B8_mono_pixels; - ctx->Driver.ReadRGBASpan = read_R8G8B8_span; - ctx->Driver.ReadRGBAPixels = read_R8G8B8_pixels; - } - else if (ctx->Visual->RedBits == 8 && - ctx->Visual->GreenBits == 8 && - ctx->Visual->BlueBits == 8 && - ctx->Visual->AlphaBits == 8) { - /* 32bpp mode */ - ctx->Driver.WriteRGBASpan = write_R8G8B8A8_rgba_span; - ctx->Driver.WriteRGBSpan = write_R8G8B8A8_rgb_span; - ctx->Driver.WriteMonoRGBASpan = write_R8G8B8A8_mono_span; - ctx->Driver.WriteRGBAPixels = write_R8G8B8A8_pixels; - ctx->Driver.WriteMonoRGBAPixels = write_R8G8B8A8_mono_pixels; - ctx->Driver.ReadRGBASpan = read_R8G8B8A8_span; - ctx->Driver.ReadRGBAPixels = read_R8G8B8A8_pixels; - } - else { - abort(); - } - - if (fxMesa->haveHwStencil) { - ctx->Driver.WriteStencilSpan = write_stencil_span; - ctx->Driver.ReadStencilSpan = read_stencil_span; - ctx->Driver.WriteStencilPixels = write_stencil_pixels; - ctx->Driver.ReadStencilPixels = read_stencil_pixels; - } - - ctx->Driver.WriteCI8Span = NULL; - ctx->Driver.WriteCI32Span = NULL; - ctx->Driver.WriteMonoCISpan = NULL; - ctx->Driver.WriteCI32Pixels = NULL; - ctx->Driver.WriteMonoCIPixels = NULL; - ctx->Driver.ReadCI32Span = NULL; - ctx->Driver.ReadCI32Pixels = NULL; -} diff --git a/xc/extras/Mesa/src/FX/fxddtex.c b/xc/extras/Mesa/src/FX/fxddtex.c deleted file mode 100644 index 24a00a8ed..000000000 --- a/xc/extras/Mesa/src/FX/fxddtex.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - -#include "fxdrv.h" -#include "image.h" -#include "texutil.h" - - -void fxPrintTextureData(tfxTexInfo *ti) -{ - fprintf(stderr, "Texture Data:\n"); - if (ti->tObj) { - fprintf(stderr, "\tName: %d\n", ti->tObj->Name); - fprintf(stderr, "\tBaseLevel: %d\n", ti->tObj->BaseLevel); - fprintf(stderr, "\tSize: %d x %d\n", - ti->tObj->Image[ti->tObj->BaseLevel]->Width, - ti->tObj->Image[ti->tObj->BaseLevel]->Height); - } else - fprintf(stderr, "\tName: UNNAMED\n"); - fprintf(stderr, "\tLast used: %d\n", ti->lastTimeUsed); - fprintf(stderr, "\tTMU: %ld\n", ti->whichTMU); - fprintf(stderr, "\t%s\n", (ti->isInTM)?"In TMU":"Not in TMU"); - if (ti->tm[0]) - fprintf(stderr, "\tMem0: %x-%x\n", (unsigned) ti->tm[0]->startAddr, - (unsigned) ti->tm[0]->endAddr); - if (ti->tm[1]) - fprintf(stderr, "\tMem1: %x-%x\n", (unsigned) ti->tm[1]->startAddr, - (unsigned) ti->tm[1]->endAddr); - fprintf(stderr, "\tMipmaps: %d-%d\n", ti->minLevel, ti->maxLevel); - fprintf(stderr, "\tFilters: min %d min %d\n", - (int) ti->minFilt, (int) ti->maxFilt); - fprintf(stderr, "\tClamps: s %d t %d\n", (int) ti->sClamp, (int) ti->tClamp); - fprintf(stderr, "\tScales: s %f t %f\n", ti->sScale, ti->tScale); - fprintf(stderr, "\tInt Scales: s %d t %d\n", - ti->int_sScale/0x800000, ti->int_tScale/0x800000); - fprintf(stderr, "\t%s\n", (ti->fixedPalette)?"Fixed palette":"Non fixed palette"); - fprintf(stderr, "\t%s\n", (ti->validated)?"Validated":"Not validated"); -} - - -/************************************************************************/ -/*************************** Texture Mapping ****************************/ -/************************************************************************/ - -static void fxTexInvalidate(GLcontext *ctx, struct gl_texture_object *tObj) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - tfxTexInfo *ti; - - ti=fxTMGetTexInfo(tObj); - if (ti->isInTM) fxTMMoveOutTM(fxMesa,tObj); /* TO DO: SLOW but easy to write */ - - ti->validated=GL_FALSE; - fxMesa->new_state|=FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -static tfxTexInfo *fxAllocTexObjData(fxMesaContext fxMesa) -{ - tfxTexInfo *ti; - int i; - - if(!(ti=CALLOC(sizeof(tfxTexInfo)))) { - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); - } - - ti->validated=GL_FALSE; - ti->isInTM=GL_FALSE; - - ti->whichTMU=FX_TMU_NONE; - - ti->tm[FX_TMU0]=NULL; - ti->tm[FX_TMU1]=NULL; - - ti->minFilt=GR_TEXTUREFILTER_POINT_SAMPLED; - ti->maxFilt=GR_TEXTUREFILTER_BILINEAR; - - ti->sClamp=GR_TEXTURECLAMP_WRAP; - ti->tClamp=GR_TEXTURECLAMP_WRAP; - - ti->mmMode=GR_MIPMAP_NEAREST; - ti->LODblend=FXFALSE; - - for(i=0;i<MAX_TEXTURE_LEVELS;i++) { - ti->mipmapLevel[i].data=NULL; - } - - return ti; -} - -void fxDDTexBind(GLcontext *ctx, GLenum target, struct gl_texture_object *tObj) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - tfxTexInfo *ti; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDTexBind(%d,%x)\n",tObj->Name,(GLuint)tObj->DriverData); - } - - if(target!=GL_TEXTURE_2D) - return; - - if (!tObj->DriverData) { - tObj->DriverData=fxAllocTexObjData(fxMesa); - } - - ti=fxTMGetTexInfo(tObj); - - fxMesa->texBindNumber++; - ti->lastTimeUsed=fxMesa->texBindNumber; - - fxMesa->new_state|=FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -void fxDDTexEnv(GLcontext *ctx, GLenum target, GLenum pname, const GLfloat *param) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - if(param) - fprintf(stderr,"fxmesa: texenv(%x,%x)\n",pname,(GLint)(*param)); - else - fprintf(stderr,"fxmesa: texenv(%x)\n",pname); - } - - /* apply any lod biasing right now */ - if (pname==GL_TEXTURE_LOD_BIAS_EXT) { - FX_grTexLodBiasValue(GR_TMU0,*param); - - if(fxMesa->haveTwoTMUs) { - FX_grTexLodBiasValue(GR_TMU1,*param); - } - - } - - fxMesa->new_state|=FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -void fxDDTexParam(GLcontext *ctx, GLenum target, struct gl_texture_object *tObj, - GLenum pname, const GLfloat *params) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLenum param=(GLenum)(GLint)params[0]; - tfxTexInfo *ti; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDTexParam(%d,%x,%x,%x)\n",tObj->Name,(GLuint)tObj->DriverData,pname,param); - } - - if(target!=GL_TEXTURE_2D) - return; - - if (!tObj->DriverData) - tObj->DriverData=fxAllocTexObjData(fxMesa); - - ti=fxTMGetTexInfo(tObj); - - switch(pname) { - - case GL_TEXTURE_MIN_FILTER: - switch(param) { - case GL_NEAREST: - ti->mmMode=GR_MIPMAP_DISABLE; - ti->minFilt=GR_TEXTUREFILTER_POINT_SAMPLED; - ti->LODblend=FXFALSE; - break; - case GL_LINEAR: - ti->mmMode=GR_MIPMAP_DISABLE; - ti->minFilt=GR_TEXTUREFILTER_BILINEAR; - ti->LODblend=FXFALSE; - break; - case GL_NEAREST_MIPMAP_NEAREST: - ti->mmMode=GR_MIPMAP_NEAREST; - ti->minFilt=GR_TEXTUREFILTER_POINT_SAMPLED; - ti->LODblend=FXFALSE; - break; - case GL_LINEAR_MIPMAP_NEAREST: - ti->mmMode=GR_MIPMAP_NEAREST; - ti->minFilt=GR_TEXTUREFILTER_BILINEAR; - ti->LODblend=FXFALSE; - break; - case GL_NEAREST_MIPMAP_LINEAR: - if(fxMesa->haveTwoTMUs) { - ti->mmMode=GR_MIPMAP_NEAREST; - ti->LODblend=FXTRUE; - } else { - ti->mmMode=GR_MIPMAP_NEAREST_DITHER; - ti->LODblend=FXFALSE; - } - ti->minFilt=GR_TEXTUREFILTER_POINT_SAMPLED; - break; - case GL_LINEAR_MIPMAP_LINEAR: - if(fxMesa->haveTwoTMUs) { - ti->mmMode=GR_MIPMAP_NEAREST; - ti->LODblend=FXTRUE; - } else { - ti->mmMode=GR_MIPMAP_NEAREST_DITHER; - ti->LODblend=FXFALSE; - } - ti->minFilt=GR_TEXTUREFILTER_BILINEAR; - break; - default: - break; - } - fxTexInvalidate(ctx,tObj); - break; - - case GL_TEXTURE_MAG_FILTER: - switch(param) { - case GL_NEAREST: - ti->maxFilt=GR_TEXTUREFILTER_POINT_SAMPLED; - break; - case GL_LINEAR: - ti->maxFilt=GR_TEXTUREFILTER_BILINEAR; - break; - default: - break; - } - fxTexInvalidate(ctx,tObj); - break; - - case GL_TEXTURE_WRAP_S: - switch(param) { - case GL_CLAMP: - ti->sClamp=GR_TEXTURECLAMP_CLAMP; - break; - case GL_REPEAT: - ti->sClamp=GR_TEXTURECLAMP_WRAP; - break; - default: - break; - } - fxMesa->new_state|=FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - - case GL_TEXTURE_WRAP_T: - switch(param) { - case GL_CLAMP: - ti->tClamp=GR_TEXTURECLAMP_CLAMP; - break; - case GL_REPEAT: - ti->tClamp=GR_TEXTURECLAMP_WRAP; - break; - default: - break; - } - fxMesa->new_state|=FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - - case GL_TEXTURE_BORDER_COLOR: - /* TO DO */ - break; - - case GL_TEXTURE_MIN_LOD: - /* TO DO */ - break; - case GL_TEXTURE_MAX_LOD: - /* TO DO */ - break; - case GL_TEXTURE_BASE_LEVEL: - fxTexInvalidate(ctx,tObj); - break; - case GL_TEXTURE_MAX_LEVEL: - fxTexInvalidate(ctx,tObj); - break; - - default: - break; - } -} - -void fxDDTexDel(GLcontext *ctx, struct gl_texture_object *tObj) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - tfxTexInfo *ti = fxTMGetTexInfo(tObj); - - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDTexDel(%d,%p)\n", tObj->Name, ti); - } - - if (!ti) - return; - - fxTMFreeTexture(fxMesa, tObj); - - FREE(ti); - tObj->DriverData = NULL; - - ctx->NewState |= NEW_TEXTURING; -} - - - -/* - * Convert a gl_color_table texture palette to Glide's format. - */ -static void -convertPalette(FxU32 data[256], const struct gl_color_table *table) -{ - const GLubyte *tableUB = (const GLubyte *) table->Table; - GLint width = table->Size; - FxU32 r, g, b, a; - GLint i; - - ASSERT(table->TableType == GL_UNSIGNED_BYTE); - - switch (table->Format) { - case GL_INTENSITY: - for (i = 0; i < width; i++) { - r = tableUB[i]; - g = tableUB[i]; - b = tableUB[i]; - a = tableUB[i]; - data[i] = (a << 24) | (r << 16) | (g << 8) | b; - } - break; - case GL_LUMINANCE: - for (i = 0; i < width; i++) { - r = tableUB[i]; - g = tableUB[i]; - b = tableUB[i]; - a = 255; - data[i] = (a << 24) | (r << 16) | (g << 8) | b; - } - break; - case GL_ALPHA: - for (i = 0; i < width; i++) { - r = g = b = 255; - a = tableUB[i]; - data[i] = (a << 24) | (r << 16) | (g << 8) | b; - } - break; - case GL_LUMINANCE_ALPHA: - for (i = 0; i < width; i++) { - r = g = b = tableUB[i*2+0]; - a = tableUB[i*2+1]; - data[i] = (a << 24) | (r << 16) | (g << 8) | b; - } - break; - case GL_RGB: - for (i = 0; i < width; i++) { - r = tableUB[i*3+0]; - g = tableUB[i*3+1]; - b = tableUB[i*3+2]; - a = 255; - data[i] = (a << 24) | (r << 16) | (g << 8) | b; - } - break; - case GL_RGBA: - for (i = 0; i < width; i++) { - r = tableUB[i*4+0]; - g = tableUB[i*4+1]; - b = tableUB[i*4+2]; - a = tableUB[i*4+3]; - data[i] = (a << 24) | (r << 16) | (g << 8) | b; - } - break; - } -} - - -void fxDDTexPalette(GLcontext *ctx, struct gl_texture_object *tObj) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (tObj) { - /* per-texture palette */ - tfxTexInfo *ti; - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDTexPalette(%d,%x)\n", - tObj->Name, (GLuint) tObj->DriverData); - } - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); - ti = fxTMGetTexInfo(tObj); - convertPalette(ti->palette.data, &tObj->Palette); - fxTexInvalidate(ctx, tObj); - } - else { - /* global texture palette */ - if (MESA_VERBOSE & VERBOSE_DRIVER) { - fprintf(stderr, "fxmesa: fxDDTexPalette(global)\n"); - } - convertPalette(fxMesa->glbPalette.data, &ctx->Texture.Palette); - fxMesa->new_state |= FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; - } -} - - -void fxDDTexUseGlbPalette(GLcontext *ctx, GLboolean state) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDTexUseGlbPalette(%d)\n",state); - } - - if (state) { - fxMesa->haveGlobalPaletteTexture = 1; - - FX_grTexDownloadTable(GR_TMU0,GR_TEXTABLE_PALETTE, &(fxMesa->glbPalette)); - if (fxMesa->haveTwoTMUs) - FX_grTexDownloadTable(GR_TMU1, GR_TEXTABLE_PALETTE, &(fxMesa->glbPalette)); - } - else { - fxMesa->haveGlobalPaletteTexture = 0; - - if ((ctx->Texture.Unit[0].Current == ctx->Texture.Unit[0].CurrentD[2]) && - (ctx->Texture.Unit[0].Current != NULL)) { - struct gl_texture_object *tObj = ctx->Texture.Unit[0].Current; - - if (!tObj->DriverData) - tObj->DriverData = fxAllocTexObjData(fxMesa); - - fxTexInvalidate(ctx, tObj); - } - } -} - - -static int logbase2(int n) -{ - GLint i = 1; - GLint log2 = 0; - - if (n<0) { - return -1; - } - - while (n > i) { - i *= 2; - log2++; - } - if (i != n) { - return -1; - } - else { - return log2; - } -} - -/* Need different versions for different cpus. - */ -#define INT_TRICK(l2) (0x800000 * (l2)) -int fxTexGetInfo(int w, int h, GrLOD_t *lodlevel, - GrAspectRatio_t *aspectratio, - float *sscale, float *tscale, - int *i_sscale, int *i_tscale, - int *wscale, int *hscale) -{ - int logw, logh, ar, l, is, it, ws, hs; - float s, t; - - logw=logbase2(w); - logh=logbase2(h); - ar=logw-logh; - /* Hardware only allows a maximum aspect ratio of 8x1, so handle - |ar|>3 by scaling the image and using an 8x1 aspect ratio */ - if (ar>=0) { - l=logw; - s=256.0; - is=INT_TRICK(8); - ws=1; - if (ar<3) { - t=256>>ar; - it=INT_TRICK(8-ar); - hs=1; - } else { - t=32.0; - it=INT_TRICK(5); - hs=1<<(ar-3); - } - } else { - l=logh; - t=256.0; - it=INT_TRICK(8); - hs=1; - if (-ar<3) { - s=256>>-ar; - is=INT_TRICK(8+ar); - ws=1; - } else { - s=32.0; - is=INT_TRICK(5); - ws=1<<(-ar-3); - } - } - if (ar<-3) ar=-3; - if (ar>3) ar=3; - - /* The above numbers are calculated sensibly and work for Glide3, but - we change them to the whacky glide2 values if needed. */ -#ifdef FX_GLIDE3 - if (lodlevel) *lodlevel=l; - if (aspectratio) *aspectratio=ar; -#else - if (lodlevel) *lodlevel=8-l; - if (aspectratio) *aspectratio=3-ar; -#endif - if (sscale) *sscale=s; - if (tscale) *tscale=t; - if (wscale) *wscale=ws; - if (hscale) *hscale=hs; - if (i_sscale) *i_sscale = is; - if (i_tscale) *i_tscale = it; - return 1; -} - -/* - * Given an OpenGL internal texture format, return the corresponding - * Glide internal texture format and base texture format. - */ -void fxTexGetFormat(GLenum glformat, GrTextureFormat_t *tfmt, GLint *ifmt) -{ - switch(glformat) { - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - if(tfmt) - (*tfmt)=GR_TEXFMT_INTENSITY_8; - if(ifmt) - (*ifmt)=GL_LUMINANCE; - break; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - if(tfmt) - (*tfmt)=GR_TEXFMT_ALPHA_INTENSITY_88; - if(ifmt) - (*ifmt)=GL_LUMINANCE_ALPHA; - break; - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - if(tfmt) - (*tfmt)=GR_TEXFMT_ALPHA_8; - if(ifmt) - (*ifmt)=GL_INTENSITY; - break; - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - if(tfmt) - (*tfmt)=GR_TEXFMT_ALPHA_8; - if(ifmt) - (*ifmt)=GL_ALPHA; - break; - case 3: - case GL_RGB: - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB5: - if(tfmt) - (*tfmt)=GR_TEXFMT_RGB_565; - if(ifmt) - (*ifmt)=GL_RGB; - break; - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - if(tfmt) - (*tfmt)=GR_TEXFMT_ARGB_8888; - if(ifmt) - (*ifmt)=GL_RGB; - break; - case 4: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA4: - if(tfmt) - (*tfmt)=GR_TEXFMT_ARGB_4444; - if(ifmt) - (*ifmt)=GL_RGBA; - break; - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - if(tfmt) - (*tfmt)=GR_TEXFMT_ARGB_4444; - if(ifmt) - (*ifmt)=GL_RGBA; - break; - case GL_RGB5_A1: - if(tfmt) - (*tfmt)=GR_TEXFMT_ARGB_1555; - if(ifmt) - (*ifmt)=GL_RGBA; - break; - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - if(tfmt) - (*tfmt)=GR_TEXFMT_P_8; - if(ifmt) - (*ifmt)=GL_RGBA; /* XXX why is this RGBA? */ - break; - default: - fprintf(stderr, - "fx Driver: unsupported internalFormat in fxTexGetFormat()\n"); - fxCloseHardware(); - exit(-1); - break; - } -} - -static GLboolean fxIsTexSupported(GLenum target, GLint internalFormat, - const struct gl_texture_image *image) -{ - if(target != GL_TEXTURE_2D) - return GL_FALSE; - - if(!fxTexGetInfo(image->Width,image->Height,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL)) - return GL_FALSE; - - if (image->Border > 0) - return GL_FALSE; - - return GL_TRUE; -} - - -/**********************************************************************/ -/**** NEW TEXTURE IMAGE FUNCTIONS ****/ -/**********************************************************************/ - -GLboolean fxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLboolean *retainInternalCopy) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - - if (target != GL_TEXTURE_2D) - return GL_FALSE; - - if (!texObj->DriverData) - texObj->DriverData = fxAllocTexObjData(fxMesa); - - if (fxIsTexSupported(target, texImage->IntFormat, texImage)) { - GrTextureFormat_t gldformat; - tfxTexInfo *ti = fxTMGetTexInfo(texObj); - tfxMipMapLevel *mml = &ti->mipmapLevel[level]; - GLint dstWidth, dstHeight, wScale, hScale, texelSize, dstStride; - MesaIntTexFormat intFormat; - - fxTexGetFormat(texImage->IntFormat, &gldformat, NULL); - - fxTexGetInfo(texImage->Width, texImage->Height, NULL,NULL,NULL,NULL, - NULL,NULL, &wScale, &hScale); - - dstWidth = texImage->Width * wScale; - dstHeight = texImage->Height * hScale; - - switch (texImage->IntFormat) { - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - texelSize = 1; - intFormat = MESA_I8; - break; - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - texelSize = 1; - intFormat = MESA_L8; - break; - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - texelSize = 1; - intFormat = MESA_A8; - break; - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - texelSize = 1; - intFormat = MESA_C8; - break; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - texelSize = 2; - intFormat = MESA_A8_L8; - break; - case 3: - case GL_RGB: - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB5: - texelSize = 2; - intFormat = MESA_R5_G6_B5; - break; - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - texelSize = 4; - intFormat = MESA_A8_R8_G8_B8; - break; - case 4: - case GL_RGBA: - case GL_RGBA2: - case GL_RGBA4: - texelSize = 2; - intFormat = MESA_A4_R4_G4_B4; - break; - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - texelSize = 2; - intFormat = MESA_A4_R4_G4_B4; - break; - case GL_RGB5_A1: - texelSize = 2; - intFormat = MESA_A1_R5_G5_B5; - break; - default: - gl_problem(NULL, "tdfx driver: texbuildimagemap() bad format"); - return GL_FALSE; - } - - _mesa_set_teximage_component_sizes(intFormat, texImage); - - /*printf("teximage:\n");*/ - /* allocate new storage for texture image, if needed */ - if (!mml->data || mml->glideFormat != gldformat || - mml->width != dstWidth || mml->height != dstHeight) { - if (mml->data) - FREE(mml->data); - mml->data = MALLOC(dstWidth * dstHeight * texelSize); - if (!mml->data) - return GL_FALSE; - mml->texelSize = texelSize; - mml->glideFormat = gldformat; - mml->width = dstWidth; - mml->height = dstHeight; - fxTexInvalidate(ctx, texObj); - } - - dstStride = dstWidth * texelSize; - - /* store the texture image */ - if (!_mesa_convert_teximage(intFormat, dstWidth, dstHeight, mml->data, - dstStride, - texImage->Width, texImage->Height, - format, type, pixels, packing)) { - return GL_FALSE; - } - - if (ti->validated && ti->isInTM) { - /*printf("reloadmipmaplevels\n");*/ - fxTMReloadMipMapLevel(fxMesa, texObj, level); - } - else { - /*printf("invalidate2\n");*/ - fxTexInvalidate(ctx,texObj); - } - - *retainInternalCopy = GL_FALSE; - return GL_TRUE; - } - else { - gl_problem(NULL, "fx Driver: unsupported texture in fxDDTexImg()\n"); - return GL_FALSE; - } -} - - -GLboolean fxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - tfxTexInfo *ti; - GLint wscale, hscale, dstStride; - tfxMipMapLevel *mml; - GLboolean result; - - if (target != GL_TEXTURE_2D) - return GL_FALSE; - - if (!texObj->DriverData) - return GL_FALSE; - - ti = fxTMGetTexInfo(texObj); - mml = &ti->mipmapLevel[level]; - - fxTexGetInfo( texImage->Width, texImage->Height, NULL,NULL,NULL,NULL, - NULL,NULL, &wscale, &hscale); - - assert(mml->data); /* must have an existing texture image! */ - - switch (mml->glideFormat) { - case GR_TEXFMT_INTENSITY_8: - dstStride = mml->width; - result = _mesa_convert_texsubimage(MESA_I8, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_ALPHA_8: - dstStride = mml->width; - result = _mesa_convert_texsubimage(MESA_A8, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_P_8: - dstStride = mml->width; - result = _mesa_convert_texsubimage(MESA_C8, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_ALPHA_INTENSITY_88: - dstStride = mml->width * 2; - result = _mesa_convert_texsubimage(MESA_A8_L8, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_RGB_565: - dstStride = mml->width * 2; - result = _mesa_convert_texsubimage(MESA_R5_G6_B5, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_ARGB_4444: - dstStride = mml->width * 2; - result = _mesa_convert_texsubimage(MESA_A4_R4_G4_B4, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_ARGB_8888: - dstStride = mml->width * 4; - result = _mesa_convert_texsubimage(MESA_A8_R8_G8_B8, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - case GR_TEXFMT_ARGB_1555: - dstStride = mml->width * 2; - result = _mesa_convert_texsubimage(MESA_A1_R5_G5_B5, xoffset, yoffset, - mml->width, mml->height, mml->data, - dstStride, width, height, - texImage->Width, texImage->Height, - format, type, pixels, packing); - break; - default: - gl_problem(NULL, "tdfx driver: fxTexBuildSubImageMap() bad format"); - result = GL_FALSE; - } - - if (!result) { - return GL_FALSE; - } - - if (ti->validated && ti->isInTM) - /* Don't use this, it's very broken. Download whole image for now. - fxTMReloadSubMipMapLevel(fxMesa, texObj, level, yoffset, height); - */ - fxTMReloadMipMapLevel(fxMesa, texObj, level); - else - fxTexInvalidate(ctx, texObj); - - return GL_TRUE; -} - - -static void PrintTexture(int w, int h, int c, const GLubyte *data) -{ - int i, j; - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - if (c==2) - printf("%02x %02x ", data[0], data[1]); - else if (c==3) - printf("%02x %02x %02x ", data[0], data[1], data[2]); - data += c; - } - printf("\n"); - } -} - - -GLvoid *fxDDGetTexImage(GLcontext *ctx, GLenum target, GLint level, - const struct gl_texture_object *texObj, - GLenum *formatOut, GLenum *typeOut, - GLboolean *freeImageOut ) -{ - tfxTexInfo *ti; - tfxMipMapLevel *mml; - - if (target != GL_TEXTURE_2D) - return NULL; - - if (!texObj->DriverData) - return NULL; - - ti = fxTMGetTexInfo(texObj); - mml = &ti->mipmapLevel[level]; - if (mml->data) { - MesaIntTexFormat mesaFormat; - GLenum glFormat; - struct gl_texture_image *texImage = texObj->Image[level]; - GLint srcStride; - - GLubyte *data = (GLubyte *) MALLOC(texImage->Width * texImage->Height * 4); - if (!data) - return NULL; - - switch (mml->glideFormat) { - case GR_TEXFMT_INTENSITY_8: - mesaFormat = MESA_I8; - glFormat = GL_INTENSITY; - srcStride = mml->width; - break; - case GR_TEXFMT_ALPHA_INTENSITY_88: - mesaFormat = MESA_A8_L8; - glFormat = GL_LUMINANCE_ALPHA; - srcStride = mml->width; - break; - case GR_TEXFMT_ALPHA_8: - mesaFormat = MESA_A8; - glFormat = GL_ALPHA; - srcStride = mml->width; - break; - case GR_TEXFMT_RGB_565: - mesaFormat = MESA_R5_G6_B5; - glFormat = GL_RGB; - srcStride = mml->width * 2; - break; - case GR_TEXFMT_ARGB_8888: - mesaFormat = MESA_A8_R8_G8_B8; - glFormat = GL_RGBA; - srcStride = mml->width * 4; - break; - case GR_TEXFMT_ARGB_4444: - mesaFormat = MESA_A4_R4_G4_B4; - glFormat = GL_RGBA; - srcStride = mml->width * 2; - break; - case GR_TEXFMT_ARGB_1555: - mesaFormat = MESA_A1_R5_G5_B5; - glFormat = GL_RGBA; - srcStride = mml->width * 2; - break; - case GR_TEXFMT_P_8: - mesaFormat = MESA_C8; - glFormat = GL_COLOR_INDEX; - srcStride = mml->width; - break; - default: - gl_problem(NULL, "Bad glideFormat in fxDDGetTexImage"); - return NULL; - } - _mesa_unconvert_teximage(mesaFormat, mml->width, mml->height, mml->data, - srcStride, texImage->Width, texImage->Height, - glFormat, data); - *formatOut = glFormat; - *typeOut = GL_UNSIGNED_BYTE; - *freeImageOut = GL_TRUE; - return data; - } - else { - return NULL; - } -} - - -#else - - -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_ddtex(void) -{ - return 0; -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxdrv.h b/xc/extras/Mesa/src/FX/fxdrv.h deleted file mode 100644 index eea75fc56..000000000 --- a/xc/extras/Mesa/src/FX/fxdrv.h +++ /dev/null @@ -1,691 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#ifndef FXDRV_H -#define FXDRV_H - -/* If you comment out this define, a variable takes its place, letting - * you turn debugging on/off from the debugger. - */ - -#ifdef XFree86Server -#include "GL/xf86glx.h" -#else -#include "glheader.h" -#endif - - -#if defined(__linux__) -#include <signal.h> -#endif - -#include "context.h" -#include "macros.h" -#include "matrix.h" -#include "mem.h" -#include "texture.h" -#include "types.h" -#include "vb.h" -#include "xform.h" -#include "clip.h" -#include "vbrender.h" - -#ifdef XF86DRI -typedef struct tfxMesaContext *fxMesaContext; -#else -#include "GL/fxmesa.h" -#endif -#include "fxglidew.h" -/* use gl/gl.h GLAPI/GLAPIENTRY/GLCALLBACK in place of WINGDIAPI/APIENTRY/CALLBACK, */ -/* these are defined in mesa gl/gl.h - tjump@spgs.com */ - - - -extern void fx_sanity_triangle( GrVertex *, GrVertex *, GrVertex * ); -#if defined(MESA_DEBUG) && 0 -#define grDrawTriangle fx_sanity_triangle -#endif - - -/* Define some shorter names for these things. - */ -#define XCOORD GR_VERTEX_X_OFFSET -#define YCOORD GR_VERTEX_Y_OFFSET -#define ZCOORD GR_VERTEX_OOZ_OFFSET -#define OOWCOORD GR_VERTEX_OOW_OFFSET - -#define RCOORD GR_VERTEX_R_OFFSET -#define GCOORD GR_VERTEX_G_OFFSET -#define BCOORD GR_VERTEX_B_OFFSET -#define ACOORD GR_VERTEX_A_OFFSET - -#define S0COORD GR_VERTEX_SOW_TMU0_OFFSET -#define T0COORD GR_VERTEX_TOW_TMU0_OFFSET -#define S1COORD GR_VERTEX_SOW_TMU1_OFFSET -#define T1COORD GR_VERTEX_TOW_TMU1_OFFSET - - -#if FX_USE_PARGB - -#define CLIP_XCOORD 0 /* normal place */ -#define CLIP_YCOROD 1 /* normal place */ -#define CLIP_ZCOORD 2 /* normal place */ -#define CLIP_WCOORD 3 /* normal place */ -#define CLIP_GCOORD 4 /* GR_VERTEX_PARGB_OFFSET */ -#define CLIP_BCOORD 5 /* GR_VERTEX_SOW_TMU0_OFFSET */ -#define CLIP_RCOORD 6 /* GR_VERTEX_TOW_TMU0_OFFSET */ -#define CLIP_ACOORD 7 /* GR_VERTEX_OOW_TMU0_OFFSET */ - -#else - -#define CLIP_XCOORD 0 /* normal place */ -#define CLIP_YCOROD 1 /* normal place */ -#define CLIP_ZCOORD 2 /* GR_VERTEX_Z_OFFSET */ -#define CLIP_WCOORD 3 /* GR_VERTEX_R_OFFSET */ -#define CLIP_GCOORD 4 /* normal place */ -#define CLIP_BCOORD 5 /* normal place */ -#define CLIP_RCOORD 6 /* GR_VERTEX_OOZ_OFFSET */ -#define CLIP_ACOORD 7 /* normal place */ - - -#endif - -/* Should have size == 16 * sizeof(float). - */ -typedef struct { - GLfloat f[15]; /* Same layout as GrVertex */ - GLubyte mask; /* Unsued */ - GLubyte usermask; /* Unused */ -} fxVertex; - - - - -#if defined(FXMESA_USE_ARGB) -#define FXCOLOR4( c ) ( \ - ( ((unsigned int)(c[3]))<<24 ) | \ - ( ((unsigned int)(c[0]))<<16 ) | \ - ( ((unsigned int)(c[1]))<<8 ) | \ - ( (unsigned int)(c[2])) ) - -#else -#ifdef __i386__ -#define FXCOLOR4( c ) (* (int *)c) -#else -#define FXCOLOR4( c ) ( \ - ( ((unsigned int)(c[3]))<<24 ) | \ - ( ((unsigned int)(c[2]))<<16 ) | \ - ( ((unsigned int)(c[1]))<<8 ) | \ - ( (unsigned int)(c[0])) ) -#endif -#endif - - -#define FX_VB_COLOR(fxm, color) \ - do { \ - if (sizeof(GLint) == 4*sizeof(GLubyte)) { \ - if (fxm->constColor != *(GLuint*)color) { \ - fxm->constColor = *(GLuint*)color; \ - FX_grConstantColorValue(FXCOLOR4(color)); \ - } \ - } else { \ - FX_grConstantColorValue(FXCOLOR4(color)); \ - } \ - } while (0) - -#define GOURAUD(x) { \ - GLubyte *col = VB->ColorPtr->data[(x)]; \ - gWin[(x)].v.r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \ - gWin[(x)].v.g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \ - gWin[(x)].v.b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \ - gWin[(x)].v.a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \ -} - -#if FX_USE_PARGB -#define GOURAUD2(v, c) { \ - GLubyte *col = c; \ - v->argb=MESACOLOR2PARGB(col); \ -} -#else -#define GOURAUD2(v, c) { \ - GLubyte *col = c; \ - v->r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \ - v->g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \ - v->b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \ - v->a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \ -} -#endif - - -/* Mergable items first - */ -#define SETUP_RGBA 0x1 -#define SETUP_TMU0 0x2 -#define SETUP_TMU1 0x4 -#define SETUP_XY 0x8 -#define SETUP_Z 0x10 -#define SETUP_W 0x20 - -#define MAX_MERGABLE 0x8 - - -#define FX_NUM_TMU 2 - -#define FX_TMU0 GR_TMU0 -#define FX_TMU1 GR_TMU1 -#define FX_TMU_SPLIT 98 -#define FX_TMU_BOTH 99 -#define FX_TMU_NONE 100 - -/* Used for fxMesa->lastUnitsMode */ - -#define FX_UM_NONE 0x00000000 - -#define FX_UM_E0_REPLACE 0x00000001 -#define FX_UM_E0_MODULATE 0x00000002 -#define FX_UM_E0_DECAL 0x00000004 -#define FX_UM_E0_BLEND 0x00000008 -#define FX_UM_E0_ADD 0x00000010 - -#define FX_UM_E1_REPLACE 0x00000020 -#define FX_UM_E1_MODULATE 0x00000040 -#define FX_UM_E1_DECAL 0x00000080 -#define FX_UM_E1_BLEND 0x00000100 -#define FX_UM_E1_ADD 0x00000200 - -#define FX_UM_E_ENVMODE 0x000003ff - -#define FX_UM_E0_ALPHA 0x00001000 -#define FX_UM_E0_LUMINANCE 0x00002000 -#define FX_UM_E0_LUMINANCE_ALPHA 0x00004000 -#define FX_UM_E0_INTENSITY 0x00008000 -#define FX_UM_E0_RGB 0x00010000 -#define FX_UM_E0_RGBA 0x00020000 - -#define FX_UM_E1_ALPHA 0x00040000 -#define FX_UM_E1_LUMINANCE 0x00080000 -#define FX_UM_E1_LUMINANCE_ALPHA 0x00100000 -#define FX_UM_E1_INTENSITY 0x00200000 -#define FX_UM_E1_RGB 0x00400000 -#define FX_UM_E1_RGBA 0x00800000 - -#define FX_UM_E_IFMT 0x00fff000 - -#define FX_UM_COLOR_ITERATED 0x01000000 -#define FX_UM_COLOR_CONSTANT 0x02000000 -#define FX_UM_ALPHA_ITERATED 0x04000000 -#define FX_UM_ALPHA_CONSTANT 0x08000000 - - -#define PACK_BGRA32(R, G, B, A) \ - ( (((GLuint) (R)) << 16) | \ - (((GLuint) (G)) << 8) | \ - (((GLuint) (B)) ) | \ - (((GLuint) (A)) << 24) ) - -#define PACK_RGBA32(R, G, B, A) \ - ( (((GLuint) (R)) ) | \ - (((GLuint) (G)) << 8) | \ - (((GLuint) (B)) << 16) | \ - (((GLuint) (A)) << 24) ) - - -typedef void (*tfxRenderVBFunc)(GLcontext *); - -/* - Memory range from startAddr to endAddr-1 -*/ -typedef struct MemRange_t { - struct MemRange_t *next; - FxU32 startAddr, endAddr; -} MemRange; - -typedef struct { - GLsizei width, height; /* image size */ - GLint texelSize; /* How many bytes to a texel */ - GrTextureFormat_t glideFormat; /* Glide image format */ - unsigned short *data; /* Glide-formated texture image */ -} tfxMipMapLevel; - -typedef struct tfxTexInfo_t { - struct tfxTexInfo *next; - struct gl_texture_object *tObj; - - GLuint lastTimeUsed; - FxU32 whichTMU; - GLboolean isInTM; - - tfxMipMapLevel mipmapLevel[MAX_TEXTURE_LEVELS]; - - MemRange *tm[FX_NUM_TMU]; - - GLint minLevel, maxLevel; - GLint baseLevelInternalFormat; - - GrTexInfo info; - - GrTextureFilterMode_t minFilt; - GrTextureFilterMode_t maxFilt; - FxBool LODblend; - - GrTextureClampMode_t sClamp; - GrTextureClampMode_t tClamp; - - GrMipMapMode_t mmMode; - - GLfloat sScale, tScale; - GLint int_sScale, int_tScale; /* x86 floating point trick for - * multiplication by powers of 2. - * Used in fxfasttmp.h - */ - - GuTexPalette palette; - - GLboolean fixedPalette; - GLboolean validated; -} tfxTexInfo; - -typedef struct { - GLuint swapBuffer; - GLuint reqTexUpload; - GLuint texUpload; - GLuint memTexUpload; -} tfxStats; - - -typedef void (*tfxTriViewClipFunc)( struct vertex_buffer *VB, - GLuint v[], - GLubyte mask ); - -typedef void (*tfxTriClipFunc)( struct vertex_buffer *VB, - GLuint v[], - GLuint mask ); - - -typedef void (*tfxLineClipFunc)( struct vertex_buffer *VB, - GLuint v1, GLuint v2, - GLubyte mask ); - - -extern tfxTriViewClipFunc fxTriViewClipTab[0x8]; -extern tfxTriClipFunc fxTriClipStrideTab[0x8]; -extern tfxLineClipFunc fxLineClipTab[0x8]; - -typedef struct { - /* Alpha test */ - GLboolean alphaTestEnabled; - GrCmpFnc_t alphaTestFunc; - GrAlpha_t alphaTestRefValue; - - /* Blend function */ - GLboolean blendEnabled; - GrAlphaBlendFnc_t blendSrcFuncRGB; - GrAlphaBlendFnc_t blendDstFuncRGB; - GrAlphaBlendFnc_t blendSrcFuncAlpha; - GrAlphaBlendFnc_t blendDstFuncAlpha; -} tfxUnitsState; - - - -/* Flags for render_index. - */ -#define FX_OFFSET 0x1 -#define FX_TWOSIDE 0x2 -#define FX_FRONT_BACK 0x4 -#define FX_FLAT 0x8 -#define FX_ANTIALIAS 0x10 -#define FX_FALLBACK 0x20 - - -/* Flags for fxMesa->new_state - */ -#define FX_NEW_TEXTURING 0x1 -#define FX_NEW_BLEND 0x2 -#define FX_NEW_ALPHA 0x4 -#define FX_NEW_DEPTH 0x8 -#define FX_NEW_FOG 0x10 -#define FX_NEW_SCISSOR 0x20 -#define FX_NEW_COLOR_MASK 0x40 -#define FX_NEW_CULL 0x80 -#define FX_NEW_STENCIL 0x100 - -/* FX struct stored in VB->driver_data. - */ -struct tfxMesaVertexBuffer { - GLvector1ui clipped_elements; - - fxVertex *verts; - fxVertex *last_vert; - void *vert_store; -#if defined(FX_GLIDE3) - GrVertex **triangle_b; /* Triangle buffer */ - GrVertex **strips_b; /* Strips buffer */ -#endif - - GLuint size; -}; - -#define FX_DRIVER_DATA(vb) ((struct tfxMesaVertexBuffer *)((vb)->driver_data)) -#define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx)) -#define FX_TEXTURE_DATA(t) fxTMGetTexInfo((t)->Current) - -#if defined(XFree86Server) || defined(GLX_DIRECT_RENDERING) -#include "tdfx_init.h" -#else -#define DRI_FX_CONTEXT -#define BEGIN_BOARD_LOCK() -#define END_BOARD_LOCK() -#define BEGIN_CLIP_LOOP() -#define END_CLIP_LOOP() -#endif - - -/* These lookup table are used to extract RGB values in [0,255] from - * 16-bit pixel values. - */ -extern GLubyte FX_PixelToR[0x10000]; -extern GLubyte FX_PixelToG[0x10000]; -extern GLubyte FX_PixelToB[0x10000]; - - -struct tfxMesaContext { - GLcontext *glCtx; /* the core Mesa context */ - GLvisual *glVis; /* describes the color buffer */ - GLframebuffer *glBuffer; /* the ancillary buffers */ - - GLint board; /* the board used for this context */ - GLint width, height; /* size of color buffer */ - - GrBuffer_t currentFB; - - GLboolean bgrOrder; - GLuint depthClear; - GrColor_t color; - GrColor_t clearC; - GrAlpha_t clearA; - GLuint constColor; - GrCullMode_t cullMode; - - tfxUnitsState unitsState; - tfxUnitsState restoreUnitsState; /* saved during multipass */ - - GuTexPalette glbPalette; - - GLuint tmu_source[FX_NUM_TMU]; - GLuint tex_dest[MAX_TEXTURE_UNITS]; - GLuint setupindex; - GLuint partial_setup_index; - GLuint setupdone; - GLuint mergeindex; - GLuint mergeinputs; - GLuint render_index; - GLuint last_tri_caps; - GLuint stw_hint_state; /* for grHints */ - GLuint is_in_hardware; - GLuint new_state; - GLuint using_fast_path, passes, multipass; - - tfxLineClipFunc clip_line; - tfxTriClipFunc clip_tri_stride; - tfxTriViewClipFunc view_clip_tri; - - - /* Texture Memory Manager Data */ - - GLuint texBindNumber; - GLint tmuSrc; - GLuint freeTexMem[FX_NUM_TMU]; - MemRange *tmPool; - MemRange *tmFree[FX_NUM_TMU]; - - GLenum fogTableMode; - GLfloat fogDensity; - GLfloat fogStart, fogEnd; - GrFog_t *fogTable; - GLint textureAlign; - - /* Acc. functions */ - - points_func PointsFunc; - line_func LineFunc; - triangle_func TriangleFunc; - quad_func QuadFunc; - - render_func **RenderVBTables; - - render_func *RenderVBClippedTab; - render_func *RenderVBCulledTab; - render_func *RenderVBRawTab; - - - tfxStats stats; - - void *state; - - /* Options */ - - GLboolean verbose; - GLboolean haveTwoTMUs; /* True if we really have 2 tmu's */ - GLboolean emulateTwoTMUs; /* True if we present 2 tmu's to mesa. */ - GLboolean haveAlphaBuffer; - GLboolean haveHwStencil; - GLboolean haveGlobalPaletteTexture; - GLint swapInterval; - GLint maxPendingSwapBuffers; - - FX_GrContext_t glideContext; - - int x_offset; - int y_offset; - int y_delta; - int screen_width; - int screen_height; - int initDone; - int clipMinX; - int clipMaxX; - int clipMinY; - int clipMaxY; - int needClip; - - DRI_FX_CONTEXT -}; - -typedef void (*tfxSetupFunc)(struct vertex_buffer *, GLuint, GLuint); - -extern GrHwConfiguration glbHWConfig; -extern int glbCurrentBoard; - -extern void fxPrintSetupFlags( const char *msg, GLuint flags ); -extern void fxSetupFXUnits(GLcontext *); -extern void fxSetupDDPointers(GLcontext *); -extern void fxDDSetNearFar(GLcontext *, GLfloat, GLfloat); - -extern void fxDDSetupInit(void); -extern void fxDDCvaInit(void); -extern void fxDDTrifuncInit(void); -extern void fxDDFastPathInit(void); - -extern void fxDDChooseRenderState( GLcontext *ctx ); - -extern void fxRenderClippedLine( struct vertex_buffer *VB, - GLuint v1, GLuint v2 ); - -extern void fxRenderClippedTriangle( struct vertex_buffer *VB, - GLuint n, GLuint vlist[] ); - - -extern tfxSetupFunc fxDDChooseSetupFunction(GLcontext *); - -extern points_func fxDDChoosePointsFunction(GLcontext *); -extern line_func fxDDChooseLineFunction(GLcontext *); -extern triangle_func fxDDChooseTriangleFunction(GLcontext *); -extern quad_func fxDDChooseQuadFunction(GLcontext *); -extern render_func **fxDDChooseRenderVBTables(GLcontext *); - -extern void fxDDRenderInit(GLcontext *); -extern void fxDDClipInit(void); - -extern void fxUpdateDDSpanPointers(GLcontext *); -extern void fxSetupDDSpanPointers(GLcontext *); - -extern void fxPrintTextureData(tfxTexInfo *ti); -extern GLboolean fxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLboolean *retainInternalCopy); -extern GLboolean fxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); -extern GLvoid *fxDDGetTexImage(GLcontext *ctx, GLenum target, GLint level, - const struct gl_texture_object *texObj, - GLenum *formatOut, GLenum *typeOut, - GLboolean *freeImageOut ); -extern void fxDDTexEnv(GLcontext *, GLenum, GLenum, const GLfloat *); -extern void fxDDTexParam(GLcontext *, GLenum, struct gl_texture_object *, - GLenum, const GLfloat *); -extern void fxDDTexBind(GLcontext *, GLenum, struct gl_texture_object *); -extern void fxDDTexDel(GLcontext *, struct gl_texture_object *); -extern void fxDDTexPalette(GLcontext *, struct gl_texture_object *); -extern void fxDDTexUseGlbPalette(GLcontext *, GLboolean); - -extern void fxDDEnable(GLcontext *, GLenum, GLboolean); -extern void fxDDAlphaFunc(GLcontext *, GLenum, GLclampf); -extern void fxDDBlendFunc(GLcontext *, GLenum, GLenum); - -extern void fxDDRegisterVB( struct vertex_buffer *VB ); -extern void fxDDUnregisterVB( struct vertex_buffer *VB ); -extern void fxDDResizeVB( struct vertex_buffer *VB, GLuint size ); - -extern void fxDDCheckMergeAndRender( GLcontext *ctx, - struct gl_pipeline_stage *d ); - -extern void fxDDMergeAndRender( struct vertex_buffer *VB ); - -extern void fxDDCheckPartialRasterSetup( GLcontext *ctx, - struct gl_pipeline_stage *d ); - -extern void fxDDPartialRasterSetup( struct vertex_buffer *VB ); - -extern void fxDDDoRasterSetup( struct vertex_buffer *VB ); - -extern GLuint fxDDRegisterPipelineStages( struct gl_pipeline_stage *out, - const struct gl_pipeline_stage *in, - GLuint nr ); - -extern GLboolean fxDDBuildPrecalcPipeline( GLcontext *ctx ); - -extern void fxDDOptimizePrecalcPipeline( GLcontext *ctx, - struct gl_pipeline *pipe ); - -extern void fxDDRenderElementsDirect( struct vertex_buffer *VB ); -extern void fxDDRenderVBIndirectDirect( struct vertex_buffer *VB ); - -extern void fxDDInitExtensions( GLcontext *ctx ); - -#define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData)) -extern void fxTMInit(fxMesaContext ctx); -extern void fxTMClose(fxMesaContext ctx); -extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx); -extern void fxTMMoveInTM(fxMesaContext, struct gl_texture_object *, GLint); -extern void fxTMMoveOutTM(fxMesaContext, struct gl_texture_object *); -#define fxTMMoveOutTM_NoLock fxTMMoveOutTM -extern void fxTMFreeTexture(fxMesaContext, struct gl_texture_object *); -extern void fxTMReloadMipMapLevel(fxMesaContext, struct gl_texture_object *, GLint); -extern void fxTMReloadSubMipMapLevel(fxMesaContext, struct gl_texture_object *, - GLint, GLint, GLint); - -extern void fxTexGetFormat(GLenum, GrTextureFormat_t *, GLint *); -extern int fxTexGetInfo(int, int, GrLOD_t *, GrAspectRatio_t *, - float *, float *, int *, int *, int *, int *); - -extern void fxDDScissor( GLcontext *ctx, - GLint x, GLint y, GLsizei w, GLsizei h ); -extern void fxDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *params ); -extern GLboolean fxDDColorMask(GLcontext *ctx, - GLboolean r, GLboolean g, - GLboolean b, GLboolean a ); - -extern void fxDDWriteDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth depth[], const GLubyte mask[]); - -extern void fxDDReadDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y, - GLdepth depth[]); - -extern void fxDDWriteDepthPixels(GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - const GLdepth depth[], const GLubyte mask[]); - -extern void fxDDReadDepthPixels(GLcontext *ctx, GLuint n, - const GLint x[], const GLint y[], - GLdepth depth[]); - -extern void fxDDFastPath( struct vertex_buffer *VB ); - -extern void fxDDShadeModel(GLcontext *ctx, GLenum mode); - -extern void fxDDCullFace(GLcontext *ctx, GLenum mode); -extern void fxDDFrontFace(GLcontext *ctx, GLenum mode); - -extern void fxPrintRenderState( const char *msg, GLuint state ); -extern void fxPrintHintState( const char *msg, GLuint state ); - -extern void fxDDDoRenderVB( struct vertex_buffer *VB ); - -extern int fxDDInitFxMesaContext( fxMesaContext fxMesa ); - - -extern void fxSetScissorValues(GLcontext *ctx); -extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa, - struct gl_texture_object *tObj, - GLint where); -extern void fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder); - -#endif diff --git a/xc/extras/Mesa/src/FX/fxfasttmp.h b/xc/extras/Mesa/src/FX/fxfasttmp.h deleted file mode 100644 index f97b8108f..000000000 --- a/xc/extras/Mesa/src/FX/fxfasttmp.h +++ /dev/null @@ -1,367 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* Build clip space vertices from object space data. - */ -static void TAG(fx_setup_full)( struct vertex_buffer *VB, GLuint do_clip ) -{ - GLcontext *ctx = VB->ctx; - GLfloat *f = (GLfloat *) FX_DRIVER_DATA(VB)->verts; - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - GLuint count = VB->Count; - GLuint i; - - const GLfloat * const m = ctx->ModelProjectMatrix.m; - -#if (TYPE & SETUP_RGBA) - GLubyte *color = (GLubyte *)VB->ColorPtr->data; - GLuint color_stride = VB->ColorPtr->stride; -#endif - -#if (TYPE & SETUP_TMU0) - GLuint tmu0_source = fxMesa->tmu_source[0]; - struct gl_texture_unit *t0 = &ctx->Texture.Unit[tmu0_source]; - GLint s0scale = FX_TEXTURE_DATA(t0)->int_sScale; - GLint t0scale = FX_TEXTURE_DATA(t0)->int_tScale; - GLint *tmu0_int_data = (GLint *)VB->TexCoordPtr[tmu0_source]->data; - GLuint tmu0_stride = VB->TexCoordPtr[tmu0_source]->stride; -#endif - -#if (TYPE & SETUP_TMU1) - GLuint tmu1_source = fxMesa->tmu_source[1]; - struct gl_texture_unit *t1 = &ctx->Texture.Unit[tmu1_source]; - GLint s1scale = FX_TEXTURE_DATA(t1)->int_sScale; - GLint t1scale = FX_TEXTURE_DATA(t1)->int_tScale; - GLint *tmu1_int_data = (GLint *)VB->TexCoordPtr[tmu1_source]->data; - GLuint tmu1_stride = VB->TexCoordPtr[tmu1_source]->stride; -#endif - - (void) fxMesa; - (void) ctx; - (void) i; - (void) f; - - /* Use 3 seperate loops because it's easier for assembly. A - * best-case solution might be to do all three in a single assembly - * loop. - */ - gl_xform_points3_v16_general(FX_DRIVER_DATA(VB)->verts[0].f, - m, - VB->ObjPtr->start, - VB->ObjPtr->stride, - count); - - if (do_clip) - { - VB->ClipAndMask = ~0; - VB->ClipOrMask = 0; - gl_cliptest_points4_v16(FX_DRIVER_DATA(VB)->verts[0].f, - FX_DRIVER_DATA(VB)->verts[count].f, - &(VB->ClipOrMask), - &(VB->ClipAndMask), - VB->ClipMask); - } - - -#if (TYPE) - for (i = 0 ; i < count ; i++, f += 16) { -#if (TYPE & SETUP_RGBA) - GLubyte *col = color; color += color_stride; - UBYTE_COLOR_TO_FLOAT_255_COLOR2( f[CLIP_R], col[0] ); - UBYTE_COLOR_TO_FLOAT_255_COLOR2( f[CLIP_G], col[1] ); - UBYTE_COLOR_TO_FLOAT_255_COLOR2( f[CLIP_B], col[2] ); - UBYTE_COLOR_TO_FLOAT_255_COLOR2( f[CLIP_A], col[3] ); -#endif -#if (TYPE & SETUP_TMU0) - * (int *) &f[CLIP_S0] = s0scale + tmu0_int_data[0]; - * (int *) &f[CLIP_T0] = t0scale + tmu0_int_data[1]; - STRIDE_T(tmu0_int_data, GLint, tmu0_stride); -#endif -#if (TYPE & SETUP_TMU1) - * (int *) &f[CLIP_S1] = s1scale + tmu1_int_data[0]; - * (int *) &f[CLIP_T1] = t1scale + tmu1_int_data[1]; - STRIDE_T(tmu1_int_data, GLint, tmu1_stride); -#endif - } -#endif - - FX_DRIVER_DATA(VB)->last_vert = &(FX_DRIVER_DATA(VB)->verts[count]); -} - - -/* Do viewport map, device scale and perspective projection. - * - * Rearrange fxVertices to look like grVertices. - */ -static void TAG(fx_project_vertices)( GLfloat *first, - GLfloat *last, - const GLfloat *mat, - GLuint stride ) -{ - GLfloat *f; - VARS_XYZ; - - for ( f = first ; f != last ; STRIDE_F(f, stride)) - { - GLfloat oow = 1.0f/f[CLIP_WCOORD]; /* urp! */ - -#if FX_USE_PARGB - if (TYPE & SETUP_RGBA) { - PACK_4F_ARGB(GET_PARGB(f),f[CLIP_A],f[CLIP_R],f[CLIP_G],f[CLIP_B]); - } -#else - if (TYPE & SETUP_RGBA) { - f[RCOORD]=f[CLIP_R]; - } -#endif - if (TYPE & SETUP_TMU1) { - f[S1COORD] = f[CLIP_S1] * oow; - f[T1COORD] = f[CLIP_T1] * oow; - } - - if (TYPE & SETUP_TMU0) { - f[T0COORD] = f[CLIP_T0] * oow; - f[S0COORD] = f[CLIP_S0] * oow; - } - - DO_SETUP_XYZ; - - f[OOWCOORD] = oow; - } -} - -static void TAG(fx_project_clipped_vertices)( GLfloat *first, - GLfloat *last, - const GLfloat *mat, - GLuint stride, - const GLubyte *mask ) -{ - GLfloat *f; - VARS_XYZ; - - for ( f = first ; f != last ; STRIDE_F(f, stride), mask++) { - if (!*mask) { - - GLfloat oow = 1.0f / f[CLIP_WCOORD]; -#if FX_USE_PARGB - if (TYPE & SETUP_RGBA) { - const GLuint r = f[CLIP_R]; - const GLuint g = f[CLIP_G]; - const GLuint b = f[CLIP_B]; - const GLuint a = f[CLIP_A]; - /* ToDo Optimize */ - GET_PARGB(f) = a << 24 | r << 16 | g << 8 | b; - } -#else - if (TYPE & SETUP_RGBA) { - f[RCOORD]=f[CLIP_R]; - } -#endif - - if (TYPE & SETUP_TMU1) { - f[S1COORD] = f[CLIP_S1] * oow; - f[T1COORD] = f[CLIP_T1] * oow; - } - - if (TYPE & SETUP_TMU0) { - f[T0COORD] = f[CLIP_T0] * oow; - f[S0COORD] = f[CLIP_S0] * oow; - } - - DO_SETUP_XYZ; - - f[OOWCOORD] = oow; - } - } -} - - -static -#if (SIZE <= 8) -INLINE -#endif -void TAG(fx_tri_clip)( GLuint **p_elts, - fxVertex *verts, - GLubyte *clipmask, - GLuint *p_next_vert, - GLubyte mask ) -{ - GLuint *elts = *p_elts; - GLuint next_vert = *p_next_vert; - GLuint vlist1[VB_MAX_CLIPPED_VERTS]; - GLuint vlist2[VB_MAX_CLIPPED_VERTS]; - GLuint *inlist[2]; - GLuint *out; - GLuint in = 0; - GLuint n = 3; - GLuint i; - - inlist[0] = elts; - inlist[1] = vlist2; - - CLIP(-,0,CLIP_RIGHT_BIT); - CLIP(+,0,CLIP_LEFT_BIT); - CLIP(-,1,CLIP_TOP_BIT); - CLIP(+,1,CLIP_BOTTOM_BIT); - CLIP(-,2,CLIP_FAR_BIT); - CLIP(+,2,CLIP_NEAR_BIT); - - /* Convert the planar polygon to a list of triangles. - */ - out = inlist[in]; - - for (i = 2 ; i < n ; i++) { - elts[0] = out[0]; - elts[1] = out[i-1]; - elts[2] = out[i]; - elts += 3; - } - - *p_next_vert = next_vert; - *p_elts = elts; -} - - -static INLINE void TAG(fx_line_clip)( GLuint **p_elts, - fxVertex *verts, - GLubyte *clipmask, - GLuint *p_next_vert, - GLubyte mask ) -{ - GLuint *elts = *p_elts; - GLfloat *I = verts[elts[0]].f; - GLfloat *J = verts[elts[1]].f; - GLuint next_vert = *p_next_vert; - - LINE_CLIP(1,0,0,-1,CLIP_LEFT_BIT); - LINE_CLIP(-1,0,0,1,CLIP_RIGHT_BIT); - LINE_CLIP(0,1,0,-1,CLIP_TOP_BIT); - LINE_CLIP(0,-1,0,1,CLIP_BOTTOM_BIT); - LINE_CLIP(0,0,1,-1,CLIP_FAR_BIT); - LINE_CLIP(0,0,-1,1,CLIP_NEAR_BIT); - - *p_next_vert = next_vert; - *p_elts += 2; -} - - -/* Build a table of functions to clip each primitive type. - */ -#define LOCAL_VARS \ - GLuint *elt = VB->EltPtr->data; \ - fxVertex *verts = FX_DRIVER_DATA(VB)->verts; \ - GLuint next_vert = VB->Count; \ - GLuint *out = FX_DRIVER_DATA(VB)->clipped_elements.data; \ - GLubyte *mask = VB->ClipMask; \ - - -#define POSTFIX \ - FX_DRIVER_DATA(VB)->clipped_elements.count = \ - out - FX_DRIVER_DATA(VB)->clipped_elements.data; \ - FX_DRIVER_DATA(VB)->last_vert = &verts[next_vert]; - -#define INIT(x) - -#define RENDER_POINTS(start, count) \ -do { \ - GLuint i; \ - for (i = start ; i < count ; i++ ) \ - CLIP_POINT( elt[i] ); \ -} while (0) - -#define RENDER_LINE(i1, i0) \ - CLIP_LINE(elt[i1], elt[i0]) - -#define RENDER_TRI(i2, i1, i0, pv, parroty) \ -do { \ - GLuint e2 = elt[i2], e1 = elt[i1], e0 = elt[i0]; \ - if (parroty) e2 = elt[i1], e1 = elt[i2]; \ - CLIP_TRIANGLE( e2, e1, e0 ); \ -} while (0) - -#define RENDER_QUAD(i3, i2, i1, i0, pv) \ - CLIP_TRIANGLE(elt[i3], elt[i2], elt[i0]); \ - CLIP_TRIANGLE(elt[i2], elt[i1], elt[i0]) - -#define PRESERVE_TAG -#include "render_tmp.h" - - -static void TAG(fx_init_fastpath)( struct fx_fast_tab *tab ) -{ - GLuint i; - - /* Use the render templates to do clipping. - */ - TAG(render_init)(); - for (i = 0 ; i < GL_POLYGON+2 ; i++) - tab->clip[i] = TAG(render_tab)[i]; - - tab->build_vertices = TAG(fx_setup_full); - tab->project_vertices = TAG(fx_project_vertices); - tab->project_clipped_vertices = TAG(fx_project_clipped_vertices); - -#if defined(USE_3DNOW_ASM) - if (gl_x86_cpu_features & GL_CPU_3Dnow) { - extern void TAG(fx_3dnow_project_vertices)( GLfloat *first, - GLfloat *last, - const GLfloat *mat, - GLuint stride ); - - extern void TAG(fx_3dnow_project_clipped_vertices)( GLfloat *first, - GLfloat *last, - const GLfloat *mat, - GLuint stride, - const GLubyte *mask ); - - tab->project_vertices = TAG(fx_3dnow_project_vertices); - tab->project_clipped_vertices = TAG(fx_3dnow_project_clipped_vertices); - } -#endif -} - -#undef TYPE -#undef TAG -#undef SIZE diff --git a/xc/extras/Mesa/src/FX/fxglidew.c b/xc/extras/Mesa/src/FX/fxglidew.c deleted file mode 100644 index f01644a60..000000000 --- a/xc/extras/Mesa/src/FX/fxglidew.c +++ /dev/null @@ -1,466 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) -#include "glide.h" -#include "fxglidew.h" -#include "fxdrv.h" - -#include <stdlib.h> -#include <string.h> - - -grStencilFunc_t grStencilFuncPtr = NULL; -grStencilMask_t grStencilMaskPtr = NULL; -grStencilOp_t grStencilOpPtr = NULL; -grBufferClearExt_t grBufferClearExtPtr = NULL; - - -FxI32 FX_grGetInteger_NoLock(FxU32 pname) -{ -#if !defined(FX_GLIDE3) - switch (pname) - { - case FX_FOG_TABLE_ENTRIES: - return GR_FOG_TABLE_SIZE; - case FX_GLIDE_STATE_SIZE: - return sizeof(GrState); - case FX_LFB_PIXEL_PIPE: - return FXFALSE; - case FX_PENDING_BUFFERSWAPS: - return grBufferNumPending(); - case FX_TEXTURE_ALIGN: - /* This is a guess from reading the glide3 docs */ - return 8; - case FX_ZDEPTH_MAX: - return 0xFFFF; - default: - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"Wrong parameter in FX_grGetInteger!\n"); - } - return -1; - } -#else - FxU32 grname; - FxI32 result; - - switch (pname) - { - case FX_FOG_TABLE_ENTRIES: - case FX_GLIDE_STATE_SIZE: - case FX_LFB_PIXEL_PIPE: - case FX_PENDING_BUFFERSWAPS: - case FX_TEXTURE_ALIGN: - grname = pname; - break; - case FX_ZDEPTH_MAX: { - int zvals[2]; - - grGet(GR_ZDEPTH_MIN_MAX, 8, zvals); - return zvals[0]; - } - default: - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"Wrong parameter in FX_grGetInteger!\n"); - } - return -1; - } - - grGet(grname,4,&result); - return result; -#endif -} - -FxI32 FX_grGetInteger(FxU32 pname) -{ - int result; - - BEGIN_BOARD_LOCK(); - result=FX_grGetInteger_NoLock(pname); - END_BOARD_LOCK(); - return result; -} - - -FxBool FX_grLfbLock(GrLock_t type, GrBuffer_t buffer, - GrLfbWriteMode_t writeMode, GrOriginLocation_t origin, - FxBool pixelPipeline, GrLfbInfo_t *info ) { - FxBool result; - - BEGIN_BOARD_LOCK(); - result=grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info); - END_BOARD_LOCK(); - return result; -} - -FxU32 FX_grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo *info) { - FxU32 result; - - BEGIN_BOARD_LOCK(); - result=grTexTextureMemRequired(evenOdd, info); - END_BOARD_LOCK(); - return result; -} - -FxU32 FX_grTexMinAddress(GrChipID_t tmu) { - FxU32 result; - - BEGIN_BOARD_LOCK(); - result=grTexMinAddress(tmu); - END_BOARD_LOCK(); - return result; -} - -extern FxU32 FX_grTexMaxAddress(GrChipID_t tmu) { - FxU32 result; - - BEGIN_BOARD_LOCK(); - result=grTexMaxAddress(tmu); - END_BOARD_LOCK(); - return result; -} - -FxBool FX_grSstControl(FxU32 code) -{ -#if defined(FX_GLIDE3) - /* The glide 3 sources call for grEnable/grDisable to be called in exchange - * for grSstControl. */ - switch(code) { - case GR_CONTROL_ACTIVATE: - grEnable(GR_PASSTHRU); - break; - case GR_CONTROL_DEACTIVATE: - grDisable(GR_PASSTHRU); - break; - } - /* Appearently GR_CONTROL_RESIZE can be ignored. */ - return 1; /* OK? */ -#else - FxU32 result; - BEGIN_BOARD_LOCK(); - result = grSstControl(code); - END_BOARD_LOCK(); - return result; -#endif -} - - -#if defined(FX_GLIDE3) - -void FX_grGammaCorrectionValue(float val) -{ - (void)val; -/* ToDo */ -} - -int FX_getFogTableSize(void) -{ - int result; - BEGIN_BOARD_LOCK(); - grGet(GR_FOG_TABLE_ENTRIES,sizeof(int),(void*)&result); - END_BOARD_LOCK(); - return result; -} - -int FX_getGrStateSize(void) -{ - int result; - BEGIN_BOARD_LOCK(); - grGet(GR_GLIDE_STATE_SIZE,sizeof(int),(void*)&result); - END_BOARD_LOCK(); - - return result; - -} - -int FX_grSstScreenWidth() -{ - FxI32 result[4]; - - BEGIN_BOARD_LOCK(); - grGet(GR_VIEWPORT,sizeof(FxI32)*4,result); - END_BOARD_LOCK(); - - return result[2]; -} - -int FX_grSstScreenHeight() -{ - FxI32 result[4]; - - BEGIN_BOARD_LOCK(); - grGet(GR_VIEWPORT,sizeof(FxI32)*4,result); - END_BOARD_LOCK(); - - return result[3]; -} - -void FX_grGlideGetVersion(char *buf) -{ - BEGIN_BOARD_LOCK(); - strcpy(buf,grGetString(GR_VERSION)); - END_BOARD_LOCK(); -} - -void FX_grSstPerfStats(GrSstPerfStats_t *st) -{ - FxI32 n; - grGet(GR_STATS_PIXELS_IN, 4, &n); st->pixelsIn = n; - grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n); st->chromaFail = n; - grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n); st->zFuncFail = n; - grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n); st->aFuncFail = n; - grGet(GR_STATS_PIXELS_OUT, 4, &n); st->pixelsOut = n; -} - -void FX_grAADrawLine(GrVertex *a,GrVertex *b) -{ - /* ToDo */ - BEGIN_CLIP_LOOP(); - grDrawLine(a,b); - END_CLIP_LOOP(); -} - -void FX_grAADrawPoint(GrVertex *a) -{ - BEGIN_CLIP_LOOP(); - grDrawPoint(a); - END_CLIP_LOOP(); -} - -void FX_grDrawPolygonVertexList(int n, GrVertex *verts) -{ - BEGIN_CLIP_LOOP(); - grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex)); - END_CLIP_LOOP(); -} - -#if FX_USE_PARGB -void FX_setupGrVertexLayout(void) -{ - BEGIN_BOARD_LOCK(); - grReset(GR_VERTEX_PARAMETER); - - grCoordinateSpace(GR_WINDOW_COORDS); - grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_PARGB, GR_VERTEX_PARGB_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE); - grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); - grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); - END_BOARD_LOCK(); -} -#else /* FX_USE_PARGB */ -void FX_setupGrVertexLayout(void) -{ - BEGIN_BOARD_LOCK(); - grReset(GR_VERTEX_PARAMETER); - - grCoordinateSpace(GR_WINDOW_COORDS); - grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE); - grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE); - grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); - grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); - END_BOARD_LOCK(); -} -#endif - -void FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask) -{ - switch(hintType) { - case GR_HINT_STWHINT: - { - if (hintMask & GR_STWHINT_W_DIFF_TMU0) - grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE); - else - grVertexLayout(GR_PARAM_Q0,GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE); - - if (hintMask & GR_STWHINT_ST_DIFF_TMU1) - grVertexLayout(GR_PARAM_ST1,GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE); - else - grVertexLayout(GR_PARAM_ST1,GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); - - if (hintMask & GR_STWHINT_W_DIFF_TMU1) - grVertexLayout(GR_PARAM_Q1,GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE); - else - grVertexLayout(GR_PARAM_Q1,GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); - - } - } -} - -void FX_grHints(GrHint_t hintType, FxU32 hintMask) { - BEGIN_BOARD_LOCK(); - FX_grHints_NoLock(hintType, hintMask); - END_BOARD_LOCK(); -} - -int FX_grSstQueryHardware(GrHwConfiguration *config) -{ - int i,j; - int numFB; - - BEGIN_BOARD_LOCK(); - grGet(GR_NUM_BOARDS,4,(void*)&(config->num_sst)); - if (config->num_sst == 0) - return 0; - for (i = 0; i< config->num_sst; i++) - { - config->SSTs[i].type = GR_SSTTYPE_VOODOO; - grSstSelect(i); - grGet(GR_MEMORY_FB,4,(void*)&(config->SSTs[i].sstBoard.VoodooConfig.fbRam)); - config->SSTs[i].sstBoard.VoodooConfig.fbRam/= 1024*1024; - - grGet(GR_NUM_TMU,4,(void*)&(config->SSTs[i].sstBoard.VoodooConfig.nTexelfx)); - - - grGet(GR_NUM_FB,4,(void*)&numFB); - if (numFB > 1) - config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXTRUE; - else - config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXFALSE; - for (j = 0; j < config->SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++) - { - grGet(GR_MEMORY_TMU,4,(void*)&(config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam)); - config->SSTs[i].sstBoard.VoodooConfig.tmuConfig[j].tmuRam /= 1024*1024; - } - } - END_BOARD_LOCK(); - return 1; -} - -#else - -int FX_grSstScreenWidth() -{ - int i; - BEGIN_BOARD_LOCK(); - i = grSstScreenWidth(); - END_BOARD_LOCK(); - return i; -} - -int FX_grSstScreenHeight() -{ - int i; - BEGIN_BOARD_LOCK(); - i = grSstScreenHeight(); - END_BOARD_LOCK(); - return i; -} - -int FX_grSstQueryHardware(GrHwConfiguration *c) -{ - int i; - BEGIN_BOARD_LOCK(); - i = grSstQueryHardware(c); - END_BOARD_LOCK(); - return i; -} - - -#endif /* FX_GLIDE3 */ - -/* It appears to me that this function is needed either way. */ -FX_GrContext_t FX_grSstWinOpen( FxU32 hWnd, - GrScreenResolution_t screen_resolution, - GrScreenRefresh_t refresh_rate, - GrColorFormat_t color_format, - GrOriginLocation_t origin_location, - int nColBuffers, - int nAuxBuffers) -{ - FX_GrContext_t i; - BEGIN_BOARD_LOCK(); - i = grSstWinOpen( hWnd, - screen_resolution, - refresh_rate, - color_format, - origin_location, - nColBuffers, - nAuxBuffers ); - - /* - fprintf(stderr, - "grSstWinOpen( win %d res %d ref %d fmt %d\n" - " org %d ncol %d naux %d )\n" - " ==> %d\n", - hWnd, - screen_resolution, - refresh_rate, - color_format, - origin_location, - nColBuffers, - nAuxBuffers, - i); - */ - END_BOARD_LOCK(); - return i; -} - - - -#else - -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_glidew(void) -{ - return 0; -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxglidew.h b/xc/extras/Mesa/src/FX/fxglidew.h deleted file mode 100644 index 4ad2942af..000000000 --- a/xc/extras/Mesa/src/FX/fxglidew.h +++ /dev/null @@ -1,938 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#ifndef __FX_GLIDE_WARPER__ -#define __FX_GLIDE_WARPER__ - -#include <glide.h> -#include <g3ext.h> - -/* - * These are glide extension definitions. These are not - * defined in glide.h. They should really be defined in - * g3ext.h, but they are not. - */ -#if 0 -FX_ENTRY void FX_CALL -grStencilFunc(GrCmpFnc_t fnc, GrStencil_t ref, GrStencil_t mask); - -FX_ENTRY void FX_CALL -grStencilMask(GrStencil_t write_mask); - -FX_ENTRY void FX_CALL -grStencilOp( - GrStencilOp_t stencil_fail, - GrStencilOp_t depth_fail, - GrStencilOp_t depth_pass); - -FX_ENTRY void FX_CALL -grBufferClearExt( - GrColor_t color, - GrAlpha_t alpha, - FxU32 depth, - GrStencil_t stencil); -#endif - - -typedef void (*grStencilFunc_t)(GrCmpFnc_t fnc, GrStencil_t ref, GrStencil_t mask); -typedef void (*grStencilMask_t)(GrStencil_t write_mask); -typedef void (*grStencilOp_t)(GrStencilOp_t stencil_fail, GrStencilOp_t depth_fail, GrStencilOp_t depth_pass); -typedef void (*grBufferClearExt_t)(GrColor_t color, GrAlpha_t alpha, FxU32 depth, GrStencil_t stencil); - -extern grStencilFunc_t grStencilFuncPtr; -extern grStencilMask_t grStencilMaskPtr; -extern grStencilOp_t grStencilOpPtr; -extern grBufferClearExt_t grBufferClearExtPtr; - - -FX_ENTRY void FX_CALL -grEnable(GrEnableMode_t mode); - -FX_ENTRY void FX_CALL -grEnable(GrEnableMode_t mode); -/* - * General context: - */ -#if !defined(FX_GLIDE3) - typedef FxU32 FX_GrContext_t; /* Not used in Glide2 */ -#else - typedef GrContext_t FX_GrContext_t; -#endif - -/* - * Glide3 emulation on Glide2: - */ -#if !defined(FX_GLIDE3) - /* Constanst for FX_grGetInteger( ) */ - #define FX_FOG_TABLE_ENTRIES 0x0004 /* The number of entries in the hardware fog table. */ - #define FX_GLIDE_STATE_SIZE 0x0006 /* Size of buffer, in bytes, needed to save Glide state. */ - #define FX_LFB_PIXEL_PIPE 0x0009 /* 1 if LFB writes can go through the 3D pixel pipe. */ - #define FX_PENDING_BUFFERSWAPS 0x0014 /* The number of buffer swaps pending. */ - #define FX_TEXTURE_ALIGN 0x0024 /* The required alignment for textures */ -#else - #define FX_FOG_TABLE_ENTRIES GR_FOG_TABLE_ENTRIES - #define FX_GLIDE_STATE_SIZE GR_GLIDE_STATE_SIZE - #define FX_LFB_PIXEL_PIPE GR_LFB_PIXEL_PIPE - #define FX_PENDING_BUFFERSWAPS GR_PENDING_BUFFERSWAPS - #define FX_TEXTURE_ALIGN GR_TEXTURE_ALIGN -#endif -#define FX_ZDEPTH_MAX 0x100 - -/* - * Genral warper functions for Glide2/Glide3: - */ -extern FxI32 FX_grGetInteger_NoLock(FxU32 pname); -extern FxI32 FX_grGetInteger(FxU32 pname); - -/* - * Glide2 emulation on Glide3: - */ -#if defined(FX_GLIDE3) - -#define GR_ASPECT_1x1 GR_ASPECT_LOG2_1x1 -#define GR_ASPECT_2x1 GR_ASPECT_LOG2_2x1 -#define GR_ASPECT_4x1 GR_ASPECT_LOG2_4x1 -#define GR_ASPECT_8x1 GR_ASPECT_LOG2_8x1 -#define GR_ASPECT_1x2 GR_ASPECT_LOG2_1x2 -#define GR_ASPECT_1x4 GR_ASPECT_LOG2_1x4 -#define GR_ASPECT_1x8 GR_ASPECT_LOG2_1x8 - -#define GR_LOD_256 GR_LOD_LOG2_256 -#define GR_LOD_128 GR_LOD_LOG2_128 -#define GR_LOD_64 GR_LOD_LOG2_64 -#define GR_LOD_32 GR_LOD_LOG2_32 -#define GR_LOD_16 GR_LOD_LOG2_16 -#define GR_LOD_8 GR_LOD_LOG2_8 -#define GR_LOD_4 GR_LOD_LOG2_4 -#define GR_LOD_2 GR_LOD_LOG2_2 -#define GR_LOD_1 GR_LOD_LOG2_1 - -#define GR_FOG_WITH_TABLE GR_FOG_WITH_TABLE_ON_Q - -typedef int GrSstType; - -#define MAX_NUM_SST 4 - -#define GR_SSTTYPE_VOODOO 0 -#define GR_SSTTYPE_SST96 1 -#define GR_SSTTYPE_AT3D 2 -#define GR_SSTTYPE_Voodoo2 3 - -typedef struct GrTMUConfig_St { - int tmuRev; /* Rev of Texelfx chip */ - int tmuRam; /* 1, 2, or 4 MB */ -} GrTMUConfig_t; - -typedef struct GrVoodooConfig_St { - int fbRam; /* 1, 2, or 4 MB */ - int fbiRev; /* Rev of Pixelfx chip */ - int nTexelfx; /* How many texelFX chips are there? */ - FxBool sliDetect; /* Is it a scan-line interleaved board? */ - GrTMUConfig_t tmuConfig[GLIDE_NUM_TMU]; /* Configuration of the Texelfx chips */ -} GrVoodooConfig_t; - -typedef struct GrSst96Config_St { - int fbRam; /* How much? */ - int nTexelfx; - GrTMUConfig_t tmuConfig; -} GrSst96Config_t; - -typedef GrVoodooConfig_t GrVoodoo2Config_t; - -typedef struct GrAT3DConfig_St { - int rev; -} GrAT3DConfig_t; - -typedef struct { - int num_sst; /* # of HW units in the system */ - struct { - GrSstType type; /* Which hardware is it? */ - union SstBoard_u { - GrVoodooConfig_t VoodooConfig; - GrSst96Config_t SST96Config; - GrAT3DConfig_t AT3DConfig; - GrVoodoo2Config_t Voodoo2Config; - } sstBoard; - } SSTs[MAX_NUM_SST]; /* configuration for each board */ -} GrHwConfiguration; - -typedef FxU32 GrHint_t; -#define GR_HINTTYPE_MIN 0 -#define GR_HINT_STWHINT 0 - -typedef FxU32 GrSTWHint_t; -#define GR_STWHINT_W_DIFF_FBI FXBIT(0) -#define GR_STWHINT_W_DIFF_TMU0 FXBIT(1) -#define GR_STWHINT_ST_DIFF_TMU0 FXBIT(2) -#define GR_STWHINT_W_DIFF_TMU1 FXBIT(3) -#define GR_STWHINT_ST_DIFF_TMU1 FXBIT(4) -#define GR_STWHINT_W_DIFF_TMU2 FXBIT(5) -#define GR_STWHINT_ST_DIFF_TMU2 FXBIT(6) - -#define GR_CONTROL_ACTIVATE 1 -#define GR_CONTROL_DEACTIVATE 0 - -#define GrState void - -/* -** move the vertex layout defintion to application -*/ -typedef struct { - float sow; /* s texture ordinate (s over w) */ - float tow; /* t texture ordinate (t over w) */ - float oow; /* 1/w (used mipmapping - really 0xfff/w) */ -} GrTmuVertex; - - -#if FX_USE_PARGB - -typedef struct -{ - float x, y; /* X and Y in screen space */ - float ooz; /* 65535/Z (used for Z-buffering) */ - float oow; /* 1/W (used for W-buffering, texturing) */ - FxU32 argb; /* R, G, B, A [0..255.0] */ - GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; - float z; /* Z is ignored */ -} GrVertex; - -#define GR_VERTEX_X_OFFSET 0 -#define GR_VERTEX_Y_OFFSET 1 -#define GR_VERTEX_OOZ_OFFSET 2 -#define GR_VERTEX_OOW_OFFSET 3 -#define GR_VERTEX_PARGB_OFFSET 4 -#define GR_VERTEX_SOW_TMU0_OFFSET 5 -#define GR_VERTEX_TOW_TMU0_OFFSET 6 -#define GR_VERTEX_OOW_TMU0_OFFSET 7 -#define GR_VERTEX_SOW_TMU1_OFFSET 8 -#define GR_VERTEX_TOW_TMU1_OFFSET 9 -#define GR_VERTEX_OOW_TMU1_OFFSET 10 -#define GR_VERTEX_Z_OFFSET 11 - -#define GET_PARGB(v) ((FxU32*)(v))[GR_VERTEX_PARGB_OFFSET] -/* GET_PA: returns the alpha component */ -#if GLIDE_ENDIAN == GLIDE_ENDIAN_BIG - #define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4] -#else - #define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+3] -#endif -#define MESACOLOR2PARGB(c) (c[ACOMP] << 24 | c[GCOMP] << 16 | c[GCOMP] << 8 | c[BCOMP]) -#define PACK_4F_ARGB(dest,a,r,g,b) { \ - const GLuint cr = (int)r; \ - const GLuint cg = (int)g; \ - const GLuint ca = (int)a; \ - const GLuint cb = (int)b; \ - dest = ca << 24 | cr << 16 | cg << 8 | cb; \ - } - -#else /* FX_USE_PARGB */ - -typedef struct -{ - float x, y, z; /* X, Y, and Z of scrn space -- Z is ignored */ - float r, g, b; /* R, G, B, ([0..255.0]) */ - float ooz; /* 65535/Z (used for Z-buffering) */ - float a; /* Alpha [0..255.0] */ - float oow; /* 1/W (used for W-buffering, texturing) */ - GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; -} GrVertex; - -#define GR_VERTEX_X_OFFSET 0 -#define GR_VERTEX_Y_OFFSET 1 -#define GR_VERTEX_Z_OFFSET 2 -#define GR_VERTEX_R_OFFSET 3 -#define GR_VERTEX_G_OFFSET 4 -#define GR_VERTEX_B_OFFSET 5 -#define GR_VERTEX_OOZ_OFFSET 6 -#define GR_VERTEX_A_OFFSET 7 -#define GR_VERTEX_OOW_OFFSET 8 -#define GR_VERTEX_SOW_TMU0_OFFSET 9 -#define GR_VERTEX_TOW_TMU0_OFFSET 10 -#define GR_VERTEX_OOW_TMU0_OFFSET 11 -#define GR_VERTEX_SOW_TMU1_OFFSET 12 -#define GR_VERTEX_TOW_TMU1_OFFSET 13 -#define GR_VERTEX_OOW_TMU1_OFFSET 14 -#endif /* FX_USE_PARGB */ - -#endif - -/* - * Glide2 functions for Glide3 - */ -#if defined(FX_GLIDE3) -#define FX_grTexDownloadTable(TMU,type,data) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexDownloadTable(type,data); \ - END_BOARD_LOCK(); \ - } while (0); -#define FX_grTexDownloadTable_NoLock(TMU,type,data) \ - grTexDownloadTable(type, data) -#else -#define FX_grTexDownloadTable(TMU,type,data) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexDownloadTable(TMU,type,data); \ - END_BOARD_LOCK(); \ - } while (0); -#define FX_grTexDownloadTable_NoLock grTexDownloadTable -#endif - -/* - * Flush - */ -#if defined(FX_GLIDE3) -#define FX_grFlush() \ - do { \ - BEGIN_BOARD_LOCK(); \ - grFlush(); \ - END_BOARD_LOCK(); \ - } while (0) -#else -#define FX_grFlush() \ - do { \ - BEGIN_BOARD_LOCK(); \ - grSstIdle(); \ - END_BOARD_LOCK(); \ - } while (0) -#endif - -#define FX_grFinish() \ - do { \ - BEGIN_BOARD_LOCK(); \ - grFinish(); \ - END_BOARD_LOCK(); \ - } while (0) - -/* - * Write region: ToDo possible exploit the PixelPipe parameter. - */ -#if defined(FX_GLIDE3) -#define FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,FXFALSE,src_stride,src_data); \ - END_BOARD_LOCK(); \ - } while(0) -#else -#define FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data); \ - END_BOARD_LOCK(); \ - } while (0) -#endif - -/* - * Read region - */ -#define FX_grLfbReadRegion(src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grLfbReadRegion(src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data); \ - END_BOARD_LOCK(); \ - } while (0); - -/* - * Draw triangle - */ -#define FX_grDrawTriangle(a,b,c) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grDrawTriangle(a,b,c); \ - END_CLIP_LOOP(); \ - } while (0) - -/* - * For Lod/LodLog2 conversion. - */ -#if defined(FX_GLIDE3) - #define FX_largeLodLog2(info) (info).largeLodLog2 -#else - #define FX_largeLodLog2(info) (info).largeLod -#endif - -#if defined(FX_GLIDE3) - #define FX_aspectRatioLog2(info) (info).aspectRatioLog2 -#else - #define FX_aspectRatioLog2(info) (info).aspectRatio -#endif - -#if defined(FX_GLIDE3) - #define FX_smallLodLog2(info) (info).smallLodLog2 -#else - #define FX_smallLodLog2(info) (info).smallLod -#endif - -#if defined(FX_GLIDE3) - #define FX_lodToValue(val) ((int)(GR_LOD_256-val)) -#else - #define FX_lodToValue(val) ((int)(val)) -#endif - -#if defined(FX_GLIDE3) - #define FX_largeLodValue(info) ((int)(GR_LOD_256-(info).largeLodLog2)) -#else - #define FX_largeLodValue(info) ((int)(info).largeLod) -#endif -#define FX_largeLodValue_NoLock FX_largeLodValue - -#if defined(FX_GLIDE3) - #define FX_smallLodValue(info) ((int)(GR_LOD_256-(info).smallLodLog2)) -#else - #define FX_smallLodValue(info) ((int)(info).smallLod) -#endif -#define FX_smallLodValue_NoLock FX_smallLodValue - -#if defined(FX_GLIDE3) - #define FX_valueToLod(val) ((GrLOD_t)(GR_LOD_256-val)) -#else - #define FX_valueToLod(val) ((GrLOD_t)(val)) -#endif - -/* - * ScreenWidth/Height stuff. - */ - extern int FX_grSstScreenWidth(void); - extern int FX_grSstScreenHeight(void); - - - -/* - * Version string. - */ -#if defined(FX_GLIDE3) - extern void FX_grGlideGetVersion(char *buf); -#else - #define FX_grGlideGetVersion(b) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grGlideGetVersion(b); \ - END_BOARD_LOCK(); \ - } while (0) -#endif -/* - * Performance statistics - */ -#if defined(FX_GLIDE3) - extern void FX_grSstPerfStats(GrSstPerfStats_t *st); -#else - #define FX_grSstPerfStats(s) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grSstPerfStats(s); \ - END_BOARD_LOCK(); \ - } while (0) -#endif - -/* - * Hardware Query - */ - extern int FX_grSstQueryHardware(GrHwConfiguration *config); - -/* - * GrHints - */ -#if defined(FX_GLIDE3) - extern void FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask); - extern void FX_grHints(GrHint_t hintType, FxU32 hintMask); -#else - #define FX_grHints(t,m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grHints(t, m); \ - END_BOARD_LOCK(); \ - } while(0) - #define FX_grHints_NoLock grHints -#endif -/* - * Antialiashed line+point drawing. - */ -#if defined(FX_GLIDE3) - extern void FX_grAADrawLine(GrVertex *a,GrVertex *b); -#else - #define FX_grAADrawLine(a,b) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grAADrawLine(a,b); \ - END_CLIP_LOOP(); \ - } while (0) -#endif - -#if defined(FX_GLIDE3) - extern void FX_grAADrawPoint(GrVertex *a); -#else - #define FX_grAADrawPoint(a) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grAADrawPoint(a); \ - END_CLIP_LOOP(); \ - } while (0) -#endif - -/* - * Needed for Glide3 only, to set up Glide2 compatible vertex layout. - */ -#if defined(FX_GLIDE3) - extern void FX_setupGrVertexLayout(void); -#else - #define FX_setupGrVertexLayout() do {} while (0) -#endif -/* - * grSstControl stuff - */ -extern FxBool FX_grSstControl(FxU32 code); - -/* - * grGammaCorrectionValue - */ -#if defined(FX_GLIDE3) - extern void FX_grGammaCorrectionValue(float val); -#else - #define FX_grGammaCorrectionValue(v) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grGammaCorrectionValue(v) \ - END_BOARD_LOCK(); \ - } while (0) -#endif - -#if defined(FX_GLIDE3) -#define FX_grSstWinClose(w) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grSstWinClose(w); \ - END_BOARD_LOCK(); \ - } while (0) -#else -#define FX_grSstWinClose(w) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grSstWinClose(); \ - END_BOARD_LOCK(); \ - } while (0) -#endif - - -extern FX_GrContext_t FX_grSstWinOpen( FxU32 hWnd, - GrScreenResolution_t screen_resolution, - GrScreenRefresh_t refresh_rate, - GrColorFormat_t color_format, - GrOriginLocation_t origin_location, - int nColBuffers, - int nAuxBuffers); - - -#define FX_grDrawLine(v1, v2) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grDrawLine(v1, v2); \ - END_CLIP_LOOP(); \ - } while (0) - -#define FX_grDrawPoint(p) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grDrawPoint(p); \ - END_CLIP_LOOP(); \ - } while (0) - -#if defined(FX_GLIDE3) -extern void FX_grDrawPolygonVertexList(int n, GrVertex *v); -#else -#define FX_grDrawPolygonVertexList(n, v) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grDrawPolygonVertexList(n, v); \ - END_CLIP_LOOP(); \ - } while (0) -#endif - -#define FX_grDitherMode(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDitherMode(m); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grRenderBuffer(b) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grRenderBuffer(b); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grBufferClear(c, a, d) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grBufferClear(c, a, d); \ - END_CLIP_LOOP(); \ - } while (0) - -#define FX_grBufferClearExt(c, a, d, s) \ - do { \ - BEGIN_CLIP_LOOP(); \ - (*grBufferClearExtPtr)(c, a, d, s); \ - END_CLIP_LOOP(); \ - } while (0) - -/* - * Enable/Disable - */ -#define FX_grEnable(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grEnable(m); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grDisable(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDisable(m); \ - END_BOARD_LOCK(); \ - } while (0) - -/* - * Stencil operations. - */ -#define FX_grStencilFunc(fnc, ref, mask) \ - do { \ - BEGIN_BOARD_LOCK(); \ - (*grStencilFuncPtr)((fnc), (ref), (mask)); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grStencilMask(write_mask) \ - do { \ - BEGIN_BOARD_LOCK(); \ - (*grStencilMaskPtr)(write_mask); \ - END_BOARD_LOCK(); \ - } while (0) - - -#define FX_grStencilOp(stencil_fail, depth_fail, depth_pass) \ - do { \ - BEGIN_BOARD_LOCK(); \ - (*grStencilOpPtr)((stencil_fail), (depth_fail), (depth_pass)); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grDepthMask(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDepthMask(m); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grColorMask(c, a) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grColorMask(c, a); \ - END_BOARD_LOCK(); \ - } while (0) - -extern FxBool FX_grLfbLock(GrLock_t type, GrBuffer_t buffer, - GrLfbWriteMode_t writeMode, - GrOriginLocation_t origin, FxBool pixelPipeline, - GrLfbInfo_t *info ); - -#define FX_grLfbUnlock(t, b) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grLfbUnlock(t, b); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grConstantColorValue(v) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grConstantColorValue(v); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grConstantColorValue_NoLock grConstantColorValue - -#define FX_grAADrawTriangle(a, b, c, ab, bc, ca) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grAADrawTriangle(a, b, c, ab, bc, ca); \ - END_CLIP_LOOP(); \ - } while (0) - -#define FX_grAlphaBlendFunction(rs, rd, as, ad) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grAlphaBlendFunction(rs, rd, as, ad); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grAlphaCombine(func, fact, loc, oth, inv) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grAlphaCombine(func, fact, loc, oth, inv); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grAlphaCombine_NoLock grAlphaCombine - -#define FX_grAlphaTestFunction(f) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grAlphaTestFunction(f); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grAlphaTestReferenceValue(v) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grAlphaTestReferenceValue(v); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grClipWindow(minx, miny, maxx, maxy) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grClipWindow(minx, miny, maxx, maxy); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grClipWindow_NoLock grClipWindow - -#define FX_grColorCombine(func, fact, loc, oth, inv) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grColorCombine(func, fact, loc, oth, inv); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grColorCombine_NoLock grColorCombine - -#define FX_grCullMode(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grCullMode(m); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grDepthBiasLevel(lev) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDepthBiasLevel(lev); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grDepthBufferFunction(func) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDepthBufferFunction(func); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grFogColorValue(c) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grFogColorValue(c); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grFogMode(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grFogMode(m); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grFogTable(t) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grFogTable(t); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexClampMode(t, sc, tc) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexClampMode(t, sc, tc); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexClampMode_NoLock grTexClampMode - -#define FX_grTexCombine(t, rfunc, rfact, afunc, afact, rinv, ainv) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexCombine(t, rfunc, rfact, afunc, afact, rinv, ainv); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexCombine_NoLock grTexCombine - -#define FX_grTexDownloadMipMapLevel(t, sa, tlod, llod, ar, f, eo, d) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexDownloadMipMapLevel(t, sa, tlod, llod, ar, f, eo, d); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexDownloadMipMapLevel_NoLock grTexDownloadMipMapLevel - -#define FX_grTexDownloadMipMapLevelPartial(t, sa, tlod, llod, ar, f, eo, d, s, e); \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexDownloadMipMapLevelPartial(t, sa, tlod, llod, ar, f, eo, d, s, e); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexFilterMode(t, minf, magf) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexFilterMode(t, minf, magf); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexFilterMode_NoLock grTexFilterMode - -extern FxU32 FX_grTexMinAddress(GrChipID_t tmu); -extern FxU32 FX_grTexMaxAddress(GrChipID_t tmu); - -#define FX_grTexMipMapMode(t, m, lod) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexMipMapMode(t, m, lod); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexMipMapMode_NoLock grTexMipMapMode - -#define FX_grTexSource(t, sa, eo, i) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexSource(t, sa, eo, i); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexSource_NoLock grTexSource - -extern FxU32 FX_grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo *info); -#define FX_grTexTextureMemRequired_NoLock grTexTextureMemRequired - -#define FX_grGlideGetState(s) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grGlideGetState(s); \ - END_BOARD_LOCK(); \ - } while (0) -#define FX_grGlideGetState_NoLock(s) grGlideGetState(s); - -#define FX_grDRIBufferSwap(i) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDRIBufferSwap(i); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grSstSelect(b) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grSstSelect(b); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grSstSelect_NoLock grSstSelect - -#define FX_grGlideSetState(s) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grGlideSetState(s); \ - END_BOARD_LOCK(); \ - } while (0) -#define FX_grGlideSetState_NoLock(s) grGlideSetState(s); - -#define FX_grDepthBufferMode(m) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grDepthBufferMode(m); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grLfbWriteColorFormat(f) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grLfbWriteColorFormat(f); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grDrawVertexArray(m, c, p) \ - do { \ - BEGIN_CLIP_LOOP(); \ - grDrawVertexArray(m, c, p); \ - END_CLIP_LOOP(); \ - } while (0) - -#define FX_grGlideShutdown() \ - do { \ - BEGIN_BOARD_LOCK(); \ - grGlideShutdown(); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grTexLodBiasValue_NoLock(t, v) grTexLodBiasValue(t, v) - -#define FX_grTexLodBiasValue(t, v) \ - do { \ - BEGIN_BOARD_LOCK(); \ - grTexLodBiasValue(t, v); \ - END_BOARD_LOCK(); \ - } while (0) - -#define FX_grGlideInit_NoLock grGlideInit -#define FX_grSstWinOpen_NoLock grSstWinOpen - -extern int FX_getFogTableSize(void); -extern int FX_getGrStateSize(void); - -#endif /* __FX_GLIDE_WARPER__ */ - diff --git a/xc/extras/Mesa/src/FX/fxpipeline.c b/xc/extras/Mesa/src/FX/fxpipeline.c deleted file mode 100644 index cf4c9ebbc..000000000 --- a/xc/extras/Mesa/src/FX/fxpipeline.c +++ /dev/null @@ -1,302 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - - -#if defined(FX) - -#include "fxdrv.h" -#include "vbindirect.h" - - -/* We don't handle texcoord-4 in the safe clip routines - maybe we should. - */ -static void fxDDRenderElements( struct vertex_buffer *VB ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - - if (fxMesa->render_index != 0 || - ((ctx->Texture.ReallyEnabled & 0xf) && VB->TexCoordPtr[0]->size>2) || - ((ctx->Texture.ReallyEnabled & 0xf0) && VB->TexCoordPtr[1]->size>2) || - (VB->ClipPtr->size != 4)) /* Brokes clipping otherwise */ - gl_render_elts( VB ); - else - fxDDRenderElementsDirect( VB ); -} - -static void fxDDCheckRenderVBIndirect( GLcontext *ctx, - struct gl_pipeline_stage *d ) -{ - d->type = 0; - - if ((ctx->IndirectTriangles & DD_SW_SETUP) == 0 && - ctx->Driver.MultipassFunc == 0) - { - d->type = PIPE_IMMEDIATE; - d->inputs = VERT_SETUP_FULL | VERT_ELT | VERT_PRECALC_DATA; - } -} - -static void fxDDRenderVBIndirect( struct vertex_buffer *VB ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - struct vertex_buffer *cvaVB = ctx->CVA.VB; - - if (fxMesa->render_index != 0 || - ((ctx->Texture.ReallyEnabled & 0xf) && cvaVB->TexCoordPtr[0]->size>2) || - ((ctx->Texture.ReallyEnabled & 0xf0) && cvaVB->TexCoordPtr[1]->size>2) || - (VB->ClipPtr->size != 4)) /* Brokes clipping otherwise */ - gl_render_vb_indirect( VB ); - else - fxDDRenderVBIndirectDirect( VB ); -} - - -static void fxDDRenderVB( struct vertex_buffer *VB ) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - - if ((fxMesa->render_index != 0) || - ((ctx->Texture.ReallyEnabled & 0xf) && VB->TexCoordPtr[0]->size>2) || - ((ctx->Texture.ReallyEnabled & 0xf0) && VB->TexCoordPtr[1]->size>2)) - gl_render_vb( VB ); - else - fxDDDoRenderVB( VB ); -} - - - - -/* This sort of driver-based reconfiguration of the pipeline could be - * used to support accelerated transformation and lighting on capable - * hardware. - * - */ -GLuint fxDDRegisterPipelineStages( struct gl_pipeline_stage *out, - const struct gl_pipeline_stage *in, - GLuint nr ) -{ - GLuint i, o; - - for (i = o = 0 ; i < nr ; i++) { - switch (in[i].ops) { - case PIPE_OP_RAST_SETUP_1|PIPE_OP_RENDER: - out[o] = in[i]; - out[o].state_change = NEW_CLIENT_STATE; - out[o].check = fxDDCheckMergeAndRender; - out[o].run = fxDDMergeAndRender; - o++; - break; - case PIPE_OP_RAST_SETUP_0: - out[o] = in[i]; - out[o].cva_state_change = NEW_LIGHTING|NEW_TEXTURING|NEW_RASTER_OPS; - out[o].state_change = ~0; - out[o].check = fxDDCheckPartialRasterSetup; - out[o].run = fxDDPartialRasterSetup; - o++; - break; - case PIPE_OP_RAST_SETUP_0|PIPE_OP_RAST_SETUP_1: - out[o] = in[i]; - out[o].run = fxDDDoRasterSetup; - o++; - break; - case PIPE_OP_RENDER: - out[o] = in[i]; - if (in[i].run == gl_render_elts) { - out[o].run = fxDDRenderElements; - } else if (in[i].run == gl_render_vb_indirect) { - out[o].check = fxDDCheckRenderVBIndirect; - out[o].run = fxDDRenderVBIndirect; - } else if (in[i].run == gl_render_vb) { - out[o].run = fxDDRenderVB; - } - - o++; - break; - default: - out[o++] = in[i]; - break; - } - } - - return o; -} - -#define ILLEGAL_ENABLES (TEXTURE0_3D| \ - TEXTURE1_3D| \ - ENABLE_TEXMAT0 | \ - ENABLE_TEXMAT1 | \ - ENABLE_TEXGEN0 | \ - ENABLE_TEXGEN1 | \ - ENABLE_USERCLIP | \ - ENABLE_LIGHT | \ - ENABLE_FOG) - - - -/* Because this is slotted in by the OptimizePipeline function, most - * of the information here is just for gl_print_pipeline(). Only the - * run member is required. - */ -static struct gl_pipeline_stage fx_fast_stage = { - "FX combined vertex transform, setup and rasterization stage", - PIPE_OP_VERT_XFORM|PIPE_OP_RAST_SETUP_0|PIPE_OP_RAST_SETUP_1|PIPE_OP_RENDER, - PIPE_PRECALC, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* never called */ - fxDDFastPath -}; - - - - -/* Better than optimizing the pipeline, we can do the whole build very - * quickly with the aid of a new flags member. - */ -GLboolean fxDDBuildPrecalcPipeline( GLcontext *ctx ) -{ - struct gl_pipeline *pipe = &ctx->CVA.pre; - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - - if (fxMesa->is_in_hardware && - fxMesa->render_index == 0 && - (ctx->Enabled & ILLEGAL_ENABLES) == 0 && - (ctx->Array.Flags & (VERT_OBJ_234| - VERT_TEX0_4| - VERT_TEX1_4| - VERT_ELT)) == (VERT_OBJ_23|VERT_ELT)) - { - if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_DRIVER)) - if (!fxMesa->using_fast_path) - fprintf(stderr, "fxMesa: using fast path\n"); - - pipe->stages[0] = &fx_fast_stage; - pipe->stages[1] = 0; - pipe->new_inputs = ctx->RenderFlags & VERT_DATA; - pipe->ops = pipe->stages[0]->ops; - fxMesa->using_fast_path = 1; - return 1; - } - - if (fxMesa->using_fast_path) - { - if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_DRIVER)) - fprintf(stderr, "fxMesa: fall back to full pipeline %x %x %x %x %x\n", - fxMesa->is_in_hardware, - fxMesa->render_index, - (ctx->Enabled & ILLEGAL_ENABLES), - (ctx->Array.Summary & (VERT_OBJ_23)), - (ctx->Array.Summary & (VERT_OBJ_4|VERT_TEX0_4|VERT_TEX1_4))); - - fxMesa->using_fast_path = 0; - ctx->CVA.VB->ClipOrMask = 0; - ctx->CVA.VB->ClipAndMask = CLIP_ALL_BITS; - ctx->Array.NewArrayState |= ctx->Array.Summary; - return 0; - } - - return 0; -} - - - - - - -/* Perform global optimizations to the pipeline. The fx driver - * implements a single such fast path, which corresponds to the standard - * quake3 cva pipeline. - * - * This is now handled by the 'build' function above. - */ -void fxDDOptimizePrecalcPipeline( GLcontext *ctx, struct gl_pipeline *pipe ) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (fxMesa->is_in_hardware && - fxMesa->render_index == 0 && - (ctx->Enabled & ILLEGAL_ENABLES) == 0 && - (ctx->Array.Summary & VERT_ELT)) - { - pipe->stages[0] = &fx_fast_stage; - pipe->stages[1] = 0; - } -} - - - -/* unused? -void fxDDOptimizeEltPipeline( GLcontext *ctx, struct gl_pipeline *pipe ) -{ - (void) ctx; - (void) pipe; -} -*/ - -#else - -/* - * Need this to provide at least one external definition. - */ -int gl_fxpipeline_dummy(void) -{ - return 0; -} - -#endif diff --git a/xc/extras/Mesa/src/FX/fxsetup.c b/xc/extras/Mesa/src/FX/fxsetup.c deleted file mode 100644 index 7ba8ee6f7..000000000 --- a/xc/extras/Mesa/src/FX/fxsetup.c +++ /dev/null @@ -1,1901 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - -#include "fxdrv.h" -#include "enums.h" - -static GLuint fxGetTexSetConfiguration(GLcontext *ctx, - struct gl_texture_object *tObj0, - struct gl_texture_object *tObj1); -static void fxSetupTextureSingleTMU_NoLock(GLcontext *ctx, GLuint textureset); -static void fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa, - struct gl_texture_object *tObj0, - struct gl_texture_object *tObj1); -static void gl_print_fx_state_flags( const char *msg, GLuint flags); -static GLboolean fxMultipassTexture( struct vertex_buffer *, GLuint ); - - - -static void fxTexValidate(GLcontext *ctx, struct gl_texture_object *tObj) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - GLint minl, maxl; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxTexValidate(...) Start\n"); - } - - if(ti->validated) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxTexValidate(...) End (validated=GL_TRUE)\n"); - } - return; - } - - ti->tObj=tObj; - minl=ti->minLevel=tObj->BaseLevel; - maxl=ti->maxLevel=MIN2(tObj->MaxLevel,tObj->Image[0]->MaxLog2); - - fxTexGetInfo(tObj->Image[minl]->Width, tObj->Image[minl]->Height, - &(FX_largeLodLog2(ti->info)), &(FX_aspectRatioLog2(ti->info)), - &(ti->sScale), &(ti->tScale), - &(ti->int_sScale), &(ti->int_tScale), - NULL, NULL); - - if((tObj->MinFilter!=GL_NEAREST) && (tObj->MinFilter!=GL_LINEAR)) - fxTexGetInfo(tObj->Image[maxl]->Width,tObj->Image[maxl]->Height, - &(FX_smallLodLog2(ti->info)),NULL, - NULL,NULL, - NULL,NULL, - NULL,NULL); - else - FX_smallLodLog2(ti->info)=FX_largeLodLog2(ti->info); - - fxTexGetFormat(tObj->Image[minl]->IntFormat,&(ti->info.format),&(ti->baseLevelInternalFormat)); - - switch (tObj->WrapS) { - case GL_CLAMP_TO_EDGE: - /* What's this really mean compared to GL_CLAMP? */ - case GL_CLAMP: - ti->sClamp=1; - break; - case GL_REPEAT: - ti->sClamp=0; - break; - default: - ; /* silence compiler warning */ - } - switch (tObj->WrapT) { - case GL_CLAMP_TO_EDGE: - /* What's this really mean compared to GL_CLAMP? */ - case GL_CLAMP: - ti->tClamp=1; - break; - case GL_REPEAT: - ti->tClamp=0; - break; - default: - ; /* silence compiler warning */ - } - - ti->validated=GL_TRUE; - - ti->info.data=NULL; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxTexValidate(...) End\n"); - } -} - -static void fxPrintUnitsMode( const char *msg, GLuint mode ) -{ - fprintf(stderr, - "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", - msg, - mode, - (mode & FX_UM_E0_REPLACE) ? "E0_REPLACE, " : "", - (mode & FX_UM_E0_MODULATE) ? "E0_MODULATE, " : "", - (mode & FX_UM_E0_DECAL) ? "E0_DECAL, " : "", - (mode & FX_UM_E0_BLEND) ? "E0_BLEND, " : "", - (mode & FX_UM_E1_REPLACE) ? "E1_REPLACE, " : "", - (mode & FX_UM_E1_MODULATE) ? "E1_MODULATE, " : "", - (mode & FX_UM_E1_DECAL) ? "E1_DECAL, " : "", - (mode & FX_UM_E1_BLEND) ? "E1_BLEND, " : "", - (mode & FX_UM_E0_ALPHA) ? "E0_ALPHA, " : "", - (mode & FX_UM_E0_LUMINANCE) ? "E0_LUMINANCE, " : "", - (mode & FX_UM_E0_LUMINANCE_ALPHA) ? "E0_LUMINANCE_ALPHA, " : "", - (mode & FX_UM_E0_INTENSITY) ? "E0_INTENSITY, " : "", - (mode & FX_UM_E0_RGB) ? "E0_RGB, " : "", - (mode & FX_UM_E0_RGBA) ? "E0_RGBA, " : "", - (mode & FX_UM_E1_ALPHA) ? "E1_ALPHA, " : "", - (mode & FX_UM_E1_LUMINANCE) ? "E1_LUMINANCE, " : "", - (mode & FX_UM_E1_LUMINANCE_ALPHA) ? "E1_LUMINANCE_ALPHA, " : "", - (mode & FX_UM_E1_INTENSITY) ? "E1_INTENSITY, " : "", - (mode & FX_UM_E1_RGB) ? "E1_RGB, " : "", - (mode & FX_UM_E1_RGBA) ? "E1_RGBA, " : "", - (mode & FX_UM_COLOR_ITERATED) ? "COLOR_ITERATED, " : "", - (mode & FX_UM_COLOR_CONSTANT) ? "COLOR_CONSTANT, " : "", - (mode & FX_UM_ALPHA_ITERATED) ? "ALPHA_ITERATED, " : "", - (mode & FX_UM_ALPHA_CONSTANT) ? "ALPHA_CONSTANT, " : ""); -} - -static GLuint fxGetTexSetConfiguration(GLcontext *ctx, - struct gl_texture_object *tObj0, - struct gl_texture_object *tObj1) -{ - GLuint unitsmode=0; - GLuint envmode=0; - GLuint ifmt=0; - - if((ctx->Light.ShadeModel==GL_SMOOTH) || 1 || - (ctx->Point.SmoothFlag) || - (ctx->Line.SmoothFlag) || - (ctx->Polygon.SmoothFlag)) - unitsmode|=FX_UM_ALPHA_ITERATED; - else - unitsmode|=FX_UM_ALPHA_CONSTANT; - - if(ctx->Light.ShadeModel==GL_SMOOTH || 1) - unitsmode|=FX_UM_COLOR_ITERATED; - else - unitsmode|=FX_UM_COLOR_CONSTANT; - - - - /* - OpenGL Feeds Texture 0 into Texture 1 - Glide Feeds Texture 1 into Texture 0 - */ - if(tObj0) { - tfxTexInfo *ti0=fxTMGetTexInfo(tObj0); - - switch(ti0->baseLevelInternalFormat) { - case GL_ALPHA: - ifmt|=FX_UM_E0_ALPHA; - break; - case GL_LUMINANCE: - ifmt|=FX_UM_E0_LUMINANCE; - break; - case GL_LUMINANCE_ALPHA: - ifmt|=FX_UM_E0_LUMINANCE_ALPHA; - break; - case GL_INTENSITY: - ifmt|=FX_UM_E0_INTENSITY; - break; - case GL_RGB: - ifmt|=FX_UM_E0_RGB; - break; - case GL_RGBA: - ifmt|=FX_UM_E0_RGBA; - break; - } - - switch(ctx->Texture.Unit[0].EnvMode) { - case GL_DECAL: - envmode|=FX_UM_E0_DECAL; - break; - case GL_MODULATE: - envmode|=FX_UM_E0_MODULATE; - break; - case GL_REPLACE: - envmode|=FX_UM_E0_REPLACE; - break; - case GL_BLEND: - envmode|=FX_UM_E0_BLEND; - break; - case GL_ADD: - envmode|=FX_UM_E0_ADD; - break; - default: - /* do nothing */ - break; - } - } - - if(tObj1) { - tfxTexInfo *ti1=fxTMGetTexInfo(tObj1); - - switch(ti1->baseLevelInternalFormat) { - case GL_ALPHA: - ifmt|=FX_UM_E1_ALPHA; - break; - case GL_LUMINANCE: - ifmt|=FX_UM_E1_LUMINANCE; - break; - case GL_LUMINANCE_ALPHA: - ifmt|=FX_UM_E1_LUMINANCE_ALPHA; - break; - case GL_INTENSITY: - ifmt|=FX_UM_E1_INTENSITY; - break; - case GL_RGB: - ifmt|=FX_UM_E1_RGB; - break; - case GL_RGBA: - ifmt|=FX_UM_E1_RGBA; - break; - default: - /* do nothing */ - break; - } - - switch(ctx->Texture.Unit[1].EnvMode) { - case GL_DECAL: - envmode|=FX_UM_E1_DECAL; - break; - case GL_MODULATE: - envmode|=FX_UM_E1_MODULATE; - break; - case GL_REPLACE: - envmode|=FX_UM_E1_REPLACE; - break; - case GL_BLEND: - envmode|=FX_UM_E1_BLEND; - break; - case GL_ADD: - envmode|=FX_UM_E1_ADD; - break; - default: - /* do nothing */ - break; - } - } - - unitsmode|=(ifmt | envmode); - - if (MESA_VERBOSE & (VERBOSE_DRIVER|VERBOSE_TEXTURE)) - fxPrintUnitsMode("unitsmode", unitsmode); - - return unitsmode; -} - -/************************************************************************/ -/************************* Rendering Mode SetUp *************************/ -/************************************************************************/ - -/************************* Single Texture Set ***************************/ - -static void fxSetupSingleTMU_NoLock(fxMesaContext fxMesa, struct gl_texture_object *tObj) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - int tmu; - - /* Make sure we're not loaded incorrectly */ - if (ti->isInTM) { - if (ti->LODblend) { - if (ti->whichTMU!=FX_TMU_SPLIT) - fxTMMoveOutTM(fxMesa, tObj); - } else { - if (ti->whichTMU==FX_TMU_SPLIT) - fxTMMoveOutTM(fxMesa, tObj); - } - } - - /* Make sure we're loaded correctly */ - if (!ti->isInTM) { - if (ti->LODblend) - fxTMMoveInTM_NoLock(fxMesa,tObj,FX_TMU_SPLIT); - else { - if (fxMesa->haveTwoTMUs) { - if (fxMesa->freeTexMem[FX_TMU0] > - FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, - &(ti->info))) { - fxTMMoveInTM_NoLock(fxMesa,tObj, FX_TMU0); - } else { - fxTMMoveInTM_NoLock(fxMesa,tObj, FX_TMU1); - } - } else - fxTMMoveInTM_NoLock(fxMesa,tObj,FX_TMU0); - } - } - - if (ti->LODblend && ti->whichTMU == FX_TMU_SPLIT) { - if ((ti->info.format==GR_TEXFMT_P_8) && (!fxMesa->haveGlobalPaletteTexture)) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: uploading texture palette\n"); - } - FX_grTexDownloadTable_NoLock(GR_TMU0,GR_TEXTABLE_PALETTE,&(ti->palette)); - FX_grTexDownloadTable_NoLock(GR_TMU1,GR_TEXTABLE_PALETTE,&(ti->palette)); - } - - FX_grTexClampMode_NoLock(GR_TMU0,ti->sClamp,ti->tClamp); - FX_grTexClampMode_NoLock(GR_TMU1,ti->sClamp,ti->tClamp); - FX_grTexFilterMode_NoLock(GR_TMU0,ti->minFilt,ti->maxFilt); - FX_grTexFilterMode_NoLock(GR_TMU1,ti->minFilt,ti->maxFilt); - FX_grTexMipMapMode_NoLock(GR_TMU0,ti->mmMode,ti->LODblend); - FX_grTexMipMapMode_NoLock(GR_TMU1,ti->mmMode,ti->LODblend); - - FX_grTexSource_NoLock(GR_TMU0,ti->tm[FX_TMU0]->startAddr, - GR_MIPMAPLEVELMASK_ODD,&(ti->info)); - FX_grTexSource_NoLock(GR_TMU1,ti->tm[FX_TMU1]->startAddr, - GR_MIPMAPLEVELMASK_EVEN,&(ti->info)); - } else { - if (ti->whichTMU==FX_TMU_BOTH) tmu=FX_TMU0; - else tmu=ti->whichTMU; - - if((ti->info.format==GR_TEXFMT_P_8) && (!fxMesa->haveGlobalPaletteTexture)) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: uploading texture palette\n"); - } - FX_grTexDownloadTable_NoLock(tmu, GR_TEXTABLE_PALETTE, &(ti->palette)); - } - - /* KW: The alternative is to do the download to the other tmu. If - * we get to this point, I think it means we are thrashing the - * texture memory, so perhaps it's not a good idea. - */ - if (ti->LODblend && (MESA_VERBOSE&VERBOSE_DRIVER)) - fprintf(stderr, "fxmesa: not blending texture - only on one tmu\n"); - - FX_grTexClampMode_NoLock(tmu, ti->sClamp, ti->tClamp); - FX_grTexFilterMode_NoLock(tmu, ti->minFilt, ti->maxFilt); - FX_grTexMipMapMode_NoLock(tmu, ti->mmMode, FXFALSE); - - FX_grTexSource_NoLock(tmu, ti->tm[tmu]->startAddr, - GR_MIPMAPLEVELMASK_BOTH, &(ti->info)); - } -} - -static void fxSelectSingleTMUSrc_NoLock(fxMesaContext fxMesa, GLint tmu, - FxBool LODblend) -{ - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSelectSingleTMUSrc(%d,%d)\n",tmu,LODblend); - } - - if (LODblend) { - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND, - GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION, - GR_COMBINE_FUNCTION_BLEND, - GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION, - FXFALSE,FXFALSE); - - if (fxMesa->haveTwoTMUs) - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL,GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL,GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - fxMesa->tmuSrc=FX_TMU_SPLIT; - } - else { - if (tmu!=FX_TMU1) { - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_LOCAL,GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL,GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - if (fxMesa->haveTwoTMUs) { - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_ZERO, GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_ZERO, GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - } - fxMesa->tmuSrc=FX_TMU0; - } - else { - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL,GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL,GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - - /* GR_COMBINE_FUNCTION_SCALE_OTHER doesn't work ?!? */ - - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND, - GR_COMBINE_FACTOR_ONE, - GR_COMBINE_FUNCTION_BLEND, - GR_COMBINE_FACTOR_ONE, - FXFALSE,FXFALSE); - - fxMesa->tmuSrc=FX_TMU1; - } - } -} - -static void fxSetupTextureSingleTMU_NoLock(GLcontext *ctx, GLuint textureset) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GrCombineLocal_t localc,locala; - GLuint unitsmode; - GLint ifmt; - tfxTexInfo *ti; - struct gl_texture_object *tObj=ctx->Texture.Unit[textureset].CurrentD[2]; - int tmu; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupTextureSingleTMU(...) Start\n"); - } - - ti=fxTMGetTexInfo(tObj); - - fxTexValidate(ctx,tObj); - - fxSetupSingleTMU_NoLock(fxMesa,tObj); - - if (ti->whichTMU==FX_TMU_BOTH) tmu=FX_TMU0; - else tmu=ti->whichTMU; - if (fxMesa->tmuSrc!=tmu) - fxSelectSingleTMUSrc_NoLock(fxMesa, tmu, ti->LODblend); - - if(textureset==0 || !fxMesa->haveTwoTMUs) - unitsmode=fxGetTexSetConfiguration(ctx,tObj,NULL); - else - unitsmode=fxGetTexSetConfiguration(ctx,NULL,tObj); - - fxMesa->stw_hint_state = 0; - FX_grHints_NoLock(GR_HINT_STWHINT,0); - - ifmt=ti->baseLevelInternalFormat; - - if(unitsmode & FX_UM_ALPHA_ITERATED) - locala=GR_COMBINE_LOCAL_ITERATED; - else - locala=GR_COMBINE_LOCAL_CONSTANT; - - if(unitsmode & FX_UM_COLOR_ITERATED) - localc=GR_COMBINE_LOCAL_ITERATED; - else - localc=GR_COMBINE_LOCAL_CONSTANT; - - if (MESA_VERBOSE & (VERBOSE_DRIVER|VERBOSE_TEXTURE)) - fprintf(stderr, "fxMesa: fxSetupTextureSingleTMU, envmode is %s\n", - gl_lookup_enum_by_nr(ctx->Texture.Unit[textureset].EnvMode)); - - switch(ctx->Texture.Unit[textureset].EnvMode) { - case GL_DECAL: - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - locala, - GR_COMBINE_OTHER_NONE, - FXFALSE); - - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_BLEND, - GR_COMBINE_FACTOR_TEXTURE_ALPHA, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - case GL_MODULATE: - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - locala, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - - if(ifmt==GL_ALPHA) - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - localc, - GR_COMBINE_OTHER_NONE, - FXFALSE); - else - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - case GL_BLEND: -#if 0 - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - locala, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - if (ifmt==GL_ALPHA) - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - localc, - GR_COMBINE_OTHER_NONE, - FXFALSE); - else - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, - GR_COMBINE_FACTOR_LOCAL, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXTRUE); - ctx->Driver.MultipassFunc = fxMultipassBlend; -#else - if (MESA_VERBOSE&VERBOSE_DRIVER) - fprintf(stderr,"fx Driver: GL_BLEND not yet supported\n"); -#endif - break; - case GL_REPLACE: - if((ifmt==GL_RGB) || (ifmt==GL_LUMINANCE)) - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - locala, - GR_COMBINE_OTHER_NONE, - FXFALSE); - else - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_ONE, - locala, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - - if(ifmt==GL_ALPHA) - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - localc, - GR_COMBINE_OTHER_NONE, - FXFALSE); - else - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_ONE, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - default: - if (MESA_VERBOSE&VERBOSE_DRIVER) - fprintf(stderr, "fx Driver: %x Texture.EnvMode not yet supported\n", - ctx->Texture.Unit[textureset].EnvMode); - break; - } - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupTextureSingleTMU(...) End\n"); - } -} - -static void fxSetupTextureSingleTMU(GLcontext *ctx, GLuint textureset) -{ - BEGIN_BOARD_LOCK(); - fxSetupTextureSingleTMU_NoLock(ctx, textureset); - END_BOARD_LOCK(); -} - -/************************* Double Texture Set ***************************/ - -static void fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa, - struct gl_texture_object *tObj0, - struct gl_texture_object *tObj1) -{ -#define T0_NOT_IN_TMU 0x01 -#define T1_NOT_IN_TMU 0x02 -#define T0_IN_TMU0 0x04 -#define T1_IN_TMU0 0x08 -#define T0_IN_TMU1 0x10 -#define T1_IN_TMU1 0x20 - - tfxTexInfo *ti0=fxTMGetTexInfo(tObj0); - tfxTexInfo *ti1=fxTMGetTexInfo(tObj1); - GLuint tstate=0; - int tmu0=0, tmu1=1; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupDoubleTMU(...)\n"); - } - - /* We shouldn't need to do this. There is something wrong with - mutlitexturing when the TMUs are swapped. So, we're forcing - them to always be loaded correctly. !!! */ - if (ti0->whichTMU==FX_TMU1) - fxTMMoveOutTM_NoLock(fxMesa, tObj0); - if (ti1->whichTMU==FX_TMU0) - fxTMMoveOutTM_NoLock(fxMesa, tObj1); - - if (ti0->isInTM) { - switch (ti0->whichTMU) { - case FX_TMU0: - tstate|=T0_IN_TMU0; - break; - case FX_TMU1: - tstate|=T0_IN_TMU1; - break; - case FX_TMU_BOTH: - tstate|=T0_IN_TMU0|T0_IN_TMU1; - break; - case FX_TMU_SPLIT: - tstate|=T0_NOT_IN_TMU; - break; - } - } else tstate|=T0_NOT_IN_TMU; - - if (ti1->isInTM) { - switch (ti1->whichTMU) { - case FX_TMU0: - tstate|=T1_IN_TMU0; - break; - case FX_TMU1: - tstate|=T1_IN_TMU1; - break; - case FX_TMU_BOTH: - tstate|=T1_IN_TMU0|T1_IN_TMU1; - break; - case FX_TMU_SPLIT: - tstate|=T1_NOT_IN_TMU; - break; - } - } else tstate|=T1_NOT_IN_TMU; - - ti0->lastTimeUsed=fxMesa->texBindNumber; - ti1->lastTimeUsed=fxMesa->texBindNumber; - - /* Move texture maps into TMUs */ - - if (!(((tstate&T0_IN_TMU0) && (tstate&T1_IN_TMU1)) || - ((tstate&T0_IN_TMU1) && (tstate&T1_IN_TMU0)))) { - if (tObj0==tObj1) fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU_BOTH); - else { - /* Find the minimal way to correct the situation */ - if ((tstate&T0_IN_TMU0) || (tstate&T1_IN_TMU1)) { - /* We have one in the standard order, setup the other */ - if (tstate&T0_IN_TMU0) { /* T0 is in TMU0, put T1 in TMU1 */ - fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU1); - } else { - fxTMMoveInTM_NoLock(fxMesa, tObj0, FX_TMU0); - } - /* tmu0 and tmu1 are setup */ - } else if ((tstate&T0_IN_TMU1) || (tstate&T1_IN_TMU0)) { - /* we have one in the reverse order, setup the other */ - if (tstate&T1_IN_TMU0) { /* T1 is in TMU0, put T0 in TMU1 */ - fxTMMoveInTM_NoLock(fxMesa, tObj0, FX_TMU1); - } else { - fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU0); - } - tmu0=1; - tmu1=0; - } else { /* Nothing is loaded */ - fxTMMoveInTM_NoLock(fxMesa, tObj0, FX_TMU0); - fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU1); - /* tmu0 and tmu1 are setup */ - } - } - } - - if (!fxMesa->haveGlobalPaletteTexture) { - if (ti0->info.format==GR_TEXFMT_P_8) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: uploading texture palette TMU0\n"); - } - FX_grTexDownloadTable_NoLock(tmu0, GR_TEXTABLE_PALETTE, &(ti0->palette)); - } - - if (ti1->info.format==GR_TEXFMT_P_8) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: uploading texture palette TMU1\n"); - } - FX_grTexDownloadTable_NoLock(tmu1, GR_TEXTABLE_PALETTE, &(ti1->palette)); - } - } - - FX_grTexSource_NoLock(tmu0, ti0->tm[tmu0]->startAddr, - GR_MIPMAPLEVELMASK_BOTH, &(ti0->info)); - FX_grTexClampMode_NoLock(tmu0, ti0->sClamp, ti0->tClamp); - FX_grTexFilterMode_NoLock(tmu0, ti0->minFilt, ti0->maxFilt); - FX_grTexMipMapMode_NoLock(tmu0, ti0->mmMode, FXFALSE); - - FX_grTexSource_NoLock(tmu1, ti1->tm[tmu1]->startAddr, - GR_MIPMAPLEVELMASK_BOTH, &(ti1->info)); - FX_grTexClampMode_NoLock(tmu1, ti1->sClamp, ti1->tClamp); - FX_grTexFilterMode_NoLock(tmu1, ti1->minFilt, ti1->maxFilt); - FX_grTexMipMapMode_NoLock(tmu1, ti1->mmMode, FXFALSE); - -#undef T0_NOT_IN_TMU -#undef T1_NOT_IN_TMU -#undef T0_IN_TMU0 -#undef T1_IN_TMU0 -#undef T0_IN_TMU1 -#undef T1_IN_TMU1 -} - -static void fxSetupTextureDoubleTMU_NoLock(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GrCombineLocal_t localc,locala; - tfxTexInfo *ti0,*ti1; - struct gl_texture_object *tObj0=ctx->Texture.Unit[0].CurrentD[2]; - struct gl_texture_object *tObj1=ctx->Texture.Unit[1].CurrentD[2]; - GLuint envmode,ifmt,unitsmode; - int tmu0=0, tmu1=1; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupTextureDoubleTMU(...) Start\n"); - } - - ti0=fxTMGetTexInfo(tObj0); - fxTexValidate(ctx,tObj0); - - ti1=fxTMGetTexInfo(tObj1); - fxTexValidate(ctx,tObj1); - - fxSetupDoubleTMU_NoLock(fxMesa,tObj0,tObj1); - - unitsmode=fxGetTexSetConfiguration(ctx,tObj0,tObj1); - - fxMesa->stw_hint_state |= GR_STWHINT_ST_DIFF_TMU1; - FX_grHints_NoLock(GR_HINT_STWHINT, fxMesa->stw_hint_state); - - envmode=unitsmode & FX_UM_E_ENVMODE; - ifmt=unitsmode & FX_UM_E_IFMT; - - if(unitsmode & FX_UM_ALPHA_ITERATED) - locala=GR_COMBINE_LOCAL_ITERATED; - else - locala=GR_COMBINE_LOCAL_CONSTANT; - - if(unitsmode & FX_UM_COLOR_ITERATED) - localc=GR_COMBINE_LOCAL_ITERATED; - else - localc=GR_COMBINE_LOCAL_CONSTANT; - - - if (MESA_VERBOSE & (VERBOSE_DRIVER|VERBOSE_TEXTURE)) - fprintf(stderr, "fxMesa: fxSetupTextureDoubleTMU, envmode is %s/%s\n", - gl_lookup_enum_by_nr(ctx->Texture.Unit[0].EnvMode), - gl_lookup_enum_by_nr(ctx->Texture.Unit[1].EnvMode)); - - - if ((ti0->whichTMU==FX_TMU1) || (ti1->whichTMU==FX_TMU0)) { - tmu0=1; - tmu1=0; - } - fxMesa->tmuSrc=FX_TMU_BOTH; - switch(envmode) { - case (FX_UM_E0_MODULATE | FX_UM_E1_MODULATE): - { - GLboolean isalpha[FX_NUM_TMU]; - - if(ti0->baseLevelInternalFormat==GL_ALPHA) - isalpha[tmu0]=GL_TRUE; - else - isalpha[tmu0]=GL_FALSE; - - if(ti1->baseLevelInternalFormat==GL_ALPHA) - isalpha[tmu1]=GL_TRUE; - else - isalpha[tmu1]=GL_FALSE; - - if(isalpha[FX_TMU1]) - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_ZERO, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXTRUE,FXFALSE); - else - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - - if(isalpha[FX_TMU0]) - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_ONE, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - FXFALSE,FXFALSE); - else - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - FXFALSE,FXFALSE); - - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - locala, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - } - case (FX_UM_E0_REPLACE | FX_UM_E1_BLEND): /* Only for GLQuake */ - if (tmu1==FX_TMU1) { - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXTRUE,FXFALSE); - - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - FXFALSE,FXFALSE); - } else { - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_ONE_MINUS_LOCAL, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_ONE_MINUS_LOCAL, - FXFALSE,FXFALSE); - } - - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - locala, - GR_COMBINE_OTHER_NONE, - FXFALSE); - - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_ONE, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - case (FX_UM_E0_REPLACE | FX_UM_E1_MODULATE): /* Quake 2 and 3 */ - if (tmu1==FX_TMU1) { - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_ZERO, - GR_COMBINE_FACTOR_NONE, - FXFALSE,FXTRUE); - - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - FXFALSE,FXFALSE); - - } else { - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_LOCAL, - GR_COMBINE_FUNCTION_BLEND_OTHER, - GR_COMBINE_FACTOR_ONE, - FXFALSE,FXFALSE); - } - - if(ti0->baseLevelInternalFormat==GL_RGB) - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - locala, - GR_COMBINE_OTHER_NONE, - FXFALSE); - else - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_ONE, - locala, - GR_COMBINE_OTHER_NONE, - FXFALSE); - - - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_ONE, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - - - case (FX_UM_E0_MODULATE | FX_UM_E1_ADD): /* Quake 3 Sky */ - { - GLboolean isalpha[FX_NUM_TMU]; - - if(ti0->baseLevelInternalFormat==GL_ALPHA) - isalpha[tmu0]=GL_TRUE; - else - isalpha[tmu0]=GL_FALSE; - - if(ti1->baseLevelInternalFormat==GL_ALPHA) - isalpha[tmu1]=GL_TRUE; - else - isalpha[tmu1]=GL_FALSE; - - if(isalpha[FX_TMU1]) - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_ZERO, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXTRUE,FXFALSE); - else - FX_grTexCombine_NoLock(GR_TMU1, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - FXFALSE,FXFALSE); - - if(isalpha[FX_TMU0]) - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_ONE, - GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, - GR_COMBINE_FACTOR_ONE, - FXFALSE,FXFALSE); - else - FX_grTexCombine_NoLock(GR_TMU0, - GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, - GR_COMBINE_FACTOR_ONE, - GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, - GR_COMBINE_FACTOR_ONE, - FXFALSE,FXFALSE); - - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - localc, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, - GR_COMBINE_FACTOR_LOCAL, - locala, - GR_COMBINE_OTHER_TEXTURE, - FXFALSE); - break; - } - default: - fprintf(stderr, "Unexpected dual texture mode encountered\n"); - break; - } - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupTextureDoubleTMU(...) End\n"); - } -} - -/************************* No Texture ***************************/ - -static void fxSetupTextureNone_NoLock(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GrCombineLocal_t localc,locala; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupTextureNone(...)\n"); - } - - if((ctx->Light.ShadeModel==GL_SMOOTH) || 1 || - (ctx->Point.SmoothFlag) || - (ctx->Line.SmoothFlag) || - (ctx->Polygon.SmoothFlag)) - locala=GR_COMBINE_LOCAL_ITERATED; - else - locala=GR_COMBINE_LOCAL_CONSTANT; - - if(ctx->Light.ShadeModel==GL_SMOOTH || 1) - localc=GR_COMBINE_LOCAL_ITERATED; - else - localc=GR_COMBINE_LOCAL_CONSTANT; - - FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - locala, - GR_COMBINE_OTHER_NONE, - FXFALSE); - - FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, - GR_COMBINE_FACTOR_NONE, - localc, - GR_COMBINE_OTHER_NONE, - FXFALSE); -} - -/************************************************************************/ -/************************** Texture Mode SetUp **************************/ -/************************************************************************/ - -static void fxSetupTexture_NoLock(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint tex2Denabled; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxSetupTexture(...)\n"); - } - - /* Disable multipass texturing. - */ - ctx->Driver.MultipassFunc = 0; - - /* Texture Combine, Color Combine and Alpha Combine. - */ - tex2Denabled = (ctx->Texture.ReallyEnabled & TEXTURE0_2D); - - if (fxMesa->emulateTwoTMUs) - tex2Denabled |= (ctx->Texture.ReallyEnabled & TEXTURE1_2D); - - switch(tex2Denabled) { - case TEXTURE0_2D: - fxSetupTextureSingleTMU_NoLock(ctx,0); - break; - case TEXTURE1_2D: - fxSetupTextureSingleTMU_NoLock(ctx,1); - break; - case (TEXTURE0_2D|TEXTURE1_2D): - if (fxMesa->haveTwoTMUs) - fxSetupTextureDoubleTMU_NoLock(ctx); - else { - if (MESA_VERBOSE&VERBOSE_DRIVER) - fprintf(stderr, "fxmesa: enabling fake multitexture\n"); - - fxSetupTextureSingleTMU_NoLock(ctx,0); - ctx->Driver.MultipassFunc = fxMultipassTexture; - } - break; - default: - fxSetupTextureNone_NoLock(ctx); - break; - } -} - -static void fxSetupTexture(GLcontext *ctx) -{ - BEGIN_BOARD_LOCK(); - fxSetupTexture_NoLock(ctx); - END_BOARD_LOCK(); -} - -/************************************************************************/ -/**************************** Blend SetUp *******************************/ -/************************************************************************/ - -/* XXX consider supporting GL_INGR_blend_func_separate */ -void fxDDBlendFunc(GLcontext *ctx, GLenum sfactor, GLenum dfactor) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - tfxUnitsState *us=&fxMesa->unitsState; - GrAlphaBlendFnc_t sfact,dfact,asfact,adfact; - - /* From the Glide documentation: - For alpha source and destination blend function factor - parameters, Voodoo Graphics supports only - GR_BLEND_ZERO and GR_BLEND_ONE. - */ - - switch(sfactor) { - case GL_ZERO: - asfact=sfact=GR_BLEND_ZERO; - break; - case GL_ONE: - asfact=sfact=GR_BLEND_ONE; - break; - case GL_DST_COLOR: - sfact=GR_BLEND_DST_COLOR; - asfact=GR_BLEND_ONE; - break; - case GL_ONE_MINUS_DST_COLOR: - sfact=GR_BLEND_ONE_MINUS_DST_COLOR; - asfact=GR_BLEND_ONE; - break; - case GL_SRC_ALPHA: - sfact=GR_BLEND_SRC_ALPHA; - asfact=GR_BLEND_ONE; - break; - case GL_ONE_MINUS_SRC_ALPHA: - sfact=GR_BLEND_ONE_MINUS_SRC_ALPHA; - asfact=GR_BLEND_ONE; - break; - case GL_DST_ALPHA: - sfact=GR_BLEND_DST_ALPHA; - asfact=GR_BLEND_ONE; - break; - case GL_ONE_MINUS_DST_ALPHA: - sfact=GR_BLEND_ONE_MINUS_DST_ALPHA; - asfact=GR_BLEND_ONE; - break; - case GL_SRC_ALPHA_SATURATE: - sfact=GR_BLEND_ALPHA_SATURATE; - asfact=GR_BLEND_ONE; - break; - case GL_SRC_COLOR: - case GL_ONE_MINUS_SRC_COLOR: - /* USELESS */ - asfact=sfact=GR_BLEND_ONE; - break; - default: - asfact=sfact=GR_BLEND_ONE; - break; - } - - if((sfact!=us->blendSrcFuncRGB) || - (asfact!=us->blendSrcFuncAlpha)) { - us->blendSrcFuncRGB=sfact; - us->blendSrcFuncAlpha=asfact; - fxMesa->new_state |= FX_NEW_BLEND; - ctx->Driver.RenderStart = fxSetupFXUnits; - } - - switch(dfactor) { - case GL_ZERO: - adfact=dfact=GR_BLEND_ZERO; - break; - case GL_ONE: - adfact=dfact=GR_BLEND_ONE; - break; - case GL_SRC_COLOR: - dfact=GR_BLEND_SRC_COLOR; - adfact=GR_BLEND_ZERO; - break; - case GL_ONE_MINUS_SRC_COLOR: - dfact=GR_BLEND_ONE_MINUS_SRC_COLOR; - adfact=GR_BLEND_ZERO; - break; - case GL_SRC_ALPHA: - dfact=GR_BLEND_SRC_ALPHA; - adfact=GR_BLEND_ZERO; - break; - case GL_ONE_MINUS_SRC_ALPHA: - dfact=GR_BLEND_ONE_MINUS_SRC_ALPHA; - adfact=GR_BLEND_ZERO; - break; - case GL_DST_ALPHA: - /* dfact=GR_BLEND_DST_ALPHA; */ - /* We can't do DST_ALPHA */ - dfact=GR_BLEND_ONE; - adfact=GR_BLEND_ZERO; - break; - case GL_ONE_MINUS_DST_ALPHA: - /* dfact=GR_BLEND_ONE_MINUS_DST_ALPHA; */ - /* We can't do DST_ALPHA */ - dfact=GR_BLEND_ZERO; - adfact=GR_BLEND_ZERO; - break; - case GL_SRC_ALPHA_SATURATE: - case GL_DST_COLOR: - case GL_ONE_MINUS_DST_COLOR: - /* USELESS */ - adfact=dfact=GR_BLEND_ZERO; - break; - default: - adfact=dfact=GR_BLEND_ZERO; - break; - } - - if((dfact!=us->blendDstFuncRGB) || - (adfact!=us->blendDstFuncAlpha)) { - us->blendDstFuncRGB=dfact; - us->blendDstFuncAlpha=adfact; - fxMesa->new_state |= FX_NEW_BLEND; - ctx->Driver.RenderStart = fxSetupFXUnits; - } -} - -static void fxSetupBlend(GLcontext *ctx) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - tfxUnitsState *us = &fxMesa->unitsState; - - if (us->blendEnabled) - FX_grAlphaBlendFunction(us->blendSrcFuncRGB, us->blendDstFuncRGB, - us->blendSrcFuncAlpha, us->blendDstFuncAlpha); - else - FX_grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO, - GR_BLEND_ONE, GR_BLEND_ZERO); -} - - -/************************************************************************/ -/************************** Alpha Test SetUp ****************************/ -/************************************************************************/ - -void fxDDAlphaFunc(GLcontext *ctx, GLenum func, GLclampf ref) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - tfxUnitsState *us = &fxMesa->unitsState; - GrCmpFnc_t newfunc; - - switch(func) { - case GL_NEVER: - newfunc=GR_CMP_NEVER; - break; - case GL_LESS: - newfunc=GR_CMP_LESS; - break; - case GL_EQUAL: - newfunc=GR_CMP_EQUAL; - break; - case GL_LEQUAL: - newfunc=GR_CMP_LEQUAL; - break; - case GL_GREATER: - newfunc=GR_CMP_GREATER; - break; - case GL_NOTEQUAL: - newfunc=GR_CMP_NOTEQUAL; - break; - case GL_GEQUAL: - newfunc=GR_CMP_GEQUAL; - break; - case GL_ALWAYS: - newfunc=GR_CMP_ALWAYS; - break; - default: - fprintf(stderr,"fx Driver: internal error in fxDDAlphaFunc()\n"); - fxCloseHardware(); - exit(-1); - break; - } - - if(newfunc!=us->alphaTestFunc) { - us->alphaTestFunc=newfunc; - fxMesa->new_state |= FX_NEW_ALPHA; - ctx->Driver.RenderStart = fxSetupFXUnits; - } - - if(ctx->Color.AlphaRef!=us->alphaTestRefValue) { - us->alphaTestRefValue=ctx->Color.AlphaRef; - fxMesa->new_state |= FX_NEW_ALPHA; - ctx->Driver.RenderStart = fxSetupFXUnits; - } -} - -static void fxSetupAlphaTest(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - tfxUnitsState *us=&fxMesa->unitsState; - - if(us->alphaTestEnabled) { - FX_grAlphaTestFunction(us->alphaTestFunc); - FX_grAlphaTestReferenceValue(us->alphaTestRefValue); - } else - FX_grAlphaTestFunction(GR_CMP_ALWAYS); -} - - -/* - * Evaluate all depth-test state and make the Glide calls. - */ -static void -fxSetupDepthTest(GLcontext *ctx) -{ - if (ctx->Depth.Test) { - GrCmpFnc_t dfunc; - switch (ctx->Depth.Func) { - case GL_NEVER: - dfunc = GR_CMP_NEVER; - break; - case GL_LESS: - dfunc = GR_CMP_LESS; - break; - case GL_GEQUAL: - dfunc = GR_CMP_GEQUAL; - break; - case GL_LEQUAL: - dfunc = GR_CMP_LEQUAL; - break; - case GL_GREATER: - dfunc = GR_CMP_GREATER; - break; - case GL_NOTEQUAL: - dfunc = GR_CMP_NOTEQUAL; - break; - case GL_EQUAL: - dfunc = GR_CMP_EQUAL; - break; - case GL_ALWAYS: - dfunc = GR_CMP_ALWAYS; - break; - default: - gl_problem(ctx, "bad depth mode in fxSetupDepthTest"); - dfunc = GR_CMP_ALWAYS; - } - FX_grDepthBufferFunction(dfunc); - FX_grDepthMask(ctx->Depth.Mask); - } - else { - /* depth test always passes, don't update Z buffer */ - FX_grDepthBufferFunction(GR_CMP_ALWAYS); - FX_grDepthMask(FXFALSE); - } -} - - -/* - * Evaluate all stencil state and make the Glide calls. - */ -static GrStencil_t -fxConvertGLStencilOp(GLenum op) -{ - switch (op) { - case GL_KEEP: - return GR_STENCILOP_KEEP; - case GL_ZERO: - return GR_STENCILOP_ZERO; - case GL_REPLACE: - return GR_STENCILOP_REPLACE; - case GL_INCR: - return GR_STENCILOP_INCR_CLAMP; - case GL_DECR: - return GR_STENCILOP_DECR_CLAMP; - case GL_INVERT: - return GR_STENCILOP_INVERT; - default: - gl_problem(NULL, "bad stencil op in fxConvertGLStencilOp"); - } - return GR_STENCILOP_KEEP; /* never get, silence compiler warning */ -} - -/* - * This function is called just before any rendering is done. - * It will validate the stencil parameters. - */ -static void -fxSetupStencilTest(GLcontext *ctx) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - if (fxMesa->haveHwStencil) { - if (ctx->Stencil.Enabled) { - GrStencil_t sfail = fxConvertGLStencilOp(ctx->Stencil.FailFunc); - GrStencil_t zfail = fxConvertGLStencilOp(ctx->Stencil.ZFailFunc); - GrStencil_t zpass = fxConvertGLStencilOp(ctx->Stencil.ZPassFunc); - FX_grStencilOp(sfail, zfail, zpass); - FX_grStencilFunc(ctx->Stencil.Function - GL_NEVER, - ctx->Stencil.Ref, ctx->Stencil.ValueMask); - FX_grStencilMask(ctx->Stencil.WriteMask); - FX_grEnable(GR_STENCIL_MODE_EXT); - } - else { - FX_grDisable(GR_STENCIL_MODE_EXT); - } - } -} - - -/* - * Set the state so that stencil is either enabled or disabled. - * This is called from Mesa only. Glide is invoked at - * setup time, not now. - */ -static void -fxDDEnableStencil(GLcontext *ctx, GLboolean state) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - (void) state; - fxMesa->new_state |= FX_NEW_STENCIL; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - - -/************************************************************************/ -/**************************** Color Mask SetUp **************************/ -/************************************************************************/ - -GLboolean fxDDColorMask(GLcontext *ctx, - GLboolean r, GLboolean g, - GLboolean b, GLboolean a ) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - fxMesa->new_state |= FX_NEW_COLOR_MASK; - ctx->Driver.RenderStart = fxSetupFXUnits; - (void) r; (void) g; (void) b; (void) a; - return GL_FALSE; -} - -static void fxSetupColorMask(GLcontext *ctx) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (ctx->Color.DrawBuffer == GL_NONE) { - FX_grColorMask(FXFALSE, FXFALSE); - } - else { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - } -} - - - - -/************************************************************************/ -/**************************** Fog Mode SetUp ****************************/ -/************************************************************************/ - -/* - * This is called during state update in order to update the Glide fog state. - */ -static void fxSetupFog(GLcontext *ctx) -{ - if (ctx->Fog.Enabled && ctx->FogMode==FOG_FRAGMENT) { - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - /* update fog color */ - GLubyte col[4]; - col[0]=(unsigned int)(255*ctx->Fog.Color[0]); - col[1]=(unsigned int)(255*ctx->Fog.Color[1]); - col[2]=(unsigned int)(255*ctx->Fog.Color[2]); - col[3]=(unsigned int)(255*ctx->Fog.Color[3]); - FX_grFogColorValue(FXCOLOR4(col)); - - if(fxMesa->fogTableMode != ctx->Fog.Mode || - fxMesa->fogDensity != ctx->Fog.Density || - fxMesa->fogStart != ctx->Fog.Start || - fxMesa->fogEnd != ctx->Fog.End) { - /* reload the fog table */ - switch (ctx->Fog.Mode) { - case GL_LINEAR: - guFogGenerateLinear(fxMesa->fogTable, ctx->Fog.Start, ctx->Fog.End); - break; - case GL_EXP: - guFogGenerateExp(fxMesa->fogTable, ctx->Fog.Density); - break; - case GL_EXP2: - guFogGenerateExp2(fxMesa->fogTable, ctx->Fog.Density); - break; - default: - ; - } - fxMesa->fogTableMode = ctx->Fog.Mode; - fxMesa->fogDensity = ctx->Fog.Density; - fxMesa->fogStart = ctx->Fog.Start; - fxMesa->fogEnd = ctx->Fog.End; - } - - FX_grFogTable(fxMesa->fogTable); - FX_grFogMode(GR_FOG_WITH_TABLE); - } - else { - FX_grFogMode(GR_FOG_DISABLE); - } -} - -void fxDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *params ) -{ - FX_CONTEXT(ctx)->new_state |= FX_NEW_FOG; - ctx->Driver.RenderStart = fxSetupFXUnits; /* XXX why is this here? */ -} - -/************************************************************************/ -/************************** Scissor Test SetUp **************************/ -/************************************************************************/ - -/* This routine is used in managing the lock state, and therefore can't lock */ -void fxSetScissorValues(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - int xmin, xmax; - int ymin, ymax, check; - - if (ctx->Scissor.Enabled) { - xmin=ctx->Scissor.X; - xmax=ctx->Scissor.X+ctx->Scissor.Width; - ymin=ctx->Scissor.Y; - ymax=ctx->Scissor.Y+ctx->Scissor.Height; - check=1; - } else { - xmin=0; - ymin=0; - xmax=fxMesa->width; - ymax=fxMesa->height; - check=0; - } - xmin+=fxMesa->x_offset; - xmax+=fxMesa->x_offset; - ymin+=fxMesa->y_delta; - ymax+=fxMesa->y_delta; - if (xmin<fxMesa->clipMinX) xmin=fxMesa->clipMinX; - if (xmax>fxMesa->clipMaxX) xmax=fxMesa->clipMaxX; - if (ymin<fxMesa->screen_height-fxMesa->clipMaxY) - ymin=fxMesa->screen_height-fxMesa->clipMaxY; - if (ymax>fxMesa->screen_height-fxMesa->clipMinY) - ymax=fxMesa->screen_height-fxMesa->clipMinY; - FX_grClipWindow_NoLock(xmin, ymin, xmax, ymax); -} - -static void fxSetupScissor(GLcontext *ctx) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - if (!fxMesa->needClip) { - BEGIN_BOARD_LOCK(); - fxSetScissorValues(ctx); - END_BOARD_LOCK(); - } -} - -void fxDDScissor( GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h ) -{ - FX_CONTEXT(ctx)->new_state |= FX_NEW_SCISSOR; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -/************************************************************************/ -/*************************** Cull mode setup ****************************/ -/************************************************************************/ - - -void fxDDCullFace(GLcontext *ctx, GLenum mode) -{ - (void) mode; - FX_CONTEXT(ctx)->new_state |= FX_NEW_CULL; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - -void fxDDFrontFace(GLcontext *ctx, GLenum mode) -{ - (void) mode; - FX_CONTEXT(ctx)->new_state |= FX_NEW_CULL; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - - -static void fxSetupCull(GLcontext *ctx) -{ - if (ctx->Polygon.CullFlag) { - switch (ctx->Polygon.CullFaceMode) { - case GL_BACK: - if (ctx->Polygon.FrontFace==GL_CCW) - FX_CONTEXT(ctx)->cullMode=GR_CULL_NEGATIVE; - else - FX_CONTEXT(ctx)->cullMode=GR_CULL_POSITIVE; - break; - case GL_FRONT: - if(ctx->Polygon.FrontFace==GL_CCW) - FX_CONTEXT(ctx)->cullMode=GR_CULL_POSITIVE; - else - FX_CONTEXT(ctx)->cullMode=GR_CULL_NEGATIVE; - break; - case GL_FRONT_AND_BACK: - FX_CONTEXT(ctx)->cullMode=GR_CULL_DISABLE; - break; - default: - break; - } - } else FX_CONTEXT(ctx)->cullMode=GR_CULL_DISABLE; - FX_grCullMode(FX_CONTEXT(ctx)->cullMode); -} - - -/************************************************************************/ -/****************************** DD Enable ******************************/ -/************************************************************************/ - -void fxDDEnable(GLcontext *ctx, GLenum cap, GLboolean state) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - tfxUnitsState *us = &fxMesa->unitsState; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDEnable(...)\n"); - } - - switch(cap) { - case GL_ALPHA_TEST: - if(state!=us->alphaTestEnabled) { - us->alphaTestEnabled=state; - fxMesa->new_state |= FX_NEW_ALPHA; - ctx->Driver.RenderStart = fxSetupFXUnits; - } - break; - case GL_BLEND: - if(state!=us->blendEnabled) { - us->blendEnabled=state; - fxMesa->new_state |= FX_NEW_BLEND; - ctx->Driver.RenderStart = fxSetupFXUnits; - } - break; - case GL_DEPTH_TEST: - fxMesa->new_state |= FX_NEW_DEPTH; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - case GL_DITHER: - if (state) - FX_grDitherMode(GR_DITHER_4x4); - else - FX_grDitherMode(GR_DITHER_DISABLE); - break; - case GL_SCISSOR_TEST: - fxMesa->new_state |= FX_NEW_SCISSOR; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - case GL_SHARED_TEXTURE_PALETTE_EXT: - fxDDTexUseGlbPalette(ctx, state); - break; - case GL_FOG: - fxMesa->new_state |= FX_NEW_FOG; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - case GL_CULL_FACE: - fxMesa->new_state |= FX_NEW_CULL; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - case GL_LINE_SMOOTH: - case GL_LINE_STIPPLE: - case GL_POINT_SMOOTH: - case GL_POLYGON_SMOOTH: - case GL_TEXTURE_2D: - fxMesa->new_state |= FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - case GL_STENCIL_TEST: - fxMesa->new_state |= FX_NEW_STENCIL; - ctx->Driver.RenderStart = fxSetupFXUnits; - break; - default: - ; /* no-op */ - } -} - - -#if 0 -/* - Multipass to do GL_BLEND texture functions - Cf*(1-Ct) has already been written to the buffer during the first pass - Cc*Ct gets written during the second pass (in this function) - Everything gets reset in the third call (in this function) -*/ -static GLboolean fxMultipassBlend(struct vertex_buffer *VB, GLuint pass) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - switch (pass) { - case 1: - /* Add Cc*Ct */ - fxMesa->restoreUnitsState=fxMesa->unitsState; - if (ctx->Depth.Mask) { - /* We don't want to check or change the depth buffers */ - switch (ctx->Depth.Func) { - case GL_NEVER: - case GL_ALWAYS: - break; - default: - fxDDDepthFunc(ctx, GL_EQUAL); - break; - } - fxDDDepthMask(ctx, FALSE); - } - /* - * Disable stencil as well. - */ - if (ctx->Stencil.Enabled) { - fxDDEnableStencil(ctx, GL_FALSE); - } - /* Enable Cc*Ct mode */ - /* XXX Set the Constant Color ? */ - fxDDEnable(ctx, GL_BLEND, GL_TRUE); - fxDDBlendFunc(ctx, XXX, XXX); - fxSetupTextureSingleTMU(ctx, XXX); - fxSetupBlend(ctx); - fxSetupDepthTest(ctx); - break; - - case 2: - /* Reset everything back to normal */ - fxMesa->unitsState = fxMesa->restoreUnitsState; - fxMesa->setupdone &= XXX; - fxSetupTextureSingleTMU(ctx, XXX); - fxSetupBlend(ctx); - fxSetupDepthTest(ctx); - fxSetupStencilText(ctx); - break; - } - - return pass==1; -} -#endif - -/************************************************************************/ -/******************** Fake Multitexture Support *************************/ -/************************************************************************/ - -/* Its considered cheeky to try to fake ARB multitexture by doing - * multipass rendering, because it is not possible to emulate the full - * spec in this way. The fact is that the voodoo 2 supports only a - * subset of the possible multitexturing modes, and it is possible to - * support almost the same subset using multipass blending on the - * voodoo 1. In all other cases for both voodoo 1 and 2, we fall back - * to software rendering, satisfying the spec if not the user. - */ -static GLboolean fxMultipassTexture( struct vertex_buffer *VB, GLuint pass ) -{ - GLcontext *ctx = VB->ctx; - fxVertex *v = FX_DRIVER_DATA(VB)->verts; - fxVertex *last = FX_DRIVER_DATA(VB)->last_vert; - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - switch (pass) { - case 1: - if (MESA_VERBOSE&(VERBOSE_DRIVER|VERBOSE_PIPELINE|VERBOSE_TEXTURE)) - fprintf(stderr, "fxmesa: Second texture pass\n"); - - for ( ; v != last ; v++) { - v->f[S0COORD] = v->f[S1COORD]; - v->f[T0COORD] = v->f[T1COORD]; - } - - fxMesa->restoreUnitsState = fxMesa->unitsState; - fxMesa->tmu_source[0] = 1; - - if (ctx->Depth.Mask) { - switch (ctx->Depth.Func) { - case GL_NEVER: - case GL_ALWAYS: - break; - default: - /*fxDDDepthFunc( ctx, GL_EQUAL );*/ - FX_grDepthBufferFunction(GR_CMP_EQUAL); - break; - } - - /*fxDDDepthMask( ctx, GL_FALSE ); */ - FX_grDepthMask(FXFALSE); - } - fxDDEnableStencil(ctx, GL_FALSE); - if (ctx->Texture.Unit[1].EnvMode == GL_MODULATE) { - fxDDEnable( ctx, GL_BLEND, GL_TRUE ); - fxDDBlendFunc( ctx, GL_DST_COLOR, GL_ZERO ); - } - - fxSetupTextureSingleTMU( ctx, 1 ); - fxSetupBlend( ctx ); - fxSetupDepthTest( ctx ); - break; - - case 2: - /* Restore original state. - */ - fxMesa->tmu_source[0] = 0; - fxMesa->unitsState = fxMesa->restoreUnitsState; - fxMesa->setupdone &= ~SETUP_TMU0; - fxSetupTextureSingleTMU( ctx, 0 ); - fxSetupBlend( ctx ); - fxSetupDepthTest( ctx ); - fxSetupStencilTest( ctx ); - break; - } - - return pass == 1; -} - - -/************************************************************************/ -/************************** Changes to units state **********************/ -/************************************************************************/ - - -/* All units setup is handled under texture setup. - */ -void fxDDShadeModel(GLcontext *ctx, GLenum mode) -{ - FX_CONTEXT(ctx)->new_state |= FX_NEW_TEXTURING; - ctx->Driver.RenderStart = fxSetupFXUnits; -} - - - -/************************************************************************/ -/****************************** Units SetUp *****************************/ -/************************************************************************/ -static void gl_print_fx_state_flags( const char *msg, GLuint flags ) -{ - fprintf(stderr, - "%s: (0x%x) %s%s%s%s%s%s%s\n", - msg, - flags, - (flags & FX_NEW_TEXTURING) ? "texture, " : "", - (flags & FX_NEW_BLEND) ? "blend, " : "", - (flags & FX_NEW_ALPHA) ? "alpha, " : "", - (flags & FX_NEW_FOG) ? "fog, " : "", - (flags & FX_NEW_SCISSOR) ? "scissor, " : "", - (flags & FX_NEW_COLOR_MASK) ? "colormask, " : "", - (flags & FX_NEW_CULL) ? "cull, " : ""); -} - -void fxSetupFXUnits( GLcontext *ctx ) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint newstate = fxMesa->new_state; - - if (MESA_VERBOSE&VERBOSE_DRIVER) - gl_print_fx_state_flags("fxmesa: fxSetupFXUnits", newstate); - - if (newstate) { - if (newstate & FX_NEW_TEXTURING) - fxSetupTexture(ctx); - - if (newstate & FX_NEW_BLEND) - fxSetupBlend(ctx); - - if (newstate & FX_NEW_ALPHA) - fxSetupAlphaTest(ctx); - - if (newstate & FX_NEW_DEPTH) - fxSetupDepthTest(ctx); - - if (newstate & FX_NEW_STENCIL) - fxSetupStencilTest(ctx); - - if (newstate & FX_NEW_FOG) - fxSetupFog(ctx); - - if (newstate & FX_NEW_SCISSOR) - fxSetupScissor(ctx); - - if (newstate & FX_NEW_COLOR_MASK) - fxSetupColorMask(ctx); - - if (newstate & FX_NEW_CULL) - fxSetupCull(ctx); - fxMesa->new_state = 0; -/* ctx->Driver.RenderStart = 0; */ - } -} - -#else - - -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_setup(void) -{ - return 0; -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxtexman.c b/xc/extras/Mesa/src/FX/fxtexman.c deleted file mode 100644 index ae38d2d76..000000000 --- a/xc/extras/Mesa/src/FX/fxtexman.c +++ /dev/null @@ -1,777 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxtexman.c - 3Dfx VooDoo texture memory functions */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - -#include "fxdrv.h" - -int texSwaps=0; - -#define FX_2MB_SPLIT 0x200000 - -static struct gl_texture_object *fxTMFindOldestObject(fxMesaContext fxMesa, - int tmu); - - -#ifdef TEXSANITY -static void fubar() -{ -} - - /* Sanity Check */ -static void sanity(fxMesaContext fxMesa) -{ - MemRange *tmp, *prev, *pos; - - prev=0; - tmp = fxMesa->tmFree[0]; - while (tmp) { - if (!tmp->startAddr && !tmp->endAddr) { - fprintf(stderr, "Textures fubar\n"); - fubar(); - } - if (tmp->startAddr>=tmp->endAddr) { - fprintf(stderr, "Node fubar\n"); - fubar(); - } - if (prev && (prev->startAddr>=tmp->startAddr || - prev->endAddr>tmp->startAddr)) { - fprintf(stderr, "Sorting fubar\n"); - fubar(); - } - prev=tmp; - tmp=tmp->next; - } - prev=0; - tmp = fxMesa->tmFree[1]; - while (tmp) { - if (!tmp->startAddr && !tmp->endAddr) { - fprintf(stderr, "Textures fubar\n"); - fubar(); - } - if (tmp->startAddr>=tmp->endAddr) { - fprintf(stderr, "Node fubar\n"); - fubar(); - } - if (prev && (prev->startAddr>=tmp->startAddr || - prev->endAddr>tmp->startAddr)) { - fprintf(stderr, "Sorting fubar\n"); - fubar(); - } - prev=tmp; - tmp=tmp->next; - } -} -#endif - -static MemRange *fxTMNewRangeNode(fxMesaContext fxMesa, FxU32 start, FxU32 end) { - MemRange *result=0; - - if (fxMesa->tmPool) { - result=fxMesa->tmPool; - fxMesa->tmPool=fxMesa->tmPool->next; - } else { - if (!(result=MALLOC(sizeof(MemRange)))) { - fprintf(stderr, "fxDriver: out of memory!\n"); - fxCloseHardware(); - exit(-1); - } - } - result->startAddr=start; - result->endAddr=end; - result->next=0; - return result; -} - -static void fxTMDeleteRangeNode(fxMesaContext fxMesa, MemRange *range) -{ - range->next=fxMesa->tmPool; - fxMesa->tmPool=range; -} - -static void fxTMUInit(fxMesaContext fxMesa, int tmu) -{ - MemRange *tmn, *last; - FxU32 start,end,blockstart,blockend; - - start=FX_grTexMinAddress(tmu); - end=FX_grTexMaxAddress(tmu); - - if(fxMesa->verbose) { - fprintf(stderr,"Voodoo %s configuration:",(tmu==FX_TMU0) ? "TMU0" : "TMU1"); - fprintf(stderr,"Voodoo Lower texture memory address (%u)\n",(unsigned int)start); - fprintf(stderr,"Voodoo Higher texture memory address (%u)\n",(unsigned int)end); - fprintf(stderr,"Voodoo Splitting Texture memory in 2b blocks:\n"); - } - - fxMesa->freeTexMem[tmu]=end-start; - fxMesa->tmFree[tmu]=NULL; - - last=0; - blockstart=start; - while (blockstart<end) { - if (blockstart+FX_2MB_SPLIT>end) blockend=end; - else blockend=blockstart+FX_2MB_SPLIT; - - if(fxMesa->verbose) - fprintf(stderr,"Voodoo %07u-%07u\n", - (unsigned int)blockstart,(unsigned int)blockend); - - tmn=fxTMNewRangeNode(fxMesa, blockstart, blockend); - - if (last) last->next=tmn; - else fxMesa->tmFree[tmu]=tmn; - last=tmn; - - blockstart+=FX_2MB_SPLIT; - } -} - -static int fxTMFindStartAddr(fxMesaContext fxMesa, GLint tmu, int size) -{ - MemRange *prev, *tmp; - int result; - struct gl_texture_object *obj; - int blockCount, deleteCount; - int largestBlock = 0; - - while (1) { - prev=0; - tmp=fxMesa->tmFree[tmu]; - blockCount = 0; - deleteCount = 0; - while (tmp) { - blockCount++; - if (tmp->endAddr - tmp->startAddr > largestBlock) - largestBlock = tmp->endAddr - tmp->startAddr; - - if (tmp->endAddr-tmp->startAddr>=size) { /* Fits here */ - result=tmp->startAddr; - tmp->startAddr+=size; - if (tmp->startAddr==tmp->endAddr) { /* Empty */ - if (prev) { - prev->next=tmp->next; - } else { - fxMesa->tmFree[tmu]=tmp->next; - } - fxTMDeleteRangeNode(fxMesa, tmp); - deleteCount++; - } - fxMesa->freeTexMem[tmu]-=size; - return result; - } - prev=tmp; - tmp=tmp->next; - } - /* No free space. Discard oldest */ - obj=fxTMFindOldestObject(fxMesa, tmu); - if (!obj) { - fprintf(stderr, "fx Driver: No space for texture\n"); - fprintf(stderr, " requested size = %d\n", size); - fprintf(stderr, " largest block = %d\n", largestBlock); - fprintf(stderr, " tmu = %d\n", tmu); - fprintf(stderr, " block count = %d\n", blockCount); - fprintf(stderr, " delete count = %d\n", deleteCount); - return -1; - } - fxTMMoveOutTM(fxMesa, obj); - texSwaps++; - } -} - -static void fxTMRemoveRange(fxMesaContext fxMesa, GLint tmu, MemRange *range) -{ - MemRange *tmp, *prev; - - if (range->startAddr==range->endAddr) { - fxTMDeleteRangeNode(fxMesa, range); - return; - } - fxMesa->freeTexMem[tmu]+=range->endAddr-range->startAddr; - prev=0; - tmp=fxMesa->tmFree[tmu]; - while (tmp) { - if (range->startAddr>tmp->startAddr) { - prev=tmp; - tmp=tmp->next; - } else break; - } - /* When we create the regions, we make a split at the 2MB boundary. - Now we have to make sure we don't join those 2MB boundary regions - back together again. */ - range->next=tmp; - if (tmp) { - if (range->endAddr==tmp->startAddr && tmp->startAddr&(FX_2MB_SPLIT-1)) { - /* Combine */ - tmp->startAddr=range->startAddr; - fxTMDeleteRangeNode(fxMesa, range); - range=tmp; - } - } - if (prev) { - if (prev->endAddr==range->startAddr && range->startAddr&(FX_2MB_SPLIT-1)) { - /* Combine */ - prev->endAddr=range->endAddr; - prev->next=range->next; - fxTMDeleteRangeNode(fxMesa, range); - } else prev->next=range; - } else { - fxMesa->tmFree[tmu]=range; - } -} - -static struct gl_texture_object *fxTMFindOldestObject(fxMesaContext fxMesa, - int tmu) -{ - GLuint age, old, lasttime, bindnumber; - tfxTexInfo *info; - struct gl_texture_object *obj, *tmp; - int wrap = 0, anyFound = 0, inTmuCount = 0; - - tmp=fxMesa->glCtx->Shared->TexObjectList; - if (!tmp) return 0; - obj=0; - old=0; - - bindnumber=fxMesa->texBindNumber; - while (tmp) { - info=fxTMGetTexInfo(tmp); - - if (info && info->isInTM) - inTmuCount++; - - if (info && info->isInTM && - ((info->whichTMU==tmu) || (info->whichTMU==FX_TMU_BOTH) || - (info->whichTMU==FX_TMU_SPLIT))) { - lasttime=info->lastTimeUsed; - anyFound = 1; - - if (lasttime>bindnumber) { - age=bindnumber+(UINT_MAX-lasttime+1); /* TO DO: check wrap around */ - wrap = 1; - } - else - age=bindnumber-lasttime; - - if (age>=old) { - old=age; - obj=tmp; - } - } - tmp=tmp->Next; - } - if (!obj) { - fprintf(stderr, " wrap = %d anyFound = %d inTmuCount = %d\n", - wrap, anyFound, inTmuCount); - } - return obj; -} - -static MemRange *fxTMAddObj(fxMesaContext fxMesa, - struct gl_texture_object *tObj, - GLint tmu, int texmemsize) -{ - FxU32 startAddr; - MemRange *range; - - startAddr=fxTMFindStartAddr(fxMesa, tmu, texmemsize); - if (startAddr<0 || startAddr > 0xffffff00) { - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - GrTexInfo *info = &(ti->info); - fprintf(stderr, " smallLodLog2 = %d\n", (int) info->smallLodLog2); - fprintf(stderr, " largeLodLog2 = %d\n", (int) info->largeLodLog2); - fprintf(stderr, " aspectRatioLog2 = %d\n", (int) info->aspectRatioLog2); - fprintf(stderr, " format = 0x%x\n", (unsigned int) info->format); - fprintf(stderr, " data = %p\n", info->data); - return 0; - } - range=fxTMNewRangeNode(fxMesa, startAddr, startAddr+texmemsize); - return range; -} - -/* External Functions */ - -void fxTMMoveInTM_NoLock(fxMesaContext fxMesa, struct gl_texture_object *tObj, GLint where) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - int i,l; - int texmemsize; - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxTMMoveInTM(%d)\n",tObj->Name); - } - - fxMesa->stats.reqTexUpload++; - - if (!ti->validated) { - fprintf(stderr,"fx Driver: internal error in fxTMMoveInTM() -> not validated\n"); - fxCloseHardware(); - exit(-1); - } - - if (ti->isInTM) { - if (ti->whichTMU==where) return; - if (where==FX_TMU_SPLIT || ti->whichTMU==FX_TMU_SPLIT) - fxTMMoveOutTM_NoLock(fxMesa, tObj); - else { - if (ti->whichTMU==FX_TMU_BOTH) return; - where=FX_TMU_BOTH; - } - } - - if (MESA_VERBOSE&(VERBOSE_DRIVER|VERBOSE_TEXTURE)) { - fprintf(stderr,"fxmesa: downloading %x (%d) in texture memory in %d\n",(GLuint)tObj,tObj->Name,where); - } - - ti->whichTMU=(FxU32)where; - - switch (where) { - case FX_TMU0: - case FX_TMU1: - texmemsize=(int)FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, - &(ti->info)); - ti->tm[where]=fxTMAddObj(fxMesa, tObj, where, texmemsize); - fxMesa->stats.memTexUpload+=texmemsize; - - for (i=FX_largeLodValue(ti->info), l=ti->minLevel; - i<=FX_smallLodValue(ti->info); - i++,l++) - FX_grTexDownloadMipMapLevel_NoLock(where, - ti->tm[where]->startAddr, - FX_valueToLod(i), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - ti->mipmapLevel[l].data); - break; - case FX_TMU_SPLIT: - texmemsize=(int)FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_ODD, - &(ti->info)); - ti->tm[FX_TMU0]=fxTMAddObj(fxMesa, tObj, FX_TMU0, texmemsize); - fxMesa->stats.memTexUpload+=texmemsize; - - texmemsize=(int)FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_EVEN, - &(ti->info)); - ti->tm[FX_TMU1]=fxTMAddObj(fxMesa, tObj, FX_TMU1, texmemsize); - fxMesa->stats.memTexUpload+=texmemsize; - - for (i=FX_largeLodValue(ti->info),l=ti->minLevel; - i<=FX_smallLodValue(ti->info); - i++,l++) { - FX_grTexDownloadMipMapLevel_NoLock(GR_TMU0, - ti->tm[FX_TMU0]->startAddr, - FX_valueToLod(i), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_ODD, - ti->mipmapLevel[l].data); - - FX_grTexDownloadMipMapLevel_NoLock(GR_TMU1, - ti->tm[FX_TMU1]->startAddr, - FX_valueToLod(i), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_EVEN, - ti->mipmapLevel[l].data); - } - break; - case FX_TMU_BOTH: - texmemsize=(int)FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, - &(ti->info)); - ti->tm[FX_TMU0]=fxTMAddObj(fxMesa, tObj, FX_TMU0, texmemsize); - fxMesa->stats.memTexUpload+=texmemsize; - - texmemsize=(int)FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, - &(ti->info)); - ti->tm[FX_TMU1]=fxTMAddObj(fxMesa, tObj, FX_TMU1, texmemsize); - fxMesa->stats.memTexUpload+=texmemsize; - - for (i=FX_largeLodValue(ti->info),l=ti->minLevel; - i<=FX_smallLodValue(ti->info); - i++,l++) { - FX_grTexDownloadMipMapLevel_NoLock(GR_TMU0, - ti->tm[FX_TMU0]->startAddr, - FX_valueToLod(i), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - ti->mipmapLevel[l].data); - - FX_grTexDownloadMipMapLevel_NoLock(GR_TMU1, - ti->tm[FX_TMU1]->startAddr, - FX_valueToLod(i), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - ti->mipmapLevel[l].data); - } - break; - default: - fprintf(stderr,"fx Driver: internal error in fxTMMoveInTM() -> wrong tmu (%d)\n",where); - fxCloseHardware(); - exit(-1); - } - - fxMesa->stats.texUpload++; - - ti->isInTM=GL_TRUE; -} - -void fxTMMoveInTM(fxMesaContext fxMesa, struct gl_texture_object *tObj, GLint where) { - BEGIN_BOARD_LOCK(); - fxTMMoveInTM_NoLock(fxMesa, tObj, where); - END_BOARD_LOCK(); -} - -void fxTMReloadMipMapLevel(fxMesaContext fxMesa, struct gl_texture_object *tObj, GLint level) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - GrLOD_t lodlevel; - GLint tmu; - - if (!ti->validated) { - fprintf(stderr,"fx Driver: internal error in fxTMReloadMipMapLevel() -> not validated\n"); - fxCloseHardware(); - exit(-1); - } - - tmu=(int)ti->whichTMU; - fxTMMoveInTM(fxMesa, tObj, tmu); - - fxTexGetInfo(ti->mipmapLevel[0].width,ti->mipmapLevel[0].height, - &lodlevel, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - -#ifdef FX_GLIDE3 - lodlevel-=level; -#else - lodlevel+=level; -#endif - switch(tmu) { - case FX_TMU0: - case FX_TMU1: - FX_grTexDownloadMipMapLevel(tmu, - ti->tm[tmu]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - ti->mipmapLevel[level].data); - break; - case FX_TMU_SPLIT: - FX_grTexDownloadMipMapLevel(GR_TMU0, - ti->tm[GR_TMU0]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_ODD, - ti->mipmapLevel[level].data); - - FX_grTexDownloadMipMapLevel(GR_TMU1, - ti->tm[GR_TMU1]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_EVEN, - ti->mipmapLevel[level].data); - break; - case FX_TMU_BOTH: - FX_grTexDownloadMipMapLevel(GR_TMU0, - ti->tm[GR_TMU0]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - ti->mipmapLevel[level].data); - - FX_grTexDownloadMipMapLevel(GR_TMU1, - ti->tm[GR_TMU1]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - ti->mipmapLevel[level].data); - break; - - default: - fprintf(stderr,"fx Driver: internal error in fxTMReloadMipMapLevel() -> wrong tmu (%d)\n",tmu); - fxCloseHardware(); - exit(-1); - } -} - -void fxTMReloadSubMipMapLevel(fxMesaContext fxMesa, - struct gl_texture_object *tObj, - GLint level, GLint yoffset, GLint height) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - GrLOD_t lodlevel; - unsigned short *data; - GLint tmu; - - if(!ti->validated) { - fprintf(stderr,"fx Driver: internal error in fxTMReloadSubMipMapLevel() -> not validated\n"); - fxCloseHardware(); - exit(-1); - } - - tmu=(int)ti->whichTMU; - fxTMMoveInTM(fxMesa, tObj, tmu); - - fxTexGetInfo(ti->mipmapLevel[0].width, ti->mipmapLevel[0].height, - &lodlevel, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - data=ti->mipmapLevel[level].data + - yoffset*ti->mipmapLevel[level].width*ti->mipmapLevel[level].texelSize; - - switch(tmu) { - case FX_TMU0: - case FX_TMU1: - FX_grTexDownloadMipMapLevelPartial(tmu, - ti->tm[tmu]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)+level), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - data, - yoffset,yoffset+height-1); - break; - case FX_TMU_SPLIT: - FX_grTexDownloadMipMapLevelPartial(GR_TMU0, - ti->tm[FX_TMU0]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)+level), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_ODD, - data, - yoffset,yoffset+height-1); - - FX_grTexDownloadMipMapLevelPartial(GR_TMU1, - ti->tm[FX_TMU1]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)+level), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_EVEN, - data, - yoffset,yoffset+height-1); - break; - case FX_TMU_BOTH: - FX_grTexDownloadMipMapLevelPartial(GR_TMU0, - ti->tm[FX_TMU0]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)+level), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - data, - yoffset,yoffset+height-1); - - FX_grTexDownloadMipMapLevelPartial(GR_TMU1, - ti->tm[FX_TMU1]->startAddr, - FX_valueToLod(FX_lodToValue(lodlevel)+level), - FX_largeLodLog2(ti->info), - FX_aspectRatioLog2(ti->info), - ti->info.format, - GR_MIPMAPLEVELMASK_BOTH, - data, - yoffset,yoffset+height-1); - break; - default: - fprintf(stderr,"fx Driver: internal error in fxTMReloadSubMipMapLevel() -> wrong tmu (%d)\n",tmu); - fxCloseHardware(); - exit(-1); - } -} - -void fxTMMoveOutTM(fxMesaContext fxMesa, struct gl_texture_object *tObj) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxTMMoveOutTM(%x (%d))\n",(GLuint)tObj,tObj->Name); - } - - if (!ti->isInTM) return; - - switch(ti->whichTMU) { - case FX_TMU0: - case FX_TMU1: - fxTMRemoveRange(fxMesa, (int)ti->whichTMU, ti->tm[ti->whichTMU]); - break; - case FX_TMU_SPLIT: - case FX_TMU_BOTH: - fxTMRemoveRange(fxMesa, FX_TMU0, ti->tm[FX_TMU0]); - fxTMRemoveRange(fxMesa, FX_TMU1, ti->tm[FX_TMU1]); - break; - default: - fprintf(stderr,"fx Driver: internal error in fxTMMoveOutTM()\n"); - fxCloseHardware(); - exit(-1); - } - - ti->isInTM=GL_FALSE; - ti->whichTMU=FX_TMU_NONE; -} - -void fxTMFreeTexture(fxMesaContext fxMesa, struct gl_texture_object *tObj) -{ - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - int i; - - fxTMMoveOutTM(fxMesa, tObj); - - for (i=0; i<MAX_TEXTURE_LEVELS; i++) { - if (ti->mipmapLevel[i].data) { - FREE(ti->mipmapLevel[i].data); - ti->mipmapLevel[i].data = NULL; - } - } - switch (ti->whichTMU) { - case FX_TMU0: - case FX_TMU1: - fxTMDeleteRangeNode(fxMesa, ti->tm[ti->whichTMU]); - break; - case FX_TMU_SPLIT: - case FX_TMU_BOTH: - fxTMDeleteRangeNode(fxMesa, ti->tm[FX_TMU0]); - fxTMDeleteRangeNode(fxMesa, ti->tm[FX_TMU1]); - break; - } -} - -void fxTMInit(fxMesaContext fxMesa) -{ - fxMesa->texBindNumber=0; - fxMesa->tmPool=0; - - fxTMUInit(fxMesa,FX_TMU0); - - if(fxMesa->haveTwoTMUs) - fxTMUInit(fxMesa,FX_TMU1); -} - -void fxTMClose(fxMesaContext fxMesa) -{ - MemRange *tmp, *next; - - tmp=fxMesa->tmPool; - while (tmp) { - next=tmp->next; - FREE(tmp); - tmp=next; - } - tmp=fxMesa->tmFree[FX_TMU0]; - while (tmp) { - next=tmp->next; - FREE(tmp); - tmp=next; - } - if (fxMesa->haveTwoTMUs) { - tmp=fxMesa->tmFree[FX_TMU1]; - while (tmp) { - next=tmp->next; - FREE(tmp); - tmp=next; - } - } -} - -void -fxTMRestoreTextures_NoLock(fxMesaContext ctx) { - tfxTexInfo *ti; - struct gl_texture_object *tObj; - int i, where; - - tObj=ctx->glCtx->Shared->TexObjectList; - while (tObj) { - ti=fxTMGetTexInfo(tObj); - if (ti && ti->isInTM) { - for (i=0; i<MAX_TEXTURE_UNITS; i++) - if (ctx->glCtx->Texture.Unit[i].Current==tObj) { - /* Force the texture onto the board, as it could be in use */ - where=ti->whichTMU; - fxTMMoveOutTM_NoLock(ctx, tObj); - fxTMMoveInTM_NoLock(ctx, tObj, where); - break; - } - if (i==MAX_TEXTURE_UNITS) /* Mark the texture as off the board */ - fxTMMoveOutTM_NoLock(ctx, tObj); - } - tObj=tObj->Next; - } -} - -#else - - -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_texman(void) -{ - return 0; -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxtritmp.h b/xc/extras/Mesa/src/FX/fxtritmp.h deleted file mode 100644 index 6411d167a..000000000 --- a/xc/extras/Mesa/src/FX/fxtritmp.h +++ /dev/null @@ -1,474 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -static void TAG(fx_tri)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, GLuint pv) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - struct vertex_buffer *VB=ctx->VB; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GrVertex *v1 = (GrVertex *)gWin[e1].f; - GrVertex *v2 = (GrVertex *)gWin[e2].f; - GrVertex *v3 = (GrVertex *)gWin[e3].f; - - (void) fxMesa; - - if (IND & (FX_TWOSIDE|FX_OFFSET)) - { - GLfloat ex = v1->x - v3->x; - GLfloat ey = v1->y - v3->y; - GLfloat fx = v2->x - v3->x; - GLfloat fy = v2->y - v3->y; - GLfloat c = ex*fy-ey*fx; - - if (IND & FX_TWOSIDE) { - GLuint facing = (c<0.0) ^ ctx->Polygon.FrontBit; - GLubyte (*color)[4] = VB->Color[facing]->data; - if (IND & FX_FLAT) { - GOURAUD2(v1,color[pv]); - GOURAUD2(v2,color[pv]); - GOURAUD2(v3,color[pv]); - } else { - GOURAUD2(v1,color[e1]); - GOURAUD2(v2,color[e2]); - GOURAUD2(v3,color[e3]); - } - } - - /* Should apply a factor to ac to compensate for different x/y - * scaling introduced in the Viewport matrix. - * - * The driver should supply scaling factors for 'factor' and 'units'. - */ - if (IND & FX_OFFSET) { - GLfloat offset = ctx->Polygon.OffsetUnits; - - if (c * c > 1e-16) { - GLfloat factor = ctx->Polygon.OffsetFactor; - GLfloat ez = v1->ooz - v3->ooz; - GLfloat fz = v2->ooz - v3->ooz; - GLfloat a = ey*fz-ez*fy; - GLfloat b = ez*fx-ex*fz; - GLfloat ic = 1.0 / c; - GLfloat ac = a * ic; - GLfloat bc = b * ic; - if (ac<0.0F) ac = -ac; - if (bc<0.0F) bc = -bc; - offset += MAX2( ac, bc ) * factor; - } - /* Probably a lot quicker just to nudge the z values and put - * them back afterwards. - */ - FX_grDepthBiasLevel((int)offset); - } - } - else if (IND & FX_FLAT) { - GLubyte (*color)[4] = VB->Color[0]->data; - GOURAUD2(v1,color[pv]); - GOURAUD2(v2,color[pv]); - GOURAUD2(v3,color[pv]); - } - - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - FXFALSE); - - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - } - - if (IND & FX_ANTIALIAS) - FX_grAADrawTriangle(v1, v2, v3, FXTRUE, FXTRUE, FXTRUE); - else - FX_grDrawTriangle(v1, v2, v3); - - /* Might be quicker to do two passes, one for each buffer? - */ - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - - if(ctx->Depth.Mask) FX_grDepthMask(FXTRUE); - - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - - if (IND & FX_ANTIALIAS) - FX_grAADrawTriangle(v1,v2,v3, FXTRUE,FXTRUE,FXTRUE); - else - FX_grDrawTriangle(v1, v2, v3); - } -} - - -/* Not worth the space? - */ -static void TAG(fx_quad)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, - GLuint e4, GLuint pv) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - struct vertex_buffer *VB=ctx->VB; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GrVertex *v1 = (GrVertex *)gWin[e1].f; - GrVertex *v2 = (GrVertex *)gWin[e2].f; - GrVertex *v3 = (GrVertex *)gWin[e3].f; - GrVertex *v4 = (GrVertex *)gWin[e4].f; - - (void) fxMesa; - - if (IND & (FX_TWOSIDE|FX_OFFSET)) - { - GLfloat ex = v3->x - v1->x; - GLfloat ey = v3->y - v1->y; - GLfloat fx = v4->x - v2->x; - GLfloat fy = v4->y - v2->y; - GLfloat c = ex*fy-ey*fx; - - if (IND & FX_TWOSIDE) { - GLuint facing = (c<0.0) ^ ctx->Polygon.FrontBit; - GLubyte (*color)[4] = VB->Color[facing]->data; - if (IND & FX_FLAT) { - GOURAUD2(v1,color[pv]); - GOURAUD2(v2,color[pv]); - GOURAUD2(v3,color[pv]); - GOURAUD2(v4,color[pv]); - } else { - GOURAUD2(v1,color[e1]); - GOURAUD2(v2,color[e2]); - GOURAUD2(v3,color[e3]); - GOURAUD2(v4,color[e4]); - } - } - - /* Should apply a factor to ac to compensate for different x/y - * scaling introduced in the Viewport matrix. - * - * The driver should supply scaling factors for 'factor' and 'units'. - */ - if (IND & FX_OFFSET) { - GLfloat offset = ctx->Polygon.OffsetUnits; - - if (c * c > 1e-16) { - GLfloat factor = ctx->Polygon.OffsetFactor; - GLfloat ez = v3->ooz - v1->ooz; - GLfloat fz = v4->ooz - v2->ooz; - GLfloat a = ey*fz-ez*fy; - GLfloat b = ez*fx-ex*fz; - GLfloat ic = 1.0 / c; - GLfloat ac = a * ic; - GLfloat bc = b * ic; - if (ac<0.0F) ac = -ac; - if (bc<0.0F) bc = -bc; - offset += MAX2( ac, bc ) * factor; - } - /* Probably a lot quicker just to nudge the z values and put - * them back afterwards. - */ - FX_grDepthBiasLevel((int)offset); - } - } - else if (IND & FX_FLAT) { - GLubyte (*color)[4] = VB->Color[0]->data; - GOURAUD2(v1,color[pv]); - GOURAUD2(v2,color[pv]); - GOURAUD2(v3,color[pv]); - GOURAUD2(v4,color[pv]); - } - - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - FXFALSE); - - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - } - - if (IND & FX_ANTIALIAS) { - FX_grAADrawTriangle(v1, v2, v4, FXTRUE, FXTRUE, FXTRUE); - FX_grAADrawTriangle(v2, v3, v4, FXTRUE, FXTRUE, FXTRUE); - } else { - FX_grDrawTriangle(v1, v2, v4); - FX_grDrawTriangle(v2, v3, v4); - } - - /* Might be quicker to do two passes, one for each buffer? - */ - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - - if(ctx->Depth.Mask) FX_grDepthMask(FXTRUE); - - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - - if (IND & FX_ANTIALIAS) { - FX_grAADrawTriangle(v1, v2, v4, FXTRUE, FXTRUE, FXTRUE); - FX_grAADrawTriangle(v2, v3, v4, FXTRUE, FXTRUE, FXTRUE); - } else { - FX_grDrawTriangle(v1, v2, v4); - FX_grDrawTriangle(v2, v3, v4); - } - } -} - -#define DRAW_LINE(tmp0, tmp1, width) \ - do { \ - const float xoff = 0.125, yoff = 0.125; \ - GrVertex verts[4]; \ - float dx, dy, wx, wy; \ - \ - dx = tmp0->x - tmp1->x; \ - dy = tmp0->y - tmp1->y; \ - \ - if (dx * dx > dy * dy) { \ - wx = 0; \ - wy = width; \ - } else { \ - wx = width; \ - wy = 0; \ - } \ - \ - verts[0] = *tmp0; \ - verts[1] = *tmp0; \ - verts[2] = *tmp1; \ - verts[3] = *tmp1; \ - \ - verts[0].x = tmp0->x - wx + xoff; \ - verts[0].y = tmp0->y - wy + yoff; \ - \ - verts[1].x = tmp0->x + wx + xoff; \ - verts[1].y = tmp0->y + wy + yoff; \ - \ - verts[2].x = tmp1->x + wx + xoff; \ - verts[2].y = tmp1->y + wy + yoff; \ - \ - verts[3].x = tmp1->x - wx + xoff; \ - verts[3].y = tmp1->y - wy + yoff; \ - \ - FX_grDrawPolygonVertexList(4, verts); \ - } while (0) - -#if (IND & FX_OFFSET) == 0 -static void TAG(fx_line)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint pv) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - struct vertex_buffer *VB=ctx->VB; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLubyte (* const color)[4] = VB->ColorPtr->data; - GrVertex *v1 = (GrVertex *)gWin[e1].f; - GrVertex *v2 = (GrVertex *)gWin[e2].f; - GLfloat w = ctx->Line.Width*.5; - - if (IND & FX_FLAT) { - v1->r = v2->r = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][0]); - v1->g = v2->g = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][1]); - v1->b = v2->b = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][2]); - v1->a = v2->a = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][3]); - } - else if (IND & FX_TWOSIDE) - { - /* XXX use signed area of the polygon to determine front/back color choice */ - GOURAUD2(v1,color[e1]); - GOURAUD2(v2,color[e2]); - } - - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - FXFALSE); - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - } - - if (IND & FX_ANTIALIAS) - FX_grAADrawLine(v1,v2); - else - DRAW_LINE(v1,v2,w); - - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - - if(ctx->Depth.Mask) - FX_grDepthMask(FXTRUE); - - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - - if (IND & FX_ANTIALIAS) - FX_grAADrawLine(v1,v2); - else - DRAW_LINE(v1,v2,w); - } -} -#endif - - -#if (IND & FX_OFFSET) == 0 - -#if IND & FX_FLAT -# if IND & FX_ANTIALIAS -#if FX_USE_PARGB -# define FLAT_COLOR(x,y) GET_PA(gWin[i].f) = y[3]; -#else -# define FLAT_COLOR(x,y) gWin[i].f[ACOORD] = y[3]; \ - FX_VB_COLOR(x, y) -#endif -# else -# define FLAT_COLOR(x,y) FX_VB_COLOR(x, y) -# endif -#else -#define FLAT_COLOR(x,y) -#endif - - -#define DRAW_POINT(i, sz) \ - do { \ - GrVertex verts[4], *tmp; \ - \ - tmp = (GrVertex*)gWin[i].f; \ - verts[0] = *tmp; \ - verts[1] = *tmp; \ - verts[2] = *tmp; \ - verts[3] = *tmp; \ - verts[0].x = verts[3].x = tmp->x + sz; \ - verts[0].y = verts[1].y = tmp->y + sz; \ - verts[2].x = verts[1].x = tmp->x - sz; \ - verts[2].y = verts[3].y = tmp->y - sz; \ - \ - FX_grDrawPolygonVertexList(4, verts); \ - } while (0) - -static void TAG(fx_points)(GLcontext *ctx, GLuint first, GLuint last) -{ - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLubyte (*color)[4] = VB->ColorPtr->data; - GLuint i; - GLfloat sz = ctx->Point.Size * .5; - - (void) color; (void) fxMesa; - - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - FXFALSE); - - FX_grDepthMask(FXFALSE); - FX_grRenderBuffer(GR_BUFFER_BACKBUFFER); - } - - if(!VB->ClipOrMask) { - for(i=first;i<=last;i++) { - FLAT_COLOR(fxMesa, color[i]); - DRAW_POINT(i, sz); - } - } else { - for(i=first;i<=last;i++) { - if(VB->ClipMask[i]==0) { - FLAT_COLOR(fxMesa, color[i]); - DRAW_POINT(i, sz); - } - } - } - - if (IND & FX_FRONT_BACK) { - FX_grColorMask(ctx->Color.ColorMask[RCOMP] || - ctx->Color.ColorMask[GCOMP] || - ctx->Color.ColorMask[BCOMP], - ctx->Color.ColorMask[ACOMP] && fxMesa->haveAlphaBuffer); - if(ctx->Depth.Mask) - FX_grDepthMask(FXTRUE); - FX_grRenderBuffer(GR_BUFFER_FRONTBUFFER); - - - if(!VB->ClipOrMask) { - for(i=first;i<=last;i++) { - FLAT_COLOR(fxMesa, color[i]); - DRAW_POINT(i, sz); - } - } else { - for(i=first;i<=last;i++) { - if(VB->ClipMask[i]==0) { - FLAT_COLOR(fxMesa, color[i]); - DRAW_POINT(i, sz); - } - } - } - } -} - -#endif - - - -static void TAG(init)( void ) -{ - tri_tab[IND] = TAG(fx_tri); - quad_tab[IND] = TAG(fx_quad); - -#if ((IND & FX_OFFSET) == 0) - line_tab[IND] = TAG(fx_line); - points_tab[IND] = TAG(fx_points); -#else - line_tab[IND] = line_tab[IND & ~FX_OFFSET]; - points_tab[IND] = points_tab[IND & ~FX_OFFSET]; -#endif -} - -#undef IND -#undef TAG -#undef FLAT_COLOR -#undef DRAW_POINT diff --git a/xc/extras/Mesa/src/FX/fxvsetup.c b/xc/extras/Mesa/src/FX/fxvsetup.c deleted file mode 100644 index ec7b3cfa1..000000000 --- a/xc/extras/Mesa/src/FX/fxvsetup.c +++ /dev/null @@ -1,575 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxvsetup.c - 3Dfx VooDoo vertices setup functions */ - - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - -#include "fxdrv.h" -#include "mmath.h" -#include "pipeline.h" -#include "fxvsetup.h" - -void fxPrintSetupFlags( const char *msg, GLuint flags ) -{ - fprintf(stderr, "%s: %d %s%s%s%s%s%s\n", - msg, - flags, - (flags & SETUP_XY) ? " xy," : "", - (flags & SETUP_Z) ? " z," : "", - (flags & SETUP_W) ? " w," : "", - (flags & SETUP_RGBA) ? " rgba," : "", - (flags & SETUP_TMU0) ? " tmu0," : "", - (flags & SETUP_TMU1) ? " tmu1," : ""); -} - -static void project_texcoords( struct vertex_buffer *VB, - GLuint tmu_nr, GLuint tc_nr, - GLuint start, GLuint count ) -{ - fxVertex *v = FX_DRIVER_DATA(VB)->verts + start; - GrTmuVertex *tmu = &(((GrVertex *)v->f)->tmuvtx[tmu_nr]); - GLvector4f *vec = VB->TexCoordPtr[tc_nr]; - - GLuint i; - GLuint stride = vec->stride; - GLfloat *data = VEC_ELT(vec, GLfloat, start); - - for (i = start ; i < count ; i++, STRIDE_F(data, stride), v++) { - tmu->oow = v->f[OOWCOORD] * data[3]; - tmu = (GrTmuVertex *)((char *)tmu + sizeof(fxVertex)); - } -} - - -static void copy_w( struct vertex_buffer *VB, - GLuint tmu_nr, - GLuint start, GLuint count ) -{ - fxVertex *v = FX_DRIVER_DATA(VB)->verts + start; - GrTmuVertex *tmu = &(((GrVertex *)v->f)->tmuvtx[tmu_nr]); - GLuint i; - - for (i = start ; i < count ; i++, v++) { - tmu->oow = v->f[OOWCOORD]; - tmu = (GrTmuVertex *)((char *)tmu + sizeof(fxVertex)); - } -} - - -static tfxSetupFunc setupfuncs[0x40]; - - - - -#define IND SETUP_XY -#define NAME fxsetupXY -#include "fxvs_tmp.h" - -#define IND (SETUP_XY|SETUP_Z) -#define NAME fxsetupXYZ -#include "fxvs_tmp.h" - -#define IND (SETUP_XY|SETUP_W) -#define NAME fxsetupXYW -#include "fxvs_tmp.h" - -#define IND (SETUP_XY|SETUP_Z|SETUP_W) -#define NAME fxsetupXYZW -#include "fxvs_tmp.h" - -#define IND (SETUP_RGBA|SETUP_XY) -#define NAME fxsetupXYRGBA -#include "fxvs_tmp.h" - -#define IND (SETUP_RGBA|SETUP_XY|SETUP_Z) -#define NAME fxsetupXYZRGBA -#include "fxvs_tmp.h" - -#define IND (SETUP_RGBA|SETUP_XY|SETUP_W) -#define NAME fxsetupXYWRGBA -#include "fxvs_tmp.h" - -#define IND (SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W) -#define NAME fxsetupXYZWRGBA -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU0|SETUP_XY|SETUP_W) -#define NAME fxsetupXYWT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU0|SETUP_XY|SETUP_Z|SETUP_W) -#define NAME fxsetupXYZWT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_XY|SETUP_W) -#define NAME fxsetupXYWT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_XY|SETUP_Z|SETUP_W) -#define NAME fxsetupXYZWT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_W) -#define NAME fxsetupXYWRGBAT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W) -#define NAME fxsetupXYZWRGBAT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_W) -#define NAME fxsetupXYWRGBAT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W) -#define NAME fxsetupXYZWRGBAT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_RGBA) -#define NAME fxsetupRGBA -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU0) -#define NAME fxsetupT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1) -#define NAME fxsetupT1 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_TMU0) -#define NAME fxsetupT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU0|SETUP_RGBA) -#define NAME fxsetupRGBAT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_RGBA) -#define NAME fxsetupRGBAT1 -#include "fxvs_tmp.h" - -#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA) -#define NAME fxsetupRGBAT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_RGBA) -#define NAME fxsetupWRGBA -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_TMU0) -#define NAME fxsetupWT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_TMU1) -#define NAME fxsetupWT1 -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_TMU1|SETUP_TMU0) -#define NAME fxsetupWT0T1 -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_TMU0|SETUP_RGBA) -#define NAME fxsetupWRGBAT0 -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_TMU1|SETUP_RGBA) -#define NAME fxsetupWRGBAT1 -#include "fxvs_tmp.h" - -#define IND (SETUP_W|SETUP_TMU1|SETUP_TMU0|SETUP_RGBA) -#define NAME fxsetupWRGBAT0T1 -#include "fxvs_tmp.h" - - - -void fxDDSetupInit( void ) -{ - setupfuncs[SETUP_XY] = fxsetupXY; - setupfuncs[SETUP_XY|SETUP_Z] = fxsetupXYZ; - setupfuncs[SETUP_XY|SETUP_W] = fxsetupXYW; - setupfuncs[SETUP_XY|SETUP_Z|SETUP_W] = fxsetupXYZW; - - setupfuncs[SETUP_RGBA|SETUP_XY] = fxsetupXYRGBA; - setupfuncs[SETUP_RGBA|SETUP_XY|SETUP_Z] = fxsetupXYZRGBA; - setupfuncs[SETUP_RGBA|SETUP_XY|SETUP_W] = fxsetupXYWRGBA; - setupfuncs[SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W] = fxsetupXYZWRGBA; - - /* If we have texture and xy then we must have w. - * If we have texture1 and w then we must have texture 0. - */ - setupfuncs[SETUP_TMU0|SETUP_XY|SETUP_W] = fxsetupXYWT0; - setupfuncs[SETUP_TMU0|SETUP_XY|SETUP_Z|SETUP_W] = fxsetupXYZWT0; - - setupfuncs[SETUP_TMU1|SETUP_TMU0|SETUP_XY|SETUP_W] = fxsetupXYWT0T1; - setupfuncs[SETUP_TMU1|SETUP_TMU0|SETUP_XY|SETUP_Z|SETUP_W] = fxsetupXYZWT0T1; - - setupfuncs[SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_W] = fxsetupXYWRGBAT0; - setupfuncs[SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W] = fxsetupXYZWRGBAT0; - - setupfuncs[SETUP_TMU1|SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_W] = fxsetupXYWRGBAT0T1; - setupfuncs[SETUP_TMU1|SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W] = fxsetupXYZWRGBAT0T1; - - /* If we don't have xy then we can't have z... w is still a possibility. - */ - setupfuncs[SETUP_RGBA] = fxsetupRGBA; - setupfuncs[SETUP_TMU0] = fxsetupT0; - setupfuncs[SETUP_TMU1] = fxsetupT1; - setupfuncs[SETUP_TMU1|SETUP_TMU0] = fxsetupT0T1; - setupfuncs[SETUP_TMU0|SETUP_RGBA] = fxsetupRGBAT0; - setupfuncs[SETUP_TMU1|SETUP_RGBA] = fxsetupRGBAT1; - setupfuncs[SETUP_TMU1|SETUP_TMU0|SETUP_RGBA] = fxsetupRGBAT0T1; - - setupfuncs[SETUP_W|SETUP_RGBA] = fxsetupWRGBA; - setupfuncs[SETUP_W|SETUP_TMU0] = fxsetupWT0; - setupfuncs[SETUP_W|SETUP_TMU1] = fxsetupWT1; - setupfuncs[SETUP_W|SETUP_TMU1|SETUP_TMU0] = fxsetupWT0T1; - setupfuncs[SETUP_W|SETUP_TMU0|SETUP_RGBA] = fxsetupWRGBAT0; - setupfuncs[SETUP_W|SETUP_TMU1|SETUP_RGBA] = fxsetupWRGBAT1; - setupfuncs[SETUP_W|SETUP_TMU1|SETUP_TMU0|SETUP_RGBA] = fxsetupWRGBAT0T1; - -} - - - -tfxSetupFunc fxDDChooseSetupFunction(GLcontext *ctx) -{ - GLuint setupindex = SETUP_XY|SETUP_Z; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - - fxMesa->setupindex = 0; - - if (ctx->RenderMode != GL_RENDER) - return 0; - - fxMesa->tmu_source[0] = 0; - fxMesa->tmu_source[1] = 1; - - fxMesa->tex_dest[0] = SETUP_TMU0; - fxMesa->tex_dest[1] = SETUP_TMU1; - - if (ctx->Light.ShadeModel == GL_SMOOTH && !ctx->Light.Model.TwoSide) - setupindex |= SETUP_RGBA; - - if (ctx->Fog.Enabled && ctx->FogMode==FOG_FRAGMENT) - setupindex |= SETUP_RGBA|SETUP_W; - - if ((ctx->Texture.ReallyEnabled & (TEXTURE0_2D|TEXTURE0_3D)) == TEXTURE0_2D) - { - /* This doesn't work for non-RGBA textures - if (ctx->Texture.Unit[0].EnvMode == GL_REPLACE) - setupindex &= ~SETUP_RGBA; - */ - setupindex |= SETUP_TMU0|SETUP_W; - } - - if ((ctx->Texture.ReallyEnabled & (TEXTURE1_2D|TEXTURE1_3D)) == TEXTURE1_2D) - { - setupindex |= SETUP_TMU1|SETUP_W; - if (setupindex & SETUP_TMU0) { /* both TMUs in use */ - struct gl_texture_object *tObj=ctx->Texture.Unit[0].CurrentD[2]; - tfxTexInfo *ti=fxTMGetTexInfo(tObj); - - if (ti->whichTMU!=FX_TMU0) { /* TMU0 and TMU1 are swapped */ - fxMesa->tmu_source[0] = 1; fxMesa->tex_dest[1] = SETUP_TMU0; - fxMesa->tmu_source[1] = 0; fxMesa->tex_dest[0] = SETUP_TMU1; - } - } - } - - if (ctx->Color.BlendEnabled) - setupindex |= SETUP_RGBA; - - if (MESA_VERBOSE & (VERBOSE_DRIVER|VERBOSE_PIPELINE|VERBOSE_STATE)) - fxPrintSetupFlags("fxmesa: vertex setup function", setupindex); - - fxMesa->setupindex = setupindex; - fxMesa->view_clip_tri = fxTriViewClipTab[setupindex&0x7]; - fxMesa->clip_tri_stride = fxTriClipStrideTab[setupindex&0x7]; - return setupfuncs[setupindex]; -} - -void fxDDDoRasterSetup( struct vertex_buffer *VB ) -{ - GLcontext *ctx = VB->ctx; - FX_DRIVER_DATA(VB)->last_vert = FX_DRIVER_DATA(VB)->verts + VB->Count; - -#if 0 /* leaving this out fixes the Heretic2 stray polygon bug */ - if ((ctx->IndirectTriangles & DD_SW_RASTERIZE) == DD_SW_RASTERIZE) { - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - fxMesa->setupdone = 0; - return; - } -#endif - - if (VB->Type == VB_CVA_PRECALC) - fxDDPartialRasterSetup( VB ); - else if (ctx->Driver.RasterSetup) /* NULL if in feedback/selection mode */ - ctx->Driver.RasterSetup( VB, VB->CopyStart, VB->Count ); - -} - - -/* - * Need to check that merge&render will work before allowing this to - * happen here. Therefore - need to know that this will be fired when - * we get a forbidden input in the elt pipeline - and therefore need to check - * whether we have one *now*. Similarly need to know if state changes cause - * size4 texcoords to be introduced. - */ -void fxDDCheckPartialRasterSetup( GLcontext *ctx, struct gl_pipeline_stage *d ) -{ - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLuint tmp = fxMesa->setupdone; - - d->type = 0; - d->pre_forbidden_inputs = 0; - fxMesa->setupdone = 0; /* cleared if we return */ - - /* Indirect triangles must be rendered via the immediate pipeline. - * If all rasterization is software, no need to set up. - */ - if ((ctx->Array.Summary & VERT_OBJ_ANY) == 0) - return; - - if ((ctx->IndirectTriangles & DD_SW_SETUP) || - (ctx->IndirectTriangles & DD_SW_RASTERIZE) == DD_SW_RASTERIZE) - return; - - if ((ctx->Texture.ReallyEnabled & 0xf) && - !(ctx->Array.Flags & VERT_TEX0_ANY)) - { - if (ctx->TextureMatrix[0].type == MATRIX_GENERAL || - ctx->TextureMatrix[0].type == MATRIX_PERSPECTIVE || - (ctx->Texture.Unit[1].TexGenEnabled & Q_BIT)) - return; - - d->pre_forbidden_inputs |= VERT_TEX0_4; - } - - if ((ctx->Texture.ReallyEnabled & 0xf0) && - !(ctx->Array.Flags & VERT_TEX1_ANY)) - { - if (ctx->TextureMatrix[1].type == MATRIX_GENERAL || - ctx->TextureMatrix[1].type == MATRIX_PERSPECTIVE || - (ctx->Texture.Unit[1].TexGenEnabled & Q_BIT)) - return; - - d->pre_forbidden_inputs |= VERT_TEX1_4; - } - - - fxMesa->setupdone = tmp; - d->inputs = 0; - d->outputs = VERT_SETUP_PART; - d->type = PIPE_PRECALC; -} - - -/* Will be different every time - no point in trying to precalc the - * function to call. - */ -void fxDDPartialRasterSetup( struct vertex_buffer *VB ) -{ - GLuint new = VB->pipeline->new_outputs; - fxMesaContext fxMesa = (fxMesaContext)VB->ctx->DriverCtx; - GLuint ind = 0; - - FX_DRIVER_DATA(VB)->last_vert = FX_DRIVER_DATA(VB)->verts + VB->Count; - - if (new & VERT_WIN) { - new = VB->pipeline->outputs; - ind |= SETUP_XY|SETUP_W|SETUP_Z; - } - - if (new & VERT_TEX0_ANY) - ind |= SETUP_W | fxMesa->tex_dest[0]; - - if (new & VERT_TEX1_ANY) - ind |= SETUP_W | fxMesa->tex_dest[1]; - - if (new & VERT_RGBA) - ind |= SETUP_W|SETUP_RGBA; - - if ((new & VERT_WIN) == 0) - ind &= ~(fxMesa->setupdone & SETUP_W); - - fxMesa->setupdone &= ~ind; - ind &= fxMesa->setupindex; - fxMesa->setupdone |= ind; - - if (MESA_VERBOSE & (VERBOSE_DRIVER|VERBOSE_PIPELINE)) { - gl_print_vert_flags("new outputs", VB->pipeline->new_outputs); - fxPrintSetupFlags("fxmesa: partial setup function", ind); - } - - if (ind) - setupfuncs[ind]( VB, VB->Start, VB->Count ); -} - -/* Almost certainly never called. - */ -void fxDDResizeVB( struct vertex_buffer *VB, GLuint size ) -{ - struct tfxMesaVertexBuffer *fvb = FX_DRIVER_DATA(VB); - - while (fvb->size < size) - fvb->size *= 2; - - FREE( VB->ClipMask ); - VB->ClipMask = (GLubyte *)MALLOC(sizeof(GLubyte) * fvb->size); - - FREE( fvb->vert_store ); - fvb->vert_store = MALLOC( sizeof(fxVertex) * fvb->size + 31); - if (!fvb->vert_store || !VB->ClipMask) - { - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); - } - fvb->verts = (fxVertex *)(((unsigned long)fvb->vert_store + 31) & ~31); - - gl_vector1ui_free( &fvb->clipped_elements ); - gl_vector1ui_alloc( &fvb->clipped_elements, VEC_WRITABLE, fvb->size, 32 ); - - if (!fvb->clipped_elements.start) goto memerror; - - return; -memerror: - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); -} - - -void fxDDRegisterVB( struct vertex_buffer *VB ) -{ - struct tfxMesaVertexBuffer *fvb; - - fvb = (struct tfxMesaVertexBuffer *)calloc( 1, sizeof(*fvb) ); - - /* This looks like it allocates a lot of memory, but it basically - * just sets an upper limit on how much can be used - nothing like - * this amount will ever be turned into 'real' memory. - */ - if (VB->Type == VB_CVA_PRECALC) { - fvb->size = VB->Size * 5; - fvb->vert_store = MALLOC( sizeof(fxVertex) * fvb->size + 31); - if (!fvb->vert_store) goto memerror; -#if defined(FX_GLIDE3) - fvb->triangle_b = MALLOC( sizeof(GrVertex*) *4* fvb->size+ 31); - if (!fvb->triangle_b) goto memerror; - fvb->strips_b = MALLOC( sizeof(GrVertex*) *4* fvb->size+ 31); - if (!fvb->strips_b ) goto memerror; -#endif - fvb->verts = (fxVertex *)(((unsigned long)fvb->vert_store + 31) & ~31); - gl_vector1ui_alloc( &fvb->clipped_elements, VEC_WRITABLE, fvb->size, 32 ); - if (!fvb->clipped_elements.start) goto memerror; - - FREE( VB->ClipMask ); - VB->ClipMask = (GLubyte *)MALLOC(sizeof(GLubyte) * fvb->size); - if (!VB->ClipMask) goto memerror; - - } else { - fvb->vert_store = MALLOC( sizeof(fxVertex) * (VB->Size + 12) + 31); - if (!fvb->vert_store) goto memerror; -#if defined(FX_GLIDE3) - fvb->triangle_b = MALLOC( sizeof(GrVertex*) *4* fvb->size+ 31); - if (!fvb->triangle_b) goto memerror; - fvb->strips_b = MALLOC( sizeof(GrVertex*) *4* fvb->size+ 31); - if (!fvb->strips_b ) goto memerror; -#endif - fvb->verts = (fxVertex *)(((unsigned long)fvb->vert_store + 31) & ~31); - fvb->size = VB->Size + 12; - } - - - VB->driver_data = fvb; - return; -memerror: - fprintf(stderr,"fx Driver: out of memory !\n"); - fxCloseHardware(); - exit(-1); -} - -void fxDDUnregisterVB( struct vertex_buffer *VB ) -{ - struct tfxMesaVertexBuffer *fvb = FX_DRIVER_DATA(VB); - - if (fvb) { - if (fvb->vert_store) FREE(fvb->vert_store); - gl_vector1ui_free( &fvb->clipped_elements ); - FREE(fvb); -#if defined(FX_GLIDE3) - if (fvb->strips_b) - FREE(fvb->strips_b); - if (fvb->triangle_b) - FREE(fvb->triangle_b); -#endif - VB->driver_data = 0; - } -} - - - -#else - - -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_vsetup(void) -{ - return 0; -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxwgl.c b/xc/extras/Mesa/src/FX/fxwgl.c deleted file mode 100644 index 1f0e16a95..000000000 --- a/xc/extras/Mesa/src/FX/fxwgl.c +++ /dev/null @@ -1,870 +0,0 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - - -/* fxwgl.c - Microsoft wgl functions emulation for - * 3Dfx VooDoo/Mesa interface - */ - - -#ifdef __WIN32__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <windows.h> -#include "GL/gl.h" - -#ifdef __cplusplus - } -#endif - -#include <stdio.h> -#include "GL/fxmesa.h" -#include "fxdrv.h" - -#define MAX_MESA_ATTRS 20 - -struct __extensions__ -{ - PROC proc; - char *name; -}; - -struct __pixelformat__ -{ - PIXELFORMATDESCRIPTOR pfd; - GLint mesaAttr[MAX_MESA_ATTRS]; -}; - -WINGDIAPI void GLAPIENTRY gl3DfxSetPaletteEXT(GLuint *); - -static struct __extensions__ ext[] = { - -#ifdef GL_EXT_polygon_offset - { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" }, -#endif - { (PROC)glBlendEquationEXT, "glBlendEquationEXT" }, - { (PROC)glBlendColorEXT, "glBlendColorExt" }, - { (PROC)glVertexPointerEXT, "glVertexPointerEXT" }, - { (PROC)glNormalPointerEXT, "glNormalPointerEXT" }, - { (PROC)glColorPointerEXT, "glColorPointerEXT" }, - { (PROC)glIndexPointerEXT, "glIndexPointerEXT" }, - { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" }, - { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" }, - { (PROC)glGetPointervEXT, "glGetPointervEXT" }, - { (PROC)glArrayElementEXT, "glArrayElementEXT" }, - { (PROC)glDrawArraysEXT, "glDrawArrayEXT" }, - { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" }, - { (PROC)glBindTextureEXT, "glBindTextureEXT" }, - { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" }, - { (PROC)glGenTexturesEXT, "glGenTexturesEXT" }, - { (PROC)glIsTextureEXT, "glIsTextureEXT" }, - { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" }, - { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" }, - { (PROC)glTexImage3DEXT, "glTexImage3DEXT" }, - { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" }, - { (PROC)gl3DfxSetPaletteEXT, "3DFX_set_global_palette" }, - { (PROC)glColorTableEXT, "glColorTableEXT" }, - { (PROC)glColorSubTableEXT, "glColorSubTableEXT" }, - { (PROC)glGetColorTableEXT, "glGetColorTableEXT" }, - { (PROC)glGetColorTableParameterfvEXT, "glGetColorTableParameterfvEXT" }, - { (PROC)glGetColorTableParameterivEXT, "glGetColorTableParameterivEXT" }, - { (PROC)glPointParameterfEXT, "glPointParameterfEXT" }, - { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" }, - { (PROC)glBlendFuncSeparateINGR, "glBlendFuncSeparateINGR" }, - { (PROC)glActiveTextureARB, "glActiveTextureARB" }, - { (PROC)glClientActiveTextureARB, "glClientActiveTextureARB" }, - { (PROC)glMultiTexCoord1dARB, "glMultiTexCoord1dARB" }, - { (PROC)glMultiTexCoord1dvARB, "glMultiTexCoord1dvARB" }, - { (PROC)glMultiTexCoord1fARB, "glMultiTexCoord1fARB" }, - { (PROC)glMultiTexCoord1fvARB, "glMultiTexCoord1fvARB" }, - { (PROC)glMultiTexCoord1iARB, "glMultiTexCoord1iARB" }, - { (PROC)glMultiTexCoord1ivARB, "glMultiTexCoord1ivARB" }, - { (PROC)glMultiTexCoord1sARB, "glMultiTexCoord1sARB" }, - { (PROC)glMultiTexCoord1svARB, "glMultiTexCoord1svARB" }, - { (PROC)glMultiTexCoord2dARB, "glMultiTexCoord2dARB" }, - { (PROC)glMultiTexCoord2dvARB, "glMultiTexCoord2dvARB" }, - { (PROC)glMultiTexCoord2fARB, "glMultiTexCoord2fARB" }, - { (PROC)glMultiTexCoord2fvARB, "glMultiTexCoord2fvARB" }, - { (PROC)glMultiTexCoord2iARB, "glMultiTexCoord2iARB" }, - { (PROC)glMultiTexCoord2ivARB, "glMultiTexCoord2ivARB" }, - { (PROC)glMultiTexCoord2sARB, "glMultiTexCoord2sARB" }, - { (PROC)glMultiTexCoord2svARB, "glMultiTexCoord2svARB" }, - { (PROC)glMultiTexCoord3dARB, "glMultiTexCoord3dARB" }, - { (PROC)glMultiTexCoord3dvARB, "glMultiTexCoord3dvARB" }, - { (PROC)glMultiTexCoord3fARB, "glMultiTexCoord3fARB" }, - { (PROC)glMultiTexCoord3fvARB, "glMultiTexCoord3fvARB" }, - { (PROC)glMultiTexCoord3iARB, "glMultiTexCoord3iARB" }, - { (PROC)glMultiTexCoord3ivARB, "glMultiTexCoord3ivARB" }, - { (PROC)glMultiTexCoord3sARB, "glMultiTexCoord3sARB" }, - { (PROC)glMultiTexCoord3svARB, "glMultiTexCoord3svARB" }, - { (PROC)glMultiTexCoord4dARB, "glMultiTexCoord4dARB" }, - { (PROC)glMultiTexCoord4dvARB, "glMultiTexCoord4dvARB" }, - { (PROC)glMultiTexCoord4fARB, "glMultiTexCoord4fARB" }, - { (PROC)glMultiTexCoord4fvARB, "glMultiTexCoord4fvARB" }, - { (PROC)glMultiTexCoord4iARB, "glMultiTexCoord4iARB" }, - { (PROC)glMultiTexCoord4ivARB, "glMultiTexCoord4ivARB" }, - { (PROC)glMultiTexCoord4sARB, "glMultiTexCoord4sARB" }, - { (PROC)glMultiTexCoord4svARB, "glMultiTexCoord4svARB" }, - { (PROC)glLockArraysEXT, "glLockArraysEXT" }, - { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" } -}; - -static int qt_ext = sizeof(ext) / sizeof(ext[0]); - -struct __pixelformat__ pix[] = -{ - /* None */ - { - { - sizeof(PIXELFORMATDESCRIPTOR), 1, - PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL| - PFD_DOUBLEBUFFER|PFD_SWAP_COPY, - PFD_TYPE_RGBA, - 32, - 8,0,8,8,8,16,0,24, - 0,0,0,0,0, - 0, - 0, - 0, - PFD_MAIN_PLANE, - 0,0,0,0 - }, - { - FXMESA_DOUBLEBUFFER, - FXMESA_ALPHA_SIZE, 0, - FXMESA_DEPTH_SIZE, 0, - FXMESA_STENCIL_SIZE, 0, - FXMESA_ACCUM_SIZE, 0, - FXMESA_NONE - } - }, - - /* Alpha */ - { - { - sizeof(PIXELFORMATDESCRIPTOR), 1, - PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL| - PFD_DOUBLEBUFFER|PFD_SWAP_COPY, - PFD_TYPE_RGBA, - 32, - 8,0,8,8,8,16,8,24, - 0,0,0,0,0, - 0, - 0, - 0, - PFD_MAIN_PLANE, - 0,0,0,0 - }, - { - FXMESA_DOUBLEBUFFER, - FXMESA_ALPHA_SIZE, 8, - FXMESA_DEPTH_SIZE, 0, - FXMESA_STENCIL_SIZE, 0, - FXMESA_ACCUM_SIZE, 0, - FXMESA_NONE - } - }, - - /* Depth */ - { - { - sizeof(PIXELFORMATDESCRIPTOR), 1, - PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL| - PFD_DOUBLEBUFFER|PFD_SWAP_COPY, - PFD_TYPE_RGBA, - 32, - 8,0,8,8,8,16,0,24, - 0,0,0,0,0, - 16, - 0, - 0, - PFD_MAIN_PLANE, - 0,0,0,0 - }, - { - FXMESA_DOUBLEBUFFER, - FXMESA_ALPHA_SIZE, 0, - FXMESA_DEPTH_SIZE, 16, - FXMESA_STENCIL_SIZE, 0, - FXMESA_ACCUM_SIZE, 0, - FXMESA_NONE - } - } -}; -static int qt_pix = sizeof(pix) / sizeof(pix[0]); - -static fxMesaContext ctx = NULL; -static WNDPROC hWNDOldProc; -static int curPFD = 0; -static HDC hDC; -static HWND hWND; - -static GLboolean haveDualHead; - -/* For the in-window-rendering hack */ - -static GLboolean gdiWindowHack; -static GLboolean gdiWindowHackEna; -static void *dibSurfacePtr; -static BITMAPINFO *dibBMI; -static HBITMAP dibHBM; -static HWND dibWnd; - -LONG GLAPIENTRY __wglMonitor(HWND hwnd,UINT message,UINT wParam,LONG lParam) - -{ - long ret; /* Now gives the resized window at the end to hWNDOldProc */ - - if(ctx && hwnd == hWND) { - switch(message) { - case WM_PAINT: - case WM_MOVE: - break; - case WM_DISPLAYCHANGE: - case WM_SIZE: - if (wParam != SIZE_MINIMIZED) { - static int moving = 0; - if (!moving) { - if(fxQueryHardware()!=GR_SSTTYPE_VOODOO) { - if(!FX_grSstControl(GR_CONTROL_RESIZE)) { - moving = 1; - SetWindowPos(hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOZORDER); - moving = 0; - if(!FX_grSstControl(GR_CONTROL_RESIZE)) { - /*MessageBox(0,_T("Error changing windowsize"),_T("fxMESA"),MB_OK);*/ - PostMessage(hWND,WM_CLOSE,0,0); - } - } - } - - /* Do the clipping in the glide library */ - FX_grClipWindow(0,0,FX_grSstScreenWidth(),FX_grSstScreenHeight()); - /* And let the new size set in the context */ - fxMesaUpdateScreenSize(ctx); - } - } - break; - case WM_ACTIVATE: - if((fxQueryHardware()==GR_SSTTYPE_VOODOO) && - (!gdiWindowHack) && - (!haveDualHead)) { - WORD fActive = LOWORD(wParam); - BOOL fMinimized = (BOOL) HIWORD(wParam); - - if((fActive == WA_INACTIVE) || fMinimized) - FX_grSstControl(GR_CONTROL_DEACTIVATE); - else - FX_grSstControl(GR_CONTROL_ACTIVATE); - } - break; - case WM_SHOWWINDOW: - break; - case WM_SYSKEYDOWN: - case WM_SYSCHAR: - if(gdiWindowHackEna && (VK_RETURN == wParam)) { - if(gdiWindowHack) { - gdiWindowHack = GL_FALSE; - FX_grSstControl(GR_CONTROL_ACTIVATE); - } else { - gdiWindowHack = GL_TRUE; - FX_grSstControl(GR_CONTROL_DEACTIVATE); - } - } - break; - } - } - - /* Finaly call the hWNDOldProc, which handles the resize witch the - now changed window sizes */ - ret = CallWindowProc( hWNDOldProc, hwnd, message, wParam, lParam ); - - return(ret); -} - -BOOL GLAPIENTRY wglCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask) -{ - return(FALSE); -} - -HGLRC GLAPIENTRY wglCreateContext(HDC hdc) -{ - HWND hWnd; - WNDPROC oldProc; - int error; - - if(ctx) { - SetLastError(0); - return(NULL); - } - - if(!(hWnd = WindowFromDC(hdc))) { - SetLastError(0); - return(NULL); - } - - if(curPFD == 0) { - SetLastError(0); - return(NULL); - } - - if((oldProc = (WNDPROC)GetWindowLong(hWnd,GWL_WNDPROC)) != __wglMonitor) { - hWNDOldProc = oldProc; - SetWindowLong(hWnd,GWL_WNDPROC,(LONG)__wglMonitor); - } - -#ifndef FX_SILENT - freopen("MESA.LOG","w",stderr); -#endif - - ShowWindow(hWnd, SW_SHOWNORMAL); - SetForegroundWindow(hWnd); - Sleep(100); /* an hack for win95 */ - - if(fxQueryHardware() == GR_SSTTYPE_VOODOO) { - RECT cliRect; - - GetClientRect(hWnd,&cliRect); - error = !(ctx = fxMesaCreateBestContext((GLuint)hWnd,cliRect.right,cliRect.bottom, - pix[curPFD - 1].mesaAttr)); - - if(!error) { - /* create the DIB section for windowed rendering */ - DWORD *p; - - dibWnd = hWnd; - - hDC = GetDC(dibWnd); - - dibBMI = (BITMAPINFO*) MALLOC( sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD))); - - memset(dibBMI,0,sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD))); - - dibBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - dibBMI->bmiHeader.biWidth = ctx->width; - dibBMI->bmiHeader.biHeight = -ctx->height; - dibBMI->bmiHeader.biPlanes = (short)1; - dibBMI->bmiHeader.biBitCount = (short)16; - dibBMI->bmiHeader.biCompression = BI_BITFIELDS; - dibBMI->bmiHeader.biSizeImage = 0; - dibBMI->bmiHeader.biXPelsPerMeter = 0; - dibBMI->bmiHeader.biYPelsPerMeter = 0; - dibBMI->bmiHeader.biClrUsed = 3; - dibBMI->bmiHeader.biClrImportant = 3; - - p = (DWORD*)dibBMI->bmiColors; - p[0] = 0xF800; - p[1] = 0x07E0; - p[2] = 0x001F; - - dibHBM = CreateDIBSection(hDC, dibBMI, DIB_RGB_COLORS, &dibSurfacePtr, NULL, 0); - - ReleaseDC(dibWnd, hDC); - - gdiWindowHackEna = (dibHBM != NULL ? GL_TRUE : GL_FALSE); - - if (!getenv("MESA_WGL_FX") || !strcmp(getenv("MESA_WGL_FX"),"fullscreen")) - gdiWindowHack = GL_FALSE; - else { - gdiWindowHack = GL_TRUE; - FX_grSstControl(GR_CONTROL_DEACTIVATE); - } - } - } else { - /* For the Voodoo Rush */ - - if(getenv("MESA_WGL_FX") && !strcmp(getenv("MESA_WGL_FX"),"fullscreen")) { - RECT cliRect; - - GetClientRect(hWnd,&cliRect); - error = !(ctx = fxMesaCreateBestContext((GLuint)hWnd,cliRect.right,cliRect.bottom, - pix[curPFD - 1].mesaAttr)); - } else - error = !(ctx = fxMesaCreateContext((GLuint)hWnd,GR_RESOLUTION_NONE,GR_REFRESH_75Hz, - pix[curPFD - 1].mesaAttr)); - } - - if(getenv("SST_DUALHEAD")) - haveDualHead=((atoi(getenv("SST_DUALHEAD"))==1) ? GL_TRUE:GL_FALSE); - else - haveDualHead=GL_FALSE; - - if(error) { - SetLastError(0); - return(NULL); - } - - hDC = hdc; - hWND = hWnd; - - /* Required by the OpenGL Optimizer 1.1 (is it a Optimizer bug ?) */ - wglMakeCurrent(hdc,(HGLRC)1); - - return((HGLRC)1); -} - -HGLRC GLAPIENTRY wglCreateLayerContext(HDC hdc,int iLayerPlane) -{ - SetLastError(0); - return(NULL); -} - -BOOL GLAPIENTRY wglDeleteContext(HGLRC hglrc) -{ - if(ctx && hglrc == (HGLRC)1) { - if (gdiWindowHackEna) { - DeleteObject(dibHBM); - FREE(dibBMI); - - dibSurfacePtr = NULL; - dibBMI = NULL; - dibHBM = NULL; - dibWnd = NULL; - } - - fxMesaDestroyContext(ctx); - - SetWindowLong(WindowFromDC(hDC),GWL_WNDPROC,(LONG)hWNDOldProc); - - ctx = NULL; - hDC = 0; - return(TRUE); - } - - SetLastError(0); - - return(FALSE); -} - -HGLRC GLAPIENTRY wglGetCurrentContext(VOID) -{ - if(ctx) - return((HGLRC)1); - - SetLastError(0); - return(NULL); -} - -HDC GLAPIENTRY wglGetCurrentDC(VOID) -{ - if(ctx) - return(hDC); - - SetLastError(0); - return(NULL); -} - -PROC GLAPIENTRY wglGetProcAddress(LPCSTR lpszProc) -{ - int i; - - /*fprintf(stderr,"fxMesa: looking for extension %s\n",lpszProc); - fflush(stderr);*/ - - for(i = 0;i < qt_ext;i++) - if(!strcmp(lpszProc,ext[i].name)) { - /*fprintf(stderr,"fxMesa: found extension %s\n",lpszProc); - fflush(stderr);*/ - - return(ext[i].proc); - } - SetLastError(0); - return(NULL); -} - -BOOL GLAPIENTRY wglMakeCurrent(HDC hdc,HGLRC hglrc) -{ - if((hdc==NULL) && (hglrc==NULL)) - return(TRUE); - - if(!ctx || hglrc != (HGLRC)1 || WindowFromDC(hdc) != hWND) { - SetLastError(0); - return(FALSE); - } - - hDC = hdc; - - fxMesaMakeCurrent(ctx); - - return(TRUE); -} - -BOOL GLAPIENTRY wglShareLists(HGLRC hglrc1,HGLRC hglrc2) -{ - if(!ctx || hglrc1 != (HGLRC)1 || hglrc1 != hglrc2) { - SetLastError(0); - return(FALSE); - } - - return(TRUE); -} - -BOOL GLAPIENTRY wglUseFontBitmaps(HDC fontDevice, DWORD firstChar, DWORD numChars, DWORD listBase) -{ -#define VERIFY(a) a - - TEXTMETRIC metric; - BITMAPINFO *dibInfo; - HDC bitDevice; - COLORREF tempColor; - int i; - - VERIFY(GetTextMetrics(fontDevice, &metric)); - - dibInfo = (BITMAPINFO *) calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1); - dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - dibInfo->bmiHeader.biPlanes = 1; - dibInfo->bmiHeader.biBitCount = 1; - dibInfo->bmiHeader.biCompression = BI_RGB; - - bitDevice = CreateCompatibleDC(fontDevice); - // HDC bitDevice = CreateDC("DISPLAY", NULL, NULL, NULL); - // VERIFY(bitDevice); - - // Swap fore and back colors so the bitmap has the right polarity - tempColor = GetBkColor(bitDevice); - SetBkColor(bitDevice, GetTextColor(bitDevice)); - SetTextColor(bitDevice, tempColor); - - // Place chars based on base line - VERIFY(SetTextAlign(bitDevice, TA_BASELINE) >= 0 ? 1 : 0); - - for(i = 0; i < numChars; i++) { - SIZE size; - char curChar; - int charWidth,charHeight,bmapWidth,bmapHeight,numBytes,res; - HBITMAP bitObject; - HGDIOBJ origBmap; - unsigned char *bmap; - - curChar = i + firstChar; - - // Find how high/wide this character is - VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size)); - - // Create the output bitmap - charWidth = size.cx; - charHeight = size.cy; - bmapWidth = ((charWidth + 31) / 32) * 32; // Round up to the next multiple of 32 bits - bmapHeight = charHeight; - bitObject = CreateCompatibleBitmap(bitDevice, - bmapWidth, - bmapHeight); - //VERIFY(bitObject); - - // Assign the output bitmap to the device - origBmap = SelectObject(bitDevice, bitObject); - VERIFY(origBmap); - - VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) ); - - // Use our source font on the device - VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT))); - - // Draw the character - VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1)); - - // Unselect our bmap object - VERIFY(SelectObject(bitDevice, origBmap)); - - // Convert the display dependant representation to a 1 bit deep DIB - numBytes = (bmapWidth * bmapHeight) / 8; - bmap = MALLOC(numBytes); - dibInfo->bmiHeader.biWidth = bmapWidth; - dibInfo->bmiHeader.biHeight = bmapHeight; - res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap, - dibInfo, - DIB_RGB_COLORS); - //VERIFY(res); - - // Create the GL object - glNewList(i + listBase, GL_COMPILE); - glBitmap(bmapWidth, bmapHeight, 0.0, metric.tmDescent, - charWidth, 0.0, - bmap); - glEndList(); - // CheckGL(); - - // Destroy the bmap object - DeleteObject(bitObject); - - // Deallocate the bitmap data - FREE(bmap); - } - - // Destroy the DC - VERIFY(DeleteDC(bitDevice)); - - FREE(dibInfo); - - return TRUE; -#undef VERIFY -} - -BOOL GLAPIENTRY wglUseFontBitmapsW(HDC hdc,DWORD first,DWORD count,DWORD listBase) -{ - return(FALSE); -} - -BOOL GLAPIENTRY wglUseFontOutlinesA(HDC hdc,DWORD first,DWORD count, - DWORD listBase,FLOAT deviation, - FLOAT extrusion,int format, - LPGLYPHMETRICSFLOAT lpgmf) -{ - SetLastError(0); - return(FALSE); -} - -BOOL GLAPIENTRY wglUseFontOutlinesW(HDC hdc,DWORD first,DWORD count, - DWORD listBase,FLOAT deviation, - FLOAT extrusion,int format, - LPGLYPHMETRICSFLOAT lpgmf) -{ - SetLastError(0); - return(FALSE); -} - - -BOOL GLAPIENTRY wglSwapLayerBuffers(HDC hdc,UINT fuPlanes) -{ - if(ctx && WindowFromDC(hdc) == hWND) { - fxMesaSwapBuffers(); - - return(TRUE); - } - - SetLastError(0); - return(FALSE); -} - -int GLAPIENTRY wglChoosePixelFormat(HDC hdc, - CONST PIXELFORMATDESCRIPTOR *ppfd) -{ - int i,best=-1,qt_valid_pix; - - qt_valid_pix = qt_pix; - - if(ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR) || ppfd->nVersion != 1) { - SetLastError(0); - return(0); - } - - for(i = 0;i < qt_valid_pix;i++) { - if((ppfd->dwFlags & PFD_DRAW_TO_WINDOW) && !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW)) - continue; - if((ppfd->dwFlags & PFD_DRAW_TO_BITMAP) && !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP)) - continue; - if((ppfd->dwFlags & PFD_SUPPORT_GDI) && !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI)) - continue; - if((ppfd->dwFlags & PFD_SUPPORT_OPENGL) && !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL)) - continue; - if(!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && - ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != (pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER))) - continue; - if(!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && - ((ppfd->dwFlags & PFD_STEREO) != (pix[i].pfd.dwFlags & PFD_STEREO))) - continue; - - if (ppfd->cDepthBits > 0 && pix[i].pfd.cDepthBits == 0) - continue; /* need depth buffer */ - - if (ppfd->cAlphaBits > 0 && pix[i].pfd.cAlphaBits == 0) - continue; /* need alpha buffer */ - - if(ppfd->iPixelType == pix[i].pfd.iPixelType) { - best = i + 1; - break; - } - } - - if(best == -1) { - SetLastError(0); - return(0); - } - - return(best); -} - -int GLAPIENTRY ChoosePixelFormat(HDC hdc, - CONST PIXELFORMATDESCRIPTOR *ppfd) -{ - return wglChoosePixelFormat(hdc,ppfd); -} - -int GLAPIENTRY wglDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes, - LPPIXELFORMATDESCRIPTOR ppfd) -{ - int qt_valid_pix; - - qt_valid_pix = qt_pix; - - if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || - ((nBytes != sizeof(PIXELFORMATDESCRIPTOR)) && (nBytes != 0))) { - SetLastError(0); - return(0); - } - - if(nBytes != 0) - *ppfd = pix[iPixelFormat - 1].pfd; - - return(qt_valid_pix); -} - -int GLAPIENTRY DescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes, - LPPIXELFORMATDESCRIPTOR ppfd) -{ - return wglDescribePixelFormat(hdc,iPixelFormat,nBytes,ppfd); -} - -int GLAPIENTRY wglGetPixelFormat(HDC hdc) -{ - if(curPFD == 0) { - SetLastError(0); - return(0); - } - - return(curPFD); -} - -int GLAPIENTRY GetPixelFormat(HDC hdc) -{ - return wglGetPixelFormat(hdc); -} - -BOOL GLAPIENTRY wglSetPixelFormat(HDC hdc,int iPixelFormat, - CONST PIXELFORMATDESCRIPTOR *ppfd) -{ - int qt_valid_pix; - - qt_valid_pix = qt_pix; - - if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) { - SetLastError(0); - return(FALSE); - } - curPFD = iPixelFormat; - - return(TRUE); -} - -BOOL GLAPIENTRY wglSwapBuffers(HDC hdc) -{ - if(!ctx) { - SetLastError(0); - return(FALSE); - } - - fxMesaSwapBuffers(); - - if(gdiWindowHack) { - GLuint width=ctx->width; - GLuint height=ctx->height; - - HDC hdcScreen = GetDC(dibWnd); - HDC hdcDIBSection = CreateCompatibleDC(hdcScreen); - HBITMAP holdBitmap = (HBITMAP) SelectObject(hdcDIBSection, dibHBM); - - FX_grLfbReadRegion(GR_BUFFER_FRONTBUFFER, 0, 0, - width, height, - width * 2, - dibSurfacePtr); - - /* Since the hardware is configured for GR_COLORFORMAT_ABGR the pixel data is - * going to come out as BGR 565, which is reverse of what we need for blitting - * to screen, so we need to convert it here pixel-by-pixel (ick). This loop would NOT - * be required if the color format was changed to GR_COLORFORMAT_ARGB, but I do - * not know the ramifications of that, so this will work until that is resolved. - * - * This routine CRIES out for MMX implementation, however since that's not - * guaranteed to be running on MMX enabled hardware so I'm not going to do - * that. I'm just going to try to make a reasonably efficient C - * version. -TAJ - * - * This routine drops frame rate by <1 fps on a 200Mhz MMX processor with a 640x480 - * display. Obviously, it's performance hit will be higher on larger displays and - * less on smaller displays. To support the window-hack display this is probably fine. - */ -#if FXMESA_USE_ARGB - { - unsigned long *pixel = dibSurfacePtr; - unsigned long count = (width * height) / 2; - - while (count--) - { - *pixel++ = (*pixel & 0x07e007e0) /* greens */ - | ((*pixel & 0xf800f800) >> 11) /* swap blues */ - | ((*pixel & 0x001f001f) << 11) /* swap reds */ - ; - } - } -#endif - - BitBlt(hdcScreen, 0, 0, - width, height, - hdcDIBSection, - 0, 0, SRCCOPY); - - ReleaseDC(dibWnd, hdcScreen); - SelectObject(hdcDIBSection, holdBitmap); - DeleteDC(hdcDIBSection); - } - - return(TRUE); -} - -BOOL GLAPIENTRY SetPixelFormat(HDC hdc, int iPixelFormat, - CONST PIXELFORMATDESCRIPTOR *ppfd) -{ - return wglSetPixelFormat(hdc,iPixelFormat,ppfd); -} - -BOOL GLAPIENTRY SwapBuffers(HDC hdc) -{ - return wglSwapBuffers(hdc); -} - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/OSmesa/osmesa.c b/xc/extras/Mesa/src/OSmesa/osmesa.c index 62b18f9e6..13ff0a16c 100644 --- a/xc/extras/Mesa/src/OSmesa/osmesa.c +++ b/xc/extras/Mesa/src/OSmesa/osmesa.c @@ -225,6 +225,7 @@ OSMesaCreateContext( GLenum format, OSMesaContext sharelist ) } gl_extensions_enable(&(osmesa->gl_ctx),"GL_HP_occlusion_test"); gl_extensions_enable(&(osmesa->gl_ctx), "GL_ARB_texture_cube_map"); + gl_extensions_enable(&(osmesa->gl_ctx), "GL_EXT_texture_env_combine"); osmesa->gl_buffer = gl_create_framebuffer( osmesa->gl_visual, osmesa->gl_visual->DepthBits > 0, diff --git a/xc/extras/Mesa/src/X/fakeglx.c b/xc/extras/Mesa/src/X/fakeglx.c index 67e49aba5..2c5866489 100644 --- a/xc/extras/Mesa/src/X/fakeglx.c +++ b/xc/extras/Mesa/src/X/fakeglx.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -30,7 +30,7 @@ * * Thanks to the contributors: * - * Initial version: Philip Brown (philb@CSUA.Berkeley.EDU) + * Initial version: Philip Brown (phil@bolthole.com) * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu) * Further visual-handling refinements: Wolfram Gloger * (wmglo@Dent.MED.Uni-Muenchen.DE). @@ -64,7 +64,7 @@ #define SERVER_MINOR_VERSION 3 /* This is appended onto the glXGetClient/ServerString version strings. */ -#define MESA_GLX_VERSION "Mesa 3.3" +#define MESA_GLX_VERSION "Mesa 3.4" /* Who implemented this GLX? */ #define VENDOR "Brian Paul" diff --git a/xc/extras/Mesa/src/X/xmesa1.c b/xc/extras/Mesa/src/X/xmesa1.c index 7261194bd..662cae85e 100644 --- a/xc/extras/Mesa/src/X/xmesa1.c +++ b/xc/extras/Mesa/src/X/xmesa1.c @@ -70,6 +70,7 @@ #include "xmesaP.h" #include "context.h" #include "extensions.h" +#include "glthread.h" #include "matrix.h" #include "mem.h" #include "types.h" @@ -84,9 +85,9 @@ /* - * Current X/Mesa context pointer: + * Global X driver lock */ -static XMesaContext XMesa = NULL; +_glthread_Mutex _xmesa_lock; /* @@ -242,7 +243,9 @@ static void get_drawable_size( XMesaDisplay *dpy, XMesaDrawable d, int x, y; unsigned int bw, depth; + _glthread_LOCK_MUTEX(_xmesa_lock); XGetGeometry( dpy, d, &root, &x, &y, width, height, &bw, &depth ); + _glthread_UNLOCK_MUTEX(_xmesa_lock); #endif } @@ -1464,10 +1467,14 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, /* For debugging only */ if (getenv("MESA_XSYNC")) { + /* This makes debugging X easier. + * In your debugger, set a breakpoint on _XError to stop when an + * X protocol error is generated. + */ #ifdef XFree86Server /* NOT_NEEDED */ #else - XSynchronize( display, 1 ); /* This makes debugging X easier */ + XSynchronize( display, 1 ); #endif } @@ -1558,6 +1565,9 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display, } } + if (alpha_flag && alpha_bits == 0) + alpha_bits = 8; + v->gl_visual = _mesa_create_visual( rgb_flag, db_flag, stereo_flag, red_bits, green_bits, blue_bits, alpha_bits, @@ -1608,6 +1618,12 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) XMesaContext c; GLboolean direct = GL_TRUE; /* XXXX */ /* NOT_DONE: should this be GL_FALSE??? */ + static GLboolean firstTime = GL_TRUE; + + if (firstTime) { + _glthread_INIT_MUTEX(_xmesa_lock); + firstTime = GL_FALSE; + } c = (XMesaContext) CALLOC_STRUCT(xmesa_context); if (!c) { @@ -1624,6 +1640,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) gl_extensions_enable(c->gl_ctx, "GL_HP_occlusion_test"); gl_extensions_enable(c->gl_ctx, "GL_ARB_texture_cube_map"); + gl_extensions_enable(c->gl_ctx, "GL_EXT_texture_env_combine"); if (CHECK_BYTE_ORDER(v)) { c->swapbytes = GL_FALSE; @@ -1687,10 +1704,6 @@ void XMesaDestroyContext( XMesaContext c ) } } - /* Set current context ptr to NULL if we freed it */ - if (XMesa == c) - XMesa = NULL; - FREE( c ); } @@ -2017,7 +2030,6 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, #ifdef FX if (drawBuffer->FXctx) { fxMesaMakeCurrent(drawBuffer->FXctx); - XMesa = c; /* Disassociate old buffer from this context */ if (c->xm_buffer) @@ -2051,7 +2063,6 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, c->use_read_buffer = (drawBuffer != readBuffer); gl_make_current2(c->gl_ctx, drawBuffer->gl_buffer, readBuffer->gl_buffer); - XMesa = c; if (c->gl_ctx->Viewport.Width == 0) { /* initialize viewport to window size */ @@ -2083,7 +2094,6 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, else { /* Detach */ gl_make_current2( NULL, NULL, NULL ); - XMesa = NULL; } return GL_TRUE; } @@ -2101,14 +2111,23 @@ GLboolean XMesaUnbindContext( XMesaContext c ) XMesaContext XMesaGetCurrentContext( void ) { - return XMesa; + GET_CURRENT_CONTEXT(ctx); + if (ctx) { + XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + return xmesa; + } + else { + return 0; + } } XMesaBuffer XMesaGetCurrentBuffer( void ) { - if (XMesa) { - return XMesa->xm_buffer; + GET_CURRENT_CONTEXT(ctx); + if (ctx) { + XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + return xmesa->xm_buffer; } else { return 0; @@ -2119,8 +2138,10 @@ XMesaBuffer XMesaGetCurrentBuffer( void ) /* New in Mesa 3.1 */ XMesaBuffer XMesaGetCurrentReadBuffer( void ) { - if (XMesa) { - return XMesa->xm_buffer; + GET_CURRENT_CONTEXT(ctx); + if (ctx) { + XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + return xmesa->xm_buffer; } else { return 0; @@ -2133,12 +2154,10 @@ GLboolean XMesaForceCurrent(XMesaContext c) if (c) { if (c->gl_ctx != gl_get_current_context()) { gl_make_current(c->gl_ctx, c->xm_buffer->gl_buffer); - XMesa = c; } } else { gl_make_current(NULL, NULL); - XMesa = NULL; } return GL_TRUE; } @@ -2148,7 +2167,6 @@ GLboolean XMesaLoseCurrent(XMesaContext c) { (void) c; gl_make_current(NULL, NULL); - XMesa = NULL; return GL_TRUE; } @@ -2161,6 +2179,7 @@ GLboolean XMesaSetFXmode( GLint mode ) #ifdef FX const char *fx = getenv("MESA_GLX_FX"); if (fx && fx[0] != 'd') { + GET_CURRENT_CONTEXT(ctx); GrHwConfiguration hw; if (!FX_grSstQueryHardware(&hw)) { /*fprintf(stderr, "!grSstQueryHardware\n");*/ @@ -2170,17 +2189,18 @@ GLboolean XMesaSetFXmode( GLint mode ) /*fprintf(stderr, "hw.num_sst < 1\n");*/ return GL_FALSE; } - if (XMesa) { + if (ctx) { + XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; if (mode == XMESA_FX_WINDOW) { - if (XMesa->xm_buffer->FXisHackUsable) { + if (xmesa->xm_buffer->FXisHackUsable) { FX_grSstControl(GR_CONTROL_DEACTIVATE); - XMesa->xm_buffer->FXwindowHack = GL_TRUE; + xmesa->xm_buffer->FXwindowHack = GL_TRUE; return GL_TRUE; } } else if (mode == XMESA_FX_FULLSCREEN) { FX_grSstControl(GR_CONTROL_ACTIVATE); - XMesa->xm_buffer->FXwindowHack = GL_FALSE; + xmesa->xm_buffer->FXwindowHack = GL_FALSE; return GL_TRUE; } else { @@ -2207,8 +2227,9 @@ static void FXgetImage( XMesaBuffer b ) int x, y; XMesaWindow root; unsigned int bw, depth, width, height; + XMesaContext xmesa = (XMesaContext) b->xm_context->gl_ctx->DriverCtx; - assert(XMesa->xm_buffer->FXctx); + assert(xmesa->xm_buffer->FXctx); #ifdef XFree86Server x = b->frontbuffer->x; @@ -2217,30 +2238,29 @@ static void FXgetImage( XMesaBuffer b ) height = b->frontbuffer->height; depth = b->frontbuffer->depth; #else - XGetGeometry( XMesa->xm_visual->display, b->frontbuffer, + XGetGeometry( xmesa->xm_visual->display, b->frontbuffer, &root, &x, &y, &width, &height, &bw, &depth); #endif if (b->width != width || b->height != height) { - b->width = MIN2((int)width, XMesa->xm_buffer->FXctx->width); - b->height = MIN2((int)height, XMesa->xm_buffer->FXctx->height); + b->width = MIN2((int)width, xmesa->xm_buffer->FXctx->width); + b->height = MIN2((int)height, xmesa->xm_buffer->FXctx->height); if (b->width & 1) b->width--; /* prevent odd width */ xmesa_alloc_back_buffer( b ); } grLfbWriteColorFormat(GR_COLORFORMAT_ARGB); - if (XMesa->xm_visual->undithered_pf==PF_5R6G5B) { + if (xmesa->xm_visual->undithered_pf==PF_5R6G5B) { /* Special case: 16bpp RGB */ grLfbReadRegion( GR_BUFFER_FRONTBUFFER, /* src buffer */ - 0, XMesa->xm_buffer->FXctx->height - b->height, /*pos*/ + 0, xmesa->xm_buffer->FXctx->height - b->height, /*pos*/ b->width, b->height, /* size */ b->width * sizeof(GLushort), /* stride */ b->backimage->data); /* dest buffer */ } - else if (XMesa->xm_visual->dithered_pf==PF_DITHER - && GET_VISUAL_DEPTH(XMesa->xm_visual)==8) { + else if (xmesa->xm_visual->dithered_pf==PF_DITHER + && GET_VISUAL_DEPTH(xmesa->xm_visual)==8) { /* Special case: 8bpp RGB */ - XMesaContext xmesa = XMesa; /* Needed for DITHER macros */ for (y=0;y<b->height;y++) { GLubyte *ptr = (GLubyte*) xmesa->xm_buffer->backimage->data + xmesa->xm_buffer->backimage->bytes_per_line * y; @@ -2248,7 +2268,7 @@ static void FXgetImage( XMesaBuffer b ) /* read row from 3Dfx frame buffer */ grLfbReadRegion( GR_BUFFER_FRONTBUFFER, - 0, XMesa->xm_buffer->FXctx->height-(b->height-y), + 0, xmesa->xm_buffer->FXctx->height-(b->height-y), b->width, 1, 0, pixbuf ); @@ -2267,7 +2287,7 @@ static void FXgetImage( XMesaBuffer b ) for (y=0;y<b->height;y++) { /* read row from 3Dfx frame buffer */ grLfbReadRegion( GR_BUFFER_FRONTBUFFER, - 0, XMesa->xm_buffer->FXctx->height-(b->height-y), + 0, xmesa->xm_buffer->FXctx->height-(b->height-y), b->width, 1, 0, pixbuf ); @@ -2275,11 +2295,11 @@ static void FXgetImage( XMesaBuffer b ) /* write to XImage back buffer */ for (x=0;x<b->width;x++) { XMesaPutPixel(b->backimage,x,y, - xmesa_color_to_pixel(XMesa, + xmesa_color_to_pixel(xmesa, (pixbuf[x] & 0xf800) >> 8, (pixbuf[x] & 0x07e0) >> 3, (pixbuf[x] & 0x001f) << 3, - 0xff, XMesa->pixelformat)); + 0xff, xmesa->pixelformat)); } } } @@ -2294,18 +2314,20 @@ static void FXgetImage( XMesaBuffer b ) */ void XMesaSwapBuffers( XMesaBuffer b ) { -#ifdef PROFILE - GLdouble t0 = gl_time(); -#endif + GET_CURRENT_CONTEXT(ctx); - _mesa_swapbuffers(XMesa->gl_ctx); + /* If we're swapping the buffer associated with the current context + * we have to flush any pending rendering commands first. + */ + if (b->xm_context && b->xm_context->gl_ctx == ctx) + _mesa_swapbuffers(ctx); if (b->db_state) { #ifdef FX - if (XMesa->xm_buffer->FXctx) { + if (b->FXctx) { fxMesaSwapBuffers(); - if (XMesa->xm_buffer->FXwindowHack) + if (b->FXwindowHack) FXgetImage(b); else return; @@ -2315,11 +2337,12 @@ void XMesaSwapBuffers( XMesaBuffer b ) /* Copy Ximage from host's memory to server's window */ #if defined(USE_XSHM) && !defined(XFree86Server) if (b->shm) { + /*_glthread_LOCK_MUTEX(_xmesa_lock);*/ XShmPutImage( b->xm_visual->display, b->frontbuffer, b->cleargc, b->backimage, 0, 0, 0, 0, b->width, b->height, False ); - /* wait for finished event??? */ + /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ } else #endif @@ -2327,15 +2350,18 @@ void XMesaSwapBuffers( XMesaBuffer b ) #if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server) XMesaDriSwapBuffers( b ); #else + /*_glthread_LOCK_MUTEX(_xmesa_lock);*/ XMesaPutImage( b->xm_visual->display, b->frontbuffer, b->cleargc, b->backimage, 0, 0, 0, 0, b->width, b->height ); + /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ #endif } } else { /* Copy pixmap to window on server */ + /*_glthread_LOCK_MUTEX(_xmesa_lock);*/ XMesaCopyArea( b->xm_visual->display, b->backpixmap, /* source drawable */ b->frontbuffer, /* dest. drawable */ @@ -2343,17 +2369,12 @@ void XMesaSwapBuffers( XMesaBuffer b ) 0, 0, b->width, b->height, /* source region */ 0, 0 /* dest region */ ); + /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/ } } -#if defined(GLX_DIRECT_RENDERING) || defined(XFree86Server) - /* NOT_NEEDED */ -#else +#if !defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server) XSync( b->xm_visual->display, False ); #endif -#ifdef PROFILE - XMesa->gl_ctx->SwapCount++; - XMesa->gl_ctx->SwapTime += gl_time() - t0; -#endif } @@ -2363,18 +2384,20 @@ void XMesaSwapBuffers( XMesaBuffer b ) */ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) { -#ifdef PROFILE - GLdouble t0 = gl_time(); -#endif + GET_CURRENT_CONTEXT(ctx); - FLUSH_VB( XMesa->gl_ctx, "swap buffers" ); + /* If we're swapping the buffer associated with the current context + * we have to flush any pending rendering commands first. + */ + if (b->xm_context->gl_ctx == ctx) + _mesa_swapbuffers(ctx); if (b->db_state) { int yTop = b->bottom - y - height; #ifdef FX - if (XMesa->xm_buffer->FXctx) { + if (b->FXctx) { fxMesaSwapBuffers(); - if (XMesa->xm_buffer->FXwindowHack) + if (b->FXwindowHack) FXgetImage(b); else return; @@ -2412,15 +2435,6 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) ); } } -#ifdef XFree86Server - /* NOT_NEEDED */ -#else - XSync( b->xm_visual->display, False ); -#endif -#ifdef PROFILE - XMesa->gl_ctx->SwapCount++; - XMesa->gl_ctx->SwapTime += gl_time() - t0; -#endif } @@ -2550,7 +2564,6 @@ void XMesaReset( void ) XMesaDestroyBuffer(XMesaBufferList); XMesaBufferList = NULL; - XMesa = NULL; } diff --git a/xc/extras/Mesa/src/X/xmesa2.c b/xc/extras/Mesa/src/X/xmesa2.c index 77b8d4b05..e1b5b69f4 100644 --- a/xc/extras/Mesa/src/X/xmesa2.c +++ b/xc/extras/Mesa/src/X/xmesa2.c @@ -150,8 +150,10 @@ static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height ) int winx, winy; unsigned int bw, d; + _glthread_LOCK_MUTEX(_xmesa_lock); XGetGeometry( xmesa->display, xmesa->xm_buffer->frontbuffer, &root, &winx, &winy, &winwidth, &winheight, &bw, &d ); + _glthread_UNLOCK_MUTEX(_xmesa_lock); #else winwidth = xmesa->xm_buffer->frontbuffer->width; @@ -209,7 +211,9 @@ static void finish( GLcontext *ctx ) #else const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; if (xmesa) { + _glthread_LOCK_MUTEX(_xmesa_lock); XSync( xmesa->display, False ); + _glthread_UNLOCK_MUTEX(_xmesa_lock); } #endif } @@ -222,7 +226,9 @@ static void flush( GLcontext *ctx ) #else const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; if (xmesa) { + _glthread_LOCK_MUTEX(_xmesa_lock); XFlush( xmesa->display ); + _glthread_UNLOCK_MUTEX(_xmesa_lock); } #endif } @@ -353,8 +359,10 @@ static void clear_color( GLcontext *ctx, xmesa->clearcolor[3] = a; xmesa->clearpixel = xmesa_color_to_pixel( xmesa, r, g, b, a, xmesa->xm_visual->undithered_pf ); + _glthread_LOCK_MUTEX(_xmesa_lock); XMesaSetForeground( xmesa->display, xmesa->xm_buffer->cleargc, xmesa->clearpixel ); + _glthread_UNLOCK_MUTEX(_xmesa_lock); } @@ -528,8 +536,10 @@ static GLboolean logicop( GLcontext *ctx, GLenum op ) case GL_OR_INVERTED: func = GXorInverted; break; default: return GL_FALSE; } + _glthread_LOCK_MUTEX(_xmesa_lock); XMesaSetFunction( xmesa->display, xmesa->xm_buffer->gc1, func ); XMesaSetFunction( xmesa->display, xmesa->xm_buffer->gc2, func ); + _glthread_UNLOCK_MUTEX(_xmesa_lock); return GL_TRUE; } diff --git a/xc/extras/Mesa/src/X/xmesa3.c b/xc/extras/Mesa/src/X/xmesa3.c index c7e4c21c8..7e81e4ba4 100644 --- a/xc/extras/Mesa/src/X/xmesa3.c +++ b/xc/extras/Mesa/src/X/xmesa3.c @@ -731,9 +731,15 @@ line_func xmesa_get_line_func( GLcontext *ctx ) return NULL; } } +#if 0 + /* XXX have to disable this because X's rasterization rules don't match + * software Mesa's. This causes the linehv.c conformance test to fail. + * In the future, we might provide a config option to enable this. + */ if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->RasterMask==0) { setup_x_line_options( ctx ); return flat_pixmap_line; } +#endif return NULL; } diff --git a/xc/extras/Mesa/src/X/xmesa4.c b/xc/extras/Mesa/src/X/xmesa4.c index 195a531f0..350922008 100644 --- a/xc/extras/Mesa/src/X/xmesa4.c +++ b/xc/extras/Mesa/src/X/xmesa4.c @@ -1439,6 +1439,98 @@ static void setup_x_polygon_options( GLcontext *ctx ) } +#ifdef DEBUG +void +_xmesa_print_triangle_func( triangle_func triFunc ) +{ + printf("XMesa tri func = "); + if (triFunc ==smooth_TRUECOLOR_z_triangle) + printf("smooth_TRUECOLOR_z_triangle\n"); + else if (triFunc ==smooth_8A8B8G8R_z_triangle) + printf("smooth_8A8B8G8R_z_triangle\n"); + else if (triFunc ==smooth_8R8G8B_z_triangle) + printf("smooth_8R8G8B_z_triangle\n"); + else if (triFunc ==smooth_8R8G8B24_z_triangle) + printf("smooth_8R8G8B24_z_triangle\n"); + else if (triFunc ==smooth_TRUEDITHER_z_triangle) + printf("smooth_TRUEDITHER_z_triangle\n"); + else if (triFunc ==smooth_5R6G5B_z_triangle) + printf("smooth_5R6G5B_z_triangle\n"); + else if (triFunc ==smooth_DITHER_5R6G5B_z_triangle) + printf("smooth_DITHER_5R6G5B_z_triangle\n"); + else if (triFunc ==smooth_HPCR_z_triangle) + printf("smooth_HPCR_z_triangle\n"); + else if (triFunc ==smooth_DITHER8_z_triangle) + printf("smooth_DITHER8_z_triangle\n"); + else if (triFunc ==smooth_LOOKUP8_z_triangle) + printf("smooth_LOOKUP8_z_triangle\n"); + else if (triFunc ==flat_TRUECOLOR_z_triangle) + printf("flat_TRUECOLOR_z_triangle\n"); + else if (triFunc ==flat_8A8B8G8R_z_triangle) + printf("flat_8A8B8G8R_z_triangle\n"); + else if (triFunc ==flat_8R8G8B_z_triangle) + printf("flat_8R8G8B_z_triangle\n"); + else if (triFunc ==flat_8R8G8B24_z_triangle) + printf("flat_8R8G8B24_z_triangle\n"); + else if (triFunc ==flat_TRUEDITHER_z_triangle) + printf("flat_TRUEDITHER_z_triangle\n"); + else if (triFunc ==flat_5R6G5B_z_triangle) + printf("flat_5R6G5B_z_triangle\n"); + else if (triFunc ==flat_DITHER_5R6G5B_z_triangle) + printf("flat_DITHER_5R6G5B_z_triangle\n"); + else if (triFunc ==flat_HPCR_z_triangle) + printf("flat_HPCR_z_triangle\n"); + else if (triFunc ==flat_DITHER8_z_triangle) + printf("flat_DITHER8_z_triangle\n"); + else if (triFunc ==flat_LOOKUP8_z_triangle) + printf("flat_LOOKUP8_z_triangle\n"); + else if (triFunc ==smooth_TRUECOLOR_triangle) + printf("smooth_TRUECOLOR_triangle\n"); + else if (triFunc ==smooth_8A8B8G8R_triangle) + printf("smooth_8A8B8G8R_triangle\n"); + else if (triFunc ==smooth_8R8G8B_triangle) + printf("smooth_8R8G8B_triangle\n"); + else if (triFunc ==smooth_8R8G8B24_triangle) + printf("smooth_8R8G8B24_triangle\n"); + else if (triFunc ==smooth_TRUEDITHER_triangle) + printf("smooth_TRUEDITHER_triangle\n"); + else if (triFunc ==smooth_5R6G5B_triangle) + printf("smooth_5R6G5B_triangle\n"); + else if (triFunc ==smooth_DITHER_5R6G5B_triangle) + printf("smooth_DITHER_5R6G5B_triangle\n"); + else if (triFunc ==smooth_HPCR_triangle) + printf("smooth_HPCR_triangle\n"); + else if (triFunc ==smooth_DITHER8_triangle) + printf("smooth_DITHER8_triangle\n"); + else if (triFunc ==smooth_LOOKUP8_triangle) + printf("smooth_LOOKUP8_triangle\n"); + else if (triFunc ==flat_TRUECOLOR_triangle) + printf("flat_TRUECOLOR_triangle\n"); + else if (triFunc ==flat_TRUEDITHER_triangle) + printf("flat_TRUEDITHER_triangle\n"); + else if (triFunc ==flat_8A8B8G8R_triangle) + printf("flat_8A8B8G8R_triangle\n"); + else if (triFunc ==flat_8R8G8B_triangle) + printf("flat_8R8G8B_triangle\n"); + else if (triFunc ==flat_8R8G8B24_triangle) + printf("flat_8R8G8B24_triangle\n"); + else if (triFunc ==flat_5R6G5B_triangle) + printf("flat_5R6G5B_triangle\n"); + else if (triFunc ==flat_DITHER_5R6G5B_triangle) + printf("flat_DITHER_5R6G5B_triangle\n"); + else if (triFunc ==flat_HPCR_triangle) + printf("flat_HPCR_triangle\n"); + else if (triFunc ==flat_DITHER8_triangle) + printf("flat_DITHER8_triangle\n"); + else if (triFunc ==flat_LOOKUP8_triangle) + printf("flat_LOOKUP8_triangle\n"); + else if (triFunc ==flat_pixmap_triangle) + printf("flat_pixmap_triangle\n"); + else + printf("???\n"); +} +#endif + triangle_func xmesa_get_triangle_func( GLcontext *ctx ) { @@ -1578,13 +1670,20 @@ triangle_func xmesa_get_triangle_func( GLcontext *ctx ) return NULL; } else { - /* pixmap */ + /* draw to pixmap */ +#if 0 + /* XXX have to disable this because X's rasterization rules + * don't match software Mesa's. This causes a buffer invariance + * test failure in the conformance tests. + * In the future, we might provide a config option to enable this. + */ if (ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0) { if (ctx->Color.DitherFlag && depth < 24) return NULL; setup_x_polygon_options( ctx ); return flat_pixmap_triangle; } +#endif return NULL; } } diff --git a/xc/extras/Mesa/src/X/xmesaP.h b/xc/extras/Mesa/src/X/xmesaP.h index 987877509..0886fa3dc 100644 --- a/xc/extras/Mesa/src/X/xmesaP.h +++ b/xc/extras/Mesa/src/X/xmesaP.h @@ -56,6 +56,9 @@ #endif +extern _glthread_Mutex _xmesa_lock; + + /* for PF_8R8G8B24 pixel format */ typedef struct { GLubyte b; diff --git a/xc/extras/Mesa/src/X86/3dnow.c b/xc/extras/Mesa/src/X86/3dnow.c index 5255a8c7f..c252f70ea 100644 --- a/xc/extras/Mesa/src/X86/3dnow.c +++ b/xc/extras/Mesa/src/X86/3dnow.c @@ -49,7 +49,7 @@ #define XFORM_ARGS GLvector4f *to_vec, \ - const GLmatrix *mat, \ + const GLfloat m[16], \ const GLvector4f *from_vec, \ const GLubyte *mask, \ const GLubyte flag diff --git a/xc/extras/Mesa/src/X86/3dnow_norm_raw.S b/xc/extras/Mesa/src/X86/3dnow_norm_raw.S index 7d4eed85b..427ba295c 100644 --- a/xc/extras/Mesa/src/X86/3dnow_norm_raw.S +++ b/xc/extras/Mesa/src/X86/3dnow_norm_raw.S @@ -61,7 +61,7 @@ #define V3F_COUNT 8 #define V3F_STRIDE 12 -#define MAT_INV 64 +#define MAT_INV 4 #define M(i) REGOFF(i * 4, ECX) #define STRIDE REGOFF(12, ESI) @@ -72,28 +72,24 @@ GLOBL GLNAME(gl_3dnow_transform_normalize_normals_raw) GLNAME(gl_3dnow_transform_normalize_normals_raw): #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L ( ARG_LENGTHS, EDI ) - MOV_L ( ARG_IN, EAX ) - MOV_L ( ARG_DEST, EDX ) - MOV_L ( REGOFF(V3F_COUNT, EAX), EAX ) /* dest->count = in->count */ - MOV_L ( EAX, REGOFF(V3F_COUNT, EDX) ) - MOV_L ( ARG_IN, ESI ) - MOV_L ( ARG_MAT, ECX ) - MOV_L ( REGOFF(V3F_START, EDX), EAX ) /* dest->start */ - MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ - MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + PUSH_L ( EDI ) + PUSH_L ( ESI ) + PUSH_L ( EBP ) -ALIGNTEXT32 - - CMP_L ( CONST(0), REGOFF (V3F_COUNT, ESI ) ) /* count > 0 ?? */ + MOV_L ( ARG_LENGTHS, EDI ) + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EBP ) /* dest->count = in->count */ + MOV_L ( EBP, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( ARG_MAT, ECX ) + MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ + + CMP_L ( CONST(0), EBP ) /* count > 0 ?? */ JE ( LLBL (G3TN_end) ) - PUSH_L ( EBP ) MOV_L ( REGOFF (V3F_COUNT, ESI), EBP ) FEMMS @@ -101,7 +97,8 @@ ALIGNTEXT32 PUSH_L ( EAX ) PUSH_L ( EDX ) /* save counter & pointer for */ /* the normalize pass */ - + #undef FRAME_OFFSET + #define FRAME_OFFSET 24 MOVQ ( M(0), MM3 ) /* m1 | m0 */ MOVQ ( M(4), MM4 ) /* m5 | m4 */ @@ -115,8 +112,6 @@ ALIGNTEXT32 CMP_L ( CONST(0), EDI ) /* lengths == 0 ? */ JNE ( LLBL (G3TN_scale_end ) ) - #undef FRAME_OFFSET - #define FRAME_OFFSET 28 MOVD ( ARG_SCALE, MM0 ) /* | scale */ PUNPCKLDQ ( MM0, MM0 ) /* scale | scale */ @@ -138,6 +133,8 @@ LLBL (G3TN_transform): PFMUL ( MM3, MM0 ) /* x1*m1 | x0*m0 */ ADD_L ( CONST(12), EAX ) /* next r */ + PREFETCHW ( REGIND(EAX) ) + PFMUL ( MM4, MM1 ) /* x1*m5 | x0*m4 */ PFACC ( MM1, MM0 ) /* x0*m4+x1*m5 | x0*m0+x1*m1 */ @@ -156,6 +153,8 @@ LLBL (G3TN_transform): PFADD ( MM2, MM1 ) /* *not used* | x0*m8+x1*m9+x2*m*/ ADD_L ( STRIDE, EDX ) /* next normal */ + PREFETCH ( REGIND(EDX) ) + MOVD ( MM1, REGOFF(-4, EAX) ) /* write r2 */ MOVQ ( REGIND (EDX), MM0 ) /* x1 | x0 */ @@ -177,19 +176,24 @@ LLBL (G3TN_transform): ALIGNTEXT32 LLBL (G3TN_norm_w_lengths): + + PREFETCHW ( REGOFF(12,EAX) ) + MOVD ( REGIND (EDI), MM3 ) /* | length (x) */ PFMUL ( MM3, MM1 ) /* | x2 (normalize*/ PUNPCKLDQ ( MM3, MM3 ) /* length (x) | length (x) */ PFMUL ( MM3, MM0 ) /* x1 (normalized) | x0 (normalize*/ + ADD_L ( STRIDE, EDX ) /* next normal */ + ADD_L ( CONST(4), EDI ) /* next length */ + + PREFETCH ( REGIND(EDI) ) + MOVQ ( MM0, REGIND(EAX) ) /* write new x0, x1 */ MOVD ( MM1, REGOFF(8, EAX) ) /* write new x2 */ - ADD_L ( STRIDE, EDX ) /* next normal */ ADD_L ( CONST(12), EAX ) /* next r */ - - ADD_L ( CONST(4), EDI ) /* next length */ DEC_L ( EBP ) /* decrement normal counter */ MOVQ ( REGIND(EAX), MM0 ) /* x1 | x0 */ @@ -199,6 +203,9 @@ LLBL (G3TN_norm_w_lengths): ALIGNTEXT32 LLBL (G3TN_norm): + + PREFETCHW ( REGIND(EAX) ) + MOVQ ( MM0, MM3 ) /* x1 | x0 */ MOVQ ( MM1, MM4 ) /* | x2 */ @@ -233,46 +240,39 @@ LLBL (G3TN_norm): LLBL (G3TN_exit_3dnow): FEMMS - POP_L ( EBP ) LLBL (G3TN_end): + POP_L ( EBP ) POP_L ( ESI ) POP_L ( EDI ) - POP_L ( ECX ) RET ALIGNTEXT16 - GLOBL GLNAME(gl_3dnow_transform_normalize_normals_no_rot_raw) GLNAME(gl_3dnow_transform_normalize_normals_no_rot_raw): #undef FRAME_OFFSET #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L ( ARG_LENGTHS, EDI ) - MOV_L ( ARG_IN, EAX ) - MOV_L ( ARG_DEST, EDX ) - MOV_L ( REGOFF(V3F_COUNT, EAX), EAX ) /* dest->count = in->count */ - MOV_L ( EAX, REGOFF(V3F_COUNT, EDX) ) - MOV_L ( ARG_IN, ESI ) - MOV_L ( ARG_MAT, ECX ) - MOV_L ( REGOFF(V3F_START, EDX), EAX ) /* dest->start */ - MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ - MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + PUSH_L ( EDI ) + PUSH_L ( ESI ) + PUSH_L ( EBP ) -ALIGNTEXT32 - - CMP_L ( CONST(0), REGOFF (V3F_COUNT, ESI ) ) /* count > 0 ?? */ + MOV_L ( ARG_LENGTHS, EDI ) + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EBP ) /* dest->count = in->count */ + MOV_L ( EBP, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( ARG_MAT, ECX ) + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ + MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + + CMP_L ( CONST(0), EBP ) /* count > 0 ?? */ JE ( LLBL (G3TNNR_end) ) - PUSH_L ( EBP ) - MOV_L ( REGOFF (V3F_COUNT, ESI), EBP ) FEMMS MOVD ( M(0), MM0 ) /* | m0 */ @@ -284,14 +284,13 @@ ALIGNTEXT32 CMP_L ( CONST(0), EDI ) /* lengths == 0 ? */ JNE ( LLBL (G3TNNR_scale_end ) ) - #undef FRAME_OFFSET - #define FRAME_OFFSET 16 MOVD ( ARG_SCALE, MM7 ) /* | scale */ PUNPCKLDQ ( MM7, MM7 ) /* scale | scale */ PFMUL ( MM7, MM0 ) /* scale * m5 | scale * m0 */ PFMUL ( MM7, MM2 ) /* scale * m10 | scale * m10 */ +ALIGNTEXT32 LLBL (G3TNNR_scale_end): MOVQ ( REGIND(EDX), MM6 ) /* x1 | x0 */ MOVD ( REGOFF(8, EDX), MM7 ) /* | x2 */ @@ -302,10 +301,16 @@ LLBL (G3TNNR_scale_end): MOVD ( REGIND(EDI), MM3 ) /* | length (x) */ +ALIGNTEXT32 LLBL (G3TNNR_norm_w_lengths): /* use precalculated lengths */ + + PREFETCHW ( REGIND(EAX) ) + PFMUL ( MM0, MM6 ) /* x1*m5 | x0*m0 */ ADD_L ( STRIDE, EDX ) /* next normal */ + PREFETCH ( REGIND(EDX) ) + PFMUL ( MM2, MM7 ) /* | x2*m10 */ ADD_L ( CONST(12), EAX ) /* next r */ @@ -327,7 +332,11 @@ LLBL (G3TNNR_norm_w_lengths): /* use precalculated lengths */ JA ( LLBL (G3TNNR_norm_w_lengths) ) JMP ( LLBL (G3TNNR_exit_3dnow) ) +ALIGNTEXT32 LLBL (G3TNNR_norm): /* need to calculate lengths */ + + PREFETCHW ( REGIND(EAX) ) + PFMUL ( MM0, MM6 ) /* x1*m5 | x0*m0 */ ADD_L ( CONST(12), EAX ) /* next r */ @@ -337,12 +346,15 @@ LLBL (G3TNNR_norm): /* need to calculate lengths */ MOVQ ( MM7, MM4 ) /* | x2 (transformed) */ PFMUL ( MM6, MM3 ) /* x1*x1 | x0*x0 */ + PFMUL ( MM7, MM4 ) /* | x2*x2 */ PFACC ( MM3, MM3 ) /* **not used** | x0*x0+x1*x1 */ PFADD ( MM4, MM3 ) /* | x0*x0+x1*x1+x2*x2*/ ADD_L ( STRIDE, EDX ) /* next normal */ + PREFETCH ( REGIND(EDX) ) + PFRSQRT ( MM3, MM5 ) /* 1/sqrt (x0*x0+x1*x1+x2*x2) */ MOVQ ( MM5, MM4 ) @@ -367,12 +379,11 @@ LLBL (G3TNNR_norm): /* need to calculate lengths */ LLBL (G3TNNR_exit_3dnow): FEMMS - POP_L ( EBP ) LLBL (G3TNNR_end): + POP_L ( EBP ) POP_L ( ESI ) POP_L ( EDI ) - POP_L ( ECX ) RET @@ -381,38 +392,31 @@ LLBL (G3TNNR_end): ALIGNTEXT16 - GLOBL GLNAME(gl_3dnow_transform_rescale_normals_no_rot_raw) GLNAME(gl_3dnow_transform_rescale_normals_no_rot_raw): #undef FRAME_OFFSET #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L ( ARG_IN, EAX ) - MOV_L ( ARG_DEST, EDX ) - MOV_L ( REGOFF(V3F_COUNT, EAX), EAX ) /* dest->count = in->count */ - MOV_L ( EAX, REGOFF(V3F_COUNT, EDX) ) - MOV_L ( ARG_IN, ESI ) - MOV_L ( ARG_MAT, ECX ) - MOV_L ( REGOFF(V3F_START, EDX), EAX ) /* dest->start */ - MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ - MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + PUSH_L ( EDI ) + PUSH_L ( ESI ) + PUSH_L ( EBP ) -ALIGNTEXT32 - - CMP_L ( CONST(0), REGOFF (V3F_COUNT, ESI) ) + MOV_L ( ARG_IN, EAX ) + MOV_L ( ARG_DEST, EDX ) + MOV_L ( REGOFF(V3F_COUNT, EAX), EBP ) /* dest->count = in->count */ + MOV_L ( EBP, REGOFF(V3F_COUNT, EDX) ) + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_MAT, ECX ) + MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ + MOV_L ( REGOFF(V3F_START, EDX), EAX ) /* dest->start */ + MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + + CMP_L ( CONST(0), EBP ) JE ( LLBL (G3TRNR_end) ) - PUSH_L ( EBP ) - MOV_L ( REGOFF (V3F_COUNT, ESI), EBP ) FEMMS - #undef FRAME_OFFSET - #define FRAME_OFFSET 16 MOVD ( ARG_SCALE, MM6 ) /* | scale */ PUNPCKLDQ ( MM6, MM6 ) /* scale | scale */ @@ -428,11 +432,15 @@ ALIGNTEXT32 MOVD ( REGOFF(8, EDX), MM5 ) /* | x2 */ ALIGNTEXT32 - LLBL (G3TRNR_rescale): + + PREFETCHW ( REGIND(EAX) ) + PFMUL ( MM0, MM4 ) /* x1*m5 | x0*m0 */ ADD_L ( STRIDE, EDX ) /* next normal */ + PREFETCH ( REGIND(EDX) ) + PFMUL ( MM2, MM5 ) /* | x2*m10 */ ADD_L ( CONST(12), EAX ) /* next r */ @@ -446,12 +454,11 @@ LLBL (G3TRNR_rescale): JA ( LLBL (G3TRNR_rescale) ) /* cnt > 0 ? -> process next normal */ FEMMS - POP_L ( EBP ) LLBL (G3TRNR_end): + POP_L ( EBP ) POP_L ( ESI ) POP_L ( EDI ) - POP_L ( ECX ) RET @@ -463,24 +470,19 @@ GLOBL GLNAME(gl_3dnow_transform_rescale_normals_raw) GLNAME(gl_3dnow_transform_rescale_normals_raw): #undef FRAME_OFFSET - #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L (REGOFF(24,ESP), EAX) - MOV_L (REGOFF(36,ESP), EDX) - MOV_L (REGOFF(8,EAX), EAX) - MOV_L (EAX, REGOFF(8,EDX)) - MOV_L (REGOFF(24,ESP), EDI) - MOV_L (REGOFF(4,EDX), EAX) - MOV_L (REGOFF(16,ESP), ECX) - MOV_L (REGOFF(24,ESP), ESI) - MOV_L (REGOFF(64,ECX), ECX) - MOV_L (REGOFF(4,EDI), EDX) - MOV_L (REGOFF(8,EDI), EDI) + #define FRAME_OFFSET 8 -ALIGNTEXT32 + PUSH_L ( EDI ) + PUSH_L ( ESI ) + + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( ARG_MAT, ECX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EDI ) /* dest->count = in->count */ + MOV_L ( EDI, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ CMP_L ( CONST(0), EDI ) JE ( LLBL (G3TR_end) ) @@ -490,12 +492,12 @@ ALIGNTEXT32 MOVQ ( REGIND(ECX), MM3 ) /* m1 | m0 */ MOVQ ( REGOFF(16,ECX), MM4 ) /* m5 | m4 */ - MOVD ( REGOFF(20, ESP), MM0 ) /* scale */ + MOVD ( ARG_SCALE, MM0 ) /* scale */ MOVD ( REGOFF(8,ECX), MM5 ) /* | m2 */ PUNPCKLDQ ( MM0, MM0 ) /* scale | scale */ - PUNPCKLDQ ( REGOFF(24, ECX), MM5 ) + PUNPCKLDQ ( REGOFF(24, ECX), MM5 ) PFMUL ( MM0, MM3 ) /* scale*m1 | scale*m0 */ MOVQ ( REGOFF(32, ECX), MM6 ) /* m9 | m8*/ @@ -510,7 +512,11 @@ ALIGNTEXT32 PFMUL ( MM0, MM7 ) /* | scale*m10 */ MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */ +ALIGNTEXT32 LLBL (G3TR_rescale): + + PREFETCHW ( REGIND(EAX) ) + MOVQ ( MM0, MM1 ) /* x1 | x0 */ PUNPCKLDQ ( MM2, MM2 ) /* x2 | x2 */ @@ -520,25 +526,28 @@ LLBL (G3TR_rescale): PFMUL ( MM4, MM1 ) /* x1*m5 | x0*m4 */ PFACC ( MM1, MM0 ) /* x0*m4+x1*m5 | x0*m0+x1*m1 */ + MOVQ ( REGIND(EDX), MM1 ) /* x1 | x0 */ + PFMUL ( MM5, MM2 ) /* x2*m6 | x2*m2 */ PFADD ( MM2, MM0 ) /* x0*m4...+x2*m6| x0*m0+x1*m1+x2*m2 */ - MOVQ ( REGIND(EDX), MM1 ) /* x1 | x0 */ - MOVQ ( MM0, REGOFF(-12, EAX) ) /* write r0, r1 */ + MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */ + ADD_L ( STRIDE, EDX ) /* next normal */ + + PREFETCH ( REGIND(EDX) ) + MOVQ ( MM0, REGOFF(-12, EAX) ) /* write r0, r1 */ PFMUL ( MM6, MM1 ) /* x1*m9 | x0*m8 */ - MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */ PFMUL ( MM7, MM2 ) /* | x2*m10 */ PFACC ( MM1, MM1 ) /* *not used* | x0*m8+x1*m9 */ PFADD ( MM2, MM1 ) /* *not used* | x0*m8+x1*m9+x2*m10 */ - ADD_L ( REGOFF(12, ESI), EDX ) /* next normal */ - MOVD ( MM1, REGOFF(-4, EAX) ) /* write r2 */ - MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */ + MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */ MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */ + DEC_L ( EDI ) /* decrement normal counter */ JA ( LLBL (G3TR_rescale) ) @@ -547,7 +556,6 @@ LLBL (G3TR_rescale): LLBL (G3TR_end): POP_L ( ESI ) POP_L ( EDI ) - POP_L ( ECX ) RET @@ -560,25 +568,20 @@ ALIGNTEXT16 GLOBL GLNAME(gl_3dnow_transform_normals_no_rot_raw) GLNAME(gl_3dnow_transform_normals_no_rot_raw): - #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L (REGOFF(24,ESP), EAX) - MOV_L (REGOFF(36,ESP), EDX) - MOV_L (REGOFF(8,EAX), EAX) - MOV_L (EAX, REGOFF(8,EDX)) - MOV_L (REGOFF(24,ESP), EDI) - MOV_L (REGOFF(4,EDX), EAX) - MOV_L (REGOFF(16,ESP), ECX) - MOV_L (REGOFF(24,ESP), ESI) - MOV_L (REGOFF(64,ECX), ECX) - MOV_L (REGOFF(4,EDI), EDX) - MOV_L (REGOFF(8,EDI), EDI) - - -ALIGNTEXT32 + #undef FRAME_OFFSET + #define FRAME_OFFSET 8 + + PUSH_L ( EDI ) + PUSH_L ( ESI ) + + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( ARG_MAT, ECX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EDI ) /* dest->count = in->count */ + MOV_L ( EDI, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ CMP_L ( CONST(0), EDI ) JE ( LLBL (G3TNR_end) ) @@ -595,10 +598,14 @@ ALIGNTEXT32 MOVD ( REGOFF(8, EDX), MM5 ) /* | x2 */ ALIGNTEXT32 - LLBL (G3TNR_transform): + + PREFETCHW ( REGIND(EAX) ) + PFMUL ( MM0, MM4 ) /* x1*m5 | x0*m0 */ - ADD_L ( REGOFF(12, ESI), EDX) /* next normal */ + ADD_L ( STRIDE, EDX) /* next normal */ + + PREFETCH ( REGIND(EDX) ) PFMUL ( MM2, MM5 ) /* | x2*m10 */ ADD_L ( CONST(12), EAX ) /* next r */ @@ -617,7 +624,6 @@ LLBL (G3TNR_transform): LLBL (G3TNR_end): POP_L ( ESI ) POP_L ( EDI ) - POP_L ( ECX ) RET @@ -631,24 +637,20 @@ ALIGNTEXT16 GLOBL GLNAME(gl_3dnow_transform_normals_raw) GLNAME(gl_3dnow_transform_normals_raw): - #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L (REGOFF(24,ESP), EAX) - MOV_L (REGOFF(36,ESP), EDX) - MOV_L (REGOFF(8,EAX), EAX) - MOV_L (EAX, REGOFF(8,EDX)) - MOV_L (REGOFF(24,ESP), EDI) - MOV_L (REGOFF(4,EDX), EAX) - MOV_L (REGOFF(16,ESP), ECX) - MOV_L (REGOFF(24,ESP), ESI) - MOV_L (REGOFF(64,ECX), ECX) - MOV_L (REGOFF(4,EDI), EDX) - MOV_L (REGOFF(8,EDI), EDI) - -ALIGNTEXT32 + #undef FRAME_OFFSET + #define FRAME_OFFSET 8 + + PUSH_L ( EDI ) + PUSH_L ( ESI ) + + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( ARG_MAT, ECX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EDI ) /* dest->count = in->count */ + MOV_L ( EDI, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( REGOFF(V3F_START, ESI), EDX ) /* in->start */ + MOV_L ( REGOFF(MAT_INV, ECX), ECX ) /* mat->inv */ CMP_L ( CONST(0), EDI ) /* count > 0 ?? */ JE ( LLBL (G3T_end) ) @@ -659,15 +661,19 @@ ALIGNTEXT32 MOVQ ( REGOFF(16, ECX), MM4 ) /* m5 | m4 */ MOVD ( REGOFF(8, ECX), MM5 ) /* | m2 */ - PUNPCKLDQ ( REGOFF(24, ECX), MM5 ) /* m6 | m2*/ + PUNPCKLDQ ( REGOFF(24, ECX), MM5 ) /* m6 | m2 */ - MOVQ ( REGOFF(32,ECX), MM6 ) /* m9 | m8 */ - MOVD ( REGOFF(40,ECX), MM7 ) /* | m10 */ + MOVQ ( REGOFF(32, ECX), MM6 ) /* m9 | m8 */ + MOVD ( REGOFF(40, ECX), MM7 ) /* | m10 */ MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */ MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */ +ALIGNTEXT32 LLBL (G3T_transform): + + PREFETCHW ( REGIND(EAX) ) + MOVQ ( MM0, MM1 ) /* x1 | x0 */ PUNPCKLDQ ( MM2, MM2 ) /* x2 | x2 */ @@ -687,10 +693,12 @@ LLBL (G3T_transform): MOVD ( REGOFF(8, EDX), MM2 ) /* | x2 */ PFMUL ( MM7, MM2 ) /* | x2*m10 */ - PFACC ( MM1, MM1 ) /* *not used* | x0*m8+x1*m9 */ + ADD_L ( STRIDE, EDX ) /* next normal */ + PREFETCH ( REGIND(EDX) ) + + PFACC ( MM1, MM1 ) /* *not used* | x0*m8+x1*m9 */ PFADD ( MM2, MM1 ) /* *not used* | x0*m8+x1*m9+x2*m10 */ - ADD_L ( REGOFF(12, ESI), EDX ) /* next normal */ MOVD ( MM1, REGOFF(-4, EAX) ) /* write r2 */ MOVQ ( REGIND(EDX), MM0 ) /* x1 | x0 */ @@ -704,7 +712,6 @@ LLBL (G3T_transform): LLBL (G3T_end): POP_L ( ESI ) POP_L ( EDI ) - POP_L ( ECX ) RET @@ -716,30 +723,23 @@ ALIGNTEXT16 GLOBL GLNAME(gl_3dnow_normalize_normals_raw) GLNAME(gl_3dnow_normalize_normals_raw): + #undef FRAME_OFFSET #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L (REGOFF(16,ESP), ESI) - MOV_L (REGOFF(24,ESP), EAX) - MOV_L (REGOFF(36,ESP), EDX) - MOV_L (REGOFF(8,EAX), EAX) - MOV_L (EAX, REGOFF(8,EDX)) - MOV_L (REGOFF(4,EDX), EAX) - MOV_L (REGOFF(24,ESP), ECX) - MOV_L (REGOFF(28,ESP), EDX) - MOV_L (REGOFF(24,ESP), EDI) - MOV_L (REGOFF(4,ECX), ECX) - - -ALIGNTEXT32 - - CMP_L ( CONST(0), REGOFF(8, EDI) ) /* count > 0 ?? */ - JE ( LLBL (G3N_end) ) + PUSH_L ( EDI ) + PUSH_L ( ESI ) PUSH_L ( EBP ) - MOV_L (REGOFF(8,EDI), EBP) + + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EBP ) /* dest->count = in->count */ + MOV_L ( EBP, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( REGOFF(V3F_START, ESI), ECX ) /* in->start */ + MOV_L ( ARG_LENGTHS, EDX ) + + CMP_L ( CONST(0), EBP ) /* count > 0 ?? */ + JE ( LLBL (G3N_end) ) FEMMS @@ -749,17 +749,23 @@ ALIGNTEXT32 CMP_L ( CONST(0), EDX ) /* lengths == 0 ? */ JE ( LLBL (G3N_norm2) ) /* calculate lengths */ +ALIGNTEXT32 LLBL (G3N_norm1): /* use precalculated lengths */ + + PREFETCH ( REGIND(EAX) ) + MOVD ( REGIND(EDX), MM3 ) /* | length (x) */ PFMUL ( MM3, MM1 ) /* | x2 (normalized) */ PUNPCKLDQ ( MM3, MM3 ) /* length (x) | length (x) */ - PFMUL ( MM3, MM0 ) /* x1 (normalized) | x0 (normalized) */ + ADD_L ( STRIDE, ECX ) /* next normal */ + + PREFETCH ( REGIND(ECX) ) + PFMUL ( MM3, MM0 ) /* x1 (normalized) | x0 (normalized) */ MOVQ ( MM0, REGIND(EAX) ) /* write new x0, x1 */ - MOVD ( MM1, REGOFF(8, EAX) ) /* write new x2 */ - ADD_L ( REGOFF(12, EDI), ECX ) /* next normal */ + MOVD ( MM1, REGOFF(8, EAX) ) /* write new x2 */ ADD_L ( CONST(12), EAX ) /* next r */ ADD_L ( CONST(4), EDX ) /* next length */ @@ -771,10 +777,15 @@ LLBL (G3N_norm1): /* use precalculated lengths */ JMP ( LLBL (G3N_end1) ) -LLBL (G3N_norm2): - /* need to calculate lengths */ +ALIGNTEXT32 +LLBL (G3N_norm2): /* need to calculate lengths */ + + PREFETCHW ( REGIND(EAX) ) + MOVQ ( MM0, MM3 ) /* x1 | x0 */ - ADD_L ( REGOFF(12, EDI), ECX ) /* next normal */ + ADD_L ( STRIDE, ECX ) /* next normal */ + + PREFETCH ( REGIND(ECX) ) PFMUL ( MM0, MM3 ) /* x1*x1 | x0*x0 */ MOVQ ( MM1, MM4 ) /* | x2 */ @@ -808,12 +819,11 @@ LLBL (G3N_norm2): LLBL (G3N_end1): FEMMS - POP_L ( EBP ) LLBL (G3N_end): - POP_L ( ESI ) - POP_L ( EDI ) - POP_L ( ECX ) + POP_L ( EBP ) + POP_L ( ESI ) + POP_L ( EDI ) RET @@ -825,48 +835,46 @@ ALIGNTEXT16 GLOBL GLNAME(gl_3dnow_rescale_normals_raw) GLNAME(gl_3dnow_rescale_normals_raw): - #define FRAME_OFFSET 12 - SUB_L ( CONST(4), ESP ) - PUSH_L ( EDI ) - PUSH_L ( ESI ) - - MOV_L (REGOFF(20,ESP), ESI) - MOV_L (REGOFF(24,ESP), EAX) - MOV_L (REGOFF(36,ESP), EDX) - MOV_L (REGOFF(8,EAX), EAX) - MOV_L (EAX, REGOFF(8,EDX)) - MOV_L (REGOFF(24,ESP), EDI) - MOV_L (EDI, ECX) - MOV_L (REGOFF(4,EDX), EAX) - MOV_L (REGOFF(4,ECX), ECX) - MOV_L (REGOFF(8,EDI), EDX) + #undef FRAME_OFFSET + #define FRAME_OFFSET 8 + PUSH_L ( EDI ) + PUSH_L ( ESI ) -ALIGNTEXT32 + MOV_L ( ARG_IN, ESI ) + MOV_L ( ARG_DEST, EAX ) + MOV_L ( REGOFF(V3F_COUNT, ESI), EDX ) /* dest->count = in->count */ + MOV_L ( EDX, REGOFF(V3F_COUNT, EAX) ) + MOV_L ( REGOFF(V3F_START, EAX), EAX ) /* dest->start */ + MOV_L ( REGOFF(V3F_START, ESI), ECX ) /* in->start */ CMP_L ( CONST(0), EDX ) JE ( LLBL (G3R_end) ) FEMMS - MOVD ( ESI, MM0 ) /* scale */ + MOVD ( ARG_SCALE, MM0 ) /* scale */ PUNPCKLDQ ( MM0, MM0 ) MOVQ ( REGIND(ECX), MM1 ) /* x1 | x0 */ MOVD ( REGOFF(8, ECX), MM2 ) /* | x2 */ ALIGNTEXT32 - LLBL (G3R_rescale): + + PREFETCHW ( REGIND(EAX) ) + PFMUL ( MM0, MM1 ) /* x1*scale | x0*scale */ - ADD_L ( REGOFF(12, EDI), ECX ) /* next normal */ + ADD_L ( STRIDE, ECX ) /* next normal */ + + PREFETCH ( REGIND(ECX) ) PFMUL ( MM0, MM2 ) /* | x2*scale */ ADD_L ( CONST(12), EAX ) /* next r */ - DEC_L ( EDX ) /* decrement normal counter */ MOVQ ( MM1, REGOFF(-12, EAX) ) /* write r0, r1 */ - MOVD ( MM2, REGOFF(-4, EAX) ) /* write r2 */ + + DEC_L ( EDX ) /* decrement normal counter */ MOVQ ( REGIND(ECX), MM1 ) /* x1 | x0 */ MOVD ( REGOFF(8, ECX), MM2 ) /* | x2 */ @@ -875,17 +883,9 @@ LLBL (G3R_rescale): FEMMS LLBL (G3R_end): - POP_L ( ESI ) - POP_L ( EDI ) - POP_L ( ECX ) + POP_L ( ESI ) + POP_L ( EDI ) RET - - - - - - - diff --git a/xc/extras/Mesa/src/X86/katmai.c b/xc/extras/Mesa/src/X86/katmai.c index 1dfa0f7fc..d27f89b2d 100644 --- a/xc/extras/Mesa/src/X86/katmai.c +++ b/xc/extras/Mesa/src/X86/katmai.c @@ -49,7 +49,7 @@ #define XFORM_ARGS GLvector4f *to_vec, \ - const GLmatrix *mat, \ + const GLfloat m[16], \ const GLvector4f *from_vec, \ const GLubyte *mask, \ const GLubyte flag diff --git a/xc/extras/Mesa/src/X86/katmai_xform_masked1.S b/xc/extras/Mesa/src/X86/katmai_xform_masked1.S index f3e11c803..235ac4e57 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_masked1.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_masked1.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_masked2.S b/xc/extras/Mesa/src/X86/katmai_xform_masked2.S index a4936fa6a..45193f19c 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_masked2.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_masked2.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_masked3.S b/xc/extras/Mesa/src/X86/katmai_xform_masked3.S index 10f3c41b5..3258f521e 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_masked3.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_masked3.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_masked4.S b/xc/extras/Mesa/src/X86/katmai_xform_masked4.S index 4a0bf5c05..82d960c02 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_masked4.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_masked4.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_raw1.S b/xc/extras/Mesa/src/X86/katmai_xform_raw1.S index 4ca992d2c..e6ff089e2 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_raw1.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_raw1.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_raw2.S b/xc/extras/Mesa/src/X86/katmai_xform_raw2.S index 61845034c..993880885 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_raw2.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_raw2.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_raw3.S b/xc/extras/Mesa/src/X86/katmai_xform_raw3.S index 49918de95..35f95f511 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_raw3.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_raw3.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/katmai_xform_raw4.S b/xc/extras/Mesa/src/X86/katmai_xform_raw4.S index d0867da7c..5a38a2f4e 100644 --- a/xc/extras/Mesa/src/X86/katmai_xform_raw4.S +++ b/xc/extras/Mesa/src/X86/katmai_xform_raw4.S @@ -32,7 +32,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/X86/x86.c b/xc/extras/Mesa/src/X86/x86.c index 1b24811d4..606ec7051 100644 --- a/xc/extras/Mesa/src/X86/x86.c +++ b/xc/extras/Mesa/src/X86/x86.c @@ -36,23 +36,23 @@ #include "x86.h" #ifdef USE_X86_ASM -extern void _ASMAPI gl_v16_x86_cliptest_points4(GLfloat *first_vert, +extern void _ASMAPI gl_v16_x86_cliptest_points4( GLfloat *first_vert, GLfloat *last_vert, GLubyte *or_mask, GLubyte *and_mask, GLubyte *clip_mask ); -extern void _ASMAPI gl_v16_x86_general_xform(GLfloat *dest, +extern void _ASMAPI gl_v16_x86_general_xform( GLfloat *dest, const GLfloat *m, const GLfloat *src, GLuint src_stride, - GLuint count); + GLuint count ); #endif #define XFORM_ARGS GLvector4f *to_vec, \ - const GLmatrix *mat, \ + const GLfloat m[16], \ const GLvector4f *from_vec, \ const GLubyte *mask, \ const GLubyte flag @@ -117,7 +117,6 @@ void gl_init_x86_asm_transforms( void ) gl_test_all_transform_functions("x86"); #endif - gl_cliptest_points4_v16 = gl_v16_x86_cliptest_points4; gl_xform_points3_v16_general = gl_v16_x86_general_xform; #endif diff --git a/xc/extras/Mesa/src/X86/x86a.S b/xc/extras/Mesa/src/X86/x86a.S index 621bc1f1a..bae1e8f65 100644 --- a/xc/extras/Mesa/src/X86/x86a.S +++ b/xc/extras/Mesa/src/X86/x86a.S @@ -28,7 +28,7 @@ * Offsets for transform_func arguments * * typedef void (*transform_func)( GLvector4f *to_vec, - * const GLmatrix *mat, + * const GLfloat m[16], * const GLvector4f *from_vec, * const GLubyte *clipmask, * const GLubyte flag ); diff --git a/xc/extras/Mesa/src/accum.c b/xc/extras/Mesa/src/accum.c index 71475eefb..5161c9f31 100644 --- a/xc/extras/Mesa/src/accum.c +++ b/xc/extras/Mesa/src/accum.c @@ -353,9 +353,8 @@ _mesa_Accum( GLenum op, GLfloat value ) static GLchan multTable[32768]; static GLfloat prevMult = 0.0; GLuint j; - const GLint max = (GLint) (256 / mult); + const GLint max = MIN2((GLint) (256 / mult), 32767); if (mult != prevMult) { - assert(max <= 32768); for (j = 0; j < max; j++) multTable[j] = (GLint) ((GLfloat) j * mult + 0.5F); prevMult = mult; diff --git a/xc/extras/Mesa/src/attrib.c b/xc/extras/Mesa/src/attrib.c index 2e750ffdb..cc736bdc5 100644 --- a/xc/extras/Mesa/src/attrib.c +++ b/xc/extras/Mesa/src/attrib.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.1 + * Version: 3.3 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -358,6 +358,7 @@ _mesa_PushAttrib(GLbitfield mask) copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].CurrentD[1]); copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].CurrentD[2]); copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].CurrentD[3]); + copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap); } newnode = new_attrib_node( GL_TEXTURE_BIT ); newnode->data = attr; @@ -473,11 +474,14 @@ _mesa_PopAttrib(void) break; case GL_DEPTH_BUFFER_BIT: { + GLboolean oldDepthTest = ctx->Depth.Test; GLenum oldDepthFunc = ctx->Depth.Func; GLboolean oldDepthMask = ctx->Depth.Mask; GLfloat oldDepthClear = ctx->Depth.Clear; MEMCPY( &ctx->Depth, attr->data, sizeof(struct gl_depthbuffer_attrib) ); + if (ctx->Depth.Test != oldDepthTest && ctx->Driver.Enable) + (*ctx->Driver.Enable)( ctx, GL_DEPTH_TEST, ctx->Depth.Test); if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc) (*ctx->Driver.DepthFunc)( ctx, ctx->Depth.Func ); if (ctx->Depth.Mask != oldDepthMask && ctx->Driver.DepthMask) @@ -769,9 +773,13 @@ _mesa_PopAttrib(void) &(ctx->Texture.Unit[u].Saved2D) ); copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3], &(ctx->Texture.Unit[u].Saved3D) ); + copy_texobj_state( ctx->Texture.Unit[u].CurrentCubeMap, + &(ctx->Texture.Unit[u].SavedCubeMap) ); + gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] ); gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] ); gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] ); + gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentCubeMap ); } } diff --git a/xc/extras/Mesa/src/blend.c b/xc/extras/Mesa/src/blend.c index 9419393f6..46f846939 100644 --- a/xc/extras/Mesa/src/blend.c +++ b/xc/extras/Mesa/src/blend.c @@ -663,7 +663,7 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[], dR = dG = dB = ctx->Color.BlendColor[3]; break; case GL_ONE_MINUS_CONSTANT_ALPHA: - dR = dG = dB = 1.0F - ctx->Color.BlendColor[3] * ascale; + dR = dG = dB = 1.0F - ctx->Color.BlendColor[3]; break; case GL_DST_COLOR: /* GL_NV_blend_square */ dR = (GLfloat) Rd * rscale; @@ -717,7 +717,7 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[], dA = ctx->Color.BlendColor[3]; break; case GL_ONE_MINUS_CONSTANT_ALPHA: - dA = 1.0F - ctx->Color.BlendColor[3] * ascale; + dA = 1.0F - ctx->Color.BlendColor[3]; break; case GL_DST_COLOR: /* GL_NV_blend_square */ dA = (GLfloat) Ad * ascale; diff --git a/xc/extras/Mesa/src/buffers.c b/xc/extras/Mesa/src/buffers.c index 086dc9345..566afed92 100644 --- a/xc/extras/Mesa/src/buffers.c +++ b/xc/extras/Mesa/src/buffers.c @@ -151,10 +151,9 @@ clear_color_buffer(GLcontext *ctx) const GLubyte a = (GLint) (ctx->Color.ClearColor[3] * 255.0F); GLubyte span[MAX_WIDTH][4]; GLint i; - ASSERT(ctx->Color.ColorMask[0] && - ctx->Color.ColorMask[1] && - ctx->Color.ColorMask[2] && - ctx->Color.ColorMask[3]); + + ASSERT(!ctx->Color.SWmasking); + for (i = 0; i < width; i++) { span[i][RCOMP] = r; span[i][GCOMP] = g; @@ -299,7 +298,7 @@ _mesa_Clear( GLbitfield mask ) /* clear software-based alpha buffer(s) */ if ( (mask & GL_COLOR_BUFFER_BIT) && ctx->DrawBuffer->UseSoftwareAlphaBuffers - && ctx->Color.ColorMask[RCOMP]) { + && ctx->Color.ColorMask[ACOMP]) { _mesa_clear_alpha_buffers( ctx ); } diff --git a/xc/extras/Mesa/src/clip_funcs.h b/xc/extras/Mesa/src/clip_funcs.h index 5f0591872..e0003bf3d 100644 --- a/xc/extras/Mesa/src/clip_funcs.h +++ b/xc/extras/Mesa/src/clip_funcs.h @@ -162,14 +162,18 @@ static GLuint TAG(viewclip_polygon)( struct vertex_buffer *VB, clipmask[idxPrev] |= (PLANE&CLIP_ALL_BITS); \ \ if (!NEGATIVE(dpPrev)) { \ + if (IND&CLIP_TAB_EDGEFLAG) { \ + if (outcount) \ + VB->EdgeFlagPtr->data[outlist[outcount-1]] &= ~2; \ + } \ outlist[outcount++] = idxPrev; \ clipmask[idxPrev] &= ~(PLANE&CLIP_ALL_BITS); \ } \ \ if (DIFFERENT_SIGNS(dp, dpPrev)) { \ - if (NEGATIVE(dp)) { \ - /* Coming back in. Avoid division by zero as we know \ - * dp != dpPrev from DIFFERENT_SIGNS, above. \ + if (NEGATIVE(dp)) { \ + /* Going out of bounds. Avoid division by zero as we \ + * know dp != dpPrev from DIFFERENT_SIGNS, above. \ */ \ GLfloat t = dp / (dp - dpPrev); \ INTERP_SZ( t, VB->ClipPtr->data, vb_free, \ @@ -177,26 +181,26 @@ static GLuint TAG(viewclip_polygon)( struct vertex_buffer *VB, interp( VB, vb_free, t, idx, idxPrev ); \ \ if (IND&CLIP_TAB_EDGEFLAG) \ - VB->EdgeFlagPtr->data[vb_free] = \ - VB->EdgeFlagPtr->data[idxPrev]; \ + VB->EdgeFlagPtr->data[vb_free] = 3; \ } else { \ - /* Going out of bounds \ + /* Coming back in. \ */ \ GLfloat t = dpPrev / (dpPrev - dp); \ - INTERP_SZ( t, VB->ClipPtr->data, vb_free, \ + INTERP_SZ( t, VB->ClipPtr->data, vb_free, \ idxPrev, idx, SIZE ); \ interp( VB, vb_free, t, idxPrev, idx ); \ \ - if (IND&CLIP_TAB_EDGEFLAG) \ - VB->EdgeFlagPtr->data[vb_free] = 3; \ + if (IND&CLIP_TAB_EDGEFLAG) { \ + VB->EdgeFlagPtr->data[vb_free] = \ + VB->EdgeFlagPtr->data[idxPrev]; \ + } \ } \ \ - if (IND&CLIP_TAB_EDGEFLAG) { \ /* Demote trailing edge to internal edge. \ */ \ - if (outcount && \ - (VB->EdgeFlagPtr->data[outlist[outcount-1]] & 0x2)) \ - VB->EdgeFlagPtr->data[outlist[outcount-1]] = 1; \ + if (IND&CLIP_TAB_EDGEFLAG) { \ + if (outcount) \ + VB->EdgeFlagPtr->data[outlist[outcount-1]] &= ~2; \ } \ \ outlist[outcount++] = vb_free; \ @@ -210,6 +214,7 @@ static GLuint TAG(viewclip_polygon)( struct vertex_buffer *VB, if (outcount < 3) \ return 0; \ \ + \ { \ GLuint *tmp = inlist; \ inlist = outlist; \ @@ -218,7 +223,6 @@ static GLuint TAG(viewclip_polygon)( struct vertex_buffer *VB, } \ } - #include "general_clip.h" if (inlist != vlist) @@ -365,6 +369,8 @@ static GLuint TAG(userclip_polygon)( struct vertex_buffer *VB, GLuint flagI = INSIDE(dpI); if (flagJ) { + if ((IND&CLIP_TAB_EDGEFLAG) && outcount) + VB->EdgeFlagPtr->data[outlist[outcount-1]] &= ~2; outlist[outcount++] = prevj; } else { VB->ClipMask[prevj] |= CLIP_USER_BIT; @@ -392,12 +398,11 @@ static GLuint TAG(userclip_polygon)( struct vertex_buffer *VB, VB->EdgeFlagPtr->data[vb_free] = 3; } - if (IND&CLIP_TAB_EDGEFLAG) { /* Demote trailing edge to internal edge. */ - if (outcount && - (VB->EdgeFlagPtr->data[outlist[outcount-1]] & 0x2)) - VB->EdgeFlagPtr->data[outlist[outcount-1]] = 1; + if (IND&CLIP_TAB_EDGEFLAG) { + if (outcount) + VB->EdgeFlagPtr->data[outlist[outcount-1]] &= ~2; } INTERP_SZ( t, coord, vb_free, in, out, SIZE ); diff --git a/xc/extras/Mesa/src/colortab.c b/xc/extras/Mesa/src/colortab.c index e15014dfe..3b6cb37ec 100644 --- a/xc/extras/Mesa/src/colortab.c +++ b/xc/extras/Mesa/src/colortab.c @@ -300,7 +300,8 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, assert(table); - if (!_mesa_is_legal_format_and_type(format, type)) { + if (!_mesa_is_legal_format_and_type(format, type) || + format == GL_INTENSITY) { gl_error(ctx, GL_INVALID_ENUM, "glColorTable(format or type)"); return; } @@ -311,17 +312,30 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, return; } - if (width < 1 || width > ctx->Const.MaxColorTableSize - || _mesa_bitcount(width) != 1) { - if (width > ctx->Const.MaxColorTableSize) - gl_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); - else + if (width < 0 || _mesa_bitcount(width) != 1) { + if (proxy) { + table->Size = 0; + table->IntFormat = (GLenum) 0; + table->Format = (GLenum) 0; + } + else { gl_error(ctx, GL_INVALID_VALUE, "glColorTable(width)"); + } + return; + } + + if (width > ctx->Const.MaxColorTableSize) { if (proxy) { table->Size = 0; table->IntFormat = (GLenum) 0; table->Format = (GLenum) 0; } + else { + if (width > ctx->Const.MaxColorTableSize) + gl_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); + else + gl_error(ctx, GL_INVALID_VALUE, "glColorTable(width)"); + } return; } @@ -339,14 +353,14 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, FREE(table->Table); } if (floatTable) { - GLubyte tableUB[MAX_COLOR_TABLE_SIZE * 4]; + GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; GLfloat *tableF; GLuint i; - _mesa_unpack_ubyte_color_span(ctx, width, table->Format, - tableUB, /* dest */ + _mesa_unpack_float_color_span(ctx, width, table->Format, + tempTab, /* dest */ format, type, data, - &ctx->Unpack, GL_TRUE); + &ctx->Unpack, GL_TRUE, GL_FALSE); table->TableType = GL_FLOAT; table->Table = MALLOC(comps * width * sizeof(GLfloat)); @@ -355,50 +369,43 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, return; } - /* Apply scale and bias and convert GLubyte values to GLfloats - * in [0, 1]. Store results in the tableF[]. - */ - rScale /= 255.0; - gScale /= 255.0; - bScale /= 255.0; - aScale /= 255.0; tableF = (GLfloat *) table->Table; switch (table->Format) { case GL_INTENSITY: for (i = 0; i < width; i++) { - tableF[i] = tableUB[i] * rScale + rBias; + tableF[i] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); } break; case GL_LUMINANCE: for (i = 0; i < width; i++) { - tableF[i] = tableUB[i] * rScale + rBias; + tableF[i] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); } break; case GL_ALPHA: for (i = 0; i < width; i++) { - tableF[i] = tableUB[i] * aScale + aBias; + tableF[i] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); } break; case GL_LUMINANCE_ALPHA: for (i = 0; i < width; i++) { - tableF[i*2+0] = tableUB[i*2+0] * rScale + rBias; - tableF[i*2+1] = tableUB[i*2+1] * aScale + aBias; + tableF[i*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); + tableF[i*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); } break; case GL_RGB: for (i = 0; i < width; i++) { - tableF[i*3+0] = tableUB[i*3+0] * rScale + rBias; - tableF[i*3+1] = tableUB[i*3+1] * gScale + gBias; - tableF[i*3+2] = tableUB[i*3+2] * bScale + bBias; + tableF[i*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); + tableF[i*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); + tableF[i*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); } break; case GL_RGBA: for (i = 0; i < width; i++) { - tableF[i*4+0] = tableUB[i*4+0] * rScale + rBias; - tableF[i*4+1] = tableUB[i*4+1] * gScale + gBias; - tableF[i*4+2] = tableUB[i*4+2] * bScale + bBias; - tableF[i*4+3] = tableUB[i*4+3] * aScale + aBias; + tableF[i*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); + tableF[i*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); + tableF[i*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); + tableF[i*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); } break; default: @@ -440,6 +447,8 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; struct gl_texture_object *texObj = NULL; struct gl_color_table *table = NULL; + GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0; + GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0; GLint comps; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorSubTable"); @@ -462,12 +471,36 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, break; case GL_COLOR_TABLE: table = &ctx->ColorTable; + rScale = ctx->Pixel.ColorTableScale[0]; + gScale = ctx->Pixel.ColorTableScale[1]; + bScale = ctx->Pixel.ColorTableScale[2]; + aScale = ctx->Pixel.ColorTableScale[3]; + rBias = ctx->Pixel.ColorTableBias[0]; + gBias = ctx->Pixel.ColorTableBias[1]; + bBias = ctx->Pixel.ColorTableBias[2]; + aBias = ctx->Pixel.ColorTableBias[3]; break; case GL_POST_CONVOLUTION_COLOR_TABLE: table = &ctx->PostConvolutionColorTable; + rScale = ctx->Pixel.PCCTscale[0]; + gScale = ctx->Pixel.PCCTscale[1]; + bScale = ctx->Pixel.PCCTscale[2]; + aScale = ctx->Pixel.PCCTscale[3]; + rBias = ctx->Pixel.PCCTbias[0]; + gBias = ctx->Pixel.PCCTbias[1]; + bBias = ctx->Pixel.PCCTbias[2]; + aBias = ctx->Pixel.PCCTbias[3]; break; case GL_POST_COLOR_MATRIX_COLOR_TABLE: table = &ctx->PostColorMatrixColorTable; + rScale = ctx->Pixel.PCMCTscale[0]; + gScale = ctx->Pixel.PCMCTscale[1]; + bScale = ctx->Pixel.PCMCTscale[2]; + aScale = ctx->Pixel.PCMCTscale[3]; + rBias = ctx->Pixel.PCMCTbias[0]; + gBias = ctx->Pixel.PCMCTbias[1]; + bBias = ctx->Pixel.PCMCTbias[2]; + aBias = ctx->Pixel.PCMCTbias[3]; break; default: gl_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); @@ -476,7 +509,8 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, assert(table); - if (!_mesa_is_legal_format_and_type(format, type)) { + if (!_mesa_is_legal_format_and_type(format, type) || + format == GL_INTENSITY) { gl_error(ctx, GL_INVALID_ENUM, "glColorSubTable(format or type)"); return; } @@ -505,11 +539,66 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, format, type, data, &ctx->Unpack, GL_TRUE); } else { - GLfloat *dest = (GLfloat *) table->Table + start * comps * sizeof(GLfloat); + GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; + GLfloat *tableF; + GLuint i; + ASSERT(table->TableType == GL_FLOAT); - _mesa_unpack_float_color_span(ctx, count, table->Format, dest, - format, type, data, &ctx->Unpack, - GL_FALSE, GL_TRUE); + + _mesa_unpack_float_color_span(ctx, count, table->Format, + tempTab, /* dest */ + format, type, data, + &ctx->Unpack, GL_TRUE, GL_FALSE); + + tableF = (GLfloat *) table->Table; + + switch (table->Format) { + case GL_INTENSITY: + for (i = 0; i < count; i++) { + GLuint j = start + i; + tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); + } + break; + case GL_LUMINANCE: + for (i = 0; i < count; i++) { + GLuint j = start + i; + tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); + } + break; + case GL_ALPHA: + for (i = 0; i < count; i++) { + GLuint j = start + i; + tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); + } + break; + case GL_LUMINANCE_ALPHA: + for (i = 0; i < count; i++) { + GLuint j = start + i; + tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); + tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); + } + break; + case GL_RGB: + for (i = 0; i < count; i++) { + GLuint j = start + i; + tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); + tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); + tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); + } + break; + case GL_RGBA: + for (i = 0; i < count; i++) { + GLuint j = start + i; + tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); + tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); + tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); + tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); + } + break; + default: + gl_problem(ctx, "Bad format in _mesa_ColorSubTable"); + return; + } } if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { @@ -725,10 +814,10 @@ _mesa_GetColorTable( GLenum target, GLenum format, if (table->TableType == GL_FLOAT) { const GLfloat *tableF = (const GLfloat *) table->Table; for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = (GLint) (tableF[i*4+0] * 255.0F); - rgba[i][GCOMP] = (GLint) (tableF[i*4+1] * 255.0F); - rgba[i][BCOMP] = (GLint) (tableF[i*4+2] * 255.0F); - rgba[i][ACOMP] = (GLint) (tableF[i*4+3] * 255.0F); + rgba[i][RCOMP] = (GLint) (tableF[i*4+0] * 255.0F + 0.5F); + rgba[i][GCOMP] = (GLint) (tableF[i*4+1] * 255.0F + 0.5F); + rgba[i][BCOMP] = (GLint) (tableF[i*4+2] * 255.0F + 0.5F); + rgba[i][ACOMP] = (GLint) (tableF[i*4+3] * 255.0F + 0.5F); } } else { diff --git a/xc/extras/Mesa/src/config.c b/xc/extras/Mesa/src/config.c index 8f8a79aae..7dc4d9613 100644 --- a/xc/extras/Mesa/src/config.c +++ b/xc/extras/Mesa/src/config.c @@ -447,8 +447,10 @@ void gl_read_config_file( GLcontext *ctx ) if (!run_init( ctx, default_config, list )) { - fprintf(stderr, "No default configuration '%s' in init file\n", - default_config); + if (getenv("MESA_DEBUG")) { + fprintf(stderr, "No default configuration '%s' in init file\n", + default_config); + } } free_list( list ); diff --git a/xc/extras/Mesa/src/config.h b/xc/extras/Mesa/src/config.h index 3ff5e5f78..07ff841f6 100644 --- a/xc/extras/Mesa/src/config.h +++ b/xc/extras/Mesa/src/config.h @@ -104,8 +104,8 @@ /* Number of texture units - GL_ARB_multitexture */ #define MAX_TEXTURE_UNITS 2 -/* Maximum viewport size: */ -#define MAX_WIDTH 1600 +/* Maximum viewport/image size: */ +#define MAX_WIDTH 2048 #define MAX_HEIGHT 1200 /* Maxmimum size for CVA. May be overridden by the drivers. */ diff --git a/xc/extras/Mesa/src/context.c b/xc/extras/Mesa/src/context.c index 0138ae6b3..5548e8c26 100644 --- a/xc/extras/Mesa/src/context.c +++ b/xc/extras/Mesa/src/context.c @@ -593,12 +593,34 @@ init_texture_unit( GLcontext *ctx, GLuint unit ) struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; texUnit->EnvMode = GL_MODULATE; + texUnit->CombineModeRGB = GL_MODULATE; + texUnit->CombineModeA = GL_MODULATE; + texUnit->CombineSourceRGB[0] = GL_TEXTURE; + texUnit->CombineSourceRGB[1] = GL_PREVIOUS_EXT; + texUnit->CombineSourceRGB[2] = GL_CONSTANT_EXT; + texUnit->CombineSourceA[0] = GL_TEXTURE; + texUnit->CombineSourceA[1] = GL_PREVIOUS_EXT; + texUnit->CombineSourceA[2] = GL_CONSTANT_EXT; + texUnit->CombineOperandRGB[0] = GL_SRC_COLOR; + texUnit->CombineOperandRGB[1] = GL_SRC_COLOR; + texUnit->CombineOperandRGB[2] = GL_SRC_ALPHA; + texUnit->CombineOperandA[0] = GL_SRC_ALPHA; + texUnit->CombineOperandA[1] = GL_SRC_ALPHA; + texUnit->CombineOperandA[2] = GL_SRC_ALPHA; + texUnit->CombineScaleShiftRGB = 0; + texUnit->CombineScaleShiftA = 0; + ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 ); texUnit->TexGenEnabled = 0; texUnit->GenModeS = GL_EYE_LINEAR; texUnit->GenModeT = GL_EYE_LINEAR; texUnit->GenModeR = GL_EYE_LINEAR; texUnit->GenModeQ = GL_EYE_LINEAR; + texUnit->GenBitS = TEXGEN_EYE_LINEAR; + texUnit->GenBitT = TEXGEN_EYE_LINEAR; + texUnit->GenBitR = TEXGEN_EYE_LINEAR; + texUnit->GenBitQ = TEXGEN_EYE_LINEAR; + /* Yes, these plane coefficients are correct! */ ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 ); ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 ); @@ -762,10 +784,11 @@ init_attrib_groups( GLcontext *ctx ) } /* Texture matrix */ - for (i=0; i<MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_UNITS; i++) { gl_matrix_ctr( &ctx->TextureMatrix[i] ); ctx->TextureStackDepth[i] = 0; for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) { + gl_matrix_ctr( &ctx->TextureStack[i][j] ); ctx->TextureStack[i][j].inv = 0; } } @@ -987,6 +1010,11 @@ init_attrib_groups( GLcontext *ctx ) ctx->ShineTable[i]->refcount++; } + gl_compute_shine_table( ctx, 0, ctx->Light.Material[0].Shininess ); + gl_compute_shine_table( ctx, 2, ctx->Light.Material[0].Shininess * .5 ); + gl_compute_shine_table( ctx, 1, ctx->Light.Material[1].Shininess ); + gl_compute_shine_table( ctx, 3, ctx->Light.Material[1].Shininess * .5 ); + /* Line group */ ctx->Line.SmoothFlag = GL_FALSE; @@ -1049,6 +1077,10 @@ init_attrib_groups( GLcontext *ctx ) ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0); ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0); ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0); + ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0); + ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0); + ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0); + ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0); ctx->Pixel.ColorTableEnabled = GL_FALSE; ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE; ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE; @@ -1066,6 +1098,7 @@ init_attrib_groups( GLcontext *ctx ) /* Point group */ ctx->Point.SmoothFlag = GL_FALSE; + ctx->Point.UserSize = 1.0; ctx->Point.Size = 1.0; ctx->Point.Params[0] = 1.0; ctx->Point.Params[1] = 0.0; @@ -1342,7 +1375,8 @@ alloc_proxy_textures( GLcontext *ctx ) /* - * Initialize a GLcontext struct. + * Initialize a GLcontext struct. This includes allocating all the + * other structs and arrays which hang off of the context by pointers. */ GLboolean _mesa_initialize_context( GLcontext *ctx, @@ -1365,15 +1399,13 @@ _mesa_initialize_context( GLcontext *ctx, ctx->VB = gl_vb_create_for_immediate( ctx ); if (!ctx->VB) { - FREE( ctx ); return GL_FALSE; } ctx->input = ctx->VB->IM; ctx->PB = gl_alloc_pb(); if (!ctx->PB) { - FREE( ctx->VB ); - FREE( ctx ); + ALIGN_FREE( ctx->VB ); return GL_FALSE; } @@ -1385,9 +1417,8 @@ _mesa_initialize_context( GLcontext *ctx, /* allocate new group of display lists */ ctx->Shared = alloc_shared_state(); if (!ctx->Shared) { - FREE(ctx->VB); - FREE(ctx->PB); - FREE(ctx); + ALIGN_FREE( ctx->VB ); + FREE( ctx->PB ); return GL_FALSE; } } @@ -1417,9 +1448,8 @@ _mesa_initialize_context( GLcontext *ctx, if (!alloc_proxy_textures(ctx)) { free_shared_state(ctx, ctx->Shared); - FREE(ctx->VB); - FREE(ctx->PB); - FREE(ctx); + ALIGN_FREE( ctx->VB ); + FREE( ctx->PB ); return GL_FALSE; } @@ -1446,11 +1476,10 @@ _mesa_initialize_context( GLcontext *ctx, ctx->Save = (struct _glapi_table *) CALLOC(dispatchSize * sizeof(void*)); if (!ctx->Exec || !ctx->Save) { free_shared_state(ctx, ctx->Shared); - FREE(ctx->VB); - FREE(ctx->PB); + ALIGN_FREE( ctx->VB ); + FREE( ctx->PB ); if (ctx->Exec) - FREE(ctx->Exec); - FREE(ctx); + FREE( ctx->Exec ); } _mesa_init_exec_table(ctx->Exec, dispatchSize); _mesa_init_dlist_table(ctx->Save, dispatchSize); @@ -1593,7 +1622,7 @@ gl_free_context_data( GLcontext *ctx ) /* Free cache of immediate buffers. */ while (ctx->nr_im_queued-- > 0) { struct immediate * next = ctx->freed_im_queue->next; - FREE( ctx->freed_im_queue ); + ALIGN_FREE( ctx->freed_im_queue ); ctx->freed_im_queue = next; } gl_extensions_dtr(ctx); @@ -1896,57 +1925,63 @@ void gl_compile_error( GLcontext *ctx, GLenum error, const char *s ) * of the current error value. If Mesa is compiled with -DDEBUG or if the * environment variable "MESA_DEBUG" is defined then a real error message * is printed to stderr. - * Input: error - the error value - * s - a diagnostic string + * Input: ctx - the GL context + * error - the error value + * where - usually the name of function where error was detected */ -void gl_error( GLcontext *ctx, GLenum error, const char *s ) +void +gl_error( GLcontext *ctx, GLenum error, const char *where ) { + const char *debugEnv = getenv("MESA_DEBUG"); GLboolean debug; #ifdef DEBUG - debug = GL_TRUE; + if (debugEnv && strstr(debugEnv, "silent")) + debug = GL_FALSE; + else + debug = GL_TRUE; #else - if (getenv("MESA_DEBUG")) { + if (debugEnv) debug = GL_TRUE; - } - else { + else debug = GL_FALSE; - } #endif if (debug) { - char errstr[1000]; - + const char *errstr; switch (error) { case GL_NO_ERROR: - strcpy( errstr, "GL_NO_ERROR" ); + errstr = "GL_NO_ERROR"; break; case GL_INVALID_VALUE: - strcpy( errstr, "GL_INVALID_VALUE" ); + errstr = "GL_INVALID_VALUE"; break; case GL_INVALID_ENUM: - strcpy( errstr, "GL_INVALID_ENUM" ); + errstr = "GL_INVALID_ENUM"; break; case GL_INVALID_OPERATION: - strcpy( errstr, "GL_INVALID_OPERATION" ); + errstr = "GL_INVALID_OPERATION"; break; case GL_STACK_OVERFLOW: - strcpy( errstr, "GL_STACK_OVERFLOW" ); + errstr = "GL_STACK_OVERFLOW"; break; case GL_STACK_UNDERFLOW: - strcpy( errstr, "GL_STACK_UNDERFLOW" ); + errstr = "GL_STACK_UNDERFLOW"; break; case GL_OUT_OF_MEMORY: - strcpy( errstr, "GL_OUT_OF_MEMORY" ); + errstr = "GL_OUT_OF_MEMORY"; break; + case GL_TABLE_TOO_LARGE: + errstr = "GL_TABLE_TOO_LARGE"; + break; default: - strcpy( errstr, "unknown" ); + errstr = "unknown"; break; } - fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s ); + fprintf(stderr, "Mesa user error: %s in %s\n", errstr, where); } - if (ctx->ErrorValue==GL_NO_ERROR) { + if (ctx->ErrorValue == GL_NO_ERROR) { ctx->ErrorValue = error; } diff --git a/xc/extras/Mesa/src/copypix.c b/xc/extras/Mesa/src/copypix.c index e76c170f6..6fbfbfee4 100644 --- a/xc/extras/Mesa/src/copypix.c +++ b/xc/extras/Mesa/src/copypix.c @@ -166,6 +166,7 @@ static void copy_rgba_pixels( GLcontext *ctx, ctx->Pixel.ScaleOrBiasRGBApcm || ctx->Pixel.ColorTableEnabled || ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.PostConvolutionColorTableEnabled || ctx->Pixel.MinMaxEnabled || ctx->Pixel.HistogramEnabled; @@ -224,6 +225,11 @@ static void copy_rgba_pixels( GLcontext *ctx, if (ctx->Pixel.ColorTableEnabled) { _mesa_lookup_rgba(&ctx->ColorTable, width, rgbaFloat); } + /* XXX convolution here */ + /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ + if (ctx->Pixel.PostConvolutionColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, width, rgbaFloat); + } /* color matrix */ if (ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm) { @@ -256,12 +262,17 @@ static void copy_rgba_pixels( GLcontext *ctx, if (ctx->Texture.ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH]; + GLubyte primary_rgba[MAX_WIDTH][4]; GLuint unit; /* XXX not sure how multitexture is supposed to work here */ + + MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLubyte)); + for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++) { _mesa_pixeltexgen(ctx, width, (const GLubyte (*)[4]) rgba, s, t, r, q); - gl_texture_pixels(ctx, unit, width, s, t, r, NULL, rgba); + gl_texture_pixels(ctx, unit, width, s, t, r, NULL, + primary_rgba, rgba); } } diff --git a/xc/extras/Mesa/src/dd.h b/xc/extras/Mesa/src/dd.h index ad389df4a..d2dfc9464 100644 --- a/xc/extras/Mesa/src/dd.h +++ b/xc/extras/Mesa/src/dd.h @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -641,17 +641,20 @@ struct dd_function_table { */ GLboolean (*CompressedTexImage1D)( GLcontext *ctx, GLenum target, - GLint level, const GLvoid *data, + GLint level, GLsizei imageSize, + const GLvoid *data, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLboolean *retainInternalCopy); GLboolean (*CompressedTexImage2D)( GLcontext *ctx, GLenum target, - GLint level, const GLvoid *data, + GLint level, GLsizei imageSize, + const GLvoid *data, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLboolean *retainInternalCopy); GLboolean (*CompressedTexImage3D)( GLcontext *ctx, GLenum target, - GLint level, const GLvoid *data, + GLint level, GLsizei imageSize, + const GLvoid *data, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLboolean *retainInternalCopy); @@ -699,6 +702,42 @@ struct dd_function_table { * should do the job. */ + GLint (*BaseCompressedTexFormat)(GLcontext *ctx, + GLint internalFormat); + /* Called to compute the base format for a specific compressed + * format. Return -1 if the internalFormat is not a specific + * compressed format that the driver recognizes. Note the + * return value differences between this function and + * SpecificCompressedTexFormat below. + */ + + GLint (*SpecificCompressedTexFormat)(GLcontext *ctx, + GLint internalFormat, + GLint numDimensions); + /* Called to turn a generic texture format into a specific + * texture format. For example, if a driver implements + * GL_3DFX_texture_compression_FXT1, this would map + * GL_COMPRESSED_RGBA_ARB to GL_COMPRESSED_RGBA_FXT1_3DFX. + * + * If the driver does not know how to handle the compressed + * format, then just return the generic format, and Mesa will + * do the right thing with it. + */ + + GLboolean (*IsCompressedFormat)(GLcontext *ctx, GLint internalFormat); + /* Called to tell if a format is a compressed format. + */ + + GLsizei (*CompressedImageSize)(GLcontext *ctx, + GLenum internalFormat, + GLuint numDimensions, + GLuint width, + GLuint height, + GLuint depth); + /* Calculate the size of a compressed image, given the image's + * format and dimensions. + */ + void (*GetCompressedTexImage)( GLcontext *ctx, GLenum target, GLint lod, void *image, const struct gl_texture_object *texObj, @@ -759,7 +798,7 @@ struct dd_function_table { /*** - *** Accelerated point, line, polygon, glDrawPixels and glBitmap functions: + *** Accelerated point, line, polygon, quad and rect functions: ***/ points_func PointsFunc; @@ -906,6 +945,16 @@ struct dd_function_table { void (*StencilMask)(GLcontext *ctx, GLuint mask); void (*StencilOp)(GLcontext *ctx, GLenum fail, GLenum zfail, GLenum zpass); void (*Viewport)(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h); + + /* State-query functions + * + * Return GL_TRUE if query was completed, GL_FALSE otherwise. + */ + GLboolean (*GetBooleanv)(GLcontext *ctx, GLenum pname, GLboolean *result); + GLboolean (*GetDoublev)(GLcontext *ctx, GLenum pname, GLdouble *result); + GLboolean (*GetFloatv)(GLcontext *ctx, GLenum pname, GLfloat *result); + GLboolean (*GetIntegerv)(GLcontext *ctx, GLenum pname, GLint *result); + GLboolean (*GetPointerv)(GLcontext *ctx, GLenum pname, GLvoid **result); }; diff --git a/xc/extras/Mesa/src/debug_xform.c b/xc/extras/Mesa/src/debug_xform.c index 28d1b9625..cd3442a58 100644 --- a/xc/extras/Mesa/src/debug_xform.c +++ b/xc/extras/Mesa/src/debug_xform.c @@ -30,6 +30,7 @@ #include "glheader.h" #include "context.h" #include "types.h" +#include "mem.h" #include "xform.h" #include "debug_xform.h" #endif @@ -234,7 +235,7 @@ static int test_transform_function( transform_func fn, int psize, int mtype, GLvector4f source[1], dest[1], ref[1]; GLmatrix mat[1]; GLfloat s[TEST_COUNT][5], d[TEST_COUNT][4], r[TEST_COUNT][4]; - GLfloat *m = mat->m; + GLfloat *m; GLubyte mask[TEST_COUNT]; int i, j; #ifdef RUN_XFORM_BENCHMARK @@ -248,8 +249,11 @@ static int test_transform_function( transform_func fn, int psize, int mtype, return 0; } + mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 ); mat->type = mtypes[mtype]; + m = mat->m; + m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0; m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] = 7.0; m[2] = 44.0; m[6] = 9.0; m[10] = 7.0; m[14] = 3.0; @@ -311,19 +315,19 @@ static int test_transform_function( transform_func fn, int psize, int mtype, if (mesa_profile) { if (masked) { BEGIN_RACE (*cycles); - fn(dest, mat, source, mask, 1); + fn(dest, mat->m, source, mask, 1); END_RACE (*cycles); } else { BEGIN_RACE (*cycles); - fn(dest, mat, source, NULL, 0); + fn(dest, mat->m, source, NULL, 0); END_RACE (*cycles); } } else { if (masked) { - fn(dest, mat, source, mask, 1); + fn(dest, mat->m, source, mask, 1); } else { - fn(dest, mat, source, NULL, 0); + fn(dest, mat->m, source, NULL, 0); } } @@ -351,6 +355,8 @@ static int test_transform_function( transform_func fn, int psize, int mtype, } } } + + ALIGN_FREE( mat->m ); return 1; } @@ -583,7 +589,7 @@ static int test_norm_function( normal_func fn, int mtype, GLfloat s [TEST_COUNT][5], d [TEST_COUNT][3], r [TEST_COUNT][3]; GLfloat d2 [TEST_COUNT][3], r2 [TEST_COUNT][3], length [TEST_COUNT]; GLfloat scale; - GLfloat *m = mat->m; + GLfloat *m; GLubyte mask[TEST_COUNT]; int i, j; #ifdef RUN_XFORM_BENCHMARK @@ -592,7 +598,8 @@ static int test_norm_function( normal_func fn, int mtype, (void) cycles; - mat->inv = mat->m; + mat->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 ); + mat->inv = m = mat->m; m[0] = 63.0; m[4] = 43.0; m[ 8] = 29.0; m[12] = 43.0; m[1] = 55.0; m[5] = 17.0; m[ 9] = 31.0; m[13] = 7.0; @@ -728,6 +735,8 @@ static int test_norm_function( normal_func fn, int mtype, } } } + + ALIGN_FREE( mat->m ); return 1; } diff --git a/xc/extras/Mesa/src/dlist.c b/xc/extras/Mesa/src/dlist.c index e56593887..ff23ee951 100644 --- a/xc/extras/Mesa/src/dlist.c +++ b/xc/extras/Mesa/src/dlist.c @@ -4055,7 +4055,7 @@ static void execute_list( GLcontext *ctx, GLuint list ) break; case OPCODE_VERTEX_CASSETTE: { struct immediate *IM; - + if (ctx->NewState) gl_update_state(ctx); if (ctx->CompileCVAFlag) { @@ -4515,6 +4515,7 @@ static void execute_list( GLcontext *ctx, GLuint list ) break; case OPCODE_RECTF: (*ctx->Exec->Rectf)( n[1].f, n[2].f, n[3].f, n[4].f ); + FLUSH_VB( ctx, "dlist rectf" ); break; case OPCODE_RESET_HISTOGRAM: (*ctx->Exec->ResetHistogram)( n[1].e ); @@ -4968,8 +4969,6 @@ _mesa_CallLists( GLsizei n, GLenum type, const GLvoid *lists ) ctx->CurrentDispatch = ctx->Save; _glapi_set_dispatch( ctx->CurrentDispatch ); } - -/* RESET_IMMEDIATE( ctx ); */ } diff --git a/xc/extras/Mesa/src/drawpix.c b/xc/extras/Mesa/src/drawpix.c index 7fb93abcc..dad8ada33 100644 --- a/xc/extras/Mesa/src/drawpix.c +++ b/xc/extras/Mesa/src/drawpix.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -121,6 +121,7 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, && ctx->ColorMatrix.type == MATRIX_IDENTITY && !ctx->Pixel.ColorTableEnabled && !ctx->Pixel.PostColorMatrixColorTableEnabled + && !ctx->Pixel.PostConvolutionColorTableEnabled && !ctx->Pixel.MinMaxEnabled && !ctx->Pixel.HistogramEnabled && ctx->Pixel.IndexShift==0 && ctx->Pixel.IndexOffset==0 @@ -138,7 +139,7 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, GLint skipRows = unpack->SkipRows; GLint rowLength; GLdepth zSpan[MAX_WIDTH]; /* only used when zooming */ - GLint zoomY0; + GLint zoomY0 = 0; if (unpack->RowLength > 0) rowLength = unpack->RowLength; @@ -171,14 +172,36 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, drawHeight -= (destY + drawHeight - ctx->DrawBuffer->Ymax - 1); if (drawHeight <= 0) return GL_TRUE; + } + else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { + /* upside-down image */ + /* horizontal clipping */ + if (destX < ctx->DrawBuffer->Xmin) { + skipPixels += (ctx->DrawBuffer->Xmin - destX); + drawWidth -= (ctx->DrawBuffer->Xmin - destX); + destX = ctx->DrawBuffer->Xmin; + } + if (destX + drawWidth > ctx->DrawBuffer->Xmax) + drawWidth -= (destX + drawWidth - ctx->DrawBuffer->Xmax - 1); + if (drawWidth <= 0) + return GL_TRUE; - zoomY0 = 0; /* not used - silence compiler warning */ + /* vertical clipping */ + if (destY > ctx->DrawBuffer->Ymax) { + skipRows += (destY - ctx->DrawBuffer->Ymax - 1); + drawHeight -= (destY - ctx->DrawBuffer->Ymax - 1); + destY = ctx->DrawBuffer->Ymax + 1; + } + if (destY - drawHeight < ctx->DrawBuffer->Ymin) + drawHeight -= (ctx->DrawBuffer->Ymin - (destY - drawHeight)); + if (drawHeight <= 0) + return GL_TRUE; } else { /* setup array of fragment Z value to pass to zoom function */ GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF); GLint i; - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); for (i=0; i<drawWidth; i++) zSpan[i] = z; @@ -209,6 +232,16 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, destY++; } } + else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { + /* upside-down */ + GLint row; + for (row=0; row<drawHeight; row++) { + destY--; + (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY, + (void *) src, NULL); + src += rowLength * 4; + } + } else { /* with zooming */ GLint row; @@ -235,6 +268,16 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, destY++; } } + else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { + /* upside-down */ + GLint row; + for (row=0; row<drawHeight; row++) { + destY--; + (*ctx->Driver.WriteRGBSpan)(ctx, drawWidth, destX, destY, + (void *) src, NULL); + src += rowLength * 3; + } + } else { /* with zooming */ GLint row; @@ -255,7 +298,7 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; for (i=0;i<drawWidth;i++) { @@ -269,10 +312,27 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, destY++; } } + else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { + /* upside-down */ + GLint row; + ASSERT(drawWidth < MAX_WIDTH); + for (row=0; row<drawHeight; row++) { + GLint i; + for (i=0;i<drawWidth;i++) { + rgb[i][0] = src[i]; + rgb[i][1] = src[i]; + rgb[i][2] = src[i]; + } + destY--; + (*ctx->Driver.WriteRGBSpan)(ctx, drawWidth, destX, destY, + (void *) rgb, NULL); + src += rowLength; + } + } else { /* with zooming */ GLint row; - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; for (i=0;i<drawWidth;i++) { @@ -296,7 +356,7 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==1.0F) { /* no zooming */ GLint row; - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLint i; GLubyte *ptr = src; @@ -312,10 +372,29 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, destY++; } } + else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { + /* upside-down */ + GLint row; + ASSERT(drawWidth < MAX_WIDTH); + for (row=0; row<drawHeight; row++) { + GLint i; + GLubyte *ptr = src; + for (i=0;i<drawWidth;i++) { + rgba[i][0] = *ptr; + rgba[i][1] = *ptr; + rgba[i][2] = *ptr++; + rgba[i][3] = *ptr++; + } + destY--; + (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY, + (void *) rgba, NULL); + src += rowLength*2; + } + } else { /* with zooming */ GLint row; - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); for (row=0; row<drawHeight; row++) { GLubyte *ptr = src; GLint i; @@ -342,7 +421,7 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, /* no zooming */ GLint row; for (row=0; row<drawHeight; row++) { - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); _mesa_map_ci8_to_rgba(ctx, drawWidth, src, rgba); (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY, (const GLubyte (*)[4])rgba, @@ -352,11 +431,25 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, } return GL_TRUE; } + else if (ctx->Pixel.ZoomX==1.0F && ctx->Pixel.ZoomY==-1.0F) { + /* upside-down */ + GLint row; + for (row=0; row<drawHeight; row++) { + ASSERT(drawWidth < MAX_WIDTH); + _mesa_map_ci8_to_rgba(ctx, drawWidth, src, rgba); + destY--; + (*ctx->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY, + (const GLubyte (*)[4])rgba, + NULL); + src += rowLength; + } + return GL_TRUE; + } else { /* with zooming */ GLint row; for (row=0; row<drawHeight; row++) { - assert(drawWidth < MAX_WIDTH); + ASSERT(drawWidth < MAX_WIDTH); _mesa_map_ci8_to_rgba(ctx, drawWidth, src, rgba); gl_write_zoomed_rgba_span(ctx, drawWidth, destX, destY, zSpan, (void *) rgba, zoomY0); @@ -511,11 +604,11 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, GLuint ispan[MAX_WIDTH]; GLint drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; - if (type != GL_UNSIGNED_BYTE + if (type != GL_BYTE && type != GL_UNSIGNED_BYTE + && type != GL_SHORT && type != GL_UNSIGNED_SHORT - && type != GL_UNSIGNED_SHORT - && type != GL_UNSIGNED_INT + && type != GL_INT && type != GL_UNSIGNED_INT && type != GL_FLOAT) { gl_error(ctx, GL_INVALID_ENUM, "glDrawPixels(type)"); @@ -652,17 +745,23 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, pixels, width, height, format, type, 0, row, 0); _mesa_unpack_ubyte_color_span(ctx, width, GL_RGBA, (void*) rgba, format, type, source, unpack, GL_TRUE); - if (ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink) + if ((ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink) || + (ctx->Pixel.HistogramEnabled && ctx->Histogram.Sink)) continue; if (ctx->Texture.ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH]; + GLubyte primary_rgba[MAX_WIDTH][4]; GLuint unit; /* XXX not sure how multitexture is supposed to work here */ + + MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLubyte)); + for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++) { _mesa_pixeltexgen(ctx, width, (const GLubyte (*)[4]) rgba, s, t, r, q); - gl_texture_pixels(ctx, unit, width, s, t, r, NULL, rgba); + gl_texture_pixels(ctx, unit, width, s, t, r, NULL, + primary_rgba, rgba); } } diff --git a/xc/extras/Mesa/src/enums.c b/xc/extras/Mesa/src/enums.c index a9daa3569..f28c61a03 100644 --- a/xc/extras/Mesa/src/enums.c +++ b/xc/extras/Mesa/src/enums.c @@ -804,7 +804,30 @@ enum_elt all_enums[] = { "GL_ARRAY_ELEMENT_LOCK_COUNT_EXT", 0x81A9}, /* GL_EXT_clip_volume_hint */ - { "GL_CLIP_VOLUME_CLIPPING_HINT_EXT", 0x80F0} + { "GL_CLIP_VOLUME_CLIPPING_HINT_EXT", 0x80F0}, + + /* GL_EXT_texture_env_combine */ + { "GL_COMBINE_EXT", 0x8570 }, + { "GL_COMBINE_RGB_EXT", 0x8571 }, + { "GL_COMBINE_ALPHA_EXT", 0x8572 }, + { "GL_SOURCE0_RGB_EXT", 0x8580 }, + { "GL_SOURCE1_RGB_EXT", 0x8581 }, + { "GL_SOURCE2_RGB_EXT", 0x8582 }, + { "GL_SOURCE0_ALPHA_EXT", 0x8588 }, + { "GL_SOURCE1_ALPHA_EXT", 0x8589 }, + { "GL_SOURCE2_ALPHA_EXT", 0x858A }, + { "GL_OPERAND0_RGB_EXT", 0x8590 }, + { "GL_OPERAND1_RGB_EXT", 0x8591 }, + { "GL_OPERAND2_RGB_EXT", 0x8592 }, + { "GL_OPERAND0_ALPHA_EXT", 0x8598 }, + { "GL_OPERAND1_ALPHA_EXT", 0x8599 }, + { "GL_OPERAND2_ALPHA_EXT", 0x859A }, + { "GL_RGB_SCALE_EXT", 0x8573 }, + { "GL_ADD_SIGNED_EXT", 0x8574 }, + { "GL_INTERPOLATE_EXT", 0x8575 }, + { "GL_CONSTANT_EXT", 0x8576 }, + { "GL_PRIMARY_COLOR_EXT", 0x8577 }, + { "GL_PREVIOUS_EXT", 0x8578 } }; diff --git a/xc/extras/Mesa/src/eval.c b/xc/extras/Mesa/src/eval.c index 2b9d8e8e9..a88c6dc85 100644 --- a/xc/extras/Mesa/src/eval.c +++ b/xc/extras/Mesa/src/eval.c @@ -2452,7 +2452,7 @@ void gl_eval_vb( struct vertex_buffer *VB ) if (ctx->Eval.Map1Color4 && any_eval1) VB->ColorPtr = eval1_color( out_color, coord, flags, IM->Start, - &ctx->EvalMap.Map1Color4 ); + &ctx->EvalMap.Map1Color4 ); if (ctx->Eval.Map2Color4 && any_eval2) VB->ColorPtr = eval2_color( out_color, coord, flags, IM->Start, @@ -2481,8 +2481,9 @@ void gl_eval_vb( struct vertex_buffer *VB ) VB->NormalPtr = eval2_norm( out_normal, coord, flags, IM->Start, &ctx->EvalMap.Map2Normal ); + new_flags |= VERT_NORM; + if (VB->NormalPtr != in_normal) { - new_flags |= VERT_NORM; if (!all_eval) VB->NormalPtr = copy_3f( out_normal, in_normal, flags, IM->Start ); } @@ -2550,26 +2551,42 @@ void gl_eval_vb( struct vertex_buffer *VB ) } if (any_eval2) { + GLvector3f *in_normal = VB->NormalPtr; + GLvector3f *out_normal = &IM->v.Normal; + if (ctx->Eval.Map2Vertex4) { - if (ctx->Eval.AutoNormal && (req & VERT_NORM)) - obj = eval2_obj_norm( out, VB->NormalPtr, coord, flags, IM->Start, - 4, &ctx->EvalMap.Map2Vertex4 ); + if (ctx->Eval.AutoNormal && (req & VERT_NORM)) { + obj = eval2_obj_norm( out, out_normal, coord, flags, + IM->Start, 4, &ctx->EvalMap.Map2Vertex4 ); + VB->NormalPtr = out_normal; + new_flags |= VERT_NORM; + } else obj = eval2_4f( out, coord, flags, IM->Start, - 4, &ctx->EvalMap.Map2Vertex4); + 4, &ctx->EvalMap.Map2Vertex4 ); } else if (ctx->Eval.Map2Vertex3) { - if (ctx->Eval.AutoNormal && (req & VERT_NORM)) - obj = eval2_obj_norm( out, VB->NormalPtr, coord, flags, IM->Start, - 3, &ctx->EvalMap.Map2Vertex3 ); + if (ctx->Eval.AutoNormal && (req & VERT_NORM)) { + obj = eval2_obj_norm( out, out_normal, coord, flags, + IM->Start, 3, &ctx->EvalMap.Map2Vertex3 ); + VB->NormalPtr = out_normal; + new_flags |= VERT_NORM; + } else obj = eval2_4f( out, coord, flags, IM->Start, 3, &ctx->EvalMap.Map2Vertex3 ); } - } + + if (VB->NormalPtr != in_normal) { + if (!all_eval) + VB->NormalPtr = copy_3f( out_normal, in_normal, flags, + IM->Start ); + } + } + if (obj != in && !all_eval) obj = copy_4f( out, in, flags, IM->Start ); @@ -2581,6 +2598,7 @@ void gl_eval_vb( struct vertex_buffer *VB ) GLuint *flags = VB->Flag = VB->EvaluatedFlags; GLuint i; GLuint count = VB->Count; + GLuint andflag = VB->IM->AndFlag; if (!flags) { VB->EvaluatedFlags = (GLuint *) MALLOC(VB->Size * sizeof(GLuint)); @@ -2588,16 +2606,21 @@ void gl_eval_vb( struct vertex_buffer *VB ) } if (all_eval) { - for (i = 0 ; i < count ; i++) + for (i = 0 ; i <= count ; i++) flags[i] = oldflags[i] | new_flags; + andflag |= new_flags; } else { - GLuint andflag = ~0; - for (i = 0 ; i < count ; i++) { - if (oldflags[i] & VERT_EVAL_ANY) - flags[i] = oldflags[i] | new_flags; + andflag = ~0; + for (i = 0 ; i <= count ; i++) { + flags[i] = oldflags[i]; + if (flags[i] & VERT_EVAL_ANY) + flags[i] |= new_flags; andflag &= flags[i]; } } + + VB->OrFlag |= new_flags; + VB->CullMode = (GLubyte) ((andflag & VERT_NORM) ? 0 : COMPACTED_NORMALS); } } diff --git a/xc/extras/Mesa/src/extensions.c b/xc/extras/Mesa/src/extensions.c index d242b2a7d..f3e771c98 100644 --- a/xc/extras/Mesa/src/extensions.c +++ b/xc/extras/Mesa/src/extensions.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -50,7 +50,7 @@ struct extension { static struct { int enabled; const char *name; } default_extensions[] = { { DEFAULT_OFF, "GL_ARB_imaging" }, /* in progress */ { DEFAULT_ON, "GL_ARB_multitexture" }, - { DEFAULT_OFF, "GL_ARB_texture_compression" }, /* in progress */ + { DEFAULT_OFF, "GL_ARB_texture_compression" }, { DEFAULT_OFF, "GL_ARB_texture_cube_map" }, /* in progress */ { ALWAYS_ENABLED, "GL_ARB_tranpose_matrix" }, { ALWAYS_ENABLED, "GL_EXT_abgr" }, @@ -74,6 +74,7 @@ static struct { int enabled; const char *name; } default_extensions[] = { { DEFAULT_OFF, "GL_EXT_texture_compression_s3tc" }, { DEFAULT_OFF, "GL_EXT_texture_env" }, { DEFAULT_ON, "GL_EXT_texture_env_add" }, + { DEFAULT_OFF, "GL_EXT_texture_env_combine" }, { ALWAYS_ENABLED, "GL_EXT_texture_object" }, { DEFAULT_ON, "GL_EXT_texture_lod_bias" }, { ALWAYS_ENABLED, "GL_EXT_vertex_array" }, @@ -102,6 +103,7 @@ update_extension_flags( GLcontext *ctx ) { /* Update flags */ ctx->Extensions.HaveTextureEnvAdd = gl_extension_is_enabled(ctx, "GL_EXT_texture_env_add"); + ctx->Extensions.HaveTextureEnvCombine = gl_extension_is_enabled(ctx, "GL_EXT_texture_env_combine"); ctx->Extensions.HaveTextureLodBias = gl_extension_is_enabled(ctx, "GL_EXT_texture_lod_bias"); ctx->Extensions.HaveHpOcclusionTest = gl_extension_is_enabled(ctx, "GL_HP_occlusion_test"); ctx->Extensions.HaveTextureCubeMap = gl_extension_is_enabled(ctx, "GL_ARB_texture_cube_map"); diff --git a/xc/extras/Mesa/src/fog.c b/xc/extras/Mesa/src/fog.c index d21711805..1a7ca2546 100644 --- a/xc/extras/Mesa/src/fog.c +++ b/xc/extras/Mesa/src/fog.c @@ -426,4 +426,3 @@ _mesa_fog_ci_pixels( const GLcontext *ctx, return; } } - diff --git a/xc/extras/Mesa/src/get.c b/xc/extras/Mesa/src/get.c index 21b5b639a..59e86056a 100644 --- a/xc/extras/Mesa/src/get.c +++ b/xc/extras/Mesa/src/get.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -91,9 +91,16 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetBooleanv"); + if (!params) + return; + if (MESA_VERBOSE & VERBOSE_API) fprintf(stderr, "glGetBooleanv %s\n", gl_lookup_enum_by_nr(pname)); + if (ctx->Driver.GetBooleanv + && (*ctx->Driver.GetBooleanv)(ctx, pname, params)) + return; + switch (pname) { case GL_ACCUM_RED_BITS: *params = INT_TO_BOOL(ctx->Visual->AccumRedBits); @@ -1234,9 +1241,15 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetDoublev"); + if (!params) + return; + if (MESA_VERBOSE & VERBOSE_API) fprintf(stderr, "glGetDoublev %s\n", gl_lookup_enum_by_nr(pname)); + if (ctx->Driver.GetDoublev && (*ctx->Driver.GetDoublev)(ctx, pname, params)) + return; + switch (pname) { case GL_ACCUM_RED_BITS: *params = (GLdouble) ctx->Visual->AccumRedBits; @@ -2377,9 +2390,15 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetFloatv"); + if (!params) + return; + if (MESA_VERBOSE & VERBOSE_API) fprintf(stderr, "glGetFloatv %s\n", gl_lookup_enum_by_nr(pname)); + if (ctx->Driver.GetFloatv && (*ctx->Driver.GetFloatv)(ctx, pname, params)) + return; + switch (pname) { case GL_ACCUM_RED_BITS: *params = (GLfloat) ctx->Visual->AccumRedBits; @@ -3491,9 +3510,16 @@ _mesa_GetIntegerv( GLenum pname, GLint *params ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetIntegerv"); + if (!params) + return; + if (MESA_VERBOSE & VERBOSE_API) fprintf(stderr, "glGetIntegerv %s\n", gl_lookup_enum_by_nr(pname)); + if (ctx->Driver.GetIntegerv + && (*ctx->Driver.GetIntegerv)(ctx, pname, params)) + return; + switch (pname) { case GL_ACCUM_RED_BITS: *params = (GLint) ctx->Visual->AccumRedBits; @@ -4628,11 +4654,19 @@ _mesa_GetPointerv( GLenum pname, GLvoid **params ) { GET_CURRENT_CONTEXT(ctx); GLuint texUnit = ctx->Texture.CurrentUnit; - /*GLuint texTransformUnit = ctx->Texture.CurrentTransformUnit;*/ + + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetPointerv"); + + if (!params) + return; if (MESA_VERBOSE & VERBOSE_API) fprintf(stderr, "glGetPointerv %s\n", gl_lookup_enum_by_nr(pname)); + if (ctx->Driver.GetPointerv + && (*ctx->Driver.GetPointerv)(ctx, pname, params)) + return; + switch (pname) { case GL_VERTEX_ARRAY_POINTER: *params = ctx->Array.Vertex.Ptr; @@ -4670,9 +4704,9 @@ const GLubyte * _mesa_GetString( GLenum name ) { GET_CURRENT_CONTEXT(ctx); - static char *vendor = "Brian Paul"; - static char *renderer = "Mesa"; - static char *version = "1.2 Mesa 3.3 beta"; + static const char *vendor = "Brian Paul"; + static const char *renderer = "Mesa"; + static const char *version = "1.2 Mesa 3.4"; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glGetString", 0); diff --git a/xc/extras/Mesa/src/glapinoop.c b/xc/extras/Mesa/src/glapinoop.c index 94d4a11f1..a48509d6b 100644 --- a/xc/extras/Mesa/src/glapinoop.c +++ b/xc/extras/Mesa/src/glapinoop.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -690,7 +690,16 @@ void *__glapi_noop_table[] = { (void *) NoOpGetColorTableEXT, (void *) NoOpGetColorTableParameterivEXT, (void *) NoOpGetColorTableParameterfvEXT, - + /* GL_3DFX_tbuffer */ + (void *) NoOpTbufferMask3DFX, + /* GL_ARB_texture_compression */ + (void *) NoOpCompressedTexImage3DARB, + (void *) NoOpCompressedTexImage2DARB, + (void *) NoOpCompressedTexImage1DARB, + (void *) NoOpCompressedTexSubImage3DARB, + (void *) NoOpCompressedTexSubImage2DARB, + (void *) NoOpCompressedTexSubImage1DARB, + (void *) NoOpGetCompressedTexImageARB, /* A whole bunch of no-op functions. These might be called * when someone tries to call a dynamically-registered extension * function without a current rendering context. diff --git a/xc/extras/Mesa/src/glheader.h b/xc/extras/Mesa/src/glheader.h index 8276f518a..5094ce2ed 100644 --- a/xc/extras/Mesa/src/glheader.h +++ b/xc/extras/Mesa/src/glheader.h @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -139,7 +139,12 @@ typedef void *HDC; typedef unsigned long COLORREF; #endif -#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) && !defined(__CYGWIN__) + +/* Make sure we include glext.h from gl.h */ +#define GL_GLEXT_PROTOTYPES + + +#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) # define WGL_FONT_LINES 0 # define WGL_FONT_POLYGONS 1 #ifndef _GNU_H_WINDOWS32_FUNCTIONS @@ -160,8 +165,6 @@ typedef struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESC -/* Make sure we include glext.h */ -#define GL_GLEXT_PROTOTYPES #include "GL/gl.h" #include "GL/glext.h" diff --git a/xc/extras/Mesa/src/image.c b/xc/extras/Mesa/src/image.c index 825ce7ed5..11703a5d0 100644 --- a/xc/extras/Mesa/src/image.c +++ b/xc/extras/Mesa/src/image.c @@ -329,6 +329,7 @@ _mesa_is_legal_format_and_type( GLenum format, GLenum type ) case GL_GREEN: case GL_BLUE: case GL_ALPHA: + case GL_INTENSITY: case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_DEPTH_COMPONENT: @@ -617,6 +618,7 @@ _mesa_pack_rgba_span( GLcontext *ctx, ctx->Pixel.ScaleOrBiasRGBApcm || ctx->Pixel.ColorTableEnabled || ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.PostConvolutionColorTableEnabled || ctx->Pixel.MinMaxEnabled || ctx->Pixel.HistogramEnabled); @@ -673,8 +675,11 @@ _mesa_pack_rgba_span( GLcontext *ctx, _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); } /* XXX convolution here */ - /* XXX post-convolution color table look-up here */ - /* color matrix */ + /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ + if (ctx->Pixel.PostConvolutionColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, n, rgba); + } + /* color matrix transform */ if (ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm) { _mesa_transform_rgba(ctx, n, rgba); @@ -2200,6 +2205,7 @@ _mesa_unpack_ubyte_color_span( GLcontext *ctx, ctx->Pixel.ScaleOrBiasRGBApcm || ctx->Pixel.ColorTableEnabled || ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.PostConvolutionColorTableEnabled || ctx->Pixel.MinMaxEnabled || ctx->Pixel.HistogramEnabled); @@ -2317,7 +2323,10 @@ _mesa_unpack_ubyte_color_span( GLcontext *ctx, _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); } /* XXX convolution here */ - /* XXX post-convolution color table look-up here */ + /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ + if (ctx->Pixel.PostConvolutionColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, n, rgba); + } /* color matrix transform */ if (ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm) { @@ -2515,6 +2524,7 @@ _mesa_unpack_float_color_span( GLcontext *ctx, ctx->Pixel.ScaleOrBiasRGBApcm || ctx->Pixel.ColorTableEnabled || ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.PostConvolutionColorTableEnabled || ctx->Pixel.MinMaxEnabled || ctx->Pixel.HistogramEnabled); @@ -2582,7 +2592,10 @@ _mesa_unpack_float_color_span( GLcontext *ctx, _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); } /* XXX convolution here */ - /* XXX post-convolution color table look-up here */ + /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ + if (ctx->Pixel.PostConvolutionColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, n, rgba); + } /* color matrix transform */ if (ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm) { @@ -2994,6 +3007,7 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, GLdepth *dest, break; default: gl_problem(NULL, "bad type in _mesa_unpack_depth_span()"); + FREE(depth); return; } diff --git a/xc/extras/Mesa/src/imaging.c b/xc/extras/Mesa/src/imaging.c index 1dd37112d..ebc1b7487 100644 --- a/xc/extras/Mesa/src/imaging.c +++ b/xc/extras/Mesa/src/imaging.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -938,6 +938,7 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX || format == GL_DEPTH_COMPONENT || + format == GL_INTENSITY || type == GL_BITMAP) { gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter1D(format or type)"); return; @@ -1007,6 +1008,7 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX || format == GL_DEPTH_COMPONENT || + format == GL_INTENSITY || type == GL_BITMAP) { gl_error(ctx, GL_INVALID_ENUM, "glConvolutionFilter2D(format or type)"); return; @@ -1353,6 +1355,7 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type, GLvoid *im format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX || format == GL_DEPTH_COMPONENT || + format == GL_INTENSITY || type == GL_BITMAP) { gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(format or type)"); return; @@ -1460,7 +1463,7 @@ _mesa_GetConvolutionParameteriv(GLenum target, GLenum pname, GLint *params) params[3] = FLOAT_TO_INT(ctx->Pixel.ConvolutionBorderColor[c][3]); break; case GL_CONVOLUTION_BORDER_MODE: - *params = (GLint) ctx->Pixel.ConvolutionBorderMode; + *params = (GLint) ctx->Pixel.ConvolutionBorderMode[c]; break; case GL_CONVOLUTION_FILTER_SCALE: params[0] = (GLint) ctx->Pixel.ConvolutionFilterScale[c][0]; @@ -1511,6 +1514,7 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type, GLvoid *row, format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX || format == GL_DEPTH_COMPONENT || + format == GL_INTENSITY || type == GL_BITMAP) { gl_error(ctx, GL_INVALID_ENUM, "glGetConvolutionFilter(format or type)"); return; @@ -1554,6 +1558,7 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLs format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX || format == GL_DEPTH_COMPONENT || + format == GL_INTENSITY || type == GL_BITMAP) { gl_error(ctx, GL_INVALID_ENUM, "glSeparableFilter2D(format or type)"); return; diff --git a/xc/extras/Mesa/src/light.c b/xc/extras/Mesa/src/light.c index ed41e2311..138aefb08 100644 --- a/xc/extras/Mesa/src/light.c +++ b/xc/extras/Mesa/src/light.c @@ -512,9 +512,6 @@ GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname, - - - /* * Check if the global material has to be updated with info that was * associated with a vertex via glMaterial. @@ -522,6 +519,8 @@ GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname, * glBegin/glEnd either by calling glMaterial() or by calling glColor() * when GL_COLOR_MATERIAL is enabled. * + * src[0] is front material, src[1] is back material + * * KW: Added code here to keep the precomputed variables uptodate. * This means we can use the faster shade functions when using * GL_COLOR_MATERIAL, and we can also now use the precomputed @@ -529,41 +528,62 @@ GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname, * the cost of doing this here. */ void gl_update_material( GLcontext *ctx, - struct gl_material *src, + const struct gl_material src[2], GLuint bitmask ) { struct gl_light *light, *list = &ctx->Light.EnabledList; - GLfloat tmp[4]; if (ctx->Light.ColorMaterialEnabled) bitmask &= ~ctx->Light.ColorMaterialBitmask; if (MESA_VERBOSE&VERBOSE_IMMEDIATE) - fprintf(stderr, "gl_update_material, mask %x\n", bitmask); + fprintf(stderr, "gl_update_material, mask 0x%x\n", bitmask); if (!bitmask) return; + /* update material emission */ + if (bitmask & FRONT_EMISSION_BIT) { + struct gl_material *mat = &ctx->Light.Material[0]; + COPY_4FV( mat->Emission, src[0].Emission ); + } + if (bitmask & BACK_EMISSION_BIT) { + struct gl_material *mat = &ctx->Light.Material[1]; + COPY_4FV( mat->Emission, src[1].Emission ); + } + + /* update material ambience */ if (bitmask & FRONT_AMBIENT_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; - SUB_3V( tmp, src[0].Ambient, mat->Ambient ); - ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp); + COPY_4FV( mat->Ambient, src[0].Ambient ); foreach (light, list) { - ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); + SCALE_3V( light->MatAmbient[0], light->Ambient, src[0].Ambient); } - COPY_4FV( mat->Ambient, src[0].Ambient ); } if (bitmask & BACK_AMBIENT_BIT) { struct gl_material *mat = &ctx->Light.Material[1]; - SUB_3V( tmp, src[1].Ambient, mat->Ambient ); - ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp); + COPY_4FV( mat->Ambient, src[1].Ambient ); foreach (light, list) { - ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); + SCALE_3V( light->MatAmbient[1], light->Ambient, src[1].Ambient); } - COPY_4FV( mat->Ambient, src[1].Ambient ); } + + /* update BaseColor = emission + scene's ambience * material's ambience */ + if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) { + struct gl_material *mat = &ctx->Light.Material[0]; + COPY_3V( ctx->Light.BaseColor[0], mat->Emission ); + ACC_SCALE_3V( ctx->Light.BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient ); + } + if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) { + struct gl_material *mat = &ctx->Light.Material[1]; + COPY_3V( ctx->Light.BaseColor[1], mat->Emission ); + ACC_SCALE_3V( ctx->Light.BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient ); + } + + /* update material diffuse values */ if (bitmask & FRONT_DIFFUSE_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; + GLfloat tmp[4]; SUB_3V( tmp, src[0].Diffuse, mat->Diffuse ); foreach (light, list) { ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp ); @@ -573,6 +593,7 @@ void gl_update_material( GLcontext *ctx, } if (bitmask & BACK_DIFFUSE_BIT) { struct gl_material *mat = &ctx->Light.Material[1]; + GLfloat tmp[4]; SUB_3V( tmp, src[1].Diffuse, mat->Diffuse ); foreach (light, list) { ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp ); @@ -580,8 +601,11 @@ void gl_update_material( GLcontext *ctx, COPY_4FV( mat->Diffuse, src[1].Diffuse ); FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[1], mat->Diffuse[3]); } + + /* update material specular values */ if (bitmask & FRONT_SPECULAR_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; + GLfloat tmp[4]; SUB_3V( tmp, src[0].Specular, mat->Specular ); foreach (light, list) { if (light->Flags & LIGHT_SPECULAR) { @@ -594,6 +618,7 @@ void gl_update_material( GLcontext *ctx, } if (bitmask & BACK_SPECULAR_BIT) { struct gl_material *mat = &ctx->Light.Material[1]; + GLfloat tmp[4]; SUB_3V( tmp, src[1].Specular, mat->Specular ); foreach (light, list) { if (light->Flags & LIGHT_SPECULAR) { @@ -604,18 +629,7 @@ void gl_update_material( GLcontext *ctx, } COPY_4FV( mat->Specular, src[1].Specular ); } - if (bitmask & FRONT_EMISSION_BIT) { - struct gl_material *mat = &ctx->Light.Material[0]; - SUB_3V( tmp, src[0].Emission, mat->Emission ); - ACC_3V( ctx->Light.BaseColor[0], tmp ); - COPY_4FV( mat->Emission, src[0].Emission ); - } - if (bitmask & BACK_EMISSION_BIT) { - struct gl_material *mat = &ctx->Light.Material[1]; - SUB_3V( tmp, src[1].Emission, mat->Emission ); - ACC_3V( ctx->Light.BaseColor[1], tmp ); - COPY_4FV( mat->Emission, src[1].Emission ); - } + if (bitmask & FRONT_SHININESS_BIT) { GLfloat shininess = ctx->Light.Material[0].Shininess = src[0].Shininess; gl_compute_shine_table( ctx, 0, shininess ); @@ -626,6 +640,7 @@ void gl_update_material( GLcontext *ctx, gl_compute_shine_table( ctx, 1, shininess ); gl_compute_shine_table( ctx, 3, shininess * .5 ); } + if (bitmask & FRONT_INDEXES_BIT) { ctx->Light.Material[0].AmbientIndex = src[0].AmbientIndex; ctx->Light.Material[0].DiffuseIndex = src[0].DiffuseIndex; @@ -662,43 +677,68 @@ void gl_update_material( GLcontext *ctx, - - +/* + * Update the current materials from the given rgba color + * according to the bitmask in ColorMaterialBitmask, which is + * set by glColorMaterial(). + */ void gl_update_color_material( GLcontext *ctx, const GLubyte rgba[4] ) { struct gl_light *light, *list = &ctx->Light.EnabledList; GLuint bitmask = ctx->Light.ColorMaterialBitmask; - GLfloat tmp[4], color[4]; + GLfloat color[4]; UBYTE_RGBA_TO_FLOAT_RGBA( color, rgba ); if (MESA_VERBOSE&VERBOSE_IMMEDIATE) - fprintf(stderr, "gl_update_color_material, mask %x\n", bitmask); + fprintf(stderr, "gl_update_color_material, mask 0x%x\n", bitmask); + + /* update emissive colors */ + if (bitmask & FRONT_EMISSION_BIT) { + struct gl_material *mat = &ctx->Light.Material[0]; + COPY_4FV( mat->Emission, color ); + } + if (bitmask & BACK_EMISSION_BIT) { + struct gl_material *mat = &ctx->Light.Material[1]; + COPY_4FV( mat->Emission, color ); + } + /* update light->MatAmbient = light's ambient * material's ambient */ if (bitmask & FRONT_AMBIENT_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; - SUB_3V( tmp, color, mat->Ambient ); - ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp); foreach (light, list) { - ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); + SCALE_3V( light->MatAmbient[0], light->Ambient, color); } COPY_4FV( mat->Ambient, color ); } if (bitmask & BACK_AMBIENT_BIT) { struct gl_material *mat = &ctx->Light.Material[1]; - SUB_3V( tmp, color, mat->Ambient ); - ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp); foreach (light, list) { - ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp ); + SCALE_3V( light->MatAmbient[1], light->Ambient, color); } COPY_4FV( mat->Ambient, color ); } + /* update BaseColor = emission + scene's ambience * material's ambience */ + if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) { + struct gl_material *mat = &ctx->Light.Material[0]; + COPY_3V( ctx->Light.BaseColor[0], mat->Emission ); + ACC_SCALE_3V( ctx->Light.BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient ); + } + + if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) { + struct gl_material *mat = &ctx->Light.Material[1]; + COPY_3V( ctx->Light.BaseColor[1], mat->Emission ); + ACC_SCALE_3V( ctx->Light.BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient ); + } + + /* update light->MatDiffuse = light's diffuse * material's diffuse */ if (bitmask & FRONT_DIFFUSE_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; + GLfloat tmp[4]; SUB_3V( tmp, color, mat->Diffuse ); foreach (light, list) { ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp ); @@ -709,6 +749,7 @@ void gl_update_color_material( GLcontext *ctx, if (bitmask & BACK_DIFFUSE_BIT) { struct gl_material *mat = &ctx->Light.Material[1]; + GLfloat tmp[4]; SUB_3V( tmp, color, mat->Diffuse ); foreach (light, list) { ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp ); @@ -717,8 +758,10 @@ void gl_update_color_material( GLcontext *ctx, FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[1], mat->Diffuse[3]); } + /* update light->MatSpecular = light's specular * material's specular */ if (bitmask & FRONT_SPECULAR_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; + GLfloat tmp[4]; SUB_3V( tmp, color, mat->Specular ); foreach (light, list) { if (light->Flags & LIGHT_SPECULAR) { @@ -729,8 +772,10 @@ void gl_update_color_material( GLcontext *ctx, } COPY_4FV( mat->Specular, color ); } + if (bitmask & BACK_SPECULAR_BIT) { struct gl_material *mat = &ctx->Light.Material[1]; + GLfloat tmp[4]; SUB_3V( tmp, color, mat->Specular ); foreach (light, list) { if (light->Flags & LIGHT_SPECULAR) { @@ -741,18 +786,6 @@ void gl_update_color_material( GLcontext *ctx, } COPY_4FV( mat->Specular, color ); } - if (bitmask & FRONT_EMISSION_BIT) { - struct gl_material *mat = &ctx->Light.Material[0]; - SUB_3V( tmp, color, mat->Emission ); - ACC_3V( ctx->Light.BaseColor[0], tmp ); - COPY_4FV( mat->Emission, color ); - } - if (bitmask & BACK_EMISSION_BIT) { - struct gl_material *mat = &ctx->Light.Material[1]; - SUB_3V( tmp, color, mat->Emission ); - ACC_3V( ctx->Light.BaseColor[1], tmp ); - COPY_4FV( mat->Emission, color ); - } if (0) { @@ -1085,26 +1118,27 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) * Whenever the spotlight exponent for a light changes we must call * this function to recompute the exponent lookup table. */ -void gl_compute_spot_exp_table( struct gl_light *l ) +void +gl_compute_spot_exp_table( struct gl_light *l ) { - int i; - double exponent = l->SpotExponent; - double tmp = 0; - int clamp = 0; + GLint i; + GLdouble exponent = l->SpotExponent; + GLdouble tmp = 0; + GLint clamp = 0; l->SpotExpTable[0][0] = 0.0; - for (i=EXP_TABLE_SIZE-1;i>0;i--) { + for (i = EXP_TABLE_SIZE - 1; i > 0 ;i--) { if (clamp == 0) { - tmp = pow(i/(double)(EXP_TABLE_SIZE-1), exponent); - if (tmp < FLT_MIN*100.0) { + tmp = pow(i / (GLdouble) (EXP_TABLE_SIZE - 1), exponent); + if (tmp < FLT_MIN * 100.0) { tmp = 0.0; clamp = 1; } } l->SpotExpTable[i][0] = tmp; } - for (i=0;i<EXP_TABLE_SIZE-1;i++) { + for (i = 0; i < EXP_TABLE_SIZE - 1; i++) { l->SpotExpTable[i][1] = l->SpotExpTable[i+1][0] - l->SpotExpTable[i][0]; } l->SpotExpTable[EXP_TABLE_SIZE-1][1] = 0.0; @@ -1117,30 +1151,36 @@ void gl_compute_spot_exp_table( struct gl_light *l ) * lighting, and the cost of doing it early may be partially offset * by keeping a MRU cache of shine tables for various shine values. */ -static void compute_shine_table( struct gl_shine_tab *tab, GLfloat shininess ) +static void +compute_shine_table( struct gl_shine_tab *tab, GLfloat shininess ) { - int i; + GLint i; GLfloat *m = tab->tab; - m[0] = 0; - if (shininess == 0) { + m[0] = 0.0; + if (shininess == 0.0) { for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++) - m[i] = 1; - } else { - for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++) { - double t = pow( i/(GLfloat)SHINE_TABLE_SIZE, shininess ); - m[i] = 0; - if (t > 1e-20) m[i] = t; + m[i] = 1.0; + } + else { + for (i = 1 ; i < SHINE_TABLE_SIZE ; i++) { + GLdouble t = pow(i / (GLfloat) (SHINE_TABLE_SIZE - 1), shininess); + if (t > 1e-20) + m[i] = t; + else + m[i] = 0.0; } + m[SHINE_TABLE_SIZE] = 1.0; } tab->shininess = shininess; } -#define DISTSQR(a,b) ((a-b)*(a-b)) -void gl_compute_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess ) +void +gl_compute_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess ) { +#define DISTSQR(a,b) ((a-b)*(a-b)) struct gl_shine_tab *list = ctx->ShineTabList; struct gl_shine_tab *s; @@ -1148,10 +1188,10 @@ void gl_compute_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess ) if ( DISTSQR(s->shininess, shininess) < 1e-4 ) break; - if (s == list) - { + if (s == list) { foreach(s, list) - if (s->refcount == 0) break; + if (s->refcount == 0) + break; compute_shine_table( s, shininess ); } @@ -1160,12 +1200,14 @@ void gl_compute_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess ) ctx->ShineTable[i] = s; move_to_tail( list, s ); s->refcount++; +#undef DISTSQR } #if 0 -static void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) +static void +gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) { GLuint i; @@ -1194,7 +1236,8 @@ static void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) * Also, precompute some lighting values such as the products of light * source and material ambient, diffuse and specular coefficients. */ -void gl_update_lighting( GLcontext *ctx ) +void +gl_update_lighting( GLcontext *ctx ) { struct gl_light *light; @@ -1224,13 +1267,12 @@ void gl_update_lighting( GLcontext *ctx ) /* Precompute some shading values. */ - if (ctx->Visual->RGBAflag) - { + if (ctx->Visual->RGBAflag) { GLuint sides = ((ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) ? 2 : 1); GLuint side; for (side=0; side < sides; side++) { struct gl_material *mat = &ctx->Light.Material[side]; - + COPY_3V(ctx->Light.BaseColor[side], mat->Emission); ACC_SCALE_3V(ctx->Light.BaseColor[side], ctx->Light.Model.Ambient, @@ -1242,12 +1284,10 @@ void gl_update_lighting( GLcontext *ctx ) foreach (light, &ctx->Light.EnabledList) { for (side=0; side< sides; side++) { - struct gl_material *mat = &ctx->Light.Material[side]; - SCALE_3V( light->MatDiffuse[side], light->Diffuse, mat->Diffuse ); - SCALE_3V( light->MatAmbient[side], light->Ambient, mat->Ambient ); - ACC_3V( ctx->Light.BaseColor[side], light->MatAmbient[side] ); - if (light->Flags & LIGHT_SPECULAR) - { + const struct gl_material *mat = &ctx->Light.Material[side]; + SCALE_3V( light->MatDiffuse[side], light->Diffuse, mat->Diffuse ); + SCALE_3V( light->MatAmbient[side], light->Ambient, mat->Ambient ); + if (light->Flags & LIGHT_SPECULAR) { SCALE_3V( light->MatSpecular[side], light->Specular, mat->Specular); light->IsMatSpecular[side] = @@ -1258,10 +1298,8 @@ void gl_update_lighting( GLcontext *ctx ) } } } - else - { - static GLfloat ci[3] = { .30, .59, .11 }; - + else { + static const GLfloat ci[3] = { .30, .59, .11 }; foreach(light, &ctx->Light.EnabledList) { light->dli = DOT3(ci, light->Diffuse); light->sli = DOT3(ci, light->Specular); @@ -1269,52 +1307,54 @@ void gl_update_lighting( GLcontext *ctx ) } } + + /* Need to seriously restrict the circumstances under which these * calc's are performed. */ -void gl_compute_light_positions( GLcontext *ctx ) +void +gl_compute_light_positions( GLcontext *ctx ) { struct gl_light *light; - if (ctx->Light.NeedVertices && !ctx->Light.Model.LocalViewer) { - GLfloat eye_z[3] = { 0, 0, 1 }; - if (!ctx->NeedEyeCoords) { - TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m ); - } else { + if (1 /*ctx->Light.NeedVertices && !ctx->Light.Model.LocalViewer*/) { + static const GLfloat eye_z[3] = { 0, 0, 1 }; + if (ctx->NeedEyeCoords) { COPY_3V( ctx->EyeZDir, eye_z ); } + else { + TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m ); + } } foreach (light, &ctx->Light.EnabledList) { - if (!ctx->NeedEyeCoords) { + if (ctx->NeedEyeCoords) { + COPY_4FV( light->Position, light->EyePosition ); + } + else { TRANSFORM_POINT( light->Position, ctx->ModelView.inv, light->EyePosition ); - } else { - COPY_4FV( light->Position, light->EyePosition ); } - if (!(light->Flags & LIGHT_POSITIONAL)) - { + if (!(light->Flags & LIGHT_POSITIONAL)) { /* VP (VP) = Normalize( Position ) */ COPY_3V( light->VP_inf_norm, light->Position ); NORMALIZE_3FV( light->VP_inf_norm ); - if (!ctx->Light.Model.LocalViewer) - { + if (!ctx->Light.Model.LocalViewer) { /* h_inf_norm = Normalize( V_to_P + <0,0,1> ) */ ADD_3V( light->h_inf_norm, light->VP_inf_norm, ctx->EyeZDir); NORMALIZE_3FV( light->h_inf_norm ); } - light->VP_inf_spot_attenuation = 1.0; } - if (light->Flags & LIGHT_SPOT) - { + if (light->Flags & LIGHT_SPOT) { if (ctx->NeedEyeNormals) { COPY_3V( light->NormDirection, light->EyeDirection ); - } else { + } + else { TRANSFORM_NORMAL( light->NormDirection, light->EyeDirection, ctx->ModelView.m); @@ -1336,18 +1376,17 @@ void gl_compute_light_positions( GLcontext *ctx ) (light->SpotExpTable[k][0] + (x-k)*light->SpotExpTable[k][1]); } - else + else { light->VP_inf_spot_attenuation = 0; + } } } } } - - - -void gl_update_normal_transform( GLcontext *ctx ) +void +gl_update_normal_transform( GLcontext *ctx ) { GLuint new_flag = 0; normal_func *last = ctx->NormalTransform; @@ -1368,20 +1407,18 @@ void gl_update_normal_transform( GLcontext *ctx ) new_flag = ctx->NewState & NEW_MODELVIEW; ctx->vb_rescale_factor = ctx->rescale_factor; - if (ctx->Transform.Normalize) - { + if (ctx->Transform.Normalize) { ctx->NormalTransform = gl_normal_tab[transform | NORM_NORMALIZE]; } else if (ctx->Transform.RescaleNormals && - ctx->rescale_factor != 1.0) - { + ctx->rescale_factor != 1.0) { ctx->NormalTransform = gl_normal_tab[transform | NORM_RESCALE]; } - else - { + else { ctx->NormalTransform = gl_normal_tab[transform]; } - } else { + } + else { ctx->NormalTransform = 0; } } @@ -1389,20 +1426,18 @@ void gl_update_normal_transform( GLcontext *ctx ) if (ctx->NeedNormals) { ctx->vb_rescale_factor = 1.0/ctx->rescale_factor; - if (ctx->Transform.Normalize) - { + if (ctx->Transform.Normalize) { ctx->NormalTransform = gl_normal_tab[NORM_NORMALIZE]; } else if (!ctx->Transform.RescaleNormals && - ctx->rescale_factor != 1.0) - { + ctx->rescale_factor != 1.0) { ctx->NormalTransform = gl_normal_tab[NORM_RESCALE]; } - else - { + else { ctx->NormalTransform = 0; } - } else { + } + else { ctx->NormalTransform = 0; } } @@ -1410,4 +1445,3 @@ void gl_update_normal_transform( GLcontext *ctx ) if (last != ctx->NormalTransform || new_flag) ctx->NewState |= NEW_NORMAL_TRANSFORM; } - diff --git a/xc/extras/Mesa/src/light.h b/xc/extras/Mesa/src/light.h index aa7ded40c..8edcac801 100644 --- a/xc/extras/Mesa/src/light.h +++ b/xc/extras/Mesa/src/light.h @@ -3,7 +3,7 @@ * Mesa 3-D graphics library * Version: 3.3 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -114,7 +114,7 @@ extern void gl_compute_light_positions( GLcontext *ctx ); extern void gl_update_normal_transform( GLcontext *ctx ); extern void gl_update_material( GLcontext *ctx, - struct gl_material *m, + const struct gl_material src[2], GLuint bitmask ); extern void gl_update_color_material( GLcontext *ctx, const GLubyte rgba[4] ); diff --git a/xc/extras/Mesa/src/lines.c b/xc/extras/Mesa/src/lines.c index dd0649ba0..7b3b51112 100644 --- a/xc/extras/Mesa/src/lines.c +++ b/xc/extras/Mesa/src/lines.c @@ -556,13 +556,8 @@ static void general_smooth_rgba_line( GLcontext *ctx, static void general_flat_rgba_line( GLcontext *ctx, GLuint vert0, GLuint vert1, GLuint pvert ) { - GLint count; - GLint *pbx = ctx->PB->x; - GLint *pby = ctx->PB->y; - GLdepth *pbz = ctx->PB->z; - GLubyte *color = ctx->VB->ColorPtr->data[pvert]; + const GLubyte *color = ctx->VB->ColorPtr->data[pvert]; PB_SET_COLOR( ctx->PB, color[0], color[1], color[2], color[3] ); - count = ctx->PB->count; if (ctx->Line.StippleFlag) { /* stippled */ @@ -570,12 +565,7 @@ static void general_flat_rgba_line( GLcontext *ctx, #define INTERP_Z 1 #define WIDE 1 #define STIPPLE 1 -#define PLOT(X,Y) \ - pbx[count] = X; \ - pby[count] = Y; \ - pbz[count] = Z; \ - count++; \ - CHECK_FULL(count); +#define PLOT(X,Y) PB_WRITE_PIXEL(ctx->PB, X, Y, Z); #include "linetemp.h" } else { @@ -584,18 +574,10 @@ static void general_flat_rgba_line( GLcontext *ctx, /* special case: unstippled and width=2 */ #define INTERP_XY 1 #define INTERP_Z 1 -#define XMAJOR_PLOT(X,Y) \ - pbx[count] = X; pbx[count+1] = X; \ - pby[count] = Y; pby[count+1] = Y+1; \ - pbz[count] = Z; pbz[count+1] = Z; \ - count += 2; \ - CHECK_FULL(count); -#define YMAJOR_PLOT(X,Y) \ - pbx[count] = X; pbx[count+1] = X+1; \ - pby[count] = Y; pby[count+1] = Y; \ - pbz[count] = Z; pbz[count+1] = Z; \ - count += 2; \ - CHECK_FULL(count); +#define XMAJOR_PLOT(X,Y) PB_WRITE_PIXEL(ctx->PB, X, Y, Z); \ + PB_WRITE_PIXEL(ctx->PB, X, Y+1, Z); +#define YMAJOR_PLOT(X,Y) PB_WRITE_PIXEL(ctx->PB, X, Y, Z); \ + PB_WRITE_PIXEL(ctx->PB, X+1, Y, Z); #include "linetemp.h" } else { @@ -603,17 +585,11 @@ static void general_flat_rgba_line( GLcontext *ctx, #define INTERP_XY 1 #define INTERP_Z 1 #define WIDE 1 -#define PLOT(X,Y) \ - pbx[count] = X; \ - pby[count] = Y; \ - pbz[count] = Z; \ - count++; \ - CHECK_FULL(count); +#define PLOT(X,Y) PB_WRITE_PIXEL(ctx->PB, X, Y, Z); #include "linetemp.h" } } - ctx->PB->count = count; gl_flush_pb(ctx); } @@ -847,6 +823,104 @@ static void smooth_multitextured_line( GLcontext *ctx, } +/* Flat-shaded, multitextured, any width, maybe stippled, separate specular + * color interpolation. + */ +static void flat_multitextured_line( GLcontext *ctx, + GLuint vert0, GLuint vert1, GLuint pvert ) +{ + GLint count = ctx->PB->count; + GLint *pbx = ctx->PB->x; + GLint *pby = ctx->PB->y; + GLdepth *pbz = ctx->PB->z; + GLfloat *pbs = ctx->PB->s[0]; + GLfloat *pbt = ctx->PB->t[0]; + GLfloat *pbu = ctx->PB->u[0]; + GLfloat *pbs1 = ctx->PB->s[1]; + GLfloat *pbt1 = ctx->PB->t[1]; + GLfloat *pbu1 = ctx->PB->u[1]; + GLubyte (*pbrgba)[4] = ctx->PB->rgba; + GLubyte (*pbspec)[3] = ctx->PB->spec; + GLubyte *color = ctx->VB->ColorPtr->data[pvert]; + GLubyte sRed = ctx->VB->Specular ? ctx->VB->Specular[pvert][0] : 0; + GLubyte sGreen = ctx->VB->Specular ? ctx->VB->Specular[pvert][1] : 0; + GLubyte sBlue = ctx->VB->Specular ? ctx->VB->Specular[pvert][2] : 0; + + (void) pvert; + + ctx->PB->mono = GL_FALSE; + + if (ctx->Line.StippleFlag) { + /* stippled */ +#define INTERP_XY 1 +#define INTERP_Z 1 +#define INTERP_ALPHA 1 +#define INTERP_STUV0 1 +#define INTERP_STUV1 1 +#define WIDE 1 +#define STIPPLE 1 +#define PLOT(X,Y) \ + { \ + pbx[count] = X; \ + pby[count] = Y; \ + pbz[count] = Z; \ + pbs[count] = s; \ + pbt[count] = t; \ + pbu[count] = u; \ + pbs1[count] = s1; \ + pbt1[count] = t1; \ + pbu1[count] = u1; \ + pbrgba[count][RCOMP] = color[0]; \ + pbrgba[count][GCOMP] = color[1]; \ + pbrgba[count][BCOMP] = color[2]; \ + pbrgba[count][ACOMP] = color[3]; \ + pbspec[count][RCOMP] = sRed; \ + pbspec[count][GCOMP] = sGreen; \ + pbspec[count][BCOMP] = sBlue; \ + count++; \ + CHECK_FULL(count); \ + } +#include "linetemp.h" + } + else { + /* unstippled */ +#define INTERP_XY 1 +#define INTERP_Z 1 +#define INTERP_ALPHA 1 +#define INTERP_STUV0 1 +#define INTERP_STUV1 1 +#define WIDE 1 +#define PLOT(X,Y) \ + { \ + pbx[count] = X; \ + pby[count] = Y; \ + pbz[count] = Z; \ + pbs[count] = s; \ + pbt[count] = t; \ + pbu[count] = u; \ + pbs1[count] = s1; \ + pbt1[count] = t1; \ + pbu1[count] = u1; \ + pbrgba[count][RCOMP] = color[0]; \ + pbrgba[count][GCOMP] = color[1]; \ + pbrgba[count][BCOMP] = color[2]; \ + pbrgba[count][ACOMP] = color[3]; \ + pbspec[count][RCOMP] = sRed; \ + pbspec[count][GCOMP] = sGreen; \ + pbspec[count][BCOMP] = sBlue; \ + count++; \ + CHECK_FULL(count); \ + } +#include "linetemp.h" + } + + ctx->PB->count = count; + gl_flush_pb(ctx); +} + + + + /* * Antialiased RGBA line * @@ -934,6 +1008,61 @@ static void null_line( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv ) } + +#ifdef DEBUG +void +_mesa_print_line_function(GLcontext *ctx) +{ + printf("Line Func == "); + if (ctx->Driver.LineFunc == flat_ci_line) + printf("flat_ci_line\n"); + else if (ctx->Driver.LineFunc == flat_ci_z_line) + printf("flat_ci_z_line\n"); + else if (ctx->Driver.LineFunc == flat_rgba_line) + printf("flat_rgba_line\n"); + else if (ctx->Driver.LineFunc == flat_rgba_z_line) + printf("flat_rgba_z_line\n"); + else if (ctx->Driver.LineFunc == smooth_ci_line) + printf("smooth_ci_line\n"); + else if (ctx->Driver.LineFunc == smooth_ci_z_line) + printf("smooth_ci_z_line\n"); + else if (ctx->Driver.LineFunc == smooth_rgba_line) + printf("smooth_rgba_line\n"); + else if (ctx->Driver.LineFunc == smooth_rgba_z_line) + printf("smooth_rgba_z_line\n"); + else if (ctx->Driver.LineFunc == general_smooth_ci_line) + printf("general_smooth_ci_line\n"); + else if (ctx->Driver.LineFunc == general_flat_ci_line) + printf("general_flat_ci_line\n"); + else if (ctx->Driver.LineFunc == general_smooth_rgba_line) + printf("general_smooth_rgba_line\n"); + else if (ctx->Driver.LineFunc == general_flat_rgba_line) + printf("general_flat_rgba_line\n"); + else if (ctx->Driver.LineFunc == flat_textured_line) + printf("flat_textured_line\n"); + else if (ctx->Driver.LineFunc == smooth_textured_line) + printf("smooth_textured_line\n"); + else if (ctx->Driver.LineFunc == smooth_multitextured_line) + printf("smooth_multitextured_line\n"); + else if (ctx->Driver.LineFunc == flat_multitextured_line) + printf("flat_multitextured_line\n"); + else if (ctx->Driver.LineFunc == aa_rgba_line) + printf("aa_rgba_line\n"); + else if (ctx->Driver.LineFunc == aa_tex_rgba_line) + printf("aa_tex_rgba_line\n"); + else if (ctx->Driver.LineFunc == aa_multitex_rgba_line) + printf("aa_multitex_rgba_line\n"); + else if (ctx->Driver.LineFunc == aa_ci_line) + printf("aa_ci_line\n"); + else if (ctx->Driver.LineFunc == null_line) + printf("null_line\n"); + else + printf("Driver func %p\n", ctx->Driver.PointsFunc); +} +#endif + + + /* * Determine which line drawing function to use given the current * rendering context. @@ -975,7 +1104,10 @@ void gl_set_line_function( GLcontext *ctx ) if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D || ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) { /* multi-texture and/or separate specular color */ - ctx->Driver.LineFunc = smooth_multitextured_line; + if (ctx->Light.ShadeModel==GL_SMOOTH) + ctx->Driver.LineFunc = smooth_multitextured_line; + else + ctx->Driver.LineFunc = flat_multitextured_line; } else { if (ctx->Light.ShadeModel==GL_SMOOTH) { @@ -1041,5 +1173,6 @@ void gl_set_line_function( GLcontext *ctx ) /* GL_SELECT mode */ ctx->Driver.LineFunc = gl_select_line; } -} + /*_mesa_print_line_function(ctx);*/ +} diff --git a/xc/extras/Mesa/src/linetemp.h b/xc/extras/Mesa/src/linetemp.h index 9e0fbd301..9d427ad32 100644 --- a/xc/extras/Mesa/src/linetemp.h +++ b/xc/extras/Mesa/src/linetemp.h @@ -223,12 +223,12 @@ zPtr = (DEPTH_TYPE *) _mesa_zbuffer_address(ctx, x0, y0); # endif if (depthBits <= 16) { - z0 = FloatToFixed(VB->Win.data[vert0][2]); - z1 = FloatToFixed(VB->Win.data[vert1][2]); + z0 = FloatToFixed(VB->Win.data[vert0][2] + ctx->LineZoffset); + z1 = FloatToFixed(VB->Win.data[vert1][2] + ctx->LineZoffset); } else { - z0 = (int) VB->Win.data[vert0][2]; - z1 = (int) VB->Win.data[vert1][2]; + z0 = (int) VB->Win.data[vert0][2] + ctx->LineZoffset; + z1 = (int) VB->Win.data[vert1][2] + ctx->LineZoffset; } #endif #ifdef PIXEL_ADDRESS diff --git a/xc/extras/Mesa/src/lnaatemp.h b/xc/extras/Mesa/src/lnaatemp.h index 118ffb675..1a96a811f 100644 --- a/xc/extras/Mesa/src/lnaatemp.h +++ b/xc/extras/Mesa/src/lnaatemp.h @@ -1,9 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 3.1 + * Version: 3.3 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -103,12 +103,12 @@ ctx->PB->mono = GL_FALSE; if (depthBits <= 16) { - z0 = FloatToFixed(VB->Win.data[vert0][2]); - z1 = FloatToFixed(VB->Win.data[vert1][2]); + z0 = FloatToFixed(VB->Win.data[vert0][2] + ctx->LineZoffset); + z1 = FloatToFixed(VB->Win.data[vert1][2] + ctx->LineZoffset); } else { - z0 = (int) VB->Win.data[vert0][2]; - z1 = (int) VB->Win.data[vert1][2]; + z0 = (int) VB->Win.data[vert0][2] + ctx->LineZoffset; + z1 = (int) VB->Win.data[vert1][2] + ctx->LineZoffset; } #ifdef INTERP_STUV0 diff --git a/xc/extras/Mesa/src/logic.c b/xc/extras/Mesa/src/logic.c index 1078cca68..872cb48d6 100644 --- a/xc/extras/Mesa/src/logic.c +++ b/xc/extras/Mesa/src/logic.c @@ -63,7 +63,7 @@ _mesa_LogicOp( GLenum opcode ) case GL_OR_INVERTED: ctx->Color.LogicOp = opcode; ctx->NewState |= NEW_RASTER_OPS; - return; + break; default: gl_error( ctx, GL_INVALID_ENUM, "glLogicOp" ); return; diff --git a/xc/extras/Mesa/src/matrix.c b/xc/extras/Mesa/src/matrix.c index 5c66ef0e3..ed3175536 100644 --- a/xc/extras/Mesa/src/matrix.c +++ b/xc/extras/Mesa/src/matrix.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -596,7 +596,7 @@ void gl_rotation_matrix( GLfloat angle, GLfloat x, GLfloat y, GLfloat z, mag = GL_SQRT( x*x + y*y + z*z ); - if (mag == 0.0) { + if (mag <= 1.0e-4) { /* generate an identity matrix and return */ MEMCPY(m, Identity, sizeof(GLfloat)*16); return; @@ -1561,16 +1561,23 @@ void gl_calculate_model_project_matrix( GLcontext *ctx ) void gl_matrix_ctr( GLmatrix *m ) { + if ( m->m == 0 ) { + m->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 ); + } + MEMCPY( m->m, Identity, sizeof(Identity) ); m->inv = 0; - MEMCPY( m->m, Identity, sizeof(Identity)); m->type = MATRIX_IDENTITY; m->flags = MAT_DIRTY_DEPENDENTS; } void gl_matrix_dtr( GLmatrix *m ) { - if (m->inv != 0) { - FREE(m->inv); + if ( m->m != 0 ) { + ALIGN_FREE( m->m ); + m->m = 0; + } + if ( m->inv != 0 ) { + ALIGN_FREE( m->inv ); m->inv = 0; } } @@ -1578,7 +1585,7 @@ void gl_matrix_dtr( GLmatrix *m ) #if 0 void gl_matrix_set_identity( GLmatrix *m ) { - MEMCPY( m->m, Identity, sizeof(Identity)); + MEMCPY( m->m, Identity, sizeof(Identity) ); m->type = MATRIX_IDENTITY; m->flags = MAT_DIRTY_DEPENDENTS; } @@ -1586,15 +1593,15 @@ void gl_matrix_set_identity( GLmatrix *m ) void gl_matrix_alloc_inv( GLmatrix *m ) { - if (m->inv == 0) { - m->inv = (GLfloat *)MALLOC(16*sizeof(GLfloat)); + if ( m->inv == 0 ) { + m->inv = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 ); MEMCPY( m->inv, Identity, 16 * sizeof(GLfloat) ); } } void gl_matrix_copy( GLmatrix *to, const GLmatrix *from ) { - MEMCPY( to->m, from->m, sizeof(Identity)); + MEMCPY( to->m, from->m, sizeof(Identity) ); to->flags = from->flags | MAT_DIRTY_DEPENDENTS; to->type = from->type; diff --git a/xc/extras/Mesa/src/matrix.h b/xc/extras/Mesa/src/matrix.h index 44d7cefab..6d989abd1 100644 --- a/xc/extras/Mesa/src/matrix.h +++ b/xc/extras/Mesa/src/matrix.h @@ -33,8 +33,8 @@ typedef struct { - GLfloat m[16]; - GLfloat *inv; /* optional */ + GLfloat *m; /* 16-byte aligned */ + GLfloat *inv; /* optional, 16-byte aligned */ GLuint flags; GLuint type; } GLmatrix; diff --git a/xc/extras/Mesa/src/mem.c b/xc/extras/Mesa/src/mem.c index fff2bb163..9334b63c4 100644 --- a/xc/extras/Mesa/src/mem.c +++ b/xc/extras/Mesa/src/mem.c @@ -36,6 +36,7 @@ #include "all.h" #else #include "glheader.h" +#include "macros.h" #include "mem.h" #endif @@ -71,3 +72,84 @@ _mesa_free(void *ptr) } + +/* + * N-byte aligned memory allocation functions. Called via the ALIGN_MALLOC, + * ALIGN_CALLOC and ALIGN_FREE macros. Debug versions? + * These functions allow dynamically allocated memory to be correctly + * aligned for improved cache utilization and specialized assembly + * support. + */ + + +/* + * Allocate N-byte aligned memory (uninitialized) + */ +void * +_mesa_align_malloc(size_t bytes, unsigned long alignment) +{ + unsigned long ptr, buf; + + ASSERT( alignment > 0 ); + + ptr = (unsigned long) MALLOC( bytes + alignment ); + + buf = (ptr + alignment) & ~(unsigned long)(alignment - 1); + *(unsigned long *)(buf - sizeof(void *)) = ptr; + +#ifdef DEBUG + /* mark the non-aligned area */ + while ( ptr < buf - sizeof(void *) ) { + *(unsigned long *)ptr = 0xcdcdcdcd; + ptr += sizeof(unsigned long); + } +#endif + + return (void *)buf; +} + + +/* + * Allocate N-byte aligned memory and initialize to zero + */ +void * +_mesa_align_calloc(size_t bytes, unsigned long alignment) +{ + unsigned long ptr, buf; + + ASSERT( alignment > 0 ); + + ptr = (unsigned long) CALLOC( bytes + alignment ); + + buf = (ptr + alignment) & ~(unsigned long)(alignment - 1); + *(unsigned long *)(buf - sizeof(void *)) = ptr; + +#ifdef DEBUG + /* mark the non-aligned area */ + while ( ptr < buf - sizeof(void *) ) { + *(unsigned long *)ptr = 0xcdcdcdcd; + ptr += sizeof(unsigned long); + } +#endif + + return (void *)buf; +} + + +/* + * Free N-byte aligned memory + */ +void +_mesa_align_free(void *ptr) +{ +#if 0 + FREE( (void *)(*(unsigned long *)((unsigned long)ptr - sizeof(void *))) ); +#else + /* The actuall address to free is stuffed in the word immediately + * before the address the client sees. + */ + void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); + void *realAddr = *cubbyHole; + FREE(realAddr); +#endif +} diff --git a/xc/extras/Mesa/src/mem.h b/xc/extras/Mesa/src/mem.h index 794aa13ef..8935cb1aa 100644 --- a/xc/extras/Mesa/src/mem.h +++ b/xc/extras/Mesa/src/mem.h @@ -38,6 +38,10 @@ extern void *_mesa_malloc(size_t bytes); extern void *_mesa_calloc(size_t bytes); extern void _mesa_free(void *ptr); +extern void *_mesa_align_malloc(size_t bytes, unsigned long alignment); +extern void *_mesa_align_calloc(size_t bytes, unsigned long alignment); +extern void _mesa_align_free(void *ptr); + #ifdef DEBUG @@ -59,6 +63,13 @@ extern void _mesa_free(void *ptr); #endif +/* call Mesa N-byte aligned memory functions */ +#define ALIGN_MALLOC(BYTES, N) (void *) _mesa_align_malloc(BYTES, N) +#define ALIGN_CALLOC(BYTES, N) (void *) _mesa_align_calloc(BYTES, N) +#define ALIGN_MALLOC_STRUCT(T, N) (struct T *) _mesa_align_malloc(sizeof(struct T), N) +#define ALIGN_CALLOC_STRUCT(T, N) (struct T *) _mesa_align_calloc(sizeof(struct T), N) +#define ALIGN_FREE(PTR) _mesa_align_free(PTR) + /* Memory copy: */ #ifdef SUNOS4 diff --git a/xc/extras/Mesa/src/mmath.h b/xc/extras/Mesa/src/mmath.h index 773e77645..c0144c924 100644 --- a/xc/extras/Mesa/src/mmath.h +++ b/xc/extras/Mesa/src/mmath.h @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -47,7 +47,7 @@ * In the worst case, we force the compiler to use a memory access to * truncate the float, by specifying the 'volatile' keyword. */ -#if defined(__linux__) && defined(__i386__) +#if defined(__linux__) && defined(__i386__) #include <fpu_control.h> #if !defined(_FPU_SETCW) @@ -232,14 +232,14 @@ do { \ * GLubyte b = FloatToInt(CLAMP(f, 0, 1) * 255) */ -#if defined(__i386__) || defined(__sparc__) +#if defined(__i386__) || defined(__sparc__) || ( defined(__alpha__) && \ + ( defined( __IEEE_FLOAT ) || !defined( VMS ) ) ) #define USE_IEEE +#define IEEE_ONE 0x3f7f0000 #endif #if defined(USE_IEEE) && !defined(DEBUG) -#define IEEE_ONE 0x3f7f0000 - #define CLAMP_FLOAT_COLOR(f) \ do { \ if (*(GLuint *)&f >= IEEE_ONE) \ diff --git a/xc/extras/Mesa/src/pb.c b/xc/extras/Mesa/src/pb.c index 78ff5d07e..4cfbfa674 100644 --- a/xc/extras/Mesa/src/pb.c +++ b/xc/extras/Mesa/src/pb.c @@ -254,17 +254,22 @@ void gl_flush_pb( GLcontext *ctx ) if ((ctx->RasterMask & modBits) || !PB->mono) { if (ctx->Texture.ReallyEnabled) { - int texUnit; + GLubyte primary_rgba[PB_SIZE][4]; + GLint texUnit; + + /* must make a copy of primary colors since they may be modified */ + MEMCPY(primary_rgba, PB->rgba, 4 * PB->count * sizeof(GLubyte)); + for (texUnit=0;texUnit<MAX_TEXTURE_UNITS;texUnit++) { - gl_texture_pixels( ctx, texUnit, - PB->count, PB->s[texUnit], PB->t[texUnit], - PB->u[texUnit], PB->lambda[texUnit], - PB->rgba); + gl_texture_pixels( ctx, texUnit, + PB->count, PB->s[texUnit], PB->t[texUnit], + PB->u[texUnit], PB->lambda[texUnit], + primary_rgba, PB->rgba ); } } if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR - && ctx->Light.Enabled) { + && ctx->Light.Enabled && ctx->Texture.ReallyEnabled) { /* add specular color to primary color */ add_colors( PB->count, PB->rgba, (const GLubyte (*)[3]) PB->spec ); } diff --git a/xc/extras/Mesa/src/points.c b/xc/extras/Mesa/src/points.c index 77d1e0de0..41cd06022 100644 --- a/xc/extras/Mesa/src/points.c +++ b/xc/extras/Mesa/src/points.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -358,7 +358,7 @@ textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) green = VB->ColorPtr->data[i][1]; blue = VB->ColorPtr->data[i][2]; alpha = VB->ColorPtr->data[i][3]; - + switch (VB->TexCoordPtr[0]->size) { case 4: s = VB->TexCoordPtr[0]->data[i][0]/VB->TexCoordPtr[0]->data[i][3]; @@ -386,15 +386,13 @@ textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) gl_problem(ctx, "unexpected texcoord size in textured_rgba_points()"); } -/* don't think this is needed - PB_SET_COLOR( red, green, blue, alpha ); -*/ - for (iy = y0; iy <= y1; iy++) { for (ix = x0; ix <= x1; ix++) { - PB_WRITE_TEX_PIXEL( PB, ix, iy, z, red, green, blue, alpha, s, t, u ); + PB_WRITE_TEX_PIXEL( PB, ix, iy, z, red, green, blue, alpha, + s, t, u ); } } + PB_CHECK_FLUSH(ctx, PB); } } @@ -417,6 +415,7 @@ multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) GLint ix, iy; GLint radius; GLint red, green, blue, alpha; + GLint sRed, sGreen, sBlue; GLfloat s, t, u; GLfloat s1, t1, u1; @@ -449,6 +448,9 @@ multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) green = VB->ColorPtr->data[i][1]; blue = VB->ColorPtr->data[i][2]; alpha = VB->ColorPtr->data[i][3]; + sRed = VB->Specular ? VB->Specular[i][0] : 0; + sGreen = VB->Specular ? VB->Specular[i][1] : 0; + sBlue = VB->Specular ? VB->Specular[i][2] : 0; switch (VB->TexCoordPtr[0]->size) { case 4: @@ -506,8 +508,10 @@ multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) for (iy=y0;iy<=y1;iy++) { for (ix=x0;ix<=x1;ix++) { - PB_WRITE_MULTITEX_PIXEL( PB, ix, iy, z, red, green, blue, alpha, - s, t, u, s1, t1, u1 ); + PB_WRITE_MULTITEX_SPEC_PIXEL( PB, ix, iy, z, + red, green, blue, alpha, + sRed, sGreen, sBlue, + s, t, u, s1, t1, u1 ); } } PB_CHECK_FLUSH(ctx, PB); @@ -516,6 +520,17 @@ multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) } +/* + * NOTES on aa point rasterization: + * + * Let d = distance of fragment center from vertex. + * if d < rmin2 then + * fragment has 100% coverage + * else if d > rmax2 then + * fragment has 0% coverage + * else + * fragement has % coverage = (d - rmin2) / (rmax2 - rmin2) + */ /* @@ -529,7 +544,7 @@ antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) const GLfloat radius = ctx->Point.Size * 0.5F; const GLfloat rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */ const GLfloat rmax = radius + 0.7071F; - const GLfloat rmin2 = rmin * rmin; + const GLfloat rmin2 = MAX2(0.0, rmin * rmin); const GLfloat rmax2 = rmax * rmax; const GLfloat cscale = 256.0F / (rmax2 - rmin2); GLuint i; @@ -539,13 +554,15 @@ antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) if (VB->ClipMask[i] == 0) { GLint x, y; GLint red, green, blue, alpha; - GLfloat s, t, u; - GLfloat s1, t1, u1; - - GLint xmin = (GLint) (VB->Win.data[i][0] - radius); - GLint xmax = (GLint) (VB->Win.data[i][0] + radius); - GLint ymin = (GLint) (VB->Win.data[i][1] - radius); - GLint ymax = (GLint) (VB->Win.data[i][1] + radius); + GLfloat s = 0.0F, t = 0.0F, u = 0.0F; + GLfloat s1 = 0.0F, t1 = 0.0F, u1 = 0.0F; + GLfloat vx = VB->Win.data[i][0]; + GLfloat vy = VB->Win.data[i][1]; + + GLint xmin = (GLint) (vx - radius); + GLint xmax = (GLint) (vx + radius); + GLint ymin = (GLint) (vy - radius); + GLint ymax = (GLint) (vy + radius); GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset); red = VB->ColorPtr->data[i][0]; @@ -616,15 +633,19 @@ antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) } } - for (y=ymin;y<=ymax;y++) { - for (x=xmin;x<=xmax;x++) { - GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0]; - GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1]; - GLfloat dist2 = dx*dx + dy*dy; - if (dist2<rmax2) { + /* translate by a half pixel to simplify math below */ + vx -= 0.5F; + vx -= 0.5F; + + for (y = ymin; y <= ymax; y++) { + for (x = xmin; x <= xmax; x++) { + const GLfloat dx = x - vx; + const GLfloat dy = y - vy; + const GLfloat dist2 = dx*dx + dy*dy; + if (dist2 < rmax2) { alpha = VB->ColorPtr->data[i][3]; - if (dist2>=rmin2) { - GLint coverage = (GLint) (256.0F-(dist2-rmin2)*cscale); + if (dist2 >= rmin2) { + GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale); /* coverage is in [0,256] */ alpha = (alpha * coverage) >> 8; } @@ -651,25 +672,29 @@ antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) GLint x, y, z; GLint red, green, blue, alpha; - xmin = (GLint) (VB->Win.data[i][0] - radius); - xmax = (GLint) (VB->Win.data[i][0] + radius); - ymin = (GLint) (VB->Win.data[i][1] - radius); - ymax = (GLint) (VB->Win.data[i][1] + radius); + xmin = (GLint) (VB->Win.data[i][0] - 0.0 - radius); + xmax = (GLint) (VB->Win.data[i][0] - 0.0 + radius); + ymin = (GLint) (VB->Win.data[i][1] - 0.0 - radius); + ymax = (GLint) (VB->Win.data[i][1] - 0.0 + radius); z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset); red = VB->ColorPtr->data[i][0]; green = VB->ColorPtr->data[i][1]; blue = VB->ColorPtr->data[i][2]; - for (y=ymin;y<=ymax;y++) { - for (x=xmin;x<=xmax;x++) { - GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0]; - GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1]; - GLfloat dist2 = dx*dx + dy*dy; - if (dist2<rmax2) { + /* + printf("point %g, %g\n", VB->Win.data[i][0], VB->Win.data[i][1]); + printf("%d..%d X %d..%d\n", xmin, xmax, ymin, ymax); + */ + for (y = ymin; y <= ymax; y++) { + for (x = xmin; x <= xmax; x++) { + const GLfloat dx = x + 0.5F - VB->Win.data[i][0]; + const GLfloat dy = y + 0.5F - VB->Win.data[i][1]; + const GLfloat dist2 = dx*dx + dy*dy; + if (dist2 < rmax2) { alpha = VB->ColorPtr->data[i][3]; - if (dist2>=rmin2) { - GLint coverage = (GLint) (256.0F-(dist2-rmin2)*cscale); + if (dist2 >= rmin2) { + GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale); /* coverage is in [0,256] */ alpha = (alpha * coverage) >> 8; } @@ -936,8 +961,8 @@ dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) GLint ix, iy; GLint isize, radius; GLint red, green, blue, alpha; - GLfloat s, t, u; - GLfloat s1, t1, u1; + GLfloat s = 0.0F, t = 0.0F, u = 0.0F; + GLfloat s1 = 0.0F, t1 = 0.0F, u1 = 0.0F; GLint x = (GLint) VB->Win.data[i][0]; GLint y = (GLint) VB->Win.data[i][1]; @@ -1084,8 +1109,8 @@ dist_atten_antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) GLint xmin, ymin, xmax, ymax; GLint x, y, z; GLint red, green, blue, alpha; - GLfloat s, t, u; - GLfloat s1, t1, u1; + GLfloat s = 0.0F, t = 0.0F, u = 0.0F; + GLfloat s1 = 0.0F, t1 = 0.0F, u1 = 0.0F; GLfloat dsize = psize * dist[i]; if (dsize >= ctx->Point.Threshold) { @@ -1099,9 +1124,9 @@ dist_atten_antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) } rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */ rmax = radius + 0.7071F; - rmin2 = rmin*rmin; - rmax2 = rmax*rmax; - cscale = 256.0F / (rmax2-rmin2); + rmin2 = MAX2(0.0, rmin * rmin); + rmax2 = rmax * rmax; + cscale = 256.0F / (rmax2 - rmin2); xmin = (GLint) (VB->Win.data[i][0] - radius); xmax = (GLint) (VB->Win.data[i][0] + radius); @@ -1179,9 +1204,9 @@ dist_atten_antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) for (y = ymin; y <= ymax; y++) { for (x = xmin; x <= xmax; x++) { - GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0]; - GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1]; - GLfloat dist2 = dx*dx + dy*dy; + const GLfloat dx = x + 0.5F - VB->Win.data[i][0]; + const GLfloat dy = y + 0.5F - VB->Win.data[i][1]; + const GLfloat dist2 = dx*dx + dy*dy; if (dist2 < rmax2) { alpha = VB->ColorPtr->data[i][3]; if (dist2 >= rmin2) { @@ -1225,7 +1250,7 @@ dist_atten_antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) } rmin = radius - 0.7071F; /* 0.7071 = sqrt(2)/2 */ rmax = radius + 0.7071F; - rmin2 = rmin * rmin; + rmin2 = MAX2(0.0, rmin * rmin); rmax2 = rmax * rmax; cscale = 256.0F / (rmax2 - rmin2); @@ -1241,9 +1266,9 @@ dist_atten_antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last ) for (y = ymin; y <= ymax; y++) { for (x = xmin; x <= xmax; x++) { - GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0]; - GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1]; - GLfloat dist2 = dx * dx + dy * dy; + const GLfloat dx = x + 0.5F - VB->Win.data[i][0]; + const GLfloat dy = y + 0.5F - VB->Win.data[i][1]; + const GLfloat dist2 = dx * dx + dy * dy; if (dist2 < rmax2) { alpha = VB->ColorPtr->data[i][3]; if (dist2 >= rmin2) { @@ -1324,7 +1349,8 @@ void gl_set_point_function( GLcontext *ctx ) ctx->Driver.PointsFunc = antialiased_rgba_points; } else if (ctx->Texture.ReallyEnabled) { - if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D) { + if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D || + ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) { ctx->Driver.PointsFunc = multitextured_rgba_points; } else { diff --git a/xc/extras/Mesa/src/readpix.c b/xc/extras/Mesa/src/readpix.c index 4f4ad90a3..f2520b6af 100644 --- a/xc/extras/Mesa/src/readpix.c +++ b/xc/extras/Mesa/src/readpix.c @@ -638,7 +638,8 @@ static void read_rgba_pixels( GLcontext *ctx, return; } - if (!_mesa_is_legal_format_and_type(format, type)) { + if (!_mesa_is_legal_format_and_type(format, type) || + format == GL_INTENSITY) { gl_error(ctx, GL_INVALID_OPERATION, "glReadPixels(format or type)"); return; } diff --git a/xc/extras/Mesa/src/rect.c b/xc/extras/Mesa/src/rect.c index 4acaf6770..502498c01 100644 --- a/xc/extras/Mesa/src/rect.c +++ b/xc/extras/Mesa/src/rect.c @@ -43,13 +43,6 @@ void _mesa_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ) { - /* - * TODO: we could examine a bunch of state variables and ultimately - * call the Driver->RectFunc() function to draw a screen-aligned - * filled rectangle. Someday... - * - * KW: What happens to cull mode here? - */ GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx, "glRect"); RESET_IMMEDIATE(ctx); @@ -59,6 +52,16 @@ _mesa_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ) gl_Vertex2f( ctx, x2, y2 ); gl_Vertex2f( ctx, x1, y2 ); gl_End( ctx ); + + /* If compiling, flush these vertices so that they aren't saved + * by the normal vertex compilation methods. + */ + if (ctx->CompileFlag) + { + ctx->CompileFlag = 0; + ctx->input->maybe_transform_vb( ctx->input ); + ctx->CompileFlag = GL_TRUE; + } } diff --git a/xc/extras/Mesa/src/render_tmp.h b/xc/extras/Mesa/src/render_tmp.h index 572a06c8c..bcc60d42b 100644 --- a/xc/extras/Mesa/src/render_tmp.h +++ b/xc/extras/Mesa/src/render_tmp.h @@ -210,13 +210,15 @@ static void TAG(render_vb_poly)( struct vertex_buffer *VB, RENDER_TRI( start, j-1, j, start, 0 ); EDGEFLAG_POLY_TRI_POST( start, j-1, j, start ); } + if (VB->Flag[count] & VERT_END) { + RESET_STIPPLE; + } } else { for (j=start+2;j<count;j++) { RENDER_TRI( start, j-1, j, start, 0 ); } } - RESET_STIPPLE; POSTFIX; } diff --git a/xc/extras/Mesa/src/shade.c b/xc/extras/Mesa/src/shade.c index 97ddf37ac..5fa94258a 100644 --- a/xc/extras/Mesa/src/shade.c +++ b/xc/extras/Mesa/src/shade.c @@ -39,29 +39,39 @@ #endif +/* Lerp between adjacent values in the f(x) lookup table, giving a + * continuous function, with adequeate overall accuracy. (Though + * still pretty good compared to a straight lookup). + */ +#define GET_SHINE_TAB_ENTRY( table, dp, result ) \ +do { \ + struct gl_shine_tab *_tab = table; \ + if (dp>1.0) \ + result = pow( dp, _tab->shininess ); \ + else { \ + float f = (dp * (SHINE_TABLE_SIZE-1)); \ + int k = (int) f; \ + result = _tab->tab[k] + (f-k)*(_tab->tab[k+1]-_tab->tab[k]); \ + } \ +} while (0) -#define GET_SHINE_TAB_ENTRY( tab, dp, result ) \ -do { \ - int k = (int) (dp * SHINE_TABLE_SIZE); \ - result = tab->tab[k]; \ -} while(0) - - /* Combinatorics: - * rgba_spec/rgba/rgba_fast/ci + * rgba_spec/rgba/rgba_fast/rgba_fast_single/ci * one_side/two_side * compacted_normals/ordinary_normals * cull_mask/no_cull_mask - * - * We end up with an award-winning 32 seperate lighting functions. */ /* Table of all the shading functions. */ -gl_shade_func gl_shade_func_tab[0x20]; +gl_shade_func gl_shade_tab[0x10]; +gl_shade_func gl_shade_fast_tab[0x10]; +gl_shade_func gl_shade_fast_single_tab[0x10]; +gl_shade_func gl_shade_spec_tab[0x10]; +gl_shade_func gl_shade_ci_tab[0x10]; /* The original case where the normal for vertex[j] is normal[j], @@ -190,28 +200,32 @@ void gl_init_shade( void ) void gl_update_lighting_function( GLcontext *ctx ) { - GLuint idx; + gl_shade_func *tab; if (ctx->Visual->RGBAflag) { if (ctx->Light.NeedVertices) { if (ctx->Texture.Enabled && ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) - idx = SHADE_RGBA_SPEC; + tab = gl_shade_spec_tab; else - idx = SHADE_RGBA_VERTICES; + tab = gl_shade_tab; } - else - idx = SHADE_RGBA_NORMALS; + else { + if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev && + !ctx->Light.ColorMaterialEnabled) + tab = gl_shade_fast_single_tab; + else + tab = gl_shade_fast_tab; + } } else - idx = 0; + tab = gl_shade_ci_tab; if (ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { - idx |= SHADE_TWOSIDE; + tab += SHADE_TWOSIDE; } - - ctx->shade_func_flags = idx; + ctx->shade_func_tab = tab; } @@ -326,13 +340,7 @@ void gl_shade_rastpos( GLcontext *ctx, shininess *= .5; } - if (n_dot_h>1.0) { - spec_coef = (GLfloat) pow( n_dot_h, shininess ); - } - else { - struct gl_shine_tab *tab = ctx->ShineTable[0]; - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); - } + GET_SHINE_TAB_ENTRY( ctx->ShineTable[0], n_dot_h, spec_coef ); if (spec_coef > 1.0e-10) { ACC_SCALE_SCALAR_3V( contrib, spec_coef, diff --git a/xc/extras/Mesa/src/shade_tmp.h b/xc/extras/Mesa/src/shade_tmp.h index 189a91d4f..f6ec08cb7 100644 --- a/xc/extras/Mesa/src/shade_tmp.h +++ b/xc/extras/Mesa/src/shade_tmp.h @@ -1,9 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 3.1 + * Version: 3.3 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -38,8 +38,6 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) GLuint vstride = VB->Unprojected->stride; const GLfloat *vertex = VB->Unprojected->start; - GLuint vertex_size = VB->Unprojected->size; - GLuint nstride = VB->NormalPtr->stride; const GLfloat *normal = VB->NormalPtr->start; CONST GLfloat (*first_normal)[3] = (CONST GLfloat (*)[3]) VB->NormalPtr->start; @@ -82,8 +80,7 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) VB->Specular = VB->Spec[0]; - for ( j=0 ; j<nr ; j++,STRIDE_F(vertex,vstride),NEXT_VERTEX_NORMAL) - { + for ( j=0 ; j<nr ; j++,STRIDE_F(vertex,vstride),NEXT_VERTEX_NORMAL) { GLfloat sum[2][3], spec[2][3]; struct gl_light *light; @@ -127,12 +124,7 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) else { GLfloat d; /* distance from vertex to light */ - if (vertex_size == 2) { - SUB_2V(VP, light->Position, vertex); - VP[2] = light->Position[2]; - } else { - SUB_3V(VP, light->Position, vertex); - } + SUB_3V(VP, light->Position, vertex); d = (GLfloat) LEN_3FV( VP ); @@ -146,8 +138,7 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) light->QuadraticAttenuation)); /* spotlight attenuation */ - if (light->Flags & LIGHT_SPOT) - { + if (light->Flags & LIGHT_SPOT) { GLfloat PV_dot_dir = - DOT3(VP, light->NormDirection); if (PV_dot_dir<light->CosCutoff) { @@ -181,7 +172,8 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) side = 1; correction = -1; n_dot_VP = -n_dot_VP; - } else { + } + else { if (LIGHT_REAR(*mask)) { ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->MatAmbient[1]); } @@ -204,7 +196,6 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) if (ctx->Light.Model.LocalViewer) { GLfloat v[3]; COPY_3V(v, vertex); - if (vertex_size == 2) v[2] = 0; NORMALIZE_3FV(v); SUB_3V(VP, VP, v); /* h = VP + VPe */ h = VP; @@ -214,15 +205,15 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) h = VP; ACC_3V(h, ctx->EyeZDir); normalized = 0; - } else { + } + else { h = light->h_inf_norm; normalized = 1; } n_dot_h = correction * DOT3(normal, h); - if (n_dot_h > 0.0F) - { + if (n_dot_h > 0.0F) { GLfloat spec_coef; struct gl_shine_tab *tab = ctx->ShineTable[side]; @@ -232,11 +223,8 @@ static void TAG(shade_rgba_spec)( struct vertex_buffer *VB ) tab = ctx->ShineTable[side+2]; } - if (n_dot_h>1.0) { - spec_coef = (GLfloat) pow( n_dot_h, tab->shininess ); - } else - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); - + GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); + if (spec_coef > 1.0e-10) { spec_coef *= attenuation; ACC_SCALE_SCALAR_3V( spec[side], spec_coef, @@ -276,8 +264,6 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) GLuint vstride = VB->Unprojected->stride; const GLfloat *vertex = (GLfloat *)VB->Unprojected->start; - GLuint vertex_size = VB->Unprojected->size; - GLuint nstride = VB->NormalPtr->stride; const GLfloat *normal = VB->NormalPtr->start; CONST GLfloat (*first_normal)[3] = (CONST GLfloat (*)[3])VB->NormalPtr->start; @@ -312,8 +298,7 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) VB->Color[0] = VB->LitColor[0]; VB->Color[1] = VB->LitColor[1]; - for ( j=0 ; j<nr ; j++,STRIDE_F(vertex,vstride),NEXT_VERTEX_NORMAL) - { + for ( j=0 ; j<nr ; j++,STRIDE_F(vertex,vstride),NEXT_VERTEX_NORMAL) { GLfloat sum[2][3]; struct gl_light *light; @@ -354,13 +339,7 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) GLfloat d; /* distance from vertex to light */ - /* KW: fix me */ - if (vertex_size == 2) { - SUB_2V(VP, light->Position, vertex); - VP[2] = light->Position[2]; - } else { - SUB_3V(VP, light->Position, vertex); - } + SUB_3V(VP, light->Position, vertex); d = LEN_3FV( VP ); @@ -368,14 +347,13 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) GLfloat invd = 1.0F / d; SELF_SCALE_SCALAR_3V(VP, invd); } -/* if (light->Flags & LIGHT_ATTENUATED) */ - attenuation = 1.0F / (light->ConstantAttenuation + d * - (light->LinearAttenuation + d * - light->QuadraticAttenuation)); + + attenuation = 1.0F / (light->ConstantAttenuation + d * + (light->LinearAttenuation + d * + light->QuadraticAttenuation)); /* spotlight attenuation */ - if (light->Flags & LIGHT_SPOT) - { + if (light->Flags & LIGHT_SPOT) { GLfloat PV_dot_dir = - DOT3(VP, light->NormDirection); if (PV_dot_dir<light->CosCutoff) { @@ -410,7 +388,8 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) side = 1; correction = -1; n_dot_VP = -n_dot_VP; - } else { + } + else { if (LIGHT_REAR(*mask)) { ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->MatAmbient[1]); } @@ -426,12 +405,10 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->MatDiffuse[side]); /* specular term - cannibalize VP... */ - if (light->IsMatSpecular[side]) - { + if (light->IsMatSpecular[side]) { if (ctx->Light.Model.LocalViewer) { GLfloat v[3]; COPY_3V(v, vertex); - if (vertex_size == 2) v[2] = 0; NORMALIZE_3FV(v); SUB_3V(VP, VP, v); /* h = VP + VPe */ h = VP; @@ -441,7 +418,8 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) h = VP; ACC_3V(h, ctx->EyeZDir); normalized = 0; - } else { + } + else { h = light->h_inf_norm; normalized = 1; } @@ -459,11 +437,7 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) tab = ctx->ShineTable[side+2]; } - if (n_dot_h>1.0) { - spec_coef = pow( n_dot_h, tab->shininess ); - } else { - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); - } + GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); ACC_SCALE_SCALAR_3V( contrib, spec_coef, light->MatSpecular[side]); @@ -494,12 +468,129 @@ static void TAG(shade_rgba)( struct vertex_buffer *VB ) +/* As below, but with just a single light and no colormaterial. + */ +static void TAG(shade_fast_rgba_single)( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + GLuint nstride = VB->NormalPtr->stride; + const GLfloat *normal = VB->NormalPtr->start; + CONST GLfloat (*first_normal)[3] = + (CONST GLfloat (*)[3])VB->NormalPtr->start; + GLubyte (*Fcolor)[4] = (GLubyte (*)[4])VB->LitColor[0]->start; + GLubyte (*Bcolor)[4] = (GLubyte (*)[4])VB->LitColor[1]->start; + GLubyte *mask = VB->NormCullStart; + struct gl_light *light = ctx->Light.EnabledList.next; + GLubyte *cullmask = mask; + GLuint *flags = VB->Flag + VB->Start; + GLubyte baseubyte[2][4]; + GLuint j = 0; + struct gl_material (*new_material)[2] = VB->Material + VB->Start; + GLuint *new_material_mask = VB->MaterialMask + VB->Start; + GLfloat base[2][3]; + + (void) cullmask; + (void) first_normal; + (void) nstride; + + if ( flags[j] & VERT_MATERIAL ) + gl_update_material( ctx, new_material[j], new_material_mask[j] ); + + /* No attenuation, so incoporate MatAmbient into base color. + */ + { + COPY_3V(base[0], light->MatAmbient[0]); + ACC_3V(base[0], ctx->Light.BaseColor[0] ); + FLOAT_RGB_TO_UBYTE_RGB( baseubyte[0], base[0] ); + baseubyte[0][3] = ctx->Light.BaseAlpha[0]; + + if (NR_SIDES == 2) { + COPY_3V(base[1], light->MatAmbient[1]); + ACC_3V(base[1], ctx->Light.BaseColor[1]); + FLOAT_RGB_TO_UBYTE_RGB( baseubyte[1], base[1]); + baseubyte[1][3] = ctx->Light.BaseAlpha[1]; + } + } + + VB->ColorPtr = VB->LitColor[0]; + VB->Color[0] = VB->LitColor[0]; + VB->Color[1] = VB->LitColor[1]; + + do { + do { + if ( !CULL(*mask) ) { + GLfloat n_dot_VP = DOT3(normal, light->VP_inf_norm); + + COPY_4UBV(Fcolor[j], baseubyte[0]); + if (NR_SIDES == 2) COPY_4UBV(Bcolor[j], baseubyte[1]); + + if (n_dot_VP < 0.0F) { + if (LIGHT_REAR(*mask)) { + GLfloat n_dot_h = -DOT3(normal, light->h_inf_norm); + if (n_dot_h > 0.0F) { + GLfloat spec, sum[3]; + GET_SHINE_TAB_ENTRY( ctx->ShineTable[1], n_dot_h, spec ); + COPY_3V(sum, base[1]); + ACC_SCALE_SCALAR_3V(sum, -n_dot_VP, light->MatDiffuse[1]); + ACC_SCALE_SCALAR_3V(sum, spec, light->MatSpecular[1]); + FLOAT_RGB_TO_UBYTE_RGB(Bcolor[j], sum ); + } + } + } else { + if (LIGHT_FRONT(*mask)) { + GLfloat n_dot_h = DOT3(normal, light->h_inf_norm); + if (n_dot_h > 0.0F) { + GLfloat spec, sum[3]; + GET_SHINE_TAB_ENTRY( ctx->ShineTable[0], n_dot_h, spec ); + COPY_3V(sum, base[0]); + ACC_SCALE_SCALAR_3V(sum, n_dot_VP, light->MatDiffuse[0]); + ACC_SCALE_SCALAR_3V(sum, spec, light->MatSpecular[0]); + FLOAT_RGB_TO_UBYTE_RGB(Fcolor[j], sum ); + } + } + } + } + j++; + NEXT_NORMAL; + } while ((flags[j] & (VERT_MATERIAL|VERT_END_VB|VERT_NORM)) == VERT_NORM); + + + if (COMPACTED) { + GLuint last = j-1; + for ( ; !(flags[j] & (VERT_MATERIAL|VERT_END_VB|VERT_NORM)) ; j++ ) { + COPY_4UBV(Fcolor[j], Fcolor[last]); + if (NR_SIDES==2) + COPY_4UBV(Bcolor[j], Bcolor[last]); + } + NEXT_NORMAL; + } + + /* Have to recompute our base colors on material change. + */ + if ( flags[j] & VERT_MATERIAL ) { + gl_update_material( ctx, new_material[j], new_material_mask[j] ); + + COPY_3V(base[0], light->MatAmbient[0]); + ACC_3V(base[0], ctx->Light.BaseColor[0] ); + FLOAT_RGB_TO_UBYTE_RGB( baseubyte[0], base[0] ); + + if (NR_SIDES == 2) { + COPY_3V(base[1], light->MatAmbient[1]); + ACC_3V(base[1], ctx->Light.BaseColor[1]); + FLOAT_RGB_TO_UBYTE_RGB( baseubyte[1], base[1]); + } + } + + } while (!(flags[j] & VERT_END_VB)); +} + + /* Vertex size doesn't matter - yay! */ static void TAG(shade_fast_rgba)( struct vertex_buffer *VB ) { GLcontext *ctx = VB->ctx; - GLfloat (*base)[3] = ctx->Light.BaseColor; + GLfloat base[2][3]; GLubyte *sumA = ctx->Light.BaseAlpha; GLuint nstride = VB->NormalPtr->stride; const GLfloat *normal = VB->NormalPtr->start; @@ -515,6 +606,7 @@ static void TAG(shade_fast_rgba)( struct vertex_buffer *VB ) GLuint j = 0; struct gl_material (*new_material)[2] = VB->Material + VB->Start; GLuint *new_material_mask = VB->MaterialMask + VB->Start; + struct gl_light *light; (void) cullmask; (void) first_normal; @@ -534,19 +626,20 @@ static void TAG(shade_fast_rgba)( struct vertex_buffer *VB ) } + if ( flags[j] & VERT_MATERIAL ) + gl_update_material( ctx, new_material[j], new_material_mask[j] ); + + COPY_3V(base[0], ctx->Light.BaseColor[0]); + if (NR_SIDES == 2) COPY_3V(base[1], ctx->Light.BaseColor[1]); + interesting = cm_flags | VERT_MATERIAL | VERT_END_VB | VERT_NORM; VB->ColorPtr = VB->LitColor[0]; VB->Color[0] = VB->LitColor[0]; VB->Color[1] = VB->LitColor[1]; - if ( flags[j] & VERT_MATERIAL ) - gl_update_material( ctx, new_material[j], new_material_mask[j] ); - do { do { - if ( !CULL(*mask) ) - { - struct gl_light *light; + if ( !CULL(*mask) ) { GLfloat sum[2][3]; GLfloat spec; @@ -563,14 +656,18 @@ static void TAG(shade_fast_rgba)( struct vertex_buffer *VB ) GLfloat n_dot_h; GLint side = 0; GLfloat n_dot_VP = DOT3(normal, light->VP_inf_norm); - + + ACC_3V(sum[0], light->MatAmbient[0]); + if (NR_SIDES == 2) ACC_3V(sum[1], light->MatAmbient[1]); + if (n_dot_VP < 0.0F) { if ( !LIGHT_REAR(*mask) ) continue; ACC_SCALE_SCALAR_3V(sum[1], -n_dot_VP, light->MatDiffuse[1]); if (!light->IsMatSpecular[1]) continue; n_dot_h = -DOT3(normal, light->h_inf_norm); side = 1; - } else { + } + else { if ( !LIGHT_FRONT(*mask) ) continue; ACC_SCALE_SCALAR_3V(sum[0], n_dot_VP, light->MatDiffuse[0]); if (!light->IsMatSpecular[0]) continue; @@ -579,11 +676,7 @@ static void TAG(shade_fast_rgba)( struct vertex_buffer *VB ) if (n_dot_h > 0.0F) { struct gl_shine_tab *tab = ctx->ShineTable[side]; - if (n_dot_h > 1.0) - spec = pow( n_dot_h, tab->shininess ); - else - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec ); - + GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec ); ACC_SCALE_SCALAR_3V( sum[side], spec, light->MatSpecular[side]); } @@ -646,8 +739,6 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) GLcontext *ctx = VB->ctx; GLuint vstride = VB->Unprojected->stride; const GLfloat *vertex = (GLfloat *)VB->Unprojected->start; - GLuint vertex_size = VB->Unprojected->size; - GLuint nstride = VB->NormalPtr->stride; const GLfloat *normal = VB->NormalPtr->start; CONST GLfloat (*first_normal)[3] = (CONST GLfloat (*)[3])VB->NormalPtr->start; @@ -686,8 +777,7 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) CMcolor = (GLubyte (*)[4])VB->ColorPtr->start; } - for ( j=0 ; j<nr ; j++,STRIDE_F(vertex,vstride),NEXT_VERTEX_NORMAL) - { + for ( j=0 ; j<nr ; j++,STRIDE_F(vertex,vstride),NEXT_VERTEX_NORMAL) { GLfloat diffuse[2], specular[2]; GLuint side = 0; struct gl_light *light; @@ -724,12 +814,7 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) else { GLfloat d; /* distance from vertex to light */ - if (vertex_size == 2) { - SUB_2V(VP, light->Position, vertex); - VP[2] = light->Position[2]; - } else { - SUB_3V(VP, light->Position, vertex); - } + SUB_3V(VP, light->Position, vertex); d = LEN_3FV( VP ); if ( d > 1e-6) { @@ -742,8 +827,7 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) light->QuadraticAttenuation)); /* spotlight attenuation */ - if (light->Flags & LIGHT_SPOT) - { + if (light->Flags & LIGHT_SPOT) { GLfloat PV_dot_dir = - DOT3(VP, light->NormDirection); if (PV_dot_dir<light->CosCutoff) { continue; /* this light makes no contribution */ @@ -770,7 +854,8 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) side = 1; correction = -1; n_dot_VP = -n_dot_VP; - } else { + } + else { if (!LIGHT_FRONT(*mask)) continue; } @@ -785,7 +870,6 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) if (ctx->Light.Model.LocalViewer) { GLfloat v[3]; COPY_3V(v, vertex); - if (vertex_size == 2) v[2] = 0; NORMALIZE_3FV(v); SUB_3V(VP, VP, v); /* h = VP + VPe */ h = VP; @@ -795,7 +879,8 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) h = VP; ACC_3V(h, ctx->EyeZDir); normalized = 0; - } else { + } + else { h = light->h_inf_norm; normalized = 1; } @@ -813,18 +898,14 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) tab = ctx->ShineTable[side+2]; } - if (n_dot_h>1.0) { - spec_coef = pow( n_dot_h, tab->shininess ); - } else { - GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef); - } + GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef); + specular[side] += spec_coef * light->sli * attenuation; } } /*loop over lights*/ /* Now compute final color index */ - for (side = 0 ; side < NR_SIDES ; side++) - { + for (side = 0 ; side < NR_SIDES ; side++) { GLfloat index; struct gl_material *mat; @@ -850,22 +931,22 @@ static void TAG(shade_ci)( struct vertex_buffer *VB ) } } /*for vertex*/ - if ( flags[j] & cm_flags ) - gl_update_color_material( ctx, CMcolor[j] ); + if ( flags[j] & cm_flags ) + gl_update_color_material( ctx, CMcolor[j] ); - if ( flags[j] & VERT_MATERIAL ) - gl_update_material( ctx, new_material[j], new_material_mask[j] ); - + if ( flags[j] & VERT_MATERIAL ) + gl_update_material( ctx, new_material[j], new_material_mask[j] ); } static void TAG(init_shade_tab)( void ) { - gl_shade_func_tab[IDX|SHADE_RGBA_VERTICES] = TAG(shade_rgba); - gl_shade_func_tab[IDX|SHADE_RGBA_NORMALS] = TAG(shade_fast_rgba); - gl_shade_func_tab[IDX|SHADE_RGBA_SPEC] = TAG(shade_rgba_spec); - gl_shade_func_tab[IDX] = TAG(shade_ci); + gl_shade_tab[IDX] = TAG(shade_rgba); + gl_shade_fast_tab[IDX] = TAG(shade_fast_rgba); + gl_shade_fast_single_tab[IDX] = TAG(shade_fast_rgba_single); + gl_shade_spec_tab[IDX] = TAG(shade_rgba_spec); + gl_shade_ci_tab[IDX] = TAG(shade_ci); } diff --git a/xc/extras/Mesa/src/span.c b/xc/extras/Mesa/src/span.c index 598834047..77d2d80b5 100644 --- a/xc/extras/Mesa/src/span.c +++ b/xc/extras/Mesa/src/span.c @@ -151,6 +151,8 @@ static void multi_write_index_span( GLcontext *ctx, GLuint n, _mesa_logicop_ci_span( ctx, n, x, y, indexTmp, mask ); } if (ctx->Color.SWmasking) { + if (ctx->Color.IndexMask == 0) + break; _mesa_mask_index_span( ctx, n, x, y, indexTmp ); } (*ctx->Driver.WriteCI32Span)( ctx, n, x, y, indexTmp, mask ); @@ -241,6 +243,8 @@ void gl_write_index_span( GLcontext *ctx, _mesa_logicop_ci_span( ctx, n, x, y, index, mask ); } if (ctx->Color.SWmasking) { + if (ctx->Color.IndexMask == 0) + return; _mesa_mask_index_span( ctx, n, x, y, index ); } @@ -315,10 +319,6 @@ void gl_write_monoindex_span( GLcontext *ctx, _mesa_logicop_ci_span( ctx, n, x, y, indexes, mask ); } - if (ctx->Color.SWmasking) { - _mesa_mask_index_span( ctx, n, x, y, indexes ); - } - if (ctx->RasterMask & MULTI_DRAW_BIT) { /* draw to zero or two or more buffers */ multi_write_index_span( ctx, n, x, y, indexes, mask ); @@ -329,6 +329,8 @@ void gl_write_monoindex_span( GLcontext *ctx, _mesa_logicop_ci_span( ctx, n, x, y, indexes, mask ); } if (ctx->Color.SWmasking) { + if (ctx->Color.IndexMask == 0) + return; _mesa_mask_index_span( ctx, n, x, y, indexes ); } (*ctx->Driver.WriteCI32Span)( ctx, n, x, y, indexes, mask ); @@ -399,6 +401,8 @@ static void multi_write_rgba_span( GLcontext *ctx, GLuint n, _mesa_blend_span( ctx, n, x, y, rgbaTmp, mask ); } if (ctx->Color.SWmasking) { + if (*((GLuint *) ctx->Color.ColorMask) == 0) + break; _mesa_mask_rgba_span( ctx, n, x, y, rgbaTmp ); } @@ -499,9 +503,7 @@ void gl_write_rgba_span( GLcontext *ctx, ctx->OcclusionResult = GL_TRUE; if (ctx->RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, - (const GLubyte (*)[4]) rgba, - write_all ? Null : mask ); + multi_write_rgba_span( ctx, n, x, y, (const GLubyte (*)[4]) rgba, mask ); } else { /* normal: write to exactly one buffer */ @@ -515,6 +517,8 @@ void gl_write_rgba_span( GLcontext *ctx, /* Color component masking */ if (ctx->Color.SWmasking) { + if (*((GLuint *) ctx->Color.ColorMask) == 0) + return; _mesa_mask_rgba_span( ctx, n, x, y, rgba ); } @@ -616,8 +620,8 @@ void gl_write_monocolor_span( GLcontext *ctx, return; } - if (ctx->Color.BlendEnabled || ctx->Color.SWLogicOpEnabled - || ctx->Color.SWmasking) { + if (ctx->Color.SWLogicOpEnabled || ctx->Color.SWmasking || + (ctx->RasterMask & (BLEND_BIT | FOG_BIT))) { /* assign same color to each pixel */ for (i=0;i<n;i++) { if (mask[i]) { @@ -625,9 +629,15 @@ void gl_write_monocolor_span( GLcontext *ctx, } } + /* Per-pixel fog */ + if (ctx->Fog.Enabled && + (primitive==GL_BITMAP || ctx->FogMode==FOG_FRAGMENT)) { + _mesa_fog_rgba_pixels( ctx, n, z, rgba ); + } + if (ctx->RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, (const GLubyte (*)[4]) rgba, - mask ); + multi_write_rgba_span( ctx, n, x, y, + (const GLubyte (*)[4]) rgba, mask ); } else { /* normal: write to exactly one buffer */ @@ -640,6 +650,8 @@ void gl_write_monocolor_span( GLcontext *ctx, /* Color component masking */ if (ctx->Color.SWmasking) { + if (*((GLuint *) ctx->Color.ColorMask) == 0) + return; _mesa_mask_rgba_span( ctx, n, x, y, rgba ); } @@ -667,8 +679,7 @@ void gl_write_monocolor_span( GLcontext *ctx, } } multi_write_rgba_span( ctx, n, x, y, - (const GLubyte (*)[4]) rgba, - mask ); + (const GLubyte (*)[4]) rgba, mask ); } else { (*ctx->Driver.WriteMonoRGBASpan)( ctx, n, x, y, mask ); @@ -748,7 +759,7 @@ void gl_write_texture_span( GLcontext *ctx, /* Texture */ ASSERT(ctx->Texture.ReallyEnabled); - gl_texture_pixels( ctx, 0, n, s, t, u, lambda, rgba ); + gl_texture_pixels( ctx, 0, n, s, t, u, lambda, rgba, rgba ); /* Add base and specular colors */ if (spec && ctx->Light.Enabled @@ -804,8 +815,7 @@ void gl_write_texture_span( GLcontext *ctx, ctx->OcclusionResult = GL_TRUE; if (ctx->RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, (const GLubyte (*)[4])rgba, - write_all ? Null : mask ); + multi_write_rgba_span( ctx, n, x, y, (const GLubyte (*)[4]) rgba, mask ); } else { /* normal: write to exactly one buffer */ @@ -816,6 +826,8 @@ void gl_write_texture_span( GLcontext *ctx, _mesa_blend_span( ctx, n, x, y, rgba, mask ); } if (ctx->Color.SWmasking) { + if (*((GLuint *) ctx->Color.ColorMask) == 0) + return; _mesa_mask_rgba_span( ctx, n, x, y, rgba ); } @@ -864,7 +876,8 @@ gl_write_multitexture_span( GLcontext *ctx, GLuint texUnits, } - if (primitive==GL_BITMAP || (ctx->RasterMask & MULTI_DRAW_BIT)) { + if (primitive==GL_BITMAP || (ctx->RasterMask & MULTI_DRAW_BIT) + || texUnits > 1) { /* must make a copy of the colors since they may be modified */ MEMCPY(rgbaBackup, rgbaIn, 4 * n * sizeof(GLubyte)); rgba = rgbaBackup; @@ -876,9 +889,8 @@ gl_write_multitexture_span( GLcontext *ctx, GLuint texUnits, /* Texture */ ASSERT(ctx->Texture.ReallyEnabled); ASSERT(texUnits <= MAX_TEXTURE_UNITS); - for (i=0;i<texUnits;i++) { - gl_texture_pixels( ctx, i, n, s[i], t[i], u[i], lambda[i], rgba ); - } + for (i=0;i<texUnits;i++) + gl_texture_pixels( ctx, i, n, s[i], t[i], u[i], lambda[i], rgbaIn, rgba ); /* Add base and specular colors */ if (spec && ctx->Light.Enabled @@ -934,8 +946,7 @@ gl_write_multitexture_span( GLcontext *ctx, GLuint texUnits, ctx->OcclusionResult = GL_TRUE; if (ctx->RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, (const GLubyte (*)[4]) rgba, - write_all ? Null : mask ); + multi_write_rgba_span( ctx, n, x, y, (const GLubyte (*)[4]) rgba, mask ); } else { /* normal: write to exactly one buffer */ @@ -947,6 +958,8 @@ gl_write_multitexture_span( GLcontext *ctx, GLuint texUnits, _mesa_blend_span( ctx, n, x, y, rgba, mask ); } if (ctx->Color.SWmasking) { + if (*((GLuint *) ctx->Color.ColorMask) == 0) + return; _mesa_mask_rgba_span( ctx, n, x, y, rgba ); } diff --git a/xc/extras/Mesa/src/stages.c b/xc/extras/Mesa/src/stages.c index 43aff42c2..8741b69cf 100644 --- a/xc/extras/Mesa/src/stages.c +++ b/xc/extras/Mesa/src/stages.c @@ -185,11 +185,18 @@ static void clean_texcoord( struct vertex_buffer *VB, GLuint i ) tc->stride = 4 * sizeof(GLfloat); } +static void clean_unprojected( struct vertex_buffer *VB ) +{ + (void) Transform( &VB->Eye, + &gl_identity_mat, + VB->Unprojected, + 0, + 0); + VB->Unprojected = &VB->Eye; +} static void clean_clip( struct vertex_buffer *VB ) { -/* printf("clean clip, stride %d, not writable\n", VB->ClipPtr->stride); */ - (void) Transform( &VB->Clip, &gl_identity_mat, VB->ClipPtr, @@ -329,7 +336,11 @@ static void do_vertex_pipeline( struct vertex_buffer *VB ) } if (VB->ClipAndMask) { + if (MESA_VERBOSE&VERBOSE_CULL) + fprintf(stderr, "Culled in clip\n"); + VB->Culled = 1; + gl_dont_cull_vb( VB ); gl_update_materials(VB); return; } @@ -344,6 +355,7 @@ static void do_vertex_pipeline( struct vertex_buffer *VB ) if (MESA_VERBOSE&VERBOSE_CULL) fprintf(stderr, "Culled in userclip\n"); + gl_dont_cull_vb( VB ); gl_update_materials(VB); return; } @@ -436,12 +448,23 @@ static void do_normal_transform( struct vertex_buffer *VB ) static void do_lighting( struct vertex_buffer *VB ) { - GLubyte flags = (GLubyte) (VB->CullMode & (CULL_MASK_ACTIVE|COMPACTED_NORMALS)); + GLubyte flags = (GLubyte) (VB->CullMode & + (CULL_MASK_ACTIVE|COMPACTED_NORMALS)); if ((flags&CULL_MASK_ACTIVE) && !VB->NormCullStart) gl_make_normal_cullmask( VB ); - gl_shade_func_tab[VB->ctx->shade_func_flags | flags]( VB ); + /* Make sure we can talk about elements 0..2 in the vector we are + * lighting. + */ + if (VB->Unprojected->size == 2) { + if (VB->Unprojected->flags & VEC_WRITABLE) + gl_vector4f_clean_elem(VB->Unprojected, VB->Count, 2); + else + clean_unprojected( VB ); + } + + VB->ctx->shade_func_tab[flags]( VB ); } diff --git a/xc/extras/Mesa/src/state.c b/xc/extras/Mesa/src/state.c index ccf0d9091..3ae304d8d 100644 --- a/xc/extras/Mesa/src/state.c +++ b/xc/extras/Mesa/src/state.c @@ -845,17 +845,15 @@ static void update_rasterflags( GLcontext *ctx ) ctx->RasterMask |= MULTI_DRAW_BIT; ctx->TriangleCaps |= DD_MULTIDRAW; } - else if (ctx->Visual->RGBAflag && ctx->Color.ColorMask==0) { + else if (ctx->Visual->RGBAflag && *((GLuint *) ctx->Color.ColorMask) == 0) { /* all RGBA channels disabled */ ctx->RasterMask |= MULTI_DRAW_BIT; ctx->TriangleCaps |= DD_MULTIDRAW; - ctx->Color.DrawDestMask = 0; } else if (!ctx->Visual->RGBAflag && ctx->Color.IndexMask==0) { /* all color index bits disabled */ ctx->RasterMask |= MULTI_DRAW_BIT; ctx->TriangleCaps |= DD_MULTIDRAW; - ctx->Color.DrawDestMask = 0; } } @@ -1062,11 +1060,6 @@ void gl_update_state( GLcontext *ctx ) ctx->Polygon.OffsetLine || ctx->Polygon.OffsetFill) ctx->TriangleCaps |= DD_TRI_OFFSET; - - /* reset Z offsets now */ - ctx->PointZoffset = 0.0; - ctx->LineZoffset = 0.0; - ctx->PolygonZoffset = 0.0; } } @@ -1183,14 +1176,13 @@ void gl_update_state( GLcontext *ctx ) ctx->NeedEyeNormals = GL_FALSE; if (ctx->Light.Enabled) { - if (ctx->Light.Flags & LIGHT_POSITIONAL) { - /* Need length for attenuation */ - if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING)) - ctx->NeedEyeCoords = GL_TRUE; - } else if (ctx->Light.NeedVertices) { - /* Need angle for spot calculations */ - if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_ANGLE_PRESERVING)) - ctx->NeedEyeCoords = GL_TRUE; + if ((ctx->Light.Flags & LIGHT_POSITIONAL) || + ctx->Light.NeedVertices || + !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING)) { + /* Need length for attenuation or need angle for spotlights + * or non-uniform scale matrix + */ + ctx->NeedEyeCoords = GL_TRUE; } ctx->NeedEyeNormals = ctx->NeedEyeCoords; } diff --git a/xc/extras/Mesa/src/texgen_tmp.h b/xc/extras/Mesa/src/texgen_tmp.h index 0324493cf..c1fa50816 100644 --- a/xc/extras/Mesa/src/texgen_tmp.h +++ b/xc/extras/Mesa/src/texgen_tmp.h @@ -290,10 +290,10 @@ static void TAG(texgen_sphere_map)( struct vertex_buffer *VB, GLfloat (*f)[3], *m; if (!VB->tmp_f) - VB->tmp_f = (GLfloat (*)[3])malloc(VB->Size * sizeof(GLfloat) * 3); + VB->tmp_f = (GLfloat (*)[3]) MALLOC(VB->Size * sizeof(GLfloat) * 3); if (!VB->tmp_m) - VB->tmp_m = (GLfloat *)malloc(VB->Size * sizeof(GLfloat)); + VB->tmp_m = (GLfloat *) MALLOC(VB->Size * sizeof(GLfloat)); f = VB->tmp_f; m = VB->tmp_m; @@ -349,10 +349,10 @@ static void TAG(texgen)( struct vertex_buffer *VB, GLuint textureUnit ) LOCAL_VARS; if (!VB->tmp_f) - VB->tmp_f = (GLfloat (*)[3])malloc(VB->Size * sizeof(GLfloat) * 3); + VB->tmp_f = (GLfloat (*)[3]) MALLOC(VB->Size * sizeof(GLfloat) * 3); if (!VB->tmp_m) - VB->tmp_m = (GLfloat *)malloc(VB->Size * sizeof(GLfloat)); + VB->tmp_m = (GLfloat *) MALLOC(VB->Size * sizeof(GLfloat)); f = VB->tmp_f; m = VB->tmp_m; diff --git a/xc/extras/Mesa/src/teximage.c b/xc/extras/Mesa/src/teximage.c index 98f62c816..05520e4eb 100644 --- a/xc/extras/Mesa/src/teximage.c +++ b/xc/extras/Mesa/src/teximage.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -139,21 +139,23 @@ logbase2( int n ) GLint _mesa_base_tex_format( GLcontext *ctx, GLint format ) { + /* + * Ask the driver for the base format, if it doesn't + * know, it will return -1; + */ + if (ctx->Driver.BaseCompressedTexFormat) { + GLint ifmt = (*ctx->Driver.BaseCompressedTexFormat)(ctx, format); + if (ifmt >= 0) { + return ifmt; + } + } switch (format) { - case GL_COMPRESSED_ALPHA_ARB: - if (ctx && !ctx->Extensions.HaveTextureCompression) - return -1; - /* fall-through */ case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8: case GL_ALPHA12: case GL_ALPHA16: return GL_ALPHA; - case GL_COMPRESSED_LUMINANCE_ARB: - if (ctx && !ctx->Extensions.HaveTextureCompression) - return -1; - /* fall-through */ case 1: case GL_LUMINANCE: case GL_LUMINANCE4: @@ -161,10 +163,6 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format ) case GL_LUMINANCE12: case GL_LUMINANCE16: return GL_LUMINANCE; - case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: - if (ctx && !ctx->Extensions.HaveTextureCompression) - return -1; - /* fall-through */ case 2: case GL_LUMINANCE_ALPHA: case GL_LUMINANCE4_ALPHA4: @@ -174,31 +172,12 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format ) case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: return GL_LUMINANCE_ALPHA; - case GL_COMPRESSED_INTENSITY_ARB: - if (ctx && !ctx->Extensions.HaveTextureCompression) - return -1; - /* fall-through */ case GL_INTENSITY: case GL_INTENSITY4: case GL_INTENSITY8: case GL_INTENSITY12: case GL_INTENSITY16: return GL_INTENSITY; - case GL_COMPRESSED_RGB_ARB: - if (ctx && ctx->Extensions.HaveTextureCompression) - return GL_RGB; - else - return -1; - case GL_COMPRESSED_RGB_FXT1_3DFX: - if (ctx && ctx->Extensions.HaveTextureCompressionFXT1) - return GL_RGB; - else - return -1; - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - if (ctx && ctx->Extensions.HaveTextureCompressionS3TC) - return GL_RGB; - else - return -1; case 3: case GL_RGB: case GL_R3_G3_B2: @@ -209,23 +188,6 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format ) case GL_RGB12: case GL_RGB16: return GL_RGB; - case GL_COMPRESSED_RGBA_ARB: - if (ctx && ctx->Extensions.HaveTextureCompression) - return GL_RGBA; - else - return -1; - case GL_COMPRESSED_RGBA_FXT1_3DFX: - if (ctx && ctx->Extensions.HaveTextureCompressionFXT1) - return GL_RGBA; - else - return -1; - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - if (ctx && ctx->Extensions.HaveTextureCompressionS3TC) - return GL_RGBA; - else - return -1; case 4: case GL_RGBA: case GL_RGBA2: @@ -328,25 +290,12 @@ components_in_intformat( GLint format ) * otherwise. */ static GLboolean -is_compressed_format(GLenum internalFormat) +is_compressed_format(GLcontext *ctx, GLenum internalFormat) { - switch (internalFormat) { - case GL_COMPRESSED_ALPHA_ARB: - case GL_COMPRESSED_LUMINANCE_ARB: - case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: - case GL_COMPRESSED_INTENSITY_ARB: - case GL_COMPRESSED_RGB_ARB: - case GL_COMPRESSED_RGBA_ARB: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_RGB_FXT1_3DFX: - case GL_COMPRESSED_RGBA_FXT1_3DFX: - return GL_TRUE; - default: - return GL_FALSE; - } + if (ctx->Driver.IsCompressedFormat) { + return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat); + } + return GL_FALSE; } @@ -511,13 +460,14 @@ _mesa_alloc_texture_image( void ) * Initialize most fields of a gl_texture_image struct. */ static void -init_texture_image( struct gl_texture_image *img, +init_texture_image( GLcontext *ctx, + struct gl_texture_image *img, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum internalFormat ) { ASSERT(img); ASSERT(!img->Data); - img->Format = (GLenum) _mesa_base_tex_format(NULL, internalFormat); + img->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat); set_teximage_component_sizes( img ); img->IntFormat = (GLenum) internalFormat; img->Border = border; @@ -537,7 +487,7 @@ init_texture_image( struct gl_texture_image *img, img->Height2 = 1 << img->HeightLog2; img->Depth2 = 1 << img->DepthLog2; img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); - img->IsCompressed = is_compressed_format(internalFormat); + img->IsCompressed = is_compressed_format(ctx, internalFormat); } @@ -556,13 +506,26 @@ _mesa_free_texture_image( struct gl_texture_image *teximage ) /* * Return number of bytes of storage needed to store a compressed texture - * image. + * image. Only the driver knows for sure. If the driver can't help us, + * we must return 0. */ GLuint -_mesa_compressed_image_size(GLenum internalFormat, - GLint width, GLint height, GLint depth) +_mesa_compressed_image_size(GLcontext *ctx, + GLenum internalFormat, + GLint numDimensions, + GLint width, + GLint height, + GLint depth) { - return 0; + if (ctx->Driver.CompressedImageSize) { + return (*ctx->Driver.CompressedImageSize)(ctx, internalFormat, + numDimensions, + width, height, depth); + } + else { + /* Shouldn't this be an internal error of some sort? */ + return 0; + } } @@ -878,6 +841,40 @@ make_null_texture( struct gl_texture_image *texImage ) /* + * This is called when a proxy texture test fails, we set all the + * image members (except DriverData) to zero. + */ +static void +clear_proxy_teximage(struct gl_texture_image *img) +{ + ASSERT(img); + img->Format = 0; + img->IntFormat = 0; + img->RedBits = 0; + img->GreenBits = 0; + img->BlueBits = 0; + img->AlphaBits = 0; + img->IntensityBits = 0; + img->LuminanceBits = 0; + img->IndexBits = 0; + img->Border = 0; + img->Width = 0; + img->Height = 0; + img->Depth = 0; + img->Width2 = 0; + img->Height2 = 0; + img->Depth2 = 0; + img->WidthLog2 = 0; + img->HeightLog2 = 0; + img->DepthLog2 = 0; + img->Data = NULL; + img->IsCompressed = 0; + img->CompressedSize = 0; +} + + + +/* * Test glTexImage[123]D() parameters for errors. * Input: * dimensions - must be 1 or 2 or 3 @@ -999,7 +996,7 @@ texture_error_check( GLcontext *ctx, GLenum target, return GL_TRUE; } - if (!is_compressed_format(internalFormat)) { + if (!is_compressed_format(ctx, internalFormat)) { if (!_mesa_is_legal_format_and_type( format, type )) { /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. @@ -1125,7 +1122,7 @@ subtexture_error_check( GLcontext *ctx, GLuint dimensions, } } - if (!is_compressed_format(destTex->IntFormat)) { + if (!is_compressed_format(ctx, destTex->IntFormat)) { if (!_mesa_is_legal_format_and_type(format, type)) { char message[100]; sprintf(message, "glTexSubImage%dD(format or type)", dimensions); @@ -1344,6 +1341,105 @@ copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, /* + * Turn generic compressed formats into specific compressed format. + * Some of the compressed formats we don't support, so we + * fall back to the uncompressed format. (See issue 15 of + * the GL_ARB_texture_compression specification.) + */ +static GLint +get_specific_compressed_tex_format(GLcontext *ctx, + GLint ifmt, GLint numDimensions) +{ + char message[100]; + GLint internalFormat = ifmt; + + if (ctx->Extensions.HaveTextureCompression + && ctx->Driver.SpecificCompressedTexFormat) { + /* + * First, ask the driver for the specific format. + */ + switch (internalFormat) { + case GL_COMPRESSED_ALPHA_ARB: + case GL_COMPRESSED_LUMINANCE_ARB: + case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: + case GL_COMPRESSED_INTENSITY_ARB: + case GL_COMPRESSED_RGB_ARB: + case GL_COMPRESSED_RGBA_ARB: + internalFormat = (*ctx->Driver.SpecificCompressedTexFormat) + (ctx, internalFormat, numDimensions); + /* XXX shouldn't we return now? */ + break; + default: + /* silence compiler warnings */ + ; + } + } + + /* + * Now, convert any generic format left to an uncompressed + * specific format. If the driver does not support compression + * of the format, we must drop back to the uncompressed format. + * See issue 15 of the GL_ARB_texture_compression specification. + */ + switch (internalFormat) { + case GL_COMPRESSED_ALPHA_ARB: + if (ctx && !ctx->Extensions.HaveTextureCompression) { + sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); + gl_error(ctx, GL_INVALID_VALUE, message); + return -1; + } + internalFormat = GL_ALPHA; + break; + case GL_COMPRESSED_LUMINANCE_ARB: + if (ctx && !ctx->Extensions.HaveTextureCompression) { + sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); + gl_error(ctx, GL_INVALID_VALUE, message); + return -1; + } + internalFormat = GL_LUMINANCE; + break; + case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: + if (ctx && !ctx->Extensions.HaveTextureCompression) { + sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); + gl_error(ctx, GL_INVALID_VALUE, message); + return -1; + } + internalFormat = GL_LUMINANCE_ALPHA; + break; + case GL_COMPRESSED_INTENSITY_ARB: + if (ctx && !ctx->Extensions.HaveTextureCompression) { + sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); + gl_error(ctx, GL_INVALID_VALUE, message); + return -1; + } + internalFormat = GL_INTENSITY; + break; + case GL_COMPRESSED_RGB_ARB: + if (ctx && !ctx->Extensions.HaveTextureCompression) { + sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); + gl_error(ctx, GL_INVALID_VALUE, message); + return -1; + } + internalFormat = GL_RGB; + break; + case GL_COMPRESSED_RGBA_ARB: + if (ctx && !ctx->Extensions.HaveTextureCompression) { + sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); + gl_error(ctx, GL_INVALID_VALUE, message); + return -1; + } + internalFormat = GL_RGBA; + break; + default: + /* silence compiler warning */ + ; + } + return internalFormat; +} + + + +/* * Called from the API. Note that width includes the border. */ void @@ -1358,6 +1454,19 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLint ifmt; + + ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 1); + if (ifmt < 0) { + /* + * The error here is that we were sent a generic compressed + * format, but the extension is not supported. + */ + return; + } + else { + internalFormat = ifmt; + } if (texture_error_check(ctx, target, level, internalFormat, format, type, 1, width, 1, 1, border)) { @@ -1382,7 +1491,7 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, } /* setup the teximage struct's fields */ - init_texture_image(texImage, width, 1, 1, border, internalFormat); + init_texture_image(ctx, texImage, width, 1, 1, border, internalFormat); /* process the texture image */ if (pixels) { @@ -1433,13 +1542,12 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, format, type, 1, width, 1, 1, border)) { /* if error, clear all proxy texture image parameters */ if (level>=0 && level<ctx->Const.MaxTextureLevels) { - MEMSET( ctx->Texture.Proxy1D->Image[level], 0, - sizeof(struct gl_texture_image) ); + clear_proxy_teximage(ctx->Texture.Proxy1D->Image[level]); } } else { /* if no error, update proxy texture image parameters */ - init_texture_image(ctx->Texture.Proxy1D->Image[level], + init_texture_image(ctx, ctx->Texture.Proxy1D->Image[level], width, 1, 1, border, internalFormat); } } @@ -1466,6 +1574,19 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLint ifmt; + + ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 2); + if (ifmt < 0) { + /* + * The error here is that we were sent a generic compressed + * format, but the extension is not supported. + */ + return; + } + else { + internalFormat = ifmt; + } if (texture_error_check(ctx, target, level, internalFormat, format, type, 2, width, height, 1, border)) { @@ -1491,7 +1612,8 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, } /* setup the teximage struct's fields */ - init_texture_image(texImage, width, height, 1, border, internalFormat); + init_texture_image(ctx, texImage, width, height, + 1, border, internalFormat); /* process the texture image */ if (pixels) { @@ -1551,13 +1673,13 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, format, type, 2, width, height, 1, border)) { /* if error, clear all proxy texture image parameters */ if (level>=0 && level<ctx->Const.MaxTextureLevels) { - MEMSET( ctx->Texture.Proxy2D->Image[level], 0, - sizeof(struct gl_texture_image) ); + clear_proxy_teximage(ctx->Texture.Proxy2D->Image[level]); } } else { /* if no error, update proxy texture image parameters */ - init_texture_image(ctx->Texture.Proxy2D->Image[level], + init_texture_image(ctx, + ctx->Texture.Proxy2D->Image[level], width, height, 1, border, internalFormat); } } @@ -1586,6 +1708,20 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLint ifmt; + + ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 3); + if (ifmt < 0) { + /* + * The error here is that we were sent a generic compressed + * format, but the extension is not supported. + */ + return; + } + else { + internalFormat = ifmt; + } + if (texture_error_check(ctx, target, level, internalFormat, format, type, 3, width, height, depth, border)) { return; /* error in texture image was detected */ @@ -1609,7 +1745,7 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, } /* setup the teximage struct's fields */ - init_texture_image(texImage, width, height, depth, + init_texture_image(ctx, texImage, width, height, depth, border, internalFormat); /* process the texture image */ @@ -1661,13 +1797,12 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, format, type, 3, width, height, depth, border)) { /* if error, clear all proxy texture image parameters */ if (level>=0 && level<ctx->Const.MaxTextureLevels) { - MEMSET( ctx->Texture.Proxy3D->Image[level], 0, - sizeof(struct gl_texture_image) ); + clear_proxy_teximage(ctx->Texture.Proxy3D->Image[level]); } } else { /* if no error, update proxy texture image parameters */ - init_texture_image(ctx->Texture.Proxy3D->Image[level], + init_texture_image(ctx, ctx->Texture.Proxy3D->Image[level], width, height, depth, border, internalFormat); } } @@ -2511,10 +2646,25 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level, GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage1DARB"); + switch (internalFormat) { + case GL_COMPRESSED_ALPHA_ARB: + case GL_COMPRESSED_LUMINANCE_ARB: + case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: + case GL_COMPRESSED_INTENSITY_ARB: + case GL_COMPRESSED_RGB_ARB: + case GL_COMPRESSED_RGBA_ARB: + gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); + return; + default: + /* silence compiler warning */ + ; + } + if (target == GL_TEXTURE_1D) { struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLsizei computedImageSize; if (texture_error_check(ctx, target, level, internalFormat, GL_NONE, GL_NONE, 1, width, 1, 1, border)) { @@ -2539,23 +2689,32 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level, } /* setup the teximage struct's fields */ - init_texture_image(texImage, width, 1, 1, border, internalFormat); + init_texture_image(ctx, texImage, width, 1, 1, + border, internalFormat); /* process the texture image */ if (data) { GLboolean retain = GL_TRUE; GLboolean success = GL_FALSE; if (ctx->Driver.CompressedTexImage1D) { - success = (*ctx->Driver.CompressedTexImage1D)( ctx, target, level, - data, texObj, texImage, &retain); + success = (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, + imageSize, data, texObj, texImage, &retain); } if (retain || !success) { /* make internal copy of the texture image */ - GLuint imageSize = _mesa_compressed_image_size(internalFormat, - width, 1, 1); - texImage->Data = MALLOC(imageSize); + computedImageSize = _mesa_compressed_image_size(ctx, + internalFormat, + 1, /* num dims */ + width, + 1, /* height */ + 1); /* depth */ + if (computedImageSize != imageSize) { + gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage1DARB(imageSize)"); + return; + } + texImage->Data = MALLOC(computedImageSize); if (texImage->Data) { - MEMCPY(texImage->Data, data, imageSize); + MEMCPY(texImage->Data, data, computedImageSize); } } if (!retain && texImage->Data) { @@ -2567,8 +2726,9 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level, make_null_texture(texImage); if (ctx->Driver.CompressedTexImage1D) { GLboolean retain; - (*ctx->Driver.CompressedTexImage1D)( ctx, target, level, - texImage->Data, texObj, texImage, &retain); + (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 0, + texImage->Data, texObj, + texImage, &retain); } } @@ -2582,13 +2742,12 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level, GL_NONE, GL_NONE, 1, width, 1, 1, border)) { /* if error, clear all proxy texture image parameters */ if (level>=0 && level<ctx->Const.MaxTextureLevels) { - MEMSET( ctx->Texture.Proxy1D->Image[level], 0, - sizeof(struct gl_texture_image) ); + clear_proxy_teximage(ctx->Texture.Proxy1D->Image[level]); } } else { /* if no error, update proxy texture image parameters */ - init_texture_image(ctx->Texture.Proxy1D->Image[level], + init_texture_image(ctx, ctx->Texture.Proxy1D->Image[level], width, 1, 1, border, internalFormat); } } @@ -2608,6 +2767,20 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage2DARB"); + switch (internalFormat) { + case GL_COMPRESSED_ALPHA_ARB: + case GL_COMPRESSED_LUMINANCE_ARB: + case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: + case GL_COMPRESSED_INTENSITY_ARB: + case GL_COMPRESSED_RGB_ARB: + case GL_COMPRESSED_RGBA_ARB: + gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); + return; + default: + /* silence compiler warning */ + ; + } + if (target==GL_TEXTURE_2D || (ctx->Extensions.HaveTextureCubeMap && target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && @@ -2615,6 +2788,7 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLsizei computedImageSize; if (texture_error_check(ctx, target, level, internalFormat, GL_NONE, GL_NONE, 1, width, height, 1, border)) { @@ -2639,23 +2813,37 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, } /* setup the teximage struct's fields */ - init_texture_image(texImage, width, height, 1, border, internalFormat); + init_texture_image(ctx, texImage, width, height, 1, border, internalFormat); /* process the texture image */ if (data) { GLboolean retain = GL_TRUE; GLboolean success = GL_FALSE; if (ctx->Driver.CompressedTexImage2D) { - success = (*ctx->Driver.CompressedTexImage2D)( ctx, target, level, - data, texObj, texImage, &retain); + success = (*ctx->Driver.CompressedTexImage2D)( ctx, + target, + level, + imageSize, + data, + texObj, + texImage, + &retain); } if (retain || !success) { /* make internal copy of the texture image */ - GLuint imageSize = _mesa_compressed_image_size(internalFormat, - width, height, 1); - texImage->Data = MALLOC(imageSize); + computedImageSize = _mesa_compressed_image_size(ctx, + internalFormat, + 2, /* num dims */ + width, + height, + 1); /* depth */ + if (computedImageSize != imageSize) { + gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage2DARB(imageSize)"); + return; + } + texImage->Data = MALLOC(computedImageSize); if (texImage->Data) { - MEMCPY(texImage->Data, data, imageSize); + MEMCPY(texImage->Data, data, computedImageSize); } } if (!retain && texImage->Data) { @@ -2667,8 +2855,9 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, make_null_texture(texImage); if (ctx->Driver.CompressedTexImage2D) { GLboolean retain; - (*ctx->Driver.CompressedTexImage2D)( ctx, target, level, - texImage->Data, texObj, texImage, &retain); + (*ctx->Driver.CompressedTexImage2D)( ctx, target, level, 0, + texImage->Data, texObj, + texImage, &retain); } } @@ -2682,13 +2871,12 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, GL_NONE, GL_NONE, 1, width, 1, 1, border)) { /* if error, clear all proxy texture image parameters */ if (level>=0 && level<ctx->Const.MaxTextureLevels) { - MEMSET( ctx->Texture.Proxy2D->Image[level], 0, - sizeof(struct gl_texture_image) ); + clear_proxy_teximage(ctx->Texture.Proxy2D->Image[level]); } } else { /* if no error, update proxy texture image parameters */ - init_texture_image(ctx->Texture.Proxy2D->Image[level], + init_texture_image(ctx, ctx->Texture.Proxy2D->Image[level], width, 1, 1, border, internalFormat); } } @@ -2708,10 +2896,25 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level, GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage3DARB"); + switch (internalFormat) { + case GL_COMPRESSED_ALPHA_ARB: + case GL_COMPRESSED_LUMINANCE_ARB: + case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: + case GL_COMPRESSED_INTENSITY_ARB: + case GL_COMPRESSED_RGB_ARB: + case GL_COMPRESSED_RGBA_ARB: + gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); + return; + default: + /* silence compiler warning */ + ; + } + if (target == GL_TEXTURE_3D) { struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLsizei computedImageSize; if (texture_error_check(ctx, target, level, internalFormat, GL_NONE, GL_NONE, 1, width, height, depth, border)) { @@ -2736,23 +2939,34 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level, } /* setup the teximage struct's fields */ - init_texture_image(texImage, width, height, depth, border, internalFormat); + init_texture_image(ctx, texImage, width, height, depth, + border, internalFormat); /* process the texture image */ if (data) { GLboolean retain = GL_TRUE; GLboolean success = GL_FALSE; if (ctx->Driver.CompressedTexImage3D) { - success = (*ctx->Driver.CompressedTexImage3D)( ctx, target, level, - data, texObj, texImage, &retain); + success = (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, + imageSize, data, + texObj, texImage, + &retain); } if (retain || !success) { /* make internal copy of the texture image */ - GLuint imageSize = _mesa_compressed_image_size(internalFormat, - width, height, depth); - texImage->Data = MALLOC(imageSize); + computedImageSize = _mesa_compressed_image_size(ctx, + internalFormat, + 3, /* num dims */ + width, + height, + depth); + if (computedImageSize != imageSize) { + gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage3DARB(imageSize)"); + return; + } + texImage->Data = MALLOC(computedImageSize); if (texImage->Data) { - MEMCPY(texImage->Data, data, imageSize); + MEMCPY(texImage->Data, data, computedImageSize); } } if (!retain && texImage->Data) { @@ -2764,8 +2978,9 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level, make_null_texture(texImage); if (ctx->Driver.CompressedTexImage3D) { GLboolean retain; - (*ctx->Driver.CompressedTexImage3D)( ctx, target, level, - texImage->Data, texObj, texImage, &retain); + (*ctx->Driver.CompressedTexImage3D)( ctx, target, level, 0, + texImage->Data, texObj, + texImage, &retain); } } @@ -2779,13 +2994,12 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level, GL_NONE, GL_NONE, 1, width, height, depth, border)) { /* if error, clear all proxy texture image parameters */ if (level>=0 && level<ctx->Const.MaxTextureLevels) { - MEMSET( ctx->Texture.Proxy3D->Image[level], 0, - sizeof(struct gl_texture_image) ); + clear_proxy_teximage(ctx->Texture.Proxy3D->Image[level]); } } else { /* if no error, update proxy texture image parameters */ - init_texture_image(ctx->Texture.Proxy3D->Image[level], + init_texture_image(ctx, ctx->Texture.Proxy3D->Image[level], width, 1, 1, border, internalFormat); } } @@ -2829,7 +3043,6 @@ _mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, gl_problem(ctx, "glCompressedTexSubImage1DARB failed!"); return; } - } diff --git a/xc/extras/Mesa/src/teximage.h b/xc/extras/Mesa/src/teximage.h index b63649eac..98fae39a8 100644 --- a/xc/extras/Mesa/src/teximage.h +++ b/xc/extras/Mesa/src/teximage.h @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -47,7 +47,9 @@ _mesa_free_texture_image( struct gl_texture_image *teximage ); extern GLuint -_mesa_compressed_image_size(GLenum internalFormat, +_mesa_compressed_image_size(GLcontext *ctx, + GLenum internalFormat, + GLint numDimensions, GLint width, GLint height, GLint depth); diff --git a/xc/extras/Mesa/src/texobj.c b/xc/extras/Mesa/src/texobj.c index e55428408..d7572d86b 100644 --- a/xc/extras/Mesa/src/texobj.c +++ b/xc/extras/Mesa/src/texobj.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -65,6 +65,7 @@ gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name, obj->RefCount = 1; obj->Name = name; obj->Dimensions = dimensions; + obj->Priority = 1.0F; obj->WrapS = GL_REPEAT; obj->WrapT = GL_REPEAT; obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR; @@ -391,11 +392,13 @@ _mesa_GenTextures( GLsizei n, GLuint *texName ) GLint i; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGenTextures"); - if (n<0) { + if (n < 0) { gl_error( ctx, GL_INVALID_VALUE, "glGenTextures" ); return; } + if (!texName) + return; /* * This must be atomic (generation and allocation of texture IDs) @@ -432,6 +435,9 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *texName) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDeleteTextures"); + if (!texName) + return; + for (i=0;i<n;i++) { struct gl_texture_object *t; if (texName[i]>0) { @@ -610,19 +616,20 @@ _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName, GLint i; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPrioritizeTextures"); - if (n<0) { + if (n < 0) { gl_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" ); return; } - for (i=0;i<n;i++) { - struct gl_texture_object *t; - if (texName[i]>0) { - t = (struct gl_texture_object *) + if (!priorities) + return; + + for (i = 0; i < n; i++) { + if (texName[i] > 0) { + struct gl_texture_object *t = (struct gl_texture_object *) _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); if (t) { t->Priority = CLAMP( priorities[i], 0.0F, 1.0F ); - if (ctx->Driver.PrioritizeTexture) ctx->Driver.PrioritizeTexture( ctx, t, t->Priority ); } @@ -636,41 +643,47 @@ _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName, * Execute glAreTexturesResident */ GLboolean -_mesa_AreTexturesResident( GLsizei n, const GLuint *texName, - GLboolean *residences ) +_mesa_AreTexturesResident(GLsizei n, const GLuint *texName, + GLboolean *residences) { GET_CURRENT_CONTEXT(ctx); - GLboolean resident = GL_TRUE; + GLboolean allResident = GL_TRUE; GLint i; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, - "glAreTexturesResident", - GL_FALSE); - if (n<0) { - gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)" ); + "glAreTexturesResident", GL_FALSE); + if (n < 0) { + gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)"); return GL_FALSE; } - for (i=0;i<n;i++) { + if (!texName || !residences) + return GL_FALSE; + + for (i = 0; i < n; i++) { struct gl_texture_object *t; - if (texName[i]==0) { - gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)" ); + if (texName[i] == 0) { + gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)"); return GL_FALSE; } t = (struct gl_texture_object *) _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); if (t) { - if (ctx->Driver.IsTextureResident) - residences[i] = ctx->Driver.IsTextureResident( ctx, t ); - else + if (ctx->Driver.IsTextureResident) { + residences[i] = ctx->Driver.IsTextureResident(ctx, t); + if (!residences[i]) + allResident = GL_FALSE; + } + else { residences[i] = GL_TRUE; + } } else { - gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)" ); + gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)"); return GL_FALSE; } } - return resident; + return allResident; } @@ -684,7 +697,7 @@ _mesa_IsTexture( GLuint texture ) GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glIsTextures", GL_FALSE); - if (texture>0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) { + if (texture > 0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) { return GL_TRUE; } else { diff --git a/xc/extras/Mesa/src/texstate.c b/xc/extras/Mesa/src/texstate.c index a51a7f873..8d8a8a20e 100644 --- a/xc/extras/Mesa/src/texstate.c +++ b/xc/extras/Mesa/src/texstate.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -70,64 +70,284 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param ) ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv"); if (target==GL_TEXTURE_ENV) { - - if (pname==GL_TEXTURE_ENV_MODE) { - GLenum mode = (GLenum) (GLint) *param; - switch (mode) { - case GL_ADD: - if (!ctx->Extensions.HaveTextureEnvAdd) { - gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)"); - return; - } - /* FALL-THROUGH */ - case GL_MODULATE: - case GL_BLEND: - case GL_DECAL: - case GL_REPLACE: - /* A small optimization for drivers */ - if (texUnit->EnvMode == mode) - return; - - if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_TEXTURE)) - fprintf(stderr, "glTexEnv: old mode %s, new mode %s\n", - gl_lookup_enum_by_nr(texUnit->EnvMode), - gl_lookup_enum_by_nr(mode)); - - texUnit->EnvMode = mode; - ctx->NewState |= NEW_TEXTURE_ENV; - break; - default: - gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" ); - return; - } - } - else if (pname==GL_TEXTURE_ENV_COLOR) { - texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F ); - texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F ); - texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F ); - texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F ); - } - else { - gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); - return; + switch (pname) { + case GL_TEXTURE_ENV_MODE: + { + GLenum mode = (GLenum) (GLint) *param; + switch (mode) { + case GL_MODULATE: + case GL_BLEND: + case GL_DECAL: + case GL_REPLACE: + case GL_ADD: + case GL_COMBINE_EXT: + if (mode == GL_ADD && + !ctx->Extensions.HaveTextureEnvAdd) { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)"); + return; + } + if (mode == GL_COMBINE_EXT && + !ctx->Extensions.HaveTextureEnvCombine) { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)"); + return; + } + if (texUnit->EnvMode == mode) + return; /* no change */ + texUnit->EnvMode = mode; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" ); + return; + } + } + break; + case GL_TEXTURE_ENV_COLOR: + texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F ); + texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F ); + texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F ); + texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F ); + break; + case GL_COMBINE_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + GLenum mode = (GLenum) (GLint) *param; + switch (mode) { + case GL_REPLACE: + case GL_MODULATE: + case GL_ADD: + case GL_ADD_SIGNED_EXT: + case GL_INTERPOLATE_EXT: + if (texUnit->CombineModeRGB == mode) + return; /* no change */ + texUnit->CombineModeRGB = mode; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_COMBINE_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + GLenum mode = (GLenum) (GLint) *param; + switch (mode) { + case GL_REPLACE: + case GL_MODULATE: + case GL_ADD: + case GL_ADD_SIGNED_EXT: + case GL_INTERPOLATE_EXT: + if (texUnit->CombineModeA == mode) + return; /* no change */ + texUnit->CombineModeA = mode; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_SOURCE0_RGB_EXT: + case GL_SOURCE1_RGB_EXT: + case GL_SOURCE2_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + GLenum source = (GLenum) (GLint) *param; + GLuint s = pname - GL_SOURCE0_RGB_EXT; + switch (source) { + case GL_TEXTURE: + case GL_CONSTANT_EXT: + case GL_PRIMARY_COLOR_EXT: + case GL_PREVIOUS_EXT: + if (texUnit->CombineSourceRGB[s] == source) + return; /* no change */ + texUnit->CombineSourceRGB[s] = source; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_SOURCE0_ALPHA_EXT: + case GL_SOURCE1_ALPHA_EXT: + case GL_SOURCE2_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + GLenum source = (GLenum) (GLint) *param; + GLuint s = pname - GL_SOURCE0_ALPHA_EXT; + switch (source) { + case GL_TEXTURE: + case GL_CONSTANT_EXT: + case GL_PRIMARY_COLOR_EXT: + case GL_PREVIOUS_EXT: + if (texUnit->CombineSourceA[s] == source) return; + texUnit->CombineSourceA[s] = source; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_OPERAND0_RGB_EXT: + case GL_OPERAND1_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + GLenum operand = (GLenum) (GLint) *param; + GLuint s = pname - GL_OPERAND0_RGB_EXT; + switch (operand) { + case GL_SRC_COLOR: + case GL_ONE_MINUS_SRC_COLOR: + case GL_SRC_ALPHA: + case GL_ONE_MINUS_SRC_ALPHA: + texUnit->CombineOperandRGB[s] = operand; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_OPERAND0_ALPHA_EXT: + case GL_OPERAND1_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + GLenum operand = (GLenum) (GLint) *param; + switch (operand) { + case GL_SRC_ALPHA: + case GL_ONE_MINUS_SRC_ALPHA: + texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT] + = operand; + ctx->NewState |= NEW_TEXTURE_ENV; + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_OPERAND2_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + if ((GLenum) (GLint) *param == GL_SRC_ALPHA) { + texUnit->CombineOperandRGB[2] = (GLenum) (GLint) *param; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_OPERAND2_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + if ((GLenum) (GLint) *param == GL_SRC_ALPHA) { + texUnit->CombineOperandA[2] = (GLenum) (GLint) *param; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else { + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_RGB_SCALE_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + if (*param == 1.0) { + texUnit->CombineScaleShiftRGB = 0; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else if (*param == 2.0) { + texUnit->CombineScaleShiftRGB = 1; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else if (*param == 4.0) { + texUnit->CombineScaleShiftRGB = 2; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else { + gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + case GL_ALPHA_SCALE: + if (ctx->Extensions.HaveTextureEnvCombine) { + if (*param == 1.0) { + texUnit->CombineScaleShiftA = 0; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else if (*param == 2.0) { + texUnit->CombineScaleShiftA = 1; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else if (*param == 4.0) { + texUnit->CombineScaleShiftA = 2; + ctx->NewState |= NEW_TEXTURE_ENV; + } + else { + gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" ); + return; + } + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)"); + return; + } + break; + default: + gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); + return; } - } else if (target==GL_TEXTURE_FILTER_CONTROL_EXT) { - if (!ctx->Extensions.HaveTextureLodBias) { gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" ); return; } - - if (pname==GL_TEXTURE_LOD_BIAS_EXT) { + if (pname == GL_TEXTURE_LOD_BIAS_EXT) { texUnit->LodBias = param[0]; } else { gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" ); return; } - } else { gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" ); @@ -183,7 +403,7 @@ void _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ) { GET_CURRENT_CONTEXT(ctx); - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnvfv"); @@ -191,6 +411,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ) gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" ); return; } + switch (pname) { case GL_TEXTURE_ENV_MODE: *params = ENUM_TO_FLOAT(texUnit->EnvMode); @@ -198,6 +419,34 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ) case GL_TEXTURE_ENV_COLOR: COPY_4FV( params, texUnit->EnvColor ); break; + case GL_RGB_SCALE_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + if (texUnit->CombineScaleShiftRGB == 0) + *params = 1.0; + else if (texUnit->CombineScaleShiftRGB == 1) + *params = 2.0; + else + *params = 4.0; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); + return; + } + break; + case GL_ALPHA_SCALE: + if (ctx->Extensions.HaveTextureEnvCombine) { + if (texUnit->CombineScaleShiftA == 0) + *params = 1.0; + else if (texUnit->CombineScaleShiftA == 1) + *params = 2.0; + else + *params = 4.0; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)"); + return; + } + break; default: gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" ); } @@ -208,14 +457,15 @@ void _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params ) { GET_CURRENT_CONTEXT(ctx); - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnviv"); - if (target!=GL_TEXTURE_ENV) { + if (target != GL_TEXTURE_ENV) { gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" ); return; } + switch (pname) { case GL_TEXTURE_ENV_MODE: *params = (GLint) texUnit->EnvMode; @@ -225,6 +475,118 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params ) params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] ); params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] ); params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] ); + break; + case GL_COMBINE_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineModeRGB; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_COMBINE_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineModeA; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_SOURCE0_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineSourceRGB[0]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_SOURCE1_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineSourceRGB[1]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_SOURCE2_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineSourceRGB[2]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_SOURCE0_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineSourceA[0]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_SOURCE1_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineSourceA[1]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_SOURCE2_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineSourceA[2]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_OPERAND0_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineOperandRGB[0]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_OPERAND1_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineOperandRGB[1]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_OPERAND2_RGB_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineOperandRGB[2]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_OPERAND0_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineOperandA[0]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_OPERAND1_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineOperandA[1]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } + break; + case GL_OPERAND2_ALPHA_EXT: + if (ctx->Extensions.HaveTextureEnvCombine) { + *params = (GLint) texUnit->CombineOperandA[2]; + } + else { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)"); + } break; default: gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" ); @@ -608,7 +970,14 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) params[3] = obj->BorderColor[3] / 255.0F; break; case GL_TEXTURE_RESIDENT: - *params = ENUM_TO_FLOAT(GL_TRUE); + { + GLboolean resident; + if (ctx->Driver.IsTextureResident) + resident = ctx->Driver.IsTextureResident(ctx, obj); + else + resident = GL_TRUE; + *params = ENUM_TO_FLOAT(resident); + } break; case GL_TEXTURE_PRIORITY: *params = obj->Priority; @@ -676,7 +1045,14 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) } break; case GL_TEXTURE_RESIDENT: - *params = (GLint) GL_TRUE; + { + GLboolean resident; + if (ctx->Driver.IsTextureResident) + resident = ctx->Driver.IsTextureResident(ctx, obj); + else + resident = GL_TRUE; + *params = (GLint) resident; + } break; case GL_TEXTURE_PRIORITY: *params = (GLint) obj->Priority; diff --git a/xc/extras/Mesa/src/texture.c b/xc/extras/Mesa/src/texture.c index 0106ab86b..9d83efd79 100644 --- a/xc/extras/Mesa/src/texture.c +++ b/xc/extras/Mesa/src/texture.c @@ -31,6 +31,7 @@ #include "context.h" #include "macros.h" #include "mmath.h" +#include "mem.h" #include "pb.h" #include "teximage.h" #include "texture.h" @@ -370,6 +371,36 @@ static void palette_sample(const struct gl_texture_object *tObj, /* + * Compute linear mipmap levels for given lambda. + */ +#define COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level) \ +{ \ + if (lambda < 0.0F) \ + lambda = 0.0F; \ + else if (lambda > tObj->M) \ + lambda = tObj->M; \ + level = (GLint) (tObj->BaseLevel + lambda); \ +} + + +/* + * Compute nearest mipmap level for given lambda. + */ +#define COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level) \ +{ \ + if (lambda <= 0.5F) \ + lambda = 0.0F; \ + else if (lambda > tObj->M + 0.4999F) \ + lambda = tObj->M + 0.4999F; \ + level = (GLint) (tObj->BaseLevel + lambda + 0.5F); \ + if (level > tObj->P) \ + level = tObj->P; \ +} + + + + +/* * Bitflags for texture border color sampling. */ #define I0BIT 1 @@ -578,14 +609,7 @@ sample_1d_nearest_mipmap_nearest( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda <= 0.5F) - lambda = 0.0F; - else if (lambda > tObj->M + 0.4999F) - lambda = tObj->M + 0.4999F; - level = (GLint) (tObj->BaseLevel + lambda + 0.5F); - if (level > tObj->P) - level = tObj->P; - + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); sample_1d_nearest( tObj, tObj->Image[level], s, rgba ); } @@ -596,14 +620,7 @@ sample_1d_linear_mipmap_nearest( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda <= 0.5F) - lambda = 0.0F; - else if (lambda > tObj->M + 0.4999F) - lambda = tObj->M + 0.4999F; - level = (GLint) (tObj->BaseLevel + lambda + 0.5F); - if (level > tObj->P) - level = tObj->P; - + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); sample_1d_linear( tObj, tObj->Image[level], s, rgba ); } @@ -615,11 +632,8 @@ sample_1d_nearest_mipmap_linear( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda < 0.0F) - lambda = 0.0F; - else if (lambda > tObj->M) - lambda = tObj->M; - level = (GLint) (tObj->BaseLevel + lambda); + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); if (level >= tObj->P) { sample_1d_nearest( tObj, tObj->Image[tObj->P], s, rgba ); @@ -644,11 +658,8 @@ sample_1d_linear_mipmap_linear( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda < 0.0F) - lambda = 0.0F; - else if (lambda > tObj->M) - lambda = tObj->M; - level = (GLint) (tObj->BaseLevel + lambda); + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); if (level >= tObj->P) { sample_1d_linear( tObj, tObj->Image[tObj->P], s, rgba ); @@ -971,14 +982,7 @@ sample_2d_nearest_mipmap_nearest( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda <= 0.5F) - lambda = 0.0F; - else if (lambda > tObj->M + 0.4999F) - lambda = tObj->M + 0.4999F; - level = (GLint) (tObj->BaseLevel + lambda + 0.5F); - if (level > tObj->P) - level = tObj->P; - + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); sample_2d_nearest( tObj, tObj->Image[level], s, t, rgba ); } @@ -990,14 +994,7 @@ sample_2d_linear_mipmap_nearest( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda <= 0.5F) - lambda = 0.0F; - else if (lambda > tObj->M + 0.4999F) - lambda = tObj->M + 0.4999F; - level = (GLint) (tObj->BaseLevel + lambda + 0.5F); - if (level > tObj->P) - level = tObj->P; - + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); sample_2d_linear( tObj, tObj->Image[level], s, t, rgba ); } @@ -1009,11 +1006,8 @@ sample_2d_nearest_mipmap_linear( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda < 0.0F) - lambda = 0.0F; - else if (lambda > tObj->M) - lambda = tObj->M; - level = (GLint) (tObj->BaseLevel + lambda); + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); if (level >= tObj->P) { sample_2d_nearest( tObj, tObj->Image[tObj->P], s, t, rgba ); @@ -1038,11 +1032,8 @@ sample_2d_linear_mipmap_linear( const struct gl_texture_object *tObj, GLubyte rgba[4] ) { GLint level; - if (lambda < 0.0F) - lambda = 0.0F; - else if (lambda > tObj->M) - lambda = tObj->M; - level = (GLint) (tObj->BaseLevel + lambda); + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); if (level >= tObj->P) { sample_2d_linear( tObj, tObj->Image[tObj->P], s, t, rgba ); @@ -1490,14 +1481,7 @@ sample_3d_nearest_mipmap_nearest( const struct gl_texture_object *tObj, GLfloat lambda, GLubyte rgba[4] ) { GLint level; - if (lambda <= 0.5F) - lambda = 0.0F; - else if (lambda > tObj->M + 0.4999F) - lambda = tObj->M + 0.4999F; - level = (GLint) (tObj->BaseLevel + lambda + 0.5F); - if (level > tObj->P) - level = tObj->P; - + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); sample_3d_nearest( tObj, tObj->Image[level], s, t, r, rgba ); } @@ -1508,14 +1492,7 @@ sample_3d_linear_mipmap_nearest( const struct gl_texture_object *tObj, GLfloat lambda, GLubyte rgba[4] ) { GLint level; - if (lambda <= 0.5F) - lambda = 0.0F; - else if (lambda > tObj->M + 0.4999F) - lambda = tObj->M + 0.4999F; - level = (GLint) (tObj->BaseLevel + lambda + 0.5F); - if (level > tObj->P) - level = tObj->P; - + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); sample_3d_linear( tObj, tObj->Image[level], s, t, r, rgba ); } @@ -1526,11 +1503,8 @@ sample_3d_nearest_mipmap_linear( const struct gl_texture_object *tObj, GLfloat lambda, GLubyte rgba[4] ) { GLint level; - if (lambda < 0.0F) - lambda = 0.0F; - else if (lambda > tObj->M) - lambda = tObj->M; - level = (GLint) (tObj->BaseLevel + lambda); + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); if (level >= tObj->P) { sample_3d_nearest( tObj, tObj->Image[tObj->P], s, t, r, rgba ); @@ -1554,11 +1528,8 @@ sample_3d_linear_mipmap_linear( const struct gl_texture_object *tObj, GLfloat lambda, GLubyte rgba[4] ) { GLint level; - if (lambda < 0.0F) - lambda = 0.0F; - else if (lambda > tObj->M) - lambda = tObj->M; - level = (GLint) (tObj->BaseLevel + lambda); + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); if (level >= tObj->P) { sample_3d_linear( tObj, tObj->Image[tObj->P], s, t, r, rgba ); @@ -1664,10 +1635,14 @@ static void sample_lambda_3d( const struct gl_texture_object *tObj, GLuint n, /* Texture Cube Map Sampling Functions */ /**********************************************************************/ -static struct gl_texture_image * +/* + * Choose one of six sides of a texture cube map given the texture + * coord (rx,ry,rz). Return pointer to corresponding array of texture + * images. + */ +static const struct gl_texture_image ** choose_cube_face(const struct gl_texture_object *texObj, - const GLfloat texcoord[4], - GLint level, + GLfloat rx, GLfloat ry, GLfloat rz, GLfloat *newS, GLfloat *newT) { /* @@ -1681,20 +1656,19 @@ choose_cube_face(const struct gl_texture_object *texObj, +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz */ - struct gl_texture_image *texImg; - const GLfloat rx = texcoord[0], ry = texcoord[1], rz = texcoord[2]; + const struct gl_texture_image **imgArray; const GLfloat arx = ABSF(rx), ary = ABSF(ry), arz = ABSF(rz); GLfloat sc, tc, ma; if (arx > ary && arx > arz) { if (rx >= 0.0F) { - texImg = texObj->Image[level]; + imgArray = (const struct gl_texture_image **) texObj->Image; sc = -rz; tc = -ry; ma = arx; } else { - texImg = texObj->NegX[level]; + imgArray = (const struct gl_texture_image **) texObj->NegX; sc = rz; tc = -ry; ma = arx; @@ -1702,13 +1676,13 @@ choose_cube_face(const struct gl_texture_object *texObj, } else if (ary > arx && ary > arz) { if (ry >= 0.0F) { - texImg = texObj->PosY[level]; + imgArray = (const struct gl_texture_image **) texObj->PosY; sc = rx; tc = rz; ma = ary; } else { - texImg = texObj->NegY[level]; + imgArray = (const struct gl_texture_image **) texObj->NegY; sc = rx; tc = -rz; ma = ary; @@ -1716,13 +1690,13 @@ choose_cube_face(const struct gl_texture_object *texObj, } else { if (rz > 0.0F) { - texImg = texObj->PosZ[level]; + imgArray = (const struct gl_texture_image **) texObj->PosZ; sc = rx; tc = -ry; ma = arz; } else { - texImg = texObj->NegZ[level]; + imgArray = (const struct gl_texture_image **) texObj->NegZ; sc = -rx; tc = -ry; ma = arz; @@ -1731,7 +1705,7 @@ choose_cube_face(const struct gl_texture_object *texObj, *newS = ( sc / ma + 1.0F ) * 0.5F; *newT = ( tc / ma + 1.0F ) * 0.5F; - return texImg; + return imgArray; } @@ -1744,17 +1718,14 @@ sample_nearest_cube(const struct gl_texture_object *tObj, GLuint n, GLuint i; (void) lambda; for (i = 0; i < n; i++) { - struct gl_texture_image *image; + const struct gl_texture_image **images; GLfloat newS, newT; - GLfloat coord[4]; - coord[0] = s[i]; - coord[1] = t[i]; - coord[2] = u[i]; - image = choose_cube_face(tObj, coord, 0, &newS, &newT); - sample_2d_nearest( tObj, image, newS, newT, rgba[i] ); + images = choose_cube_face(tObj, s[i], t[i], u[i], &newS, &newT); + sample_2d_nearest( tObj, images[tObj->BaseLevel], newS, newT, rgba[i] ); } } + static void sample_linear_cube(const struct gl_texture_object *tObj, GLuint n, const GLfloat s[], const GLfloat t[], @@ -1764,17 +1735,104 @@ sample_linear_cube(const struct gl_texture_object *tObj, GLuint n, GLuint i; (void) lambda; for (i = 0; i < n; i++) { - struct gl_texture_image *image; + const struct gl_texture_image **images; GLfloat newS, newT; - GLfloat coord[4]; - coord[0] = s[i]; - coord[1] = t[i]; - coord[2] = u[i]; - image = choose_cube_face(tObj, coord, 0, &newS, &newT); - sample_2d_linear( tObj, image, newS, newT, rgba[i] ); + images = choose_cube_face(tObj, s[i], t[i], u[i], &newS, &newT); + sample_2d_linear( tObj, images[tObj->BaseLevel], newS, newT, rgba[i] ); } } + +static void +sample_cube_nearest_mipmap_nearest( const struct gl_texture_object *tObj, + GLfloat s, GLfloat t, GLfloat u, + GLfloat lambda, GLubyte rgba[4] ) +{ + const struct gl_texture_image **images; + GLfloat newS, newT; + GLint level; + + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); + + images = choose_cube_face(tObj, s, t, u, &newS, &newT); + sample_2d_nearest( tObj, images[level], newS, newT, rgba ); +} + + +static void +sample_cube_linear_mipmap_nearest( const struct gl_texture_object *tObj, + GLfloat s, GLfloat t, GLfloat u, + GLfloat lambda, GLubyte rgba[4] ) +{ + const struct gl_texture_image **images; + GLfloat newS, newT; + GLint level; + + COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level); + + images = choose_cube_face(tObj, s, t, u, &newS, &newT); + sample_2d_linear( tObj, images[level], newS, newT, rgba ); +} + + +static void +sample_cube_nearest_mipmap_linear( const struct gl_texture_object *tObj, + GLfloat s, GLfloat t, GLfloat u, + GLfloat lambda, GLubyte rgba[4] ) +{ + const struct gl_texture_image **images; + GLfloat newS, newT; + GLint level; + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); + + images = choose_cube_face(tObj, s, t, u, &newS, &newT); + + if (level >= tObj->P) { + sample_2d_nearest( tObj, images[tObj->P], newS, newT, rgba ); + } + else { + GLubyte t0[4], t1[4]; /* texels */ + const GLfloat f = myFrac(lambda); + sample_2d_nearest( tObj, images[level ], newS, newT, t0 ); + sample_2d_nearest( tObj, images[level+1], newS, newT, t1 ); + rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); + rgba[GCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[GCOMP] + f * t1[GCOMP]); + rgba[BCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[BCOMP] + f * t1[BCOMP]); + rgba[ACOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]); + } +} + + +static void +sample_cube_linear_mipmap_linear( const struct gl_texture_object *tObj, + GLfloat s, GLfloat t, GLfloat u, + GLfloat lambda, GLubyte rgba[4] ) +{ + const struct gl_texture_image **images; + GLfloat newS, newT; + GLint level; + + COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level); + + images = choose_cube_face(tObj, s, t, u, &newS, &newT); + + if (level >= tObj->P) { + sample_2d_linear( tObj, images[tObj->P], newS, newT, rgba ); + } + else { + GLubyte t0[4], t1[4]; + const GLfloat f = myFrac(lambda); + sample_2d_linear( tObj, images[level ], newS, newT, t0 ); + sample_2d_linear( tObj, images[level+1], newS, newT, t1 ); + rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); + rgba[GCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[GCOMP] + f * t1[GCOMP]); + rgba[BCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[BCOMP] + f * t1[BCOMP]); + rgba[ACOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]); + } +} + + static void sample_lambda_cube(const struct gl_texture_object *tObj, GLuint n, const GLfloat s[], const GLfloat t[], @@ -1784,42 +1842,44 @@ sample_lambda_cube(const struct gl_texture_object *tObj, GLuint n, GLuint i; for (i = 0; i < n; i++) { - struct gl_texture_image *image; - GLfloat newS, newT; - GLfloat coord[4]; - coord[0] = s[i]; - coord[1] = t[i]; - coord[2] = u[i]; - image = choose_cube_face(tObj, coord, 0, &newS, &newT); - if (lambda[i] > tObj->MinMagThresh) { /* minification */ switch (tObj->MinFilter) { case GL_NEAREST: - sample_2d_nearest( tObj, image, newS, newT, rgba[i] ); + { + const struct gl_texture_image **images; + GLfloat newS, newT; + images = choose_cube_face(tObj, s[i], t[i], u[i], + &newS, &newT); + sample_2d_nearest( tObj, images[tObj->BaseLevel], + newS, newT, rgba[i] ); + } break; case GL_LINEAR: - sample_2d_linear( tObj, image, newS, newT, rgba[i] ); + { + const struct gl_texture_image **images; + GLfloat newS, newT; + images = choose_cube_face(tObj, s[i], t[i], u[i], + &newS, &newT); + sample_2d_linear( tObj, images[tObj->BaseLevel], + newS, newT, rgba[i] ); + } break; case GL_NEAREST_MIPMAP_NEAREST: - /* - sample_3d_nearest_mipmap_nearest( tObj, s[i], t[i], u[i], lambda[i], rgba[i] ); - */ + sample_cube_nearest_mipmap_nearest( tObj, s[i], t[i], u[i], + lambda[i], rgba[i] ); break; case GL_LINEAR_MIPMAP_NEAREST: - /* - sample_3d_linear_mipmap_nearest( tObj, s[i], t[i], u[i], lambda[i], rgba[i] ); - */ + sample_cube_linear_mipmap_nearest( tObj, s[i], t[i], u[i], + lambda[i], rgba[i] ); break; case GL_NEAREST_MIPMAP_LINEAR: - /* - sample_3d_nearest_mipmap_linear( tObj, s[i], t[i], u[i], lambda[i], rgba[i] ); - */ + sample_cube_nearest_mipmap_linear( tObj, s[i], t[i], u[i], + lambda[i], rgba[i] ); break; case GL_LINEAR_MIPMAP_LINEAR: - /* - sample_3d_linear_mipmap_linear( tObj, s[i], t[i], u[i], lambda[i], rgba[i] ); - */ + sample_cube_linear_mipmap_linear( tObj, s[i], t[i], u[i], + lambda[i], rgba[i] ); break; default: gl_problem(NULL, "Bad min filter in sample_lambda_cube"); @@ -1827,12 +1887,18 @@ sample_lambda_cube(const struct gl_texture_object *tObj, GLuint n, } else { /* magnification */ + const struct gl_texture_image **images; + GLfloat newS, newT; + images = choose_cube_face(tObj, s[i], t[i], u[i], + &newS, &newT); switch (tObj->MagFilter) { case GL_NEAREST: - sample_2d_nearest( tObj, image, newS, newT, rgba[i] ); + sample_2d_nearest( tObj, images[tObj->BaseLevel], + newS, newT, rgba[i] ); break; case GL_LINEAR: - sample_2d_linear( tObj, image, newS, newT, rgba[i] ); + sample_2d_linear( tObj, images[tObj->BaseLevel], + newS, newT, rgba[i] ); break; default: gl_problem(NULL, "Bad mag filter in sample_lambda_cube"); @@ -1936,6 +2002,256 @@ _mesa_set_texture_sampler( struct gl_texture_object *t ) } +#define PROD(A,B) ( (GLuint)(A) * ((GLuint)(B)+1) ) + +static INLINE void +_mesa_texture_combine(CONST GLcontext *ctx, + CONST struct gl_texture_unit *textureUnit, + GLuint n, + GLubyte (*primary_rgba)[4], + GLubyte (*texel)[4], + GLubyte (*rgba)[4]) +{ + GLubyte ccolor [3][3*MAX_WIDTH][4]; + GLubyte (*argRGB [3])[4]; + GLubyte (*argA [3])[4]; + GLuint i, j; + GLuint RGBshift = textureUnit->CombineScaleShiftRGB; + GLuint Ashift = textureUnit->CombineScaleShiftA; + + ASSERT(ctx->Extensions.HaveTextureEnvCombine); + + for (j = 0; j < 3; j++) { + switch (textureUnit->CombineSourceA[j]) { + case GL_TEXTURE: + argA[j] = texel; + break; + case GL_PRIMARY_COLOR_EXT: + argA[j] = primary_rgba; + break; + case GL_PREVIOUS_EXT: + argA[j] = rgba; + break; + case GL_CONSTANT_EXT: + { + GLubyte (*c)[4] = ccolor[j]; + GLubyte col = FLOAT_TO_UBYTE(textureUnit->EnvColor[3]); + for (i = 0; i < n; i++) + c[i][ACOMP] = col; + argA[j] = ccolor[j]; + } + break; + default: + gl_problem(NULL, "invalid combine source"); + } + + if (textureUnit->CombineOperandA[j] == GL_ONE_MINUS_SRC_ALPHA) { + GLubyte (*src)[4] = argA[j]; + GLubyte (*dst)[4] = ccolor[j]; + argA[j] = ccolor[j]; + for (i = 0; i < n; i++) + dst[i][ACOMP] = 255 - src[i][ACOMP]; + } + + if (j == 2) /* arg2 has no color component in specification. */ + break; + + switch (textureUnit->CombineSourceRGB[j]) { + case GL_TEXTURE: + argRGB[j] = texel; + break; + case GL_PRIMARY_COLOR_EXT: + argRGB[j] = primary_rgba; + break; + case GL_PREVIOUS_EXT: + argRGB[j] = rgba; + break; + case GL_CONSTANT_EXT: + { + GLubyte (*c)[4] = ccolor[j]; + GLubyte col[4]; + + col[RCOMP] = FLOAT_TO_UBYTE(textureUnit->EnvColor[0]); + col[GCOMP] = FLOAT_TO_UBYTE(textureUnit->EnvColor[1]); + col[BCOMP] = FLOAT_TO_UBYTE(textureUnit->EnvColor[2]); + + for (i = 0; i < n; i++) { + c[i][RCOMP] = col[RCOMP]; + c[i][GCOMP] = col[GCOMP]; + c[i][BCOMP] = col[BCOMP]; + } + argRGB[j] = ccolor[j]; + } + break; + default: + gl_problem(NULL, "invalid combine source"); + } + + if (textureUnit->CombineOperandRGB[j] != GL_SRC_COLOR) { + GLubyte (*src)[4] = argRGB[j]; + GLubyte (*dst)[4] = ccolor[j]; + + argRGB[j] = ccolor[j]; + + if (textureUnit->CombineOperandRGB[j] == GL_ONE_MINUS_SRC_COLOR) { + for (i = 0; i < n; i++) { + dst[i][RCOMP] = 255 - src[i][RCOMP]; + dst[i][GCOMP] = 255 - src[i][GCOMP]; + dst[i][BCOMP] = 255 - src[i][BCOMP]; + } + } else if (textureUnit->CombineOperandRGB[j] == GL_SRC_ALPHA) { + for (i = 0; i < n; i++) { + dst[i][RCOMP] = src[i][ACOMP]; + dst[i][GCOMP] = src[i][ACOMP]; + dst[i][BCOMP] = src[i][ACOMP]; + } + } else { /* GL_ONE_MINUS_SRC_ALPHA */ + for (i = 0; i < n; i++) { + dst[i][RCOMP] = 255 - src[i][ACOMP]; + dst[i][GCOMP] = 255 - src[i][ACOMP]; + dst[i][BCOMP] = 255 - src[i][ACOMP]; + } + } + } + + if (textureUnit->CombineModeRGB == GL_REPLACE && + textureUnit->CombineModeA == GL_REPLACE) { + break; /* done, we need only arg0 */ + } + + if (j == 1 && + textureUnit->CombineModeRGB != GL_INTERPOLATE_EXT && + textureUnit->CombineModeA != GL_INTERPOLATE_EXT) { + break; /* arg0 and arg1 are done. we don't need arg2. */ + } + } + + switch (textureUnit->CombineModeRGB) { + case GL_REPLACE: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argRGB[0]; + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = arg0[i][RCOMP] << RGBshift; + rgba[i][GCOMP] = arg0[i][GCOMP] << RGBshift; + rgba[i][BCOMP] = arg0[i][BCOMP] << RGBshift; + } + } + break; + case GL_MODULATE: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argRGB[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argRGB[1]; + RGBshift = 8 - RGBshift; + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = (GLubyte) (PROD(arg0[i][0], arg1[i][RCOMP]) >> RGBshift); + rgba[i][GCOMP] = (GLubyte) (PROD(arg0[i][1], arg1[i][GCOMP]) >> RGBshift); + rgba[i][BCOMP] = (GLubyte) (PROD(arg0[i][2], arg1[i][BCOMP]) >> RGBshift); + } + } + break; + case GL_ADD: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argRGB[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argRGB[1]; + for (i = 0; i < n; i++) { + GLint r = ((GLuint) arg0[i][RCOMP] + arg1[i][RCOMP]) << RGBshift; + GLint g = ((GLuint) arg0[i][GCOMP] + arg1[i][GCOMP]) << RGBshift; + GLint b = ((GLuint) arg0[i][BCOMP] + arg1[i][BCOMP]) << RGBshift; + rgba[i][RCOMP] = (r > 255) ? 255 : (GLubyte) r; + rgba[i][GCOMP] = (g > 255) ? 255 : (GLubyte) g; + rgba[i][BCOMP] = (b > 255) ? 255 : (GLubyte) b; + } + } + break; + case GL_ADD_SIGNED_EXT: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argRGB[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argRGB[1]; + for (i = 0; i < n; i++) { + GLint r = (GLint) arg0[i][RCOMP] + (GLint) arg1[i][RCOMP] - 128; + GLint g = (GLint) arg0[i][GCOMP] + (GLint) arg1[i][GCOMP] - 128; + GLint b = (GLint) arg0[i][BCOMP] + (GLint) arg1[i][BCOMP] - 128; + r = (r < 0) ? 0 : r << RGBshift; + b = (b < 0) ? 0 : b << RGBshift; + g = (g < 0) ? 0 : g << RGBshift; + rgba[i][RCOMP] = (r > 255) ? 255 : (GLubyte) r; + rgba[i][GCOMP] = (g > 255) ? 255 : (GLubyte) g; + rgba[i][BCOMP] = (b > 255) ? 255 : (GLubyte) b; + } + } + break; + case GL_INTERPOLATE_EXT: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argRGB[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argRGB[1]; + const GLubyte (*arg2)[4] = (const GLubyte (*)[4]) argRGB[2]; + RGBshift = 8 - RGBshift; + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = (GLubyte) ((PROD(arg0[i][RCOMP], arg2[i][ACOMP]) + PROD(arg1[i][RCOMP], 255 - arg2[i][ACOMP])) >> RGBshift); + rgba[i][GCOMP] = (GLubyte) ((PROD(arg0[i][GCOMP], arg2[i][ACOMP]) + PROD(arg1[i][GCOMP], 255 - arg2[i][ACOMP])) >> RGBshift); + rgba[i][BCOMP] = (GLubyte) ((PROD(arg0[i][BCOMP], arg2[i][ACOMP]) + PROD(arg1[i][BCOMP], 255 - arg2[i][ACOMP])) >> RGBshift); + } + } + break; + default: + gl_problem(NULL, "invalid combine mode"); + } + + switch (textureUnit->CombineModeA) { + case GL_REPLACE: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argA[0]; + for (i = 0; i < n; i++) + rgba[i][ACOMP] = arg0[i][ACOMP] << Ashift; + } + break; + case GL_MODULATE: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argA[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argA[1]; + Ashift = 8 - Ashift; + for (i = 0; i < n; i++) + rgba[i][ACOMP] = (GLubyte) (PROD(arg0[i][ACOMP], arg1[i][ACOMP]) >> Ashift); + } + break; + case GL_ADD: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argA[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argA[1]; + for (i = 0; i < n; i++) { + GLint a = ((GLint) arg0[i][ACOMP] + arg1[i][ACOMP]) << Ashift; + rgba[i][ACOMP] = (a > 255) ? 255 : (GLubyte) a; + } + } + break; + case GL_ADD_SIGNED_EXT: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argA[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argA[1]; + for (i = 0; i < n; i++) { + GLint a = (GLint) arg0[i][ACOMP] + (GLint) arg1[i][ACOMP] - 128; + a = (a < 0) ? 0 : a << Ashift; + rgba[i][ACOMP] = (a > 255) ? 255 : (GLubyte) a; + } + } + break; + case GL_INTERPOLATE_EXT: + { + const GLubyte (*arg0)[4] = (const GLubyte (*)[4]) argA[0]; + const GLubyte (*arg1)[4] = (const GLubyte (*)[4]) argA[1]; + const GLubyte (*arg2)[4] = (const GLubyte (*)[4]) argA[2]; + Ashift = 8 - Ashift; + for (i=0; i<n; i++) + rgba[i][ACOMP] = (GLubyte) ((PROD(arg0[i][ACOMP], arg2[i][ACOMP]) + PROD(arg1[i][ACOMP], 255 - arg2[i][ACOMP])) >> Ashift); + } + break; + default: + gl_problem(NULL, "invalid combine mode"); + } +} +#undef PROD + + /**********************************************************************/ /* Texture Application */ @@ -1947,14 +2263,16 @@ _mesa_set_texture_sampler( struct gl_texture_object *t ) * Input: textureUnit - pointer to texture unit to apply * format - base internal texture format * n - number of fragments + * primary_rgba - primary colors (may be rgba for single texture) * texels - array of texel colors * InOut: rgba - incoming fragment colors modified by texel colors * according to the texture environment mode. */ -static void apply_texture( const GLcontext *ctx, - const struct gl_texture_unit *texUnit, +static void apply_texture( CONST GLcontext *ctx, + CONST struct gl_texture_unit *texUnit, GLuint n, - GLubyte rgba[][4], CONST GLubyte texel[][4] ) + GLubyte primary_rgba[][4], GLubyte texel[][4], + GLubyte rgba[][4] ) { GLint baseLevel; GLuint i; @@ -2284,6 +2602,52 @@ static void apply_texture( const GLcontext *ctx, } break; + case GL_COMBINE_EXT: /* GL_EXT_combine_ext; we modify texel array */ + switch (format) { + case GL_ALPHA: + for (i=0;i<n;i++) + texel[i][RCOMP] = texel[i][GCOMP] = texel[i][BCOMP] = 0; + break; + case GL_LUMINANCE: + for (i=0;i<n;i++) { + /* Cv = Lt */ + GLubyte Lt = texel[i][RCOMP]; + texel[i][GCOMP] = texel[i][BCOMP] = Lt; + /* Av = 1 */ + texel[i][ACOMP] = 255; + } + break; + case GL_LUMINANCE_ALPHA: + for (i=0;i<n;i++) { + GLubyte Lt = texel[i][RCOMP]; + /* Cv = Lt */ + texel[i][GCOMP] = texel[i][BCOMP] = Lt; + } + break; + case GL_INTENSITY: + for (i=0;i<n;i++) { + /* Cv = It */ + GLubyte It = texel[i][RCOMP]; + texel[i][GCOMP] = texel[i][BCOMP] = It; + /* Av = It */ + texel[i][ACOMP] = It; + } + break; + case GL_RGB: + for (i=0;i<n;i++) { + /* Av = 1 */ + texel[i][ACOMP] = 255; + } + break; + case GL_RGBA: /* do nothing. */ + break; + default: + gl_problem(ctx, "Bad format in apply_texture (GL_COMBINE_EXT)"); + return; + } + _mesa_texture_combine (ctx, texUnit, n, primary_rgba, texel, rgba); + break; + default: gl_problem(ctx, "Bad env mode in apply_texture"); return; @@ -2299,7 +2663,7 @@ static void apply_texture( const GLcontext *ctx, void gl_texture_pixels( GLcontext *ctx, GLuint texUnit, GLuint n, const GLfloat s[], const GLfloat t[], const GLfloat r[], GLfloat lambda[], - GLubyte rgba[][4] ) + GLubyte primary_rgba[][4], GLubyte rgba[][4] ) { GLuint mask = (TEXTURE0_1D | TEXTURE0_2D | TEXTURE0_3D | TEXTURE0_CUBE) << (texUnit * 4); if (ctx->Texture.Enabled & mask) { @@ -2369,8 +2733,7 @@ void gl_texture_pixels( GLcontext *ctx, GLuint texUnit, GLuint n, (*textureUnit->Current->SampleFunc)( textureUnit->Current, n, s, t, r, lambda, texel ); - apply_texture( ctx, textureUnit, n, - rgba, (const GLubyte (*)[4])texel ); + apply_texture( ctx, textureUnit, n, primary_rgba, texel, rgba ); } } } diff --git a/xc/extras/Mesa/src/texture.h b/xc/extras/Mesa/src/texture.h index 58bc13136..113602bf7 100644 --- a/xc/extras/Mesa/src/texture.h +++ b/xc/extras/Mesa/src/texture.h @@ -46,7 +46,7 @@ extern void gl_update_texture_unit( GLcontext *ctx, extern void gl_texture_pixels( GLcontext *ctx, GLuint texSet, GLuint n, const GLfloat s[], const GLfloat t[], const GLfloat r[], GLfloat lambda[], - GLubyte rgba[][4] ); + GLubyte primary_rgba[][4], GLubyte rgba[][4] ); #endif diff --git a/xc/extras/Mesa/src/texutil.c b/xc/extras/Mesa/src/texutil.c index 67805c8d7..eb310ee55 100644 --- a/xc/extras/Mesa/src/texutil.c +++ b/xc/extras/Mesa/src/texutil.c @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -586,6 +586,7 @@ _mesa_convert_teximage(MesaIntTexFormat dstFormat, break; case MESA_A8_R8_G8_B8: + case MESA_FF_R8_G8_B8: /* 32-bit texels */ if (srcFormat == GL_BGRA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV){ /* special, optimized case */ @@ -661,13 +662,63 @@ _mesa_convert_teximage(MesaIntTexFormat dstFormat, } } } + else if (srcFormat == GL_RGB && srcType == GL_UNSIGNED_BYTE) { + /* general case */ + if (wScale == 1 && hScale == 1) { + const GLubyte *src = _mesa_image_address(packing, srcImage, + srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0); + const GLint srcStride = _mesa_image_row_stride(packing, + srcWidth, srcFormat, srcType); + GLuint *dst = dstImage; + GLint row; + for (row = 0; row < dstHeight; row++) { + GLint col, col3; + for (col = col3 = 0; col < dstWidth; col++, col3 += 3) { + GLubyte r = src[col3 + 0]; + GLubyte g = src[col3 + 1]; + GLubyte b = src[col3 + 2]; + GLubyte a = 255; + dst[col] = (a << 24) | (r << 16) | (g << 8) | b; + } + src += srcStride; + dst = (GLuint *) ((GLubyte *) dst + dstRowStride); + } + } + else { + /* must rescale image */ + GLuint *dst = dstImage; + GLint row; + for (row = 0; row < dstHeight; row++) { + GLint srcRow = row / hScale; + const GLubyte *src = _mesa_image_address(packing, srcImage, + srcWidth, srcHeight, srcFormat, srcType, 0, srcRow, 0); + GLint col; + for (col = 0; col < dstWidth; col++) { + GLint col3 = (col / wScale) * 3; + GLubyte r = src[col3 + 0]; + GLubyte g = src[col3 + 1]; + GLubyte b = src[col3 + 2]; + GLubyte a = 255; + dst[col] = (a << 24) | (r << 16) | (g << 8) | b; + } + dst = (GLuint *) ((GLubyte *) dst + dstRowStride); + } + } + } else { /* can't handle this source format/type combination */ return GL_FALSE; } + if (dstFormat == MESA_FF_R8_G8_B8) { + /* set alpha bytes to 0xff */ + GLuint i; + GLubyte *dst = (GLubyte *) dstImage; + for (i = 0; i < dstWidth * dstHeight; i++) { + dst[i * 4 + 3] = 0xff; + } + } break; - default: /* unexpected internal format! */ return GL_FALSE; @@ -1140,6 +1191,7 @@ _mesa_convert_texsubimage(MesaIntTexFormat dstFormat, break; case MESA_A8_R8_G8_B8: + case MESA_FF_R8_G8_B8: /* 32-bit texels */ if (srcFormat == GL_BGRA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV){ /* special, optimized case */ @@ -1223,6 +1275,18 @@ _mesa_convert_texsubimage(MesaIntTexFormat dstFormat, /* can't handle this source format/type combination */ return GL_FALSE; } + if (dstFormat == MESA_FF_R8_G8_B8) { + /* set alpha bytes to 0xff */ + GLint row, col; + GLubyte *dst = (GLubyte *) dstImage + + dstYoffset * dstRowStride + dstXoffset; + for (row = 0; row < height; row++) { + for (col = 0; col < width; col++) { + dst[col * 4 + 3] = 0xff; + } + dst = dst + dstRowStride; + } + } break; @@ -1491,6 +1555,7 @@ _mesa_unconvert_teximage(MesaIntTexFormat srcFormat, } break; case MESA_A8_R8_G8_B8: + case MESA_FF_R8_G8_B8: ASSERT(dstFormat == GL_RGBA); if (wScale == 1 && hScale == 1) { GLint i, n = dstWidth * dstHeight; @@ -1546,6 +1611,7 @@ _mesa_set_teximage_component_sizes(MesaIntTexFormat mesaFormat, { MESA_A4_R4_G4_B4, 4, 4, 4, 4, 0, 0, 0 }, { MESA_A1_R5_G5_B5, 5, 5, 5, 1, 0, 0, 0 }, { MESA_A8_R8_G8_B8, 8, 8, 8, 8, 0, 0, 0 }, + { MESA_FF_R8_G8_B8, 8, 8, 8, 8, 0, 0, 0 }, { -1, 0, 0, 0, 0, 0, 0, 0 } }; GLint i; diff --git a/xc/extras/Mesa/src/texutil.h b/xc/extras/Mesa/src/texutil.h index 5f000be60..22e916d50 100644 --- a/xc/extras/Mesa/src/texutil.h +++ b/xc/extras/Mesa/src/texutil.h @@ -1,7 +1,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -32,6 +32,9 @@ +/* + * NOTE: "FF" means fill with byte value 0xff + */ /* msb <------ TEXEL BITS -----------> lsb */ typedef enum { /* ---- ---- ---- ---- ---- ---- ---- ---- */ MESA_I8, /* IIII IIII */ @@ -42,7 +45,8 @@ typedef enum { /* ---- ---- ---- ---- ---- ---- ---- ---- */ MESA_R5_G6_B5, /* RRRR RGGG GGGB BBBB */ MESA_A4_R4_G4_B4, /* AAAA RRRR GGGG BBBB */ MESA_A1_R5_G5_B5, /* ARRR RRGG GGGB BBBB */ - MESA_A8_R8_G8_B8 /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */ + MESA_A8_R8_G8_B8, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */ + MESA_FF_R8_G8_B8 /* FFFF FFFF RRRR RRRR GGGG GGGG BBBB BBBB */ } MesaIntTexFormat; diff --git a/xc/extras/Mesa/src/triangle.c b/xc/extras/Mesa/src/triangle.c index 29f85a4ef..04c91bdc0 100644 --- a/xc/extras/Mesa/src/triangle.c +++ b/xc/extras/Mesa/src/triangle.c @@ -1534,7 +1534,8 @@ void gl_set_triangle_function( GLcontext *ctx ) && image->Border==0 && ((format = image->Format)==GL_RGB || format==GL_RGBA) && (filter = current2Dtex->MinFilter)==current2Dtex->MagFilter - && ctx->Light.Model.ColorControl==GL_SINGLE_COLOR) { + && ctx->Light.Model.ColorControl==GL_SINGLE_COLOR + && ctx->Texture.Unit[0].EnvMode!=GL_COMBINE_EXT) { if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) { diff --git a/xc/extras/Mesa/src/tritemp.h b/xc/extras/Mesa/src/tritemp.h index 61e040365..25f0f2b57 100644 --- a/xc/extras/Mesa/src/tritemp.h +++ b/xc/extras/Mesa/src/tritemp.h @@ -146,10 +146,17 @@ const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; /* Do backface culling */ - if (area * bf < 0 || area * area < .0025) + if (area * bf < 0.0) return; - oneOverArea = 1.0F / area; + if (area == 0.0F) + return; + + /* check for very tiny triangle */ + if (area * area < 0.0025F) /* square it to ensure positive value */ + oneOverArea = 1.0F / 0.0025F; /* a close-enough value */ + else + oneOverArea = 1.0F / area; } #ifndef DO_OCCLUSION_TEST diff --git a/xc/extras/Mesa/src/types.h b/xc/extras/Mesa/src/types.h index c44d602b9..ada9fd745 100644 --- a/xc/extras/Mesa/src/types.h +++ b/xc/extras/Mesa/src/types.h @@ -2,7 +2,7 @@ /* * Mesa 3-D graphics library - * Version: 3.3 + * Version: 3.4 * * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * @@ -831,9 +831,18 @@ struct gl_texture_unit { GLuint Enabled; GLuint ReallyEnabled; - GLenum EnvMode; /* GL_MODULATE, GL_DECAL, GL_BLEND */ + GLenum EnvMode; /* GL_MODULATE, GL_DECAL, GL_BLEND, GL_COMBINE_EXT */ GLenum LastEnvMode; + GLenum CombineSourceRGB[3]; /* arg[i] for rgb EXT_texture_combine */ + GLenum CombineSourceA[3]; /* dito for alpha combiner */ + GLenum CombineModeRGB; /* GL_REPLACE, GL_DECAL, GL_ADD ... */ + GLenum CombineModeA; + GLenum CombineOperandRGB[3]; /* SRC_COLOR or ONE_MINUS_SRC_COLOR */ + GLenum CombineOperandA[3]; /* SRC_ALPHA or ONE_MINUS_SRC_ALPHA */ + GLuint CombineScaleShiftRGB; /* 0, 1 or 2 */ + GLuint CombineScaleShiftA; + GLfloat EnvColor[4]; GLuint TexGenEnabled; /* Bitwise-OR of [STRQ]_BIT values */ GLenum GenModeS; /* Tex coord generation mode, either */ @@ -868,6 +877,7 @@ struct gl_texture_unit { struct gl_texture_object Saved1D; /* only used by glPush/PopAttrib */ struct gl_texture_object Saved2D; struct gl_texture_object Saved3D; + struct gl_texture_object SavedCubeMap; }; @@ -1259,6 +1269,8 @@ struct gl_shared_state { /* Default texture objects (shared by all multi-texture units) */ struct gl_texture_object *DefaultD[4]; struct gl_texture_object *DefaultCubeMap; + + void *DriverData; /* Device driver shared state */ }; @@ -1365,6 +1377,7 @@ struct gl_extensions { struct extension *ext_list; /* flags to quickly test if certain extensions are available */ GLboolean HaveTextureEnvAdd; + GLboolean HaveTextureEnvCombine; GLboolean HaveTextureLodBias; GLboolean HaveHpOcclusionTest; GLboolean HaveTextureCubeMap; @@ -1520,10 +1533,7 @@ struct gl_extensions { * shared with the cull mode (ie. cull_mask_active and * compacted_normals.) */ -#define SHADE_RGBA_VERTICES 0x4 -#define SHADE_RGBA_NORMALS 0x8 -#define SHADE_RGBA_SPEC 0xc /* note - not a seperate bit */ -#define SHADE_TWOSIDE 0x10 +#define SHADE_TWOSIDE 0x4 /* Flags for selecting a normal transformation function. */ @@ -1778,7 +1788,7 @@ struct gl_context { GLmatrix ProjectionMatrix; /* current matrix, not stored on stack */ GLuint ProjectionStackDepth; GLmatrix ProjectionStack[MAX_PROJECTION_STACK_DEPTH - 1]; - GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH - 1][2]; + GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH][2]; /* Combined modelview and projection matrix */ GLmatrix ModelProjectMatrix; @@ -1825,18 +1835,18 @@ struct gl_context { struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH]; /* Renderer attribute groups */ - struct gl_accum_attrib Accum; + struct gl_accum_attrib Accum; struct gl_colorbuffer_attrib Color; struct gl_current_attrib Current; struct gl_depthbuffer_attrib Depth; - struct gl_eval_attrib Eval; + struct gl_eval_attrib Eval; struct gl_fog_attrib Fog; - struct gl_hint_attrib Hint; - struct gl_light_attrib Light; - struct gl_line_attrib Line; - struct gl_list_attrib List; - struct gl_pixel_attrib Pixel; - struct gl_point_attrib Point; + struct gl_hint_attrib Hint; + struct gl_light_attrib Light; + struct gl_line_attrib Line; + struct gl_list_attrib List; + struct gl_pixel_attrib Pixel; + struct gl_point_attrib Point; struct gl_polygon_attrib Polygon; GLuint PolygonStipple[32]; struct gl_scissor_attrib Scissor; @@ -1847,23 +1857,23 @@ struct gl_context { /* Other attribute groups */ struct gl_histogram_attrib Histogram; - struct gl_minmax_attrib MinMax; - struct gl_convolution_attrib Convolution1D; - struct gl_convolution_attrib Convolution2D; - struct gl_convolution_attrib Separable2D; + struct gl_minmax_attrib MinMax; + struct gl_convolution_attrib Convolution1D; + struct gl_convolution_attrib Convolution2D; + struct gl_convolution_attrib Separable2D; /* Client attribute stack */ GLuint ClientAttribStackDepth; struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH]; /* Client attribute groups */ - struct gl_array_attrib Array; /* Vertex arrays */ + struct gl_array_attrib Array; /* Vertex arrays */ struct gl_pixelstore_attrib Pack; /* Pixel packing */ struct gl_pixelstore_attrib Unpack; /* Pixel unpacking */ - struct gl_evaluators EvalMap; /* All evaluators */ - struct gl_feedback Feedback; /* Feedback */ - struct gl_selection Select; /* Selection */ + struct gl_evaluators EvalMap; /* All evaluators */ + struct gl_feedback Feedback; /* Feedback */ + struct gl_selection Select; /* Selection */ struct gl_color_table ColorTable; /* Pre-convolution */ struct gl_color_table ProxyColorTable; /* Pre-convolution */ @@ -1878,21 +1888,21 @@ struct gl_context { struct gl_fallback_arrays Fallback; - GLenum ErrorValue; /* Last error code */ + GLenum ErrorValue; /* Last error code */ /* Miscellaneous */ - GLuint NewState; /* bitwise OR of NEW_* flags */ - GLuint Enabled; /* bitwise or of ENABLE_* flags */ - GLenum RenderMode; /* either GL_RENDER, GL_SELECT, GL_FEEDBACK */ - GLuint StippleCounter; /* Line stipple counter */ - GLuint RasterMask; /* OR of rasterization flags */ + GLuint NewState; /* bitwise OR of NEW_* flags */ + GLuint Enabled; /* bitwise or of ENABLE_* flags */ + GLenum RenderMode; /* either GL_RENDER, GL_SELECT, GL_FEEDBACK */ + GLuint StippleCounter; /* Line stipple counter */ + GLuint RasterMask; /* OR of rasterization flags */ GLuint TriangleCaps; /* OR of DD_* flags */ GLuint IndirectTriangles; /* TriangleCaps not handled by the driver */ - GLfloat PolygonZoffset; /* Z offset for GL_FILL polygons */ - GLfloat LineZoffset; /* Z offset for GL_LINE polygons */ - GLfloat PointZoffset; /* Z offset for GL_POINT polygons */ - GLboolean NeedNormals; /* Are vertex normal vectors needed? */ - GLuint FogMode; /* FOG_OFF, FOG_VERTEX or FOG_FRAGMENT */ + GLfloat PolygonZoffset; /* Z offset for GL_FILL polygons */ + GLfloat LineZoffset; /* Z offset for GL_LINE polygons */ + GLfloat PointZoffset; /* Z offset for GL_POINT polygons */ + GLboolean NeedNormals; /* Are vertex normal vectors needed? */ + GLuint FogMode; /* FOG_OFF, FOG_VERTEX or FOG_FRAGMENT */ GLboolean DoViewportMapping; @@ -1906,8 +1916,8 @@ struct gl_context { normal_func *NormalTransform; - /* Current shading function */ - GLuint shade_func_flags; + /* Current shading function table */ + gl_shade_func *shade_func_tab; GLfloat EyeZDir[3]; GLfloat rescale_factor; diff --git a/xc/extras/Mesa/src/varray.c b/xc/extras/Mesa/src/varray.c index 7df2603b1..5915cdb97 100644 --- a/xc/extras/Mesa/src/varray.c +++ b/xc/extras/Mesa/src/varray.c @@ -375,7 +375,6 @@ _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *ptr) { (void) count; - printf("glVertexPointerEXT %p\n", ptr); _mesa_VertexPointer(size, type, stride, ptr); } diff --git a/xc/extras/Mesa/src/vb.c b/xc/extras/Mesa/src/vb.c index 7dcb64b10..18ca16b14 100644 --- a/xc/extras/Mesa/src/vb.c +++ b/xc/extras/Mesa/src/vb.c @@ -43,9 +43,9 @@ struct vertex_buffer *gl_vb_create_for_immediate( GLcontext *ctx ) { struct vertex_buffer *VB; struct immediate *IM; - GLuint alignment = 32; + const GLuint alignment = 32; - VB = CALLOC_STRUCT(vertex_buffer); + VB = ALIGN_CALLOC_STRUCT( vertex_buffer, alignment ); if (!VB) return 0; @@ -63,14 +63,14 @@ struct vertex_buffer *gl_vb_create_for_immediate( GLcontext *ctx ) gl_vector4ub_alloc( &VB->BColor, VEC_WRITABLE, VB_SIZE, alignment ); gl_vector1ui_alloc( &VB->BIndex, VEC_WRITABLE, VB_SIZE, alignment ); - VB->ClipMask = (GLubyte *)MALLOC(sizeof(GLubyte) * VB_SIZE); - VB->UserClipMask = (GLubyte *)CALLOC(sizeof(GLubyte) * VB_SIZE); - VB->CullMask = (GLubyte *)MALLOC(sizeof(GLubyte) * VB_SIZE); - VB->NormCullMask = (GLubyte *)MALLOC(sizeof(GLubyte) * VB_SIZE); - VB->Spec[0] = (GLubyte (*)[4])MALLOC(sizeof(GLubyte) * 4 * VB_SIZE); - VB->Spec[1] = (GLubyte (*)[4])MALLOC(sizeof(GLubyte) * 4 * VB_SIZE); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * VB_SIZE, alignment); + VB->UserClipMask = (GLubyte *) ALIGN_CALLOC(sizeof(GLubyte) * VB_SIZE, alignment); + VB->CullMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * VB_SIZE, alignment); + VB->NormCullMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * VB_SIZE, alignment); + VB->Spec[0] = (GLubyte (*)[4]) ALIGN_MALLOC(sizeof(GLubyte) * 4 * VB_SIZE, alignment); + VB->Spec[1] = (GLubyte (*)[4]) ALIGN_MALLOC(sizeof(GLubyte) * 4 * VB_SIZE, alignment); - IM = VB->IM = gl_immediate_alloc( ctx ); + IM = VB->IM = gl_immediate_alloc(ctx); VB->store.Obj = &IM->v.Obj; VB->store.Normal = &IM->v.Normal; @@ -105,7 +105,7 @@ struct vertex_buffer *gl_vb_create_for_cva( GLcontext *ctx, GLuint size ) struct vertex_buffer *VB; GLuint alignment = 32; - VB = CALLOC_STRUCT(vertex_buffer); + VB = ALIGN_CALLOC_STRUCT( vertex_buffer, alignment ); if (!VB) return 0; @@ -121,11 +121,14 @@ struct vertex_buffer *gl_vb_create_for_cva( GLcontext *ctx, GLuint size ) VB->ClipAndMask = CLIP_ALL_BITS; VB->pipeline = &ctx->CVA.pre; - VB->ClipMask = (GLubyte *)MALLOC(sizeof(GLubyte) * size); - VB->UserClipMask = (GLubyte *)CALLOC(sizeof(GLubyte) * size); - VB->Spec[0] = (GLubyte (*)[4])MALLOC(sizeof(GLubyte) * 4 * size); - VB->Spec[1] = (GLubyte (*)[4])MALLOC(sizeof(GLubyte) * 4 * size); - VB->Flag = (GLuint *)MALLOC(sizeof(GLuint) * size); + VB->ClipMask = (GLubyte *)ALIGN_MALLOC( sizeof(GLubyte) * size, alignment ); + VB->UserClipMask = (GLubyte *)ALIGN_CALLOC( sizeof(GLubyte) * size, + alignment ); + VB->Spec[0] = (GLubyte (*)[4])ALIGN_MALLOC( sizeof(GLubyte) * 4 * size, + alignment ); + VB->Spec[1] = (GLubyte (*)[4])ALIGN_MALLOC( sizeof(GLubyte) * 4 * size, + alignment ); + VB->Flag = (GLuint *)ALIGN_MALLOC( sizeof(GLuint) * size, alignment ); gl_vector4f_alloc( &VB->Eye, 2, VEC_WRITABLE, size, alignment ); gl_vector4f_alloc( &VB->Clip, 2, VEC_WRITABLE, size, alignment ); @@ -201,8 +204,8 @@ void gl_vb_free( struct vertex_buffer *VB ) if ( ! --VB->IM->ref_count ) gl_immediate_free( VB->IM ); - FREE( VB->CullMask ); - FREE( VB->NormCullMask ); + ALIGN_FREE( VB->CullMask ); + ALIGN_FREE( VB->NormCullMask ); } else { if (VB->store.Elt) gl_vector4f_free( VB->store.Obj ); FREE( VB->store.Obj ); @@ -221,22 +224,22 @@ void gl_vb_free( struct vertex_buffer *VB ) gl_vector1ui_free( VB->FoggedIndex[0] ); FREE( VB->FoggedIndex[0] ); gl_vector1ui_free( VB->FoggedIndex[1] ); FREE( VB->FoggedIndex[1] ); - FREE( VB->Flag ); + ALIGN_FREE( VB->Flag ); } - if (VB->tmp_f) FREE(VB->tmp_f); - if (VB->tmp_m) FREE(VB->tmp_m); - if (VB->EvaluatedFlags) FREE(VB->EvaluatedFlags); + if (VB->tmp_f) FREE( VB->tmp_f ); + if (VB->tmp_m) FREE( VB->tmp_m ); + if (VB->EvaluatedFlags) FREE( VB->EvaluatedFlags ); - FREE( VB->Spec[0] ); - FREE( VB->Spec[1] ); - FREE( VB->ClipMask ); - FREE( VB->UserClipMask ); + ALIGN_FREE( VB->Spec[0] ); + ALIGN_FREE( VB->Spec[1] ); + ALIGN_FREE( VB->ClipMask ); + ALIGN_FREE( VB->UserClipMask ); if (VB->ctx->Driver.UnregisterVB) VB->ctx->Driver.UnregisterVB( VB ); - FREE( VB ); + ALIGN_FREE( VB ); } @@ -254,7 +257,7 @@ struct immediate *gl_immediate_alloc( GLcontext *ctx ) return IM; } - IM = MALLOC_STRUCT(immediate); + IM = ALIGN_MALLOC_STRUCT( immediate, 32 ); if (!IM) return 0; @@ -272,7 +275,7 @@ struct immediate *gl_immediate_alloc( GLcontext *ctx ) IM->Material = 0; IM->MaterialMask = 0; #ifdef VMS - for (j=0; j<VB_SIZE ; j++ ) + for (j = 0; j < VB_SIZE; j++) IM->Normal[j][0] = IM->Normal[j][1] = IM->Normal[j][2] = 0.0; #endif @@ -323,7 +326,7 @@ void gl_immediate_free( struct immediate *IM ) if (MESA_VERBOSE&VERBOSE_IMMEDIATE) fprintf(stderr, "really free immediate %d\n", IM->id); - FREE( IM ); + ALIGN_FREE( IM ); } else { if (MESA_VERBOSE&VERBOSE_IMMEDIATE) diff --git a/xc/extras/Mesa/src/vbcull.c b/xc/extras/Mesa/src/vbcull.c index 927e485c6..61c8ea9eb 100644 --- a/xc/extras/Mesa/src/vbcull.c +++ b/xc/extras/Mesa/src/vbcull.c @@ -92,7 +92,7 @@ static GLuint gl_cull_points( struct vertex_buffer *VB, /* This is pretty pointless. (arf arf) */ - for (i=start+1;i<count;i++) { + for (i = start; i < count; i++) { if (clipmask[i] == 0) cullmask[i] = VERT_FACE_FRONT | PRIM_FACE_FRONT; else { @@ -783,6 +783,7 @@ void gl_purge_vertices( struct vertex_buffer *VB ) #define VERT_NOT_CLIPPED 0x80 + static void build_clip_vert_bits( GLubyte *clipmask, const GLubyte *cullmask, GLuint count ) { @@ -842,7 +843,6 @@ GLuint gl_cull_vb( struct vertex_buffer *VB ) cullcount += n; } - if (VB->LastPrimitive < VB->Count) { if (copy_tab_cull[lastprim]) cullcount -= copy_tab_cull[prim]( VB, @@ -862,8 +862,8 @@ GLuint gl_cull_vb( struct vertex_buffer *VB ) if (cullcount < VB->Count) build_clip_vert_bits( VB->ClipMask, VB->CullMask, VB->Count ); - } + if (VB->ClipOrMask) { VB->CullMode |= CLIP_MASK_ACTIVE; VB->CullFlag[1] |= (CLIP_ALL_BITS|CLIP_USER_BIT) & ctx->AllowVertexCull; diff --git a/xc/extras/Mesa/src/vbfill.c b/xc/extras/Mesa/src/vbfill.c index 4ee9d52a3..50d5806d5 100644 --- a/xc/extras/Mesa/src/vbfill.c +++ b/xc/extras/Mesa/src/vbfill.c @@ -693,6 +693,20 @@ _mesa_Indexubv( const GLubyte *c ) ASSIGN_3V(normal, x,y,z); \ } +#if defined(USE_IEEE) +#define NORMALF( x, y, z ) \ +{ \ + GLuint count; \ + GLint *normal; \ + GET_IMMEDIATE; \ + count = IM->Count; \ + IM->Flag[count] |= VERT_NORM; \ + normal = (GLint *)IM->Normal[count]; \ + ASSIGN_3V(normal, *(int*)&(x), *(int*)&(y), *(int*)&(z)); \ +} +#else +#define NORMALF NORMAL +#endif void _mesa_Normal3b( GLbyte nx, GLbyte ny, GLbyte nz ) @@ -711,7 +725,7 @@ _mesa_Normal3d( GLdouble nx, GLdouble ny, GLdouble nz ) void _mesa_Normal3f( GLfloat nx, GLfloat ny, GLfloat nz ) { - NORMAL(nx, ny, nz); + NORMALF(nx, ny, nz); } @@ -746,7 +760,7 @@ _mesa_Normal3dv( const GLdouble *v ) void _mesa_Normal3fv( const GLfloat *v ) { - NORMAL( v[0], v[1], v[2] ); + NORMALF( v[0], v[1], v[2] ); } @@ -811,6 +825,23 @@ _mesa_Normal3sv( const GLshort *v ) ASSIGN_4V(tc, s,t,u,v); \ } +#if defined(USE_IEEE) +#define TEXCOORD2F(s,t) \ +{ \ + GLuint count; \ + GLint *tc; \ + GET_IMMEDIATE; \ + count = IM->Count; \ + IM->Flag[count] |= VERT_TEX0_12; \ + tc = (GLint *)IM->TexCoord[0][count]; \ + *tc = *(int *)&(s); \ + *(tc+1) = *(int *)&(t); \ + *(tc+2) = 0; \ + *(tc+3) = IEEE_ONE; \ +} +#else +#define TEXCOORD2F TEXCOORD2 +#endif void _mesa_TexCoord1d( GLdouble s ) @@ -850,7 +881,7 @@ _mesa_TexCoord2d( GLdouble s, GLdouble t ) void _mesa_TexCoord2f( GLfloat s, GLfloat t ) { - TEXCOORD2(*(&s),*&t); + TEXCOORD2F(s,t); } @@ -962,7 +993,7 @@ _mesa_TexCoord2dv( const GLdouble *v ) void _mesa_TexCoord2fv( const GLfloat *v ) { - TEXCOORD2(v[0],v[1]); + TEXCOORD2F(v[0],v[1]); } @@ -1072,6 +1103,22 @@ _mesa_TexCoord4sv( const GLshort *v ) IM->maybe_transform_vb( IM ); \ } +#if defined(USE_IEEE) +#define VERTEX3F(IM,x,y,z) \ +{ \ + GLuint count = IM->Count++; \ + GLint *dest = (GLint *)IM->Obj[count]; \ + IM->Flag[count] |= VERT_OBJ_23; \ + dest[0] = *(int *)&(x); \ + dest[1] = *(int *)&(y); \ + dest[2] = *(int *)&(z); \ + dest[3] = IEEE_ONE; \ + if (dest == (GLint *)IM->Obj[VB_MAX-1]) \ + IM->maybe_transform_vb( IM ); \ +} +#else +#define VERTEX3F VERTEX3 +#endif void _mesa_Vertex2d( GLdouble x, GLdouble y ) @@ -1127,7 +1174,7 @@ void _mesa_Vertex3f( GLfloat x, GLfloat y, GLfloat z ) { GET_IMMEDIATE; - VERTEX3( IM, *(&x), *(&y), *(&z) ); + VERTEX3F( IM, x, y, z ); } @@ -1159,7 +1206,7 @@ void _mesa_Vertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ) { GET_IMMEDIATE; - VERTEX4( IM, *(&x), *(&y), *(&z), *(&w) ); + VERTEX4( IM, x, y, z, w ); } @@ -1223,7 +1270,7 @@ void _mesa_Vertex3fv( const GLfloat *v ) { GET_IMMEDIATE; - VERTEX3( IM, v[0], v[1], v[2] ); + VERTEX3F( IM, v[0], v[1], v[2] ); } @@ -1347,6 +1394,22 @@ _mesa_Vertex4sv( const GLshort *v ) ASSIGN_4V(tc, s,t,u,v); \ } +#if defined(USE_IEEE) +#define MULTI_TEXCOORD2F(s,t) \ +{ \ + GLuint count; \ + GLint *tc; \ + count = IM->Count; \ + IM->Flag[count] |= IM->TF2[texSet]; \ + tc = (GLint *)IM->TexCoord[texSet][count]; \ + tc[0] = *(int *)&(s); \ + tc[1] = *(int *)&(t); \ + tc[2] = 0; \ + tc[3] = IEEE_ONE; \ +} +#else +#define MULTI_TEXCOORD2F MULTI_TEXCOORD2 +#endif void _mesa_MultiTexCoord1dARB(GLenum target, GLdouble s) @@ -1444,7 +1507,7 @@ _mesa_MultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t) GLint texSet; GET_IMMEDIATE; CHECK_ARB - MULTI_TEXCOORD2( s, t ); + MULTI_TEXCOORD2F( s, t ); } void @@ -1453,7 +1516,7 @@ _mesa_MultiTexCoord2fvARB(GLenum target, const GLfloat *v) GLint texSet; GET_IMMEDIATE; CHECK_ARB - MULTI_TEXCOORD2( v[0], v[1] ); + MULTI_TEXCOORD2F( v[0], v[1] ); } void diff --git a/xc/extras/Mesa/src/vbrender.c b/xc/extras/Mesa/src/vbrender.c index dd1ae5159..5391ff186 100644 --- a/xc/extras/Mesa/src/vbrender.c +++ b/xc/extras/Mesa/src/vbrender.c @@ -100,20 +100,14 @@ static INLINE void gl_render_clipped_line2( GLcontext *ctx, static void offset_polygon( GLcontext *ctx, GLfloat a, GLfloat b, GLfloat c ) { GLfloat ac, bc, m; - GLfloat offset; + GLfloat offset = 0.0F; - if (c<0.001F && c>-0.001F) { - /* to prevent underflow problems */ - offset = 0.0F; - } - else { + if (c*c > 1e-16) { ac = a / c; bc = b / c; if (ac<0.0F) ac = -ac; if (bc<0.0F) bc = -bc; m = MAX2( ac, bc ); - /* m = sqrt( ac*ac + bc*bc ); */ - offset = m * ctx->Polygon.OffsetFactor + ctx->Polygon.OffsetUnits; } @@ -125,10 +119,17 @@ static void offset_polygon( GLcontext *ctx, GLfloat a, GLfloat b, GLfloat c ) #define FLUSH_PRIM(prim) \ do { \ if (ctx->PB->primitive != prim) { \ - gl_reduced_prim_change( ctx, prim ); \ + gl_reduced_prim_change( ctx, prim ); \ } \ } while(0) +#define FLUSH_POLY(prim) \ +do { \ + if ((ctx->IndirectTriangles & DD_TRI_UNFILLED) == 0) { \ + FLUSH_PRIM(prim); \ + } \ +} while(0) + /* * When glPolygonMode() is used to specify that the front/back rendering @@ -156,7 +157,6 @@ static void unfilled_polygon( GLcontext *ctx, } else if (mode==GL_LINE) { GLuint i, j0, j1; - ctx->StippleCounter = 0; /* draw the edges */ for (i=0;i<n-1;i++) { @@ -319,6 +319,13 @@ static void render_triangle( GLcontext *ctx, else { (*ctx->Driver.TriangleFunc)( ctx, v0, v1, v2, pv ); } + + if (tricaps & DD_TRI_OFFSET) { + /* reset Z offsets now */ + ctx->PointZoffset = 0.0; + ctx->LineZoffset = 0.0; + ctx->PolygonZoffset = 0.0; + } } @@ -377,6 +384,13 @@ static void render_quad( GLcontext *ctx, GLuint v0, GLuint v1, else { (*ctx->Driver.QuadFunc)( ctx, v0, v1, v2, v3, pv ); } + + if (tricaps & DD_TRI_OFFSET) { + /* reset Z offsets now */ + ctx->PointZoffset = 0.0; + ctx->LineZoffset = 0.0; + ctx->PolygonZoffset = 0.0; + } } @@ -415,15 +429,16 @@ do { \ #define EDGEFLAG_POLY_TRI_PRE( i2, i1, i, pv) \ do { \ + eflag[i2] |= (eflag[i2] >> 2) & 1; \ eflag[i1] |= (eflag[i1] >> 2) & 1; \ eflag[i] |= (eflag[i] >> 2) & 2; \ } while (0) #define EDGEFLAG_POLY_TRI_POST( i2, i1, i, pv) \ do { \ - eflag[i2] = 0; \ + eflag[i2] &= ~(4|1); \ eflag[i1] &= ~(4|1); \ - eflag[i] &= ~(8|2); \ + eflag[i] &= ~(8|2); \ } while (0) @@ -503,7 +518,7 @@ do { \ (void) vlist; (void) eflag; (void) stipplecounter; #define TAG(x) x##_cull -#define INIT(x) FLUSH_PRIM(x) +#define INIT(x) if (x == GL_POLYGON) FLUSH_POLY(x); else FLUSH_PRIM(x) #define RESET_STIPPLE *stipplecounter = 0 #include "render_tmp.h" @@ -541,7 +556,7 @@ do { \ GLuint *stipplecounter = &VB->ctx->StippleCounter; \ (void) eflag; (void) stipplecounter; -#define INIT(x) FLUSH_PRIM(x); +#define INIT(x) if (x == GL_POLYGON) FLUSH_POLY(x); else FLUSH_PRIM(x) #define RESET_STIPPLE *stipplecounter = 0 #include "render_tmp.h" @@ -575,7 +590,7 @@ do { \ GLuint *stipplecounter = &VB->ctx->StippleCounter; \ (void) eflag; (void) stipplecounter; -#define INIT(x) FLUSH_PRIM(x); +#define INIT(x) if (x == GL_POLYGON) FLUSH_POLY(x); else FLUSH_PRIM(x) #define TAG(x) x##_clipped #define RESET_STIPPLE *stipplecounter = 0 @@ -633,9 +648,9 @@ setup_edgeflag( struct vertex_buffer *VB, case GL_POLYGON: if (flag[0]) flag[0] = 0x1; for (i = 1 ; i < n-1 ; i++) { - if (flag[i]) flag[i] = 0x1<<2; + if (flag[i]) flag[i] = 0x4; } - if (flag[i]) flag[i] = 0x3<<2; + if (flag[i]) flag[i] = 0x8; break; default: break; diff --git a/xc/extras/Mesa/src/vector.c b/xc/extras/Mesa/src/vector.c index b63b8df69..954a4235a 100644 --- a/xc/extras/Mesa/src/vector.c +++ b/xc/extras/Mesa/src/vector.c @@ -68,6 +68,8 @@ static const GLubyte size_bits[5] = { VEC_SIZE_4, }; + + void gl_vector4f_init( GLvector4f *v, GLuint flags, GLfloat (*storage)[4] ) { v->stride = 4*sizeof(GLfloat); @@ -78,7 +80,6 @@ void gl_vector4f_init( GLvector4f *v, GLuint flags, GLfloat (*storage)[4] ) v->flags = size_bits[4] | flags | VEC_GOOD_STRIDE; } - void gl_vector3f_init( GLvector3f *v, GLuint flags, GLfloat (*storage)[3] ) { v->stride = 3*sizeof(GLfloat); @@ -116,13 +117,6 @@ void gl_vector1ui_init( GLvector1ui *v, GLuint flags, GLuint *storage ) } -#define ALIGN_MALLOC(vec, type, bytes, alignment) \ -do { \ - vec->storage = MALLOC( bytes + alignment - 1 ); \ - vec->start = type (((unsigned long)vec->storage + alignment - 1) \ - & ~(unsigned long)(alignment - 1)); \ -} while (0) - void gl_vector4f_alloc( GLvector4f *v, GLuint sz, GLuint flags, GLuint count, GLuint alignment ) @@ -130,18 +124,19 @@ void gl_vector4f_alloc( GLvector4f *v, GLuint sz, GLuint flags, GLuint count, (void) sz; v->stride = 4*sizeof(GLfloat); v->size = 2; - ALIGN_MALLOC(v, (GLfloat *), count * 4 * sizeof(GLfloat), alignment); + v->storage = v->start = (GLfloat *) + ALIGN_MALLOC( count * 4 * sizeof(GLfloat), alignment ); v->data = (GLfloat (*)[4])v->start; v->count = 0; v->flags = size_bits[4] | flags | VEC_MALLOC | VEC_GOOD_STRIDE; } - void gl_vector3f_alloc( GLvector3f *v, GLuint flags, GLuint count, GLuint alignment ) { v->stride = 3*sizeof(GLfloat); - ALIGN_MALLOC(v, (GLfloat *), count * 3 * sizeof(GLfloat), alignment); + v->storage = v->start = (GLfloat *) + ALIGN_MALLOC( count * 3 * sizeof(GLfloat), alignment ); v->data = (GLfloat (*)[3])v->start; v->count = 0; v->flags = flags | VEC_MALLOC | VEC_GOOD_STRIDE; @@ -151,7 +146,8 @@ void gl_vector4ub_alloc( GLvector4ub *v, GLuint flags, GLuint count, GLuint alignment ) { v->stride = 4*sizeof(GLubyte); - ALIGN_MALLOC(v, (GLubyte *), count * 4 * sizeof(GLubyte), alignment); + v->storage = v->start = (GLubyte *) + ALIGN_MALLOC( count * 4 * sizeof(GLubyte), alignment ); v->data = (GLubyte (*)[4])v->start; v->count = 0; v->flags = flags | VEC_MALLOC | VEC_GOOD_STRIDE; @@ -161,7 +157,8 @@ void gl_vector1ub_alloc( GLvector1ub *v, GLuint flags, GLuint count, GLuint alignment ) { v->stride = 1*sizeof(GLubyte); - ALIGN_MALLOC(v, (GLubyte *), count * sizeof(GLubyte), alignment); + v->storage = v->start = (GLubyte *) + ALIGN_MALLOC( count * sizeof(GLubyte), alignment ); v->data = v->start; v->count = 0; v->flags = flags | VEC_MALLOC | VEC_GOOD_STRIDE; @@ -171,7 +168,8 @@ void gl_vector1ui_alloc( GLvector1ui *v, GLuint flags, GLuint count, GLuint alignment ) { v->stride = 1*sizeof(GLuint); - ALIGN_MALLOC(v, (GLuint *), count * sizeof(GLuint), alignment); + v->storage = v->start = (GLuint *) + ALIGN_MALLOC( count * sizeof(GLuint), alignment ); v->data = v->start; v->count = 0; v->flags = flags | VEC_MALLOC | VEC_GOOD_STRIDE; @@ -182,7 +180,7 @@ void gl_vector1ui_alloc( GLvector1ui *v, GLuint flags, GLuint count, void gl_vector4f_free( GLvector4f *v ) { if (v->flags & VEC_MALLOC) { - FREE( v->storage ); + ALIGN_FREE( v->storage ); v->data = 0; v->start = 0; v->storage = 0; @@ -193,7 +191,7 @@ void gl_vector4f_free( GLvector4f *v ) void gl_vector3f_free( GLvector3f *v ) { if (v->flags & VEC_MALLOC) { - FREE( v->storage ); + ALIGN_FREE( v->storage ); v->data = 0; v->start = 0; v->storage = 0; @@ -204,7 +202,7 @@ void gl_vector3f_free( GLvector3f *v ) void gl_vector4ub_free( GLvector4ub *v ) { if (v->flags & VEC_MALLOC) { - FREE( v->storage ); + ALIGN_FREE( v->storage ); v->data = 0; v->start = 0; v->storage = 0; @@ -215,7 +213,7 @@ void gl_vector4ub_free( GLvector4ub *v ) void gl_vector1ub_free( GLvector1ub *v ) { if (v->flags & VEC_MALLOC) { - FREE( v->storage ); + ALIGN_FREE( v->storage ); v->data = 0; v->start = 0; v->storage = 0; @@ -226,7 +224,7 @@ void gl_vector1ub_free( GLvector1ub *v ) void gl_vector1ui_free( GLvector1ui *v ) { if (v->flags & VEC_MALLOC) { - FREE( v->storage ); + ALIGN_FREE( v->storage ); v->data = 0; v->start = 0; v->storage = 0; @@ -234,6 +232,8 @@ void gl_vector1ui_free( GLvector1ui *v ) } } + + void gl_vector4f_print( GLvector4f *v, GLubyte *cullmask, GLboolean culling ) { GLfloat c[4] = { 0, 0, 0, 1 }; @@ -282,7 +282,6 @@ void gl_vector4f_print( GLvector4f *v, GLubyte *cullmask, GLboolean culling ) } } - void gl_vector3f_print( GLvector3f *v, GLubyte *cullmask, GLboolean culling ) { GLfloat *d = (GLfloat *)v->data; diff --git a/xc/extras/Mesa/src/xform.h b/xc/extras/Mesa/src/xform.h index d8757b803..2f8843815 100644 --- a/xc/extras/Mesa/src/xform.h +++ b/xc/extras/Mesa/src/xform.h @@ -134,7 +134,7 @@ typedef void (*vec_copy_func)( GLvector4f *to, * parameter, to allow a unified interface. */ typedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec, - const GLmatrix *mat, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *clipmask, const GLubyte flag ); @@ -144,11 +144,11 @@ extern GLvector4f *gl_project_points( GLvector4f *to, const GLvector4f *from ); extern void gl_transform_bounds3( GLubyte *orMask, GLubyte *andMask, - const GLmatrix *mat, + const GLfloat m[16], CONST GLfloat src[][3] ); extern void gl_transform_bounds2( GLubyte *orMask, GLubyte *andMask, - const GLmatrix *mat, + const GLfloat m[16], CONST GLfloat src[][3] ); @@ -168,11 +168,11 @@ extern void gl_transform_point_sz( GLfloat Q[4], const GLfloat M[16], #define TransformRaw( to, mat, from ) \ - ( (*gl_transform_tab[0][(from)->size][(mat)->type])( to, mat, from, 0, 0 ), \ + ( (*gl_transform_tab[0][(from)->size][(mat)->type])( to, (mat)->m, from, 0, 0 ), \ (to) ) #define Transform( to, mat, from, mask, cull ) \ - ( (*gl_transform_tab[cull!=0][(from)->size][(mat)->type])( to, mat, from, mask, cull ), \ + ( (*gl_transform_tab[cull!=0][(from)->size][(mat)->type])( to, (mat)->m, from, mask, cull ), \ (to) ) diff --git a/xc/extras/Mesa/src/xform_tmp.h b/xc/extras/Mesa/src/xform_tmp.h index 2e796aac1..aacbee841 100644 --- a/xc/extras/Mesa/src/xform_tmp.h +++ b/xc/extras/Mesa/src/xform_tmp.h @@ -64,8 +64,9 @@ * cliped and/or culled vertices. */ -static void _XFORMAPI TAG(transform_points1_general)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_general)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -74,7 +75,6 @@ static void _XFORMAPI TAG(transform_points1_general)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m12 = m[12]; const GLfloat m1 = m[1], m13 = m[13]; const GLfloat m2 = m[2], m14 = m[14]; @@ -97,8 +97,9 @@ static void _XFORMAPI TAG(transform_points1_general)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points1_identity)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_identity)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -108,10 +109,8 @@ static void _XFORMAPI TAG(transform_points1_identity)( GLvector4f *to_vec, GLuint count = from_vec->count; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint i; - (void) mat; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_IDENTITY); if (to_vec == from_vec) return; STRIDE_LOOP { CLIP_CHECK { @@ -124,8 +123,9 @@ static void _XFORMAPI TAG(transform_points1_identity)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points1_2d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_2d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -134,13 +134,11 @@ static void _XFORMAPI TAG(transform_points1_2d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1]; const GLfloat m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0]; @@ -153,8 +151,9 @@ static void _XFORMAPI TAG(transform_points1_2d)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points1_2d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_2d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -163,12 +162,10 @@ static void _XFORMAPI TAG(transform_points1_2d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0]; @@ -182,8 +179,9 @@ static void _XFORMAPI TAG(transform_points1_2d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points1_3d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_3d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -192,13 +190,11 @@ static void _XFORMAPI TAG(transform_points1_3d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m2 = m[2]; const GLfloat m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0]; @@ -213,8 +209,9 @@ static void _XFORMAPI TAG(transform_points1_3d)( GLvector4f *to_vec, } -static void _XFORMAPI TAG(transform_points1_3d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_3d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -223,13 +220,11 @@ static void _XFORMAPI TAG(transform_points1_3d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0]; const GLfloat m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0]; @@ -243,8 +238,9 @@ static void _XFORMAPI TAG(transform_points1_3d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points1_perspective)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points1_perspective)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -253,12 +249,10 @@ static void _XFORMAPI TAG(transform_points1_perspective)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_PERSPECTIVE); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0]; @@ -280,8 +274,9 @@ static void _XFORMAPI TAG(transform_points1_perspective)( GLvector4f *to_vec, * present early in the geometry pipeline and throughout the * texture pipeline. */ -static void _XFORMAPI TAG(transform_points2_general)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_general)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -290,7 +285,6 @@ static void _XFORMAPI TAG(transform_points2_general)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m4 = m[4], m12 = m[12]; const GLfloat m1 = m[1], m5 = m[5], m13 = m[13]; const GLfloat m2 = m[2], m6 = m[6], m14 = m[14]; @@ -312,8 +306,9 @@ static void _XFORMAPI TAG(transform_points2_general)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points2_identity)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_identity)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -323,10 +318,8 @@ static void _XFORMAPI TAG(transform_points2_identity)( GLvector4f *to_vec, GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; GLuint i; - (void) mat; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_IDENTITY); if (to_vec == from_vec) return; STRIDE_LOOP { CLIP_CHECK { @@ -339,8 +332,9 @@ static void _XFORMAPI TAG(transform_points2_identity)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points2_2d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_2d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -349,13 +343,11 @@ static void _XFORMAPI TAG(transform_points2_2d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m4 = m[4], m5 = m[5]; const GLfloat m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1]; @@ -369,8 +361,9 @@ static void _XFORMAPI TAG(transform_points2_2d)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points2_2d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_2d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -379,12 +372,10 @@ static void _XFORMAPI TAG(transform_points2_2d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5], m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1]; @@ -398,8 +389,9 @@ static void _XFORMAPI TAG(transform_points2_2d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points2_3d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_3d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -408,13 +400,11 @@ static void _XFORMAPI TAG(transform_points2_3d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m2 = m[2], m4 = m[4], m5 = m[5]; const GLfloat m6 = m[6], m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1]; @@ -432,8 +422,9 @@ static void _XFORMAPI TAG(transform_points2_3d)( GLvector4f *to_vec, /* I would actually say this was a fairly important function, from * a texture transformation point of view. */ -static void _XFORMAPI TAG(transform_points2_3d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_3d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -442,13 +433,11 @@ static void _XFORMAPI TAG(transform_points2_3d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5]; const GLfloat m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1]; @@ -471,8 +460,9 @@ static void _XFORMAPI TAG(transform_points2_3d_no_rot)( GLvector4f *to_vec, * code. It's also hard to remove any of these functions if you are * attached to the assertions that have appeared in them. */ -static void _XFORMAPI TAG(transform_points2_perspective)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points2_perspective)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -481,12 +471,10 @@ static void _XFORMAPI TAG(transform_points2_perspective)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_PERSPECTIVE); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1]; @@ -503,8 +491,9 @@ static void _XFORMAPI TAG(transform_points2_perspective)( GLvector4f *to_vec, -static void _XFORMAPI TAG(transform_points3_general)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_general)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -513,7 +502,6 @@ static void _XFORMAPI TAG(transform_points3_general)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m4 = m[4], m8 = m[8], m12 = m[12]; const GLfloat m1 = m[1], m5 = m[5], m9 = m[9], m13 = m[13]; const GLfloat m2 = m[2], m6 = m[6], m10 = m[10], m14 = m[14]; @@ -521,7 +509,6 @@ static void _XFORMAPI TAG(transform_points3_general)( GLvector4f *to_vec, GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_GENERAL); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2]; @@ -536,8 +523,9 @@ static void _XFORMAPI TAG(transform_points3_general)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points3_identity)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_identity)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -547,10 +535,8 @@ static void _XFORMAPI TAG(transform_points3_identity)( GLvector4f *to_vec, GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; GLuint i; - (void) mat; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_IDENTITY); if (to_vec == from_vec) return; STRIDE_LOOP { CLIP_CHECK { @@ -564,8 +550,9 @@ static void _XFORMAPI TAG(transform_points3_identity)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points3_2d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_2d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -574,13 +561,11 @@ static void _XFORMAPI TAG(transform_points3_2d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m4 = m[4], m5 = m[5]; const GLfloat m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2]; @@ -594,8 +579,9 @@ static void _XFORMAPI TAG(transform_points3_2d)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points3_2d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_2d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -604,12 +590,10 @@ static void _XFORMAPI TAG(transform_points3_2d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5], m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2]; @@ -623,8 +607,9 @@ static void _XFORMAPI TAG(transform_points3_2d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points3_3d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_3d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -633,14 +618,12 @@ static void _XFORMAPI TAG(transform_points3_3d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m2 = m[2], m4 = m[4], m5 = m[5]; const GLfloat m6 = m[6], m8 = m[8], m9 = m[9], m10 = m[10]; const GLfloat m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2]; @@ -656,8 +639,9 @@ static void _XFORMAPI TAG(transform_points3_3d)( GLvector4f *to_vec, /* previously known as ortho... */ -static void _XFORMAPI TAG(transform_points3_3d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_3d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -666,13 +650,11 @@ static void _XFORMAPI TAG(transform_points3_3d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5]; const GLfloat m10 = m[10], m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2]; @@ -686,8 +668,9 @@ static void _XFORMAPI TAG(transform_points3_3d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points3_perspective)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points3_perspective)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -696,13 +679,11 @@ static void _XFORMAPI TAG(transform_points3_perspective)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5], m8 = m[8], m9 = m[9]; const GLfloat m10 = m[10], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_PERSPECTIVE); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2]; @@ -719,8 +700,9 @@ static void _XFORMAPI TAG(transform_points3_perspective)( GLvector4f *to_vec, -static void _XFORMAPI TAG(transform_points4_general)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_general)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -729,7 +711,6 @@ static void _XFORMAPI TAG(transform_points4_general)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m4 = m[4], m8 = m[8], m12 = m[12]; const GLfloat m1 = m[1], m5 = m[5], m9 = m[9], m13 = m[13]; const GLfloat m2 = m[2], m6 = m[6], m10 = m[10], m14 = m[14]; @@ -737,7 +718,6 @@ static void _XFORMAPI TAG(transform_points4_general)( GLvector4f *to_vec, GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_GENERAL); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3]; @@ -752,8 +732,9 @@ static void _XFORMAPI TAG(transform_points4_general)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points4_identity)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_identity)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -763,10 +744,8 @@ static void _XFORMAPI TAG(transform_points4_identity)( GLvector4f *to_vec, GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; GLuint i; - (void) mat; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_IDENTITY); if (to_vec == from_vec) return; STRIDE_LOOP { CLIP_CHECK { @@ -781,8 +760,9 @@ static void _XFORMAPI TAG(transform_points4_identity)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points4_2d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_2d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -791,13 +771,11 @@ static void _XFORMAPI TAG(transform_points4_2d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m4 = m[4], m5 = m[5]; const GLfloat m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3]; @@ -812,8 +790,9 @@ static void _XFORMAPI TAG(transform_points4_2d)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points4_2d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_2d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -822,12 +801,10 @@ static void _XFORMAPI TAG(transform_points4_2d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5], m12 = m[12], m13 = m[13]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_2D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3]; @@ -842,8 +819,9 @@ static void _XFORMAPI TAG(transform_points4_2d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points4_3d)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_3d)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -852,14 +830,12 @@ static void _XFORMAPI TAG(transform_points4_3d)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m1 = m[1], m2 = m[2], m4 = m[4], m5 = m[5]; const GLfloat m6 = m[6], m8 = m[8], m9 = m[9], m10 = m[10]; const GLfloat m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3]; @@ -874,8 +850,9 @@ static void _XFORMAPI TAG(transform_points4_3d)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points4_3d_no_rot)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_3d_no_rot)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -884,13 +861,11 @@ static void _XFORMAPI TAG(transform_points4_3d_no_rot)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5]; const GLfloat m10 = m[10], m12 = m[12], m13 = m[13], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_3D_NO_ROT); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3]; @@ -905,8 +880,9 @@ static void _XFORMAPI TAG(transform_points4_3d_no_rot)( GLvector4f *to_vec, to_vec->count = from_vec->count; } -static void _XFORMAPI TAG(transform_points4_perspective)( GLvector4f *to_vec, - const GLmatrix *mat, +static void _XFORMAPI +TAG(transform_points4_perspective)( GLvector4f *to_vec, + const GLfloat m[16], const GLvector4f *from_vec, const GLubyte *mask, const GLubyte flag ) @@ -915,13 +891,11 @@ static void _XFORMAPI TAG(transform_points4_perspective)( GLvector4f *to_vec, GLfloat *from = from_vec->start; GLfloat (*to)[4] = (GLfloat (*)[4])to_vec->start; GLuint count = from_vec->count; - const GLfloat *m = mat->m; const GLfloat m0 = m[0], m5 = m[5], m8 = m[8], m9 = m[9]; const GLfloat m10 = m[10], m14 = m[14]; GLuint i; (void) mask; (void) flag; - ASSERT(mat->type == MATRIX_PERSPECTIVE); STRIDE_LOOP { CLIP_CHECK { const GLfloat ox = from[0], oy = from[1], oz = from[2], ow = from[3]; diff --git a/xc/extras/rman/contrib/bennett.txt b/xc/extras/rman/contrib/bennett.txt index 072facbde..dd16e9305 100644 --- a/xc/extras/rman/contrib/bennett.txt +++ b/xc/extras/rman/contrib/bennett.txt @@ -3,7 +3,7 @@ *************** *** 1,5 **** --- 1,9 ---- - static char rcsid[] = "$Header: /home/ajax/dri-backup/xc/xc/extras/rman/contrib/bennett.txt,v 1.1 2000/07/10 20:49:22 alanh Exp $"; + static char rcsid[] = "$Header: /home/ajax/dri-backup/xc/xc/extras/rman/contrib/bennett.txt,v 1.2 2000/09/07 12:40:24 alanh Exp $"; + /* ELS: SearchDirs by "Edward L. Sutter" <els@sage.sage.att.com> */ + /* AB: HTMLHeader and HTMLFooter by Anne Bennett <anne@alcor.concordia.ca> */ diff --git a/xc/extras/rman/contrib/hman.pl b/xc/extras/rman/contrib/hman.pl index dfed39703..29b96a0d2 100755 --- a/xc/extras/rman/contrib/hman.pl +++ b/xc/extras/rman/contrib/hman.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -w #!/citi/gtfd/mach/bin/perl -w ############### -# $Id: hman.pl,v 1.1 2000/07/10 20:49:22 alanh Exp $ +# $Id: hman.pl,v 1.2 2000/09/07 12:40:24 alanh Exp $ # $Source: /home/ajax/dri-backup/xc/xc/extras/rman/contrib/hman.pl,v $ ############################################ # TODO: diff --git a/xc/extras/rman/contrib/http-rman.c b/xc/extras/rman/contrib/http-rman.c index 8ab82ee49..39dcee60b 100644 --- a/xc/extras/rman/contrib/http-rman.c +++ b/xc/extras/rman/contrib/http-rman.c @@ -1,4 +1,4 @@ -/* $Id: http-rman.c,v 1.1 2000/07/10 20:49:23 alanh Exp $ +/* $Id: http-rman.c,v 1.2 2000/09/07 12:40:24 alanh Exp $ * * Name: * http-rman.c -- a rudimentary man-page HTTP server diff --git a/xc/extras/rman/rman.1 b/xc/extras/rman/rman.1 index 7be339197..7e4c48cb2 100644 --- a/xc/extras/rman/rman.1 +++ b/xc/extras/rman/rman.1 @@ -266,4 +266,4 @@ University of California, Berkeley .br Computer Science Division .PP -Manual page last updated on $Date: 2000/07/10 20:49:14 $ +Manual page last updated on $Date: 2000/09/07 12:40:24 $ diff --git a/xc/extras/rman/rman.html b/xc/extras/rman/rman.html index 8ff15172b..af2ecd18f 100644 --- a/xc/extras/rman/rman.html +++ b/xc/extras/rman/rman.html @@ -317,6 +317,6 @@ developed at the<BR> University of California, Berkeley<BR> Computer Science Division -<P>Manual page last updated on $Date: 2000/07/10 20:49:21 $ +<P>Manual page last updated on $Date: 2000/09/07 12:40:24 $ </BODY></HTML> diff --git a/xc/lib/GL/Imakefile b/xc/lib/GL/Imakefile index 9c489b532..4c7f8566d 100644 --- a/xc/lib/GL/Imakefile +++ b/xc/lib/GL/Imakefile @@ -3,6 +3,7 @@ XCOMM $XFree86: xc/lib/GL/Imakefile,v 1.29 2000/07/02 19:23:34 dawes Exp $ #include <Threads.tmpl> #define IHaveSubdirs + #define PassCDebugFlags #define DoNormalLib NormalLibGlx @@ -52,6 +53,7 @@ NormalLintTarget($(PROFSRC)) DRMPOBJS = dri/drm/profiled/?*.o DRMDONES = dri/drm/DONE + MESAOBJS = mesa/src/?*.o #ifdef i386Architecture ASM_OBJS = mesa/src/X86/common_x86asm.o \ mesa/src/X86/mmx_blend.o \ @@ -70,9 +72,23 @@ NormalLintTarget($(PROFSRC)) mesa/src/X86/3dnow_xform_raw4.o \ mesa/src/X86/vertex_3dnow.o #endif +#ifdef MesaUseKatmai + ASM_OBJS += mesa/src/X86/katmai_norm.o \ + mesa/src/X86/katmai_norm_raw.o \ + mesa/src/X86/katmai_xform_masked1.o \ + mesa/src/X86/katmai_xform_masked2.o \ + mesa/src/X86/katmai_xform_masked3.o \ + mesa/src/X86/katmai_xform_masked4.o \ + mesa/src/X86/katmai_xform_raw1.o \ + mesa/src/X86/katmai_xform_raw2.o \ + mesa/src/X86/katmai_xform_raw3.o \ + mesa/src/X86/katmai_xform_raw4.o \ + mesa/src/X86/vertex_katmai.o #endif MESAOBJS = mesa/src/?*.o mesa/src/X86/?*.o +#endif + MESAUOBJS = mesa/src/unshared/?*.o mesa/src/X86/unshared/?*.o $(ASM_OBJS) MESADOBJS = mesa/src/debugger/?*.o mesa/src/X86/debugger/?*.o $(ASM_OBJS) MESAPOBJS = mesa/src/profiled/?*.o mesa/src/X86/profiled/?*.o $(ASM_OBJS) @@ -286,9 +302,9 @@ InstallSharedLibrary($(LIBNAME),$(SOREV),$(SHLIBDIR)) install:: MakeDir($(DESTDIR)$(SYSTEMUSRLIBDIR)) $(RM) $(DESTDIR)$(SYSTEMUSRLIBDIR)/lib$(LIBNAME).so - $(LN) $(SHLIBDIR)/lib$(LIBNAME).so $(DESTDIR)$(SYSTEMUSRLIBDIR)/lib$(LIBNAME).so + $(LN) $(SHLIBDIR)/lib$(LIBNAME).so $(DESTDIR)$(SYSTEMUSRLIBDIR)/lib$(LIBNAME).so || true $(RM) $(DESTDIR)$(SYSTEMUSRLIBDIR)/lib$(LIBNAME).so.1 - $(LN) $(SHLIBDIR)/lib$(LIBNAME).so.1 $(DESTDIR)$(SYSTEMUSRLIBDIR)/lib$(LIBNAME).so.1 + $(LN) $(SHLIBDIR)/lib$(LIBNAME).so.1 $(DESTDIR)$(SYSTEMUSRLIBDIR)/lib$(LIBNAME).so.1 || true #endif #endif #if DebugLibGlx diff --git a/xc/lib/GL/dri/XF86dri.c b/xc/lib/GL/dri/XF86dri.c index ea3160cd5..e99320db5 100644 --- a/xc/lib/GL/dri/XF86dri.c +++ b/xc/lib/GL/dri/XF86dri.c @@ -83,17 +83,27 @@ static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86dri_info) * * *****************************************************************************/ +#if 0 +#define TRACE(msg) printf("XF86DRI%s\n", msg); +#else +#define TRACE(msg) +#endif + + Bool XF86DRIQueryExtension (dpy, event_basep, error_basep) Display *dpy; int *event_basep, *error_basep; { XExtDisplayInfo *info = find_display (dpy); + TRACE("QueryExtension..."); if (XextHasExtension(info)) { *event_basep = info->codes->first_event; *error_basep = info->codes->first_error; + TRACE("QueryExtension... return True"); return True; } else { + TRACE("QueryExtension... return False"); return False; } } @@ -108,6 +118,7 @@ Bool XF86DRIQueryVersion(dpy, majorVersion, minorVersion, patchVersion) xXF86DRIQueryVersionReply rep; xXF86DRIQueryVersionReq *req; + TRACE("QueryVersion..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -117,6 +128,7 @@ Bool XF86DRIQueryVersion(dpy, majorVersion, minorVersion, patchVersion) if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("QueryVersion... return False"); return False; } *majorVersion = rep.majorVersion; @@ -124,6 +136,7 @@ Bool XF86DRIQueryVersion(dpy, majorVersion, minorVersion, patchVersion) *patchVersion = rep.patchVersion; UnlockDisplay(dpy); SyncHandle(); + TRACE("QueryVersion... return True"); return True; } @@ -136,6 +149,7 @@ Bool XF86DRIQueryDirectRenderingCapable(dpy, screen, isCapable) xXF86DRIQueryDirectRenderingCapableReply rep; xXF86DRIQueryDirectRenderingCapableReq *req; + TRACE("QueryDirectRenderingCapable..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -146,11 +160,13 @@ Bool XF86DRIQueryDirectRenderingCapable(dpy, screen, isCapable) if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("QueryDirectRenderingCapable... return False"); return False; } *isCapable = rep.isCapable; UnlockDisplay(dpy); SyncHandle(); + TRACE("QueryDirectRenderingCapable... return True"); return True; } @@ -164,6 +180,7 @@ Bool XF86DRIOpenConnection(dpy, screen, hSAREA, busIdString) xXF86DRIOpenConnectionReply rep; xXF86DRIOpenConnectionReq *req; + TRACE("OpenConnection..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -174,6 +191,7 @@ Bool XF86DRIOpenConnection(dpy, screen, hSAREA, busIdString) if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("OpenConnection... return False"); return False; } @@ -187,6 +205,7 @@ Bool XF86DRIOpenConnection(dpy, screen, hSAREA, busIdString) _XEatData(dpy, ((rep.busIdStringLength+3) & ~3)); UnlockDisplay(dpy); SyncHandle(); + TRACE("OpenConnection... return False"); return False; } _XReadPad(dpy, *busIdString, rep.busIdStringLength); @@ -195,6 +214,7 @@ Bool XF86DRIOpenConnection(dpy, screen, hSAREA, busIdString) } UnlockDisplay(dpy); SyncHandle(); + TRACE("OpenConnection... return True"); return True; } @@ -207,6 +227,7 @@ Bool XF86DRIAuthConnection(dpy, screen, magic) xXF86DRIAuthConnectionReq *req; xXF86DRIAuthConnectionReply rep; + TRACE("AuthConnection..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -219,10 +240,12 @@ Bool XF86DRIAuthConnection(dpy, screen, magic) if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.authenticated) { UnlockDisplay(dpy); SyncHandle(); + TRACE("AuthConnection... return False"); return False; } UnlockDisplay(dpy); SyncHandle(); + TRACE("AuthConnection... return True"); return True; } @@ -233,6 +256,8 @@ Bool XF86DRICloseConnection(dpy, screen) XExtDisplayInfo *info = find_display (dpy); xXF86DRICloseConnectionReq *req; + TRACE("CloseConnection..."); + XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -242,6 +267,7 @@ Bool XF86DRICloseConnection(dpy, screen) req->screen = screen; UnlockDisplay(dpy); SyncHandle(); + TRACE("CloseConnection... return True"); return True; } @@ -258,6 +284,7 @@ Bool XF86DRIGetClientDriverName(dpy, screen, ddxDriverMajorVersion, xXF86DRIGetClientDriverNameReply rep; xXF86DRIGetClientDriverNameReq *req; + TRACE("GetClientDriverName..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -268,6 +295,7 @@ Bool XF86DRIGetClientDriverName(dpy, screen, ddxDriverMajorVersion, if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("GetClientDriverName... return False"); return False; } @@ -278,6 +306,9 @@ Bool XF86DRIGetClientDriverName(dpy, screen, ddxDriverMajorVersion, if (rep.length) { if (!(*clientDriverName = (char *)Xcalloc(rep.clientDriverNameLength + 1, 1))) { _XEatData(dpy, ((rep.clientDriverNameLength+3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetClientDriverName... return False"); return False; } _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength); @@ -286,6 +317,7 @@ Bool XF86DRIGetClientDriverName(dpy, screen, ddxDriverMajorVersion, } UnlockDisplay(dpy); SyncHandle(); + TRACE("GetClientDriverName... return True"); return True; } @@ -300,6 +332,7 @@ Bool XF86DRICreateContext(dpy, screen, visual, context, hHWContext) xXF86DRICreateContextReply rep; xXF86DRICreateContextReq *req; + TRACE("CreateContext..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -313,11 +346,13 @@ Bool XF86DRICreateContext(dpy, screen, visual, context, hHWContext) if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("CreateContext... return False"); return False; } *hHWContext = rep.hHWContext; UnlockDisplay(dpy); SyncHandle(); + TRACE("CreateContext... return True"); return True; } @@ -329,6 +364,7 @@ Bool XF86DRIDestroyContext(dpy, screen, context) XExtDisplayInfo *info = find_display (dpy); xXF86DRIDestroyContextReq *req; + TRACE("DestroyContext..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -339,6 +375,7 @@ Bool XF86DRIDestroyContext(dpy, screen, context) req->context = context; UnlockDisplay(dpy); SyncHandle(); + TRACE("DestroyContext... return True"); return True; } @@ -352,6 +389,7 @@ Bool XF86DRICreateDrawable(dpy, screen, drawable, hHWDrawable) xXF86DRICreateDrawableReply rep; xXF86DRICreateDrawableReq *req; + TRACE("CreateDrawable..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -363,11 +401,13 @@ Bool XF86DRICreateDrawable(dpy, screen, drawable, hHWDrawable) if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("CreateDrawable... return False"); return False; } *hHWDrawable = rep.hHWDrawable; UnlockDisplay(dpy); SyncHandle(); + TRACE("CreateDrawable... return True"); return True; } @@ -379,6 +419,7 @@ Bool XF86DRIDestroyDrawable(dpy, screen, drawable) XExtDisplayInfo *info = find_display (dpy); xXF86DRIDestroyDrawableReq *req; + TRACE("DestroyDrawable..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -389,6 +430,7 @@ Bool XF86DRIDestroyDrawable(dpy, screen, drawable) req->drawable = drawable; UnlockDisplay(dpy); SyncHandle(); + TRACE("DestroyDrawable... return True"); return True; } @@ -419,6 +461,7 @@ Bool XF86DRIGetDrawableInfo(dpy, screen, drawable, xXF86DRIGetDrawableInfoReq *req; int total_rects; + TRACE("GetDrawableInfo..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -432,6 +475,7 @@ Bool XF86DRIGetDrawableInfo(dpy, screen, drawable, { UnlockDisplay(dpy); SyncHandle(); + TRACE("GetDrawableInfo... return False"); return False; } *index = rep.drawableTableIndex; @@ -448,20 +492,28 @@ Bool XF86DRIGetDrawableInfo(dpy, screen, drawable, *numBackClipRects = rep.numBackClipRects; total_rects += *numBackClipRects; - if (rep.length != (SIZEOF(xXF86DRIGetDrawableInfoReply) - +#if 0 + /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks + * backwards compatibility (Because of the >> 2 shift) but the fix + * enables multi-threaded apps to work. + */ + if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) - SIZEOF(xGenericReply) + - total_rects * sizeof(XF86DRIClipRectRec))) { - _XEatData(dpy, rep.length); - return False; + total_rects * sizeof(XF86DRIClipRectRec)) + 3) & ~3) >> 2)) { + _XEatData(dpy, rep.length); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDrawableInfo... return False"); + return False; } - +#endif if (*numClipRects) { int len = sizeof(XF86DRIClipRectRec) * (*numClipRects); *pClipRects = (XF86DRIClipRectPtr)Xcalloc(len, 1); if (*pClipRects) - _XRead32(dpy, *pClipRects, len); + _XRead(dpy, (char*)*pClipRects, len); } else { *pClipRects = NULL; } @@ -471,13 +523,14 @@ Bool XF86DRIGetDrawableInfo(dpy, screen, drawable, *pBackClipRects = (XF86DRIClipRectPtr)Xcalloc(len, 1); if (*pBackClipRects) - _XRead32(dpy, *pBackClipRects, len); + _XRead(dpy, (char*)*pBackClipRects, len); } else { *pBackClipRects = NULL; } UnlockDisplay(dpy); SyncHandle(); + TRACE("GetDrawableInfo... return True"); return True; } @@ -496,6 +549,7 @@ Bool XF86DRIGetDeviceInfo(dpy, screen, hFrameBuffer, xXF86DRIGetDeviceInfoReply rep; xXF86DRIGetDeviceInfoReq *req; + TRACE("GetDeviceInfo..."); XF86DRICheckExtension (dpy, info, False); LockDisplay(dpy); @@ -506,12 +560,13 @@ Bool XF86DRIGetDeviceInfo(dpy, screen, hFrameBuffer, if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + TRACE("GetDeviceInfo... return False"); return False; } *hFrameBuffer = rep.hFrameBufferLow; #ifdef LONG64 - *hFrameBuffer = ((drmHandle)rep.hFrameBufferHigh) << 32; + *hFrameBuffer |= ((drmHandle)rep.hFrameBufferHigh) << 32; #endif *fbOrigin = rep.framebufferOrigin; @@ -520,15 +575,20 @@ Bool XF86DRIGetDeviceInfo(dpy, screen, hFrameBuffer, *devPrivateSize = rep.devPrivateSize; if (rep.length) { - if (!(*pDevPrivate = (void *)Xcalloc(rep.length, 1))) { - _XEatData(dpy, ((rep.length+3) & ~3)); + if (!(*pDevPrivate = (void *)Xcalloc(rep.devPrivateSize, 1))) { + _XEatData(dpy, ((rep.devPrivateSize+3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDeviceInfo... return False"); return False; } - _XRead32(dpy, *pDevPrivate, rep.length); + _XRead(dpy, (char*)*pDevPrivate, rep.devPrivateSize); } else { *pDevPrivate = NULL; } + UnlockDisplay(dpy); SyncHandle(); + TRACE("GetDeviceInfo... return True"); return True; } diff --git a/xc/lib/GL/glx/glxclient.h b/xc/lib/GL/glx/glxclient.h index 0f0bc9e63..fffa57b17 100644 --- a/xc/lib/GL/glx/glxclient.h +++ b/xc/lib/GL/glx/glxclient.h @@ -43,6 +43,9 @@ #ifdef NEED_GL_FUNCS_WRAPPED #include "indirect.h" #endif +#ifdef XTHREADS +#include "Xthreads.h" +#endif #define GLX_MAJOR_VERSION 1 /* current version numbers */ @@ -560,8 +563,15 @@ extern __GLXcontext *__glXcurrentContext; ** Global lock for all threads in this address space using the GLX ** extension */ +#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) +extern xmutex_rec __glXmutex; +extern xmutex_rec __glXSwapBuffersMutex; +#define __glXLock() xmutex_lock(&__glXmutex) +#define __glXUnlock() xmutex_unlock(&__glXmutex) +#else #define __glXLock() #define __glXUnlock() +#endif /* ** Setup for a command. Initialize the extension for dpy if necessary. diff --git a/xc/lib/GL/glx/glxcmds.c b/xc/lib/GL/glx/glxcmds.c index deccf9a3c..fb4e65429 100644 --- a/xc/lib/GL/glx/glxcmds.c +++ b/xc/lib/GL/glx/glxcmds.c @@ -68,8 +68,6 @@ GLXContext CreateContext(Display *dpy, XVisualInfo *vis, __GLXdisplayPrivate *priv; #endif - if (getenv("LIBGL_ALWAYS_INDIRECT")) - allowDirect = GL_FALSE; opcode = __glXSetupForCommand(dpy); if (!opcode) { return NULL; @@ -541,6 +539,10 @@ void glXSwapBuffers(Display *dpy, GLXDrawable drawable) __GLXdisplayPrivate *priv; __DRIdrawable *pdraw; +#if defined(XTHREADS) + xmutex_lock(&__glXSwapBuffersMutex); +#endif + priv = __glXInitialize(dpy); if (priv->driDisplay.private) { __GLXscreenConfigs *psc = &priv->screenConfigs[gc->screen]; @@ -552,6 +554,9 @@ void glXSwapBuffers(Display *dpy, GLXDrawable drawable) pdraw = (*psc->driScreen.getDrawable)(dpy, drawable); if (pdraw) { (*pdraw->swapBuffers)(dpy, pdraw->private); +#if defined(XTHREADS) + xmutex_unlock(&__glXSwapBuffersMutex); +#endif return; } } @@ -560,6 +565,9 @@ void glXSwapBuffers(Display *dpy, GLXDrawable drawable) opcode = __glXSetupForCommand(dpy); if (!opcode) { +#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) + xmutex_unlock(&__glXSwapBuffersMutex); +#endif return; } @@ -583,6 +591,9 @@ void glXSwapBuffers(Display *dpy, GLXDrawable drawable) UnlockDisplay(dpy); SyncHandle(); XFlush(dpy); +#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) + xmutex_unlock(&__glXSwapBuffersMutex); +#endif } /* diff --git a/xc/lib/GL/glx/glxext.c b/xc/lib/GL/glx/glxext.c index 2367f49a0..424365549 100644 --- a/xc/lib/GL/glx/glxext.c +++ b/xc/lib/GL/glx/glxext.c @@ -29,10 +29,10 @@ */ #include "packrender.h" -#include <stdio.h> #include <Xext.h> #include <extutil.h> #include <assert.h> +#include <stdio.h> #include "indirect_init.h" #include "glapi.h" #ifdef XTHREADS @@ -72,7 +72,7 @@ static __GLapi *IndirectAPI = NULL; /* - * Current context management + * Current context management and locking */ #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) @@ -107,6 +107,11 @@ void __glXSetCurrentContext(__GLXcontext *c) xthread_set_specific(ContextTSD, c); } + +/* Used by the __glXLock() and __glXUnlock() macros */ +xmutex_rec __glXmutex; +xmutex_rec __glXSwapBuffersMutex; + #else /* not thread safe */ @@ -451,6 +456,18 @@ __GLXdisplayPrivate *__glXInitialize(Display* dpy) XEDataObject dataObj; int major, minor; +#if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS) + { + static int firstCall = 1; + if (firstCall) { + /* initialize the GLX mutexes */ + xmutex_init(&__glXmutex); + xmutex_init(&__glXSwapBuffersMutex); + firstCall = 0; + } + } +#endif + /* The one and only long long lock */ __glXLock(); @@ -510,8 +527,16 @@ __GLXdisplayPrivate *__glXInitialize(Display* dpy) ** Note: This _must_ be done before calling any other DRI routines ** (e.g., those called in AllocAndFetchScreenConfigs). */ - dpyPriv->driDisplay.private = - driCreateDisplay(dpy, &dpyPriv->driDisplay); + if (getenv("LIBGL_ALWAYS_INDIRECT")) { + /* Assinging zero here assures we'll never go direct */ + dpyPriv->driDisplay.private = 0; + dpyPriv->driDisplay.destroyDisplay = 0; + dpyPriv->driDisplay.createScreen = 0; + } + else { + dpyPriv->driDisplay.private = + driCreateDisplay(dpy, &dpyPriv->driDisplay); + } #endif if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) { @@ -533,7 +558,9 @@ __GLXdisplayPrivate *__glXInitialize(Display* dpy) XAddToExtensionList(privList, private); if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1) { +#if 0 __glXClientInfo(dpy, dpyPriv->majorOpcode); +#endif } __glXUnlock(); @@ -811,6 +838,7 @@ Bool glXMakeCurrent(Display *dpy, GLXDrawable draw, GLXContext gc) } } else { #endif + _glapi_check_multithread(); /* Send a glXMakeCurrent request to bind the new context. */ LockDisplay(dpy); GetReq(GLXMakeCurrent,req); @@ -820,14 +848,15 @@ Bool glXMakeCurrent(Display *dpy, GLXDrawable draw, GLXContext gc) req->context = gc ? gc->xid : None; req->oldContextTag = oldGC->currentContextTag; bindReturnValue = _XReply(dpy, (xReply*) &reply, 0, False); + UnlockDisplay(dpy); #ifdef GLX_DIRECT_RENDERING } #endif + if (!bindReturnValue) { /* The make current failed. */ if (!gc->isDirect) { - UnlockDisplay(dpy); SyncHandle(); } @@ -884,6 +913,9 @@ Bool glXMakeCurrent(Display *dpy, GLXDrawable draw, GLXContext gc) ** request, and cannot adhere to the "no-op" behavior. */ } + else { + UnlockDisplay(dpy); + } oldGC->currentContextTag = reply.contextTag; } return GL_FALSE; diff --git a/xc/lib/GL/highpc.c b/xc/lib/GL/highpc.c index c9218d02a..eca2a9382 100644 --- a/xc/lib/GL/highpc.c +++ b/xc/lib/GL/highpc.c @@ -32,16 +32,17 @@ glx_init_prof( void ) fprintf(stderr, "\n\n\nIn glx_init_prof\n\n\n"); if (!s) return; + if (profile) return; profile = 1; monstartup( (char *)glx_lowpc, (char *)glx_highpc ); - fprintf(stderr, "Starting profiling, %x %x\n", - (unsigned int)glx_lowpc, - (unsigned int)glx_highpc); + fprintf(stderr, "Starting profiling, %lx %lx\n", + (unsigned long)glx_lowpc, + (unsigned long)glx_highpc); if ((fp = fopen( "glx_lowpc", "w" )) != NULL) { - fprintf( fp, "0x%08x ", (unsigned int)glx_lowpc ); + fprintf( fp, "0x%08lx ", (unsigned long)glx_lowpc ); fclose( fp ); } } diff --git a/xc/lib/GL/mesa/dri/dri_mesa.c b/xc/lib/GL/mesa/dri/dri_mesa.c index f72ce375a..7c12e540b 100644 --- a/xc/lib/GL/mesa/dri/dri_mesa.c +++ b/xc/lib/GL/mesa/dri/dri_mesa.c @@ -285,7 +285,7 @@ static Bool driMesaBindContext(Display *dpy, int scrn, DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); } - /* Bind Mesa's drawable to Mesa's context */ + /* Call device-specific MakeCurrent */ (*psp->MesaAPI.MakeCurrent)(pcp, pdp, pdp); return GL_TRUE; @@ -293,6 +293,13 @@ static Bool driMesaBindContext(Display *dpy, int scrn, /*****************************************************************/ +/* + * This function basically updates the __DRIdrawablePrivate struct's + * cliprect information by calling XF86DRIGetDrawableInfo(). + * This is usually called by a macro which compares the + * __DRIdrwablePrivate pStamp and lastStamp values. If the values + * are different that means we have to update the clipping info. + */ void driMesaUpdateDrawableInfo(Display *dpy, int scrn, __DRIdrawablePrivate *pdp) { @@ -318,7 +325,6 @@ void driMesaUpdateDrawableInfo(Display *dpy, int scrn, Xfree(pdp->pBackClipRects); } - DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); if (!XF86DRIGetDrawableInfo(dpy, scrn, pdp->draw, diff --git a/xc/lib/GL/mesa/src/Imakefile b/xc/lib/GL/mesa/src/Imakefile index 779cde990..2ccd8ec1f 100644 --- a/xc/lib/GL/mesa/src/Imakefile +++ b/xc/lib/GL/mesa/src/Imakefile @@ -349,13 +349,15 @@ LinkSourceFile(zoom.h, $(MESASRCDIR)/src) ASM_SRCS = ASM_OBJS = #ifdef MesaUse3DNow - ASM_DEFS = -DUSE_MMX_ASM -DUSE_X86_ASM -DUSE_3DNOW_ASM -#else - ASM_DEFS = -DUSE_MMX_ASM -DUSE_X86_ASM + 3DNOW_DEFS = -DUSE_3DNOW_ASM +#endif +#ifdef MesaUseKatmai + KATMAI_DEFS = -DUSE_KATMAI_ASM #endif + ASM_DEFS = -DUSE_MMX_ASM -DUSE_X86_ASM $(3DNOW_DEFS) $(KATMAI_DEFS) #endif - DEFINES = $(ALLOC_DEFINES) GlxDefines $(TDFX_DEFS) $(ASM_DEFS) + DEFINES = $(ALLOC_DEFINES) GlxDefines $(TDFX_DEFS) $(ASM_DEFS) $(IEEE_DEFS) INCLUDES = -I$(XLIBSRC) -I$(EXTINCSRC) -I../include -I../../dri -I. -I../../../../include SRCS = $(CORE_SRCS) $(ASM_SRCS) OBJS = $(CORE_OBJS) $(ASM_OBJS) diff --git a/xc/lib/GL/mesa/src/X86/Imakefile b/xc/lib/GL/mesa/src/X86/Imakefile index f97040009..c87407e1d 100644 --- a/xc/lib/GL/mesa/src/X86/Imakefile +++ b/xc/lib/GL/mesa/src/X86/Imakefile @@ -40,7 +40,7 @@ ALLOC_DEFINES = -DMALLOC_0_RETURNS_NULL #endif #ifdef i386Architecture -XCOMM We'll learn at runtime whether 3dNow, MMX, etc are really present. +XCOMM Determine at runtime whether 3dNow, Katmai, MMX, etc are really present. X86_SRCS = x86a.S common_x86.c common_x86asm.S glapi_x86.S x86.c vertex.S X86_OBJS = x86a.o common_x86.o common_x86asm.o x86.o vertex.o @@ -70,13 +70,28 @@ XCOMM We'll learn at runtime whether 3dNow, MMX, etc are really present. 3DNOW_DEFS = -DUSE_3DNOW_ASM #endif +#ifdef MesaUseKatmai + KATMAI_SRCS = katmai.c katmai_norm_raw.S katmai_xform_masked1.S \ + katmai_xform_masked2.S katmai_xform_masked3.S \ + katmai_xform_masked4.S katmai_xform_raw1.S \ + katmai_xform_raw2.S katmai_xform_raw3.S katmai_xform_raw4.S \ + vertex_katmai.S + + KATMAI_OBJS = katmai.o katmai_norm_raw.o katmai_xform_masked1.o \ + katmai_xform_masked2.o katmai_xform_masked3.o \ + katmai_xform_masked4.o katmai_xform_raw1.o \ + katmai_xform_raw2.o katmai_xform_raw3.o katmai_xform_raw4.o \ + vertex_katmai.o + + KATMAI_DEFS = -DUSE_KATMAI_ASM +#endif #endif - DEFINES = $(ALLOC_DEFINES) GlxDefines -DFX $(X86_DEFS) $(MMX_DEFS) $(3DNOW_DEFS) + DEFINES = $(ALLOC_DEFINES) GlxDefines -DFX $(X86_DEFS) $(MMX_DEFS) $(3DNOW_DEFS) $(KATMAI_DEFS) INCLUDES = -I$(XLIBSRC) -I$(EXTINCSRC) -I../include -I../../include -I../../dri -I.. - SRCS = $(X86_SRCS) $(MMX_SRCS) $(3DNOW_SRCS) - OBJS = $(X86_OBJS) $(MMX_OBJS) $(3DNOW_OBJS) + SRCS = $(X86_SRCS) $(MMX_SRCS) $(3DNOW_SRCS) $(KATMAI_SRCS) + OBJS = $(X86_OBJS) $(MMX_OBJS) $(3DNOW_OBJS) $(KATMAI_OBJS) #if !GlxUseBuiltInDRIDriver #undef DoNormalLib NormalLibGlx @@ -107,6 +122,19 @@ ObjectFromAsmSource(3dnow_xform_raw4, NullParameter) ObjectFromAsmSource(vertex_3dnow, NullParameter) #endif +#ifdef MesaUseKatmai +ObjectFromAsmSource(katmai_norm_raw, NullParameter) +ObjectFromAsmSource(katmai_xform_masked1, NullParameter) +ObjectFromAsmSource(katmai_xform_masked2, NullParameter) +ObjectFromAsmSource(katmai_xform_masked3, NullParameter) +ObjectFromAsmSource(katmai_xform_masked4, NullParameter) +ObjectFromAsmSource(katmai_xform_raw1, NullParameter) +ObjectFromAsmSource(katmai_xform_raw2, NullParameter) +ObjectFromAsmSource(katmai_xform_raw3, NullParameter) +ObjectFromAsmSource(katmai_xform_raw4, NullParameter) +ObjectFromAsmSource(vertex_katmai, NullParameter) +#endif + ObjectFromAsmSource(mmx_blend, NullParameter) ObjectFromAsmSource(common_x86asm, NullParameter) diff --git a/xc/lib/GL/mesa/src/drv/ffb/ffb_vb.c b/xc/lib/GL/mesa/src/drv/ffb/ffb_vb.c index c48b06082..03c1b32a5 100644 --- a/xc/lib/GL/mesa/src/drv/ffb/ffb_vb.c +++ b/xc/lib/GL/mesa/src/drv/ffb/ffb_vb.c @@ -28,7 +28,7 @@ #include "ffb_xmesa.h" #include "ffb_context.h" #include "ffb_vb.h" - +#include "mem.h" #include "stages.h" #define COL { \ @@ -242,8 +242,8 @@ void ffbDDResizeVB(struct vertex_buffer *VB, GLuint size) exit(1); } - free(VB->ClipMask); - VB->ClipMask = (GLubyte *)malloc(sizeof(GLubyte) * mvb->size); + ALIGN_FREE(VB->ClipMask); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * mvb->size, 4); if (!VB->ClipMask) { fprintf(stderr, "ffb-glx: out of memory !\n"); exit(1); @@ -283,8 +283,8 @@ void ffbDDRegisterVB(struct vertex_buffer *VB) exit(1); } - free(VB->ClipMask); - VB->ClipMask = (GLubyte *)malloc(sizeof(GLubyte) * mvb->size); + ALIGN_FREE(VB->ClipMask); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * mvb->size, 4); if (!VB->ClipMask) { fprintf(stderr, "ffb-glx: out of memory !\n"); exit(1); diff --git a/xc/lib/GL/mesa/src/drv/i810/i810vb.c b/xc/lib/GL/mesa/src/drv/i810/i810vb.c index 075063489..002920100 100644 --- a/xc/lib/GL/mesa/src/drv/i810/i810vb.c +++ b/xc/lib/GL/mesa/src/drv/i810/i810vb.c @@ -23,14 +23,14 @@ * */ +#include <stdio.h> +#include <stdlib.h> #include "i810context.h" #include "i810vb.h" #include "i810log.h" - +#include "mem.h" #include "stages.h" -#include <stdio.h> -#include <stdlib.h> #define TEX0 { \ @@ -386,8 +386,8 @@ void i810DDResizeVB( struct vertex_buffer *VB, GLuint size ) exit(1); } - free( VB->ClipMask ); - VB->ClipMask = (GLubyte *)malloc(sizeof(GLubyte) * mvb->size); + ALIGN_FREE( VB->ClipMask ); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * mvb->size, 4); if (!VB->ClipMask) { fprintf(stderr, "i810-glx: out of memory !\n"); exit(1); @@ -428,8 +428,8 @@ void i810DDRegisterVB( struct vertex_buffer *VB ) exit(1); } - free( VB->ClipMask ); - VB->ClipMask = (GLubyte *)malloc(sizeof(GLubyte) * mvb->size); + ALIGN_FREE( VB->ClipMask ); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * mvb->size, 4); if (!VB->ClipMask) { fprintf(stderr, "i810-glx: out of memory !\n"); exit(1); diff --git a/xc/lib/GL/mesa/src/drv/r128/r128_vb.c b/xc/lib/GL/mesa/src/drv/r128/r128_vb.c index 0cc529957..05eb07e28 100644 --- a/xc/lib/GL/mesa/src/drv/r128/r128_vb.c +++ b/xc/lib/GL/mesa/src/drv/r128/r128_vb.c @@ -40,7 +40,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "r128_cce.h" #include "r128_state.h" #include "r128_vb.h" - +#include "mem.h" #include "stages.h" #define TEX0 \ @@ -423,8 +423,8 @@ void r128DDResizeVB(struct vertex_buffer *VB, GLuint size) exit(1); } - free(VB->ClipMask); - VB->ClipMask = (GLubyte *)malloc(sizeof(GLubyte) * r128vb->size); + ALIGN_FREE(VB->ClipMask); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * r128vb->size, 4); if (!VB->ClipMask) { fprintf(stderr, "Cannot allocate clipmask! Exiting...\n"); exit(1); @@ -454,8 +454,8 @@ void r128DDRegisterVB(struct vertex_buffer *VB) exit(1); } - free(VB->ClipMask); - VB->ClipMask = (GLubyte *)malloc(sizeof(GLubyte) * r128vb->size); + ALIGN_FREE(VB->ClipMask); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * r128vb->size, 4); if (!VB->ClipMask) { fprintf(stderr, "Cannot allocate clipmask! Exiting...\n"); exit(1); diff --git a/xc/lib/GL/mesa/src/drv/sis/Imakefile b/xc/lib/GL/mesa/src/drv/sis/Imakefile index 2ed7b8c15..275a36693 100644 --- a/xc/lib/GL/mesa/src/drv/sis/Imakefile +++ b/xc/lib/GL/mesa/src/drv/sis/Imakefile @@ -264,7 +264,7 @@ LinkSourceFile(xdriP.h, ../../X) MMX_OBJS = ../../X86/mmx_blend.o -#if MesaUse3DNow +#ifdef MesaUse3DNow 3DNOW_SRCS = ../../X86/3dnow.c \ ../../X86/3dnow_norm_raw.S \ ../../X86/3dnow_xform_masked1.S \ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/Imakefile b/xc/lib/GL/mesa/src/drv/tdfx/Imakefile index c10b64969..ea80d8e4f 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/Imakefile +++ b/xc/lib/GL/mesa/src/drv/tdfx/Imakefile @@ -13,7 +13,7 @@ ALLOC_DEFINES = -DMALLOC_0_RETURNS_NULL #endif #if BuildXF86DRI - DRI_DEFINES = GlxDefines -DFX -DFX_GLIDE3 -DGLIDE3 -DDRIVERTS + DRI_DEFINES = GlxDefines -DFX_GLIDE3 -DDRIVERTS DRI_INCLUDES = -I../../../../dri -I../../../../glx \ -I../../../dri \ -I$(TOP)/include -I$(TOP)/include/GL \ @@ -24,32 +24,6 @@ ALLOC_DEFINES = -DMALLOC_0_RETURNS_NULL MESA_INCLUDES = -I. -I.. -I../../include -LinkSourceFile(fxclip.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxcliptmp.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxcva.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxcva.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxcvatmp.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxdd.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxddspan.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxddtex.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxdrv.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxfastpath.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxfasttmp.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxglidew.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxglidew.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxpipeline.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxrender.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxsanity.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxsdettmp.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxsetup.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxstripdet.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxtexman.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxtrifuncs.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxtritmp.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxvsetup.c, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxvsetup.h, $(MESASRCDIR)/src/FX) -LinkSourceFile(fxvs_tmp.h, $(MESASRCDIR)/src/FX) - DEFINES = $(ALLOC_DEFINES) $(DRI_DEFINES) INCLUDES = -I$(XLIBSRC) -I$(EXTINCSRC) $(MESA_INCLUDES) $(DRI_INCLUDES) \ -I$(GLIDE3INCDIR) @@ -253,7 +227,7 @@ LinkSourceFile(fxvs_tmp.h, $(MESASRCDIR)/src/FX) MMX_OBJS = ../../X86/mmx_blend.o -#if MesaUse3DNow +#ifdef MesaUse3DNow 3DNOW_SRCS = ../../X86/3dnow.c \ ../../X86/3dnow_norm_raw.S \ ../../X86/3dnow_xform_masked1.S \ @@ -279,10 +253,36 @@ LinkSourceFile(fxvs_tmp.h, $(MESASRCDIR)/src/FX) ../../X86/vertex_3dnow.o #endif +#ifdef MesaUseKatmai + KATMAI_SRCS = ../../X86/katmai.c \ + ../../X86/katmai_norm_raw.S \ + ../../X86/katmai_xform_masked1.S \ + ../../X86/katmai_xform_masked2.S \ + ../../X86/katmai_xform_masked3.S \ + ../../X86/katmai_xform_masked4.S \ + ../../X86/katmai_xform_raw1.S \ + ../../X86/katmai_xform_raw2.S \ + ../../X86/katmai_xform_raw3.S \ + ../../X86/katmai_xform_raw4.S \ + ../../X86/vertex_katmai.S + + KATMAI_OBJS = ../../X86/katmai.o \ + ../../X86/katmai_norm_raw.o \ + ../../X86/katmai_xform_masked1.o \ + ../../X86/katmai_xform_masked2.o \ + ../../X86/katmai_xform_masked3.o \ + ../../X86/katmai_xform_masked4.o \ + ../../X86/katmai_xform_raw1.o \ + ../../X86/katmai_xform_raw2.o \ + ../../X86/katmai_xform_raw3.o \ + ../../X86/katmai_xform_raw4.o \ + ../../X86/vertex_katmai.o +#endif + #endif - ASMSRCS = $(X86_SRCS) $(MMX_SRCS) $(3DNOW_SRCS) - ASMOBJS = $(X86_OBJS) $(MMX_OBJS) $(3DNOW_OBJS) + ASMSRCS = $(X86_SRCS) $(MMX_SRCS) $(3DNOW_SRCS) $(KATMAI_SRCS) + ASMOBJS = $(X86_OBJS) $(MMX_OBJS) $(3DNOW_OBJS) $(KATMAI_OBJS) SRCS = $(LOSRCS) $(DRISRCS) $(DRMSRCS) $(TDFXSRCS) $(MESASRCS) $(ASMSRCS) $(HISRCS) OBJS = $(LOOBJS) $(DRIOBJS) $(DRMOBJS) $(TDFXOBJS) $(MESAOBJS) $(ASMOBJS) $(HIOBJS) diff --git a/xc/extras/Mesa/src/FX/X86/fx_3dnow_fastpath.S b/xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fastpath.S index eb426f705..eb426f705 100644 --- a/xc/extras/Mesa/src/FX/X86/fx_3dnow_fastpath.S +++ b/xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fastpath.S diff --git a/xc/extras/Mesa/src/FX/X86/fx_3dnow_fasttmp.h b/xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fasttmp.h index 78c5fef74..78c5fef74 100644 --- a/xc/extras/Mesa/src/FX/X86/fx_3dnow_fasttmp.h +++ b/xc/lib/GL/mesa/src/drv/tdfx/X86/fx_3dnow_fasttmp.h diff --git a/xc/extras/Mesa/src/FX/fxclip.c b/xc/lib/GL/mesa/src/drv/tdfx/fxclip.c index 7067516be..9d6f7e4c2 100644 --- a/xc/extras/Mesa/src/FX/fxclip.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxclip.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -43,13 +41,8 @@ */ -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - #include "fxdrv.h" +#include "fxtexman.h" #include "mmath.h" #include "macros.h" #include "vector.h" @@ -170,119 +163,116 @@ do { \ * storage. * */ -static INLINE GLuint fx_clip_triangle( GLcontext *ctx, - GLfloat *inoutlist[], - GrVertex **verts, - GLuint sz, - GLuint mask ) +static INLINE GLuint +fx_clip_triangle(GLcontext * ctx, + GLfloat * inoutlist[], + GrVertex ** verts, GLuint sz, GLuint mask) { - GLuint n = 3; - GLfloat *store = inoutlist[n-1] + sz; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GrVertex *verts2[VB_MAX_CLIPPED_VERTS]; - GLfloat **inlist[2]; - GrVertex **vertlist[2]; - GLuint in = 0; - GLuint i; - - inlist[0] = inoutlist; - inlist[1] = vlist; - - vertlist[0] = verts; - vertlist[1] = verts2; - - if (mask & CLIP_ALL_BITS) - { - if (mask & CLIP_RIGHT_BIT) - CLIP(-,0); - - if (mask & CLIP_LEFT_BIT) - CLIP(+,0); - - if (mask & CLIP_TOP_BIT) - CLIP(-,1); - - if (mask & CLIP_BOTTOM_BIT) - CLIP(+,1); - - if (mask & CLIP_FAR_BIT) - CLIP(-,2); - - if (mask & CLIP_NEAR_BIT) - CLIP(+,2); - } - - if (mask & CLIP_USER_BIT) { - GLuint bit; - GLfloat (*plane)[4] = &ctx->Transform.ClipUserPlane[0]; - for (bit = 0x100 ; bit < mask ; plane++, bit *= 2) { - if (mask & bit) { - GLfloat a = plane[0][0]; - GLfloat b = plane[0][1]; - GLfloat c = plane[0][2]; - GLfloat d = plane[0][3]; - UCLIP(a,b,c,d); - } - } - } - - if (inlist[in] != inoutlist) - for (i = 0 ; i < n ; i++) { - inoutlist[i] = inlist[in][i]; - verts[i] = verts2[i]; - } - - return n; + GLuint n = 3; + GLfloat *store = inoutlist[n - 1] + sz; + GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; + GrVertex *verts2[VB_MAX_CLIPPED_VERTS]; + GLfloat **inlist[2]; + GrVertex **vertlist[2]; + GLuint in = 0; + GLuint i; + + inlist[0] = inoutlist; + inlist[1] = vlist; + + vertlist[0] = verts; + vertlist[1] = verts2; + + if (mask & CLIP_ALL_BITS) { + if (mask & CLIP_RIGHT_BIT) + CLIP(-, 0); + + if (mask & CLIP_LEFT_BIT) + CLIP(+, 0); + + if (mask & CLIP_TOP_BIT) + CLIP(-, 1); + + if (mask & CLIP_BOTTOM_BIT) + CLIP(+, 1); + + if (mask & CLIP_FAR_BIT) + CLIP(-, 2); + + if (mask & CLIP_NEAR_BIT) + CLIP(+, 2); + } + + if (mask & CLIP_USER_BIT) { + GLuint bit; + GLfloat(*plane)[4] = &ctx->Transform.ClipUserPlane[0]; + for (bit = 0x100; bit < mask; plane++, bit *= 2) { + if (mask & bit) { + GLfloat a = plane[0][0]; + GLfloat b = plane[0][1]; + GLfloat c = plane[0][2]; + GLfloat d = plane[0][3]; + UCLIP(a, b, c, d); + } + } + } + + if (inlist[in] != inoutlist) + for (i = 0; i < n; i++) { + inoutlist[i] = inlist[in][i]; + verts[i] = verts2[i]; + } + + return n; } -static INLINE GLuint fx_view_clip_triangle( GLcontext *ctx, - GLfloat *inoutlist[], - GrVertex **verts, - GLuint sz, - GLubyte mask ) +static INLINE GLuint +fx_view_clip_triangle(GLcontext * ctx, + GLfloat * inoutlist[], + GrVertex ** verts, GLuint sz, GLubyte mask) { - GLuint n = 3; - GLfloat *store = inoutlist[n-1] + sz; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GrVertex *verts2[VB_MAX_CLIPPED_VERTS]; - GLfloat **inlist[2]; - GrVertex **vertlist[2]; - GLuint in = 0; - GLuint i; + GLuint n = 3; + GLfloat *store = inoutlist[n - 1] + sz; + GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; + GrVertex *verts2[VB_MAX_CLIPPED_VERTS]; + GLfloat **inlist[2]; + GrVertex **vertlist[2]; + GLuint in = 0; + GLuint i; - inlist[0] = inoutlist; - inlist[1] = vlist; + inlist[0] = inoutlist; + inlist[1] = vlist; - vertlist[0] = verts; - vertlist[1] = verts2; + vertlist[0] = verts; + vertlist[1] = verts2; - if (mask & CLIP_RIGHT_BIT) - CLIP(-,0); + if (mask & CLIP_RIGHT_BIT) + CLIP(-, 0); - if (mask & CLIP_LEFT_BIT) - CLIP(+,0); + if (mask & CLIP_LEFT_BIT) + CLIP(+, 0); - if (mask & CLIP_TOP_BIT) - CLIP(-,1); + if (mask & CLIP_TOP_BIT) + CLIP(-, 1); - if (mask & CLIP_BOTTOM_BIT) - CLIP(+,1); + if (mask & CLIP_BOTTOM_BIT) + CLIP(+, 1); - if (mask & CLIP_FAR_BIT) - CLIP(-,2); + if (mask & CLIP_FAR_BIT) + CLIP(-, 2); - if (mask & CLIP_NEAR_BIT) - CLIP(+,2); + if (mask & CLIP_NEAR_BIT) + CLIP(+, 2); - if (inlist[in] != inoutlist) - for (i = 0 ; i < n ; i++) { - inoutlist[i] = inlist[in][i]; - verts[i] = verts2[i]; - } + if (inlist[in] != inoutlist) + for (i = 0; i < n; i++) { + inoutlist[i] = inlist[in][i]; + verts[i] = verts2[i]; + } - return n; + return n; } @@ -316,53 +306,51 @@ do { \ } while (0) -static GLuint fx_clip_line( GLcontext *ctx, - GLfloat *inoutlist[], - GLuint sz, - GLubyte clipor ) +static GLuint +fx_clip_line(GLcontext * ctx, + GLfloat * inoutlist[], GLuint sz, GLubyte clipor) { - GLfloat *I = inoutlist[0]; - GLfloat *J = inoutlist[1]; - GLfloat *store = J + sz; - - if (clipor & CLIP_ALL_BITS) - { - if (clipor & CLIP_LEFT_BIT) - CLIP(1,0,0,1); - - if (clipor & CLIP_RIGHT_BIT) - CLIP(-1,0,0,1); - - if (clipor & CLIP_TOP_BIT) - CLIP(0,-1,0,1); - - if (clipor & CLIP_BOTTOM_BIT) - CLIP(0,1,0,1); - - if (clipor & CLIP_FAR_BIT) - CLIP(0,0,-1,1); - - if (clipor & CLIP_NEAR_BIT) - CLIP(0,0,1,1); - } - - if (clipor & CLIP_USER_BIT) { - GLuint i; - for (i = 0 ; i < MAX_CLIP_PLANES ; i++) { - if (ctx->Transform.ClipEnabled[i]) { - GLfloat a = ctx->Transform.ClipUserPlane[i][0]; - GLfloat b = ctx->Transform.ClipUserPlane[i][1]; - GLfloat c = ctx->Transform.ClipUserPlane[i][2]; - GLfloat d = ctx->Transform.ClipUserPlane[i][3]; - CLIP(a,b,c,d); - } - } - } - - inoutlist[0] = I; - inoutlist[1] = J; - - return 2; + GLfloat *I = inoutlist[0]; + GLfloat *J = inoutlist[1]; + GLfloat *store = J + sz; + + if (clipor & CLIP_ALL_BITS) { + if (clipor & CLIP_LEFT_BIT) + CLIP(1, 0, 0, 1); + + if (clipor & CLIP_RIGHT_BIT) + CLIP(-1, 0, 0, 1); + + if (clipor & CLIP_TOP_BIT) + CLIP(0, -1, 0, 1); + + if (clipor & CLIP_BOTTOM_BIT) + CLIP(0, 1, 0, 1); + + if (clipor & CLIP_FAR_BIT) + CLIP(0, 0, -1, 1); + + if (clipor & CLIP_NEAR_BIT) + CLIP(0, 0, 1, 1); + } + + if (clipor & CLIP_USER_BIT) { + GLuint i; + for (i = 0; i < MAX_CLIP_PLANES; i++) { + if (ctx->Transform.ClipEnabled[i]) { + GLfloat a = ctx->Transform.ClipUserPlane[i][0]; + GLfloat b = ctx->Transform.ClipUserPlane[i][1]; + GLfloat c = ctx->Transform.ClipUserPlane[i][2]; + GLfloat d = ctx->Transform.ClipUserPlane[i][3]; + CLIP(a, b, c, d); + } + } + } + + inoutlist[0] = I; + inoutlist[1] = J; + + return 2; } @@ -378,7 +366,7 @@ static GLuint fx_clip_line( GLcontext *ctx, GLfloat vsz = mat[MAT_SZ]; \ GLfloat vtx = mat[MAT_TX]; \ GLfloat vty = mat[MAT_TY]; \ - GLfloat vtz = mat[MAT_TZ]; + GLfloat vtz = mat[MAT_TZ]; #define DO_SETUP_XYZW \ { \ @@ -448,7 +436,7 @@ static GLuint fx_clip_line( GLcontext *ctx, GET_PARGB(v) = (((int)data[4+3]) << 24) | \ (((int)data[4+0]) << 16) | \ (((int)data[4+1]) << 8) | \ - (((int)data[4+2]) << 0); + (((int)data[4+2]) << 0); #else #define DO_SETUP_RGBA \ v->r = data[4+0]; \ @@ -517,38 +505,32 @@ tfxTriClipFunc fxTriClipStrideTab[0x8]; tfxLineClipFunc fxLineClipTab[0x8]; -void fxDDClipInit() -{ - fxTriViewClipTab[0] = fx_tri_view_clip_nil; - fxTriViewClipTab[SETUP_RGBA] = fx_tri_view_clip_RGBA; - fxTriViewClipTab[SETUP_TMU0] = fx_tri_view_clip_TMU0; - fxTriViewClipTab[SETUP_TMU0|SETUP_TMU1] = fx_tri_view_clip_TMU0_TMU1; - fxTriViewClipTab[SETUP_RGBA|SETUP_TMU0] = fx_tri_view_clip_RGBA_TMU0; - fxTriViewClipTab[SETUP_RGBA|SETUP_TMU0|SETUP_TMU1] = fx_tri_view_clip_RGBA_TMU0_TMU1; - - fxTriClipStrideTab[0] = fx_tri_clip_stride_nil; - fxTriClipStrideTab[SETUP_RGBA] = fx_tri_clip_stride_RGBA; - fxTriClipStrideTab[SETUP_TMU0] = fx_tri_clip_stride_TMU0; - fxTriClipStrideTab[SETUP_TMU0|SETUP_TMU1] = fx_tri_clip_stride_TMU0_TMU1; - fxTriClipStrideTab[SETUP_RGBA|SETUP_TMU0] = fx_tri_clip_stride_RGBA_TMU0; - fxTriClipStrideTab[SETUP_RGBA|SETUP_TMU0|SETUP_TMU1] = fx_tri_clip_stride_RGBA_TMU0_TMU1; - - fxLineClipTab[0] = fx_line_clip_nil; - fxLineClipTab[SETUP_RGBA] = fx_line_clip_RGBA; - fxLineClipTab[SETUP_TMU0] = fx_line_clip_TMU0; - fxLineClipTab[SETUP_TMU0|SETUP_TMU1] = fx_line_clip_TMU0_TMU1; - fxLineClipTab[SETUP_RGBA|SETUP_TMU0] = fx_line_clip_RGBA_TMU0; - fxLineClipTab[SETUP_RGBA|SETUP_TMU0|SETUP_TMU1] = fx_line_clip_RGBA_TMU0_TMU1; -} - -#else - -/* - * Need this to provide at least one external definition. - */ -int gl_fxclip_dummy(void) +void +fxDDClipInit() { - return 0; + fxTriViewClipTab[0] = fx_tri_view_clip_nil; + fxTriViewClipTab[SETUP_RGBA] = fx_tri_view_clip_RGBA; + fxTriViewClipTab[SETUP_TMU0] = fx_tri_view_clip_TMU0; + fxTriViewClipTab[SETUP_TMU0 | SETUP_TMU1] = fx_tri_view_clip_TMU0_TMU1; + fxTriViewClipTab[SETUP_RGBA | SETUP_TMU0] = fx_tri_view_clip_RGBA_TMU0; + fxTriViewClipTab[SETUP_RGBA | SETUP_TMU0 | SETUP_TMU1] = + fx_tri_view_clip_RGBA_TMU0_TMU1; + + fxTriClipStrideTab[0] = fx_tri_clip_stride_nil; + fxTriClipStrideTab[SETUP_RGBA] = fx_tri_clip_stride_RGBA; + fxTriClipStrideTab[SETUP_TMU0] = fx_tri_clip_stride_TMU0; + fxTriClipStrideTab[SETUP_TMU0 | SETUP_TMU1] = + fx_tri_clip_stride_TMU0_TMU1; + fxTriClipStrideTab[SETUP_RGBA | SETUP_TMU0] = + fx_tri_clip_stride_RGBA_TMU0; + fxTriClipStrideTab[SETUP_RGBA | SETUP_TMU0 | SETUP_TMU1] = + fx_tri_clip_stride_RGBA_TMU0_TMU1; + + fxLineClipTab[0] = fx_line_clip_nil; + fxLineClipTab[SETUP_RGBA] = fx_line_clip_RGBA; + fxLineClipTab[SETUP_TMU0] = fx_line_clip_TMU0; + fxLineClipTab[SETUP_TMU0 | SETUP_TMU1] = fx_line_clip_TMU0_TMU1; + fxLineClipTab[SETUP_RGBA | SETUP_TMU0] = fx_line_clip_RGBA_TMU0; + fxLineClipTab[SETUP_RGBA | SETUP_TMU0 | SETUP_TMU1] = + fx_line_clip_RGBA_TMU0_TMU1; } - -#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h new file mode 100644 index 000000000..6cc1ae938 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h @@ -0,0 +1,352 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#define V1 VARS_XYZW +#define S1 DO_SETUP_XYZW +#define T1 COPY_XYZW_STRIDE +#define Z1 4 + +#if (IND & SETUP_RGBA) +#define V2 V1 VARS_RGBA +#define S2 S1 DO_SETUP_RGBA +#define T2 T1 COPY_RGBA_STRIDE +#define Z2 (Z1 + 4) +#else +#define V2 V1 +#define S2 S1 +#define T2 T1 +#define Z2 Z1 +#endif + +#if (IND & SETUP_TMU0) +#define V3 V2 VARS_TMU0 +#define S3 S2 DO_SETUP_TMU0(Z2) +#define T3 T2 COPY_TMU0_STRIDE(Z2) +#define Z3 (Z2 + 2) +#else +#define V3 V2 +#define S3 S2 +#define T3 T2 +#define Z3 Z2 +#endif + +#if (IND & SETUP_TMU1) +#define V4 V3 VARS_TMU1 +#define S4 S3 DO_SETUP_TMU1(Z3) +#define T4 T3 COPY_TMU1_STRIDE(Z3) +#define Z4 (Z3 + 2) +#else +#define V4 V3 +#define S4 S3 +#define T4 T3 +#define Z4 Z3 +#endif + +#if (Z4 & 2) +#define SIZE (Z4+2) +#define COPY_STRIDE T4 COPY_NIL(Z4) +#else +#define SIZE Z4 +#define COPY_STRIDE T4 +#endif + +#define VARS V4 +#define SETUP S4 + +#define DRAW_LINE(fxMesa, tmp0, tmp1, width) \ + if (width <= 1.0) { \ + FX_grDrawLine(fxMesa, tmp0, tmp1); \ + } \ + else { \ + GrVertex verts[4]; \ + float dx, dy, ix, iy; \ + \ + dx = tmp0->x - tmp1->x; \ + dy = tmp0->y - tmp1->y; \ + \ + if (dx * dx > dy * dy) { \ + iy = width * .5; \ + ix = 0; \ + } \ + else { \ + iy = 0; \ + ix = width * .5; \ + } \ + \ + verts[0] = *tmp0; \ + verts[1] = *tmp0; \ + verts[2] = *tmp1; \ + verts[3] = *tmp1; \ + \ + verts[0].x = tmp0->x - ix; \ + verts[0].y = tmp0->y - iy; \ + \ + verts[1].x = tmp0->x + ix; \ + verts[1].y = tmp0->y + iy; \ + \ + verts[2].x = tmp1->x + ix; \ + verts[2].y = tmp1->y + iy; \ + \ + verts[3].x = tmp1->x - ix; \ + verts[3].y = tmp1->y - iy; \ + \ + FX_grDrawPolygonVertexList(fxMesa, 4, verts); \ + } + + + +static void TAG(fx_tri_view_clip) (struct vertex_buffer * VB, + GLuint v[], GLubyte mask) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLfloat data[VB_MAX_CLIPPED_VERTS * 12]; + GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; + GrVertex *verts[VB_MAX_CLIPPED_VERTS]; + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GLfloat *out = data; + GLfloat *mat = ctx->Viewport.WindowMap.m; + GLuint i, n; + GLubyte *clipmask = VB->ClipMask; + + GLuint tmu0_source = fxMesa->tmu_source[0]; + GLuint tmu1_source = fxMesa->tmu_source[1]; + GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; + GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; + + (void) fxMesa; + (void) tmu0_source; + (void) tc0_vec; + (void) tmu1_source; + (void) tc1_vec; + + for (i = 0; i < 3; i++) { + GLuint e = v[i]; + verts[i] = 0; + if (!clipmask[e]) + verts[i] = (GrVertex *) gWin[e].f; + vlist[i] = out; + COPY_STRIDE; + out += SIZE; + } + + if ((n = fx_view_clip_triangle(ctx, vlist, verts, SIZE, mask)) >= 3) { + GrVertex tmp[VB_MAX_CLIPPED_VERTS]; + GrVertex *v = tmp, *v2, *v3; + VARS; + + for (i = 0; i < n; i++) + if (!verts[i]) { + GLfloat *data = vlist[i]; + SETUP; + verts[i] = v++; + } + + v = verts[0]; + v2 = verts[1]; + v3 = verts[2]; + + for (i = 2; i < n; v2 = v3, v3 = verts[++i]) + FX_grDrawTriangle(fxMesa, v, v2, v3); + } +} + + + + + +static void TAG(fx_tri_clip_stride) (struct vertex_buffer * VB, + GLuint v[], GLuint mask) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLfloat data[VB_MAX_CLIPPED_VERTS * 12]; + GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; + GrVertex *verts[VB_MAX_CLIPPED_VERTS]; + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GLfloat *out = data; + GLfloat *mat = ctx->Viewport.WindowMap.m; + GLuint i, n; + GLubyte *clipmask = VB->ClipMask; + + GLuint tmu0_source = fxMesa->tmu_source[0]; + GLuint tmu1_source = fxMesa->tmu_source[1]; + GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; + GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; + + (void) fxMesa; + (void) tmu0_source; + (void) tc0_vec; + (void) tmu1_source; + (void) tc1_vec; + + for (i = 0; i < 3; i++) { + GLuint e = v[i]; + verts[i] = 0; + if (!clipmask[e]) + verts[i] = (GrVertex *) gWin[e].f; + vlist[i] = out; + COPY_STRIDE; + out += SIZE; + } + + if (VB->ClipPtr->size < 4) { + vlist[0][3] = vlist[1][3] = vlist[2][3] = 1.0; + if (VB->ClipPtr->size == 2) + vlist[0][2] = vlist[1][2] = vlist[2][2] = 0.0; + } + + if ((n = fx_clip_triangle(ctx, vlist, verts, SIZE, mask)) >= 3) { + GrVertex tmp[VB_MAX_CLIPPED_VERTS]; + GrVertex *v = tmp, *v2, *v3; + VARS; + + for (i = 0; i < n; i++) + if (!verts[i]) { + GLfloat *data = vlist[i]; + SETUP; + verts[i] = v++; + } + + v = verts[0]; + v2 = verts[1]; + v3 = verts[2]; + + for (i = 2; i < n; v2 = v3, v3 = verts[++i]) + FX_grDrawTriangle(fxMesa, v, v2, v3); + } +} + + + +static void TAG(fx_line_clip) (struct vertex_buffer * VB, + GLuint v1, GLuint v2, GLubyte mask) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLfloat data[VB_MAX_CLIPPED_VERTS * 12]; + GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; + GLfloat *out = data; + GLfloat *mat = ctx->Viewport.WindowMap.m; + GLfloat w = ctx->Line.Width * .5; + GLuint e, n; + + GLuint tmu0_source = fxMesa->tmu_source[0]; + GLuint tmu1_source = fxMesa->tmu_source[1]; + GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; + GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; + + VARS; + + (void) fxMesa; + (void) tmu0_source; + (void) tc0_vec; + (void) tmu1_source; + (void) tc1_vec; + + vlist[0] = out; + e = v1; + COPY_STRIDE; + out += SIZE; + + vlist[1] = out; + e = v2; + COPY_STRIDE; + out += SIZE; + + if (VB->ClipPtr->size < 4) { + vlist[0][3] = vlist[1][3] = 1.0; + if (VB->ClipPtr->size == 2) + vlist[0][2] = vlist[1][2] = 0.0; + } + + if ((n = fx_clip_line(ctx, vlist, SIZE, mask)) != 0) { + GrVertex gWin[2]; + GrVertex *v; + GLfloat *data; + + v = gWin; + data = vlist[0]; + SETUP; + + v++; + data = vlist[1]; + SETUP; + + DRAW_LINE(fxMesa, gWin, v, w); + } +} + + + +#undef V1 +#undef S1 +#undef C1 +#undef Z1 +#undef T1 + +#undef V2 +#undef S2 +#undef C2 +#undef Z2 +#undef T2 + +#undef V3 +#undef S3 +#undef C3 +#undef Z3 +#undef T3 + +#undef V4 +#undef S4 +#undef C4 +#undef Z4 +#undef T4 + +#undef VARS +#undef SETUP +#undef COPY +#undef COPY_STRIDE +#undef SIZE +#undef IND +#undef TAG diff --git a/xc/extras/Mesa/src/FX/fxcva.c b/xc/lib/GL/mesa/src/drv/tdfx/fxcva.c index 188210add..9a7e2feb5 100644 --- a/xc/extras/Mesa/src/FX/fxcva.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxcva.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -45,18 +43,14 @@ /* fxcva.c - the CVA related code */ - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - #include "fxdrv.h" +#include "fxtexman.h" #include "mmath.h" #include "vbindirect.h" #include "pb.h" +#include "fxsetup.h" #include "fxvsetup.h" +#include "fxcva.h" #include "pipeline.h" #include "stages.h" @@ -66,64 +60,66 @@ #define PRIM_CULLED 3 -static GLuint reduce_prim[GL_POLYGON+2] = { - PRIM_POINTS, - PRIM_LINES, - PRIM_LINES, - PRIM_LINES, - PRIM_TRIS, - PRIM_TRIS, - PRIM_TRIS, - PRIM_TRIS, - PRIM_TRIS, - PRIM_TRIS, - PRIM_CULLED +static GLuint reduce_prim[GL_POLYGON + 2] = { + PRIM_POINTS, + PRIM_LINES, + PRIM_LINES, + PRIM_LINES, + PRIM_TRIS, + PRIM_TRIS, + PRIM_TRIS, + PRIM_TRIS, + PRIM_TRIS, + PRIM_TRIS, + PRIM_CULLED }; -typedef void (*mergefunc)( struct vertex_buffer *cvaVB, - struct vertex_buffer *VB, - const struct gl_prim_state *state, - GLuint start, - GLuint count ); - -static void fxCvaRenderNoop( struct vertex_buffer *cvaVB, - struct vertex_buffer *VB, - const struct gl_prim_state *state, - GLuint start, - GLuint count ) +typedef void (*mergefunc) (struct vertex_buffer * cvaVB, + struct vertex_buffer * VB, + const struct gl_prim_state * state, + GLuint start, GLuint count); + +static void +fxCvaRenderNoop(struct vertex_buffer *cvaVB, + struct vertex_buffer *VB, + const struct gl_prim_state *state, GLuint start, GLuint count) { } -static INLINE void fxRenderClippedTriangle2( struct vertex_buffer *VB, - GLuint v1, GLuint v2, GLuint v3 ) +static INLINE void +fxRenderClippedTriangle2(struct vertex_buffer *VB, + GLuint v1, GLuint v2, GLuint v3) { - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v1] | clipmask[v2] | clipmask[v3]; - - if (!mask) { - FX_grDrawTriangle((GrVertex *)gWin[v1].f, - (GrVertex *)gWin[v2].f, - (GrVertex *)gWin[v3].f); - } else if (!(clipmask[v1]&clipmask[v2]&clipmask[v3]&CLIP_ALL_BITS)) { - GLuint n; - GLuint vlist[VB_MAX_CLIPPED_VERTS]; - ASSIGN_3V(vlist, v1, v2, v3); - - n = (VB->ctx->poly_clip_tab[VB->ClipPtr->size])( VB, 3, vlist, mask ); - if (n >= 3) { - GLuint i, j0 = vlist[0]; - for (i=2;i<n;i++) { - FX_grDrawTriangle((GrVertex *)gWin[j0].f, - (GrVertex *)gWin[vlist[i-1]].f, - (GrVertex *)gWin[vlist[i]].f); - } + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GLubyte *clipmask = VB->ClipMask; + GLubyte mask = clipmask[v1] | clipmask[v2] | clipmask[v3]; + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (!mask) { + FX_grDrawTriangle(fxMesa, (GrVertex *) gWin[v1].f, + (GrVertex *) gWin[v2].f, (GrVertex *) gWin[v3].f); + } + else if (!(clipmask[v1] & clipmask[v2] & clipmask[v3] & CLIP_ALL_BITS)) { + GLuint n; + GLuint vlist[VB_MAX_CLIPPED_VERTS]; + ASSIGN_3V(vlist, v1, v2, v3); + + n = (VB->ctx->poly_clip_tab[VB->ClipPtr->size]) (VB, 3, vlist, mask); + if (n >= 3) { + GLuint i, j0 = vlist[0]; + for (i = 2; i < n; i++) { + FX_grDrawTriangle(fxMesa, + (GrVertex *) gWin[j0].f, + (GrVertex *) gWin[vlist[i - 1]].f, + (GrVertex *) gWin[vlist[i]].f); + } + } } - } } -static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED+1]; +static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED + 1]; /* @@ -174,10 +170,10 @@ static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED+1]; #define INIT_TMU1 (void) cva_tex1; (void) tmu1_stride; (void) tmu1_sz; -#define DRAW_POINT FX_grDrawPoint( (GrVertex *)v ) -#define DRAW_LINE FX_grDrawLine( (GrVertex *)v, (GrVertex *)prev_v ) -#define DRAW_TRI FX_grDrawTriangle( (GrVertex *)gWin[l[0]].f, (GrVertex *)gWin[l[1]].f, (GrVertex *)v ) -#define DRAW_TRI2 FX_grDrawTriangle( vl[0], vl[1], vl[2] ) +#define DRAW_POINT FX_grDrawPoint( fxMesa, (GrVertex *)v ) +#define DRAW_LINE FX_grDrawLine( fxMesa, (GrVertex *)v, (GrVertex *)prev_v ) +#define DRAW_TRI FX_grDrawTriangle( fxMesa, (GrVertex *)gWin[l[0]].f, (GrVertex *)gWin[l[1]].f, (GrVertex *)v ) +#define DRAW_TRI2 FX_grDrawTriangle( fxMesa, vl[0], vl[1], vl[2] ) #define CLIP_LINE fxRenderClippedLine( cvaVB, e, prev ) #define CLIP_OR_DRAW_TRI fxRenderClippedTriangle2( cvaVB, l[0], l[1], e ) #define DIRECT 1 @@ -220,8 +216,8 @@ static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED+1]; #define TAG(x) x##T0T1 #define IDX SETUP_TMU0|SETUP_TMU1 -#define VARS CVA_VARS_TMU0 CVA_VARS_TMU1 -#define INIT INIT_TMU0 INIT_TMU1 +#define VARS CVA_VARS_TMU0 CVA_VARS_TMU1 +#define INIT INIT_TMU0 INIT_TMU1 #define INCR , tmu0_data+=4 , tmu1_data+=4 #define MERGE_RAST DO_SETUP_TMU0 DO_SETUP_TMU1 #define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \ @@ -230,9 +226,9 @@ static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED+1]; #define TAG(x) x##RGBAT0 #define IDX SETUP_RGBA|SETUP_TMU0 -#define VARS CVA_VARS_RGBA CVA_VARS_TMU0 -#define INIT INIT_RGBA INIT_TMU0 -#define INCR , tmu0_data+=4 +#define VARS CVA_VARS_RGBA CVA_VARS_TMU0 +#define INIT INIT_RGBA INIT_TMU0 +#define INCR , tmu0_data+=4 #define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU0 #define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \ COPY_4UBV(cva_color[e], color[i]); @@ -261,15 +257,15 @@ static mergefunc merge_and_render_tab[2][MAX_MERGABLE][PRIM_CULLED+1]; -#undef DRAW_POINT -#undef DRAW_LINE -#undef DRAW_TRI -#undef CLIP_LINE -#undef CLIP_OR_DRAW_TRI +#undef DRAW_POINT +#undef DRAW_LINE +#undef DRAW_TRI +#undef CLIP_LINE +#undef CLIP_OR_DRAW_TRI #undef DIRECT #define DRAW_POINT ctx->Driver.PointsFunc( ctx, e, e ) -#define DRAW_LINE ctx->Driver.LineFunc( ctx, e, prev, e ) +#define DRAW_LINE ctx->Driver.LineFunc( ctx, e, prev, e ) #define DRAW_TRI ctx->TriangleFunc( ctx, l[0], l[1], e, e ) #define CLIP_LINE gl_render_clipped_line( ctx, e, prev ) #define CLIP_OR_DRAW_TRI \ @@ -283,7 +279,7 @@ do { \ else ctx->TriangleFunc( ctx, l[0], l[1], e, e ); \ } while (0) - + #define DIRECT 0 #define TAG(x) x##_indirect @@ -324,8 +320,8 @@ do { \ #define TAG(x) x##T0T1_indirect #define IDX SETUP_TMU0|SETUP_TMU1 -#define VARS CVA_VARS_TMU0 CVA_VARS_TMU1 -#define INIT INIT_TMU0 INIT_TMU1 +#define VARS CVA_VARS_TMU0 CVA_VARS_TMU1 +#define INIT INIT_TMU0 INIT_TMU1 #define INCR , tmu0_data+=4 , tmu1_data+=4 #define MERGE_RAST DO_SETUP_TMU0 DO_SETUP_TMU1 #define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \ @@ -334,8 +330,8 @@ do { \ #define TAG(x) x##RGBAT0_indirect #define IDX SETUP_RGBA|SETUP_TMU0 -#define VARS CVA_VARS_RGBA CVA_VARS_TMU0 -#define INIT INIT_RGBA INIT_TMU0 +#define VARS CVA_VARS_RGBA CVA_VARS_TMU0 +#define INIT INIT_RGBA INIT_TMU0 #define INCR , tmu0_data+=4 #define MERGE_RAST DO_SETUP_RGBA; DO_SETUP_TMU0 #define MERGE_VB COPY_2FV(cva_tex0[e], tmu0_data); \ @@ -366,148 +362,130 @@ do { \ -void fxDDCvaInit() +void +fxDDCvaInit() { - /* Call grDrawTriangle et al */ - init_cva(); - init_cvaT0(); - init_cvaT1(); - init_cvaT0T1(); - init_cvaRGBA(); - init_cvaRGBAT0(); - init_cvaRGBAT1(); - init_cvaRGBAT0T1(); - - /* Call ctx->TriangleFunc and friends */ - init_cva_indirect(); - init_cvaT0_indirect(); - init_cvaT1_indirect(); - init_cvaT0T1_indirect(); - init_cvaRGBA_indirect(); - init_cvaRGBAT0_indirect(); - init_cvaRGBAT1_indirect(); - init_cvaRGBAT0T1_indirect(); + /* Call grDrawTriangle et al */ + init_cva(); + init_cvaT0(); + init_cvaT1(); + init_cvaT0T1(); + init_cvaRGBA(); + init_cvaRGBAT0(); + init_cvaRGBAT1(); + init_cvaRGBAT0T1(); + + /* Call ctx->TriangleFunc and friends */ + init_cva_indirect(); + init_cvaT0_indirect(); + init_cvaT1_indirect(); + init_cvaT0T1_indirect(); + init_cvaRGBA_indirect(); + init_cvaRGBAT0_indirect(); + init_cvaRGBAT1_indirect(); + init_cvaRGBAT0T1_indirect(); } -void fxDDCheckMergeAndRender( GLcontext *ctx, struct gl_pipeline_stage *d ) +void +fxDDCheckMergeAndRender(GLcontext * ctx, struct gl_pipeline_stage *d) { - GLuint inputs = ctx->RenderFlags & ~ctx->CVA.pre.outputs; + GLuint inputs = ctx->RenderFlags & ~ctx->CVA.pre.outputs; - if (!(ctx->TriangleCaps & DD_TRI_UNFILLED) && - (ctx->Array.Summary & VERT_OBJ_ANY)) - { - d->inputs = (VERT_SETUP_PART | VERT_ELT | inputs); - d->outputs = 0; - d->type = PIPE_IMMEDIATE; - } + if (!(ctx->TriangleCaps & DD_TRI_UNFILLED) && + (ctx->Array.Summary & VERT_OBJ_ANY)) { + d->inputs = (VERT_SETUP_PART | VERT_ELT | inputs); + d->outputs = 0; + d->type = PIPE_IMMEDIATE; + } /* gl_print_vert_flags("merge&render inputs", d->inputs); */ } -extern void fxPointSmooth(GLcontext *ctx, GLuint first, GLuint last); -extern void fxLineSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv); -extern void fxTriangleSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint v3, - GLuint pv); +extern void fxPointSmooth(GLcontext * ctx, GLuint first, GLuint last); +extern void fxLineSmooth(GLcontext * ctx, GLuint v1, GLuint v2, GLuint pv); +extern void fxTriangleSmooth(GLcontext * ctx, GLuint v1, GLuint v2, GLuint v3, + GLuint pv); extern const char *gl_prim_name[]; /* static GLboolean edge_flag[GL_POLYGON+2] = { 0,0,0,0,1,0,0,1,0,1,0 }; */ -void fxDDMergeAndRender( struct vertex_buffer *VB ) +void +fxDDMergeAndRender(struct vertex_buffer *VB) { - GLcontext *ctx = VB->ctx; - struct vertex_buffer *cvaVB = ctx->CVA.VB; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - GLuint i, next, prim; - GLuint parity = VB->Parity; - GLuint count = VB->Count; - const struct gl_prim_state *state; - mergefunc func; - struct vertex_buffer *saved_vb = ctx->VB; - GLuint inputs = ctx->RenderFlags & ~ctx->CVA.pre.outputs; - GLuint flags = 0; - GLuint direct = (fxMesa->render_index == 0); - mergefunc (*tab)[PRIM_CULLED+1] = merge_and_render_tab[direct]; - GLuint p = 0; - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - - /* May actually contain elements not present in fxMesa->setupindex, - * eg RGBA when flat shading. These need to be copied into the cva - * VB so that funcs like fxTriangleFlat will be able to reach them. - * - * This leads to some duplication of effort in the merge funcs. - */ - if (inputs & VERT_RGBA) { - cvaVB->ColorPtr = cvaVB->Color[0] = cvaVB->LitColor[0]; - cvaVB->Color[1] = cvaVB->LitColor[1]; - flags |= SETUP_RGBA; - } - - if (inputs & VERT_TEX0_ANY) { - cvaVB->TexCoordPtr[0] = cvaVB->store.TexCoord[0]; - flags |= fxMesa->tex_dest[0]; - } - - if (inputs & VERT_TEX1_ANY) { - cvaVB->TexCoordPtr[1] = cvaVB->store.TexCoord[1]; - flags |= fxMesa->tex_dest[1]; - } -#if 0 - fxPrintSetupFlags("FX cva merge & render", flags); -#endif - - if (cvaVB->ClipOrMask) - gl_import_client_data( cvaVB, ctx->RenderFlags, - VEC_WRITABLE|VEC_GOOD_STRIDE ); - - ctx->VB = cvaVB; + GLcontext *ctx = VB->ctx; + struct vertex_buffer *cvaVB = ctx->CVA.VB; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint i, next, prim; + GLuint parity = VB->Parity; + GLuint count = VB->Count; + const struct gl_prim_state *state; + mergefunc func; + struct vertex_buffer *saved_vb = ctx->VB; + GLuint inputs = ctx->RenderFlags & ~ctx->CVA.pre.outputs; + GLuint flags = 0; + GLuint direct = (fxMesa->render_index == 0); + mergefunc(*tab)[PRIM_CULLED + 1] = merge_and_render_tab[direct]; + GLuint p = 0; + + if (fxMesa->new_state) + fxSetupFXUnits(ctx); + + + /* May actually contain elements not present in fxMesa->setupindex, + * eg RGBA when flat shading. These need to be copied into the cva + * VB so that funcs like fxTriangleFlat will be able to reach them. + * + * This leads to some duplication of effort in the merge funcs. + */ + if (inputs & VERT_RGBA) { + cvaVB->ColorPtr = cvaVB->Color[0] = cvaVB->LitColor[0]; + cvaVB->Color[1] = cvaVB->LitColor[1]; + flags |= SETUP_RGBA; + } - do { - for ( i= VB->CopyStart ; i < count ; parity = 0, i = next ) - { - prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; + if (inputs & VERT_TEX0_ANY) { + cvaVB->TexCoordPtr[0] = cvaVB->store.TexCoord[0]; + flags |= fxMesa->tex_dest[0]; + } - state = gl_prim_state_machine[prim][parity]; - func = tab[flags][reduce_prim[prim]]; - func( cvaVB, VB, state, i, next ); - - if ( ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE ) - { - cvaVB->Specular = cvaVB->Spec[0]; - cvaVB->ColorPtr = cvaVB->Color[0]; - cvaVB->IndexPtr = cvaVB->Index[0]; - } - } - } while (ctx->Driver.MultipassFunc && - ctx->Driver.MultipassFunc( VB, ++p )); + if (inputs & VERT_TEX1_ANY) { + cvaVB->TexCoordPtr[1] = cvaVB->store.TexCoord[1]; + flags |= fxMesa->tex_dest[1]; + } +#if 0 + fxPrintSetupFlags("FX cva merge & render", flags); +#endif + if (cvaVB->ClipOrMask) + gl_import_client_data(cvaVB, ctx->RenderFlags, + VEC_WRITABLE | VEC_GOOD_STRIDE); + ctx->VB = cvaVB; - if (ctx->PB->count > 0) - gl_flush_pb(ctx); + do { + for (i = VB->CopyStart; i < count; parity = 0, i = next) { + prim = VB->Primitive[i]; + next = VB->NextPrimitive[i]; - ctx->VB = saved_vb; -} + state = gl_prim_state_machine[prim][parity]; + func = tab[flags][reduce_prim[prim]]; + func(cvaVB, VB, state, i, next); + if (ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { + cvaVB->Specular = cvaVB->Spec[0]; + cvaVB->ColorPtr = cvaVB->Color[0]; + cvaVB->IndexPtr = cvaVB->Index[0]; + } + } + } while (ctx->Driver.MultipassFunc && ctx->Driver.MultipassFunc(VB, ++p)); -#else + if (ctx->PB->count > 0) + gl_flush_pb(ctx); -/* - * Need this to provide at least one external definition. - */ - -int gl_fx_dummy_function_cva(void) -{ - return 0; + ctx->VB = saved_vb; } - - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxcva.h b/xc/lib/GL/mesa/src/drv/tdfx/fxcva.h index f809ec010..f5f416da6 100644 --- a/xc/extras/Mesa/src/FX/fxcva.h +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxcva.h @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -48,23 +46,18 @@ -extern GLboolean fxMergeAndRenderCVA( struct vertex_buffer *VB, - struct vertex_buffer *cvaVB ); - - +extern GLboolean fxMergeAndRenderCVA(struct vertex_buffer *VB, + struct vertex_buffer *cvaVB); -extern void fxRenderCVAElements( struct vertex_buffer *VB, - GLenum mode, - GLuint *elts, - GLuint n ); +extern void fxRenderCVAElements(struct vertex_buffer *VB, + GLenum mode, GLuint * elts, GLuint n); +extern GLboolean fxCheckCVA(GLcontext * ctx); -extern GLboolean fxCheckCVA( GLcontext *ctx ); - - -extern void fxPrecalcCVA( struct vertex_buffer *VB ); +extern void fxPrecalcCVA(struct vertex_buffer *VB); +extern void fxDDCheckMergeAndRender(GLcontext * ctx, + struct gl_pipeline_stage *d); #endif - diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h new file mode 100644 index 000000000..584ef7504 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h @@ -0,0 +1,277 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +static void TAG(cva_render_points) (struct vertex_buffer * cvaVB, + struct vertex_buffer * VB, + const struct gl_prim_state * state, + GLuint start, GLuint count) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; + const GLuint *elt = VB->EltPtr->data; + GLuint i; + + VARS; + INIT; + (void) fxMesa; + + if (cvaVB->ClipOrMask) { + const GLubyte *clip = cvaVB->ClipMask; + for (i = start; i < count; i++ INCR) { + GLuint e = elt[i]; + if (!clip[e]) { + GLfloat *v = gWin[e].f; + (void) v; + if (!DIRECT) { + MERGE_VB; + } + MERGE_RAST; + DRAW_POINT; + } + } + } + else { + for (i = start; i < count; i++ INCR) { + GLuint e = elt[i]; + GLfloat *v = gWin[e].f; + (void) v; + if (!DIRECT) { + MERGE_VB; + } + MERGE_RAST; + DRAW_POINT; + } + } +} + +static void TAG(cva_render_lines) (struct vertex_buffer * cvaVB, + struct vertex_buffer * VB, + const struct gl_prim_state * state, + GLuint start, GLuint count) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; + const GLuint *elt = VB->EltPtr->data; + GLuint i; + + VARS; + INIT; + (void) fxMesa; + + if (cvaVB->ClipOrMask) { + const GLubyte *clip = cvaVB->ClipMask; + GLuint prev = 0; + GLfloat *prev_v = 0; + + (void) ctx; + + for (i = start; i < count; i++ INCR) { + GLuint e = elt[i]; + GLfloat *v = gWin[e].f; + + MERGE_VB; + + if (!clip[e]) + MERGE_RAST; + + if (state->draw) { + if (clip[e] | clip[prev]) + CLIP_LINE; + else + DRAW_LINE; + } + + prev = e; + prev_v = v; + state = state->next; + } + if (state->finish_loop) { + GLuint e = elt[start]; + GLfloat *v = gWin[e].f; + (void) v; + + if (!DIRECT) { + MERGE_VB; + } + MERGE_RAST; + + if (clip[e] | clip[prev]) + CLIP_LINE; + else + DRAW_LINE; + } + } + else { + GLuint prev = 0; + GLfloat *prev_v = 0; + + for (i = start; i < count; i++ INCR) { + GLuint e = elt[i]; + GLfloat *v = gWin[e].f; + + if (!DIRECT) { + MERGE_VB; + } + MERGE_RAST; + if (state->draw) + DRAW_LINE; + prev = e; + prev_v = v; + state = state->next; + } + if (state->finish_loop) { + GLuint e = elt[start]; + GLfloat *v = gWin[e].f; + (void) v; + + if (!DIRECT) { + MERGE_VB; + } + MERGE_RAST; + DRAW_LINE; + } + } +} + + +static void TAG(cva_render_tris) (struct vertex_buffer * cvaVB, + struct vertex_buffer * VB, + const struct gl_prim_state * state, + GLuint start, GLuint count) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; + const GLuint *elt = VB->EltPtr->data; + GLuint i; + VARS; + INIT; + (void) fxMesa; + + if (cvaVB->ClipOrMask) { + GLuint vlist[VB_MAX_CLIPPED_VERTS]; + GLuint l[3]; + const GLubyte *clip = cvaVB->ClipMask; + + (void) vlist; + + for (i = start; i < count; i++ INCR) { + GLuint e = l[2] = elt[i]; + GLfloat *v = gWin[e].f; + (void) v; + + MERGE_VB; /* needed for clip-interp */ + + if (!clip[e]) { + MERGE_RAST; + } + + if (state->draw) + CLIP_OR_DRAW_TRI; + + + l[0] = l[state->v0]; + l[1] = l[state->v1]; + state = state->next; + } + } + else if (DIRECT) { + GrVertex *vl[3]; + for (i = start; i < count; i++ INCR) { + GLuint e = elt[i]; + GLfloat *v = gWin[elt[i]].f; + + vl[2] = (GrVertex *) v; + + (void) v; + (void) e; + + MERGE_RAST; + + if (state->draw) + DRAW_TRI2; + + vl[0] = vl[state->v0]; + vl[1] = vl[state->v1]; + state = state->next; + } + } + else { + GLuint l[3]; + for (i = start; i < count; i++ INCR) { + GLuint e = l[2] = elt[i]; + GLfloat *v = gWin[e].f; + (void) v; + + MERGE_VB; /* needed for ctx->trianglefunc? */ + MERGE_RAST; + + if (state->draw) + DRAW_TRI; + + l[0] = l[state->v0]; + l[1] = l[state->v1]; + state = state->next; + } + } +} + + +static void TAG(init_cva) (void) +{ + merge_and_render_tab[DIRECT][IDX][PRIM_POINTS] = TAG(cva_render_points); + merge_and_render_tab[DIRECT][IDX][PRIM_LINES] = TAG(cva_render_lines); + merge_and_render_tab[DIRECT][IDX][PRIM_TRIS] = TAG(cva_render_tris); + merge_and_render_tab[DIRECT][IDX][PRIM_CULLED] = fxCvaRenderNoop; +} + + +#undef IDX +#undef MERGE_RAST +#undef MERGE_VB +#undef VARS +#undef INIT +#undef INCR +#undef TAG diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxdd.c b/xc/lib/GL/mesa/src/drv/tdfx/fxdd.c new file mode 100644 index 000000000..19c534c2f --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxdd.c @@ -0,0 +1,1938 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#include <dlfcn.h> +#include "image.h" +#include "types.h" +#include "fxdrv.h" +#include "fxsetup.h" +#include "fxpipeline.h" +#include "fxddtex.h" +#include "fxtexman.h" +#include "enums.h" +#include "extensions.h" +#include "pb.h" + + +/* These are used in calls to FX_grColorMaskv() */ +static const GLboolean false4[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; +static const GLboolean true4[4] = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE }; + +#if defined(FX_PXCONV_TABULAR) +/* These lookup table are used to extract RGB values in [0,255] from + * 16-bit pixel values. + */ +GLubyte FX_PixelToRArray[0x10000]; +GLubyte FX_PixelToGArray[0x10000]; +GLubyte FX_PixelToBArray[0x10000]; +#endif /* defined(FX_PXCONV_TABULAR) */ + +/* + * Initialize the FX_PixelTo{RGB} arrays. + * Input: bgrOrder - if TRUE, pixels are in BGR order, else RGB order. + */ +void +fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder) +{ + fxMesa->bgrOrder = bgrOrder; +#ifdef FX_PXCONV_TABULAR + /* + * We add a level of braces so that we can define the + * variable pixel here. + */ + { + GLuint pixel = 0; + for (pixel = 0; pixel <= 0xffff; pixel++) { + GLuint r, g, b; + if (bgrOrder) { + r = (pixel & 0x001F) << 3; + g = (pixel & 0x07E0) >> 3; + b = (pixel & 0xF800) >> 8; + } + else { + r = (pixel & 0xF800) >> 8; + g = (pixel & 0x07E0) >> 3; + b = (pixel & 0x001F) << 3; + } + r = r * 255 / 0xF8; /* fill in low-order bits */ + g = g * 255 / 0xFC; + b = b * 255 / 0xF8; + FX_PixelToRArray[pixel] = r; + FX_PixelToGArray[pixel] = g; + FX_PixelToBArray[pixel] = b; + } + } +#endif /* FX_PXCONV_TABULAR */ +} + +/**********************************************************************/ +/***** Miscellaneous functions *****/ +/**********************************************************************/ + + +/* Return buffer size information */ +static void +fxDDBufferSize(GLcontext * ctx, GLuint * width, GLuint * height) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDBufferSize(...) Start\n"); + } + + *width = fxMesa->width; + *height = fxMesa->height; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDBufferSize(...) End\n"); + } +} + + +/* Set current drawing color */ +static void +fxDDSetColor(GLcontext * ctx, GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GLubyte col[4]; + ASSIGN_4V(col, red, green, blue, alpha); + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDSetColor(%d,%d,%d,%d)\n", red, green, + blue, alpha); + } + fxMesa->color = FXCOLOR4(col); +} + + +/* Implements glClearColor() */ +static void +fxDDClearColor(GLcontext * ctx, GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GLubyte col[4]; + ASSIGN_4V(col, red, green, blue, 255); + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDClearColor(%d,%d,%d,%d)\n", red, green, + blue, alpha); + } + fxMesa->clearC = FXCOLOR4(col); + fxMesa->clearA = alpha; +} + + +/* Clear the color and/or depth buffers */ +static GLbitfield +fxDDClear(GLcontext * ctx, GLbitfield mask, GLboolean all, + GLint x, GLint y, GLint width, GLint height) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + const GLuint colorMask = *((GLuint *) & ctx->Color.ColorMask); + const FxU32 clearD = (FxU32) (ctx->Depth.Clear * fxMesa->depthClear); + const FxU32 clearS = (FxU32) (ctx->Stencil.Clear); + GLbitfield softwareMask = mask & (DD_ACCUM_BIT); + GLuint stencil_size = + fxMesa->haveHwStencil ? fxMesa->glVis->StencilBits : 0; + + /* we can't clear accum buffers */ + mask &= ~(DD_ACCUM_BIT); + + if ((mask & DD_STENCIL_BIT) && !fxMesa->haveHwStencil) { + /* software stencil buffer */ + mask &= ~(DD_STENCIL_BIT); + softwareMask |= DD_STENCIL_BIT; + } + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDClear(%d,%d,%d,%d)\n", (int) x, (int) y, + (int) width, (int) height); + } + + if (colorMask != 0xffffffff) { + /* do masked color buffer clears in software */ + softwareMask |= (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)); + mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); + } + + + if (fxMesa->haveHwStencil) { + /* + * If we want to clear stencil, it must be enabled + * in the HW, even if the stencil test is not enabled + * in the OGL state. + */ + if (mask & DD_STENCIL_BIT) { + FX_grStencilMask(fxMesa, ctx->Stencil.WriteMask); + /* set stencil ref value = desired clear value */ + FX_grStencilFunc(fxMesa, GR_CMP_ALWAYS, ctx->Stencil.Clear, 0xff); + FX_grStencilOp(fxMesa, GR_STENCILOP_REPLACE, + GR_STENCILOP_REPLACE, GR_STENCILOP_REPLACE); + FX_grEnable(fxMesa, GR_STENCIL_MODE_EXT); + } + else { + FX_grDisable(fxMesa, GR_STENCIL_MODE_EXT); + } + } + + /* + * This could probably be done fancier but doing each possible case + * explicitly is less error prone. + */ + switch (mask & ~DD_STENCIL_BIT) { + case DD_BACK_LEFT_BIT | DD_DEPTH_BIT: + /* back buffer & depth */ + FX_grDepthMask(fxMesa, FXTRUE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + if (!ctx->Depth.Mask || !ctx->Depth.Test) { + FX_grDepthMask(fxMesa, FXFALSE); + } + break; + case DD_FRONT_LEFT_BIT | DD_DEPTH_BIT: + /* XXX it appears that the depth buffer isn't cleared when + * glRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER) is set. + * This is a work-around/ + */ + /* clear depth */ + FX_grDepthMask(fxMesa, FXTRUE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + FX_grColorMaskv(ctx, false4); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + /* clear front */ + FX_grColorMaskv(ctx, true4); + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + if (!ctx->Depth.Mask || !ctx->Depth.Test) { + FX_grDepthMask(fxMesa, FXFALSE); + } + break; + case DD_BACK_LEFT_BIT: + /* back buffer only */ + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask(fxMesa, FXTRUE); + } + break; + case DD_FRONT_LEFT_BIT: + /* front buffer only */ + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask(fxMesa, FXTRUE); + } + break; + case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT: + /* front and back */ + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask(fxMesa, FXTRUE); + } + break; + case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT: + /* clear front */ + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + /* clear back and depth */ + FX_grDepthMask(fxMesa, FXTRUE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + if (!ctx->Depth.Mask || !ctx->Depth.Mask) { + FX_grDepthMask(fxMesa, FXFALSE); + } + break; + case DD_DEPTH_BIT: + /* just the depth buffer */ + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + FX_grColorMaskv(ctx, false4); + FX_grDepthMask(fxMesa, FXTRUE); + if (stencil_size > 0) + FX_grBufferClearExt(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD, + clearS); + else + FX_grBufferClear(fxMesa, fxMesa->clearC, fxMesa->clearA, clearD); + FX_grColorMaskv(ctx, true4); + if (ctx->Color.DrawDestMask & FRONT_LEFT_BIT) + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + if (!ctx->Depth.Test || !ctx->Depth.Mask) + FX_grDepthMask(fxMesa, FXFALSE); + break; + default: + /* error */ + ; + } + + if (fxMesa->haveHwStencil) { + if (ctx->Stencil.Enabled) { + /* restore stencil state to as it was before the clear */ + GrStencil_t sfail = fxConvertGLStencilOp(ctx->Stencil.FailFunc); + GrStencil_t zfail = fxConvertGLStencilOp(ctx->Stencil.ZFailFunc); + GrStencil_t zpass = fxConvertGLStencilOp(ctx->Stencil.ZPassFunc); + FX_grStencilOp(fxMesa, sfail, zfail, zpass); + FX_grStencilMask(fxMesa, ctx->Stencil.WriteMask); + FX_grStencilFunc(fxMesa, ctx->Stencil.Function - GL_NEVER, + ctx->Stencil.Ref, ctx->Stencil.ValueMask); + FX_grEnable(fxMesa, GR_STENCIL_MODE_EXT); + } + else { + FX_grDisable(fxMesa, GR_STENCIL_MODE_EXT); + } + } + return softwareMask; +} + + +/* Set the buffer used for drawing */ +/* XXX support for separate read/draw buffers hasn't been tested */ +static GLboolean +fxDDSetDrawBuffer(GLcontext * ctx, GLenum mode) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDSetBuffer(%x)\n", (int) mode); + } + + if (mode == GL_FRONT_LEFT) { + fxMesa->currentFB = GR_BUFFER_FRONTBUFFER; + FX_grRenderBuffer(fxMesa, fxMesa->currentFB); + return GL_TRUE; + } + else if (mode == GL_BACK_LEFT) { + fxMesa->currentFB = GR_BUFFER_BACKBUFFER; + FX_grRenderBuffer(fxMesa, fxMesa->currentFB); + return GL_TRUE; + } + else if (mode == GL_NONE) { + FX_grColorMaskv(ctx, false4); + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + + +/* Set the buffer used for reading */ +/* XXX support for separate read/draw buffers hasn't been tested */ +static void +fxDDSetReadBuffer(GLcontext * ctx, GLframebuffer * buffer, GLenum mode) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + (void) buffer; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDSetBuffer(%x)\n", (int) mode); + } + + if (mode == GL_FRONT_LEFT) { + fxMesa->currentFB = GR_BUFFER_FRONTBUFFER; + FX_grRenderBuffer(fxMesa, fxMesa->currentFB); + } + else if (mode == GL_BACK_LEFT) { + fxMesa->currentFB = GR_BUFFER_BACKBUFFER; + FX_grRenderBuffer(fxMesa, fxMesa->currentFB); + } +} + + +/* + * These functions just set new-state flags. The exact state + * values will be evaluated later. + */ +static void +fxDDStencilFunc(GLcontext * ctx, GLenum func, GLint ref, GLuint mask) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + (void) func; + (void) ref; + (void) mask; + fxMesa->new_state |= FX_NEW_STENCIL; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +static void +fxDDStencilMask(GLcontext * ctx, GLuint mask) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + (void) mask; + fxMesa->new_state |= FX_NEW_STENCIL; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +static void +fxDDStencilOp(GLcontext * ctx, GLenum sfail, GLenum zfail, GLenum zpass) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + (void) sfail; + (void) zfail; + (void) zpass; + fxMesa->new_state |= FX_NEW_STENCIL; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +static void +fxDDDepthFunc(GLcontext * ctx, GLenum func) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + (void) func; + fxMesa->new_state |= FX_NEW_DEPTH; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +static void +fxDDDepthMask(GLcontext * ctx, GLboolean mask) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + (void) mask; + fxMesa->new_state |= FX_NEW_DEPTH; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + + + +/* + * Return the current value of the occlusion test flag and + * reset the flag (hardware counters) to false. + */ +static GLboolean +get_occlusion_result(GLcontext *ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLboolean result; + + BEGIN_BOARD_LOCK(fxMesa); + + if (ctx->Depth.OcclusionTest) { + if (ctx->OcclusionResult) { + result = GL_TRUE; /* result of software rendering */ + } + else { + FxI32 zfail, in; + zfail = FX_grGetInteger_NoLock(GR_STATS_PIXELS_DEPTHFUNC_FAIL); + in = FX_grGetInteger_NoLock(GR_STATS_PIXELS_IN); + if (in == zfail) + result = GL_FALSE; /* geom was completely occluded */ + else + result = GL_TRUE; /* all or part of geom was visible */ + } + } + else { + result = ctx->OcclusionResultSaved; + } + + /* reset results now */ + grReset(GR_STATS_PIXELS); + ctx->OcclusionResult = GL_FALSE; + ctx->OcclusionResultSaved = GL_FALSE; + + END_BOARD_LOCK(fxMesa); + + return result; +} + + +/* + * We're only implementing this function to handle the + * GL_OCCLUSTION_TEST_RESULT_HP case. It's special because it + * has a side-effect: resetting the occlustion result flag. + */ +static GLboolean +fxDDGetBooleanv(GLcontext *ctx, GLenum pname, GLboolean *result) +{ + if (pname == GL_OCCLUSION_TEST_RESULT_HP) { + *result = get_occlusion_result(ctx); + return GL_TRUE; + } + return GL_FALSE; +} + + +static GLboolean +fxDDGetIntegerv(GLcontext *ctx, GLenum pname, GLint *result) +{ + if (pname == GL_OCCLUSION_TEST_RESULT_HP) { + *result = (GLint) get_occlusion_result(ctx); + return GL_TRUE; + } + return GL_FALSE; +} + + +static GLboolean +fxDDGetFloatv(GLcontext *ctx, GLenum pname, GLfloat *result) +{ + if (pname == GL_OCCLUSION_TEST_RESULT_HP) { + *result = (GLfloat) get_occlusion_result(ctx); + return GL_TRUE; + } + return GL_FALSE; +} + + +static GLboolean +fxDDGetDoublev(GLcontext *ctx, GLenum pname, GLdouble *result) +{ + if (pname == GL_OCCLUSION_TEST_RESULT_HP) { + *result = (GLdouble) get_occlusion_result(ctx); + return GL_TRUE; + } + return GL_FALSE; +} + + +#ifdef XF86DRI +/* test if window coord (px,py) is visible */ +static GLboolean +inClipRects(fxMesaContext fxMesa, int px, int py) +{ + int i; + for (i = 0; i < fxMesa->numClipRects; i++) { + if ((px >= fxMesa->pClipRects[i].x1) && + (px < fxMesa->pClipRects[i].x2) && + (py >= fxMesa->pClipRects[i].y1) && + (py < fxMesa->pClipRects[i].y2)) return GL_TRUE; + } + return GL_FALSE; +} +#endif + + + +static GLboolean +bitmap_R5G6B5(GLcontext * ctx, GLint px, GLint py, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte * bitmap) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + FxU16 color; + const struct gl_pixelstore_attrib *finalUnpack; + struct gl_pixelstore_attrib scissoredUnpack; + + /* check if there's any raster operations enabled which we can't handle */ + if (ctx->RasterMask & (ALPHATEST_BIT | + BLEND_BIT | + DEPTH_BIT | + FOG_BIT | + LOGIC_OP_BIT | + SCISSOR_BIT | + STENCIL_BIT | + MASKING_BIT | + ALPHABUF_BIT | MULTI_DRAW_BIT)) return GL_FALSE; + + if (ctx->Scissor.Enabled) { + /* This is a bit tricky, but by carefully adjusting the px, py, + * width, height, skipPixels and skipRows values we can do + * scissoring without special code in the rendering loop. + */ + + /* we'll construct a new pixelstore struct */ + finalUnpack = &scissoredUnpack; + scissoredUnpack = *unpack; + if (scissoredUnpack.RowLength == 0) + scissoredUnpack.RowLength = width; + + /* clip left */ + if (px < ctx->Scissor.X) { + scissoredUnpack.SkipPixels += (ctx->Scissor.X - px); + width -= (ctx->Scissor.X - px); + px = ctx->Scissor.X; + } + /* clip right */ + if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) { + width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width)); + } + /* clip bottom */ + if (py < ctx->Scissor.Y) { + scissoredUnpack.SkipRows += (ctx->Scissor.Y - py); + height -= (ctx->Scissor.Y - py); + py = ctx->Scissor.Y; + } + /* clip top */ + if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) { + height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height)); + } + + if (width <= 0 || height <= 0) + return GL_TRUE; /* totally scissored away */ + } + else { + finalUnpack = unpack; + } + + /* compute pixel value */ + { + GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f); + GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f); + GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f); + /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f); */ + if (fxMesa->bgrOrder) { + color = (FxU16) + (((FxU16) 0xf8 & b) << (11 - 3)) | + (((FxU16) 0xfc & g) << (5 - 3 + 1)) | + (((FxU16) 0xf8 & r) >> 3); + } + else + color = (FxU16) + (((FxU16) 0xf8 & r) << (11 - 3)) | + (((FxU16) 0xfc & g) << (5 - 3 + 1)) | + (((FxU16) 0xf8 & b) >> 3); + } + + info.size = sizeof(info); + if (!FX_grLfbLock(fxMesa, + GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { +#ifndef FX_SILENT + fprintf(stderr, "fx Driver: error locking the linear frame buffer\n"); +#endif + return GL_TRUE; + } + +#ifdef XF86DRI +#define INSIDE(c, x, y) inClipRects((c), (x), (y)) +#else +#define INSIDE(c, x, y) (1) +#endif + + { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + /* The dest stride depends on the hardware and whether we're drawing + * to the front or back buffer. This compile-time test seems to do + * the job for now. + */ +#ifdef XF86DRI + const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); +#else + const GLint dstStride = info.strideInBytes / 2; /* stride in GLushorts */ +#endif + GLint row; + /* compute dest address of bottom-left pixel in bitmap */ + GLushort *dst = (GLushort *) info.lfbPtr + + (winY - py) * dstStride + (winX + px); + + for (row = 0; row < height; row++) { + const GLubyte *src = + (const GLubyte *) _mesa_image_address(finalUnpack, + bitmap, width, height, + GL_COLOR_INDEX, + GL_BITMAP, 0, row, 0); + if (finalUnpack->LsbFirst) { + /* least significan bit first */ + GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (INSIDE(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + if (mask != 1) + src++; + } + else { + /* most significan bit first */ + GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (INSIDE(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + if (mask != 128) + src++; + } + dst -= dstStride; + } + } + +#undef INSIDE + + FX_grLfbUnlock(fxMesa, GR_LFB_WRITE_ONLY, fxMesa->currentFB); + return GL_TRUE; +} + + +static GLboolean +bitmap_R8G8B8A8(GLcontext * ctx, GLint px, GLint py, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte * bitmap) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLuint color; + const struct gl_pixelstore_attrib *finalUnpack; + struct gl_pixelstore_attrib scissoredUnpack; + + /* check if there's any raster operations enabled which we can't handle */ + if (ctx->RasterMask & (ALPHATEST_BIT | + BLEND_BIT | + DEPTH_BIT | + FOG_BIT | + LOGIC_OP_BIT | + SCISSOR_BIT | + STENCIL_BIT | + MASKING_BIT | + ALPHABUF_BIT | MULTI_DRAW_BIT)) return GL_FALSE; + + if (ctx->Scissor.Enabled) { + /* This is a bit tricky, but by carefully adjusting the px, py, + * width, height, skipPixels and skipRows values we can do + * scissoring without special code in the rendering loop. + */ + + /* we'll construct a new pixelstore struct */ + finalUnpack = &scissoredUnpack; + scissoredUnpack = *unpack; + if (scissoredUnpack.RowLength == 0) + scissoredUnpack.RowLength = width; + + /* clip left */ + if (px < ctx->Scissor.X) { + scissoredUnpack.SkipPixels += (ctx->Scissor.X - px); + width -= (ctx->Scissor.X - px); + px = ctx->Scissor.X; + } + /* clip right */ + if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) { + width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width)); + } + /* clip bottom */ + if (py < ctx->Scissor.Y) { + scissoredUnpack.SkipRows += (ctx->Scissor.Y - py); + height -= (ctx->Scissor.Y - py); + py = ctx->Scissor.Y; + } + /* clip top */ + if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) { + height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height)); + } + + if (width <= 0 || height <= 0) + return GL_TRUE; /* totally scissored away */ + } + else { + finalUnpack = unpack; + } + + /* compute pixel value */ + { + GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f); + GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f); + GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f); + GLint a = (GLint) (ctx->Current.RasterColor[3] * 255.0f); + color = PACK_BGRA32(r, g, b, a); + } + + info.size = sizeof(info); + if (!FX_grLfbLock(fxMesa, GR_LFB_WRITE_ONLY, + fxMesa->currentFB, GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { +#ifndef FX_SILENT + fprintf(stderr, "fx Driver: error locking the linear frame buffer\n"); +#endif + return GL_TRUE; + } + +#ifdef XF86DRI +#define INSIDE(c, x, y) inClipRects((c), (x), (y)) +#else +#define INSIDE(c, x, y) (1) +#endif + + { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + GLint dstStride; + GLuint *dst; + GLint row; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + dstStride = fxMesa->screen_width; + dst = + (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX + + px); + } + else { + dstStride = info.strideInBytes / 4; + dst = + (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX + + px); + } + + /* compute dest address of bottom-left pixel in bitmap */ + for (row = 0; row < height; row++) { + const GLubyte *src = + (const GLubyte *) _mesa_image_address(finalUnpack, + bitmap, width, height, + GL_COLOR_INDEX, + GL_BITMAP, 0, row, 0); + if (finalUnpack->LsbFirst) { + /* least significan bit first */ + GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (INSIDE(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + if (mask != 1) + src++; + } + else { + /* most significan bit first */ + GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (INSIDE(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + if (mask != 128) + src++; + } + dst -= dstStride; + } + } + +#undef INSIDE + + FX_grLfbUnlock(fxMesa, GR_LFB_WRITE_ONLY, fxMesa->currentFB); + return GL_TRUE; +} + + +static GLboolean +readpixels_R5G6B5(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid * dstImage) +{ + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + else { + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; +#ifdef XF86DRI + const GLint srcStride = + (fxMesa->glCtx->Color.DrawBuffer == + GL_FRONT) ? (fxMesa->screen_width) : (info.strideInBytes / + 2); +#else + const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */ +#endif + const GLushort *src = (const GLushort *) info.lfbPtr + + (winY - y) * srcStride + (winX + x); + GLubyte *dst = (GLubyte *) _mesa_image_address(packing, dstImage, + width, height, + format, type, 0, 0, + 0); + GLint dstStride = + _mesa_image_row_stride(packing, width, format, type); + + if (format == GL_RGB && type == GL_UNSIGNED_BYTE) { + /* convert 5R6G5B into 8R8G8B */ + GLint row, col; + const GLint halfWidth = width >> 1; + const GLint extraPixel = (width & 1); + for (row = 0; row < height; row++) { + GLubyte *d = dst; + for (col = 0; col < halfWidth; col++) { + const GLuint pixel = ((const GLuint *) src)[col]; + const GLint pixel0 = pixel & 0xffff; + const GLint pixel1 = pixel >> 16; + *d++ = FX_PixelToR(fxMesa, pixel0); + *d++ = FX_PixelToG(fxMesa, pixel0); + *d++ = FX_PixelToB(fxMesa, pixel0); + *d++ = FX_PixelToR(fxMesa, pixel1); + *d++ = FX_PixelToG(fxMesa, pixel1); + *d++ = FX_PixelToB(fxMesa, pixel1); + } + if (extraPixel) { + GLushort pixel = src[width - 1]; + *d++ = FX_PixelToR(fxMesa, pixel); + *d++ = FX_PixelToG(fxMesa, pixel); + *d++ = FX_PixelToB(fxMesa, pixel); + } + dst += dstStride; + src -= srcStride; + } + result = GL_TRUE; + } + else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { + /* convert 5R6G5B into 8R8G8B8A */ + GLint row, col; + const GLint halfWidth = width >> 1; + const GLint extraPixel = (width & 1); + for (row = 0; row < height; row++) { + GLubyte *d = dst; + for (col = 0; col < halfWidth; col++) { + const GLuint pixel = ((const GLuint *) src)[col]; + const GLint pixel0 = pixel & 0xffff; + const GLint pixel1 = pixel >> 16; + *d++ = FX_PixelToR(fxMesa, pixel0); + *d++ = FX_PixelToG(fxMesa, pixel0); + *d++ = FX_PixelToB(fxMesa, pixel0); + *d++ = 255; + *d++ = FX_PixelToR(fxMesa, pixel1); + *d++ = FX_PixelToG(fxMesa, pixel1); + *d++ = FX_PixelToB(fxMesa, pixel1); + *d++ = 255; + } + if (extraPixel) { + const GLushort pixel = src[width - 1]; + *d++ = FX_PixelToR(fxMesa, pixel); + *d++ = FX_PixelToG(fxMesa, pixel); + *d++ = FX_PixelToB(fxMesa, pixel); + *d++ = 255; + } + dst += dstStride; + src -= srcStride; + } + result = GL_TRUE; + } + else if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { + /* directly memcpy 5R6G5B pixels into client's buffer */ + const GLint widthInBytes = width * 2; + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst += dstStride; + src -= srcStride; + } + result = GL_TRUE; + } + else { + result = GL_FALSE; + } + + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); + return result; + } +} + + + +static GLboolean +readpixels_R8G8B8A8(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid * dstImage) +{ + if (!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) + && !(format == GL_BGRA && type == GL_UNSIGNED_BYTE) + && !(format == GL_RGBA && type == GL_UNSIGNED_BYTE)) { + return GL_FALSE; /* format/type not optimised */ + } + + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + + { + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { +#ifdef XF86DRI + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 4); +#else + const GLint srcStride = info.strideInBytes / 4; /* stride in GLuints */ +#endif + const GLuint *src = (const GLuint *) info.lfbPtr + + scrY * srcStride + scrX; + const GLint dstStride = + _mesa_image_row_stride(packing, width, format, type); + const GLubyte *dst = (GLubyte *) _mesa_image_address(packing, + dstImage, width, height, format, type, 0, 0, 0); + + if ((format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) + || (format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + const GLint widthInBytes = width * 4; + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst += dstStride; + src -= srcStride; + } + result = GL_TRUE; + } else + if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) { + const GLint widthInBytes = width * 4; + GLuint *dstp = (GLuint *)dst; + GLint row; + GLint i; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst += dstStride; + src -= srcStride; + /* Data is in memory in BGRA format - we need to convert now */ + for (i = 0; i < width; i++) { + const GLuint data = *dstp; + /* Swap R & B values */ + *dstp++ = ((data & 0xff) << 16) | + ((data & 0xff0000) >> 16) | + (data & 0xff00ff00); + } + } + result = GL_TRUE; + } + + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); + return result; + } +} + + + +static GLboolean +drawpixels_R8G8B8A8(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid * pixels) +{ + if (!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) + && !(format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + return GL_FALSE; /* format/type not optimised */ + } + + if (ctx->Pixel.ZoomX!=1.0F || ctx->Pixel.ZoomY!=1.0F) { + return GL_FALSE; /* can't scale pixels */ + } + + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + + if (ctx->RasterMask) { + return GL_FALSE; /* can't do any raster ops */ + } + + { + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + /* look for clipmasks, giveup if region obscured */ + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + int i; + for (i = 0; i < fxMesa->numClipRects; i++) { + const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; + + if (scrY < rect->y1 || scrY+height > rect->y2) { + if (scrX < rect->x1 || scrX+width > rect->x2) { + return GL_FALSE; /* dst is obscured */ + } + } + } + } + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_8888, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { +#ifdef XF86DRI + const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width * 4) : (info.strideInBytes); +#else + const GLint dstStride = info.strideInBytes; +#endif + const GLubyte *dst = (const GLubyte *) info.lfbPtr + + scrY * dstStride + scrX * 4; + const GLint srcStride = + _mesa_image_row_stride(unpack, width, format, type); + const GLubyte *src = (GLubyte *) _mesa_image_address(unpack, + pixels, width, height, format, type, 0, 0, 0); + + if ((format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) + || (format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + const GLint widthInBytes = width * 4; + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst -= dstStride; + src += srcStride; + } + result = GL_TRUE; + } + + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); + return result; + } +} + + +static GLboolean +drawpixels_R8G8B8A8_v2(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid * pixels) +{ + if (!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) + && !(format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + return GL_FALSE; /* format/type not optimised */ + } + + if (ctx->Pixel.ZoomX!=1.0F || ctx->Pixel.ZoomY!=1.0F) { + return GL_FALSE; /* can't scale pixels */ + } + + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + + if (ctx->RasterMask & (~BLEND_BIT)) { + return GL_FALSE; /* can't do any raster ops, except blend */ + } + + { + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + /* look for clipmasks, giveup if region obscured */ + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + int i; + for (i = 0; i < fxMesa->numClipRects; i++) { + const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; + + if (scrY < rect->y1 || scrY+height > rect->y2) { + if (scrX < rect->x1 || scrX+width > rect->x2) { + return GL_FALSE; /* dst is obscured */ + } + } + } + } + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_8888, GR_ORIGIN_UPPER_LEFT, FXTRUE, &info)) { +#ifdef XF86DRI + const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width * 4) : (info.strideInBytes); +#else + const GLint dstStride = info.strideInBytes; +#endif + const GLubyte *dst = (const GLubyte *) info.lfbPtr + + scrY * dstStride + scrX * 4; + const GLint srcStride = + _mesa_image_row_stride(unpack, width, format, type); + const GLubyte *src = (GLubyte *) _mesa_image_address(unpack, + pixels, width, height, format, type, 0, 0, 0); + + void *grState = NULL; + GLint grSize; + + if (grGet(GR_GLIDE_STATE_SIZE, sizeof(grSize), (void *) &grSize)) { + if ((grState = malloc(grSize)) != 0) { + grGlideGetState(grState); + } + } + + if (ctx->RasterMask & BLEND_BIT) { + grDisableAllEffects(); + grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, + GR_BLEND_ONE_MINUS_SRC_ALPHA, + GR_BLEND_ONE, + GR_BLEND_ZERO); + grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_OTHER_ALPHA, + GR_COMBINE_LOCAL_NONE, + GR_COMBINE_OTHER_ITERATED, + FXFALSE); + grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_OTHER_ALPHA, + GR_COMBINE_LOCAL_ITERATED, + GR_COMBINE_OTHER_ITERATED, + FXFALSE); + } + + if ((format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) + || (format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + const GLint widthInBytes = width * 4; + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst -= dstStride; + src += srcStride; + } + result = GL_TRUE; + } + + if (grState) { + grGlideSetState(grState); + free(grState); + } + + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); + return result; + } +} + + +static void +fxDDFinish(GLcontext *ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + FX_grFinish(fxMesa); +} + + +static void +fxDDFlush(GLcontext *ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + FX_grFlush(fxMesa); +} + + +static GLint +fxDDGetParameteri(const GLcontext * ctx, GLint param) +{ + switch (param) { + case DD_HAVE_HARDWARE_FOG: + return 1; + default: + fprintf(stderr, + "fx Driver: internal error in fxDDGetParameteri(): %x\n", + (int) param); + return 0; + } +} + + +static void +fxDDSetNearFar(GLcontext * ctx, GLfloat n, GLfloat f) +{ + FX_CONTEXT(ctx)->new_state |= FX_NEW_FOG; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + + +/* KW: Put the word Mesa in the render string because quakeworld + * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE). + * Why? + */ +static const GLubyte * +fxDDGetString(GLcontext * ctx, GLenum name) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + switch (name) { + case GL_RENDERER: + { + static char buffer[100]; + char hardware[100]; + strcpy(hardware, FX_grGetString(fxMesa, GR_HARDWARE)); + if (strcmp(hardware, "Voodoo3 (tm)") == 0) + strcpy(hardware, "Voodoo3"); + else if (strcmp(hardware, "Voodoo Banshee (tm)") == 0) + strcpy(hardware, "VoodooBanshee"); + else { + /* unexpected result: replace spaces with hyphens */ + int i; + for (i = 0; hardware[i]; i++) { + if (hardware[i] == ' ' || hardware[i] == '\t') + hardware[i] = '-'; + } + } + /* now make the GL_RENDERER string */ + sprintf(buffer, "Mesa DRI %s 20000821", hardware); + return buffer; + } + case GL_VENDOR: + return "VA Linux Systems, Inc."; + default: + return NULL; + } +} + + +#if 0 +/* Example extension function */ +static void +fxFooBarEXT(GLint i) +{ + printf("You called glFooBarEXT(%d)\n", i); +} +#endif + + + +/* + * Enable/Disable the extensions for this context. + */ +static void +fxDDInitExtensions(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + gl_extensions_disable(ctx, "GL_EXT_blend_logic_op"); + gl_extensions_disable(ctx, "GL_EXT_blend_minmax"); + gl_extensions_disable(ctx, "GL_EXT_blend_subtract"); + gl_extensions_disable(ctx, "GL_EXT_blend_color"); + gl_extensions_disable(ctx, "GL_EXT_blend_func_separate"); + gl_extensions_disable(ctx, "GL_INGR_blend_func_separate"); + gl_extensions_enable(ctx, "GL_HP_occlusion_test"); + + if (!fxMesa->haveTwoTMUs) + gl_extensions_disable(ctx, "GL_EXT_texture_env_add"); + + if (!fxMesa->emulateTwoTMUs) + gl_extensions_disable(ctx, "GL_ARB_multitexture"); + + if (fxMesa->isNapalm) { + gl_extensions_enable(ctx, "GL_ARB_texture_compression"); + gl_extensions_enable(ctx, "GL_3DFX_texture_compression_FXT1"); + } + + /* Example of hooking in an extension function. + * For DRI-based drivers, also see __driRegisterExtensions in the + * tdfx_xmesa.c file. + */ +#if 0 + { + void **dispatchTable = (void **) ctx->Exec; + const int _gloffset_FooBarEXT = 555; /* just an example number! */ + const int tabSize = _glapi_get_dispatch_table_size(); + assert(_gloffset_FooBarEXT < tabSize); + dispatchTable[_gloffset_FooBarEXT] = (void *) fxFooBarEXT; + /* XXX You would also need to hook into the display list dispatch + * table. Really, the implementation of extensions might as well + * be in the core of Mesa since core Mesa and the device driver + * is one big shared lib. + */ + } +#endif +} + + + +/* + * Initialize the state in an fxMesaContext struct. + */ +int +fxDDInitFxMesaContext(fxMesaContext fxMesa) +{ + /* Get Glide3 extension function pointers */ + { + void *handle = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL); + if (!handle) { + txImgQuantizePtr = 0; + txImgDequantizeFXT1Ptr = 0; + txErrorSetCallbackPtr = 0; + return 0; + } + else { + /* + * These are not exported by Glide. + */ + txImgQuantizePtr = dlsym(handle, "txImgQuantize"); + txImgDequantizeFXT1Ptr = dlsym(handle, "_txImgDequantizeFXT1"); + txErrorSetCallbackPtr = dlsym(handle, "txErrorSetCallback"); + grStencilFuncPtr = dlsym(handle, "grStencilFunc"); + grStencilMaskPtr = dlsym(handle, "grStencilMask"); + grStencilOpPtr = dlsym(handle, "grStencilOp"); + grBufferClearExtPtr = dlsym(handle, "grBufferClearExt"); + grColorMaskExtPtr = dlsym(handle, "grColorMaskExt"); + } + dlclose(handle); + } + + FX_setupGrVertexLayout(fxMesa); + + if (getenv("FX_EMULATE_SINGLE_TMU")) + fxMesa->haveTwoTMUs = GL_FALSE; + + fxMesa->emulateTwoTMUs = fxMesa->haveTwoTMUs; + + if (!getenv("FX_DONT_FAKE_MULTITEX")) + fxMesa->emulateTwoTMUs = GL_TRUE; + + if (getenv("FX_GLIDE_SWAPINTERVAL")) + fxMesa->swapInterval = atoi(getenv("FX_GLIDE_SWAPINTERVAL")); + else + fxMesa->swapInterval = 1; + + if (getenv("MESA_FX_SWAP_PENDING")) + fxMesa->maxPendingSwapBuffers = atoi(getenv("MESA_FX_SWAP_PENDING")); + else + fxMesa->maxPendingSwapBuffers = 2; + + if (getenv("MESA_FX_INFO")) + fxMesa->verbose = GL_TRUE; + else + fxMesa->verbose = GL_FALSE; + +#if 0 + printf("haveTwoTMUs=%d emulateTwoTMUs=%d\n", + fxMesa->haveTwoTMUs, fxMesa->emulateTwoTMUs); +#endif + + fxMesa->depthClear = FX_grGetInteger(fxMesa, FX_ZDEPTH_MAX); + + fxMesa->color = 0xffffffff; + fxMesa->clearC = 0; + fxMesa->clearA = 0; + + fxMesa->stats.swapBuffer = 0; + fxMesa->stats.reqTexUpload = 0; + fxMesa->stats.texUpload = 0; + fxMesa->stats.memTexUpload = 0; + + fxMesa->tmuSrc = FX_TMU_NONE; + fxTMInit(fxMesa); + + /* FX units setup */ + fxMesa->unitsState.alphaTestEnabled = GL_FALSE; + fxMesa->unitsState.alphaTestFunc = GR_CMP_ALWAYS; + fxMesa->unitsState.alphaTestRefValue = 0; + + fxMesa->unitsState.blendEnabled = GL_FALSE; + fxMesa->unitsState.blendSrcFuncRGB = GR_BLEND_ONE; + fxMesa->unitsState.blendDstFuncRGB = GR_BLEND_ZERO; + fxMesa->unitsState.blendSrcFuncAlpha = GR_BLEND_ONE; + fxMesa->unitsState.blendDstFuncAlpha = GR_BLEND_ZERO; + + /* + fxMesa->unitsState.depthTestEnabled = GL_FALSE; + fxMesa->unitsState.depthMask = GL_TRUE; + fxMesa->unitsState.depthTestFunc = GR_CMP_LESS; + */ + + FX_grColorMaskv(fxMesa->glCtx, true4); + if (fxMesa->glVis->DBflag) { + fxMesa->currentFB = GR_BUFFER_BACKBUFFER; + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + } + else { + fxMesa->currentFB = GR_BUFFER_FRONTBUFFER; + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + } + + fxMesa->state = NULL; + fxMesa->fogTable = NULL; + + fxMesa->state = malloc(FX_grGetInteger(fxMesa, FX_GLIDE_STATE_SIZE)); + fxMesa->fogTable = + malloc(FX_grGetInteger(fxMesa, FX_FOG_TABLE_ENTRIES) * sizeof(GrFog_t)); + + if (!fxMesa->state || !fxMesa->fogTable) { + if (fxMesa->state) + free(fxMesa->state); + if (fxMesa->fogTable) + free(fxMesa->fogTable); + return 0; + } + + if (fxMesa->glVis->DepthBits > 0) + FX_grDepthBufferMode(fxMesa, GR_DEPTHBUFFER_ZBUFFER); + + FX_grLfbWriteColorFormat(fxMesa, GR_COLORFORMAT_ABGR); + + fxMesa->textureAlign = FX_grGetInteger(fxMesa, FX_TEXTURE_ALIGN); + if (fxMesa->isNapalm) { + fxMesa->glCtx->Const.MaxTextureLevels = 12; + fxMesa->glCtx->Const.MaxTextureSize = 2048; + fxMesa->glCtx->Const.NumCompressedTextureFormats = 1; + } + else { + fxMesa->glCtx->Const.MaxTextureLevels = 9; + fxMesa->glCtx->Const.MaxTextureSize = 256; + fxMesa->glCtx->Const.NumCompressedTextureFormats = 0; + } + fxMesa->glCtx->Const.MaxTextureUnits = fxMesa->emulateTwoTMUs ? 2 : 1; + fxMesa->glCtx->NewState |= NEW_DRVSTATE1; + fxMesa->new_state = NEW_ALL; + + fxDDSetupInit(); + fxDDCvaInit(); + fxDDClipInit(); + fxDDTrifuncInit(); + fxDDFastPathInit(); + + fxSetupDDPointers(fxMesa->glCtx); + fxDDRenderInit(fxMesa->glCtx); + fxDDInitExtensions(fxMesa->glCtx); + + fxDDSetNearFar(fxMesa->glCtx, 1.0, 100.0); + + FX_grGlideGetState(fxMesa, (GrState *) fxMesa->state); + + /* XXX Fix me: callback not registered when main VB is created. + */ + if (fxMesa->glCtx->VB) + fxDDRegisterVB(fxMesa->glCtx->VB); + + /* XXX Fix me too: need to have the 'struct dd' prepared prior to + * creating the context... The below is broken if you try to insert + * new stages. + */ + if (fxMesa->glCtx->NrPipelineStages) + fxMesa->glCtx->NrPipelineStages = + fxDDRegisterPipelineStages(fxMesa->glCtx->PipelineStage, + fxMesa->glCtx->PipelineStage, + fxMesa->glCtx->NrPipelineStages); + + /* this little bit ensures that all Glide state gets initialized */ + fxMesa->new_state = NEW_ALL; + fxMesa->glCtx->Driver.RenderStart = fxSetupFXUnits; + + fxInitPixelTables(fxMesa, GL_FALSE); /* Load tables of pixel colors */ + + /* Run the config file */ + gl_context_initialize(fxMesa->glCtx); + + return 1; +} + + +/************************************************************************/ +/************************************************************************/ +/************************************************************************/ + +/* Check if the hardware supports the current context + * + * Performs similar work to fxDDChooseRenderState() - should be merged. + */ +static GLboolean +fxIsInHardware(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + if (!ctx->Hint.AllowDrawMem) + return GL_TRUE; /* you'll take it and like it */ + + if ( + ((ctx->Color.BlendEnabled) + && (ctx->Color.BlendEquation != GL_FUNC_ADD_EXT)) + || ((ctx->Color.ColorLogicOpEnabled) + && (ctx->Color.LogicOp != GL_COPY)) + || (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) + || + (!((ctx->Color.ColorMask[RCOMP] == ctx->Color.ColorMask[GCOMP]) + && (ctx->Color.ColorMask[GCOMP] == ctx->Color.ColorMask[BCOMP]) + && (ctx->Color.ColorMask[ACOMP] == ctx->Color.ColorMask[ACOMP]))) + ) { + return GL_FALSE; + } + /* Unsupported texture/multitexture cases */ + + if (fxMesa->emulateTwoTMUs) { + if ((ctx->Enabled & (TEXTURE0_3D | TEXTURE1_3D)) || + /* Not very well written ... */ + ((ctx->Enabled & (TEXTURE0_1D | TEXTURE1_1D)) && + ((ctx->Enabled & (TEXTURE0_2D | TEXTURE1_2D)) != + (TEXTURE0_2D | TEXTURE1_2D)))) { + return GL_FALSE; + } + + if (ctx->Texture.ReallyEnabled & TEXTURE0_2D) { +#if 0 + if (ctx->Texture.Unit[0].EnvMode == GL_BLEND) { + return GL_FALSE; + } +#endif + if (ctx->Texture.Unit[0].EnvMode == GL_BLEND && + (ctx->Texture.ReallyEnabled & TEXTURE1_2D || + ctx->Texture.Unit[0].EnvColor[0] != 0 || + ctx->Texture.Unit[0].EnvColor[1] != 0 || + ctx->Texture.Unit[0].EnvColor[2] != 0 || + ctx->Texture.Unit[0].EnvColor[3] != 1)) { + return GL_FALSE; + } + if (ctx->Texture.Unit[0].Current->Image[0]->Border > 0) + return GL_FALSE; + } + + if (ctx->Texture.ReallyEnabled & TEXTURE1_2D) { + if (ctx->Texture.Unit[1].EnvMode == GL_BLEND) + return GL_FALSE; + if (ctx->Texture.Unit[0].Current->Image[0]->Border > 0) + return GL_FALSE; + } + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_TEXTURE)) + fprintf(stderr, "fxMesa: fxIsInHardware, envmode is %s/%s\n", + gl_lookup_enum_by_nr(ctx->Texture.Unit[0].EnvMode), + gl_lookup_enum_by_nr(ctx->Texture.Unit[1].EnvMode)); + + /* KW: This was wrong (I think) and I changed it... which doesn't mean + * it is now correct... + */ + if ((ctx->Enabled & (TEXTURE0_1D | TEXTURE0_2D | TEXTURE0_3D)) && + (ctx->Enabled & (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D))) { + /* Can't use multipass to blend a multitextured triangle - fall + * back to software. + */ + if (!fxMesa->haveTwoTMUs && ctx->Color.BlendEnabled) { + return GL_FALSE; + } + + if ((ctx->Texture.Unit[0].EnvMode != ctx->Texture.Unit[1].EnvMode) + && (ctx->Texture.Unit[0].EnvMode != GL_MODULATE) + && (ctx->Texture.Unit[0].EnvMode != GL_REPLACE)) { /* q2, seems ok... */ + if (MESA_VERBOSE & VERBOSE_DRIVER) + fprintf(stderr, + "fxMesa: unsupported multitex env mode\n"); + return GL_FALSE; + } + } + } + else { + if ((ctx->Enabled & (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D)) || + /* Not very well written ... */ + ((ctx->Enabled & TEXTURE0_1D) && (!(ctx->Enabled & TEXTURE0_2D))) + ) { + return GL_FALSE; + } + + + if ((ctx->Texture.ReallyEnabled & TEXTURE0_2D) && + (ctx->Texture.Unit[0].EnvMode == GL_BLEND)) { + return GL_FALSE; + } + } + + if (ctx->Stencil.Enabled && !fxMesa->haveHwStencil) + return GL_FALSE; + + return GL_TRUE; +} + + + +#define INTERESTED (~(NEW_MODELVIEW|NEW_PROJECTION|NEW_PROJECTION|NEW_TEXTURE_MATRIX|NEW_USER_CLIP|NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE)) + +static void +fxDDUpdateDDPointers(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint new_state = ctx->NewState; + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_STATE)) + fprintf(stderr, "fxmesa: fxDDUpdateDDPointers(...)\n"); + + if (new_state & (NEW_RASTER_OPS | NEW_TEXTURING)) + fxMesa->is_in_hardware = fxIsInHardware(ctx); + + if (fxMesa->is_in_hardware) { + if (fxMesa->new_state) + fxSetupFXUnits(ctx); + + if (new_state & INTERESTED) { + fxDDChooseRenderState(ctx); + fxMesa->RenderVBTables = fxDDChooseRenderVBTables(ctx); + fxMesa->RenderVBClippedTab = fxMesa->RenderVBTables[0]; + fxMesa->RenderVBCulledTab = fxMesa->RenderVBTables[1]; + fxMesa->RenderVBRawTab = fxMesa->RenderVBTables[2]; + + ctx->Driver.RasterSetup = fxDDChooseSetupFunction(ctx); + } + + ctx->Driver.PointsFunc = fxMesa->PointsFunc; + ctx->Driver.LineFunc = fxMesa->LineFunc; + ctx->Driver.TriangleFunc = fxMesa->TriangleFunc; + ctx->Driver.QuadFunc = fxMesa->QuadFunc; + } + else { + fxMesa->render_index = FX_FALLBACK; + } +} + +static void +fxDDReducedPrimitiveChange(GLcontext * ctx, GLenum prim) +{ + if (ctx->Polygon.CullFlag) { + if (ctx->PB->primitive != GL_POLYGON) { /* Lines or Points */ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + FX_grCullMode(fxMesa, GR_CULL_DISABLE); + fxMesa->cullMode = GR_CULL_DISABLE; + } + } +} + + +void +fxSetupDDPointers(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupDDPointers()\n"); + } + ctx->Driver.UpdateState = fxDDUpdateDDPointers; + ctx->Driver.ClearIndex = NULL; + ctx->Driver.ClearColor = fxDDClearColor; + ctx->Driver.Clear = fxDDClear; + ctx->Driver.Index = NULL; + ctx->Driver.Color = fxDDSetColor; + ctx->Driver.SetDrawBuffer = fxDDSetDrawBuffer; + ctx->Driver.SetReadBuffer = fxDDSetReadBuffer; + ctx->Driver.GetBufferSize = fxDDBufferSize; + ctx->Driver.Finish = fxDDFinish; + ctx->Driver.Flush = fxDDFlush; + ctx->Driver.GetString = fxDDGetString; + ctx->Driver.NearFar = fxDDSetNearFar; + ctx->Driver.GetParameteri = fxDDGetParameteri; + ctx->Driver.GetBooleanv = fxDDGetBooleanv; + ctx->Driver.GetFloatv = fxDDGetFloatv; + ctx->Driver.GetDoublev = fxDDGetDoublev; + ctx->Driver.GetIntegerv = fxDDGetIntegerv; + + if (ctx->Visual->RedBits == 8 && + ctx->Visual->GreenBits == 8 && + ctx->Visual->BlueBits == 8 && + ctx->Visual->AlphaBits == 8) { + ctx->Driver.Bitmap = bitmap_R8G8B8A8; + ctx->Driver.DrawPixels = drawpixels_R8G8B8A8; + ctx->Driver.ReadPixels = readpixels_R8G8B8A8; + } + else if (ctx->Visual->RedBits == 5 && + ctx->Visual->GreenBits == 6 && + ctx->Visual->BlueBits == 5 && + ctx->Visual->AlphaBits == 0) { + ctx->Driver.Bitmap = bitmap_R5G6B5; + ctx->Driver.DrawPixels = NULL; + ctx->Driver.ReadPixels = readpixels_R5G6B5; + } + else { + ctx->Driver.Bitmap = NULL; + ctx->Driver.DrawPixels = NULL; + ctx->Driver.ReadPixels = NULL; + } + + ctx->Driver.RenderStart = NULL; + ctx->Driver.RenderFinish = NULL; + + ctx->Driver.TexImage2D = fxDDTexImage2D; + ctx->Driver.TexSubImage2D = fxDDTexSubImage2D; + ctx->Driver.GetTexImage = fxDDGetTexImage; + ctx->Driver.CompressedTexImage2D = fxDDCompressedTexImage2D; + ctx->Driver.CompressedTexSubImage2D = fxDDCompressedTexSubImage2D; + ctx->Driver.GetCompressedTexImage = fxDDGetCompressedTexImage; + ctx->Driver.SpecificCompressedTexFormat = fxDDSpecificCompressedTexFormat; + ctx->Driver.BaseCompressedTexFormat = fxDDBaseCompressedTexFormat; + ctx->Driver.IsCompressedFormat = fxDDIsCompressedFormat; + ctx->Driver.CompressedImageSize = fxDDCompressedImageSize; + ctx->Driver.TexEnv = fxDDTexEnv; + ctx->Driver.TexParameter = fxDDTexParam; + ctx->Driver.BindTexture = fxDDTexBind; + ctx->Driver.DeleteTexture = fxDDTexDel; + ctx->Driver.IsTextureResident = fxDDIsTextureResident; + ctx->Driver.UpdateTexturePalette = fxDDTexPalette; + + ctx->Driver.RectFunc = NULL; + + if (fxMesa->haveHwStencil) { + ctx->Driver.StencilFunc = fxDDStencilFunc; + ctx->Driver.StencilMask = fxDDStencilMask; + ctx->Driver.StencilOp = fxDDStencilOp; + } + + ctx->Driver.AlphaFunc = fxDDAlphaFunc; + ctx->Driver.BlendFunc = fxDDBlendFunc; + ctx->Driver.BlendFuncSeparate = fxDDBlendFuncSeparate; + ctx->Driver.DepthFunc = fxDDDepthFunc; + ctx->Driver.DepthMask = fxDDDepthMask; + ctx->Driver.ColorMask = fxDDColorMask; + ctx->Driver.Fogfv = fxDDFogfv; + ctx->Driver.Scissor = fxDDScissor; + ctx->Driver.FrontFace = fxDDFrontFace; + ctx->Driver.CullFace = fxDDCullFace; + ctx->Driver.ShadeModel = fxDDShadeModel; + ctx->Driver.Enable = fxDDEnable; + ctx->Driver.ReducedPrimitiveChange = fxDDReducedPrimitiveChange; + + ctx->Driver.RegisterVB = fxDDRegisterVB; + ctx->Driver.UnregisterVB = fxDDUnregisterVB; + + ctx->Driver.RegisterPipelineStages = fxDDRegisterPipelineStages; + + ctx->Driver.OptimizeImmediatePipeline = 0; /* nothing done yet */ + ctx->Driver.OptimizePrecalcPipeline = 0; + +/* if (getenv("MESA_USE_FAST") || getenv("FX_USE_FAST")) */ +/* ctx->Driver.OptimizePrecalcPipeline = fxDDOptimizePrecalcPipeline; */ + + if (!getenv("FX_NO_FAST")) + ctx->Driver.BuildPrecalcPipeline = fxDDBuildPrecalcPipeline; + + ctx->Driver.TriangleCaps = + DD_TRI_CULL | DD_TRI_OFFSET | DD_TRI_LIGHT_TWOSIDE; + + fxSetupDDSpanPointers(ctx); + + FX_CONTEXT(ctx)->render_index = 1; /* force an update */ + fxDDUpdateDDPointers(ctx); +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxddspan.c b/xc/lib/GL/mesa/src/drv/tdfx/fxddspan.c new file mode 100644 index 000000000..732885a21 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxddspan.c @@ -0,0 +1,2053 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +/* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */ + + +#include "fxdrv.h" + +/* + * Examine the cliprects to generate an array of flags to indicate + * which pixels in a span are visible. Note: (x,y) is a screen + * coordinate. + */ +static void +generate_vismask(const fxMesaContext fxMesa, GLint x, GLint y, GLint n, + GLubyte vismask[]) +{ + GLboolean initialized = GL_FALSE; + GLint i, j; + + /* Ensure we clear the visual mask */ + MEMSET(vismask, 0, n); + + /* turn on flags for all visible pixels */ + for (i = 0; i < fxMesa->numClipRects; i++) { + const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; + + if (y >= rect->y1 && y < rect->y2) { + if (x >= rect->x1 && x + n <= rect->x2) { + /* common case, whole span inside cliprect */ + MEMSET(vismask, 1, n); + return; + } + if (x < rect->x2 && x + n >= rect->x1) { + /* some of the span is inside the rect */ + GLint start, end; + if (!initialized) { + MEMSET(vismask, 0, n); + initialized = GL_TRUE; + } + if (x < rect->x1) + start = rect->x1 - x; + else + start = 0; + if (x + n > rect->x2) + end = rect->x2 - x; + else + end = n; + assert(start >= 0); + assert(end <= n); + for (j = start; j < end; j++) + vismask[j] = 1; + } + } + } +} + +/* + * Examine cliprects and determine if the given screen pixel is visible. + */ +static GLboolean +visible_pixel(const fxMesaContext fxMesa, int scrX, int scrY) +{ + int i; + for (i = 0; i < fxMesa->numClipRects; i++) { + const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; + if (scrX >= rect->x1 && + scrX < rect->x2 && + scrY >= rect->y1 && scrY < rect->y2) return GL_TRUE; + } + return GL_FALSE; +} + +/* + * 16bpp span/pixel functions + */ +static void +write_R5G6B5_rgba_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: write_R5G6B5_rgba_span\n"); + } + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLushort *data16 = (GLushort *) info.lfbPtr + scrY * srcStride + scrX; + GLuint i; + + if (mask) { + for (i = 0; i < n; i++) { + if (visible_pixel(fxMesa, scrX + i, scrY) && mask[i]) { + GLushort pixel; + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(rgba[i][0], + rgba[i][1], + rgba[i][2]); + } else { + pixel = PACK_RGB16(rgba[i][0], + rgba[i][1], + rgba[i][2]); + } + data16[i] = pixel; + } + } + } else { + for (i = 0; i < n; i++) { + if (visible_pixel(fxMesa, scrX + i, scrY)) { + GLushort pixel; + + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(rgba[i][0], + rgba[i][1], + rgba[i][2]); + } else { + pixel = PACK_RGB16(rgba[i][0], + rgba[i][1], + rgba[i][2]); + } + data16[i] = pixel; + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R5G6B5_rgb_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: write_R5G6B5_rgb_span\n"); + } + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLushort *data16 = (GLushort *) info.lfbPtr + scrY * srcStride + scrX; + GLuint i; + + if (mask) { + for (i = 0; i < n; i++) { + if (visible_pixel(fxMesa, scrX + i, scrY) && mask[i]) { + GLushort pixel; + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(rgb[i][0], + rgb[i][1], + rgb[i][2]); + } else { + pixel = PACK_RGB16(rgb[i][0], + rgb[i][1], + rgb[i][2]); + } + data16[i] = pixel; + } + } + } else { + for (i = 0; i < n; i++) { + if (visible_pixel(fxMesa, scrX + i, scrY)) { + GLushort pixel; + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(rgb[i][0], + rgb[i][1], + rgb[i][2]); + } else { + pixel = PACK_RGB16(rgb[i][0], + rgb[i][1], + rgb[i][2]); + } + data16[i] = pixel; + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + +static void +write_R5G6B5_mono_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLubyte *constantColor = (GLubyte *)(&fxMesa->color); + GLushort pixel; + + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(constantColor[0], + constantColor[1], + constantColor[2]); + } else { + pixel = PACK_RGB16(constantColor[0], + constantColor[1], + constantColor[2]); + } + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: write_r5g6b5_mono_span\n"); + } + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLushort *data16 = (GLushort *) info.lfbPtr + + scrY * srcStride + scrX; + GLuint i; + + if (mask) { + for (i = 0; i < n; i++) { + if (visible_pixel(fxMesa, scrX + i, scrY) && mask[i]) { + data16[i] = pixel; + } + } + } else { + for (i = 0; i < n; i++) { + if (visible_pixel(fxMesa, scrX + i, scrY)) { + data16[i] = pixel; + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + +/* + * Read a span of 16-bit RGB pixels. Note, we don't worry about cliprects + * since OpenGL says obscured pixels have undefined values. + */ +static void +read_R5G6B5_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + GLubyte rgba[][4]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + const GLushort *data16 = (const GLushort *) info.lfbPtr + + (winY - y) * srcStride + (winX + x); + const GLuint *data32 = (const GLuint *) data16; + GLuint i, j; + GLuint extraPixel = (n & 1); + n -= extraPixel; + for (i = j = 0; i < n; i += 2, j++) { + GLuint pixel = data32[j]; + GLuint pixel0 = pixel & 0xffff; + GLuint pixel1 = pixel >> 16; + rgba[i][RCOMP] = FX_PixelToR(fxMesa, pixel0); + rgba[i][GCOMP] = FX_PixelToG(fxMesa, pixel0); + rgba[i][BCOMP] = FX_PixelToB(fxMesa, pixel0); + rgba[i][ACOMP] = 255; + rgba[i + 1][RCOMP] = FX_PixelToR(fxMesa, pixel1); + rgba[i + 1][GCOMP] = FX_PixelToG(fxMesa, pixel1); + rgba[i + 1][BCOMP] = FX_PixelToB(fxMesa, pixel1); + rgba[i + 1][ACOMP] = 255; + } + if (extraPixel) { + GLushort pixel = data16[n]; + rgba[n][RCOMP] = FX_PixelToR(fxMesa, pixel); + rgba[n][GCOMP] = FX_PixelToG(fxMesa, pixel); + rgba[n][BCOMP] = FX_PixelToB(fxMesa, pixel); + rgba[n][ACOMP] = 255; + } + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R5G6B5_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: write_R5G6B5_pixels\n"); + } + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLuint i; + + for (i = 0; i < n; i++) { + GLint scrX = winX + x[i]; + GLint scrY = winY - y[i]; + if (visible_pixel(fxMesa, scrX, scrY) && mask[i]) { + GLushort *data16 = (GLushort *) info.lfbPtr + + scrY * srcStride + scrX; + GLushort pixel; + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(rgba[i][0], + rgba[i][1], + rgba[i][2]); + } else { + pixel = PACK_RGB16(rgba[i][0], + rgba[i][1], + rgba[i][2]); + } + data16[0] = pixel; + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + +static void +write_R5G6B5_mono_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrLfbInfo_t info; + GLubyte *constantColor = (GLubyte *)(&fxMesa->color); + GLushort pixel; + + if (fxMesa->bgrOrder) { + pixel = PACK_BGR16(constantColor[0], + constantColor[1], + constantColor[2]); + } else { + pixel = PACK_RGB16(constantColor[0], + constantColor[1], + constantColor[2]); + } + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: write_R5G6B5_mono_pixels\n"); + } + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLuint i; + + for (i = 0; i < n; i++) { + GLint scrX = winX + x[i]; + GLint scrY = winY - y[i]; + if (visible_pixel(fxMesa, scrX, scrY) && mask[i]) { + GLushort *data16 = (GLushort *) info.lfbPtr + + scrY * srcStride + scrX; + data16[0] = pixel; + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + +static void +read_R5G6B5_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLuint i; + for (i = 0; i < n; i++) { + if (mask[i]) { + const GLushort *data16 = (const GLushort *) info.lfbPtr + + (winY - y[i]) * srcStride + (winX + x[i]); + GLushort pixel = *data16; + rgba[i][RCOMP] = FX_PixelToR(fxMesa, pixel); + rgba[i][GCOMP] = FX_PixelToG(fxMesa, pixel); + rgba[i][BCOMP] = FX_PixelToB(fxMesa, pixel); + rgba[i][ACOMP] = 255; + } + } + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +/* + * 24bpp span/pixel functions + */ + +static void +write_R8G8B8_rgb_span(const GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbWriteMode_t mode; + GrLfbInfo_t info; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + mode = GR_LFBWRITEMODE_888; + else + mode = GR_LFBWRITEMODE_888; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + mode, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + /*GLint dstStride = fxMesa->screen_width * 3; */ + GLint dstStride = info.strideInBytes / 1; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 1; + GLuint *dst32 = (GLuint *) dst; + GLubyte visMask[MAX_WIDTH]; + GLuint i; + generate_vismask(fxMesa, scrX, scrY, n, visMask); + for (i = 0; i < n; i++) { + if (visMask[i] && (!mask || mask[i])) { + dst32[i] = + PACK_BGRA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); + } + } + } + else { + /* back buffer */ + GLint dstStride = info.strideInBytes; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + GLuint *dst32 = (GLuint *) dst; + if (mask) { + GLuint i; + for (i = 0; i < n; i++) { + if (mask[i]) { + dst32[i] = + PACK_RGBA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); + } + } + } + else { + GLuint i; + for (i = 0; i < n; i++) { + dst32[i] = + PACK_RGBA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + + +static void +write_R8G8B8_rgba_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbWriteMode_t mode; + GrLfbInfo_t info; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + mode = GR_LFBWRITEMODE_8888; + else + mode = GR_LFBWRITEMODE_888; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + mode, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + /* XXX have to do cliprect clipping! */ + GLint dstStride = fxMesa->screen_width * 4; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + GLuint *dst32 = (GLuint *) dst; + GLubyte visMask[MAX_WIDTH]; + GLuint i; + generate_vismask(fxMesa, scrX, scrY, n, visMask); + for (i = 0; i < n; i++) { + if (visMask[i] && (!mask || mask[i])) { + dst32[i] = + PACK_BGRA32(rgba[i][0], rgba[i][1], rgba[i][2], + rgba[i][3]); + } + } + } + else { + /* back buffer */ + GLint dstStride = info.strideInBytes; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + if (mask) { + const GLuint *src32 = (const GLuint *) rgba; + GLuint *dst32 = (GLuint *) dst; + GLuint i; + for (i = 0; i < n; i++) { + if (mask[i]) { + dst32[i] = src32[i]; + } + } + } + else { + /* no mask, write all pixels */ + MEMCPY(dst, rgba, 4 * n); + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R8G8B8_mono_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GLubyte rgba[MAX_WIDTH][4]; + GLuint *data = (GLuint *) rgba; + GLuint i; + + /* XXX this is a simple-minded implementation but good enough for now */ + for (i = 0; i < n; i++) { + data[i] = (GLuint) fxMesa->color; + } + write_R8G8B8_rgba_span(ctx, n, x, y, (const GLubyte(*)[4]) rgba, mask); +} + + +static void +read_R8G8B8_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + GLubyte rgba[][4]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, fxMesa->currentFB, GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + GLint srcStride = fxMesa->screen_width * 4; + const GLubyte *src = (const GLubyte *) info.lfbPtr + + (winY - y) * srcStride + (winX + x) * 4; + GLuint i; + for (i = 0; i < n; i++) { + rgba[i][0] = src[i * 4 + 2]; + rgba[i][1] = src[i * 4 + 1]; + rgba[i][2] = src[i * 4 + 0]; + rgba[i][3] = src[i * 4 + 3]; + } + } + else { + /* back buffer */ + GLint srcStride = info.strideInBytes / 2; + const GLubyte *src = (const GLubyte *) info.lfbPtr + + (winY - y) * srcStride + (winX + x) * 4; + GLuint i; + for (i = 0; i < n; i++) { + rgba[i][0] = src[i * 4 + 2]; + rgba[i][1] = src[i * 4 + 1]; + rgba[i][2] = src[i * 4 + 0]; + rgba[i][3] = src[i * 4 + 3]; + } + } + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R8G8B8_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbWriteMode_t mode; + GrLfbInfo_t info; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + mode = GR_LFBWRITEMODE_8888; + else + mode = GR_LFBWRITEMODE_888 /*565 */ ; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + mode, GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + GLuint i; + for (i = 0; i < n; i++) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { + GLint dstStride = fxMesa->screen_width * 4; + GLubyte *dst = + (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; + GLuint *dst32 = (GLuint *) dst; + *dst32 = PACK_BGRA32(rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3]); + } + } + } + else { + /* back buffer */ + GLuint i; + for (i = 0; i < n; i++) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { + GLint dstStride = info.strideInBytes; + GLubyte *dst = + (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; + GLuint *dst32 = (GLuint *) dst; + *dst32 = PACK_BGRA32(rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3]); + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R8G8B8_mono_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + const GLubyte mask[]) +{ + printf("write_r8g8b8_mono_pixels\n"); +} + + +static void +read_R8G8B8_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[]) +{ + printf("read_R8G8B8_pixels %d\n", n); +} + + + +/* + * 32bpp span/pixel functions + */ + +static void +write_R8G8B8A8_rgb_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, fxMesa->currentFB, GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + GLint dstStride = fxMesa->screen_width * 4; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + GLuint *dst32 = (GLuint *) dst; + GLubyte visMask[MAX_WIDTH]; + GLuint i; + generate_vismask(fxMesa, scrX, scrY, n, visMask); + for (i = 0; i < n; i++) { + if (visMask[i] && (!mask || mask[i])) { + dst32[i] = + PACK_BGRA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); + } + } + } + else { + /* back buffer */ + GLint dstStride = info.strideInBytes; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + GLuint *dst32 = (GLuint *) dst; + if (mask) { + GLuint i; + for (i = 0; i < n; i++) { + if (mask[i]) { + dst32[i] = + PACK_BGRA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); + } + } + } + else { + GLuint i; + for (i = 0; i < n; i++) { + dst32[i] = + PACK_BGRA32(rgb[i][0], rgb[i][1], rgb[i][2], 255); + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +/* + *XXX test of grLfbWriteRegion in 32bpp mode. Doesn't seem to work! + */ +#if 0 +static void +write_R8G8B8A8_rgb_span2(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLint x2 = fxMesa->x_offset + x; + GLint y2 = bottom - y; + + FX_grLfbWriteRegion(fxMesa->currentFB, x2, y2, GR_LFB_SRC_FMT_888, + n, 1, 0, rgb); +} +#endif + + +static void +write_R8G8B8A8_rgba_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, fxMesa->currentFB, GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + GLint dstStride = fxMesa->screen_width * 4; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + GLuint *dst32 = (GLuint *) dst; + GLubyte visMask[MAX_WIDTH]; + GLuint i; + generate_vismask(fxMesa, scrX, scrY, n, visMask); + for (i = 0; i < n; i++) { + if (visMask[i] && (!mask || mask[i])) { + dst32[i] = + PACK_BGRA32(rgba[i][0], rgba[i][1], rgba[i][2], + rgba[i][3]); + } + } + } + else { + /* back buffer */ + GLint dstStride = info.strideInBytes; + GLubyte *dst = (GLubyte *) info.lfbPtr + + (winY - y) * dstStride + (winX + x) * 4; + GLuint *dst32 = (GLuint *) dst; + if (mask) { + GLuint i; + for (i = 0; i < n; i++) { + if (mask[i]) { + dst32[i] = PACK_BGRA32(rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3]); + } + } + } + else { + /* no mask, write all pixels */ + GLuint i; + for (i = 0; i < n; i++) { + dst32[i] = PACK_BGRA32(rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3]); + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + else { + info.strideInBytes = -1; + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R8G8B8A8_mono_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GLubyte rgba[MAX_WIDTH][4]; + GLuint *data = (GLuint *) rgba; + GLuint i; + + /* XXX this is a simple-minded implementation but good enough for now */ + for (i = 0; i < n; i++) { + data[i] = (GLuint) fxMesa->color; + } + write_R8G8B8A8_rgba_span(ctx, n, x, y, (const GLubyte(*)[4]) rgba, mask); +} + + +static void +read_R8G8B8A8_span(const GLcontext * ctx, GLuint n, GLint x, GLint y, + GLubyte rgba[][4]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, fxMesa->currentFB, GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + GLint srcStride = fxMesa->screen_width; + const GLuint *src32 = (const GLuint *) info.lfbPtr + + (winY - y) * srcStride + (winX + x); + GLuint i; + GLuint *color = (GLuint*)rgba; + MEMCPY(color, src32, n * 4); + for (i = 0; i < n; i++) { + const GLuint p = *color; + *color++ = ((p & 0x00ff0000) >> 16) | + (p & 0xff00ff00) | + ((p & 0x000000ff) << 16); + } + } + else { + /* back buffer */ + GLint srcStride = info.strideInBytes / sizeof(GLuint); + const GLuint *src32 = (const GLuint *) info.lfbPtr + + (winY - y) * srcStride + (winX + x); + GLuint i; + GLuint *color = (GLuint*)rgba; + MEMCPY(color, src32, n * 4); + for (i = 0; i < n; i++) { + const GLuint p = *color; + *color++ = ((p & 0x00ff0000) >> 16) | + (p & 0xff00ff00) | + ((p & 0x000000ff) << 16); + } + } + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB); + } + else + info.strideInBytes = -1; + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R8G8B8A8_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + + BEGIN_BOARD_LOCK(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, fxMesa->currentFB, GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + GLuint i; + for (i = 0; i < n; i++) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { + GLint dstStride = fxMesa->screen_width * 4; + GLubyte *dst = + (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; + GLuint *dst32 = (GLuint *) dst; + *dst32 = PACK_BGRA32(rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3]); + } + } + } + else { + /* back buffer */ + GLuint i; + for (i = 0; i < n; i++) { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + if (mask[i] && visible_pixel(fxMesa, scrX, scrY)) { + GLint dstStride = info.strideInBytes; + GLubyte *dst = + (GLubyte *) info.lfbPtr + scrY * dstStride + scrX * 4; + GLuint *dst32 = (GLuint *) dst; + *dst32 = PACK_BGRA32(rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3]); + } + } + } + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->currentFB); + } + END_BOARD_LOCK(fxMesa); +} + + +static void +write_R8G8B8A8_mono_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint i; + GLuint color = fxMesa->color; + for (i = 0; i < n; i++) { + if (mask[i]) { + write_R8G8B8A8_rgba_span(ctx, 1, x[i], y[i], + (const GLubyte(*)[4]) &color, mask + i); + } + } +} + + + +static void +read_R8G8B8A8_pixels(const GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[]) +{ + GLuint i; + for (i = 0; i < n; i++) { + if (mask[i]) { + read_R8G8B8A8_span(ctx, 1, x[i], y[i], rgba + i); + } + } +} + + + +/* + * Depth buffer read/write functions. + */ +/* + * To read the frame buffer, we need to lock and unlock it. The + * four macros {READ,WRITE}_FB_SPAN_{LOCK,UNLOCK} + * do this for us. + * + * Note that the lock must be matched with an unlock. These + * macros include a spare curly brace, so they must + * be syntactically matched. + * + * Note, also, that you can't lock a buffer twice with different + * modes. That is to say, you can't lock a buffer in both read + * and write modes. The strideInBytes and LFB pointer will be + * the same with read and write locks, so you can use either. + * o The HW has different state for reads and writes, so + * locking it twice may give screwy results. + * o The DRM won't let you lock twice. It hangs. This is probably + * because of the BEGIN_BOARD_LOCK IN THE *_FB_SPAN_LOCK macros, + * and could be eliminated with nonlocking lock routines. But + * what's the point after all. + */ +#define READ_FB_SPAN_LOCK(fxMesa, info, target_buffer) \ + BEGIN_BOARD_LOCK(fxMesa); \ + (info).size=sizeof(info); \ + if (grLfbLock(GR_LFB_READ_ONLY, \ + target_buffer, \ + GR_LFBWRITEMODE_ANY, \ + GR_ORIGIN_LOWER_LEFT, \ + FXFALSE, \ + &(info))) { + +#define READ_FB_SPAN_UNLOCK(fxMesa, target_buffer) \ + grLfbUnlock(GR_LFB_READ_ONLY, target_buffer); \ + } else { \ + fprintf(stderr, "fxDriver: Can't get %s (%d) read lock\n", \ + (target_buffer == GR_BUFFER_BACKBUFFER) \ + ? "back buffer" \ + : ((target_buffer == GR_BUFFER_AUXBUFFER) \ + ? "depth buffer" \ + : "unknown buffer"), \ + target_buffer); \ + } \ + END_BOARD_LOCK(fxMesa); + + +#define WRITE_FB_SPAN_LOCK(fxMesa, info, target_buffer, write_mode) \ + BEGIN_BOARD_LOCK(fxMesa); \ + info.size=sizeof(info); \ + if (grLfbLock(GR_LFB_WRITE_ONLY, \ + target_buffer, \ + write_mode, \ + GR_ORIGIN_LOWER_LEFT, \ + FXFALSE, \ + &info)) { + +#define WRITE_FB_SPAN_UNLOCK(fxMesa, target_buffer) \ + grLfbUnlock(GR_LFB_WRITE_ONLY, target_buffer); \ + } else { \ + fprintf(stderr, "fxDriver: Can't get %s (%d) write lock\n", \ + (target_buffer == GR_BUFFER_BACKBUFFER) \ + ? "back buffer" \ + : ((target_buffer == GR_BUFFER_AUXBUFFER) \ + ? "depth buffer" \ + : "unknown buffer"), \ + target_buffer); \ + } \ + END_BOARD_LOCK(fxMesa); + +/* + * Because the Linear Frame Buffer is not necessarily aligned + * with the depth buffer, we have to do some fiddling + * around to get the right addresses. + * + * Perhaps a picture is in order. The Linear Frame Buffer + * looks like this: + * + * |<----------------------info.strideInBytes------------->| + * |<-----physicalStrideInBytes------->| + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * | | | + * | Legal Memory | Forbidden Zone | + * | | | + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * + * You can only reliably read and write legal locations. Reads + * and writes from the Forbidden Zone will return undefined values, + * and may cause segmentation faults. + * + * Now, the depth buffer may not end up in a location such each + * scan line is an LFB line. For example, the depth buffer may + * look like this: + * + * wrapped ordinary. + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * |0000000000000000000000 | | back + * |1111111111111111111111 | | buffer + * |2222222222222222222222 | | + * |4096b align. padxx00000000000000000| Forbidden Zone | depth + * |0000 11111111111111111| | buffer + * |1111 22222222222222222| | + * |2222 | | + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * where each number is the scan line number. We know it will + * be aligned on 128 byte boundaries, at least. Aligning this + * on a scanline boundary causes the back and depth buffers to + * thrash in the SST1 cache. (Note that the back buffer is always + * allocated at the beginning of LFB memory, and so it is always + * properly aligned with the LFB stride.) + * + * We call the beginning of the line (which is the rightmost + * part of the depth line in the picture above) the *ordinary* part + * of the scanline, and the end of the line (which is the + * leftmost part, one line below) the *wrapped* part of the scanline. + * a.) We need to know what x value to subtract from the screen + * x coordinate to index into the wrapped part. + * b.) We also need to figure out if we need to read from the ordinary + * part scan line, or from the wrapped part of the scan line. + * + * [ad a] + * The first wrapped x coordinate is that coordinate such that + * depthBufferOffset&(info.strideInBytes) + x*elmentSize {*} + * > physicalStrideInBytes + * where depthBufferOffset is the LFB distance in bytes + * from the back buffer to the depth buffer. The expression + * depthBufferOffset&(info.strideInBytes) + * is then the offset (in bytes) from the beginining of (any) + * depth buffer line to first element in the line. + * Simplifying inequation {*} above we see that x is the smallest + * value such that + * x*elementSize > physicalStrideInBytes {**} + * - depthBufferOffset&(info.strideInBytes) + * Now, we know that both the summands on the right are multiples of + * 128, and elementSize <= 4, so if equality holds in {**}, x would + * be a multiple of 32. Thus we can set x to + * xwrapped = (physicalStrideInBytes + * - depthBufferOffset&(info.strideInBytes))/elementSize + * + 1 + * + * [ad b] + * Question b is now simple. We read from the wrapped scan line if + * x is greater than xwrapped. + */ +#define TILE_WIDTH_IN_BYTES 128 +#define TILE_WIDTH_IN_ZOXELS(bpz) (TILE_WIDTH_IN_BYTES/(bpz)) +#define TILE_HEIGHT_IN_LINES 32 +typedef struct +{ + void *lfbPtr; + void *lfbWrapPtr; + FxU32 LFBStrideInElts; + FxU32 firstWrappedX; +} +LFBParameters; + +static void GetFbParams(fxMesaContext fxMesa, + GrLfbInfo_t * info, + GrLfbInfo_t * backBufferInfo, + LFBParameters * ReadParams, FxU32 elementSize); + +/* + * We need information about the back buffer. Note that + * this function *cannot be called* while the aux buffer + * is locked, or the caller will hang. + * + * Only Glide knows the LFB address of the back and depth + * offsets. The upper levels of Mesa know the depth offset, + * but that is not in LFB space, it is tiled memory space, + * and is not useable for us. + */ +static void +GetBackBufferInfo(fxMesaContext fxMesa, GrLfbInfo_t * backBufferInfo) +{ + READ_FB_SPAN_LOCK(fxMesa, *backBufferInfo, GR_BUFFER_BACKBUFFER); + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_BACKBUFFER); +} + +static void +GetFbParams(fxMesaContext fxMesa, + GrLfbInfo_t * info, + GrLfbInfo_t * backBufferInfo, + LFBParameters * ReadParamsp, FxU32 elementSize) +{ + FxU32 physicalStrideInBytes, bufferOffset; + FxU32 strideInBytes = info->strideInBytes; + FxU32 lfbPtr = (FxU32) (info->lfbPtr); + + /* + * These two come directly from the info structure. + */ + ReadParamsp->lfbPtr = (void *) lfbPtr; + ReadParamsp->LFBStrideInElts = strideInBytes / elementSize; + /* + * Now, calculate the value of firstWrappedX. + * + * The physical stride is the screen width in bytes rounded up to + * the next highest multiple of 128 bytes. Note that this fails + * when TILE_WIDTH_IN_BYTES is not a power of two. + * + * The buffer Offset is the distance between the beginning of + * the LFB space, which is the beginning of the back buffer, + * and the buffer we are gathering information about. + * We want to make this routine usable for operations on the + * back buffer, though we don't actually use it on the back + * buffer. Note, then, that if bufferOffset == 0, the firstWrappedX + * is in the forbidden zone, and is therefore never reached. + * + * Note that if + * physicalStrideInBytes + * < bufferOffset&(info->strideInBytes-1) + * the buffer begins in the forbidden zone. We assert for this. + */ + bufferOffset = lfbPtr - (FxU32) backBufferInfo->lfbPtr; + physicalStrideInBytes + = (fxMesa->screen_width * elementSize + TILE_WIDTH_IN_BYTES - 1) + & ~(TILE_WIDTH_IN_BYTES - 1); + assert(physicalStrideInBytes > (bufferOffset & (strideInBytes - 1))); + ReadParamsp->firstWrappedX + = (physicalStrideInBytes + - (bufferOffset & (strideInBytes - 1))) / elementSize; + /* + * This is the address of the next physical line. + */ + ReadParamsp->lfbWrapPtr + = (void *) ((FxU32) backBufferInfo->lfbPtr + + (bufferOffset & ~(strideInBytes - 1)) + + (TILE_HEIGHT_IN_LINES) * strideInBytes); +} + +/* + * These macros fetch data from the frame buffer. The type is + * the type of data we want to fetch. It should match the type + * whose size was used with GetFbParams to fill in the structure + * in *ReadParamsp. We have a macro to read the ordinary + * part, a second macro to read the wrapped part, and one which + * will do either. When we are reading a span, we will know + * when the ordinary part ends, so there's no need to test for + * it. However, when reading and writing pixels, we don't + * necessarily know. I suppose it's a matter of taste whether + * it's better in the macro or in the call. + * + * Recall that x and y are screen coordinates. + */ +#define GET_FB_DATA(ReadParamsp, type, x, y) \ + (((x) < (ReadParamsp)->firstWrappedX) \ + ? (((type *)((ReadParamsp)->lfbPtr)) \ + [(y) * ((ReadParamsp)->LFBStrideInElts) \ + + (x)]) \ + : (((type *)((ReadParamsp)->lfbWrapPtr)) \ + [((y)) * ((ReadParamsp)->LFBStrideInElts) \ + + ((x) - (ReadParamsp)->firstWrappedX)])) +#define GET_ORDINARY_FB_DATA(ReadParamsp, type, x, y) \ + (((type *)((ReadParamsp)->lfbPtr)) \ + [(y) * ((ReadParamsp)->LFBStrideInElts) \ + + (x)]) +#define GET_WRAPPED_FB_DATA(ReadParamsp, type, x, y) \ + (((type *)((ReadParamsp)->lfbWrapPtr)) \ + [((y)) * ((ReadParamsp)->LFBStrideInElts) \ + + ((x) - (ReadParamsp)->firstWrappedX)]) +#define PUT_FB_DATA(ReadParamsp, type, x, y, value) \ + (GET_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) +#define PUT_ORDINARY_FB_DATA(ReadParamsp, type, x, y, value) \ + (GET_ORDINARY_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) +#define PUT_WRAPPED_FB_DATA(ReadParamsp, type, x, y, value) \ + (GET_WRAPPED_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) + +static void +fxDDWriteDepthSpan(GLcontext * ctx, + GLuint n, GLint x, GLint y, const GLdepth depth[], + const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLint bottom = fxMesa->y_offset + fxMesa->height - 1; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLuint stencil_size = fxMesa->glVis->StencilBits; + GrLfbInfo_t info; + GLubyte visMask[MAX_WIDTH]; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDWriteDepthSpan(...)\n"); + } + + assert((depth_size == 16) || (depth_size == 24) || (depth_size == 32)); + /* + * Convert x and y to screen coordinates. + */ + x += fxMesa->x_offset; + y = bottom - y; + if (mask) { + GLint i; + GLushort d16; + GrLfbInfo_t backBufferInfo; + + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, + GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + int wrappedPartStart; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = n - (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + if (mask[i] && visMask[i]) { + d16 = depth[i]; + PUT_ORDINARY_FB_DATA(&ReadParams, GLushort, x + i, y, d16); + } + } + for (; i < n; i++) { + if (mask[i] && visMask[i]) { + d16 = depth[i]; + PUT_WRAPPED_FB_DATA(&ReadParams, GLushort, x + i, y, d16); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, + GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + int wrappedPartStart; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = n - (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + GLuint d32; + if (mask[i] && visMask[i]) { + if (stencil_size > 0) { + d32 = + GET_ORDINARY_FB_DATA(&ReadParams, GLuint, + x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + for (; i < n; i++) { + GLuint d32; + if (mask[i] && visMask[i]) { + if (stencil_size > 0) { + d32 = + GET_WRAPPED_FB_DATA(&ReadParams, GLuint, + x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + } + else { + GLint i; + GLuint d32; + GLushort d16; + GrLfbInfo_t backBufferInfo; + + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + GLuint wrappedPartStart; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = n - (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + if (visMask[i]) { + d16 = depth[i]; + PUT_ORDINARY_FB_DATA(&ReadParams, + GLushort, + x + i, y, + d16); + } + } + for (; i < n; i++) { + if (visMask[i]) { + d16 = depth[i]; + PUT_WRAPPED_FB_DATA(&ReadParams, + GLushort, + x + i, y, + d16); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + GLuint wrappedPartStart; + + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = n - (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + if (visMask[i]) { + if (stencil_size > 0) { + d32 = GET_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + for (; i < n; i++) { + if (visMask[i]) { + if (stencil_size > 0) { + d32 = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + } +} + +static void +fxDDReadDepthSpan(GLcontext * ctx, + GLuint n, GLint x, GLint y, GLdepth depth[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLushort depth16[MAX_WIDTH]; + GLuint i; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLuint stencil_size = fxMesa->glVis->StencilBits; + GrLfbInfo_t info; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDReadDepthSpan(...)\n"); + } + + /* + * Convert to screen coordinates. + */ + x += fxMesa->x_offset; + y = bottom - y; + switch (depth_size) { + case 16: + FX_grLfbReadRegion(fxMesa, GR_BUFFER_AUXBUFFER, x, y, n, 1, 0, depth16); + for (i = 0; i < n; i++) { + depth[i] = depth16[i]; + } + break; + case 24: + case 32: + { + LFBParameters ReadParams; + GrLfbInfo_t backBufferInfo; + int wrappedPartStart; + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + /* + * Read the line. + */ + for (i = 0; i < wrappedPartStart; i++) { + const GLuint mask = + (stencil_size > 0) ? 0x00FFFFFF : 0xFFFFFFFF; + depth[i] = + GET_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y); + depth[i] &= mask; + } + for (; i < n; i++) { + const GLuint mask = + (stencil_size > 0) ? 0x00FFFFFF : 0xFFFFFFFF; + depth[i] = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y); + depth[i] &= mask; + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + } +} + + +static void +fxDDWriteDepthPixels(GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + const GLdepth depth[], const GLubyte mask[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLuint i; + GLushort d16; + GLuint d32; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLuint stencil_size = fxMesa->glVis->StencilBits; + GrLfbInfo_t info; + int xpos; + int ypos; + GrLfbInfo_t backBufferInfo; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDWriteDepthPixels(...)\n"); + } + + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + for (i = 0; i < n; i++) { + if (mask[i] && visible_pixel(fxMesa, x[i], y[i])) { + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + d16 = depth[i]; + PUT_FB_DATA(&ReadParams, GLushort, xpos, ypos, d16); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + for (i = 0; i < n; i++) { + if (mask[i]) { + if (visible_pixel(fxMesa, x[i], y[i])) { + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + if (stencil_size > 0) { + d32 = + GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); + d32 = (d32 & 0xFF000000) | (depth[i] & 0xFFFFFF); + } + else { + d32 = depth[i]; + } + PUT_FB_DATA(&ReadParams, GLuint, xpos, ypos, d32); + } + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } +} + + +static void +fxDDReadDepthPixels(GLcontext * ctx, GLuint n, + const GLint x[], const GLint y[], GLdepth depth[]) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLuint i; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLushort d16; + int xpos; + int ypos; + GrLfbInfo_t info; + GLuint stencil_size; + GrLfbInfo_t backBufferInfo; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDReadDepthPixels(...)\n"); + } + + assert((depth_size == 16) || (depth_size == 24) || (depth_size == 32)); + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + for (i = 0; i < n; i++) { + /* + * Convert to screen coordinates. + */ + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + d16 = GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); + depth[i] = d16; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + stencil_size = fxMesa->glVis->StencilBits; + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + for (i = 0; i < n; i++) { + GLuint d32; + + /* + * Convert to screen coordinates. + */ + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + d32 = GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); + if (stencil_size > 0) { + d32 &= 0x00FFFFFF; + } + depth[i] = d32; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + default: + assert(0); + } +} + +/* + * Stencil buffer read/write functions. + */ +#define EXTRACT_S_FROM_ZS(zs) (((zs) >> 24) & 0xFF) +#define EXTRACT_Z_FROM_ZS(zs) ((zs) & 0xffffff) +#define BUILD_ZS(z, s) (((s) << 24) | (z)) + +static void +write_stencil_span(GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLstencil stencil[], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + LFBParameters ReadParams; + GLubyte visMask[MAX_WIDTH]; + GLuint i; + int wrappedPartStart; + + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + generate_vismask(fxMesa, scrX, scrY, n, visMask); + for (i = 0; i < wrappedPartStart; i++) { + if (visMask[i] && (!mask || mask[i])) { + GLuint z = GET_ORDINARY_FB_DATA(&ReadParams, GLuint, + scrX + i, scrY) & 0x00FFFFFF; + z |= (stencil[i] & 0xFF) << 24; + PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, scrX + i, scrY, z); + } + } + for (; i < n; i++) { + if (visMask[i] && (!mask || mask[i])) { + GLuint z = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, + scrX + i, scrY) & 0x00FFFFFF; + z |= (stencil[i] & 0xFF) << 24; + PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, scrX + i, scrY, z); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + + +static void +read_stencil_span(GLcontext * ctx, GLuint n, GLint x, GLint y, + GLstencil stencil[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + GLuint i; + LFBParameters ReadParams; + int wrappedPartStart; + + /* + * Convert to screen coordinates. + */ + x += winX; + y = winY - y; + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + stencil[i] = (GET_ORDINARY_FB_DATA(&ReadParams, GLuint, + x + i, y) >> 24) & 0xFF; + } + for (; i < n; i++) { + stencil[i] = (GET_WRAPPED_FB_DATA(&ReadParams, GLuint, + x + i, y) >> 24) & 0xFF; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + + +static void +write_stencil_pixels(GLcontext * ctx, GLuint n, + const GLint x[], const GLint y[], + const GLstencil stencil[], const GLubyte mask[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + LFBParameters ReadParams; + GLuint i; + + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + for (i = 0; i < n; i++) { + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + if ((!mask || mask[i]) && visible_pixel(fxMesa, scrX, scrY)) { + GLuint z = + GET_FB_DATA(&ReadParams, GLuint, scrX, scrY) & 0x00FFFFFF; + z |= (stencil[i] & 0xFF) << 24; + PUT_FB_DATA(&ReadParams, GLuint, scrX, scrY, z); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + + +static void +read_stencil_pixels(GLcontext * ctx, GLuint n, const GLint x[], + const GLint y[], GLstencil stencil[]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + GLuint i; + LFBParameters ReadParams; + + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + for (i = 0; i < n; i++) { + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + stencil[i] = + (GET_FB_DATA(&ReadParams, GLuint, scrX, scrY) >> 24) & 0xFF; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + +void +fxSetupDDSpanPointers(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (ctx->Visual->RedBits == 5 && + ctx->Visual->GreenBits == 6 && + ctx->Visual->BlueBits == 5 && ctx->Visual->AlphaBits == 0) { + /* 16bpp mode */ + ctx->Driver.WriteRGBASpan = write_R5G6B5_rgba_span; + ctx->Driver.WriteRGBSpan = write_R5G6B5_rgb_span; + ctx->Driver.WriteMonoRGBASpan = write_R5G6B5_mono_span; + ctx->Driver.WriteRGBAPixels = write_R5G6B5_pixels; + ctx->Driver.WriteMonoRGBAPixels = write_R5G6B5_mono_pixels; + ctx->Driver.ReadRGBASpan = read_R5G6B5_span; + ctx->Driver.ReadRGBAPixels = read_R5G6B5_pixels; + } + else if (ctx->Visual->RedBits == 8 && + ctx->Visual->GreenBits == 8 && + ctx->Visual->BlueBits == 8 && ctx->Visual->AlphaBits == 0) { + /* 24bpp mode */ + ctx->Driver.WriteRGBASpan = write_R8G8B8_rgba_span; + ctx->Driver.WriteRGBSpan = write_R8G8B8_rgb_span; + ctx->Driver.WriteMonoRGBASpan = write_R8G8B8_mono_span; + ctx->Driver.WriteRGBAPixels = write_R8G8B8_pixels; + ctx->Driver.WriteMonoRGBAPixels = write_R8G8B8_mono_pixels; + ctx->Driver.ReadRGBASpan = read_R8G8B8_span; + ctx->Driver.ReadRGBAPixels = read_R8G8B8_pixels; + } + else if (ctx->Visual->RedBits == 8 && + ctx->Visual->GreenBits == 8 && + ctx->Visual->BlueBits == 8 && ctx->Visual->AlphaBits == 8) { + /* 32bpp mode */ + ctx->Driver.WriteRGBASpan = write_R8G8B8A8_rgba_span; + ctx->Driver.WriteRGBSpan = write_R8G8B8A8_rgb_span; + ctx->Driver.WriteMonoRGBASpan = write_R8G8B8A8_mono_span; + ctx->Driver.WriteRGBAPixels = write_R8G8B8A8_pixels; + ctx->Driver.WriteMonoRGBAPixels = write_R8G8B8A8_mono_pixels; + ctx->Driver.ReadRGBASpan = read_R8G8B8A8_span; + ctx->Driver.ReadRGBAPixels = read_R8G8B8A8_pixels; + } + else { + abort(); + } + + if (fxMesa->haveHwStencil) { + ctx->Driver.WriteStencilSpan = write_stencil_span; + ctx->Driver.ReadStencilSpan = read_stencil_span; + ctx->Driver.WriteStencilPixels = write_stencil_pixels; + ctx->Driver.ReadStencilPixels = read_stencil_pixels; + } + + ctx->Driver.WriteDepthSpan = fxDDWriteDepthSpan; + ctx->Driver.WriteDepthPixels = fxDDWriteDepthPixels; + ctx->Driver.ReadDepthSpan = fxDDReadDepthSpan; + ctx->Driver.ReadDepthPixels = fxDDReadDepthPixels; + + ctx->Driver.WriteCI8Span = NULL; + ctx->Driver.WriteCI32Span = NULL; + ctx->Driver.WriteMonoCISpan = NULL; + ctx->Driver.WriteCI32Pixels = NULL; + ctx->Driver.WriteMonoCIPixels = NULL; + ctx->Driver.ReadCI32Span = NULL; + ctx->Driver.ReadCI32Pixels = NULL; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxddtex.c b/xc/lib/GL/mesa/src/drv/tdfx/fxddtex.c new file mode 100644 index 000000000..f7d0ef0a1 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxddtex.c @@ -0,0 +1,1646 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#include "fxdrv.h" +#include "fxddtex.h" +#include "fxtexman.h" +#include "fxsetup.h" +#include "image.h" +#include "texutil.h" + + +void +fxPrintTextureData(tfxTexInfo * ti) +{ + fprintf(stderr, "Texture Data:\n"); + if (ti->tObj) { + fprintf(stderr, "\tName: %d\n", ti->tObj->Name); + fprintf(stderr, "\tBaseLevel: %d\n", ti->tObj->BaseLevel); + fprintf(stderr, "\tSize: %d x %d\n", + ti->tObj->Image[ti->tObj->BaseLevel]->Width, + ti->tObj->Image[ti->tObj->BaseLevel]->Height); + } + else + fprintf(stderr, "\tName: UNNAMED\n"); + fprintf(stderr, "\tLast used: %d\n", ti->lastTimeUsed); + fprintf(stderr, "\tTMU: %ld\n", ti->whichTMU); + fprintf(stderr, "\t%s\n", (ti->isInTM) ? "In TMU" : "Not in TMU"); + if (ti->tm[0]) + fprintf(stderr, "\tMem0: %x-%x\n", (unsigned) ti->tm[0]->startAddr, + (unsigned) ti->tm[0]->endAddr); + if (ti->tm[1]) + fprintf(stderr, "\tMem1: %x-%x\n", (unsigned) ti->tm[1]->startAddr, + (unsigned) ti->tm[1]->endAddr); + fprintf(stderr, "\tMipmaps: %d-%d\n", ti->minLevel, ti->maxLevel); + fprintf(stderr, "\tFilters: min %d min %d\n", + (int) ti->minFilt, (int) ti->maxFilt); + fprintf(stderr, "\tClamps: s %d t %d\n", (int) ti->sClamp, + (int) ti->tClamp); + fprintf(stderr, "\tScales: s %f t %f\n", ti->sScale, ti->tScale); + fprintf(stderr, "\tInt Scales: s %d t %d\n", + ti->int_sScale / 0x800000, ti->int_tScale / 0x800000); + fprintf(stderr, "\t%s\n", + (ti->fixedPalette) ? "Fixed palette" : "Non fixed palette"); + fprintf(stderr, "\t%s\n", + (ti->validated) ? "Validated" : "Not validated"); +} + + +/************************************************************************/ +/*************************** Texture Mapping ****************************/ +/************************************************************************/ + +static void +fxTexInvalidate(GLcontext * ctx, struct gl_texture_object *tObj) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + tfxTexInfo *ti; + + ti = fxTMGetTexInfo(tObj); + if (ti->isInTM) + fxTMMoveOutTM(fxMesa, tObj); /* TO DO: SLOW but easy to write */ + + ti->validated = GL_FALSE; + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +static tfxTexInfo * +fxAllocTexObjData(fxMesaContext fxMesa) +{ + tfxTexInfo *ti; + int i; + + if (!(ti = CALLOC(sizeof(tfxTexInfo)))) { + gl_problem(NULL, "fx Driver: out of memory !\n"); + return NULL; + } + + ti->validated = GL_FALSE; + ti->isInTM = GL_FALSE; + + ti->whichTMU = FX_TMU_NONE; + + ti->tm[FX_TMU0] = NULL; + ti->tm[FX_TMU1] = NULL; + + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->maxFilt = GR_TEXTUREFILTER_BILINEAR; + + ti->sClamp = GR_TEXTURECLAMP_WRAP; + ti->tClamp = GR_TEXTURECLAMP_WRAP; + + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXFALSE; + + for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { + ti->mipmapLevel[i].data = NULL; + } + + return ti; +} + + +/* + * Called via glBindTexture. + */ +void +fxDDTexBind(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + tfxTexInfo *ti; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexBind(%d,%x)\n", tObj->Name, + (GLuint) tObj->DriverData); + } + + if (target != GL_TEXTURE_2D) + return; + + if (!tObj->DriverData) { + tObj->DriverData = fxAllocTexObjData(fxMesa); + } + + ti = fxTMGetTexInfo(tObj); + + fxMesa->texBindNumber++; + ti->lastTimeUsed = fxMesa->texBindNumber; + + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +void +fxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname, + const GLfloat * param) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + if (param) + fprintf(stderr, "fxmesa: texenv(%x,%x)\n", pname, + (GLint) (*param)); + else + fprintf(stderr, "fxmesa: texenv(%x)\n", pname); + } + + /* apply any lod biasing right now */ + if (pname == GL_TEXTURE_LOD_BIAS_EXT) { + FX_grTexLodBiasValue(GR_TMU0, *param); + if (fxMesa->haveTwoTMUs) { + FX_grTexLodBiasValue(GR_TMU1, *param); + } + } + + /* invalidate currently bound texture(s) */ + { + int i; + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { + struct gl_texture_object *tObj = ctx->Texture.Unit[i].CurrentD[2]; + if (!tObj->DriverData) { + tObj->DriverData = fxAllocTexObjData(fxMesa); + } + fxTexInvalidate(ctx, tObj); + } + } + + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +void +fxDDTexParam(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj, + GLenum pname, const GLfloat * params) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLenum param = (GLenum) (GLint) params[0]; + tfxTexInfo *ti; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexParam(%d,%x,%x,%x)\n", tObj->Name, + (GLuint) tObj->DriverData, pname, param); + } + + if (target != GL_TEXTURE_2D) + return; + + if (!tObj->DriverData) + tObj->DriverData = fxAllocTexObjData(fxMesa); + + ti = fxTMGetTexInfo(tObj); + + switch (pname) { + + case GL_TEXTURE_MIN_FILTER: + switch (param) { + case GL_NEAREST: + ti->mmMode = GR_MIPMAP_DISABLE; + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->LODblend = FXFALSE; + break; + case GL_LINEAR: + ti->mmMode = GR_MIPMAP_DISABLE; + ti->minFilt = GR_TEXTUREFILTER_BILINEAR; + ti->LODblend = FXFALSE; + break; + case GL_NEAREST_MIPMAP_NEAREST: + ti->mmMode = GR_MIPMAP_NEAREST; + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->LODblend = FXFALSE; + break; + case GL_LINEAR_MIPMAP_NEAREST: + ti->mmMode = GR_MIPMAP_NEAREST; + ti->minFilt = GR_TEXTUREFILTER_BILINEAR; + ti->LODblend = FXFALSE; + break; + case GL_NEAREST_MIPMAP_LINEAR: + if (fxMesa->haveTwoTMUs) { + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXTRUE; + } + else { + ti->mmMode = GR_MIPMAP_NEAREST_DITHER; + ti->LODblend = FXFALSE; + } + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + break; + case GL_LINEAR_MIPMAP_LINEAR: + if (fxMesa->haveTwoTMUs) { + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXTRUE; + } + else { + ti->mmMode = GR_MIPMAP_NEAREST_DITHER; + ti->LODblend = FXFALSE; + } + ti->minFilt = GR_TEXTUREFILTER_BILINEAR; + break; + default: + break; + } + fxTexInvalidate(ctx, tObj); + break; + + case GL_TEXTURE_MAG_FILTER: + switch (param) { + case GL_NEAREST: + ti->maxFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + break; + case GL_LINEAR: + ti->maxFilt = GR_TEXTUREFILTER_BILINEAR; + break; + default: + break; + } + fxTexInvalidate(ctx, tObj); + break; + + case GL_TEXTURE_WRAP_S: + switch (param) { + case GL_CLAMP: + ti->sClamp = GR_TEXTURECLAMP_CLAMP; + break; + case GL_REPEAT: + ti->sClamp = GR_TEXTURECLAMP_WRAP; + break; + default: + break; + } + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + + case GL_TEXTURE_WRAP_T: + switch (param) { + case GL_CLAMP: + ti->tClamp = GR_TEXTURECLAMP_CLAMP; + break; + case GL_REPEAT: + ti->tClamp = GR_TEXTURECLAMP_WRAP; + break; + default: + break; + } + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + + case GL_TEXTURE_BORDER_COLOR: + /* TO DO */ + break; + + case GL_TEXTURE_MIN_LOD: + /* TO DO */ + break; + case GL_TEXTURE_MAX_LOD: + /* TO DO */ + break; + case GL_TEXTURE_BASE_LEVEL: + fxTexInvalidate(ctx, tObj); + break; + case GL_TEXTURE_MAX_LEVEL: + fxTexInvalidate(ctx, tObj); + break; + + default: + break; + } +} + + +/* + * Called via glDeleteTextures to delete a texture object. + * Here, we delete the Glide data associated with the texture. + */ +void +fxDDTexDel(GLcontext * ctx, struct gl_texture_object *tObj) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexDel(%d,%p)\n", tObj->Name, ti); + } + + if (!ti) + return; + + fxTMFreeTexture(fxMesa, tObj); + + FREE(ti); + tObj->DriverData = NULL; + + ctx->NewState |= NEW_TEXTURING; +} + + +/* + * Return true if texture is resident, false otherwise. + */ +GLboolean +fxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj) +{ + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + /*printf("resident %d\n", (int) (ti && ti->isInTM));*/ + return (GLboolean) (ti && ti->isInTM); +} + + + +/* + * Convert a gl_color_table texture palette to Glide's format. + */ +static void +convertPalette(FxU32 data[256], const struct gl_color_table *table) +{ + const GLubyte *tableUB = (const GLubyte *) table->Table; + GLint width = table->Size; + FxU32 r, g, b, a; + GLint i; + + ASSERT(table->TableType == GL_UNSIGNED_BYTE); + + switch (table->Format) { + case GL_INTENSITY: + for (i = 0; i < width; i++) { + r = tableUB[i]; + g = tableUB[i]; + b = tableUB[i]; + a = tableUB[i]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_LUMINANCE: + for (i = 0; i < width; i++) { + r = tableUB[i]; + g = tableUB[i]; + b = tableUB[i]; + a = 255; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_ALPHA: + for (i = 0; i < width; i++) { + r = g = b = 255; + a = tableUB[i]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_LUMINANCE_ALPHA: + for (i = 0; i < width; i++) { + r = g = b = tableUB[i * 2 + 0]; + a = tableUB[i * 2 + 1]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_RGB: + for (i = 0; i < width; i++) { + r = tableUB[i * 3 + 0]; + g = tableUB[i * 3 + 1]; + b = tableUB[i * 3 + 2]; + a = 255; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_RGBA: + for (i = 0; i < width; i++) { + r = tableUB[i * 4 + 0]; + g = tableUB[i * 4 + 1]; + b = tableUB[i * 4 + 2]; + a = tableUB[i * 4 + 3]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + } +} + + + +void +fxDDTexPalette(GLcontext * ctx, struct gl_texture_object *tObj) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (tObj) { + /* per-texture palette */ + tfxTexInfo *ti; + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexPalette(%d,%x)\n", + tObj->Name, (GLuint) tObj->DriverData); + } + if (!tObj->DriverData) + tObj->DriverData = fxAllocTexObjData(fxMesa); + ti = fxTMGetTexInfo(tObj); + convertPalette(ti->palette.data, &tObj->Palette); + fxTexInvalidate(ctx, tObj); + } + else { + /* global texture palette */ + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexPalette(global)\n"); + } + convertPalette(fxMesa->glbPalette.data, &ctx->Texture.Palette); + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; + } +} + + +void +fxDDTexUseGlbPalette(GLcontext * ctx, GLboolean state) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexUseGlbPalette(%d)\n", state); + } + + if (state) { + fxMesa->haveGlobalPaletteTexture = 1; + + FX_grTexDownloadTable(fxMesa, GR_TMU0, GR_TEXTABLE_PALETTE_6666_EXT, + &(fxMesa->glbPalette)); + if (fxMesa->haveTwoTMUs) + FX_grTexDownloadTable(fxMesa, GR_TMU1, GR_TEXTABLE_PALETTE_6666_EXT, + &(fxMesa->glbPalette)); + } + else { + fxMesa->haveGlobalPaletteTexture = 0; + + if ((ctx->Texture.Unit[0].Current == ctx->Texture.Unit[0].CurrentD[2]) + && (ctx->Texture.Unit[0].Current != NULL)) { + struct gl_texture_object *tObj = ctx->Texture.Unit[0].Current; + + if (!tObj->DriverData) + tObj->DriverData = fxAllocTexObjData(fxMesa); + + fxTexInvalidate(ctx, tObj); + } + } +} + + +static int +logbase2(int n) +{ + GLint i = 1; + GLint log2 = 0; + + if (n < 0) { + return -1; + } + + while (n > i) { + i *= 2; + log2++; + } + if (i != n) { + return -1; + } + else { + return log2; + } +} + +/* Need different versions for different cpus. + */ +#define INT_TRICK(pow2) (0x800000 * (pow2)) + +/* + * Compute various texture image parameters. + * Input: w, h - source texture width and height + * Output: lodlevel - Glide lod level token + * aspectratio - Glide aspect ratio token + * sscale - S scale factor used during triangle setup + * tscale - T scale factor used during triangle setup + * i_sscale - integer S scale used during triangle setup + * i_tscale - integer T scale used during triangle setup + * wscale - OpenGL -> Glide image width scale factor + * hscale - OpenGL -> Glide image height scale factor + */ +void +fxTexGetInfo(const GLcontext *ctx, int w, int h, + GrLOD_t *lodlevel, GrAspectRatio_t *aspectratio, + float *sscale, float *tscale, + int *i_sscale, int *i_tscale, + int *wscale, int *hscale) +{ + int logw, logh, ar, lod, is, it, ws, hs; + float s, t; + + ASSERT(w >= 1); + ASSERT(h >= 1); + + logw = logbase2(w); + logh = logbase2(h); + ar = logw - logh; /* aspect ratio = difference in log dimensions */ + + /* Hardware only allows a maximum aspect ratio of 8x1, so handle + |ar| > 3 by scaling the image and using an 8x1 aspect ratio */ + if (ar >= 0) { + ASSERT(width >= height); + lod = logw; +#if 1 + s = 256.0; + is = INT_TRICK(8); +#else + s = ctx->Const.MaxTextureSize; + is = INT_TRICK(ctx->Const.MaxTextureLevels - 1); +#endif + ws = 1; + if (ar < 3) { +#if 1 + t = 256 >> ar; + it = INT_TRICK(8 - ar); +#else + t = ctx->Const.MaxTextureSize >> ar; + it = INT_TRICK(ctx->Const.MaxTextureLevels - 1 - ar); +#endif + hs = 1; + } + else { + t = 32.0; + it = INT_TRICK(5); + hs = 1 << (ar - 3); + } + } + else { + ASSERT(width < height); + lod = logh; +#if 1 + t = 256.0; + it = INT_TRICK(8); +#else + t = ctx->Const.MaxTextureSize; + it = INT_TRICK(ctx->Const.MaxTextureLevels - 1); +#endif + hs = 1; + if (-ar < 3) { +#if 1 + s = 256 >> -ar; + is = INT_TRICK(8 + ar); +#else + s = ctx->Const.MaxTextureSize >> - ar; + is = INT_TRICK(ctx->Const.MaxTextureLevels - 1 + ar); +#endif + ws = 1; + } + else { + s = 32.0; + is = INT_TRICK(5); + ws = 1 << (-ar - 3); + } + } + if (ar < -3) + ar = -3; + if (ar > 3) + ar = 3; + + if (lodlevel) + *lodlevel = (GrLOD_t) lod; + if (aspectratio) + *aspectratio = (GrAspectRatio_t) ar; + if (sscale) + *sscale = s; + if (tscale) + *tscale = t; + if (wscale) + *wscale = ws; + if (hscale) + *hscale = hs; + if (i_sscale) + *i_sscale = is; + if (i_tscale) + *i_tscale = it; +} + +/* + * Given an OpenGL internal texture format, return the corresponding + * Glide internal texture format and base texture format. + * If allow32bpp is true, we'll return 32-bit texel formats when + * appropriate. + */ +void +fxTexGetFormat(GLenum glformat, GrTextureFormat_t *glideFormat, + GLint *glFormat, MesaIntTexFormat *mesaFormat, + GLint *texelSize, GLboolean allow32bpp) +{ + switch (glformat) { + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + if (glideFormat) + *glideFormat = GR_TEXFMT_INTENSITY_8; + if (glFormat) + *glFormat = GL_LUMINANCE; + if (mesaFormat) + *mesaFormat = MESA_L8; + if (texelSize) + *texelSize = 1; + break; + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + if (glideFormat) + *glideFormat = GR_TEXFMT_ALPHA_INTENSITY_88; + if (glFormat) + *glFormat = GL_LUMINANCE_ALPHA; + if (mesaFormat) + *mesaFormat = MESA_A8_L8; + if (texelSize) + *texelSize = 2; + break; + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + if (glideFormat) + *glideFormat = GR_TEXFMT_ALPHA_8; + if (glFormat) + *glFormat = GL_INTENSITY; + if (mesaFormat) + *mesaFormat = MESA_I8; + if (texelSize) + *texelSize = 1; + break; + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + if (glideFormat) + *glideFormat = GR_TEXFMT_ALPHA_8; + if (glFormat) + *glFormat = GL_ALPHA; + if (mesaFormat) + *mesaFormat = MESA_A8; + if (texelSize) + *texelSize = 1; + break; + case GL_R3_G3_B2: + case GL_RGB4: + case GL_RGB5: + if (glideFormat) + *glideFormat = GR_TEXFMT_RGB_565; + if (glFormat) + *glFormat = GL_RGB; + if (mesaFormat) + *mesaFormat = MESA_R5_G6_B5; + if (texelSize) + *texelSize = 2; + break; + case 3: + case GL_RGB: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + if (allow32bpp) { + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_8888; + if (glFormat) + *glFormat = GL_RGB; + if (mesaFormat) + *mesaFormat = MESA_FF_R8_G8_B8; + if (texelSize) + *texelSize = 4; + } + else { + if (glideFormat) + *glideFormat = GR_TEXFMT_RGB_565; + if (glFormat) + *glFormat = GL_RGB; + if (mesaFormat) + *mesaFormat = MESA_R5_G6_B5; + if (texelSize) + *texelSize = 2; + } + break; + case GL_RGBA2: + case GL_RGBA4: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_4444; + if (glFormat) + *glFormat = GL_RGBA; + if (mesaFormat) + *mesaFormat = MESA_A4_R4_G4_B4; + if (texelSize) + *texelSize = 2; + break; + case 4: + case GL_RGBA: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + if (allow32bpp) { + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_8888; + if (glFormat) + *glFormat = GL_RGBA; + if (mesaFormat) + *mesaFormat = MESA_A8_R8_G8_B8; + if (texelSize) + *texelSize = 4; + } + else { + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_4444; + if (glFormat) + *glFormat = GL_RGBA; + if (mesaFormat) + *mesaFormat = MESA_A4_R4_G4_B4; + if (texelSize) + *texelSize = 2; + } + break; + case GL_RGB5_A1: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_1555; + if (glFormat) + *glFormat = GL_RGBA; + if (mesaFormat) + *mesaFormat = MESA_A1_R5_G5_B5; + if (texelSize) + *texelSize = 2; + break; + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + if (glideFormat) + *glideFormat = GR_TEXFMT_P_8; + if (glFormat) + *glFormat = GL_RGBA; /* XXX why is this RGBA? */ + if (mesaFormat) + *mesaFormat = MESA_C8; + if (texelSize) + *texelSize = 1; + break; + case GL_COMPRESSED_RGB_FXT1_3DFX: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_CMP_FXT1; + if (glFormat) + *glFormat = GL_COMPRESSED_RGB_FXT1_3DFX; + if (mesaFormat) + *mesaFormat = MESA_A8_R8_G8_B8; + if (texelSize) + *texelSize = 4; + break; + case GL_COMPRESSED_RGBA_FXT1_3DFX: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_CMP_FXT1; + if (glFormat) + *glFormat = GL_COMPRESSED_RGBA_FXT1_3DFX; + if (mesaFormat) + *mesaFormat = MESA_A8_R8_G8_B8; + if (texelSize) + *texelSize = 4; + break; + default: + gl_problem(NULL, "bad texture format in fxTexGetFormat()\n"); + break; + } +} + + +/**********************************************************************/ +/**** NEW TEXTURE IMAGE FUNCTIONS ****/ +/**********************************************************************/ + +static FxBool TexusFatalError = FXFALSE; +static FxBool TexusError = FXFALSE; + +#define TX_DITHER_NONE 0x00000000 + +static void +fxTexusError(const char *string, FxBool fatal) +{ + gl_problem(NULL, string); + /* + * Just propagate the fatal value up. + */ + TexusError = FXTRUE; + TexusFatalError = fatal; +} + +GLboolean +fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level, + GLenum format, GLenum type, const GLvoid * pixels, + const struct gl_pixelstore_attrib * packing, + struct gl_texture_object * texObj, + struct gl_texture_image * texImage, + GLboolean * retainInternalCopy) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + const GLboolean allow32bpt = fxMesa->haveHwStencil; + GrTextureFormat_t gldformat; + tfxTexInfo *ti; + tfxMipMapLevel *mml; + GLint dstWidth, dstHeight, wScale, hScale, texelSize, dstStride; + MesaIntTexFormat intFormat; + GLboolean isCompressedFormat; + GLint texsize; + void *uncompressedImage; + + if (target == GL_PROXY_TEXTURE_2D) { + /* XXX not possible for now */ + + } + + isCompressedFormat = texImage->IsCompressed; + if (target != GL_TEXTURE_2D || texImage->Border > 0) + return GL_FALSE; + + if (!texObj->DriverData) + texObj->DriverData = fxAllocTexObjData(fxMesa); + + ti = fxTMGetTexInfo(texObj); + mml = &ti->mipmapLevel[level]; + + /* Determine the appropriate GL internal texel format, Mesa internal + * texel format, and texelSize (bytes) given the user's internal + * texture format hint. + */ + fxTexGetFormat(texImage->IntFormat, &gldformat, NULL, &intFormat, + &texelSize, allow32bpt); + + /* Determine width and height scale factors for texture. + * Remember, Glide is limited to 8:1 aspect ratios. + */ + fxTexGetInfo(ctx, + texImage->Width, texImage->Height, + NULL, /* lod level */ + NULL, /* aspect ratio */ + NULL, NULL, /* sscale, tscale */ + NULL, NULL, /* i_sscale, i_tscale */ + &wScale, &hScale); + dstWidth = texImage->Width * wScale; + dstHeight = texImage->Height * hScale; + if (isCompressedFormat) { + texsize = fxDDCompressedImageSize(ctx, + texImage->IntFormat, + 2, + texImage->Width, + texImage->Height, + 1); + } else { + texsize = dstWidth * dstHeight * texelSize; + } + /* + * If the image is not compressed, this doesn't + * matter, but it might as well have a sensible + * value, and it might save a failure later on. + */ + texImage->CompressedSize = texsize; + /* housekeeping */ + _mesa_set_teximage_component_sizes(intFormat, texImage); + + /* + * allocate new storage for texture image, if needed. + * This conditional wants to set uncompressedImage to + * point to the uncompressed image, and mml->data to + * the texture data. If the image is uncompressed, + * these are identical. If the image is not compressed, + * these are different. + */ + if (!mml->data || mml->glideFormat != gldformat || + mml->width != dstWidth || mml->height != dstHeight || + texsize != mml->dataSize ) { + if (mml->data) { + FREE(mml->data); + } + uncompressedImage + = (void *)MALLOC(dstWidth * dstHeight * texelSize); + if (!uncompressedImage) { + return(GL_FALSE); + } + if (isCompressedFormat) { + mml->data = MALLOC(texsize); + if (!mml->data) { + FREE(uncompressedImage); + return GL_FALSE; + } + } else { + mml->data = uncompressedImage; + } + mml->texelSize = texelSize; + mml->glideFormat = gldformat; + mml->width = dstWidth; + mml->height = dstHeight; + mml->dataSize = texsize; + fxTexInvalidate(ctx, texObj); + } else { + /* + * Here we don't have to allocate anything, but we + * do have to point uncompressedImage to the uncompressed + * data. + */ + if (isCompressedFormat) { + uncompressedImage + = (void *)MALLOC(dstWidth * dstHeight * texelSize); + if (!uncompressedImage) { + return GL_FALSE; + } + } else { + uncompressedImage = mml->data; + } + } + + dstStride = dstWidth * texelSize; + + /* store the texture image into uncompressedImage */ + if (!_mesa_convert_teximage(intFormat, + dstWidth, dstHeight, + uncompressedImage, + dstStride, + texImage->Width, texImage->Height, + format, type, pixels, packing)) { + printf("convert failed\n"); + return GL_FALSE; + } + /* + * Now compress it if necessary. + */ + if (isCompressedFormat) { + TxErrorCallbackFnc_t oldErrorCallback; + (*txErrorSetCallbackPtr)(fxTexusError, &oldErrorCallback); + (*txImgQuantizePtr)((char *)mml->data, + (char *)uncompressedImage, + texImage->Width, + texImage->Height, + gldformat, + TX_DITHER_NONE); + (*txErrorSetCallbackPtr)(oldErrorCallback, NULL); + if (uncompressedImage != mml->data) { + /* + * We do not need this any more, errors or no. + */ + FREE(uncompressedImage); + } + TexusError = FXFALSE; + if (TexusFatalError) { + FREE(mml->data); + mml->data = (unsigned short *)0; + TexusFatalError = FXFALSE; + return(GL_FALSE); + } + } + if (ti->validated && ti->isInTM) { + fxTMReloadMipMapLevel(ctx, texObj, level); + } + else { + fxTexInvalidate(ctx, texObj); + } + + *retainInternalCopy = GL_FALSE; + return GL_TRUE; +} + + +GLboolean +fxDDTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const GLvoid * pixels, + const struct gl_pixelstore_attrib * packing, + struct gl_texture_object * texObj, + struct gl_texture_image * texImage) +{ + tfxTexInfo *ti; + GLint wscale, hscale, dstStride = 0; + tfxMipMapLevel *mml; + GLboolean result; + void *uncompressedImage = (void *)0; + FxU32 uncompressedSize; + TxErrorCallbackFnc_t oldErrorCallback; + + if (target != GL_TEXTURE_2D) + return GL_FALSE; + + if (!texObj->DriverData) + return GL_FALSE; + + ti = fxTMGetTexInfo(texObj); + mml = &ti->mipmapLevel[level]; + + fxTexGetInfo(ctx, texImage->Width, texImage->Height, NULL, NULL, + NULL, NULL, NULL, NULL, &wscale, &hscale); + + /* + * Must have an existing texture image! + */ + assert(mml->data); + + switch (mml->glideFormat) { + case GR_TEXFMT_INTENSITY_8: + dstStride = mml->width; + result = _mesa_convert_texsubimage(MESA_I8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ALPHA_8: + dstStride = mml->width; + result = _mesa_convert_texsubimage(MESA_A8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_P_8: + dstStride = mml->width; + result = _mesa_convert_texsubimage(MESA_C8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_A8_L8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_RGB_565: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_R5_G6_B5, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ARGB_4444: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_A4_R4_G4_B4, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + /* + * There are some special legality constraints for compressed + * textures. + */ + if ((xoffset != texImage->Border) + || (yoffset != texImage->Border)) { + gl_error( ctx, + GL_INVALID_OPERATION, + "glTexSubImage2D(offset)" ); + return GL_FALSE; + } + if ((width != texImage->Width) + || (height != texImage->Height)) { + gl_error( ctx, + GL_INVALID_VALUE, + "glTexSubImage2D(image size)" ); + return GL_FALSE; + } + /* + * The width and height have to be multiples of + * 8 and 4 respectively. + */ + width = (mml->width + 0x7) &~ 0x7; + height = (mml->height + 0x3) &~ 0x3; + /* + * A texel is 8888 for this format. + */ + uncompressedSize = mml->width * mml->height * 4; + uncompressedImage = (void *)MALLOC(uncompressedSize); + /* + * Convert the data. + */ + dstStride = mml->width * 4; + result = _mesa_convert_texsubimage(MESA_A8_R8_G8_B8, xoffset, yoffset, + mml->width, mml->height, uncompressedImage, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + if (!result) { + FREE(uncompressedImage); + return GL_FALSE; + } + /* + * Now that we have converted the data, then compress it. + */ + (*txErrorSetCallbackPtr)(fxTexusError, &oldErrorCallback); + (*txImgQuantizePtr)((char *)mml->data, + (char *)uncompressedImage, + mml->width, + mml->height, + mml->glideFormat, + TX_DITHER_NONE); + (*txErrorSetCallbackPtr)(oldErrorCallback, NULL); + result = TexusFatalError; + TexusFatalError = TexusError = FXFALSE; + /* + * We don't need this any more. + */ + FREE(uncompressedImage); + break; + case GR_TEXFMT_ARGB_8888: + { + MesaIntTexFormat intFormat; + if (texImage->Format == GL_RGB) { + /* An RGB image padded out to 4 bytes/texel */ + intFormat = MESA_FF_R8_G8_B8; + } + else { + intFormat = MESA_A8_R8_G8_B8; + } + dstStride = mml->width * 4; + result = _mesa_convert_texsubimage(intFormat, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + } + break; + case GR_TEXFMT_ARGB_1555: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_A1_R5_G5_B5, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + default: + gl_problem(NULL, "tdfx driver: fxTexBuildSubImageMap() bad format"); + result = GL_FALSE; + } + + if (!result) { + return GL_FALSE; + } + + if (ti->validated && ti->isInTM) + /* Don't use this, it's very broken. Download whole image for now.*/ +#if 0 + fxTMReloadSubMipMapLevel(ctx, texObj, level, yoffset, height); +#else + fxTMReloadMipMapLevel(ctx, texObj, level); +#endif + else + fxTexInvalidate(ctx, texObj); + + return GL_TRUE; +} + + +/**********************************************************************/ +/**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/ +/**********************************************************************/ + +GLboolean +fxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, + GLint level, GLsizei imageSize, + const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLboolean *retainInternalCopy) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + const GLboolean allow32bpt = fxMesa->haveHwStencil; + GrTextureFormat_t gldformat; + tfxTexInfo *ti; + tfxMipMapLevel *mml; + GLint dstWidth, dstHeight, wScale, hScale, texelSize; + MesaIntTexFormat intFormat; + GLboolean isCompressedFormat; + GLsizei texsize; + + if (target == GL_PROXY_TEXTURE_2D) { + /* XXX not possible for now */ + + } + + if (target != GL_TEXTURE_2D || texImage->Border > 0) + return GL_FALSE; + + if (!texObj->DriverData) + texObj->DriverData = fxAllocTexObjData(fxMesa); + + ti = fxTMGetTexInfo(texObj); + mml = &ti->mipmapLevel[level]; + + isCompressedFormat = fxDDIsCompressedGlideFormatMacro(texImage->IntFormat); + if (!isCompressedFormat) { + gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(format)" ); + return GL_FALSE; + } + /* Determine the apporpriate GL internal texel format, Mesa internal + * texel format, and texelSize (bytes) given the user's internal + * texture format hint. + */ + fxTexGetFormat(texImage->IntFormat, &gldformat, NULL, &intFormat, + &texelSize, allow32bpt); + + /* Determine width and height scale factors for texture. + * Remember, Glide is limited to 8:1 aspect ratios. + */ + fxTexGetInfo(ctx, + texImage->Width, texImage->Height, + NULL, /* lod level */ + NULL, /* aspect ratio */ + NULL, NULL, /* sscale, tscale */ + NULL, NULL, /* i_sscale, i_tscale */ + &wScale, &hScale); + dstWidth = texImage->Width * wScale; + dstHeight = texImage->Height * hScale; + /* housekeeping */ + _mesa_set_teximage_component_sizes(intFormat, texImage); + + texsize = fxDDCompressedImageSize(ctx, + texImage->IntFormat, + 2, + texImage->Width, + texImage->Height, + 1); + if (texsize != imageSize) { + gl_error(ctx, + GL_INVALID_VALUE, + "glCompressedTexImage2D(texsize)"); + return GL_FALSE; + } + /* allocate new storage for texture image, if needed */ + if (!mml->data || mml->glideFormat != gldformat || + mml->width != dstWidth || mml->height != dstHeight || + texsize != mml->dataSize) { + if (mml->data) { + FREE(mml->data); + } + mml->data = MALLOC(texsize); + if (!mml->data) { + return GL_FALSE; + } + mml->texelSize = texelSize; + mml->glideFormat = gldformat; + mml->width = dstWidth; + mml->height = dstHeight; + fxTexInvalidate(ctx, texObj); + } + + MEMCPY(mml->data, data, imageSize); + if (ti->validated && ti->isInTM) { + fxTMReloadMipMapLevel(ctx, texObj, level); + } + else { + fxTexInvalidate(ctx, texObj); + } + + *retainInternalCopy = GL_FALSE; + return GL_TRUE; +} + +GLboolean +fxDDCompressedTexSubImage2D( GLcontext *ctx, GLenum target, + GLint level, GLint xoffset, + GLint yoffset, GLsizei width, + GLint height, GLenum format, + GLsizei imageSize, const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + tfxTexInfo *ti; + tfxMipMapLevel *mml; + /* + * We punt if we are not replacing the entire image. This + * is allowed by the spec. + */ + if ((xoffset != 0) && (yoffset != 0) + && (width != texImage->Width) + && (height != texImage->Height)) { + return(GL_FALSE); + } + ti = fxTMGetTexInfo(texObj); + mml = &ti->mipmapLevel[level]; + if (imageSize != mml->dataSize) { + return(GL_FALSE); + } + MEMCPY(data, mml->data, imageSize); + return(GL_TRUE); +} + +#if 0 +static void +PrintTexture(int w, int h, int c, const GLubyte * data) +{ + int i, j; + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + if (c == 2) + printf("%02x %02x ", data[0], data[1]); + else if (c == 3) + printf("%02x %02x %02x ", data[0], data[1], data[2]); + data += c; + } + printf("\n"); + } +} +#endif + + +/* + * Return a texture image to Mesa. This is either to satisfy + * a glGetTexImage() call or to prepare for software texturing. + */ +GLvoid * +fxDDGetTexImage(GLcontext * ctx, GLenum target, GLint level, + const struct gl_texture_object *texObj, + GLenum * formatOut, GLenum * typeOut, + GLboolean * freeImageOut) +{ + tfxTexInfo *ti; + tfxMipMapLevel *mml; + + if (target != GL_TEXTURE_2D) + return NULL; + + if (!texObj->DriverData) + return NULL; + + ti = fxTMGetTexInfo(texObj); + mml = &ti->mipmapLevel[level]; + if (mml->data) { + MesaIntTexFormat mesaFormat; + GLenum glFormat; + struct gl_texture_image *texImage = texObj->Image[level]; + GLint srcStride; + void *uncompressedImage = NULL; + + GLubyte *data = + (GLubyte *) MALLOC(texImage->Width * texImage->Height * 4); + if (!data) + return NULL; + + uncompressedImage = (void *)mml->data; + switch (mml->glideFormat) { + case GR_TEXFMT_INTENSITY_8: + mesaFormat = MESA_I8; + glFormat = GL_INTENSITY; + srcStride = mml->width; + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + mesaFormat = MESA_A8_L8; + glFormat = GL_LUMINANCE_ALPHA; + srcStride = mml->width; + break; + case GR_TEXFMT_ALPHA_8: + if (texImage->Format == GL_INTENSITY) { + mesaFormat = MESA_I8; + glFormat = GL_INTENSITY; + } + else { + mesaFormat = MESA_A8; + glFormat = GL_ALPHA; + } + srcStride = mml->width; + break; + case GR_TEXFMT_RGB_565: + mesaFormat = MESA_R5_G6_B5; + glFormat = GL_RGB; + srcStride = mml->width * 2; + break; + case GR_TEXFMT_ARGB_8888: + mesaFormat = MESA_A8_R8_G8_B8; + glFormat = GL_RGBA; + srcStride = mml->width * 4; + break; + case GR_TEXFMT_ARGB_4444: + mesaFormat = MESA_A4_R4_G4_B4; + glFormat = GL_RGBA; + srcStride = mml->width * 2; + break; + case GR_TEXFMT_ARGB_1555: + mesaFormat = MESA_A1_R5_G5_B5; + glFormat = GL_RGBA; + srcStride = mml->width * 2; + break; + case GR_TEXFMT_P_8: + mesaFormat = MESA_C8; + glFormat = GL_COLOR_INDEX; + srcStride = mml->width; + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + mesaFormat = MESA_A8_R8_G8_B8; + glFormat = GL_RGBA; + srcStride = mml->width * 4; + /* + * Allocate data for the uncompressed image, + * decompress the image. The data will be deallocated + * after it is converted to the mesa format. + */ + uncompressedImage = MALLOC(mml->width * mml->height * 4); + if (!uncompressedImage) { + gl_problem(NULL, "can't get memory in fxDDGetTexImage"); + return(NULL); + } + (*txImgDequantizeFXT1Ptr)((FxU32 *)uncompressedImage, + (FxU32 *)mml->data, + mml->width, + mml->height); + break; + default: + gl_problem(NULL, "Bad glideFormat in fxDDGetTexImage"); + return NULL; + } + _mesa_unconvert_teximage(mesaFormat, mml->width, mml->height, + uncompressedImage, srcStride, texImage->Width, + texImage->Height, glFormat, data); + if (uncompressedImage != mml->data) { + FREE(uncompressedImage); + } + *formatOut = glFormat; + *typeOut = GL_UNSIGNED_BYTE; + *freeImageOut = GL_TRUE; + return data; + } + else { + return NULL; + } +} + +/* + * This is called from _mesa_GetCompressedTexImage. We just + * copy out the compressed data. + */ +void +fxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, + GLint lod, void *image, + const struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + tfxTexInfo *ti; + tfxMipMapLevel *mml; + + if (target != GL_TEXTURE_2D) + return; + + if (!texObj->DriverData) + return; + + ti = fxTMGetTexInfo(texObj); + mml = &ti->mipmapLevel[lod]; + if (mml->data) { + MEMCPY(image, mml->data, mml->dataSize); + } +} + +/* + * Calculate a specific texture format given a generic + * texture format. + */ +GLint +fxDDSpecificCompressedTexFormat(GLcontext *ctx, + GLint internalFormat, + GLint numDimensions) +{ + if (numDimensions != 2) { + return internalFormat; + } + /* + * If we don't have pointers to the functions, then + * we drop back to uncompressed format. The logic + * in Mesa proper handles this for us. + * + * This is just to ease the transition to a Glide with + * the texus2 library. + */ + if (!txImgQuantizePtr || !txImgDequantizeFXT1Ptr) { + return(internalFormat); + } + switch (internalFormat) { + case GL_COMPRESSED_RGB_ARB: + return GL_COMPRESSED_RGB_FXT1_3DFX; + case GL_COMPRESSED_RGBA_ARB: + return GL_COMPRESSED_RGBA_FXT1_3DFX; + } + return internalFormat; +} + +/* + * Calculate a specific texture format given a generic + * texture format. + */ +GLint +fxDDBaseCompressedTexFormat(GLcontext *ctx, + GLint internalFormat) +{ + switch (internalFormat) { + case GL_COMPRESSED_RGB_FXT1_3DFX: + return(GL_RGB); + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return(GL_RGBA); + } + return -1; +} + +/* + * Tell us if an image is compressed. The real work is done + * in a macro, but we need to have a function to create a + * function pointer. + */ +GLboolean +fxDDIsCompressedFormat(GLcontext *ctx, GLint internalFormat) +{ + return(fxDDIsCompressedFormatMacro(internalFormat)); +} + + +/* + * Calculate the image size of a compressed texture. + * + * The current compressed format, the FXT1 family, all + * map 8x32 texel blocks into 128 bits. + * + * We return 0 if we can't calculate the size. + * + * Glide would report this out to us, but we don't have + * exactly the right parameters. + */ +GLsizei +fxDDCompressedImageSize(GLcontext *ctx, + GLenum intFormat, + GLuint numDimensions, + GLuint width, + GLuint height, + GLuint depth) +{ + if (numDimensions != 2) { + return 0; + } + switch (intFormat) { + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: + /* + * Round height and width to multiples of 4 and 8, + * divide the resulting product by 32 to get the number + * of blocks, and multiply by 32 = 128/8 to get the. + * number of bytes required. That is to say, just + * return the product. Remember that we are returning + * bytes, not texels, so we have shrunk the texture + * by a factor of the texel size. + */ + width = (width + 0x7) &~ 0x7; + height = (height + 0x3) &~ 0x3; + return(width * height); + } + return(0); +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxddtex.h b/xc/lib/GL/mesa/src/drv/tdfx/fxddtex.h new file mode 100644 index 000000000..7a57df4e7 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxddtex.h @@ -0,0 +1,98 @@ +#ifndef FXDDTEX_H +#define FXDDTEX_H + + +#include "texutil.h" + + +extern void fxPrintTextureData(tfxTexInfo * ti); + +extern void fxTexGetFormat(GLenum, GrTextureFormat_t *, GLint *, + MesaIntTexFormat *, GLint *, GLboolean); + +extern void fxTexGetInfo(const GLcontext *, int, int, GrLOD_t *, + GrAspectRatio_t *, + float *, float *, int *, int *, int *, int *); + +extern GLboolean fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level, + GLenum format, GLenum type, + const GLvoid * pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLboolean * retainInternalCopy); + +extern GLboolean fxDDTexSubImage2D(GLcontext * ctx, GLenum target, + GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid * pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage); + +extern GLvoid *fxDDGetTexImage(GLcontext * ctx, GLenum target, GLint level, + const struct gl_texture_object *texObj, + GLenum * formatOut, GLenum * typeOut, + GLboolean * freeImageOut); + +extern GLboolean fxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, + GLint level, GLsizei imageSize, + const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLboolean *retainInternalCopy); +extern GLboolean fxDDCompressedTexSubImage2D( GLcontext *ctx, GLenum target, + GLint level, GLint xoffset, + GLint yoffset, GLsizei width, + GLint height, GLenum format, + GLsizei imageSize, const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ); +extern void fxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, + GLint lod, void *image, + const struct gl_texture_object *texObj, + struct gl_texture_image *texImage ); +extern GLint fxDDSpecificCompressedTexFormat(GLcontext *ctx, + GLint internalFormat, + GLint numDimensions); +extern GLint fxDDBaseCompressedTexFormat(GLcontext *ctx, + GLint internalFormat); + +#define fxDDIsCompressedFormatMacro(internalFormat) \ + (((internalFormat) == GL_COMPRESSED_RGB_FXT1_3DFX) || \ + ((internalFormat) == GL_COMPRESSED_RGBA_FXT1_3DFX)) +#define fxDDIsCompressedGlideFormatMacro(internalFormat) \ + ((internalFormat) == GR_TEXFMT_ARGB_CMP_FXT1) +extern GLboolean fxDDIsCompressedFormat(GLcontext *ctx, GLint internalFormat); + +extern void fxDDTexEnv(GLcontext *, GLenum, GLenum, const GLfloat *); + +extern void fxDDTexParam(GLcontext *, GLenum, struct gl_texture_object *, + GLenum, const GLfloat *); + +extern void fxDDTexBind(GLcontext *, GLenum, struct gl_texture_object *); + +extern void fxDDTexDel(GLcontext *, struct gl_texture_object *); + +extern GLboolean fxDDIsTextureResident(GLcontext *ctx, + struct gl_texture_object *t); + +extern void fxDDTexPalette(GLcontext *, struct gl_texture_object *); + +extern void fxDDTexUseGlbPalette(GLcontext *, GLboolean); + +/* + * Calculate the image size of a compressed texture. + * + * We return 0 if we can't calculate the size. + */ + +extern GLsizei fxDDCompressedImageSize(GLcontext *ctx, + GLenum internalFormat, + GLuint numDimensions, + GLuint width, + GLuint height, + GLuint depth); + +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxdrv.h b/xc/lib/GL/mesa/src/drv/tdfx/fxdrv.h new file mode 100644 index 000000000..5c9382a2c --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxdrv.h @@ -0,0 +1,799 @@ +/************************************************************************** + +Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Daryll Strauss <daryll@precisioninsight.com> + * Brian Paul <brianp@valinux.com> + */ + + +#ifndef _FXDRV_H_ +#define _FXDRV_H_ + +#ifdef GLX_DIRECT_RENDERING + +#include <sys/time.h> +#include <glide.h> +#include "dri_tmm.h" +#include "dri_mesaint.h" +#include "dri_mesa.h" +#include "dri_xmesaapi.h" +#ifdef XFree86Server +#include "GL/xf86glx.h" +#else +#include "glheader.h" +#endif +#if defined(__linux__) +#include <signal.h> +#endif +#include "context.h" +#include "macros.h" +#include "matrix.h" +#include "mem.h" +#include "texture.h" +#include "types.h" +#include "vb.h" +#include "xform.h" +#include "clip.h" +#include "vbrender.h" +#include "fxglidew.h" + + +/*typedef struct tfxMesaContext *fxMesaContext;*/ + + +typedef struct +{ + drmHandle handle; + drmSize size; + drmAddress map; +} +tdfxRegion, *tdfxRegionPtr; + +typedef struct +{ + tdfxRegion regs; + int deviceID; + int width; + int height; + int mem; + int cpp; + int stride; + int fifoOffset; + int fifoSize; + int fbOffset; + int backOffset; + int depthOffset; + int textureOffset; + int textureSize; + __DRIscreenPrivate *driScrnPriv; +} +tdfxScreenPrivate; + +typedef struct +{ + volatile int fifoPtr; + volatile int fifoRead; + volatile int fifoOwner; + volatile int ctxOwner; + volatile int texOwner; +} +TDFXSAREAPriv; + + +extern void fx_sanity_triangle(fxMesaContext fxMesa, + GrVertex *, GrVertex *, GrVertex *); +#if defined(MESA_DEBUG) && 0 +#define grDrawTriangle fx_sanity_triangle +#endif + + +/* Define some shorter names for these things. + */ +#define XCOORD GR_VERTEX_X_OFFSET +#define YCOORD GR_VERTEX_Y_OFFSET +#define ZCOORD GR_VERTEX_OOZ_OFFSET +#define OOWCOORD GR_VERTEX_OOW_OFFSET + +#define RCOORD GR_VERTEX_R_OFFSET +#define GCOORD GR_VERTEX_G_OFFSET +#define BCOORD GR_VERTEX_B_OFFSET +#define ACOORD GR_VERTEX_A_OFFSET + +#define S0COORD GR_VERTEX_SOW_TMU0_OFFSET +#define T0COORD GR_VERTEX_TOW_TMU0_OFFSET +#define S1COORD GR_VERTEX_SOW_TMU1_OFFSET +#define T1COORD GR_VERTEX_TOW_TMU1_OFFSET + + +#define CLIP_XCOORD 0 /* normal place */ +#define CLIP_YCOROD 1 /* normal place */ +#define CLIP_ZCOORD 2 /* GR_VERTEX_Z_OFFSET */ +#define CLIP_WCOORD 3 /* GR_VERTEX_R_OFFSET */ +#define CLIP_GCOORD 4 /* normal place */ +#define CLIP_BCOORD 5 /* normal place */ +#define CLIP_RCOORD 6 /* GR_VERTEX_OOZ_OFFSET */ +#define CLIP_ACOORD 7 /* normal place */ + + +/* Should have size == 16 * sizeof(float). + */ +typedef struct +{ + GLfloat f[15]; /* Same layout as GrVertex */ + GLubyte mask; /* Unsued */ + GLubyte usermask; /* Unused */ +} +fxVertex; + + +#ifdef __i386__ +#define FXCOLOR4( c ) (* (int *)c) +#else +#define FXCOLOR4( c ) ( \ + ( ((unsigned int)(c[3]))<<24 ) | \ + ( ((unsigned int)(c[2]))<<16 ) | \ + ( ((unsigned int)(c[1]))<<8 ) | \ + ( (unsigned int)(c[0])) ) +#endif + + +#define FX_VB_COLOR(fxm, color) \ + do { \ + if (sizeof(GLint) == 4*sizeof(GLubyte)) { \ + if (fxm->constColor != *(GLuint*)color) { \ + fxm->constColor = *(GLuint*)color; \ + FX_grConstantColorValue(fxm, FXCOLOR4(color)); \ + } \ + } else { \ + FX_grConstantColorValue(fxm, FXCOLOR4(color)); \ + } \ + } while (0) + +#define GOURAUD(x) { \ + GLubyte *col = VB->ColorPtr->data[(x)]; \ + gWin[(x)].v.r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \ + gWin[(x)].v.g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \ + gWin[(x)].v.b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \ + gWin[(x)].v.a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \ +} + +#define GOURAUD2(v, c) { \ + GLubyte *col = c; \ + v->r=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[0]); \ + v->g=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[1]); \ + v->b=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[2]); \ + v->a=UBYTE_COLOR_TO_FLOAT_255_COLOR(col[3]); \ +} + + +/* Mergable items first + */ +#define SETUP_RGBA 0x1 +#define SETUP_TMU0 0x2 +#define SETUP_TMU1 0x4 +#define SETUP_XY 0x8 +#define SETUP_Z 0x10 +#define SETUP_W 0x20 + +#define MAX_MERGABLE 0x8 + + +#define FX_NUM_TMU 2 + +#define FX_TMU0 GR_TMU0 +#define FX_TMU1 GR_TMU1 +#define FX_TMU_SPLIT 98 +#define FX_TMU_BOTH 99 +#define FX_TMU_NONE 100 + +/* Used for fxMesa->lastUnitsMode */ + +#define FX_UM_NONE 0x00000000 + +#define FX_UM_E0_REPLACE 0x00000001 +#define FX_UM_E0_MODULATE 0x00000002 +#define FX_UM_E0_DECAL 0x00000004 +#define FX_UM_E0_BLEND 0x00000008 +#define FX_UM_E0_ADD 0x00000010 + +#define FX_UM_E1_REPLACE 0x00000020 +#define FX_UM_E1_MODULATE 0x00000040 +#define FX_UM_E1_DECAL 0x00000080 +#define FX_UM_E1_BLEND 0x00000100 +#define FX_UM_E1_ADD 0x00000200 + +#define FX_UM_E_ENVMODE 0x000003ff + +#define FX_UM_E0_ALPHA 0x00001000 +#define FX_UM_E0_LUMINANCE 0x00002000 +#define FX_UM_E0_LUMINANCE_ALPHA 0x00004000 +#define FX_UM_E0_INTENSITY 0x00008000 +#define FX_UM_E0_RGB 0x00010000 +#define FX_UM_E0_RGBA 0x00020000 + +#define FX_UM_E1_ALPHA 0x00040000 +#define FX_UM_E1_LUMINANCE 0x00080000 +#define FX_UM_E1_LUMINANCE_ALPHA 0x00100000 +#define FX_UM_E1_INTENSITY 0x00200000 +#define FX_UM_E1_RGB 0x00400000 +#define FX_UM_E1_RGBA 0x00800000 + +#define FX_UM_E_IFMT 0x00fff000 + +#define FX_UM_COLOR_ITERATED 0x01000000 +#define FX_UM_COLOR_CONSTANT 0x02000000 +#define FX_UM_ALPHA_ITERATED 0x04000000 +#define FX_UM_ALPHA_CONSTANT 0x08000000 + + +#define PACK_BGRA32(R, G, B, A) \ + ( (((GLuint) (R)) << 16) | \ + (((GLuint) (G)) << 8) | \ + (((GLuint) (B)) ) | \ + (((GLuint) (A)) << 24) ) + +#define PACK_RGBA32(R, G, B, A) \ + ( (((GLuint) (R)) ) | \ + (((GLuint) (G)) << 8) | \ + (((GLuint) (B)) << 16) | \ + (((GLuint) (A)) << 24) ) + +/* + * The first two macros are to pack 8 bit color + * channel values into a 565 format. + */ +#define PACK_RGB16(R, G, B) \ + ((((GLuint) (R) & 0xF8) << 8) | \ + (((GLuint) (G) & 0xFC) << 3) | \ + (((GLuint) (B) & 0xFF) >> 3)) +#define PACK_BGR16(R, G, B) \ + ((((GLuint) (B) & 0xF8) << 8) | \ + (((GLuint) (G) & 0xFC) << 3) | \ + (((GLuint) (R) & 0xFF) >> 3)) +/* + * The second two macros pack 8 bit color channel values + * into 1555 values. + */ +#define PACK_RGBA16(R, G, B, A) \ + (((((GLuint) (A) & 0xFF) > 0) << 15)| \ + (((GLuint) (R) & 0xF8) << 7) | \ + (((GLuint) (G) & 0xF8) << 2) | \ + (((GLuint) (B) & 0xF8) >> 3)) +#define PACK_BGRA16(R, G, B, A) \ + (((((GLuint) (A) & 0xFF) > 0) << 15)| \ + (((GLuint) (B) & 0xF8) << 7) | \ + (((GLuint) (G) & 0xF8) << 2) | \ + (((GLuint) (R) & 0xF8) >> 3)) + +typedef void (*tfxRenderVBFunc) (GLcontext *); + +/* + Memory range from startAddr to endAddr-1 +*/ +typedef struct MemRange_t +{ + struct MemRange_t *next; + FxU32 startAddr, endAddr; +} +MemRange; + + +typedef struct +{ + GLsizei width, height; /* image size */ + GLint texelSize; /* How many bytes to a texel */ + GrTextureFormat_t glideFormat; /* Glide image format */ + unsigned short *data; /* Glide-formated texture image */ + FxU32 dataSize; /* Count of the data size */ +} +tfxMipMapLevel; + + +typedef struct tfxTexInfo_t +{ + struct tfxTexInfo *next; + struct gl_texture_object *tObj; + + GLuint lastTimeUsed; + FxU32 whichTMU; + GLboolean isInTM; + + GrAspectRatio_t aspectRatio; + tfxMipMapLevel mipmapLevel[MAX_TEXTURE_LEVELS]; + + MemRange *tm[FX_NUM_TMU]; + + GLint minLevel, maxLevel; + GLint baseLevelInternalFormat; + + GrTexInfo info; + + GrTextureFilterMode_t minFilt; + GrTextureFilterMode_t maxFilt; + FxBool LODblend; + + GrTextureClampMode_t sClamp; + GrTextureClampMode_t tClamp; + + GrMipMapMode_t mmMode; + + GLfloat sScale, tScale; + GLint int_sScale, int_tScale; /* x86 floating point trick for + * multiplication by powers of 2. + * Used in fxfasttmp.h + */ + GuTexPalette palette; + + GLboolean fixedPalette; + GLboolean validated; +} +tfxTexInfo; + + +typedef struct +{ + GLuint swapBuffer; + GLuint reqTexUpload; + GLuint texUpload; + GLuint memTexUpload; +} +tfxStats; + + +typedef void (*tfxTriViewClipFunc) (struct vertex_buffer * VB, + GLuint v[], GLubyte mask); + +typedef void (*tfxTriClipFunc) (struct vertex_buffer * VB, + GLuint v[], GLuint mask); + + +typedef void (*tfxLineClipFunc) (struct vertex_buffer * VB, + GLuint v1, GLuint v2, GLubyte mask); + + +extern tfxTriViewClipFunc fxTriViewClipTab[0x8]; +extern tfxTriClipFunc fxTriClipStrideTab[0x8]; +extern tfxLineClipFunc fxLineClipTab[0x8]; + +typedef struct +{ + /* Alpha test */ + GLboolean alphaTestEnabled; + GrCmpFnc_t alphaTestFunc; + GrAlpha_t alphaTestRefValue; + + /* Blend function */ + GLboolean blendEnabled; + GrAlphaBlendFnc_t blendSrcFuncRGB; + GrAlphaBlendFnc_t blendDstFuncRGB; + GrAlphaBlendFnc_t blendSrcFuncAlpha; + GrAlphaBlendFnc_t blendDstFuncAlpha; +} +tfxUnitsState; + + + +/* Flags for render_index. + */ +#define FX_OFFSET 0x1 +#define FX_TWOSIDE 0x2 +#define FX_FRONT_BACK 0x4 +#define FX_FLAT 0x8 +#define FX_ANTIALIAS 0x10 +#define FX_FALLBACK 0x20 + + +/* Flags for fxMesa->new_state + */ +#define FX_NEW_TEXTURING 0x1 +#define FX_NEW_BLEND 0x2 +#define FX_NEW_ALPHA 0x4 +#define FX_NEW_DEPTH 0x8 +#define FX_NEW_FOG 0x10 +#define FX_NEW_SCISSOR 0x20 +#define FX_NEW_COLOR_MASK 0x40 +#define FX_NEW_CULL 0x80 +#define FX_NEW_STENCIL 0x100 + +/* FX struct stored in VB->driver_data. + */ +struct tfxMesaVertexBuffer +{ + GLvector1ui clipped_elements; + + fxVertex *verts; + fxVertex *last_vert; + void *vert_store; +#if defined(FX_GLIDE3) + GrVertex **triangle_b; /* Triangle buffer */ + GrVertex **strips_b; /* Strips buffer */ +#endif + + GLuint size; +}; + +#define FX_DRIVER_DATA(vb) ((struct tfxMesaVertexBuffer *)((vb)->driver_data)) +#define FX_CONTEXT(ctx) ((fxMesaContext)((ctx)->DriverCtx)) +#define FX_TEXTURE_DATA(t) fxTMGetTexInfo((t)->Current) + + +#if !defined(FX_PXCONV_TABULAR) \ + && !defined(FX_PXCONV_APPROXIMATION) \ + && !defined(FX_PXCONV_EXACT) +#define FX_PXCONV_TABULAR +#endif +/* These lookup table are used to extract RGB values in [0,255] from + * 16-bit pixel values. + * + * In general, we want to convert 5 or 6 bit numbers to 8 + * bit numbers. + * o In the FX_PXCONV_TABULAR case, we do the numerically + * correct calculation at initialization time, and store + * the results in three large tables. + * o In the FX_PXCONV_APPROXIMATION method we approximate + * the numerically correct value by using the upper bits + * of the 5 or 6 bit value. That is, + * 8bitvalue = 5bitvalue << 3 | (5bitvalue >> 2) + * o In the FX_PXCONV_EXACT method, we calculate the + * exact value at runtime every time, using a floating + * point calculation. + */ +#define FX_PXCONV_INT_FIELD(v, w, s) (((v) >> (s)) & ((1 << (w)) - 1)) +#if defined(FX_PXCONV_TABULAR) +/* These lookup table are used to extract RGB values in [0,255] from + * 16-bit pixel values. + */ +extern GLubyte FX_PixelToRArray[0x10000]; +extern GLubyte FX_PixelToGArray[0x10000]; +extern GLubyte FX_PixelToBArray[0x10000]; +#define FX_PixelToB(fxMesa, v) (FX_PixelToBArray[(v)]) +#define FX_PixelToR(fxMesa, v) (FX_PixelToRArray[(v)]) +#define FX_PixelToG(fxMesa, v) (FX_PixelToGArray[(v)]) +#elif defined(FX_PXCONV_APPROXIMATION) +#define FX_PixelToR(fxMesa, v) \ + ((fxMesa)->bgrOrder \ + ? (FX_PXCONV_INT_FIELD(v, 5, 0) << 3) | FX_PXCONV_INT_FIELD(v, 3, 2) \ + : (FX_PXCONV_INT_FIELD(v, 5, 11) << 3) | FX_PXCONV_INT_FIELD(v, 3, 13)) +#define FX_PixelToG(fxMesa, v) \ + ((FX_PXCONV_INT_FIELD(v, 6, 5) << 2) | FX_PXCONV_INT_FIELD(v, 2, 7)) +#define FX_PixelToB(fxMesa, v) \ + ((fxMesa)->bgrOrder \ + ? (FX_PXCONV_INT_FIELD(v, 5, 11) << 3) | FX_PXCONV_INT_FIELD(v, 3, 13)\ + : (FX_PXCONV_INT_FIELD(v, 5, 0) << 3) | FX_PXCONV_INT_FIELD(v, 3, 2)) +#elif defined(FX_PXCONV_EXACT) +#define FX_PixelToR(fxMesa, v) \ + ((((fxMesa)->bgrOrder \ + ? FX_PXCONV_INT_FIELD(v, 5, 0) + : FX_PXCONV_INT_FIELD(v, 5, 11)) * 8 * 255) / 0xF8) +#define FX_PixelToG(fxMesa, v) \ + ((FX_PXCONV_INT_FIELD(v, 6, 5) * 4 * 255) / 0xFC) +#define FX_PixelToB(fxMesa, v) \ + ((((fxMesa)->bgrOrder \ + ? FX_PXCONV_INT_FIELD(v, 5, 11) + : FX_PXCONV_INT_FIELD(v, 5, 0)) * 8 * 255) / 0xF8) +#else +#error Need to define pixel a conversion method. +#endif + +struct tfxMesaContext +{ + GLcontext *glCtx; /* the core Mesa context */ + GLvisual *glVis; /* describes the color buffer */ + + GLint board; /* the board used for this context */ + GLint width, height; /* size of color buffer */ + + GrBuffer_t currentFB; + + GLboolean bgrOrder; + GLuint depthClear; + GrColor_t color; + GrColor_t clearC; + GrAlpha_t clearA; + GLuint constColor; + GrCullMode_t cullMode; + + tfxUnitsState unitsState; + tfxUnitsState restoreUnitsState; /* saved during multipass */ + + GuTexPalette glbPalette; + + GLuint tmu_source[FX_NUM_TMU]; + GLuint tex_dest[MAX_TEXTURE_UNITS]; + GLuint setupindex; + GLuint partial_setup_index; + GLuint setupdone; + GLuint mergeindex; + GLuint mergeinputs; + GLuint render_index; + GLuint last_tri_caps; + GLuint stw_hint_state; /* for grHints */ + GLuint is_in_hardware; + GLuint new_state; + GLuint using_fast_path, passes, multipass; + + tfxLineClipFunc clip_line; + tfxTriClipFunc clip_tri_stride; + tfxTriViewClipFunc view_clip_tri; + + + /* Texture Memory Manager Data */ + GLboolean umaTexMemory; + GLuint texBindNumber; + GLint tmuSrc; + GLuint freeTexMem[FX_NUM_TMU]; + MemRange *tmPool; + MemRange *tmFree[FX_NUM_TMU]; + + GLenum fogTableMode; + GLfloat fogDensity; + GLfloat fogStart, fogEnd; + GrFog_t *fogTable; + GLint textureAlign; + + /* Acc. functions */ + + points_func PointsFunc; + line_func LineFunc; + triangle_func TriangleFunc; + quad_func QuadFunc; + + render_func **RenderVBTables; + + render_func *RenderVBClippedTab; + render_func *RenderVBCulledTab; + render_func *RenderVBRawTab; + + + tfxStats stats; + + void *state; + + /* Options */ + + GLboolean verbose; + GLboolean haveTwoTMUs; /* True if we really have 2 tmu's */ + GLboolean emulateTwoTMUs; /* True if we present 2 tmu's to mesa. */ + GLboolean haveAlphaBuffer; + GLboolean haveHwStencil; + GLboolean haveGlobalPaletteTexture; + GLboolean isNapalm; + GLint swapInterval; + GLint maxPendingSwapBuffers; + + FX_GrContext_t glideContext; + + int x_offset; + int y_offset; + int y_delta; + int screen_width; + int screen_height; + int initDone; + int clipMinX; + int clipMaxX; + int clipMinY; + int clipMaxY; + int needClip; + + /* stuff added for DRI */ + __DRIcontextPrivate *driContextPriv; + drmContext hHWContext; + int numClipRects; + XF86DRIClipRectPtr pClipRects; + tdfxScreenPrivate *tdfxScrnPriv; +}; + + +typedef void (*tfxSetupFunc) (struct vertex_buffer *, GLuint, GLuint); + +extern int texSwaps; + +extern void fxPrintSetupFlags(const char *msg, GLuint flags); +extern void fxSetupDDPointers(GLcontext *); + +extern void fxDDSetupInit(void); +extern void fxDDCvaInit(void); +extern void fxDDTrifuncInit(void); +extern void fxDDFastPathInit(void); + +extern void fxDDRenderInitGlide3(GLcontext * ctx); + +extern void fxDDChooseRenderState(GLcontext * ctx); + +extern void fxRenderClippedLine(struct vertex_buffer *VB, + GLuint v1, GLuint v2); + +extern void fxRenderClippedTriangle(struct vertex_buffer *VB, + GLuint n, GLuint vlist[]); + + +extern tfxSetupFunc fxDDChooseSetupFunction(GLcontext *); + +extern points_func fxDDChoosePointsFunction(GLcontext *); +extern line_func fxDDChooseLineFunction(GLcontext *); +extern triangle_func fxDDChooseTriangleFunction(GLcontext *); +extern quad_func fxDDChooseQuadFunction(GLcontext *); +extern render_func **fxDDChooseRenderVBTables(GLcontext *); + +extern void fxDDRenderInit(GLcontext *); +extern void fxDDClipInit(void); + +extern void fxSetupDDSpanPointers(GLcontext *); + + +extern void fxDDRegisterVB(struct vertex_buffer *VB); +extern void fxDDUnregisterVB(struct vertex_buffer *VB); +extern void fxDDResizeVB(struct vertex_buffer *VB, GLuint size); + +extern void fxDDMergeAndRender(struct vertex_buffer *VB); + +extern void fxDDCheckPartialRasterSetup(GLcontext * ctx, + struct gl_pipeline_stage *d); + +extern void fxDDPartialRasterSetup(struct vertex_buffer *VB); + +extern void fxDDDoRasterSetup(struct vertex_buffer *VB); + +extern void fxDDRenderElementsDirect(struct vertex_buffer *VB); +extern void fxDDRenderVBIndirectDirect(struct vertex_buffer *VB); + +extern void fxDDFastPath(struct vertex_buffer *VB); + +extern void fxPrintRenderState(const char *msg, GLuint state); +extern void fxPrintHintState(const char *msg, GLuint state); + +extern void fxDDDoRenderVB(struct vertex_buffer *VB); + +extern int fxDDInitFxMesaContext(fxMesaContext fxMesa); + + +extern void fxSetScissorValues(GLcontext * ctx); +extern void fxTMMoveInTM_NoLock(fxMesaContext fxMesa, + struct gl_texture_object *tObj, GLint where); +extern void fxInitPixelTables(fxMesaContext fxMesa, GLboolean bgrOrder); + + + +extern GLboolean tdfxMapAllRegions(__DRIscreenPrivate * driScrnPriv); +extern void tdfxUnmapAllRegions(__DRIscreenPrivate * driScrnPriv); +extern GLboolean tdfxInitHW(__DRIdrawablePrivate * driDrawPrivate, + fxMesaContext cPriv); + +extern void XMesaUpdateState(fxMesaContext fxMesa); + + +/* This is the private interface between Glide and DRI */ +extern void grDRIOpen(char *pFB, char *pRegs, int deviceID, + int width, int height, + int mem, int cpp, int stride, + int fifoOffset, int fifoSize, + int fbOffset, int backOffset, int depthOffset, + int textureOffset, int textureSize, + volatile int *fifoPtr, volatile int *fifoRead); +extern void grDRIPosition(int x, int y, int w, int h, + int numClip, XF86DRIClipRectPtr pClip); +extern void grDRILostContext(void); +extern void grDRIImportFifo(int fifoPtr, int fifoRead); +extern void grDRIInvalidateAll(void); +extern void grDRIResetSAREA(void); +extern void grDRIBufferSwap(FxU32 swapInterval); +extern void grDRISwapClipRects(FxU32 swapInterval, + int numClip, + const XF86DRIClipRectPtr pClip); + + + +/* You can turn this on to find locking conflicts. +#define DEBUG_LOCKING +*/ + +#ifdef DEBUG_LOCKING +extern char *prevLockFile; +extern int prevLockLine; +#define DEBUG_LOCK() \ + do { \ + prevLockFile=(__FILE__); \ + prevLockLine=(__LINE__); \ + } while (0) +#define DEBUG_RESET() \ + do { \ + prevLockFile=0; \ + prevLockLine=0; \ + } while (0) +#define DEBUG_CHECK_LOCK() \ + do { \ + if (prevLockFile) { \ + fprintf(stderr, "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \ + prevLockFile, prevLockLine, __FILE__, __LINE__); \ + exit(1); \ + } \ + } while (0) +#else +#define DEBUG_LOCK() +#define DEBUG_RESET() +#define DEBUG_CHECK_LOCK() +#endif /* DEBUG_LOCKING */ + + +/* !!! We may want to separate locks from locks with validation. + This could be used to improve performance for those things + commands that do not do any drawing !!! */ + +#define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret) \ + do { \ + DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ + if (__ret) drmGetLock(fd,context,0); \ + } while(0) + +#define LOCK_HARDWARE(fxMesa) XMesaUpdateState(fxMesa) + +/* Unlock the hardware using the global current context */ +#define UNLOCK_HARDWARE(fxMesa) \ + do { \ + __DRIcontextPrivate *cPriv = fxMesa->driContextPriv; \ + __DRIdrawablePrivate *dPriv = cPriv->driDrawablePriv; \ + __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; \ + DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, \ + dPriv->driContextPriv->hHWContext); \ + DEBUG_RESET(); \ + } while (0) + +#define BEGIN_BOARD_LOCK(fxMesa) LOCK_HARDWARE(fxMesa) +#define END_BOARD_LOCK(fxMesa) UNLOCK_HARDWARE(fxMesa) + +/* + This pair of macros makes a loop over the drawing operations + so it is not self contained and doesn't have the nice single + statement semantics of most macros +*/ +#define BEGIN_CLIP_LOOP(fxMesa) \ + do { \ + __DRIcontextPrivate *cPriv = fxMesa->driContextPriv; \ + __DRIdrawablePrivate *dPriv = cPriv->driDrawablePriv; \ + int _nc; \ + LOCK_HARDWARE(fxMesa); \ + _nc = dPriv->numClipRects; \ + while (_nc--) { \ + if (fxMesa->needClip) { \ + fxMesa->clipMinX = dPriv->pClipRects[_nc].x1; \ + fxMesa->clipMaxX = dPriv->pClipRects[_nc].x2; \ + fxMesa->clipMinY = dPriv->pClipRects[_nc].y1; \ + fxMesa->clipMaxY = dPriv->pClipRects[_nc].y2; \ + fxSetScissorValues(fxMesa->glCtx); \ + } + +#define END_CLIP_LOOP(fxMesa) \ + } \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + + +#endif /* GLX_DIRECT_RENDERING */ + +#endif /* _FXDRV_H_ */ diff --git a/xc/extras/Mesa/src/FX/fxfastpath.c b/xc/lib/GL/mesa/src/drv/tdfx/fxfastpath.c index 605dd8d34..a86be1d92 100644 --- a/xc/extras/Mesa/src/FX/fxfastpath.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxfastpath.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -43,19 +41,15 @@ */ -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - - -#if defined(FX) - #include "types.h" #include "cva.h" #include "mmath.h" #include "fxdrv.h" +#include "fxtexman.h" #include "vertices.h" +#ifdef __i386__ #include "X86/common_x86asm.h" +#endif #if 0 && defined(__i386__) @@ -143,7 +137,7 @@ if (mask & PLANE) { \ #define CLIP_POINT( e ) \ if (mask[e]) \ - *out++ = e + *out++ = e #define CLIP_LINE( e1, e0 ) \ do { \ @@ -230,25 +224,21 @@ do { \ -struct fx_fast_tab +struct fx_fast_tab { - void (*build_vertices)( struct vertex_buffer *VB, GLuint do_clip ); - - void (*clip[GL_POLYGON+1])( struct vertex_buffer *VB, - GLuint start, - GLuint count, - GLuint parity ); - - void (*project_clipped_vertices)( GLfloat *first, - GLfloat *last, - const GLfloat *mat, - GLuint stride, - const GLubyte *mask ); - - void (*project_vertices)( GLfloat *first, - GLfloat *last, - const GLfloat *mat, - GLuint stride ); + void (*build_vertices) (struct vertex_buffer * VB, GLuint do_clip); + + void (*clip[GL_POLYGON + 1]) (struct vertex_buffer * VB, + GLuint start, GLuint count, GLuint parity); + + void (*project_clipped_vertices) (GLfloat * first, + GLfloat * last, + const GLfloat * mat, + GLuint stride, const GLubyte * mask); + + void (*project_vertices) (GLfloat * first, + GLfloat * last, + const GLfloat * mat, GLuint stride); }; /* Pack either rgba or texture into the remaining half of a 32 byte vertex. @@ -257,7 +247,7 @@ struct fx_fast_tab #define CLIP_G CLIP_GCOORD #define CLIP_B CLIP_BCOORD #define CLIP_A CLIP_ACOORD -#define CLIP_S0 4 +#define CLIP_S0 4 #define CLIP_T0 5 #define CLIP_S1 6 #define CLIP_T1 7 @@ -326,100 +316,89 @@ struct fx_fast_tab static struct fx_fast_tab fxFastTab[0x8]; -void fxDDFastPathInit() +void +fxDDFastPathInit() { - fx_init_fastpath( &fxFastTab[0] ); - fx_init_fastpath_RGBA( &fxFastTab[SETUP_RGBA] ); - fx_init_fastpath_TMU0( &fxFastTab[SETUP_TMU0] ); - fx_init_fastpath_TMU1( &fxFastTab[SETUP_TMU1] ); - fx_init_fastpath_RGBA_TMU0( &fxFastTab[SETUP_RGBA|SETUP_TMU0] ); - fx_init_fastpath_RGBA_TMU1( &fxFastTab[SETUP_RGBA|SETUP_TMU1] ); - fx_init_fastpath_TMU0_TMU1( &fxFastTab[SETUP_TMU0|SETUP_TMU1] ); - fx_init_fastpath_RGBA_TMU0_TMU1( &fxFastTab[SETUP_RGBA|SETUP_TMU0| - SETUP_TMU1] ); + fx_init_fastpath(&fxFastTab[0]); + fx_init_fastpath_RGBA(&fxFastTab[SETUP_RGBA]); + fx_init_fastpath_TMU0(&fxFastTab[SETUP_TMU0]); + fx_init_fastpath_TMU1(&fxFastTab[SETUP_TMU1]); + fx_init_fastpath_RGBA_TMU0(&fxFastTab[SETUP_RGBA | SETUP_TMU0]); + fx_init_fastpath_RGBA_TMU1(&fxFastTab[SETUP_RGBA | SETUP_TMU1]); + fx_init_fastpath_TMU0_TMU1(&fxFastTab[SETUP_TMU0 | SETUP_TMU1]); + fx_init_fastpath_RGBA_TMU0_TMU1(&fxFastTab[SETUP_RGBA | SETUP_TMU0 | + SETUP_TMU1]); } -void fxDDFastPath( struct vertex_buffer *VB ) +void +fxDDFastPath(struct vertex_buffer *VB) { - GLcontext *ctx = VB->ctx; - GLenum prim = ctx->CVA.elt_mode; - struct tfxMesaContext *fxMesa = FX_CONTEXT(ctx); - struct fx_fast_tab *tab = &fxFastTab[fxMesa->setupindex & 0x7]; - GLuint do_clip = 1; - struct tfxMesaVertexBuffer *fxVB = FX_DRIVER_DATA(VB); + GLcontext *ctx = VB->ctx; + GLenum prim = ctx->CVA.elt_mode; + struct tfxMesaContext *fxMesa = FX_CONTEXT(ctx); + struct fx_fast_tab *tab = &fxFastTab[fxMesa->setupindex & 0x7]; + GLuint do_clip = 1; + struct tfxMesaVertexBuffer *fxVB = FX_DRIVER_DATA(VB); #ifdef DRIVERTS - GLfloat tx, ty; + GLfloat tx, ty; #endif - fxVertex *first; - GLfloat *mat = ctx->Viewport.WindowMap.m; + fxVertex *first; + GLfloat *mat = ctx->Viewport.WindowMap.m; - gl_prepare_arrays_cva( VB ); /* still need this */ + gl_prepare_arrays_cva(VB); /* still need this */ - if (VB->EltPtr->count * 12 > fxVB->size) { - fxDDResizeVB( VB, VB->EltPtr->count * 12 ); - do_clip = 1; - } + if (VB->EltPtr->count * 12 > fxVB->size) { + fxDDResizeVB(VB, VB->EltPtr->count * 12); + do_clip = 1; + } - tab->build_vertices( VB, do_clip ); /* object->clip space */ + tab->build_vertices(VB, do_clip); /* object->clip space */ - first = FX_DRIVER_DATA(VB)->verts; + first = FX_DRIVER_DATA(VB)->verts; #ifdef DRIVERTS - tx=mat[MAT_TX]; - ty=mat[MAT_TY]; - mat[MAT_TX]=tx+fxMesa->x_offset; - mat[MAT_TY]=ty+fxMesa->y_delta; + tx = mat[MAT_TX]; + ty = mat[MAT_TY]; + mat[MAT_TX] = tx + fxMesa->x_offset; + mat[MAT_TY] = ty + fxMesa->y_delta; #endif - if (VB->ClipOrMask) { - if (!VB->ClipAndMask) { - GLubyte tmp = VB->ClipOrMask; + if (VB->ClipOrMask) { + if (!VB->ClipAndMask) { + GLubyte tmp = VB->ClipOrMask; + + tab->clip[prim] (VB, 0, VB->EltPtr->count, 0); /* clip */ - tab->clip[prim]( VB, 0, VB->EltPtr->count, 0 ); /* clip */ + tab->project_clipped_vertices(fxVB->verts->f, + fxVB->last_vert->f, + mat, 16 * 4, VB->ClipMask); - tab->project_clipped_vertices( fxVB->verts->f, - fxVB->last_vert->f, - mat, 16 * 4, - VB->ClipMask ); - - ctx->CVA.elt_mode = gl_reduce_prim[prim]; - VB->EltPtr = &(FX_DRIVER_DATA(VB)->clipped_elements); + ctx->CVA.elt_mode = gl_reduce_prim[prim]; + VB->EltPtr = &(FX_DRIVER_DATA(VB)->clipped_elements); - VB->ClipOrMask = 0; - fxDDRenderElementsDirect( VB ); /* render using new list */ - VB->ClipOrMask = tmp; - } - } else { - tab->project_vertices( fxVB->verts->f, - fxVB->last_vert->f, - mat, 16 * 4 ); + VB->ClipOrMask = 0; + fxDDRenderElementsDirect(VB); /* render using new list */ + VB->ClipOrMask = tmp; + } + } + else { + tab->project_vertices(fxVB->verts->f, fxVB->last_vert->f, mat, + 16 * 4); - fxDDRenderElementsDirect( VB ); /* render using orig list */ - } + fxDDRenderElementsDirect(VB); /* render using orig list */ + } #ifdef DRIVERTS - mat[MAT_TX]=tx; - mat[MAT_TY]=ty; + mat[MAT_TX] = tx; + mat[MAT_TY] = ty; #endif - /* This indicates that there is no cached data to reuse. - */ - VB->pipeline->data_valid = 0; - VB->pipeline->pipeline_valid = 0; + /* This indicates that there is no cached data to reuse. + */ + VB->pipeline->data_valid = 0; + VB->pipeline->pipeline_valid = 0; } - -#else - -/* - * Need this to provide at least one external definition. - */ -int gl_fxfastpath_dummy(void) -{ - return 0; -} - -#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxfasttmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxfasttmp.h new file mode 100644 index 000000000..2d9439084 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxfasttmp.h @@ -0,0 +1,362 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +/* Build clip space vertices from object space data. + */ +static void TAG(fx_setup_full) (struct vertex_buffer * VB, GLuint do_clip) +{ + GLcontext *ctx = VB->ctx; + GLfloat *f = (GLfloat *) FX_DRIVER_DATA(VB)->verts; + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); + GLuint count = VB->Count; + GLuint i; + + const GLfloat *const m = ctx->ModelProjectMatrix.m; + +#if (TYPE & SETUP_RGBA) + GLubyte *color = (GLubyte *) VB->ColorPtr->data; + GLuint color_stride = VB->ColorPtr->stride; +#endif + +#if (TYPE & SETUP_TMU0) + GLuint tmu0_source = fxMesa->tmu_source[0]; + struct gl_texture_unit *t0 = &ctx->Texture.Unit[tmu0_source]; + GLint s0scale = FX_TEXTURE_DATA(t0)->int_sScale; + GLint t0scale = FX_TEXTURE_DATA(t0)->int_tScale; + GLint *tmu0_int_data = (GLint *) VB->TexCoordPtr[tmu0_source]->data; + GLuint tmu0_stride = VB->TexCoordPtr[tmu0_source]->stride; +#endif + +#if (TYPE & SETUP_TMU1) + GLuint tmu1_source = fxMesa->tmu_source[1]; + struct gl_texture_unit *t1 = &ctx->Texture.Unit[tmu1_source]; + GLint s1scale = FX_TEXTURE_DATA(t1)->int_sScale; + GLint t1scale = FX_TEXTURE_DATA(t1)->int_tScale; + GLint *tmu1_int_data = (GLint *) VB->TexCoordPtr[tmu1_source]->data; + GLuint tmu1_stride = VB->TexCoordPtr[tmu1_source]->stride; +#endif + + (void) fxMesa; + (void) ctx; + (void) i; + (void) f; + + /* Use 3 seperate loops because it's easier for assembly. A + * best-case solution might be to do all three in a single assembly + * loop. + */ + gl_xform_points3_v16_general(FX_DRIVER_DATA(VB)->verts[0].f, + m, + VB->ObjPtr->start, VB->ObjPtr->stride, + count); + + if (do_clip) { + VB->ClipAndMask = ~0; + VB->ClipOrMask = 0; + gl_cliptest_points4_v16(FX_DRIVER_DATA(VB)->verts[0].f, + FX_DRIVER_DATA(VB)->verts[count].f, + &(VB->ClipOrMask), + &(VB->ClipAndMask), VB->ClipMask); + } + + +#if (TYPE) + for (i = 0; i < count; i++, f += 16) { +#if (TYPE & SETUP_RGBA) + GLubyte *col = color; + color += color_stride; + UBYTE_COLOR_TO_FLOAT_255_COLOR2(f[CLIP_R], col[0]); + UBYTE_COLOR_TO_FLOAT_255_COLOR2(f[CLIP_G], col[1]); + UBYTE_COLOR_TO_FLOAT_255_COLOR2(f[CLIP_B], col[2]); + UBYTE_COLOR_TO_FLOAT_255_COLOR2(f[CLIP_A], col[3]); +#endif +#if (TYPE & SETUP_TMU0) + *(int *) &f[CLIP_S0] = s0scale + tmu0_int_data[0]; + *(int *) &f[CLIP_T0] = t0scale + tmu0_int_data[1]; + STRIDE_T(tmu0_int_data, GLint, tmu0_stride); +#endif +#if (TYPE & SETUP_TMU1) + *(int *) &f[CLIP_S1] = s1scale + tmu1_int_data[0]; + *(int *) &f[CLIP_T1] = t1scale + tmu1_int_data[1]; + STRIDE_T(tmu1_int_data, GLint, tmu1_stride); +#endif + } +#endif + + FX_DRIVER_DATA(VB)->last_vert = &(FX_DRIVER_DATA(VB)->verts[count]); +} + + +/* Do viewport map, device scale and perspective projection. + * + * Rearrange fxVertices to look like grVertices. + */ +static void TAG(fx_project_vertices) (GLfloat * first, + GLfloat * last, + const GLfloat * mat, GLuint stride) +{ + GLfloat *f; + VARS_XYZ; + + for (f = first; f != last; STRIDE_F(f, stride)) { + GLfloat oow = 1.0f / f[CLIP_WCOORD]; /* urp! */ + +#if FX_USE_PARGB + if (TYPE & SETUP_RGBA) { + PACK_4F_ARGB(GET_PARGB(f), f[CLIP_A], f[CLIP_R], f[CLIP_G], + f[CLIP_B]); + } +#else + if (TYPE & SETUP_RGBA) { + f[RCOORD] = f[CLIP_R]; + } +#endif + if (TYPE & SETUP_TMU1) { + f[S1COORD] = f[CLIP_S1] * oow; + f[T1COORD] = f[CLIP_T1] * oow; + } + + if (TYPE & SETUP_TMU0) { + f[T0COORD] = f[CLIP_T0] * oow; + f[S0COORD] = f[CLIP_S0] * oow; + } + + DO_SETUP_XYZ; + + f[OOWCOORD] = oow; + } +} + +static void TAG(fx_project_clipped_vertices) (GLfloat * first, + GLfloat * last, + const GLfloat * mat, + GLuint stride, + const GLubyte * mask) +{ + GLfloat *f; + VARS_XYZ; + + for (f = first; f != last; STRIDE_F(f, stride), mask++) { + if (!*mask) { + + GLfloat oow = 1.0f / f[CLIP_WCOORD]; +#if FX_USE_PARGB + if (TYPE & SETUP_RGBA) { + const GLuint r = f[CLIP_R]; + const GLuint g = f[CLIP_G]; + const GLuint b = f[CLIP_B]; + const GLuint a = f[CLIP_A]; + /* ToDo Optimize */ + GET_PARGB(f) = a << 24 | r << 16 | g << 8 | b; + } +#else + if (TYPE & SETUP_RGBA) { + f[RCOORD] = f[CLIP_R]; + } +#endif + + if (TYPE & SETUP_TMU1) { + f[S1COORD] = f[CLIP_S1] * oow; + f[T1COORD] = f[CLIP_T1] * oow; + } + + if (TYPE & SETUP_TMU0) { + f[T0COORD] = f[CLIP_T0] * oow; + f[S0COORD] = f[CLIP_S0] * oow; + } + + DO_SETUP_XYZ; + + f[OOWCOORD] = oow; + } + } +} + + +static +#if (SIZE <= 8) + INLINE +#endif +void TAG(fx_tri_clip) (GLuint ** p_elts, + fxVertex * verts, + GLubyte * clipmask, GLuint * p_next_vert, GLubyte mask) +{ + GLuint *elts = *p_elts; + GLuint next_vert = *p_next_vert; + GLuint vlist1[VB_MAX_CLIPPED_VERTS]; + GLuint vlist2[VB_MAX_CLIPPED_VERTS]; + GLuint *inlist[2]; + GLuint *out; + GLuint in = 0; + GLuint n = 3; + GLuint i; + + inlist[0] = elts; + inlist[1] = vlist2; + + CLIP(-, 0, CLIP_RIGHT_BIT); + CLIP(+, 0, CLIP_LEFT_BIT); + CLIP(-, 1, CLIP_TOP_BIT); + CLIP(+, 1, CLIP_BOTTOM_BIT); + CLIP(-, 2, CLIP_FAR_BIT); + CLIP(+, 2, CLIP_NEAR_BIT); + + /* Convert the planar polygon to a list of triangles. + */ + out = inlist[in]; + + for (i = 2; i < n; i++) { + elts[0] = out[0]; + elts[1] = out[i - 1]; + elts[2] = out[i]; + elts += 3; + } + + *p_next_vert = next_vert; + *p_elts = elts; +} + + +static INLINE void TAG(fx_line_clip) (GLuint ** p_elts, + fxVertex * verts, + GLubyte * clipmask, + GLuint * p_next_vert, GLubyte mask) +{ + GLuint *elts = *p_elts; + GLfloat *I = verts[elts[0]].f; + GLfloat *J = verts[elts[1]].f; + GLuint next_vert = *p_next_vert; + + LINE_CLIP(1, 0, 0, -1, CLIP_LEFT_BIT); + LINE_CLIP(-1, 0, 0, 1, CLIP_RIGHT_BIT); + LINE_CLIP(0, 1, 0, -1, CLIP_TOP_BIT); + LINE_CLIP(0, -1, 0, 1, CLIP_BOTTOM_BIT); + LINE_CLIP(0, 0, 1, -1, CLIP_FAR_BIT); + LINE_CLIP(0, 0, -1, 1, CLIP_NEAR_BIT); + + *p_next_vert = next_vert; + *p_elts += 2; +} + + +/* Build a table of functions to clip each primitive type. + */ +#define LOCAL_VARS \ + GLuint *elt = VB->EltPtr->data; \ + fxVertex *verts = FX_DRIVER_DATA(VB)->verts; \ + GLuint next_vert = VB->Count; \ + GLuint *out = FX_DRIVER_DATA(VB)->clipped_elements.data; \ + GLubyte *mask = VB->ClipMask; \ + + +#define POSTFIX \ + FX_DRIVER_DATA(VB)->clipped_elements.count = \ + out - FX_DRIVER_DATA(VB)->clipped_elements.data; \ + FX_DRIVER_DATA(VB)->last_vert = &verts[next_vert]; + +#define INIT(x) + +#define RENDER_POINTS(start, count) \ +do { \ + GLuint i; \ + for (i = start ; i < count ; i++ ) \ + CLIP_POINT( elt[i] ); \ +} while (0) + +#define RENDER_LINE(i1, i0) \ + CLIP_LINE(elt[i1], elt[i0]) + +#define RENDER_TRI(i2, i1, i0, pv, parroty) \ +do { \ + GLuint e2 = elt[i2], e1 = elt[i1], e0 = elt[i0]; \ + if (parroty) e2 = elt[i1], e1 = elt[i2]; \ + CLIP_TRIANGLE( e2, e1, e0 ); \ +} while (0) + +#define RENDER_QUAD(i3, i2, i1, i0, pv) \ + CLIP_TRIANGLE(elt[i3], elt[i2], elt[i0]); \ + CLIP_TRIANGLE(elt[i2], elt[i1], elt[i0]) + +#define PRESERVE_TAG +#include "render_tmp.h" + + +static void TAG(fx_init_fastpath) (struct fx_fast_tab * tab) +{ + GLuint i; + + /* Use the render templates to do clipping. + */ + TAG(render_init) (); + for (i = 0; i < GL_POLYGON + 2; i++) + tab->clip[i] = TAG(render_tab)[i]; + + tab->build_vertices = TAG(fx_setup_full); + tab->project_vertices = TAG(fx_project_vertices); + tab->project_clipped_vertices = TAG(fx_project_clipped_vertices); + +#if defined(USE_3DNOW_ASM) + if (gl_x86_cpu_features & GL_CPU_3Dnow) { + extern void TAG(fx_3dnow_project_vertices) (GLfloat * first, + GLfloat * last, + const GLfloat * mat, + GLuint stride); + + extern void TAG(fx_3dnow_project_clipped_vertices) (GLfloat * first, + GLfloat * last, + const GLfloat * + mat, + GLuint stride, + const GLubyte * + mask); + + tab->project_vertices = TAG(fx_3dnow_project_vertices); + tab->project_clipped_vertices = + TAG(fx_3dnow_project_clipped_vertices); + } +#endif +} + +#undef TYPE +#undef TAG +#undef SIZE diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.c b/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.c new file mode 100644 index 000000000..70fb6b00e --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.c @@ -0,0 +1,482 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#include <stdlib.h> +#include <string.h> +#include "glide.h" +#include "fxdrv.h" +#include "fxglidew.h" + + +grStencilFunc_t grStencilFuncPtr = NULL; +grStencilMask_t grStencilMaskPtr = NULL; +grStencilOp_t grStencilOpPtr = NULL; +grBufferClearExt_t grBufferClearExtPtr = NULL; +grColorMaskExt_t grColorMaskExtPtr = NULL; +txImgQuantize_t txImgQuantizePtr = NULL; +txImgDeQuantize_t txImgDequantizeFXT1Ptr = NULL; +txErrorSetCallback_t txErrorSetCallbackPtr = NULL; + +FxI32 +FX_grGetInteger_NoLock(FxU32 pname) +{ + switch (pname) { + case FX_FOG_TABLE_ENTRIES: + case FX_GLIDE_STATE_SIZE: + case FX_LFB_PIXEL_PIPE: + case FX_PENDING_BUFFERSWAPS: + case FX_TEXTURE_ALIGN: + case GR_STATS_PIXELS_DEPTHFUNC_FAIL: + case GR_STATS_PIXELS_IN: + case GR_STATS_PIXELS_OUT: + { + FxI32 result; + FxU32 grname = pname; + grGet(grname, 4, &result); + return result; + } + case FX_ZDEPTH_MAX: + { + FxI32 zvals[2]; + grGet(GR_ZDEPTH_MIN_MAX, 8, zvals); + return zvals[0]; + } + default: + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "Wrong parameter in FX_grGetInteger!\n"); + } + } + + return 0; +} + + +FxI32 +FX_grGetInteger(fxMesaContext fxMesa, FxU32 pname) +{ + int result; + BEGIN_BOARD_LOCK(fxMesa); + result = FX_grGetInteger_NoLock(pname); + END_BOARD_LOCK(fxMesa); + return result; +} + + +const char * +FX_grGetString(fxMesaContext fxMesa, FxU32 pname) +{ + const char *s; + BEGIN_BOARD_LOCK(fxMesa); + s = grGetString(pname); + END_BOARD_LOCK(fxMesa); + return s; +} + + + +/* Wrapper for grColorMask() and grColorMaskExt(). + */ +void +FX_grColorMask(GLcontext *ctx, GLboolean r, GLboolean g, + GLboolean b, GLboolean a) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + BEGIN_BOARD_LOCK(fxMesa); + if (ctx->Visual->RedBits == 8) { + /* 32bpp mode */ + ASSERT(grColorMaskExtPtr); + (*grColorMaskExtPtr)(r, g, b, a); + } + else { + /* 16 bpp mode */ + /* we never have an alpha buffer */ + grColorMask(r || g || b, GL_FALSE); + } + END_BOARD_LOCK(fxMesa); +} + + +/* As above, but pass the mask as an array + */ +void +FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4]) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + BEGIN_BOARD_LOCK(fxMesa); + if (ctx->Visual->RedBits == 8) { + /* 32bpp mode */ + ASSERT(grColorMaskExtPtr); + (*grColorMaskExtPtr)(rgba[RCOMP], rgba[GCOMP], + rgba[BCOMP], rgba[ACOMP]); + } + else { + /* 16 bpp mode */ + /* we never have an alpha buffer */ + grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP], GL_FALSE); + } + END_BOARD_LOCK(fxMesa); +} + + + +FxBool +FX_grLfbLock(fxMesaContext fxMesa, GrLock_t type, GrBuffer_t buffer, + GrLfbWriteMode_t writeMode, GrOriginLocation_t origin, + FxBool pixelPipeline, GrLfbInfo_t * info) +{ + FxBool result; + + BEGIN_BOARD_LOCK(fxMesa); + result = grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info); + END_BOARD_LOCK(fxMesa); + return result; +} + +FxU32 +FX_grTexTextureMemRequired(fxMesaContext fxMesa, FxU32 evenOdd, GrTexInfo * info) +{ + FxU32 result; + + BEGIN_BOARD_LOCK(fxMesa); + result = grTexTextureMemRequired(evenOdd, info); + END_BOARD_LOCK(fxMesa); + return result; +} + +FxU32 +FX_grTexMinAddress(fxMesaContext fxMesa, GrChipID_t tmu) +{ + FxU32 result; + + BEGIN_BOARD_LOCK(fxMesa); + result = grTexMinAddress(tmu); + END_BOARD_LOCK(fxMesa); + return result; +} + +extern FxU32 +FX_grTexMaxAddress(fxMesaContext fxMesa, GrChipID_t tmu) +{ + FxU32 result; + + BEGIN_BOARD_LOCK(fxMesa); + result = grTexMaxAddress(tmu); + END_BOARD_LOCK(fxMesa); + return result; +} + + +#if defined(FX_GLIDE3) + +void +FX_grGammaCorrectionValue(float val) +{ + (void) val; +/* ToDo */ +} + +int +FX_getFogTableSize(fxMesaContext fxMesa) +{ + int result; + BEGIN_BOARD_LOCK(fxMesa); + grGet(GR_FOG_TABLE_ENTRIES, sizeof(int), (void *) &result); + END_BOARD_LOCK(fxMesa); + return result; +} + +int +FX_getGrStateSize(fxMesaContext fxMesa) +{ + int result; + BEGIN_BOARD_LOCK(fxMesa); + grGet(GR_GLIDE_STATE_SIZE, sizeof(int), (void *) &result); + END_BOARD_LOCK(fxMesa); + return result; +} + + +void +FX_grGlideGetVersion(fxMesaContext fxMesa, char *buf) +{ + BEGIN_BOARD_LOCK(fxMesa); + strcpy(buf, grGetString(GR_VERSION)); + END_BOARD_LOCK(fxMesa); +} + +void +FX_grSstPerfStats(GrSstPerfStats_t * st) +{ + FxI32 n; + grGet(GR_STATS_PIXELS_IN, 4, &n); + st->pixelsIn = n; + grGet(GR_STATS_PIXELS_CHROMA_FAIL, 4, &n); + st->chromaFail = n; + grGet(GR_STATS_PIXELS_DEPTHFUNC_FAIL, 4, &n); + st->zFuncFail = n; + grGet(GR_STATS_PIXELS_AFUNC_FAIL, 4, &n); + st->aFuncFail = n; + grGet(GR_STATS_PIXELS_OUT, 4, &n); + st->pixelsOut = n; +} + +void +FX_grAADrawLine(fxMesaContext fxMesa, GrVertex * a, GrVertex * b) +{ + /* ToDo */ + BEGIN_CLIP_LOOP(fxMesa); + grDrawLine(a, b); + END_CLIP_LOOP(fxMesa); +} + +void +FX_grAADrawPoint(fxMesaContext fxMesa, GrVertex * a) +{ + BEGIN_CLIP_LOOP(fxMesa); + grDrawPoint(a); + END_CLIP_LOOP(fxMesa); +} + +void +FX_grDrawPolygonVertexList(fxMesaContext fxMesa, int n, GrVertex * verts) +{ + BEGIN_CLIP_LOOP(fxMesa); + grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex)); + END_CLIP_LOOP(fxMesa); +} + +#if FX_USE_PARGB +void +FX_setupGrVertexLayout(void) +{ + BEGIN_BOARD_LOCK(fxMesa); + grReset(GR_VERTEX_PARAMETER); + + grCoordinateSpace(GR_WINDOW_COORDS); + grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_PARGB, GR_VERTEX_PARGB_OFFSET << 2, + GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, + GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, + GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + END_BOARD_LOCK(fxMesa); +} +#else /* FX_USE_PARGB */ +void +FX_setupGrVertexLayout(fxMesaContext fxMesa) +{ + BEGIN_BOARD_LOCK(fxMesa); + grReset(GR_VERTEX_PARAMETER); + + grCoordinateSpace(GR_WINDOW_COORDS); + grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, + GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, + GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + END_BOARD_LOCK(fxMesa); +} +#endif + +void +FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask) +{ + switch (hintType) { + case GR_HINT_STWHINT: + { + if (hintMask & GR_STWHINT_W_DIFF_TMU0) + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, + GR_PARAM_ENABLE); + else + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, + GR_PARAM_DISABLE); + + if (hintMask & GR_STWHINT_ST_DIFF_TMU1) + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, + GR_PARAM_ENABLE); + else + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + + if (hintMask & GR_STWHINT_W_DIFF_TMU1) + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, + GR_PARAM_ENABLE); + else + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + + } + } +} + +void +FX_grHints(fxMesaContext fxMesa, GrHint_t hintType, FxU32 hintMask) +{ + BEGIN_BOARD_LOCK(fxMesa); + FX_grHints_NoLock(hintType, hintMask); + END_BOARD_LOCK(fxMesa); +} + +int +FX_grSstQueryHardware(fxMesaContext fxMesa, GrHwConfiguration * config) +{ + int i, j; + int numFB; + + BEGIN_BOARD_LOCK(fxMesa); + grGet(GR_NUM_BOARDS, 4, (void *) &(config->num_sst)); + if (config->num_sst == 0) + return 0; + for (i = 0; i < config->num_sst; i++) { + config->SSTs[i].type = GR_SSTTYPE_VOODOO; + grSstSelect(i); + grGet(GR_MEMORY_FB, 4, + (void *) &(config->SSTs[i].sstBoard.VoodooConfig.fbRam)); + config->SSTs[i].sstBoard.VoodooConfig.fbRam /= 1024 * 1024; + + grGet(GR_NUM_TMU, 4, + (void *) &(config->SSTs[i].sstBoard.VoodooConfig.nTexelfx)); + + + grGet(GR_NUM_FB, 4, (void *) &numFB); + if (numFB > 1) + config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXTRUE; + else + config->SSTs[i].sstBoard.VoodooConfig.sliDetect = FXFALSE; + for (j = 0; j < config->SSTs[i].sstBoard.VoodooConfig.nTexelfx; j++) { + grGet(GR_MEMORY_TMU, 4, + (void *) &(config->SSTs[i].sstBoard. + VoodooConfig.tmuConfig[j].tmuRam)); + config->SSTs[i].sstBoard.VoodooConfig. + tmuConfig[j].tmuRam /= 1024 * 1024; + } + } + END_BOARD_LOCK(fxMesa); + return 1; +} + +#else + +int +FX_grSstScreenWidth() +{ + int i; + BEGIN_BOARD_LOCK(fxMesa); + i = grSstScreenWidth(); + END_BOARD_LOCK(fxMesa); + return i; +} + +int +FX_grSstScreenHeight() +{ + int i; + BEGIN_BOARD_LOCK(fxMesa); + i = grSstScreenHeight(); + END_BOARD_LOCK(fxMesa); + return i; +} + +int +FX_grSstQueryHardware(GrHwConfiguration * c) +{ + int i; + BEGIN_BOARD_LOCK(fxMesa); + i = grSstQueryHardware(c); + END_BOARD_LOCK(fxMesa); + return i; +} + + +#endif /* FX_GLIDE3 */ + +/* It appears to me that this function is needed either way. */ +FX_GrContext_t +FX_grSstWinOpen(fxMesaContext fxMesa, + FxU32 hWnd, + GrScreenResolution_t screen_resolution, + GrScreenRefresh_t refresh_rate, + GrColorFormat_t color_format, + GrOriginLocation_t origin_location, + int nColBuffers, int nAuxBuffers) +{ + FX_GrContext_t i; + BEGIN_BOARD_LOCK(fxMesa); + i = grSstWinOpen(hWnd, + screen_resolution, + refresh_rate, + color_format, origin_location, nColBuffers, nAuxBuffers); + + /* + fprintf(stderr, + "grSstWinOpen( win %d res %d ref %d fmt %d\n" + " org %d ncol %d naux %d )\n" + " ==> %d\n", + hWnd, + screen_resolution, + refresh_rate, + color_format, + origin_location, + nColBuffers, + nAuxBuffers, + i); + */ + END_BOARD_LOCK(fxMesa); + return i; +} + diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.h b/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.h new file mode 100644 index 000000000..27c762124 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxglidew.h @@ -0,0 +1,986 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#ifndef __FX_GLIDE_WARPER__ +#define __FX_GLIDE_WARPER__ + +#include <glide.h> +#include <g3ext.h> + +typedef struct tfxMesaContext *fxMesaContext; + + +/* + * These are glide extension definitions. These are not + * defined in glide.h. They should really be defined in + * g3ext.h, but they are not. + */ +#if 0 +FX_ENTRY void FX_CALL +grStencilFunc(GrCmpFnc_t fnc, GrStencil_t ref, GrStencil_t mask); + +FX_ENTRY void FX_CALL grStencilMask(GrStencil_t write_mask); + +FX_ENTRY void FX_CALL +grStencilOp(GrStencilOp_t stencil_fail, + GrStencilOp_t depth_fail, GrStencilOp_t depth_pass); + +FX_ENTRY void FX_CALL +grBufferClearExt(GrColor_t color, + GrAlpha_t alpha, FxU32 depth, GrStencil_t stencil); + +FX_ENTRY void FX_CALL +grColorMaskExt(FxBool r, FxBool g, FxBool b, FxBool a); +#endif + + +typedef void (*grStencilFunc_t) (GrCmpFnc_t fnc, GrStencil_t ref, + GrStencil_t mask); +typedef void (*grStencilMask_t) (GrStencil_t write_mask); +typedef void (*grStencilOp_t) (GrStencilOp_t stencil_fail, + GrStencilOp_t depth_fail, + GrStencilOp_t depth_pass); +typedef void (*grBufferClearExt_t) (GrColor_t color, GrAlpha_t alpha, + FxU32 depth, GrStencil_t stencil); +typedef void (*grColorMaskExt_t) (FxBool r, FxBool g, FxBool b, FxBool a); +/* + * These are functions to compress and decompress images. + * The types of the first and second parameters are not exactly + * right. The texus library declares them to be "char *", not + * "void *". However, "void *" is more correct, and more convenient. + */ +typedef void (*txImgQuantize_t) (void *dst, void *src, + int w, int h, + FxU32 format, FxU32 dither); +typedef void (*txImgDeQuantize_t)(void *dst, void *src, + int w, int h); +/* + * These next three declarations should probably be taken from + * texus.h. However, there are duplicate declarations in g3ext.h + * and texus.h which make it hard to include them both. + */ +typedef void (*TxErrorCallbackFnc_t)( const char *string, FxBool fatal ); +typedef void (*txErrorSetCallback_t)(TxErrorCallbackFnc_t fnc, + TxErrorCallbackFnc_t *old_fnc); + +extern grStencilFunc_t grStencilFuncPtr; +extern grStencilMask_t grStencilMaskPtr; +extern grStencilOp_t grStencilOpPtr; +extern grBufferClearExt_t grBufferClearExtPtr; +extern grColorMaskExt_t grColorMaskExtPtr; +extern txImgQuantize_t txImgQuantizePtr; +extern txImgDeQuantize_t txImgDequantizeFXT1Ptr; +extern txErrorSetCallback_t txErrorSetCallbackPtr; + +FX_ENTRY void FX_CALL grEnable(GrEnableMode_t mode); + +FX_ENTRY void FX_CALL grEnable(GrEnableMode_t mode); +/* + * General context: + */ +#if !defined(FX_GLIDE3) +typedef FxU32 FX_GrContext_t; /* Not used in Glide2 */ +#else +typedef GrContext_t FX_GrContext_t; +#endif + +/* + * Glide3 emulation on Glide2: + */ +#if !defined(FX_GLIDE3) + /* Constanst for FX_grGetInteger( ) */ +#define FX_FOG_TABLE_ENTRIES 0x0004 /* The number of entries in the hardware fog table. */ +#define FX_GLIDE_STATE_SIZE 0x0006 /* Size of buffer, in bytes, needed to save Glide state. */ +#define FX_LFB_PIXEL_PIPE 0x0009 /* 1 if LFB writes can go through the 3D pixel pipe. */ +#define FX_PENDING_BUFFERSWAPS 0x0014 /* The number of buffer swaps pending. */ +#define FX_TEXTURE_ALIGN 0x0024 /* The required alignment for textures */ +#else +#define FX_FOG_TABLE_ENTRIES GR_FOG_TABLE_ENTRIES +#define FX_GLIDE_STATE_SIZE GR_GLIDE_STATE_SIZE +#define FX_LFB_PIXEL_PIPE GR_LFB_PIXEL_PIPE +#define FX_PENDING_BUFFERSWAPS GR_PENDING_BUFFERSWAPS +#define FX_TEXTURE_ALIGN GR_TEXTURE_ALIGN +#endif +#define FX_ZDEPTH_MAX 0x100 + +/* + * General warper functions for Glide2/Glide3: + */ +extern FxI32 FX_grGetInteger_NoLock(FxU32 pname); +extern FxI32 FX_grGetInteger(fxMesaContext fxMesa, FxU32 pname); + +extern const char *FX_grGetString(fxMesaContext fxMesa, FxU32 pname); + +/* + * Glide2 emulation on Glide3: + */ +#if defined(FX_GLIDE3) + +#define GR_ASPECT_1x1 GR_ASPECT_LOG2_1x1 +#define GR_ASPECT_2x1 GR_ASPECT_LOG2_2x1 +#define GR_ASPECT_4x1 GR_ASPECT_LOG2_4x1 +#define GR_ASPECT_8x1 GR_ASPECT_LOG2_8x1 +#define GR_ASPECT_1x2 GR_ASPECT_LOG2_1x2 +#define GR_ASPECT_1x4 GR_ASPECT_LOG2_1x4 +#define GR_ASPECT_1x8 GR_ASPECT_LOG2_1x8 + +#define GR_LOD_256 GR_LOD_LOG2_256 +#define GR_LOD_128 GR_LOD_LOG2_128 +#define GR_LOD_64 GR_LOD_LOG2_64 +#define GR_LOD_32 GR_LOD_LOG2_32 +#define GR_LOD_16 GR_LOD_LOG2_16 +#define GR_LOD_8 GR_LOD_LOG2_8 +#define GR_LOD_4 GR_LOD_LOG2_4 +#define GR_LOD_2 GR_LOD_LOG2_2 +#define GR_LOD_1 GR_LOD_LOG2_1 + +#define GR_FOG_WITH_TABLE GR_FOG_WITH_TABLE_ON_Q + +typedef int GrSstType; + +#define MAX_NUM_SST 4 + +#define GR_SSTTYPE_VOODOO 0 +#define GR_SSTTYPE_SST96 1 +#define GR_SSTTYPE_AT3D 2 +#define GR_SSTTYPE_Voodoo2 3 + +typedef struct GrTMUConfig_St +{ + int tmuRev; /* Rev of Texelfx chip */ + int tmuRam; /* 1, 2, or 4 MB */ +} +GrTMUConfig_t; + +typedef struct GrVoodooConfig_St +{ + int fbRam; /* 1, 2, or 4 MB */ + int fbiRev; /* Rev of Pixelfx chip */ + int nTexelfx; /* How many texelFX chips are there? */ + FxBool sliDetect; /* Is it a scan-line interleaved board? */ + GrTMUConfig_t tmuConfig[GLIDE_NUM_TMU]; /* Configuration of the Texelfx chips */ +} +GrVoodooConfig_t; + +typedef struct GrSst96Config_St +{ + int fbRam; /* How much? */ + int nTexelfx; + GrTMUConfig_t tmuConfig; +} +GrSst96Config_t; + +typedef GrVoodooConfig_t GrVoodoo2Config_t; + +typedef struct GrAT3DConfig_St +{ + int rev; +} +GrAT3DConfig_t; + +typedef struct +{ + int num_sst; /* # of HW units in the system */ + struct + { + GrSstType type; /* Which hardware is it? */ + union SstBoard_u + { + GrVoodooConfig_t VoodooConfig; + GrSst96Config_t SST96Config; + GrAT3DConfig_t AT3DConfig; + GrVoodoo2Config_t Voodoo2Config; + } + sstBoard; + } + SSTs[MAX_NUM_SST]; /* configuration for each board */ +} +GrHwConfiguration; + +typedef FxU32 GrHint_t; +#define GR_HINTTYPE_MIN 0 +#define GR_HINT_STWHINT 0 + +typedef FxU32 GrSTWHint_t; +#define GR_STWHINT_W_DIFF_FBI FXBIT(0) +#define GR_STWHINT_W_DIFF_TMU0 FXBIT(1) +#define GR_STWHINT_ST_DIFF_TMU0 FXBIT(2) +#define GR_STWHINT_W_DIFF_TMU1 FXBIT(3) +#define GR_STWHINT_ST_DIFF_TMU1 FXBIT(4) +#define GR_STWHINT_W_DIFF_TMU2 FXBIT(5) +#define GR_STWHINT_ST_DIFF_TMU2 FXBIT(6) + +#define GR_CONTROL_ACTIVATE 1 +#define GR_CONTROL_DEACTIVATE 0 + +#define GrState void + +/* +** move the vertex layout defintion to application +*/ +typedef struct +{ + float sow; /* s texture ordinate (s over w) */ + float tow; /* t texture ordinate (t over w) */ + float oow; /* 1/w (used mipmapping - really 0xfff/w) */ +} +GrTmuVertex; + + +#if FX_USE_PARGB + +typedef struct +{ + float x, y; /* X and Y in screen space */ + float ooz; /* 65535/Z (used for Z-buffering) */ + float oow; /* 1/W (used for W-buffering, texturing) */ + FxU32 argb; /* R, G, B, A [0..255.0] */ + GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; + float z; /* Z is ignored */ +} +GrVertex; + +#define GR_VERTEX_X_OFFSET 0 +#define GR_VERTEX_Y_OFFSET 1 +#define GR_VERTEX_OOZ_OFFSET 2 +#define GR_VERTEX_OOW_OFFSET 3 +#define GR_VERTEX_PARGB_OFFSET 4 +#define GR_VERTEX_SOW_TMU0_OFFSET 5 +#define GR_VERTEX_TOW_TMU0_OFFSET 6 +#define GR_VERTEX_OOW_TMU0_OFFSET 7 +#define GR_VERTEX_SOW_TMU1_OFFSET 8 +#define GR_VERTEX_TOW_TMU1_OFFSET 9 +#define GR_VERTEX_OOW_TMU1_OFFSET 10 +#define GR_VERTEX_Z_OFFSET 11 + +#define GET_PARGB(v) ((FxU32*)(v))[GR_VERTEX_PARGB_OFFSET] +/* GET_PA: returns the alpha component */ +#if GLIDE_ENDIAN == GLIDE_ENDIAN_BIG +#define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4] +#else +#define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+3] +#endif +#define MESACOLOR2PARGB(c) (c[ACOMP] << 24 | c[GCOMP] << 16 | c[GCOMP] << 8 | c[BCOMP]) +#define PACK_4F_ARGB(dest,a,r,g,b) { \ + const GLuint cr = (int)r; \ + const GLuint cg = (int)g; \ + const GLuint ca = (int)a; \ + const GLuint cb = (int)b; \ + dest = ca << 24 | cr << 16 | cg << 8 | cb; \ + } + +#else /* FX_USE_PARGB */ + +typedef struct +{ + float x, y, z; /* X, Y, and Z of scrn space -- Z is ignored */ + float r, g, b; /* R, G, B, ([0..255.0]) */ + float ooz; /* 65535/Z (used for Z-buffering) */ + float a; /* Alpha [0..255.0] */ + float oow; /* 1/W (used for W-buffering, texturing) */ + GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; +} +GrVertex; + +#define GR_VERTEX_X_OFFSET 0 +#define GR_VERTEX_Y_OFFSET 1 +#define GR_VERTEX_Z_OFFSET 2 +#define GR_VERTEX_R_OFFSET 3 +#define GR_VERTEX_G_OFFSET 4 +#define GR_VERTEX_B_OFFSET 5 +#define GR_VERTEX_OOZ_OFFSET 6 +#define GR_VERTEX_A_OFFSET 7 +#define GR_VERTEX_OOW_OFFSET 8 +#define GR_VERTEX_SOW_TMU0_OFFSET 9 +#define GR_VERTEX_TOW_TMU0_OFFSET 10 +#define GR_VERTEX_OOW_TMU0_OFFSET 11 +#define GR_VERTEX_SOW_TMU1_OFFSET 12 +#define GR_VERTEX_TOW_TMU1_OFFSET 13 +#define GR_VERTEX_OOW_TMU1_OFFSET 14 +#endif /* FX_USE_PARGB */ + +#endif + +/* + * Glide2 functions for Glide3 + */ +#if defined(FX_GLIDE3) + +#define FX_grTexDownloadTable(fxMesa, TMU, type, data) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexDownloadTable(type,data); \ + END_BOARD_LOCK(fxMesa); \ + } while (0); + +#define FX_grTexDownloadTable_NoLock(TMU, type, data) \ + grTexDownloadTable(type, data) + +#else +#define FX_grTexDownloadTable(TMU,type,data) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grTexDownloadTable(TMU,type,data); \ + END_BOARD_LOCK(); \ + } while (0); +#define FX_grTexDownloadTable_NoLock grTexDownloadTable +#endif + +/* + * Flush + */ +#if defined(FX_GLIDE3) +#define FX_grFlush(fxMesa) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grFlush(); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) +#else +#define FX_grFlush(fxMesa) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grSstIdle(); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) +#endif + +#define FX_grFinish(fxMesa) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grFinish(); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +/* + * Write region: ToDo possible exploit the PixelPipe parameter. + */ +#if defined(FX_GLIDE3) + +#define FX_grLfbWriteRegion(fxMesa,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,FXFALSE,src_stride,src_data); \ + END_BOARD_LOCK(fxMesa); \ + } while(0) + +#else + +#define FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data); \ + END_BOARD_LOCK(); \ + } while (0) +#endif + +/* + * Read region + */ +#define FX_grLfbReadRegion(fxMesa,src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grLfbReadRegion(src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data); \ + END_BOARD_LOCK(fxMesa); \ + } while (0); + +/* + * Draw triangle + */ +#define FX_grDrawTriangle_NoLock(a,b,c) grDrawTriangle(a,b,c) +#define FX_grDrawTriangle(fxMesa, a,b,c) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + FX_grDrawTriangle_NoLock(a,b,c); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +/* + * For Lod/LodLog2 conversion. + */ +#if defined(FX_GLIDE3) +#define FX_largeLodLog2(info) (info).largeLodLog2 +#else +#define FX_largeLodLog2(info) (info).largeLod +#endif + +#if defined(FX_GLIDE3) +#define FX_aspectRatioLog2(info) (info).aspectRatioLog2 +#else +#define FX_aspectRatioLog2(info) (info).aspectRatio +#endif + +#if defined(FX_GLIDE3) +#define FX_smallLodLog2(info) (info).smallLodLog2 +#else +#define FX_smallLodLog2(info) (info).smallLod +#endif + +#if defined(FX_GLIDE3) +#define FX_lodToValue(val) ((int)(GR_LOD_256-val)) +#else +#define FX_lodToValue(val) ((int)(val)) +#endif + +#if defined(FX_GLIDE3) +#define FX_largeLodValue(info) ((int)(GR_LOD_256-(info).largeLodLog2)) +#else +#define FX_largeLodValue(info) ((int)(info).largeLod) +#endif +#define FX_largeLodValue_NoLock FX_largeLodValue + +#if defined(FX_GLIDE3) +#define FX_smallLodValue(info) ((int)(GR_LOD_256-(info).smallLodLog2)) +#else +#define FX_smallLodValue(info) ((int)(info).smallLod) +#endif +#define FX_smallLodValue_NoLock FX_smallLodValue + +#if defined(FX_GLIDE3) +#define FX_valueToLod(val) ((GrLOD_t)(GR_LOD_256-val)) +#else +#define FX_valueToLod(val) ((GrLOD_t)(val)) +#endif + + + +/* + * Version string. + */ +#if defined(FX_GLIDE3) +extern void FX_grGlideGetVersion(fxMesaContext fxMesa, char *buf); +#else +#define FX_grGlideGetVersion(b) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grGlideGetVersion(b); \ + END_BOARD_LOCK(); \ + } while (0) +#endif + +/* + * Performance statistics + */ +#if defined(FX_GLIDE3) +extern void FX_grSstPerfStats(GrSstPerfStats_t * st); +#else +#define FX_grSstPerfStats(s) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grSstPerfStats(s); \ + END_BOARD_LOCK(); \ + } while (0) +#endif + +/* + * Hardware Query + */ +extern int FX_grSstQueryHardware(fxMesaContext fxMesa, + GrHwConfiguration * config); + +/* + * GrHints + */ +#if defined(FX_GLIDE3) +extern void FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask); +extern void FX_grHints(fxMesaContext fxMesa, GrHint_t hintType, FxU32 hintMask); +#else +#define FX_grHints(t,m) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grHints(t, m); \ + END_BOARD_LOCK(); \ + } while(0) +#define FX_grHints_NoLock grHints +#endif +/* + * Antialiashed line+point drawing. + */ +#if defined(FX_GLIDE3) +extern void FX_grAADrawLine(fxMesaContext fxMesa, GrVertex * a, GrVertex * b); +#else +#define FX_grAADrawLine(a,b) \ + do { \ + BEGIN_CLIP_LOOP(); \ + grAADrawLine(a,b); \ + END_CLIP_LOOP(); \ + } while (0) +#endif + +#if defined(FX_GLIDE3) +extern void FX_grAADrawPoint(fxMesaContext fxMesa, GrVertex * a); +#else +#define FX_grAADrawPoint(a) \ + do { \ + BEGIN_CLIP_LOOP(); \ + grAADrawPoint(a); \ + END_CLIP_LOOP(); \ + } while (0) +#endif + +/* + * Needed for Glide3 only, to set up Glide2 compatible vertex layout. + */ +#if defined(FX_GLIDE3) +extern void FX_setupGrVertexLayout(fxMesaContext fxMesa); +#else +#define FX_setupGrVertexLayout() do {} while (0) +#endif + + +/* + * grGammaCorrectionValue + */ +#if defined(FX_GLIDE3) +extern void FX_grGammaCorrectionValue(float val); +#else +#define FX_grGammaCorrectionValue(v) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grGammaCorrectionValue(v) \ + END_BOARD_LOCK(); \ + } while (0) +#endif + +#if defined(FX_GLIDE3) +#define FX_grSstWinClose(fxMesa, w) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grSstWinClose(w); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) +#else +#define FX_grSstWinClose(w) \ + do { \ + BEGIN_BOARD_LOCK(); \ + grSstWinClose(); \ + END_BOARD_LOCK(); \ + } while (0) +#endif + + +extern FX_GrContext_t FX_grSstWinOpen(fxMesaContext fxMesa, + FxU32 hWnd, + GrScreenResolution_t screen_resolution, + GrScreenRefresh_t refresh_rate, + GrColorFormat_t color_format, + GrOriginLocation_t origin_location, + int nColBuffers, int nAuxBuffers); + + +#define FX_grDrawLine_NoLock(v1, v2) grDrawLine(v1, v2) +#define FX_grDrawLine(fxMesa, v1, v2) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + FX_grDrawLine_NoLock(v1, v2); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grDrawPoint_NoLock(p) grDrawPoint(p) +#define FX_grDrawPoint(fxMesa, p) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + FX_grDrawPoint_NoLock(p); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#if defined(FX_GLIDE3) +extern void FX_grDrawPolygonVertexList(fxMesaContext fxMesa, + int n, GrVertex * v); +#else +#define FX_grDrawPolygonVertexList(n, v) \ + do { \ + BEGIN_CLIP_LOOP(); \ + grDrawPolygonVertexList(n, v); \ + END_CLIP_LOOP(); \ + } while (0) +#endif + +#define FX_grDitherMode(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDitherMode(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grRenderBuffer(fxMesa, b) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grRenderBuffer(b); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grBufferClear(fxMesa, c, a, d) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grBufferClear(c, a, d); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grBufferClearExt(fxMesa, c, a, d, s) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + (*grBufferClearExtPtr)(c, a, d, s); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +/* + * Enable/Disable + */ +#define FX_grEnable(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grEnable(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grDisable(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDisable(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +/* + * Stencil operations. + */ +#define FX_grStencilFunc(fxMesa, fnc, ref, mask) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + (*grStencilFuncPtr)((fnc), (ref), (mask)); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grStencilMask(fxMesa, write_mask) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + (*grStencilMaskPtr)(write_mask); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + + +#define FX_grStencilOp(fxMesa, stencil_fail, depth_fail, depth_pass) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + (*grStencilOpPtr)((stencil_fail), (depth_fail), (depth_pass)); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grDepthMask(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDepthMask(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + + +extern void FX_grColorMask(GLcontext *ctx, GLboolean r, GLboolean g, + GLboolean b, GLboolean a); + +extern void FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4]); + +extern FxBool FX_grLfbLock(fxMesaContext fxMesa, + GrLock_t type, GrBuffer_t buffer, + GrLfbWriteMode_t writeMode, + GrOriginLocation_t origin, FxBool pixelPipeline, + GrLfbInfo_t * info); + +#define FX_grLfbUnlock(fxMesa, t, b) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grLfbUnlock(t, b); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grConstantColorValue(fxMesa, v) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grConstantColorValue(v); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grConstantColorValue_NoLock grConstantColorValue + +#define FX_grAADrawTriangle(fxMesa, a, b, c, ab, bc, ca) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grAADrawTriangle(a, b, c, ab, bc, ca); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grAlphaBlendFunction(rs, rd, as, ad) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grAlphaBlendFunction(rs, rd, as, ad); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grAlphaCombine(func, fact, loc, oth, inv) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grAlphaCombine(func, fact, loc, oth, inv); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grAlphaCombine_NoLock grAlphaCombine + +#define FX_grAlphaTestFunction(fxMesa, f) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grAlphaTestFunction(f); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grAlphaTestReferenceValue(fxMesa, v) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grAlphaTestReferenceValue(v); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grClipWindow(fxMesa, minx, miny, maxx, maxy) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grClipWindow(minx, miny, maxx, maxy); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grClipWindow_NoLock grClipWindow + +#define FX_grColorCombine(fxMesa, func, fact, loc, oth, inv) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grColorCombine(func, fact, loc, oth, inv); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grColorCombine_NoLock grColorCombine + +#define FX_grCullMode(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grCullMode(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grDepthBiasLevel(fxMesa, lev) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDepthBiasLevel(lev); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grDepthBufferFunction(fxMesa, func) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDepthBufferFunction(func); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grFogColorValue(fxMesa, c) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grFogColorValue(c); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grFogMode(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grFogMode(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grFogTable(fxMesa, t)\ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grFogTable(t); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexClampMode(fxMesa, t, sc, tc) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexClampMode(t, sc, tc); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexClampMode_NoLock grTexClampMode + +#define FX_grTexCombine(fxMesa, t, rfunc, rfact, afunc, afact, rinv, ainv) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexCombine(t, rfunc, rfact, afunc, afact, rinv, ainv); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexCombine_NoLock grTexCombine + +#define FX_grTexDownloadMipMapLevel(fxMesa, t, sa, tlod, llod, ar, f, eo, d) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexDownloadMipMapLevel(t, sa, tlod, llod, ar, f, eo, d); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexDownloadMipMapLevel_NoLock grTexDownloadMipMapLevel + +#define FX_grTexDownloadMipMapLevelPartial(fxMesa, t, sa, tlod, llod, ar, f, eo, d, s, e); \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexDownloadMipMapLevelPartial(t, sa, tlod, llod, ar, f, eo, d, s, e); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexFilterMode(fxMesa, t, minf, magf) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexFilterMode(t, minf, magf); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexFilterMode_NoLock grTexFilterMode + +extern FxU32 FX_grTexMinAddress(fxMesaContext fxMesa, GrChipID_t tmu); +extern FxU32 FX_grTexMaxAddress(fxMesaContext fxMesa, GrChipID_t tmu); + +#define FX_grTexMipMapMode(t, m, lod) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexMipMapMode(t, m, lod); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexMipMapMode_NoLock grTexMipMapMode + +#define FX_grTexSource(t, sa, eo, i) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexSource(t, sa, eo, i); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexSource_NoLock grTexSource + +extern FxU32 FX_grTexTextureMemRequired(fxMesaContext fxMesa, + FxU32 evenOdd, GrTexInfo * info); + +#define FX_grTexTextureMemRequired_NoLock grTexTextureMemRequired + +#define FX_grGlideGetState(fxMesa, s) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grGlideGetState(s); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) +#define FX_grGlideGetState_NoLock(s) grGlideGetState(s); + +#define FX_grDRIBufferSwap(fxMesa, i) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDRIBufferSwap(i); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grSstSelect(fxMesa, b) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grSstSelect(b); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grSstSelect_NoLock grSstSelect + +#define FX_grGlideSetState(fxMesa, s) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grGlideSetState(s); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) +#define FX_grGlideSetState_NoLock(s) grGlideSetState(s); + +#define FX_grDepthBufferMode(fxMesa, m) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grDepthBufferMode(m); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grLfbWriteColorFormat(fxMesa, f) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grLfbWriteColorFormat(f); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grDrawVertexArray(fxMesa, m, c, p) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grDrawVertexArray(m, c, p); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grGlideShutdown(fxMesa) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grGlideShutdown(); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grTexLodBiasValue_NoLock(t, v) grTexLodBiasValue(t, v) + +#define FX_grTexLodBiasValue(t, v) \ + do { \ + BEGIN_BOARD_LOCK(fxMesa); \ + grTexLodBiasValue(t, v); \ + END_BOARD_LOCK(fxMesa); \ + } while (0) + +#define FX_grGlideInit_NoLock grGlideInit +#define FX_grSstWinOpen_NoLock grSstWinOpen + +extern int FX_getFogTableSize(fxMesaContext fxMesa); + +extern int FX_getGrStateSize(fxMesaContext fxMesa); + +#endif /* __FX_GLIDE_WARPER__ */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c b/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c new file mode 100644 index 000000000..eb286e848 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c @@ -0,0 +1,292 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#include "fxdrv.h" +#include "fxcva.h" +#include "fxpipeline.h" +#include "vbindirect.h" + + +/* We don't handle texcoord-4 in the safe clip routines - maybe we should. + */ +static void +fxDDRenderElements(struct vertex_buffer *VB) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + if (fxMesa->render_index != 0 || + ((ctx->Texture.ReallyEnabled & 0xf) && VB->TexCoordPtr[0]->size > 2) + || ((ctx->Texture.ReallyEnabled & 0xf0) + && VB->TexCoordPtr[1]->size > 2) || (VB->ClipPtr->size != 4)) /* Brokes clipping otherwise */ + gl_render_elts(VB); + else + fxDDRenderElementsDirect(VB); +} + +static void +fxDDCheckRenderVBIndirect(GLcontext * ctx, struct gl_pipeline_stage *d) +{ + d->type = 0; + + if ((ctx->IndirectTriangles & DD_SW_SETUP) == 0 && + ctx->Driver.MultipassFunc == 0) { + d->type = PIPE_IMMEDIATE; + d->inputs = VERT_SETUP_FULL | VERT_ELT | VERT_PRECALC_DATA; + } +} + +static void +fxDDRenderVBIndirect(struct vertex_buffer *VB) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + struct vertex_buffer *cvaVB = ctx->CVA.VB; + + if (fxMesa->render_index != 0 || ((ctx->Texture.ReallyEnabled & 0xf) + && cvaVB->TexCoordPtr[0]->size > 2) + || ((ctx->Texture.ReallyEnabled & 0xf0) + && cvaVB->TexCoordPtr[1]->size > 2) || (VB->ClipPtr->size != 4)) /* Brokes clipping otherwise */ + gl_render_vb_indirect(VB); + else + fxDDRenderVBIndirectDirect(VB); +} + + +static void +fxDDRenderVB(struct vertex_buffer *VB) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + if ((fxMesa->render_index != 0) || + ((ctx->Texture.ReallyEnabled & 0xf) && VB->TexCoordPtr[0]->size > 2) + || ((ctx->Texture.ReallyEnabled & 0xf0) + && VB->TexCoordPtr[1]->size > 2)) + gl_render_vb(VB); + else + fxDDDoRenderVB(VB); +} + + + + +/* This sort of driver-based reconfiguration of the pipeline could be + * used to support accelerated transformation and lighting on capable + * hardware. + * + */ +GLuint +fxDDRegisterPipelineStages(struct gl_pipeline_stage *out, + const struct gl_pipeline_stage *in, GLuint nr) +{ + GLuint i, o; + + for (i = o = 0; i < nr; i++) { + switch (in[i].ops) { + case PIPE_OP_RAST_SETUP_1 | PIPE_OP_RENDER: + out[o] = in[i]; + out[o].state_change = NEW_CLIENT_STATE; + out[o].check = fxDDCheckMergeAndRender; + out[o].run = fxDDMergeAndRender; + o++; + break; + case PIPE_OP_RAST_SETUP_0: + out[o] = in[i]; + out[o].cva_state_change = + NEW_LIGHTING | NEW_TEXTURING | NEW_RASTER_OPS; + out[o].state_change = ~0; + out[o].check = fxDDCheckPartialRasterSetup; + out[o].run = fxDDPartialRasterSetup; + o++; + break; + case PIPE_OP_RAST_SETUP_0 | PIPE_OP_RAST_SETUP_1: + out[o] = in[i]; + out[o].run = fxDDDoRasterSetup; + o++; + break; + case PIPE_OP_RENDER: + out[o] = in[i]; + if (in[i].run == gl_render_elts) { + out[o].run = fxDDRenderElements; + } + else if (in[i].run == gl_render_vb_indirect) { + out[o].check = fxDDCheckRenderVBIndirect; + out[o].run = fxDDRenderVBIndirect; + } + else if (in[i].run == gl_render_vb) { + out[o].run = fxDDRenderVB; + } + + o++; + break; + default: + out[o++] = in[i]; + break; + } + } + + return o; +} + +#define ILLEGAL_ENABLES (TEXTURE0_3D| \ + TEXTURE1_3D| \ + ENABLE_TEXMAT0 | \ + ENABLE_TEXMAT1 | \ + ENABLE_TEXGEN0 | \ + ENABLE_TEXGEN1 | \ + ENABLE_USERCLIP | \ + ENABLE_LIGHT | \ + ENABLE_FOG) + + + +/* Because this is slotted in by the OptimizePipeline function, most + * of the information here is just for gl_print_pipeline(). Only the + * run member is required. + */ +static struct gl_pipeline_stage fx_fast_stage = { + "FX combined vertex transform, setup and rasterization stage", + PIPE_OP_VERT_XFORM | PIPE_OP_RAST_SETUP_0 | PIPE_OP_RAST_SETUP_1 | + PIPE_OP_RENDER, + PIPE_PRECALC, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* never called */ + fxDDFastPath +}; + + + + +/* Better than optimizing the pipeline, we can do the whole build very + * quickly with the aid of a new flags member. + */ +GLboolean +fxDDBuildPrecalcPipeline(GLcontext * ctx) +{ + struct gl_pipeline *pipe = &ctx->CVA.pre; + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + + if (fxMesa->is_in_hardware && + fxMesa->render_index == 0 && + (ctx->Enabled & ILLEGAL_ENABLES) == 0 && + (ctx->Array.Flags & (VERT_OBJ_234 | + VERT_TEX0_4 | + VERT_TEX1_4 | + VERT_ELT)) == (VERT_OBJ_23 | VERT_ELT)) { + if (MESA_VERBOSE & (VERBOSE_STATE | VERBOSE_DRIVER)) + if (!fxMesa->using_fast_path) + fprintf(stderr, "fxMesa: using fast path\n"); + + pipe->stages[0] = &fx_fast_stage; + pipe->stages[1] = 0; + pipe->new_inputs = ctx->RenderFlags & VERT_DATA; + pipe->ops = pipe->stages[0]->ops; + fxMesa->using_fast_path = 1; + return 1; + } + + if (fxMesa->using_fast_path) { + if (MESA_VERBOSE & (VERBOSE_STATE | VERBOSE_DRIVER)) + fprintf(stderr, + "fxMesa: fall back to full pipeline %x %x %x %x %x\n", + fxMesa->is_in_hardware, fxMesa->render_index, + (ctx->Enabled & ILLEGAL_ENABLES), + (ctx->Array.Summary & (VERT_OBJ_23)), + (ctx->Array.Summary & (VERT_OBJ_4 | VERT_TEX0_4 | + VERT_TEX1_4))); + + fxMesa->using_fast_path = 0; + ctx->CVA.VB->ClipOrMask = 0; + ctx->CVA.VB->ClipAndMask = CLIP_ALL_BITS; + ctx->Array.NewArrayState |= ctx->Array.Summary; + return 0; + } + + return 0; +} + + + + + + +/* Perform global optimizations to the pipeline. The fx driver + * implements a single such fast path, which corresponds to the standard + * quake3 cva pipeline. + * + * This is now handled by the 'build' function above. + */ +void +fxDDOptimizePrecalcPipeline(GLcontext * ctx, struct gl_pipeline *pipe) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + if (fxMesa->is_in_hardware && + fxMesa->render_index == 0 && + (ctx->Enabled & ILLEGAL_ENABLES) == 0 && + (ctx->Array.Summary & VERT_ELT)) { + pipe->stages[0] = &fx_fast_stage; + pipe->stages[1] = 0; + } +} + + + +/* unused? +void +fxDDOptimizeEltPipeline( GLcontext *ctx, struct gl_pipeline *pipe ) +{ + (void) ctx; + (void) pipe; +} +*/ + diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h b/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h new file mode 100644 index 000000000..01b0aecb1 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h @@ -0,0 +1,15 @@ +#ifndef FXPIPELINE_H +#define FXPIPELINE_H + + +extern GLuint fxDDRegisterPipelineStages(struct gl_pipeline_stage *out, + const struct gl_pipeline_stage *in, + GLuint nr); + +extern GLboolean fxDDBuildPrecalcPipeline(GLcontext * ctx); + +extern void fxDDOptimizePrecalcPipeline(GLcontext * ctx, + struct gl_pipeline *pipe); + + +#endif diff --git a/xc/extras/Mesa/src/FX/fxrender.c b/xc/lib/GL/mesa/src/drv/tdfx/fxrender.c index 5935998f8..d1f5d1ff3 100644 --- a/xc/extras/Mesa/src/FX/fxrender.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxrender.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -45,31 +43,29 @@ /* fxrender.c - 3Dfx VooDoo RenderVB driver function support */ - -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - #include "fxdrv.h" #include "vbcull.h" +#include "fxsetup.h" + + /* * Render a line segment from VB[v1] to VB[v2] when either one or both * endpoints must be clipped. */ -#if !defined(__MWERKS__) +#if !defined(__MWERKS__) INLINE #endif -void fxRenderClippedLine( struct vertex_buffer *VB, - GLuint v1, GLuint v2 ) + void +fxRenderClippedLine(struct vertex_buffer *VB, GLuint v1, GLuint v2) { - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLubyte mask = VB->ClipMask[v1] | VB->ClipMask[v2]; + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GLubyte mask = VB->ClipMask[v1] | VB->ClipMask[v2]; - if (!mask || (VB->ctx->line_clip_tab[VB->ClipPtr->size])(VB, &v1, &v2, mask)) - FX_grDrawLine((GrVertex *)gWin[v1].f,(GrVertex *)gWin[v2].f); + if (!mask || (VB->ctx->line_clip_tab[VB->ClipPtr->size]) (VB, &v1, &v2, + mask)) + FX_grDrawLine(fxMesa, (GrVertex *) gWin[v1].f, (GrVertex *) gWin[v2].f); } @@ -77,127 +73,135 @@ void fxRenderClippedLine( struct vertex_buffer *VB, /* This is legal for Quads as well as triangles, hence the 'n' parameter. */ -INLINE void fxRenderClippedTriangle( struct vertex_buffer *VB, - GLuint n, GLuint vlist[] ) +INLINE void +fxRenderClippedTriangle(struct vertex_buffer *VB, GLuint n, GLuint vlist[]) { - GLubyte mask = 0; - GLuint i; - - for (i = 0 ; i < n ; i++) - mask |= VB->ClipMask[vlist[i]]; - - if (mask & CLIP_USER_BIT) { - GLubyte *userclipmask = VB->UserClipMask; - if (userclipmask[vlist[0]] & userclipmask[vlist[1]] & userclipmask[vlist[2]]) - return; - } - - n = (VB->ctx->poly_clip_tab[VB->ClipPtr->size])( VB, n, vlist, mask ); - if (n >= 3) { - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GrVertex *i0 = (GrVertex *)gWin[vlist[0]].f; - GrVertex *i1 = (GrVertex *)gWin[vlist[1]].f; - GrVertex *i2 = (GrVertex *)gWin[vlist[2]].f; + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); + GLubyte mask = 0; GLuint i; - - for (i=2;i<n;i++, i1 = i2, i2 = (GrVertex *)gWin[vlist[i]].f) { - FX_grDrawTriangle(i0,i1,i2); + + for (i = 0; i < n; i++) + mask |= VB->ClipMask[vlist[i]]; + + if (mask & CLIP_USER_BIT) { + GLubyte *userclipmask = VB->UserClipMask; + if (userclipmask[vlist[0]] & userclipmask[vlist[1]] & + userclipmask[vlist[2]]) + return; + } + + n = (VB->ctx->poly_clip_tab[VB->ClipPtr->size]) (VB, n, vlist, mask); + if (n >= 3) { + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GrVertex *i0 = (GrVertex *) gWin[vlist[0]].f; + GrVertex *i1 = (GrVertex *) gWin[vlist[1]].f; + GrVertex *i2 = (GrVertex *) gWin[vlist[2]].f; + GLuint i; + + for (i = 2; i < n; i++, i1 = i2, i2 = (GrVertex *) gWin[vlist[i]].f) { + FX_grDrawTriangle(fxMesa, i0, i1, i2); + } } - } } -static INLINE void fxSafeClippedLine( struct vertex_buffer *VB, - GLuint v1, GLuint v2 ) +static INLINE void +fxSafeClippedLine(struct vertex_buffer *VB, GLuint v1, GLuint v2) { - GLubyte mask = VB->ClipMask[v1] | VB->ClipMask[v2]; + GLubyte mask = VB->ClipMask[v1] | VB->ClipMask[v2]; + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - if (!mask) { - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - FX_grDrawLine((GrVertex *)gWin[v1].f,(GrVertex *)gWin[v2].f); - } else { - fxMesaContext fxMesa = (fxMesaContext)VB->ctx->DriverCtx; - fxLineClipTab[fxMesa->setupindex & 0x7]( VB, v1, v2, mask ); - } + if (!mask) { + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + FX_grDrawLine(fxMesa, (GrVertex *) gWin[v1].f, (GrVertex *) gWin[v2].f); + } + else { + fxMesaContext fxMesa = (fxMesaContext) VB->ctx->DriverCtx; + fxLineClipTab[fxMesa->setupindex & 0x7] (VB, v1, v2, mask); + } } -static INLINE void fxSafeClippedTriangle( struct vertex_buffer *VB, - fxVertex *gWin, - tfxTriClipFunc cliptri, - GLuint v2, GLuint v1, GLuint v ) +static INLINE void +fxSafeClippedTriangle(struct vertex_buffer *VB, + fxVertex * gWin, + tfxTriClipFunc cliptri, GLuint v2, GLuint v1, GLuint v) { - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; - - if (!mask) { - FX_grDrawTriangle((GrVertex *)gWin[v2].f, - (GrVertex *)gWin[v1].f, - (GrVertex *)gWin[v].f); - return; - } - - if (!(clipmask[v2] & clipmask[v1] & clipmask[v] & CLIP_ALL_BITS)) - { - GLuint vl[3]; - GLuint imask = mask; - - if (imask & CLIP_USER_BIT) { - GLubyte *userclipmask = VB->UserClipMask; - if (userclipmask[v2] & userclipmask[v1] & userclipmask[v]) - return; - imask |= (userclipmask[v2] | userclipmask[v1] | userclipmask[v]) << 8; + GLubyte *clipmask = VB->ClipMask; + GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); + + if (!mask) { + FX_grDrawTriangle(fxMesa, (GrVertex *) gWin[v2].f, + (GrVertex *) gWin[v1].f, (GrVertex *) gWin[v].f); + return; } - ASSIGN_3V(vl, v2, v1, v ); - cliptri( VB, vl, imask ); - } + if (!(clipmask[v2] & clipmask[v1] & clipmask[v] & CLIP_ALL_BITS)) { + GLuint vl[3]; + GLuint imask = mask; + + if (imask & CLIP_USER_BIT) { + GLubyte *userclipmask = VB->UserClipMask; + if (userclipmask[v2] & userclipmask[v1] & userclipmask[v]) + return; + imask |= + (userclipmask[v2] | userclipmask[v1] | userclipmask[v]) << 8; + } + + ASSIGN_3V(vl, v2, v1, v); + cliptri(VB, vl, imask); + } } -static INLINE void fxSafeClippedTriangle2( struct vertex_buffer *VB, - fxVertex *gWin, - tfxTriViewClipFunc cliptri, - GLuint v2, GLuint v1, GLuint v ) +static INLINE void +fxSafeClippedTriangle2(struct vertex_buffer *VB, + fxVertex * gWin, + tfxTriViewClipFunc cliptri, + GLuint v2, GLuint v1, GLuint v) { - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; - - if (!mask) { - FX_grDrawTriangle((GrVertex *)gWin[v2].f,(GrVertex *)gWin[v1].f, - (GrVertex *)gWin[v].f); - } else if (!(clipmask[v2] & clipmask[v1] & clipmask[v])) { - GLuint vl[3]; - ASSIGN_3V(vl, v2, v1, v ); - cliptri( VB, vl, mask ); - } + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); + GLubyte *clipmask = VB->ClipMask; + GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; + + if (!mask) { + FX_grDrawTriangle(fxMesa, + (GrVertex *) gWin[v2].f, (GrVertex *) gWin[v1].f, + (GrVertex *) gWin[v].f); + } + else if (!(clipmask[v2] & clipmask[v1] & clipmask[v])) { + GLuint vl[3]; + ASSIGN_3V(vl, v2, v1, v); + cliptri(VB, vl, mask); + } } -static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, - fxVertex *gWin, - tfxTriClipFunc cliptri, - GLuint v2, GLuint v1, GLuint v ) +static INLINE void +fxSafeClippedTriangle3(struct vertex_buffer *VB, + fxVertex * gWin, + tfxTriClipFunc cliptri, GLuint v2, GLuint v1, GLuint v) { - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; - GLuint imask = mask; - - if (imask & CLIP_USER_BIT) { - GLubyte *userclipmask = VB->UserClipMask; - if (userclipmask[v2] & userclipmask[v1] & userclipmask[v]) - return; - imask |= (userclipmask[v2] | userclipmask[v1] | userclipmask[v]) << 8; - } - - { - GLuint vl[3]; - ASSIGN_3V(vl, v2, v1, v ); - cliptri( VB, vl, imask ); - } + GLubyte *clipmask = VB->ClipMask; + GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; + GLuint imask = mask; + + if (imask & CLIP_USER_BIT) { + GLubyte *userclipmask = VB->UserClipMask; + if (userclipmask[v2] & userclipmask[v1] & userclipmask[v]) + return; + imask |= (userclipmask[v2] | userclipmask[v1] | userclipmask[v]) << 8; + } + + { + GLuint vl[3]; + ASSIGN_3V(vl, v2, v1, v); + cliptri(VB, vl, imask); + } } @@ -220,7 +224,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, #define RENDER_LINE( i1, i ) \ do { \ RVB_COLOR(i); \ - FX_grDrawLine((GrVertex *)gWin[i1].f, \ + FX_grDrawLine(fxMesa, (GrVertex *)gWin[i1].f, \ (GrVertex *)gWin[i].f); \ } while (0) @@ -228,11 +232,11 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, do { \ RVB_COLOR(pv); \ if (parity) { \ - FX_grDrawTriangle((GrVertex *)gWin[i1].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i1].f, \ (GrVertex *)gWin[i2].f, \ (GrVertex *)gWin[i].f); \ } else { \ - FX_grDrawTriangle((GrVertex *)gWin[i2].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i2].f, \ (GrVertex *)gWin[i1].f, \ (GrVertex *)gWin[i].f); \ } \ @@ -241,10 +245,10 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, #define RENDER_QUAD( i3, i2, i1, i, pv ) \ do { \ RVB_COLOR(pv); \ - FX_grDrawTriangle((GrVertex *)gWin[i3].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i3].f, \ (GrVertex *)gWin[i2].f, \ (GrVertex *)gWin[i].f); \ - FX_grDrawTriangle((GrVertex *)gWin[i2].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i2].f, \ (GrVertex *)gWin[i1].f, \ (GrVertex *)gWin[i].f); \ } while (0) @@ -256,7 +260,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ (void) fxMesa; -#define INIT(x) +#define INIT(x) #define TAG(x) x##_fx_flat_raw #undef RVB_COLOR @@ -292,7 +296,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, if (flags & PRIM_ANY_CLIP) \ fxRenderClippedLine( VB, i1, i ); \ else \ - FX_grDrawLine( (GrVertex *)gWin[i1].f, (GrVertex *)gWin[i].f ); \ + FX_grDrawLine( fxMesa, (GrVertex *)gWin[i1].f, (GrVertex *)gWin[i].f ); \ } while (0) @@ -311,7 +315,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, if (flags & PRIM_ANY_CLIP) { \ fxSafeClippedTriangle3(VB,gWin,cliptri,e2,e1,i); \ } else { \ - FX_grDrawTriangle((GrVertex *)gWin[e2].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[e2].f, \ (GrVertex *)gWin[e1].f, \ (GrVertex *)gWin[i].f); \ } \ @@ -330,10 +334,10 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, fxSafeClippedTriangle3(VB,gWin,cliptri,i3,i2,i); \ fxSafeClippedTriangle3(VB,gWin,cliptri,i2,i1,i); \ } else { \ - FX_grDrawTriangle((GrVertex *)gWin[i3].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i3].f, \ (GrVertex *)gWin[i2].f, \ (GrVertex *)gWin[i].f); \ - FX_grDrawTriangle((GrVertex *)gWin[i2].f, \ + FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i2].f, \ (GrVertex *)gWin[i1].f, \ (GrVertex *)gWin[i].f); \ } \ @@ -370,7 +374,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, /* Direct, with the possibility of clipping. - */ + */ #define RENDER_POINTS( start, count ) \ do { \ fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ @@ -379,7 +383,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, for (i = start ; i <= count ; i++) \ if (clipmask[i] == 0) { \ RVB_COLOR(i); \ - FX_grDrawPoint( (GrVertex *)gWin[i].f );\ + FX_grDrawPoint( fxMesa, (GrVertex *)gWin[i].f );\ } \ } while (0) @@ -429,7 +433,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, /* Indirect, with the possibility of clipping. - */ + */ #define RENDER_POINTS( start, count ) \ do { \ fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ @@ -437,7 +441,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, GLubyte *clipmask = VB->ClipMask; \ for(e=start;e<=count;e++) \ if(clipmask[elt[e]]==0) { \ - FX_grDrawPoint((GrVertex *)gWin[elt[e]].f); \ + FX_grDrawPoint(fxMesa, (GrVertex *)gWin[elt[e]].f); \ } \ } while (0) @@ -484,7 +488,7 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, GLubyte *clipmask = VB->ClipMask; \ for(e=start;e<=count;e++) \ if(clipmask[elt[e]]==0) { \ - FX_grDrawPoint((GrVertex *)gWin[elt[e]].f); \ + FX_grDrawPoint(fxMesa, (GrVertex *)gWin[elt[e]].f); \ } \ } while (0) @@ -533,43 +537,45 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, do { \ GLuint e; \ for(e=start;e<=count;e++) { \ - FX_grDrawPoint((GrVertex *)gWin[elt[e]].f); \ + FX_grDrawPoint_NoLock((GrVertex *)gWin[elt[e]].f);\ } \ } while (0) #define RENDER_LINE( i1, i ) \ do { \ GLuint e1 = elt[i1], e = elt[i]; \ - FX_grDrawLine((GrVertex *)gWin[e1].f, (GrVertex *)gWin[e].f); \ + FX_grDrawLine_NoLock((GrVertex *)gWin[e1].f, (GrVertex *)gWin[e].f);\ } while (0) #define RENDER_TRI( i2, i1, i, pv, parity) \ do { \ GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ - if (parity) {GLuint tmp = e2; e2 = e1; e1 = tmp;} \ - FX_grDrawTriangle((GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e1].f, \ - (GrVertex *)gWin[e].f); \ + if (parity) {GLuint tmp = e2; e2 = e1; e1 = tmp;} \ + FX_grDrawTriangle_NoLock((GrVertex *)gWin[e2].f, \ + (GrVertex *)gWin[e1].f, \ + (GrVertex *)gWin[e].f); \ } while (0) #define RENDER_QUAD( i3, i2, i1, i, pv) \ do { \ GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i];\ - FX_grDrawTriangle((GrVertex *)gWin[e3].f, \ - (GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e].f); \ - FX_grDrawTriangle((GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e1].f, \ - (GrVertex *)gWin[e].f); \ + FX_grDrawTriangle_NoLock((GrVertex *)gWin[e3].f, \ + (GrVertex *)gWin[e2].f, \ + (GrVertex *)gWin[e].f); \ + FX_grDrawTriangle_NoLock((GrVertex *)gWin[e2].f, \ + (GrVertex *)gWin[e1].f, \ + (GrVertex *)gWin[e].f); \ } while (0) #define LOCAL_VARS \ fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - const GLuint *elt = VB->EltPtr->data; + const GLuint *elt = VB->EltPtr->data; \ + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); -#define INIT(x) +#define INIT(x) BEGIN_CLIP_LOOP(fxMesa); +#define POSTFIX END_CLIP_LOOP(fxMesa); #define TAG(x) x##_fx_smooth_indirect #undef RVB_COLOR @@ -595,118 +601,120 @@ static INLINE void fxSafeClippedTriangle3( struct vertex_buffer *VB, * We don't handle texcoord-4 in the safe clip routines - maybe we should. * */ -void fxDDRenderElementsDirect( struct vertex_buffer *VB ) +void +fxDDRenderElementsDirect(struct vertex_buffer *VB) { - GLcontext *ctx = VB->ctx; - struct vertex_buffer *saved_vb = ctx->VB; - GLenum prim = ctx->CVA.elt_mode; - GLuint nr = VB->EltPtr->count; - render_func func = render_tab_fx_smooth_indirect[prim]; - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint p = 0; - - if (!nr) - return; - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - if (!nr) return; + GLcontext *ctx = VB->ctx; + struct vertex_buffer *saved_vb = ctx->VB; + GLenum prim = ctx->CVA.elt_mode; + GLuint nr = VB->EltPtr->count; + render_func func = render_tab_fx_smooth_indirect[prim]; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint p = 0; + + if (!nr) + return; + + if (fxMesa->new_state) + fxSetupFXUnits(ctx); + + if (!nr) + return; + + if (VB->ClipOrMask) { + func = render_tab_fx_smooth_indirect_view_clipped[prim]; + if (VB->ClipOrMask & CLIP_USER_BIT) + func = render_tab_fx_smooth_indirect_clipped[prim]; + } - if (VB->ClipOrMask) { - func = render_tab_fx_smooth_indirect_view_clipped[prim]; - if (VB->ClipOrMask & CLIP_USER_BIT) - func = render_tab_fx_smooth_indirect_clipped[prim]; - } - - ctx->VB = VB; /* kludge */ + ctx->VB = VB; /* kludge */ - do { - func( VB, 0, nr, 0 ); - } while (ctx->Driver.MultipassFunc && - ctx->Driver.MultipassFunc( VB, ++p )); + do { + func(VB, 0, nr, 0); + } while (ctx->Driver.MultipassFunc && ctx->Driver.MultipassFunc(VB, ++p)); - ctx->VB = saved_vb; + ctx->VB = saved_vb; } -void fxDDRenderVBIndirectDirect( struct vertex_buffer *VB ) +void +fxDDRenderVBIndirectDirect(struct vertex_buffer *VB) { - GLcontext *ctx = VB->ctx; - struct vertex_buffer *cvaVB = ctx->CVA.VB; - struct vertex_buffer *saved_vb = ctx->VB; - GLuint i, next, count = VB->Count; - render_func *tab = render_tab_fx_smooth_indirect; - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint p = 0; - - if (cvaVB->ClipOrMask) - tab = render_tab_fx_smooth_indirect_clipped; - - if (!VB->CullDone) - gl_fast_copy_vb( VB ); - - if (fxMesa->new_state) - fxSetupFXUnits( ctx ); - - ctx->VB = cvaVB; - cvaVB->EltPtr = VB->EltPtr; - - do { - GLuint parity = VB->Parity; - - for (i = VB->CopyStart ; i < count ; parity = 0, i = next) - { - GLuint prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; - tab[prim]( cvaVB, i, next, parity ); - } - /* loop never taken */ - } while (ctx->Driver.MultipassFunc && - ctx->Driver.MultipassFunc( cvaVB, ++p )); - - cvaVB->EltPtr = 0; - ctx->VB = saved_vb; + GLcontext *ctx = VB->ctx; + struct vertex_buffer *cvaVB = ctx->CVA.VB; + struct vertex_buffer *saved_vb = ctx->VB; + GLuint i, next, count = VB->Count; + render_func *tab = render_tab_fx_smooth_indirect; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint p = 0; + + if (cvaVB->ClipOrMask) + tab = render_tab_fx_smooth_indirect_clipped; + + if (!VB->CullDone) + gl_fast_copy_vb(VB); + + if (fxMesa->new_state) + fxSetupFXUnits(ctx); + + ctx->VB = cvaVB; + cvaVB->EltPtr = VB->EltPtr; + + do { + GLuint parity = VB->Parity; + + for (i = VB->CopyStart; i < count; parity = 0, i = next) { + GLuint prim = VB->Primitive[i]; + next = VB->NextPrimitive[i]; + tab[prim] (cvaVB, i, next, parity); + } + /* loop never taken */ + } while (ctx->Driver.MultipassFunc && + ctx->Driver.MultipassFunc(cvaVB, ++p)); + + cvaVB->EltPtr = 0; + ctx->VB = saved_vb; } static render_func *fxDDRenderVBSmooth_tables[3] = { - render_tab_fx_smooth_clipped, - render_tab_fx_smooth_culled, - render_tab_fx_smooth_raw + render_tab_fx_smooth_clipped, + render_tab_fx_smooth_culled, + render_tab_fx_smooth_raw }; static render_func *fxDDRenderVBFlat_tables[3] = { - render_tab_fx_flat_clipped, - render_tab_fx_flat_culled, - render_tab_fx_flat_raw + render_tab_fx_flat_clipped, + render_tab_fx_flat_culled, + render_tab_fx_flat_raw }; static render_func *null_tables[3] = { - 0, - 0, - 0 + 0, + 0, + 0 }; #if defined(FX_GLIDE3) #include "fxstripdet.c" #endif -void fxDDRenderInit( GLcontext *ctx ) +void +fxDDRenderInit(GLcontext * ctx) { - render_init_fx_smooth_indirect_view_clipped(); - render_init_fx_smooth_indirect_clipped(); - render_init_fx_smooth_indirect(); - render_init_fx_smooth_raw(); - render_init_fx_smooth_culled(); - render_init_fx_smooth_clipped(); - render_init_fx_flat_raw(); - render_init_fx_flat_culled(); - render_init_fx_flat_clipped(); + render_init_fx_smooth_indirect_view_clipped(); + render_init_fx_smooth_indirect_clipped(); + render_init_fx_smooth_indirect(); + render_init_fx_smooth_raw(); + render_init_fx_smooth_culled(); + render_init_fx_smooth_clipped(); + render_init_fx_flat_raw(); + render_init_fx_flat_culled(); + render_init_fx_flat_clipped(); #if defined(FX_GLIDE3) - fxDDRenderInitGlide3(ctx); + fxDDRenderInitGlide3(ctx); #endif } @@ -714,72 +722,58 @@ void fxDDRenderInit( GLcontext *ctx ) /* Now used to set an internal var in fxMesa - we hook out at the * level of gl_render_vb() instead. */ -render_func **fxDDChooseRenderVBTables(GLcontext *ctx) +render_func ** +fxDDChooseRenderVBTables(GLcontext * ctx) { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - if (ctx->IndirectTriangles & DD_SW_SETUP) - return null_tables; + if (ctx->IndirectTriangles & DD_SW_SETUP) + return null_tables; - switch (fxMesa->render_index) { + switch (fxMesa->render_index) { /* case FX_FLAT: */ /* return fxDDRenderVBFlat_tables; */ - case 0: - return fxDDRenderVBSmooth_tables; - default: - return null_tables; - } + case 0: + return fxDDRenderVBSmooth_tables; + default: + return null_tables; + } } -void fxDDDoRenderVB( struct vertex_buffer *VB ) +void +fxDDDoRenderVB(struct vertex_buffer *VB) { - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint i, next, prim; - GLuint parity = VB->Parity; - render_func *tab; - GLuint count = VB->Count; - GLint p = 0; - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - if (VB->Indirect) { - return; - } else if (VB->CullMode & CLIP_MASK_ACTIVE) { - tab = fxMesa->RenderVBClippedTab; - } else { - tab = fxMesa->RenderVBRawTab; - } - - if (!VB->CullDone) - gl_fast_copy_vb( VB ); - - do - { - for ( i= VB->CopyStart ; i < count ; parity = 0, i = next ) - { - prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; - tab[prim]( VB, i, next, parity ); - } - - } while (ctx->Driver.MultipassFunc && - ctx->Driver.MultipassFunc( VB, ++p )); -} + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint i, next, prim; + GLuint parity = VB->Parity; + render_func *tab; + GLuint count = VB->Count; + GLint p = 0; + if (fxMesa->new_state) + fxSetupFXUnits(ctx); -#else + if (VB->Indirect) { + return; + } + else if (VB->CullMode & CLIP_MASK_ACTIVE) { + tab = fxMesa->RenderVBClippedTab; + } + else { + tab = fxMesa->RenderVBRawTab; + } + if (!VB->CullDone) + gl_fast_copy_vb(VB); -/* - * Need this to provide at least one external definition. - */ + do { + for (i = VB->CopyStart; i < count; parity = 0, i = next) { + prim = VB->Primitive[i]; + next = VB->NextPrimitive[i]; + tab[prim] (VB, i, next, parity); + } -int gl_fx_dummy_function_render(void) -{ - return 0; + } while (ctx->Driver.MultipassFunc && ctx->Driver.MultipassFunc(VB, ++p)); } - -#endif /* FX */ diff --git a/xc/extras/Mesa/src/FX/fxsanity.c b/xc/lib/GL/mesa/src/drv/tdfx/fxsanity.c index 9f815012e..9abee0d89 100644 --- a/xc/extras/Mesa/src/FX/fxsanity.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxsanity.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -43,13 +41,6 @@ */ -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - - - -#if defined(FX) #include "fxdrv.h" /* I have found this quite useful in tracking down transformation & @@ -62,63 +53,57 @@ #undef grDrawTriangle -void fx_sanity_triangle( GrVertex *v1, GrVertex *v2, GrVertex *v3 ) -{ - GLuint rv = 1, print = 0; - - GLfloat area = ((v1->x - v3->x) * (v2->y - v3->y) - - (v1->y - v3->y) * (v2->x - v3->x)); - - if (v1->x < 0 || v1->y < 0 || v1->x > WID || v1->y > HI || - v2->x < 0 || v2->y < 0 || v2->x > WID || v2->y > HI || - v3->x < 0 || v3->y < 0 || v3->x > WID || v3->y > HI) - { - fprintf(stderr,"not clipped/set up!!!!!\n"); - rv = 0; - print = 1; - } - - if (area > (WID*HI)) { - fprintf(stderr,"too big\n"); - rv = 0; - } - if (v1->oow == 0 || v2->oow == 0 || v3->oow == 0) { - fprintf(stderr,"zero oow\n"); - rv = 0; - } - if (0 && area == 0) { - fprintf(stderr,"zero area %p %p %p\n", v1,v2,v3); - rv =0; - } - - if (print) { - fprintf(stderr,"v1: %f %f %f %f col %.0f %.0f %.0f %.0f t0 %f %f %f t1 %f %f %f\n", - v1->x, v1->y, v1->ooz, v1->oow, - v1->r, v1->g, v1->b, v1->a, - v1->tmuvtx[0].sow, v1->tmuvtx[0].tow, v1->tmuvtx[0].oow, - v1->tmuvtx[1].sow, v1->tmuvtx[1].tow, v1->tmuvtx[1].oow); - fprintf(stderr,"v2: %f %f %f %f col %.0f %.0f %.0f %.0f t0 %f %f %f t1 %f %f %f\n", - v2->x, v2->y, v2->ooz, v2->oow, - v2->r, v2->g, v2->b, v2->a, - v2->tmuvtx[0].sow, v2->tmuvtx[0].tow, v2->tmuvtx[0].oow, - v2->tmuvtx[1].sow, v2->tmuvtx[1].tow, v2->tmuvtx[1].oow); - fprintf(stderr,"v3: %f %f %f %f col %.0f %.0f %.0f %.0f t0 %f %f %f t1 %f %f %f\n", - v3->x, v3->y, v3->ooz, v3->oow, - v3->r, v3->g, v3->b, v3->a, - v3->tmuvtx[0].sow, v3->tmuvtx[0].tow, v3->tmuvtx[0].oow, - v3->tmuvtx[1].sow, v3->tmuvtx[1].tow, v3->tmuvtx[1].oow); - } - - if (1) - FX_grDrawTriangle(v1,v2,v3); - else - fprintf(stderr, "\n\n\n"); -} - -#else - -void gl_fxsanity_dummy() +void +fx_sanity_triangle(fxMesaContext fxMesa, + GrVertex * v1, GrVertex * v2, GrVertex * v3) { + GLuint rv = 1, print = 0; + + GLfloat area = ((v1->x - v3->x) * (v2->y - v3->y) - + (v1->y - v3->y) * (v2->x - v3->x)); + + if (v1->x < 0 || v1->y < 0 || v1->x > WID || v1->y > HI || + v2->x < 0 || v2->y < 0 || v2->x > WID || v2->y > HI || + v3->x < 0 || v3->y < 0 || v3->x > WID || v3->y > HI) { + fprintf(stderr, "not clipped/set up!!!!!\n"); + rv = 0; + print = 1; + } + + if (area > (WID * HI)) { + fprintf(stderr, "too big\n"); + rv = 0; + } + if (v1->oow == 0 || v2->oow == 0 || v3->oow == 0) { + fprintf(stderr, "zero oow\n"); + rv = 0; + } + if (0 && area == 0) { + fprintf(stderr, "zero area %p %p %p\n", v1, v2, v3); + rv = 0; + } + + if (print) { + fprintf(stderr, + "v1: %f %f %f %f col %.0f %.0f %.0f %.0f t0 %f %f %f t1 %f %f %f\n", + v1->x, v1->y, v1->ooz, v1->oow, v1->r, v1->g, v1->b, v1->a, + v1->tmuvtx[0].sow, v1->tmuvtx[0].tow, v1->tmuvtx[0].oow, + v1->tmuvtx[1].sow, v1->tmuvtx[1].tow, v1->tmuvtx[1].oow); + fprintf(stderr, + "v2: %f %f %f %f col %.0f %.0f %.0f %.0f t0 %f %f %f t1 %f %f %f\n", + v2->x, v2->y, v2->ooz, v2->oow, v2->r, v2->g, v2->b, v2->a, + v2->tmuvtx[0].sow, v2->tmuvtx[0].tow, v2->tmuvtx[0].oow, + v2->tmuvtx[1].sow, v2->tmuvtx[1].tow, v2->tmuvtx[1].oow); + fprintf(stderr, + "v3: %f %f %f %f col %.0f %.0f %.0f %.0f t0 %f %f %f t1 %f %f %f\n", + v3->x, v3->y, v3->ooz, v3->oow, v3->r, v3->g, v3->b, v3->a, + v3->tmuvtx[0].sow, v3->tmuvtx[0].tow, v3->tmuvtx[0].oow, + v3->tmuvtx[1].sow, v3->tmuvtx[1].tow, v3->tmuvtx[1].oow); + } + + if (1) + FX_grDrawTriangle(fxMesa, v1, v2, v3); + else + fprintf(stderr, "\n\n\n"); } -#endif diff --git a/xc/extras/Mesa/src/FX/fxsdettmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxsdettmp.h index 7b77b36c2..71cf37e2e 100644 --- a/xc/extras/Mesa/src/FX/fxsdettmp.h +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxsdettmp.h @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -41,8 +39,8 @@ * * See fxapi.h for more revision/author details. */ - - + + /* * Notes: the folowing code works only if count is > start. * Corrently we are looking for the pattern: @@ -56,86 +54,80 @@ static void TAG(render_vb_triangles_smooth_indirect_sd) - ( struct vertex_buffer *VB, - GLuint start, - GLuint count, - GLuint parity) + (struct vertex_buffer * VB, GLuint start, GLuint count, GLuint parity) { - GLint u0,u1,u2; - GLint v0,v1,v2; - GLuint *elt = VB->EltPtr->data; - - int i; - LOCAL_VARS - - INIT(GL_TRIANGLES); - - elt = &elt[start-1]; - u0 = *(++elt); - u1 = *(++elt); - u2 = *(++elt); - i = start+3; - while (i < count) - { - v0 = *(++elt); - v1 = *(++elt); - v2 = *(++elt); - - if (CLIPPED(u0,u1,u2)) - { - if (!CULLED(u0,u1,u2)) SENDCLIPTRI(u0,u1,u2); - } - else - { - if (STRIP0(u,v)) - { - int is_strips = 1; - int parity = 0; - STRIPSLOCAL_VAR - - FLUSHTRI(); - STARTSTRIPS(u0,u1,u2); - while (is_strips && i < count) - { - SENDSTRIPS(v2); - - u0 = v0; u1 = v1; u2 = v2; i+= 3; - v0 = *(++elt); - v1 = *(++elt); - v2 = *(++elt); - - if (parity) { - is_strips = STRIP0(u,v); - parity = 0; - } else { - is_strips = STRIP1(u,v); - parity = 1; - } - } - FLUSHSTRIPS(); - - if (i >= count) - return; - } - else - { - SENDTRI(u0,u1,u2); - } - } - u0 = v0; u1 = v1; u2 = v2; i+= 3; - } - if (CLIPPED(u0,u1,u2)) - { - if (!CULLED(u0,u1,u2)) SENDCLIPTRI(u0,u1,u2); - } - else - { - SENDTRI(u0,u1,u2); - } - FLUSHTRI(); - + GLint u0, u1, u2; + GLint v0, v1, v2; + GLuint *elt = VB->EltPtr->data; + + int i; + LOCAL_VARS INIT(GL_TRIANGLES); + + elt = &elt[start - 1]; + u0 = *(++elt); + u1 = *(++elt); + u2 = *(++elt); + i = start + 3; + while (i < count) { + v0 = *(++elt); + v1 = *(++elt); + v2 = *(++elt); + + if (CLIPPED(u0, u1, u2)) { + if (!CULLED(u0, u1, u2)) + SENDCLIPTRI(u0, u1, u2); + } + else { + if (STRIP0(u, v)) { + int is_strips = 1; + int parity = 0; + STRIPSLOCAL_VAR FLUSHTRI(); + STARTSTRIPS(u0, u1, u2); + while (is_strips && i < count) { + SENDSTRIPS(v2); + + u0 = v0; + u1 = v1; + u2 = v2; + i += 3; + v0 = *(++elt); + v1 = *(++elt); + v2 = *(++elt); + + if (parity) { + is_strips = STRIP0(u, v); + parity = 0; + } + else { + is_strips = STRIP1(u, v); + parity = 1; + } + } + FLUSHSTRIPS(); + + if (i >= count) + return; + } + else { + SENDTRI(u0, u1, u2); + } + } + u0 = v0; + u1 = v1; + u2 = v2; + i += 3; + } + if (CLIPPED(u0, u1, u2)) { + if (!CULLED(u0, u1, u2)) + SENDCLIPTRI(u0, u1, u2); + } + else { + SENDTRI(u0, u1, u2); + } + FLUSHTRI(); + } - + #ifndef PRESERVE_VB_DEFS #undef SENDTRI #undef STRIP0 diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxsetup.c b/xc/lib/GL/mesa/src/drv/tdfx/fxsetup.c new file mode 100644 index 000000000..2dc5edab0 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxsetup.c @@ -0,0 +1,2076 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +/* fxsetup.c - 3Dfx VooDoo rendering mode setup functions */ + +#include "fxdrv.h" +#include "fxddtex.h" +#include "fxtexman.h" +#include "fxsetup.h" +#include "enums.h" + + +static GLboolean fxMultipassTexture(struct vertex_buffer *, GLuint); + + + +static void +fxTexValidate(GLcontext * ctx, struct gl_texture_object *tObj) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + GLint minl, maxl; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxTexValidate(...) Start\n"); + } + + if (ti->validated) { + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, + "fxmesa: fxTexValidate(...) End (validated=GL_TRUE)\n"); + } + return; + } + + ti->tObj = tObj; + minl = ti->minLevel = tObj->BaseLevel; + maxl = ti->maxLevel = MIN2(tObj->MaxLevel, tObj->Image[0]->MaxLog2); + + fxTexGetInfo(ctx, tObj->Image[minl]->Width, tObj->Image[minl]->Height, + &(FX_largeLodLog2(ti->info)), + &(FX_aspectRatioLog2(ti->info)), &(ti->sScale), + &(ti->tScale), &(ti->int_sScale), &(ti->int_tScale), NULL, + NULL); + + if ((tObj->MinFilter != GL_NEAREST) && (tObj->MinFilter != GL_LINEAR)) + fxTexGetInfo(ctx, tObj->Image[maxl]->Width, tObj->Image[maxl]->Height, + &(FX_smallLodLog2(ti->info)), NULL, + NULL, NULL, NULL, NULL, NULL, NULL); + else + FX_smallLodLog2(ti->info) = FX_largeLodLog2(ti->info); + + fxTexGetFormat(tObj->Image[minl]->IntFormat, &(ti->info.format), + &(ti->baseLevelInternalFormat), NULL, NULL, + fxMesa->haveHwStencil); + + switch (tObj->WrapS) { + case GL_CLAMP_TO_EDGE: + case GL_CLAMP: + ti->sClamp = 1; + break; + case GL_REPEAT: + ti->sClamp = 0; + break; + default: + ; /* silence compiler warning */ + } + switch (tObj->WrapT) { + case GL_CLAMP_TO_EDGE: + case GL_CLAMP: + ti->tClamp = 1; + break; + case GL_REPEAT: + ti->tClamp = 0; + break; + default: + ; /* silence compiler warning */ + } + + ti->validated = GL_TRUE; + + ti->info.data = NULL; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxTexValidate(...) End\n"); + } +} + +static void +fxPrintUnitsMode(const char *msg, GLuint mode) +{ + fprintf(stderr, + "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + msg, + mode, + (mode & FX_UM_E0_REPLACE) ? "E0_REPLACE, " : "", + (mode & FX_UM_E0_MODULATE) ? "E0_MODULATE, " : "", + (mode & FX_UM_E0_DECAL) ? "E0_DECAL, " : "", + (mode & FX_UM_E0_BLEND) ? "E0_BLEND, " : "", + (mode & FX_UM_E1_REPLACE) ? "E1_REPLACE, " : "", + (mode & FX_UM_E1_MODULATE) ? "E1_MODULATE, " : "", + (mode & FX_UM_E1_DECAL) ? "E1_DECAL, " : "", + (mode & FX_UM_E1_BLEND) ? "E1_BLEND, " : "", + (mode & FX_UM_E0_ALPHA) ? "E0_ALPHA, " : "", + (mode & FX_UM_E0_LUMINANCE) ? "E0_LUMINANCE, " : "", + (mode & FX_UM_E0_LUMINANCE_ALPHA) ? "E0_LUMINANCE_ALPHA, " : "", + (mode & FX_UM_E0_INTENSITY) ? "E0_INTENSITY, " : "", + (mode & FX_UM_E0_RGB) ? "E0_RGB, " : "", + (mode & FX_UM_E0_RGBA) ? "E0_RGBA, " : "", + (mode & FX_UM_E1_ALPHA) ? "E1_ALPHA, " : "", + (mode & FX_UM_E1_LUMINANCE) ? "E1_LUMINANCE, " : "", + (mode & FX_UM_E1_LUMINANCE_ALPHA) ? "E1_LUMINANCE_ALPHA, " : "", + (mode & FX_UM_E1_INTENSITY) ? "E1_INTENSITY, " : "", + (mode & FX_UM_E1_RGB) ? "E1_RGB, " : "", + (mode & FX_UM_E1_RGBA) ? "E1_RGBA, " : "", + (mode & FX_UM_COLOR_ITERATED) ? "COLOR_ITERATED, " : "", + (mode & FX_UM_COLOR_CONSTANT) ? "COLOR_CONSTANT, " : "", + (mode & FX_UM_ALPHA_ITERATED) ? "ALPHA_ITERATED, " : "", + (mode & FX_UM_ALPHA_CONSTANT) ? "ALPHA_CONSTANT, " : ""); +} + +static GLuint +fxGetTexSetConfiguration(GLcontext * ctx, + struct gl_texture_object *tObj0, + struct gl_texture_object *tObj1) +{ + GLuint unitsmode = 0; + GLuint envmode = 0; + GLuint ifmt = 0; + + if ((ctx->Light.ShadeModel == GL_SMOOTH) || 1 || + (ctx->Point.SmoothFlag) || + (ctx->Line.SmoothFlag) || + (ctx->Polygon.SmoothFlag)) + unitsmode |= FX_UM_ALPHA_ITERATED; + else + unitsmode |= FX_UM_ALPHA_CONSTANT; + + if (ctx->Light.ShadeModel == GL_SMOOTH || 1) + unitsmode |= FX_UM_COLOR_ITERATED; + else + unitsmode |= FX_UM_COLOR_CONSTANT; + + + + /* + OpenGL Feeds Texture 0 into Texture 1 + Glide Feeds Texture 1 into Texture 0 + */ + if (tObj0) { + tfxTexInfo *ti0 = fxTMGetTexInfo(tObj0); + + switch (ti0->baseLevelInternalFormat) { + case GL_ALPHA: + ifmt |= FX_UM_E0_ALPHA; + break; + case GL_LUMINANCE: + ifmt |= FX_UM_E0_LUMINANCE; + break; + case GL_LUMINANCE_ALPHA: + ifmt |= FX_UM_E0_LUMINANCE_ALPHA; + break; + case GL_INTENSITY: + ifmt |= FX_UM_E0_INTENSITY; + break; + case GL_RGB: + ifmt |= FX_UM_E0_RGB; + break; + case GL_RGBA: + ifmt |= FX_UM_E0_RGBA; + break; + } + + switch (ctx->Texture.Unit[0].EnvMode) { + case GL_DECAL: + envmode |= FX_UM_E0_DECAL; + break; + case GL_MODULATE: + envmode |= FX_UM_E0_MODULATE; + break; + case GL_REPLACE: + envmode |= FX_UM_E0_REPLACE; + break; + case GL_BLEND: + envmode |= FX_UM_E0_BLEND; + break; + case GL_ADD: + envmode |= FX_UM_E0_ADD; + break; + default: + /* do nothing */ + break; + } + } + + if (tObj1) { + tfxTexInfo *ti1 = fxTMGetTexInfo(tObj1); + + switch (ti1->baseLevelInternalFormat) { + case GL_ALPHA: + ifmt |= FX_UM_E1_ALPHA; + break; + case GL_LUMINANCE: + ifmt |= FX_UM_E1_LUMINANCE; + break; + case GL_LUMINANCE_ALPHA: + ifmt |= FX_UM_E1_LUMINANCE_ALPHA; + break; + case GL_INTENSITY: + ifmt |= FX_UM_E1_INTENSITY; + break; + case GL_RGB: + ifmt |= FX_UM_E1_RGB; + break; + case GL_RGBA: + ifmt |= FX_UM_E1_RGBA; + break; + default: + /* do nothing */ + break; + } + + switch (ctx->Texture.Unit[1].EnvMode) { + case GL_DECAL: + envmode |= FX_UM_E1_DECAL; + break; + case GL_MODULATE: + envmode |= FX_UM_E1_MODULATE; + break; + case GL_REPLACE: + envmode |= FX_UM_E1_REPLACE; + break; + case GL_BLEND: + envmode |= FX_UM_E1_BLEND; + break; + case GL_ADD: + envmode |= FX_UM_E1_ADD; + break; + default: + /* do nothing */ + break; + } + } + + unitsmode |= (ifmt | envmode); + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_TEXTURE)) + fxPrintUnitsMode("unitsmode", unitsmode); + + return unitsmode; +} + +/************************************************************************/ +/************************* Rendering Mode SetUp *************************/ +/************************************************************************/ + +/************************* Single Texture Set ***************************/ + +static void +fxSetupSingleTMU_NoLock(fxMesaContext fxMesa, struct gl_texture_object *tObj) +{ + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + int tmu; + + /* Make sure we're not loaded incorrectly */ + if (ti->isInTM) { + if (ti->LODblend) { + if (ti->whichTMU != FX_TMU_SPLIT) + fxTMMoveOutTM(fxMesa, tObj); + } + else { + if (ti->whichTMU == FX_TMU_SPLIT) + fxTMMoveOutTM(fxMesa, tObj); + } + } + + /* Make sure we're loaded correctly */ + if (!ti->isInTM) { + if (ti->LODblend) + fxTMMoveInTM_NoLock(fxMesa, tObj, FX_TMU_SPLIT); + else { + if (fxMesa->haveTwoTMUs) { + if (fxMesa->freeTexMem[FX_TMU0] > + FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info))) { + fxTMMoveInTM_NoLock(fxMesa, tObj, FX_TMU0); + } + else { + fxTMMoveInTM_NoLock(fxMesa, tObj, FX_TMU1); + } + } + else + fxTMMoveInTM_NoLock(fxMesa, tObj, FX_TMU0); + } + } + + if (ti->LODblend && ti->whichTMU == FX_TMU_SPLIT) { + if ((ti->info.format == GR_TEXFMT_P_8) + && (!fxMesa->haveGlobalPaletteTexture)) { + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: uploading texture palette\n"); + } + FX_grTexDownloadTable_NoLock(GR_TMU0, GR_TEXTABLE_PALETTE_6666_EXT, + &(ti->palette)); + FX_grTexDownloadTable_NoLock(GR_TMU1, GR_TEXTABLE_PALETTE_6666_EXT, + &(ti->palette)); + } + + FX_grTexClampMode_NoLock(GR_TMU0, ti->sClamp, ti->tClamp); + FX_grTexClampMode_NoLock(GR_TMU1, ti->sClamp, ti->tClamp); + FX_grTexFilterMode_NoLock(GR_TMU0, ti->minFilt, ti->maxFilt); + FX_grTexFilterMode_NoLock(GR_TMU1, ti->minFilt, ti->maxFilt); + FX_grTexMipMapMode_NoLock(GR_TMU0, ti->mmMode, ti->LODblend); + FX_grTexMipMapMode_NoLock(GR_TMU1, ti->mmMode, ti->LODblend); + + FX_grTexSource_NoLock(GR_TMU0, ti->tm[FX_TMU0]->startAddr, + GR_MIPMAPLEVELMASK_ODD, &(ti->info)); + FX_grTexSource_NoLock(GR_TMU1, ti->tm[FX_TMU1]->startAddr, + GR_MIPMAPLEVELMASK_EVEN, &(ti->info)); + } + else { + if (ti->whichTMU == FX_TMU_BOTH) + tmu = FX_TMU0; + else + tmu = ti->whichTMU; + + if ((ti->info.format == GR_TEXFMT_P_8) + && (!fxMesa->haveGlobalPaletteTexture)) { + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: uploading texture palette\n"); + } + FX_grTexDownloadTable_NoLock(tmu, GR_TEXTABLE_PALETTE_6666_EXT, + &(ti->palette)); + } + + /* KW: The alternative is to do the download to the other tmu. If + * we get to this point, I think it means we are thrashing the + * texture memory, so perhaps it's not a good idea. + */ + if (ti->LODblend && (MESA_VERBOSE & VERBOSE_DRIVER)) + fprintf(stderr, + "fxmesa: not blending texture - only on one tmu\n"); + + FX_grTexClampMode_NoLock(tmu, ti->sClamp, ti->tClamp); + FX_grTexFilterMode_NoLock(tmu, ti->minFilt, ti->maxFilt); + FX_grTexMipMapMode_NoLock(tmu, ti->mmMode, FXFALSE); + + if (ti->tm[tmu]) { + FX_grTexSource_NoLock(tmu, ti->tm[tmu]->startAddr, + GR_MIPMAPLEVELMASK_BOTH, &(ti->info)); + } + } +} + +static void +fxSelectSingleTMUSrc_NoLock(fxMesaContext fxMesa, GLint tmu, FxBool LODblend) +{ + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSelectSingleTMUSrc(%d,%d)\n", tmu, + LODblend); + } + + if (LODblend) { + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND, + GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION, + GR_COMBINE_FUNCTION_BLEND, + GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION, + FXFALSE, FXFALSE); + + if (fxMesa->haveTwoTMUs) + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE); + fxMesa->tmuSrc = FX_TMU_SPLIT; + } + else { + if (tmu != FX_TMU1) { + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE); + if (fxMesa->haveTwoTMUs) { + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_ZERO, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_ZERO, + GR_COMBINE_FACTOR_NONE, FXFALSE, + FXFALSE); + } + fxMesa->tmuSrc = FX_TMU0; + } + else { + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE); + + /* GR_COMBINE_FUNCTION_SCALE_OTHER doesn't work ?!? */ + + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND, + GR_COMBINE_FACTOR_ONE, + GR_COMBINE_FUNCTION_BLEND, + GR_COMBINE_FACTOR_ONE, FXFALSE, FXFALSE); + + fxMesa->tmuSrc = FX_TMU1; + } + } +} + +static void +fxSetupTextureSingleTMU_NoLock(GLcontext * ctx, GLuint textureset) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrCombineLocal_t localc, locala; + GLuint unitsmode; + GLint ifmt; + tfxTexInfo *ti; + struct gl_texture_object *tObj = + ctx->Texture.Unit[textureset].CurrentD[2]; + int tmu; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupTextureSingleTMU(...) Start\n"); + } + + ti = fxTMGetTexInfo(tObj); + + fxTexValidate(ctx, tObj); + + fxSetupSingleTMU_NoLock(fxMesa, tObj); + + if (ti->whichTMU == FX_TMU_BOTH) + tmu = FX_TMU0; + else + tmu = ti->whichTMU; + if (fxMesa->tmuSrc != tmu) + fxSelectSingleTMUSrc_NoLock(fxMesa, tmu, ti->LODblend); + + if (textureset == 0 || !fxMesa->haveTwoTMUs) + unitsmode = fxGetTexSetConfiguration(ctx, tObj, NULL); + else + unitsmode = fxGetTexSetConfiguration(ctx, NULL, tObj); + + fxMesa->stw_hint_state = 0; + FX_grHints_NoLock(GR_HINT_STWHINT, 0); + + ifmt = ti->baseLevelInternalFormat; + + if (unitsmode & FX_UM_ALPHA_ITERATED) + locala = GR_COMBINE_LOCAL_ITERATED; + else + locala = GR_COMBINE_LOCAL_CONSTANT; + + if (unitsmode & FX_UM_COLOR_ITERATED) + localc = GR_COMBINE_LOCAL_ITERATED; + else + localc = GR_COMBINE_LOCAL_CONSTANT; + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_TEXTURE)) + fprintf(stderr, "fxMesa: fxSetupTextureSingleTMU, envmode is %s\n", + gl_lookup_enum_by_nr(ctx->Texture.Unit[textureset].EnvMode)); + + switch (ctx->Texture.Unit[textureset].EnvMode) { + case GL_DECAL: + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_BLEND, + GR_COMBINE_FACTOR_TEXTURE_ALPHA, + localc, GR_COMBINE_OTHER_TEXTURE, FXFALSE); + break; + case GL_MODULATE: + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + locala, GR_COMBINE_OTHER_TEXTURE, FXFALSE); + + if (ifmt == GL_ALPHA) + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + localc, GR_COMBINE_OTHER_NONE, FXFALSE); + else + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + localc, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + break; + case GL_BLEND: +#if 0 + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + locala, GR_COMBINE_OTHER_TEXTURE, FXFALSE); + if (ifmt == GL_ALPHA) + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + localc, GR_COMBINE_OTHER_NONE, FXFALSE); + else + FX_grColorCombine_NoLock + (GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_LOCAL, localc, GR_COMBINE_OTHER_TEXTURE, + FXTRUE); + ctx->Driver.MultipassFunc = fxMultipassBlend; +#else + if (MESA_VERBOSE & VERBOSE_DRIVER) + fprintf(stderr, "fx Driver: GL_BLEND not yet supported\n"); +#endif + break; + case GL_REPLACE: + if ((ifmt == GL_RGB) || (ifmt == GL_LUMINANCE)) + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + else + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_ONE, + locala, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + + if (ifmt == GL_ALPHA) + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + localc, GR_COMBINE_OTHER_NONE, FXFALSE); + else + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_ONE, + localc, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + break; + case GL_ADD: + if (ifmt == GL_ALPHA || + ifmt == GL_LUMINANCE_ALPHA || + ifmt == GL_RGBA) { + /* product of texel and fragment alpha */ + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + locala, GR_COMBINE_OTHER_TEXTURE, FXFALSE); + } + else if (ifmt == GL_LUMINANCE || ifmt == GL_RGB) { + /* fragment alpha is unchanged */ + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + } + else { + ASSERT(ifmt == GL_INTENSITY); + /* sum of texel and fragment alpha */ + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_ONE, + locala, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + } + if (ifmt == GL_ALPHA) { + /* rgb unchanged */ + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + localc, GR_COMBINE_OTHER_NONE, FXFALSE); + } + else { + /* sum of texel and fragment rgb */ + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_ONE, + localc, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + } + break; + default: + if (MESA_VERBOSE & VERBOSE_DRIVER) + fprintf(stderr, + "fx Driver: %x Texture.EnvMode not yet supported\n", + ctx->Texture.Unit[textureset].EnvMode); + break; + } + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupTextureSingleTMU(...) End\n"); + } +} + +static void +fxSetupTextureSingleTMU(GLcontext * ctx, GLuint textureset) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + BEGIN_BOARD_LOCK(fxMesa); + fxSetupTextureSingleTMU_NoLock(ctx, textureset); + END_BOARD_LOCK(fxMesa); +} + +/************************* Double Texture Set ***************************/ + +static void +fxSetupDoubleTMU_NoLock(fxMesaContext fxMesa, + struct gl_texture_object *tObj0, + struct gl_texture_object *tObj1) +{ +#define T0_NOT_IN_TMU 0x01 +#define T1_NOT_IN_TMU 0x02 +#define T0_IN_TMU0 0x04 +#define T1_IN_TMU0 0x08 +#define T0_IN_TMU1 0x10 +#define T1_IN_TMU1 0x20 + + tfxTexInfo *ti0 = fxTMGetTexInfo(tObj0); + tfxTexInfo *ti1 = fxTMGetTexInfo(tObj1); + GLuint tstate = 0; + int tmu0 = 0, tmu1 = 1; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupDoubleTMU(...)\n"); + } + + /* We shouldn't need to do this. There is something wrong with + mutlitexturing when the TMUs are swapped. So, we're forcing + them to always be loaded correctly. !!! */ + if (ti0->whichTMU == FX_TMU1) + fxTMMoveOutTM_NoLock(fxMesa, tObj0); + if (ti1->whichTMU == FX_TMU0) + fxTMMoveOutTM_NoLock(fxMesa, tObj1); + + if (ti0->isInTM) { + switch (ti0->whichTMU) { + case FX_TMU0: + tstate |= T0_IN_TMU0; + break; + case FX_TMU1: + tstate |= T0_IN_TMU1; + break; + case FX_TMU_BOTH: + tstate |= T0_IN_TMU0 | T0_IN_TMU1; + break; + case FX_TMU_SPLIT: + tstate |= T0_NOT_IN_TMU; + break; + } + } + else + tstate |= T0_NOT_IN_TMU; + + if (ti1->isInTM) { + switch (ti1->whichTMU) { + case FX_TMU0: + tstate |= T1_IN_TMU0; + break; + case FX_TMU1: + tstate |= T1_IN_TMU1; + break; + case FX_TMU_BOTH: + tstate |= T1_IN_TMU0 | T1_IN_TMU1; + break; + case FX_TMU_SPLIT: + tstate |= T1_NOT_IN_TMU; + break; + } + } + else + tstate |= T1_NOT_IN_TMU; + + ti0->lastTimeUsed = fxMesa->texBindNumber; + ti1->lastTimeUsed = fxMesa->texBindNumber; + + /* Move texture maps into TMUs */ + + if (!(((tstate & T0_IN_TMU0) && (tstate & T1_IN_TMU1)) || + ((tstate & T0_IN_TMU1) && (tstate & T1_IN_TMU0)))) { + if (tObj0 == tObj1) + fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU_BOTH); + else { + /* Find the minimal way to correct the situation */ + if ((tstate & T0_IN_TMU0) || (tstate & T1_IN_TMU1)) { + /* We have one in the standard order, setup the other */ + if (tstate & T0_IN_TMU0) { /* T0 is in TMU0, put T1 in TMU1 */ + fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU1); + } + else { + fxTMMoveInTM_NoLock(fxMesa, tObj0, FX_TMU0); + } + /* tmu0 and tmu1 are setup */ + } + else if ((tstate & T0_IN_TMU1) || (tstate & T1_IN_TMU0)) { + /* we have one in the reverse order, setup the other */ + if (tstate & T1_IN_TMU0) { /* T1 is in TMU0, put T0 in TMU1 */ + fxTMMoveInTM_NoLock(fxMesa, tObj0, FX_TMU1); + } + else { + fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU0); + } + tmu0 = 1; + tmu1 = 0; + } + else { /* Nothing is loaded */ + fxTMMoveInTM_NoLock(fxMesa, tObj0, FX_TMU0); + fxTMMoveInTM_NoLock(fxMesa, tObj1, FX_TMU1); + /* tmu0 and tmu1 are setup */ + } + } + } + + if (!fxMesa->haveGlobalPaletteTexture) { + if (ti0->info.format == GR_TEXFMT_P_8) { + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: uploading texture palette TMU0\n"); + } + FX_grTexDownloadTable_NoLock(tmu0, GR_TEXTABLE_PALETTE_6666_EXT, + &(ti0->palette)); + } + + if (ti1->info.format == GR_TEXFMT_P_8) { + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: uploading texture palette TMU1\n"); + } + FX_grTexDownloadTable_NoLock(tmu1, GR_TEXTABLE_PALETTE_6666_EXT, + &(ti1->palette)); + } + } + + FX_grTexSource_NoLock(tmu0, ti0->tm[tmu0]->startAddr, + GR_MIPMAPLEVELMASK_BOTH, &(ti0->info)); + FX_grTexClampMode_NoLock(tmu0, ti0->sClamp, ti0->tClamp); + FX_grTexFilterMode_NoLock(tmu0, ti0->minFilt, ti0->maxFilt); + FX_grTexMipMapMode_NoLock(tmu0, ti0->mmMode, FXFALSE); + + FX_grTexSource_NoLock(tmu1, ti1->tm[tmu1]->startAddr, + GR_MIPMAPLEVELMASK_BOTH, &(ti1->info)); + FX_grTexClampMode_NoLock(tmu1, ti1->sClamp, ti1->tClamp); + FX_grTexFilterMode_NoLock(tmu1, ti1->minFilt, ti1->maxFilt); + FX_grTexMipMapMode_NoLock(tmu1, ti1->mmMode, FXFALSE); + +#undef T0_NOT_IN_TMU +#undef T1_NOT_IN_TMU +#undef T0_IN_TMU0 +#undef T1_IN_TMU0 +#undef T0_IN_TMU1 +#undef T1_IN_TMU1 +} + +static void +fxSetupTextureDoubleTMU_NoLock(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GrCombineLocal_t localc, locala; + tfxTexInfo *ti0, *ti1; + struct gl_texture_object *tObj0 = ctx->Texture.Unit[0].CurrentD[2]; + struct gl_texture_object *tObj1 = ctx->Texture.Unit[1].CurrentD[2]; + GLuint envmode, ifmt, unitsmode; + int tmu0 = 0, tmu1 = 1; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupTextureDoubleTMU(...) Start\n"); + } + + ti0 = fxTMGetTexInfo(tObj0); + fxTexValidate(ctx, tObj0); + + ti1 = fxTMGetTexInfo(tObj1); + fxTexValidate(ctx, tObj1); + + fxSetupDoubleTMU_NoLock(fxMesa, tObj0, tObj1); + + unitsmode = fxGetTexSetConfiguration(ctx, tObj0, tObj1); + + fxMesa->stw_hint_state |= GR_STWHINT_ST_DIFF_TMU1; + FX_grHints_NoLock(GR_HINT_STWHINT, fxMesa->stw_hint_state); + + envmode = unitsmode & FX_UM_E_ENVMODE; + ifmt = unitsmode & FX_UM_E_IFMT; + + if (unitsmode & FX_UM_ALPHA_ITERATED) + locala = GR_COMBINE_LOCAL_ITERATED; + else + locala = GR_COMBINE_LOCAL_CONSTANT; + + if (unitsmode & FX_UM_COLOR_ITERATED) + localc = GR_COMBINE_LOCAL_ITERATED; + else + localc = GR_COMBINE_LOCAL_CONSTANT; + + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_TEXTURE)) + fprintf(stderr, "fxMesa: fxSetupTextureDoubleTMU, envmode is %s/%s\n", + gl_lookup_enum_by_nr(ctx->Texture.Unit[0].EnvMode), + gl_lookup_enum_by_nr(ctx->Texture.Unit[1].EnvMode)); + + + if ((ti0->whichTMU == FX_TMU1) || (ti1->whichTMU == FX_TMU0)) { + tmu0 = 1; + tmu1 = 0; + } + fxMesa->tmuSrc = FX_TMU_BOTH; + switch (envmode) { + case (FX_UM_E0_MODULATE | FX_UM_E1_MODULATE): + { + GLboolean isalpha[FX_NUM_TMU]; + + if (ti0->baseLevelInternalFormat == GL_ALPHA) + isalpha[tmu0] = GL_TRUE; + else + isalpha[tmu0] = GL_FALSE; + + if (ti1->baseLevelInternalFormat == GL_ALPHA) + isalpha[tmu1] = GL_TRUE; + else + isalpha[tmu1] = GL_FALSE; + + if (isalpha[FX_TMU1]) + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_ZERO, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXTRUE, + FXFALSE); + else + FX_grTexCombine_NoLock(GR_TMU1, GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, + FXFALSE); + + if (isalpha[FX_TMU0]) + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_ONE, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, FXFALSE, + FXFALSE); + else + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, FXFALSE, + FXFALSE); + + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + localc, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + locala, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + break; + } + case (FX_UM_E0_REPLACE | FX_UM_E1_BLEND): /* Only for GLQuake */ + if (tmu1 == FX_TMU1) { + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXTRUE, FXFALSE); + + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, FXFALSE, FXFALSE); + } + else { + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE); + + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_ONE_MINUS_LOCAL, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_ONE_MINUS_LOCAL, + FXFALSE, FXFALSE); + } + + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_ONE, + localc, GR_COMBINE_OTHER_TEXTURE, FXFALSE); + break; + case (FX_UM_E0_REPLACE | FX_UM_E1_MODULATE): /* Quake 2 and 3 */ + if (tmu1 == FX_TMU1) { + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_ZERO, + GR_COMBINE_FACTOR_NONE, FXFALSE, FXTRUE); + + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, FXFALSE, FXFALSE); + + } + else { + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, FXFALSE); + + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_LOCAL, + GR_COMBINE_FUNCTION_BLEND_OTHER, + GR_COMBINE_FACTOR_ONE, FXFALSE, FXFALSE); + } + + if (ti0->baseLevelInternalFormat == GL_RGB) + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + else + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_ONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + + + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_ONE, + localc, GR_COMBINE_OTHER_TEXTURE, FXFALSE); + break; + + + case (FX_UM_E0_MODULATE | FX_UM_E1_ADD): /* Quake 3 Sky */ + { + GLboolean isalpha[FX_NUM_TMU]; + + if (ti0->baseLevelInternalFormat == GL_ALPHA) + isalpha[tmu0] = GL_TRUE; + else + isalpha[tmu0] = GL_FALSE; + + if (ti1->baseLevelInternalFormat == GL_ALPHA) + isalpha[tmu1] = GL_TRUE; + else + isalpha[tmu1] = GL_FALSE; + + if (isalpha[FX_TMU1]) + FX_grTexCombine_NoLock(GR_TMU1, + GR_COMBINE_FUNCTION_ZERO, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXTRUE, + FXFALSE); + else + FX_grTexCombine_NoLock(GR_TMU1, GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, FXFALSE, + FXFALSE); + + if (isalpha[FX_TMU0]) + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_ONE, + GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_ONE, FXFALSE, + FXFALSE); + else + FX_grTexCombine_NoLock(GR_TMU0, + GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_ONE, + GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + GR_COMBINE_FACTOR_ONE, FXFALSE, + FXFALSE); + + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + localc, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_SCALE_OTHER, + GR_COMBINE_FACTOR_LOCAL, + locala, GR_COMBINE_OTHER_TEXTURE, + FXFALSE); + break; + } + default: + fprintf(stderr, "Unexpected dual texture mode encountered\n"); + break; + } + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupTextureDoubleTMU(...) End\n"); + } +} + +/************************* No Texture ***************************/ + +static void +fxSetupTextureNone_NoLock(GLcontext * ctx) +{ + /*fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;*/ + GrCombineLocal_t localc, locala; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupTextureNone(...)\n"); + } + + if ((ctx->Light.ShadeModel == GL_SMOOTH) || 1 || + (ctx->Point.SmoothFlag) || + (ctx->Line.SmoothFlag) || + (ctx->Polygon.SmoothFlag)) locala = GR_COMBINE_LOCAL_ITERATED; + else + locala = GR_COMBINE_LOCAL_CONSTANT; + + if (ctx->Light.ShadeModel == GL_SMOOTH || 1) + localc = GR_COMBINE_LOCAL_ITERATED; + else + localc = GR_COMBINE_LOCAL_CONSTANT; + + FX_grAlphaCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + locala, GR_COMBINE_OTHER_NONE, FXFALSE); + + FX_grColorCombine_NoLock(GR_COMBINE_FUNCTION_LOCAL, + GR_COMBINE_FACTOR_NONE, + localc, GR_COMBINE_OTHER_NONE, FXFALSE); +} + +/************************************************************************/ +/************************** Texture Mode SetUp **************************/ +/************************************************************************/ + +static void +fxSetupTexture_NoLock(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint tex2Denabled; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxSetupTexture(...)\n"); + } + + /* Disable multipass texturing. + */ + ctx->Driver.MultipassFunc = 0; + + /* Texture Combine, Color Combine and Alpha Combine. + */ + tex2Denabled = (ctx->Texture.ReallyEnabled & TEXTURE0_2D); + + if (fxMesa->emulateTwoTMUs) + tex2Denabled |= (ctx->Texture.ReallyEnabled & TEXTURE1_2D); + + switch (tex2Denabled) { + case TEXTURE0_2D: + fxSetupTextureSingleTMU_NoLock(ctx, 0); + break; + case TEXTURE1_2D: + fxSetupTextureSingleTMU_NoLock(ctx, 1); + break; + case (TEXTURE0_2D | TEXTURE1_2D): + if (fxMesa->haveTwoTMUs) + fxSetupTextureDoubleTMU_NoLock(ctx); + else { + if (MESA_VERBOSE & VERBOSE_DRIVER) + fprintf(stderr, "fxmesa: enabling fake multitexture\n"); + + fxSetupTextureSingleTMU_NoLock(ctx, 0); + ctx->Driver.MultipassFunc = fxMultipassTexture; + } + break; + default: + fxSetupTextureNone_NoLock(ctx); + break; + } +} + +static void +fxSetupTexture(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + BEGIN_BOARD_LOCK(fxMesa); + fxSetupTexture_NoLock(ctx); + END_BOARD_LOCK(fxMesa); +} + +/************************************************************************/ +/**************************** Blend SetUp *******************************/ +/************************************************************************/ + +void +fxDDBlendFunc(GLcontext * ctx, GLenum sfactor, GLenum dfactor) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + tfxUnitsState *us = &fxMesa->unitsState; + GrAlphaBlendFnc_t sfact, dfact, asfact, adfact; + + /* From the Glide documentation: + For alpha source and destination blend function factor + parameters, Voodoo Graphics supports only + GR_BLEND_ZERO and GR_BLEND_ONE. + */ + + switch (sfactor) { + case GL_ZERO: + asfact = sfact = GR_BLEND_ZERO; + break; + case GL_ONE: + asfact = sfact = GR_BLEND_ONE; + break; + case GL_DST_COLOR: + sfact = GR_BLEND_DST_COLOR; + asfact = GR_BLEND_ONE; + break; + case GL_ONE_MINUS_DST_COLOR: + sfact = GR_BLEND_ONE_MINUS_DST_COLOR; + asfact = GR_BLEND_ONE; + break; + case GL_SRC_ALPHA: + sfact = GR_BLEND_SRC_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_ONE_MINUS_SRC_ALPHA: + sfact = GR_BLEND_ONE_MINUS_SRC_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_DST_ALPHA: + sfact = GR_BLEND_DST_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_ONE_MINUS_DST_ALPHA: + sfact = GR_BLEND_ONE_MINUS_DST_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_SRC_ALPHA_SATURATE: + sfact = GR_BLEND_ALPHA_SATURATE; + asfact = GR_BLEND_ONE; + break; + case GL_SRC_COLOR: + case GL_ONE_MINUS_SRC_COLOR: + /* USELESS */ + asfact = sfact = GR_BLEND_ONE; + break; + default: + asfact = sfact = GR_BLEND_ONE; + break; + } + + if ((sfact != us->blendSrcFuncRGB) || (asfact != us->blendSrcFuncAlpha)) { + us->blendSrcFuncRGB = sfact; + us->blendSrcFuncAlpha = asfact; + fxMesa->new_state |= FX_NEW_BLEND; + ctx->Driver.RenderStart = fxSetupFXUnits; + } + + switch (dfactor) { + case GL_ZERO: + adfact = dfact = GR_BLEND_ZERO; + break; + case GL_ONE: + adfact = dfact = GR_BLEND_ONE; + break; + case GL_SRC_COLOR: + dfact = GR_BLEND_SRC_COLOR; + adfact = GR_BLEND_ZERO; + break; + case GL_ONE_MINUS_SRC_COLOR: + dfact = GR_BLEND_ONE_MINUS_SRC_COLOR; + adfact = GR_BLEND_ZERO; + break; + case GL_SRC_ALPHA: + dfact = GR_BLEND_SRC_ALPHA; + adfact = GR_BLEND_ZERO; + break; + case GL_ONE_MINUS_SRC_ALPHA: + dfact = GR_BLEND_ONE_MINUS_SRC_ALPHA; + adfact = GR_BLEND_ZERO; + break; + case GL_DST_ALPHA: + /* dfact=GR_BLEND_DST_ALPHA; */ + /* We can't do DST_ALPHA */ + dfact = GR_BLEND_ONE; + adfact = GR_BLEND_ZERO; + break; + case GL_ONE_MINUS_DST_ALPHA: + /* dfact=GR_BLEND_ONE_MINUS_DST_ALPHA; */ + /* We can't do DST_ALPHA */ + dfact = GR_BLEND_ZERO; + adfact = GR_BLEND_ZERO; + break; + case GL_SRC_ALPHA_SATURATE: + case GL_DST_COLOR: + case GL_ONE_MINUS_DST_COLOR: + /* USELESS */ + adfact = dfact = GR_BLEND_ZERO; + break; + default: + adfact = dfact = GR_BLEND_ZERO; + break; + } + + if ((dfact != us->blendDstFuncRGB) || (adfact != us->blendDstFuncAlpha)) { + us->blendDstFuncRGB = dfact; + us->blendDstFuncAlpha = adfact; + fxMesa->new_state |= FX_NEW_BLEND; + ctx->Driver.RenderStart = fxSetupFXUnits; + } +} + + +/* XXX not done yet, but it looks do-able in the hardware */ +void +fxDDBlendFuncSeparate(GLcontext *ctx, + GLenum sfactorRGB, GLenum sfactorA, + GLenum dfactorRGB, GLenum dfactorA) +{ +#if 000 + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + tfxUnitsState *us = &fxMesa->unitsState; + GrAlphaBlendFnc_t sfact, dfact, asfact, adfact; + + /* From the Glide documentation: + For alpha source and destination blend function factor + parameters, Voodoo Graphics supports only + GR_BLEND_ZERO and GR_BLEND_ONE. + */ + + switch (sfactor) { + case GL_ZERO: + asfact = sfact = GR_BLEND_ZERO; + break; + case GL_ONE: + asfact = sfact = GR_BLEND_ONE; + break; + case GL_DST_COLOR: + sfact = GR_BLEND_DST_COLOR; + asfact = GR_BLEND_ONE; + break; + case GL_ONE_MINUS_DST_COLOR: + sfact = GR_BLEND_ONE_MINUS_DST_COLOR; + asfact = GR_BLEND_ONE; + break; + case GL_SRC_ALPHA: + sfact = GR_BLEND_SRC_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_ONE_MINUS_SRC_ALPHA: + sfact = GR_BLEND_ONE_MINUS_SRC_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_DST_ALPHA: + sfact = GR_BLEND_DST_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_ONE_MINUS_DST_ALPHA: + sfact = GR_BLEND_ONE_MINUS_DST_ALPHA; + asfact = GR_BLEND_ONE; + break; + case GL_SRC_ALPHA_SATURATE: + sfact = GR_BLEND_ALPHA_SATURATE; + asfact = GR_BLEND_ONE; + break; + case GL_SRC_COLOR: + case GL_ONE_MINUS_SRC_COLOR: + /* USELESS */ + asfact = sfact = GR_BLEND_ONE; + break; + default: + asfact = sfact = GR_BLEND_ONE; + break; + } + + if ((sfact != us->blendSrcFuncRGB) || (asfact != us->blendSrcFuncAlpha)) { + us->blendSrcFuncRGB = sfact; + us->blendSrcFuncAlpha = asfact; + fxMesa->new_state |= FX_NEW_BLEND; + ctx->Driver.RenderStart = fxSetupFXUnits; + } + + switch (dfactor) { + case GL_ZERO: + adfact = dfact = GR_BLEND_ZERO; + break; + case GL_ONE: + adfact = dfact = GR_BLEND_ONE; + break; + case GL_SRC_COLOR: + dfact = GR_BLEND_SRC_COLOR; + adfact = GR_BLEND_ZERO; + break; + case GL_ONE_MINUS_SRC_COLOR: + dfact = GR_BLEND_ONE_MINUS_SRC_COLOR; + adfact = GR_BLEND_ZERO; + break; + case GL_SRC_ALPHA: + dfact = GR_BLEND_SRC_ALPHA; + adfact = GR_BLEND_ZERO; + break; + case GL_ONE_MINUS_SRC_ALPHA: + dfact = GR_BLEND_ONE_MINUS_SRC_ALPHA; + adfact = GR_BLEND_ZERO; + break; + case GL_DST_ALPHA: + /* dfact=GR_BLEND_DST_ALPHA; */ + /* We can't do DST_ALPHA */ + dfact = GR_BLEND_ONE; + adfact = GR_BLEND_ZERO; + break; + case GL_ONE_MINUS_DST_ALPHA: + /* dfact=GR_BLEND_ONE_MINUS_DST_ALPHA; */ + /* We can't do DST_ALPHA */ + dfact = GR_BLEND_ZERO; + adfact = GR_BLEND_ZERO; + break; + case GL_SRC_ALPHA_SATURATE: + case GL_DST_COLOR: + case GL_ONE_MINUS_DST_COLOR: + /* USELESS */ + adfact = dfact = GR_BLEND_ZERO; + break; + default: + adfact = dfact = GR_BLEND_ZERO; + break; + } + + if ((dfact != us->blendDstFuncRGB) || (adfact != us->blendDstFuncAlpha)) { + us->blendDstFuncRGB = dfact; + us->blendDstFuncAlpha = adfact; + fxMesa->new_state |= FX_NEW_BLEND; + ctx->Driver.RenderStart = fxSetupFXUnits; + } +#endif +} + + +static void +fxSetupBlend(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxUnitsState *us = &fxMesa->unitsState; + + if (us->blendEnabled) + FX_grAlphaBlendFunction(us->blendSrcFuncRGB, us->blendDstFuncRGB, + us->blendSrcFuncAlpha, us->blendDstFuncAlpha); + else + FX_grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO, + GR_BLEND_ONE, GR_BLEND_ZERO); +} + + +/************************************************************************/ +/************************** Alpha Test SetUp ****************************/ +/************************************************************************/ + +void +fxDDAlphaFunc(GLcontext * ctx, GLenum func, GLclampf ref) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxUnitsState *us = &fxMesa->unitsState; + GrCmpFnc_t newfunc; + + switch (func) { + case GL_NEVER: + newfunc = GR_CMP_NEVER; + break; + case GL_LESS: + newfunc = GR_CMP_LESS; + break; + case GL_EQUAL: + newfunc = GR_CMP_EQUAL; + break; + case GL_LEQUAL: + newfunc = GR_CMP_LEQUAL; + break; + case GL_GREATER: + newfunc = GR_CMP_GREATER; + break; + case GL_NOTEQUAL: + newfunc = GR_CMP_NOTEQUAL; + break; + case GL_GEQUAL: + newfunc = GR_CMP_GEQUAL; + break; + case GL_ALWAYS: + newfunc = GR_CMP_ALWAYS; + break; + default: + gl_problem(ctx, "fx Driver: internal error in fxDDAlphaFunc()\n"); + return; + } + + if (newfunc != us->alphaTestFunc) { + us->alphaTestFunc = newfunc; + fxMesa->new_state |= FX_NEW_ALPHA; + ctx->Driver.RenderStart = fxSetupFXUnits; + } + + if (ctx->Color.AlphaRef != us->alphaTestRefValue) { + us->alphaTestRefValue = ctx->Color.AlphaRef; + fxMesa->new_state |= FX_NEW_ALPHA; + ctx->Driver.RenderStart = fxSetupFXUnits; + } +} + +static void +fxSetupAlphaTest(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + tfxUnitsState *us = &fxMesa->unitsState; + + if (us->alphaTestEnabled) { + FX_grAlphaTestFunction(fxMesa, us->alphaTestFunc); + FX_grAlphaTestReferenceValue(fxMesa, us->alphaTestRefValue); + } + else + FX_grAlphaTestFunction(fxMesa, GR_CMP_ALWAYS); +} + + +/* + * Evaluate all depth-test state and make the Glide calls. + */ +static void +fxSetupDepthTest(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + if (ctx->Depth.Test) { + GrCmpFnc_t dfunc; + switch (ctx->Depth.Func) { + case GL_NEVER: + dfunc = GR_CMP_NEVER; + break; + case GL_LESS: + dfunc = GR_CMP_LESS; + break; + case GL_GEQUAL: + dfunc = GR_CMP_GEQUAL; + break; + case GL_LEQUAL: + dfunc = GR_CMP_LEQUAL; + break; + case GL_GREATER: + dfunc = GR_CMP_GREATER; + break; + case GL_NOTEQUAL: + dfunc = GR_CMP_NOTEQUAL; + break; + case GL_EQUAL: + dfunc = GR_CMP_EQUAL; + break; + case GL_ALWAYS: + dfunc = GR_CMP_ALWAYS; + break; + default: + gl_problem(ctx, "bad depth mode in fxSetupDepthTest"); + dfunc = GR_CMP_ALWAYS; + } + FX_grDepthBufferFunction(fxMesa, dfunc); + FX_grDepthMask(fxMesa, ctx->Depth.Mask); + } + else { + /* depth test always passes, don't update Z buffer */ + FX_grDepthBufferFunction(fxMesa, GR_CMP_ALWAYS); + FX_grDepthMask(fxMesa, FXFALSE); + } +} + + +/* + * Evaluate all stencil state and make the Glide calls. + */ +GrStencil_t +fxConvertGLStencilOp(GLenum op) +{ + switch (op) { + case GL_KEEP: + return GR_STENCILOP_KEEP; + case GL_ZERO: + return GR_STENCILOP_ZERO; + case GL_REPLACE: + return GR_STENCILOP_REPLACE; + case GL_INCR: + return GR_STENCILOP_INCR_CLAMP; + case GL_DECR: + return GR_STENCILOP_DECR_CLAMP; + case GL_INVERT: + return GR_STENCILOP_INVERT; + default: + gl_problem(NULL, "bad stencil op in fxConvertGLStencilOp"); + } + return GR_STENCILOP_KEEP; /* never get, silence compiler warning */ +} + +/* + * This function is called just before any rendering is done. + * It will validate the stencil parameters. + */ +static void +fxSetupStencilTest(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + if (fxMesa->haveHwStencil) { + if (ctx->Stencil.Enabled) { + GrStencil_t sfail = fxConvertGLStencilOp(ctx->Stencil.FailFunc); + GrStencil_t zfail = fxConvertGLStencilOp(ctx->Stencil.ZFailFunc); + GrStencil_t zpass = fxConvertGLStencilOp(ctx->Stencil.ZPassFunc); + FX_grStencilOp(fxMesa, sfail, zfail, zpass); + FX_grStencilFunc(fxMesa, ctx->Stencil.Function - GL_NEVER, + ctx->Stencil.Ref, ctx->Stencil.ValueMask); + FX_grStencilMask(fxMesa, ctx->Stencil.WriteMask); + FX_grEnable(fxMesa, GR_STENCIL_MODE_EXT); + } + else { + FX_grDisable(fxMesa, GR_STENCIL_MODE_EXT); + } + } +} + + +/* + * Set the state so that stencil is either enabled or disabled. + * This is called from Mesa only. Glide is invoked at + * setup time, not now. + */ +static void +fxDDEnableStencil(GLcontext * ctx, GLboolean state) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + (void) state; + fxMesa->new_state |= FX_NEW_STENCIL; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + + +/************************************************************************/ +/**************************** Color Mask SetUp **************************/ +/************************************************************************/ + +GLboolean +fxDDColorMask(GLcontext *ctx, + GLboolean r, GLboolean g, GLboolean b, GLboolean a) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + fxMesa->new_state |= FX_NEW_COLOR_MASK; + ctx->Driver.RenderStart = fxSetupFXUnits; + (void) r; + (void) g; + (void) b; + (void) a; + return GL_FALSE; +} + +static void +fxSetupColorMask(GLcontext *ctx) +{ + if (ctx->Color.DrawBuffer == GL_NONE) { + FX_grColorMask(ctx, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + } + else { + fxMesaContext fxMesa = FX_CONTEXT(ctx); + /* XXX need to call grRenderBuffer to work around strange mask bug */ + FX_grRenderBuffer(fxMesa, fxMesa->currentFB); + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + } +} + + +/************************************************************************/ +/**************************** Fog Mode SetUp ****************************/ +/************************************************************************/ + +/* + * This is called during state update in order to update the Glide fog state. + */ +static void +fxSetupFog(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + if (ctx->Fog.Enabled && ctx->FogMode == FOG_FRAGMENT) { + + /* update fog color */ + GLubyte col[4]; + col[0] = (unsigned int) (255 * ctx->Fog.Color[0]); + col[1] = (unsigned int) (255 * ctx->Fog.Color[1]); + col[2] = (unsigned int) (255 * ctx->Fog.Color[2]); + col[3] = (unsigned int) (255 * ctx->Fog.Color[3]); + FX_grFogColorValue(fxMesa, FXCOLOR4(col)); + + if (fxMesa->fogTableMode != ctx->Fog.Mode || + fxMesa->fogDensity != ctx->Fog.Density || + fxMesa->fogStart != ctx->Fog.Start || + fxMesa->fogEnd != ctx->Fog.End) { + /* reload the fog table */ + switch (ctx->Fog.Mode) { + case GL_LINEAR: + guFogGenerateLinear(fxMesa->fogTable, ctx->Fog.Start, + ctx->Fog.End); + break; + case GL_EXP: + guFogGenerateExp(fxMesa->fogTable, ctx->Fog.Density); + break; + case GL_EXP2: + guFogGenerateExp2(fxMesa->fogTable, ctx->Fog.Density); + break; + default: + ; + } + fxMesa->fogTableMode = ctx->Fog.Mode; + fxMesa->fogDensity = ctx->Fog.Density; + fxMesa->fogStart = ctx->Fog.Start; + fxMesa->fogEnd = ctx->Fog.End; + } + + FX_grFogTable(fxMesa, fxMesa->fogTable); + FX_grFogMode(fxMesa, GR_FOG_WITH_TABLE); + } + else { + FX_grFogMode(fxMesa, GR_FOG_DISABLE); + } +} + +void +fxDDFogfv(GLcontext * ctx, GLenum pname, const GLfloat * params) +{ + FX_CONTEXT(ctx)->new_state |= FX_NEW_FOG; + ctx->Driver.RenderStart = fxSetupFXUnits; /* XXX why is this here? */ +} + +/************************************************************************/ +/************************** Scissor Test SetUp **************************/ +/************************************************************************/ + +/* This routine is used in managing the lock state, and therefore can't lock */ +void +fxSetScissorValues(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + int xmin, xmax, ymin, ymax; + + if (ctx->Scissor.Enabled) { + xmin = ctx->Scissor.X; + xmax = ctx->Scissor.X + ctx->Scissor.Width; + ymin = ctx->Scissor.Y; + ymax = ctx->Scissor.Y + ctx->Scissor.Height; + } + else { + xmin = 0; + ymin = 0; + xmax = fxMesa->width; + ymax = fxMesa->height; + } + /* translate to screen coords */ + xmin += fxMesa->x_offset; + xmax += fxMesa->x_offset; + ymin += fxMesa->y_delta; + ymax += fxMesa->y_delta; + + /* intersect scissor region with first clip rect */ + if (xmin < fxMesa->clipMinX) + xmin = fxMesa->clipMinX; + else if (xmin > fxMesa->clipMaxX) + xmin = fxMesa->clipMaxX; + + if (xmax > fxMesa->clipMaxX) + xmax = fxMesa->clipMaxX; + + if (ymin < fxMesa->screen_height - fxMesa->clipMaxY) + ymin = fxMesa->screen_height - fxMesa->clipMaxY; + else if (ymin > fxMesa->screen_height - fxMesa->clipMinY) + ymin = fxMesa->screen_height - fxMesa->clipMinY; + + if (ymax > fxMesa->screen_height - fxMesa->clipMinY) + ymax = fxMesa->screen_height - fxMesa->clipMinY; + + /* prevent wrap-around problems */ + if (xmax < xmin) + xmax = xmin; + if (ymax < ymin) + ymax = ymin; + + FX_grClipWindow_NoLock(xmin, ymin, xmax, ymax); +} + +static void +fxSetupScissor(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + if (!fxMesa->needClip) { + BEGIN_BOARD_LOCK(fxMesa); + fxSetScissorValues(ctx); + END_BOARD_LOCK(fxMesa); + } +} + +void +fxDDScissor(GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h) +{ + FX_CONTEXT(ctx)->new_state |= FX_NEW_SCISSOR; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +/************************************************************************/ +/*************************** Cull mode setup ****************************/ +/************************************************************************/ + + +void +fxDDCullFace(GLcontext * ctx, GLenum mode) +{ + (void) mode; + FX_CONTEXT(ctx)->new_state |= FX_NEW_CULL; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + +void +fxDDFrontFace(GLcontext * ctx, GLenum mode) +{ + (void) mode; + FX_CONTEXT(ctx)->new_state |= FX_NEW_CULL; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + + +static void +fxSetupCull(GLcontext * ctx) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + if (ctx->Polygon.CullFlag) { + switch (ctx->Polygon.CullFaceMode) { + case GL_BACK: + if (ctx->Polygon.FrontFace == GL_CCW) + FX_CONTEXT(ctx)->cullMode = GR_CULL_NEGATIVE; + else + FX_CONTEXT(ctx)->cullMode = GR_CULL_POSITIVE; + break; + case GL_FRONT: + if (ctx->Polygon.FrontFace == GL_CCW) + FX_CONTEXT(ctx)->cullMode = GR_CULL_POSITIVE; + else + FX_CONTEXT(ctx)->cullMode = GR_CULL_NEGATIVE; + break; + case GL_FRONT_AND_BACK: + FX_CONTEXT(ctx)->cullMode = GR_CULL_DISABLE; + break; + default: + break; + } + } + else { + FX_CONTEXT(ctx)->cullMode = GR_CULL_DISABLE; + } + FX_grCullMode(fxMesa, FX_CONTEXT(ctx)->cullMode); +} + + +/************************************************************************/ +/****************************** DD Enable ******************************/ +/************************************************************************/ + +void +fxDDEnable(GLcontext * ctx, GLenum cap, GLboolean state) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxUnitsState *us = &fxMesa->unitsState; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDEnable(...)\n"); + } + + switch (cap) { + case GL_ALPHA_TEST: + if (state != us->alphaTestEnabled) { + us->alphaTestEnabled = state; + fxMesa->new_state |= FX_NEW_ALPHA; + ctx->Driver.RenderStart = fxSetupFXUnits; + } + break; + case GL_BLEND: + if (state != us->blendEnabled) { + us->blendEnabled = state; + fxMesa->new_state |= FX_NEW_BLEND; + ctx->Driver.RenderStart = fxSetupFXUnits; + } + break; + case GL_DEPTH_TEST: + fxMesa->new_state |= FX_NEW_DEPTH; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + case GL_DITHER: + if (state) + FX_grDitherMode(fxMesa, GR_DITHER_4x4); + else + FX_grDitherMode(fxMesa, GR_DITHER_DISABLE); + break; + case GL_SCISSOR_TEST: + fxMesa->new_state |= FX_NEW_SCISSOR; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + case GL_SHARED_TEXTURE_PALETTE_EXT: + fxDDTexUseGlbPalette(ctx, state); + break; + case GL_FOG: + fxMesa->new_state |= FX_NEW_FOG; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + case GL_CULL_FACE: + fxMesa->new_state |= FX_NEW_CULL; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + case GL_LINE_SMOOTH: + case GL_LINE_STIPPLE: + case GL_POINT_SMOOTH: + case GL_POLYGON_SMOOTH: + case GL_TEXTURE_2D: + fxMesa->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + case GL_STENCIL_TEST: + fxMesa->new_state |= FX_NEW_STENCIL; + ctx->Driver.RenderStart = fxSetupFXUnits; + break; + default: + ; /* no-op */ + } +} + + +#if 0 +/* + Multipass to do GL_BLEND texture functions + Cf*(1-Ct) has already been written to the buffer during the first pass + Cc*Ct gets written during the second pass (in this function) + Everything gets reset in the third call (in this function) +*/ +static GLboolean +fxMultipassBlend(struct vertex_buffer *VB, GLuint pass) +{ + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + switch (pass) { + case 1: + /* Add Cc*Ct */ + fxMesa->restoreUnitsState = fxMesa->unitsState; + if (ctx->Depth.Mask) { + /* We don't want to check or change the depth buffers */ + switch (ctx->Depth.Func) { + case GL_NEVER: + case GL_ALWAYS: + break; + default: + fxDDDepthFunc(ctx, GL_EQUAL); + break; + } + fxDDDepthMask(ctx, FALSE); + } + /* + * Disable stencil as well. + */ + if (ctx->Stencil.Enabled) { + fxDDEnableStencil(ctx, GL_FALSE); + } + /* Enable Cc*Ct mode */ + /* XXX Set the Constant Color ? */ + fxDDEnable(ctx, GL_BLEND, GL_TRUE); + fxDDBlendFunc(ctx, XXX, XXX); + fxSetupTextureSingleTMU(ctx, XXX); + fxSetupBlend(ctx); + fxSetupDepthTest(ctx); + break; + + case 2: + /* Reset everything back to normal */ + fxMesa->unitsState = fxMesa->restoreUnitsState; + fxMesa->setupdone &= XXX; + fxSetupTextureSingleTMU(ctx, XXX); + fxSetupBlend(ctx); + fxSetupDepthTest(ctx); + fxSetupStencilText(ctx); + break; + } + + return pass == 1; +} +#endif + +/************************************************************************/ +/******************** Fake Multitexture Support *************************/ +/************************************************************************/ + +/* Its considered cheeky to try to fake ARB multitexture by doing + * multipass rendering, because it is not possible to emulate the full + * spec in this way. The fact is that the voodoo 2 supports only a + * subset of the possible multitexturing modes, and it is possible to + * support almost the same subset using multipass blending on the + * voodoo 1. In all other cases for both voodoo 1 and 2, we fall back + * to software rendering, satisfying the spec if not the user. + */ +static GLboolean +fxMultipassTexture(struct vertex_buffer *VB, GLuint pass) +{ + GLcontext *ctx = VB->ctx; + fxVertex *v = FX_DRIVER_DATA(VB)->verts; + fxVertex *last = FX_DRIVER_DATA(VB)->last_vert; + fxMesaContext fxMesa = FX_CONTEXT(ctx); + + switch (pass) { + case 1: + if (MESA_VERBOSE & + (VERBOSE_DRIVER | VERBOSE_PIPELINE | VERBOSE_TEXTURE)) + fprintf(stderr, "fxmesa: Second texture pass\n"); + + for (; v != last; v++) { + v->f[S0COORD] = v->f[S1COORD]; + v->f[T0COORD] = v->f[T1COORD]; + } + + fxMesa->restoreUnitsState = fxMesa->unitsState; + fxMesa->tmu_source[0] = 1; + + if (ctx->Depth.Mask) { + switch (ctx->Depth.Func) { + case GL_NEVER: + case GL_ALWAYS: + break; + default: + /*fxDDDepthFunc( ctx, GL_EQUAL ); */ + FX_grDepthBufferFunction(fxMesa, GR_CMP_EQUAL); + break; + } + + /*fxDDDepthMask( ctx, GL_FALSE ); */ + FX_grDepthMask(fxMesa, FXFALSE); + } + fxDDEnableStencil(ctx, GL_FALSE); + if (ctx->Texture.Unit[1].EnvMode == GL_MODULATE) { + fxDDEnable(ctx, GL_BLEND, GL_TRUE); + fxDDBlendFunc(ctx, GL_DST_COLOR, GL_ZERO); + } + + fxSetupTextureSingleTMU(ctx, 1); + fxSetupBlend(ctx); + fxSetupDepthTest(ctx); + break; + + case 2: + /* Restore original state. + */ + fxMesa->tmu_source[0] = 0; + fxMesa->unitsState = fxMesa->restoreUnitsState; + fxMesa->setupdone &= ~SETUP_TMU0; + fxSetupTextureSingleTMU(ctx, 0); + fxSetupBlend(ctx); + fxSetupDepthTest(ctx); + fxSetupStencilTest(ctx); + break; + } + + return pass == 1; +} + + +/************************************************************************/ +/************************** Changes to units state **********************/ +/************************************************************************/ + + +/* All units setup is handled under texture setup. + */ +void +fxDDShadeModel(GLcontext * ctx, GLenum mode) +{ + FX_CONTEXT(ctx)->new_state |= FX_NEW_TEXTURING; + ctx->Driver.RenderStart = fxSetupFXUnits; +} + + + +/************************************************************************/ +/****************************** Units SetUp *****************************/ +/************************************************************************/ +static void +gl_print_fx_state_flags(const char *msg, GLuint flags) +{ + fprintf(stderr, + "%s: (0x%x) %s%s%s%s%s%s%s\n", + msg, + flags, + (flags & FX_NEW_TEXTURING) ? "texture, " : "", + (flags & FX_NEW_BLEND) ? "blend, " : "", + (flags & FX_NEW_ALPHA) ? "alpha, " : "", + (flags & FX_NEW_FOG) ? "fog, " : "", + (flags & FX_NEW_SCISSOR) ? "scissor, " : "", + (flags & FX_NEW_COLOR_MASK) ? "colormask, " : "", + (flags & FX_NEW_CULL) ? "cull, " : ""); +} + +void +fxSetupFXUnits(GLcontext * ctx) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint newstate = fxMesa->new_state; + + if (MESA_VERBOSE & VERBOSE_DRIVER) + gl_print_fx_state_flags("fxmesa: fxSetupFXUnits", newstate); + + if (newstate) { + if (newstate & FX_NEW_TEXTURING) + fxSetupTexture(ctx); + + if (newstate & FX_NEW_BLEND) + fxSetupBlend(ctx); + + if (newstate & FX_NEW_ALPHA) + fxSetupAlphaTest(ctx); + + if (newstate & FX_NEW_DEPTH) + fxSetupDepthTest(ctx); + + if (newstate & FX_NEW_STENCIL) + fxSetupStencilTest(ctx); + + if (newstate & FX_NEW_FOG) + fxSetupFog(ctx); + + if (newstate & FX_NEW_SCISSOR) + fxSetupScissor(ctx); + + if (newstate & FX_NEW_COLOR_MASK) + fxSetupColorMask(ctx); + + if (newstate & FX_NEW_CULL) + fxSetupCull(ctx); + fxMesa->new_state = 0; +/* ctx->Driver.RenderStart = 0; */ + } +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxsetup.h b/xc/lib/GL/mesa/src/drv/tdfx/fxsetup.h new file mode 100644 index 000000000..650392a11 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxsetup.h @@ -0,0 +1,34 @@ +#ifndef FXSETUP_H +#define FXSETUP_H + + +extern void fxDDEnable(GLcontext *, GLenum, GLboolean); + +extern void fxDDAlphaFunc(GLcontext *, GLenum, GLclampf); + +extern void fxDDBlendFunc(GLcontext *, GLenum, GLenum); + +extern void fxDDBlendFuncSeparate(GLcontext *ctx, + GLenum sfactorRGB, GLenum sfactorA, + GLenum dfactorRGB, GLenum dfactorA); + +extern GrStencil_t fxConvertGLStencilOp(GLenum op); + +extern void fxDDScissor(GLcontext *ctx, + GLint x, GLint y, GLsizei w, GLsizei h); + +extern void fxDDFogfv(GLcontext *ctx, GLenum pname, const GLfloat * params); + +extern GLboolean fxDDColorMask(GLcontext *ctx, + GLboolean r, GLboolean g, + GLboolean b, GLboolean a); + +extern void fxDDShadeModel(GLcontext * ctx, GLenum mode); + +extern void fxDDCullFace(GLcontext * ctx, GLenum mode); + +extern void fxDDFrontFace(GLcontext * ctx, GLenum mode); + +extern void fxSetupFXUnits(GLcontext *); + +#endif diff --git a/xc/extras/Mesa/src/FX/fxstripdet.c b/xc/lib/GL/mesa/src/drv/tdfx/fxstripdet.c index bc21234b6..0d3b6fec3 100644 --- a/xc/extras/Mesa/src/FX/fxstripdet.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxstripdet.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -43,34 +41,31 @@ */ -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif -#if defined(FX) && defined(FX_GLIDE3) - #include "fxdrv.h" #include "vbcull.h" - -#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) + +#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) #define STRIP1(u,v) ((u0 == v0) && (u2 == v1)) #define LOCAL_VARS fxVertex* gWin = FX_DRIVER_DATA(VB)->verts; \ - GrVertex** sb = FX_DRIVER_DATA(VB)->strips_b; - + GrVertex** sb = FX_DRIVER_DATA(VB)->strips_b;\ + fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); + + #define STRIPSLOCAL_VAR int sc = 0; -#define INIT(a) +#define INIT(a) -#define SENDTRI(u0,u1,u2) FX_grDrawTriangle((GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) -#define FLUSHTRI() /* No-Op */ +#define SENDTRI(u0,u1,u2) FX_grDrawTriangle(fxMesa, (GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) +#define FLUSHTRI() /* No-Op */ #define STARTSTRIPS(u0,u1,u2) { sb[sc++] = (GrVertex*)&(gWin[u0].f); sb[sc++] = (GrVertex*)&(gWin[u1].f); sb[sc++] = (GrVertex*)&(gWin[u2].f); } #define SENDSTRIPS(v2) { sb[sc++] = (GrVertex*)&(gWin[v2].f); } -#define FLUSHSTRIPS() FX_grDrawVertexArray(GR_TRIANGLE_STRIP,sc,sb) +#define FLUSHSTRIPS() FX_grDrawVertexArray(fxMesa, GR_TRIANGLE_STRIP,sc,sb) #define CLIPPED(a,b,c) 0 #define CULLED(a,b,c) 0 -#define SENDCLIPTRI(a,b,c) /* NoOp */ +#define SENDCLIPTRI(a,b,c) /* NoOp */ #define TAG(x) x##_fx @@ -78,7 +73,7 @@ /* Clipped but no userclip */ -#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) && !clipmask[v2] +#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) && !clipmask[v2] #define STRIP1(u,v) ((u0 == v0) && (u2 == v1)) && !clipmask[v2] #define LOCAL_VARS fxVertex* gWin = FX_DRIVER_DATA(VB)->verts; \ @@ -86,16 +81,16 @@ const GLubyte *const clipmask = VB->ClipMask; \ const fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ const tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - + #define STRIPSLOCAL_VAR int sc = 0; -#define INIT(a) +#define INIT(a) -#define SENDTRI(u0,u1,u2) FX_grDrawTriangle((GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) -#define FLUSHTRI() /* No-Op */ +#define SENDTRI(u0,u1,u2) FX_grDrawTriangle(fxMesa, (GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) +#define FLUSHTRI() /* No-Op */ #define STARTSTRIPS(u0,u1,u2) { sb[sc++] = (GrVertex*)&(gWin[u0].f); sb[sc++] = (GrVertex*)&(gWin[u1].f); sb[sc++] = (GrVertex*)&(gWin[u2].f); } #define SENDSTRIPS(v2) { sb[sc++] = (GrVertex*)&(gWin[v2].f); } -#define FLUSHSTRIPS() FX_grDrawVertexArray(GR_TRIANGLE_STRIP,sc,sb) +#define FLUSHSTRIPS() FX_grDrawVertexArray(fxMesa, GR_TRIANGLE_STRIP,sc,sb) #define CLIPPED(u0,u1,u2) (clipmask[u0] | clipmask[u1] | clipmask[u2]) #define CULLED(u0,u1,u2) (clipmask[u0] & clipmask[u1] & clipmask[u2]) @@ -104,13 +99,13 @@ ASSIGN_3V(vl, u0, u1, u2 ); \ cliptri(VB,vl,clipmask[u0] | clipmask[u1] | clipmask[u2]); \ } - + #define TAG(x) x##_fx_view_clipped #include "fxsdettmp.h" /* Clipped and might be userclip */ -#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) && !clipmask[v2] +#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) && !clipmask[v2] #define STRIP1(u,v) ((u0 == v0) && (u2 == v1)) && !clipmask[v2] #define LOCAL_VARS fxVertex* gWin = FX_DRIVER_DATA(VB)->verts; \ @@ -119,16 +114,16 @@ const GLubyte *userclipmask = VB->UserClipMask; \ const fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ const tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - + #define STRIPSLOCAL_VAR int sc = 0; -#define INIT(a) +#define INIT(a) -#define SENDTRI(u0,u1,u2) FX_grDrawTriangle((GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) -#define FLUSHTRI() /* No-Op */ +#define SENDTRI(u0,u1,u2) FX_grDrawTriangle(fxMesa, (GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) +#define FLUSHTRI() /* No-Op */ #define STARTSTRIPS(u0,u1,u2) { sb[sc++] = (GrVertex*)&(gWin[u0].f); sb[sc++] = (GrVertex*)&(gWin[u1].f); sb[sc++] = (GrVertex*)&(gWin[u2].f); } #define SENDSTRIPS(v2) { sb[sc++] = (GrVertex*)&(gWin[v2].f); } -#define FLUSHSTRIPS() FX_grDrawVertexArray(GR_TRIANGLE_STRIP,sc,sb) +#define FLUSHSTRIPS() FX_grDrawVertexArray(fxMesa, GR_TRIANGLE_STRIP,sc,sb) #define CLIPPED(u0,u1,u2) (clipmask[u0] | clipmask[u1] | clipmask[u2]) #define CULLED(u0,u1,u2) (clipmask[u0] & clipmask[u1] & clipmask[u2] & CLIP_ALL_BITS) @@ -145,20 +140,21 @@ else { ASSIGN_3V(vl, u2, u1, u0 ); \ cliptri( VB, vl, imask ); } \ } - + #define TAG(x) x##_fx_clipped #include "fxsdettmp.h" -void fxDDRenderInitGlide3(GLcontext *ctx) +void +fxDDRenderInitGlide3(GLcontext * ctx) { #if 0 - render_tab_fx_smooth_indirect[GL_TRIANGLES] = render_vb_triangles_smooth_indirect_sd_fx; - render_tab_fx_smooth_indirect_view_clipped[GL_TRIANGLES] = render_vb_triangles_smooth_indirect_sd_fx_view_clipped; - render_tab_fx_smooth_indirect_clipped[GL_TRIANGLES] = render_vb_triangles_smooth_indirect_sd_fx_clipped; + render_tab_fx_smooth_indirect[GL_TRIANGLES] = + render_vb_triangles_smooth_indirect_sd_fx; + render_tab_fx_smooth_indirect_view_clipped[GL_TRIANGLES] = + render_vb_triangles_smooth_indirect_sd_fx_view_clipped; + render_tab_fx_smooth_indirect_clipped[GL_TRIANGLES] = + render_vb_triangles_smooth_indirect_sd_fx_clipped; #endif } - - -#endif /* defined(FX) && FX_GLIDE3 */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxtexman.c b/xc/lib/GL/mesa/src/drv/tdfx/fxtexman.c new file mode 100644 index 000000000..037706292 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxtexman.c @@ -0,0 +1,844 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +/* fxtexman.c - 3Dfx VooDoo texture memory functions */ + + +#include "fxdrv.h" +#include "fxtexman.h" +#include "fxddtex.h" + + +#define BAD_ADDRESS ((FxU32) -1) + +int texSwaps = 0; + + + +#ifdef TEXSANITY +static void +fubar(void) +{ +} + +/* + * Sanity Check + */ +static void +sanity(fxMesaContext fxMesa) +{ + MemRange *tmp, *prev, *pos; + + prev = 0; + tmp = fxMesa->tmFree[0]; + while (tmp) { + if (!tmp->startAddr && !tmp->endAddr) { + fprintf(stderr, "Textures fubar\n"); + fubar(); + } + if (tmp->startAddr >= tmp->endAddr) { + fprintf(stderr, "Node fubar\n"); + fubar(); + } + if (prev && (prev->startAddr >= tmp->startAddr || + prev->endAddr > tmp->startAddr)) { + fprintf(stderr, "Sorting fubar\n"); + fubar(); + } + prev = tmp; + tmp = tmp->next; + } + prev = 0; + tmp = fxMesa->tmFree[1]; + while (tmp) { + if (!tmp->startAddr && !tmp->endAddr) { + fprintf(stderr, "Textures fubar\n"); + fubar(); + } + if (tmp->startAddr >= tmp->endAddr) { + fprintf(stderr, "Node fubar\n"); + fubar(); + } + if (prev && (prev->startAddr >= tmp->startAddr || + prev->endAddr > tmp->startAddr)) { + fprintf(stderr, "Sorting fubar\n"); + fubar(); + } + prev = tmp; + tmp = tmp->next; + } +} +#endif + + +/* + * Allocate and initialize a new MemRange struct. + * Try to allocate it from the pool of free MemRange nodes rather than malloc. + */ +static MemRange * +fxTMNewRangeNode(fxMesaContext fxMesa, FxU32 start, FxU32 end) +{ + MemRange *result; + + if (fxMesa->tmPool) { + result = fxMesa->tmPool; + fxMesa->tmPool = fxMesa->tmPool->next; + } + else { + result = MALLOC(sizeof(MemRange)); + if (!result) { + /*fprintf(stderr, "fxDriver: out of memory!\n");*/ + return NULL; + } + } + result->startAddr = start; + result->endAddr = end; + result->next = NULL; + return result; +} + + +/* + * Delete a MemRange struct. + * We keep a linked list of free/available MemRange structs to + * avoid extra malloc/free calls. + */ +static void +fxTMDeleteRangeNode(fxMesaContext fxMesa, MemRange *range) +{ + range->next = fxMesa->tmPool; + fxMesa->tmPool = range; +} + + +/* + * When we've run out of texture memory we have to throw out an + * existing texture to make room for the new one. This function + * determins the texture to throw out. + */ +static struct gl_texture_object * +fxTMFindOldestObject(fxMesaContext fxMesa, int tmu) +{ + const GLuint bindnumber = fxMesa->texBindNumber; + struct gl_texture_object *oldestObj, *obj, *lowestPriorityObj; + GLfloat lowestPriority; + GLuint oldestAge; + + oldestObj = NULL; + oldestAge = 0; + + lowestPriority = 1.0F; + lowestPriorityObj = NULL; + + for (obj = fxMesa->glCtx->Shared->TexObjectList; obj; obj = obj->Next) { + tfxTexInfo *info = fxTMGetTexInfo(obj); + + if (info && info->isInTM && + ((info->whichTMU == tmu) || (info->whichTMU == FX_TMU_BOTH) || + (info->whichTMU == FX_TMU_SPLIT))) { + GLuint age, lasttime; + + lasttime = info->lastTimeUsed; + + if (lasttime > bindnumber) + age = bindnumber + (UINT_MAX - lasttime + 1); /* TO DO: check wrap around */ + else + age = bindnumber - lasttime; + + if (age >= oldestAge) { + oldestAge = age; + oldestObj = obj; + } + + /* examine priority */ + if (obj->Priority < lowestPriority) { + lowestPriority = obj->Priority; + lowestPriorityObj = obj; + } + } + } + + if (lowestPriority < 1.0) { + ASSERT(lowestPriorityObj); + /* + printf("discard %d pri=%f\n", lowestPriorityObj->Name, lowestPriority); + */ + return lowestPriorityObj; + } + else { + /* + printf("discard %d age=%d\n", oldestObj->Name, oldestAge); + */ + return oldestObj; + } +} + + +/* + * Find the address (offset?) at which we can store a new texture. + * <tmu> is the texture unit. + * <size> is the texture size in bytes. + */ +static FxU32 +fxTMFindStartAddr(fxMesaContext fxMesa, GLint tmu, FxU32 size) +{ + MemRange *prev, *block; + FxU32 result; + struct gl_texture_object *obj; + + while (1) { + prev = NULL; + block = fxMesa->tmFree[tmu]; + while (block) { + if (block->endAddr - block->startAddr >= size) { + /* The texture will fit here */ + result = block->startAddr; + block->startAddr += size; + if (block->startAddr == block->endAddr) { + /* Remove this node since it's empty */ + if (prev) { + prev->next = block->next; + } + else { + fxMesa->tmFree[tmu] = block->next; + } + fxTMDeleteRangeNode(fxMesa, block); + } + fxMesa->freeTexMem[tmu] -= size; + return result; + } + prev = block; + block = block->next; + } + /* No free space. Discard oldest */ + obj = fxTMFindOldestObject(fxMesa, tmu); + if (!obj) { + /*gl_problem(NULL, "fx Driver: No space for texture\n");*/ + return BAD_ADDRESS; + } + fxTMMoveOutTM(fxMesa, obj); + texSwaps++; + } +} + + +/* + * Remove the given MemRange node from hardware texture memory. + */ +static void +fxTMRemoveRange(fxMesaContext fxMesa, GLint tmu, MemRange *range) +{ + MemRange *block, *prev; + + if (!range) + return; + + if (range->startAddr == range->endAddr) { + fxTMDeleteRangeNode(fxMesa, range); + return; + } + fxMesa->freeTexMem[tmu] += range->endAddr - range->startAddr; + + /* find position in linked list to insert this MemRange node */ + prev = NULL; + block = fxMesa->tmFree[tmu]; + while (block) { + if (range->startAddr > block->startAddr) { + prev = block; + block = block->next; + } + else { + break; + } + } + + /* Insert the free block, combine with adjacent blocks when possible */ + range->next = block; + if (block) { + if (range->endAddr == block->startAddr) { + /* Combine */ + block->startAddr = range->startAddr; + fxTMDeleteRangeNode(fxMesa, range); + range = block; + } + } + if (prev) { + if (prev->endAddr == range->startAddr) { + /* Combine */ + prev->endAddr = range->endAddr; + prev->next = range->next; + fxTMDeleteRangeNode(fxMesa, range); + } + else { + prev->next = range; + } + } + else { + fxMesa->tmFree[tmu] = range; + } +} + + +/* + * Allocate space for a texture image. + * <tmu> is the texture unit + * <texmemsize> is the number of bytes to allocate + */ +static MemRange * +fxTMAllocTexMem(fxMesaContext fxMesa, GLint tmu, FxU32 texmemsize) +{ + FxU32 startAddr = fxTMFindStartAddr(fxMesa, tmu, texmemsize); + if (startAddr == BAD_ADDRESS) { + return NULL; + } + else { + MemRange *range; + range = fxTMNewRangeNode(fxMesa, startAddr, startAddr + texmemsize); + return range; + } +} + + + +/* + * Move the given texture back into hardare texture memory. + */ +void +fxTMMoveInTM_NoLock(fxMesaContext fxMesa, struct gl_texture_object *tObj, + GLint where) +{ + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + int i, l; + FxU32 texmemsize; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxTMMoveInTM(%d)\n", tObj->Name); + } + + fxMesa->stats.reqTexUpload++; + + if (!ti->validated) { + gl_problem(NULL, + "fx Driver: internal error in fxTMMoveInTM() -> not validated\n"); + return; /* used to abort here */ + } + + if (ti->isInTM) { + if (ti->whichTMU == where) + return; + if (where == FX_TMU_SPLIT || ti->whichTMU == FX_TMU_SPLIT) { + fxTMMoveOutTM_NoLock(fxMesa, tObj); + } + else { + if (ti->whichTMU == FX_TMU_BOTH) + return; + where = FX_TMU_BOTH; + } + } + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_TEXTURE)) { + fprintf(stderr, + "fxmesa: downloading %x (%d) in texture memory in %d\n", + (GLuint) tObj, tObj->Name, where); + } + + ti->whichTMU = (FxU32) where; + + switch (where) { + case FX_TMU0: + case FX_TMU1: + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info)); + ti->tm[where] = fxTMAllocTexMem(fxMesa, where, texmemsize); + if (ti->tm[where]) { + fxMesa->stats.memTexUpload += texmemsize; + + for (i = FX_largeLodValue(ti->info), l = ti->minLevel; + i <= FX_smallLodValue(ti->info); i++, l++) + FX_grTexDownloadMipMapLevel_NoLock(where, + ti->tm[where]->startAddr, + FX_valueToLod(i), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[l].data); + } + break; + case FX_TMU_SPLIT: + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_ODD, + &(ti->info)); + ti->tm[FX_TMU0] = fxTMAllocTexMem(fxMesa, FX_TMU0, texmemsize); + if (ti->tm[FX_TMU0]) + fxMesa->stats.memTexUpload += texmemsize; + + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_EVEN, + &(ti->info)); + ti->tm[FX_TMU1] = fxTMAllocTexMem(fxMesa, FX_TMU1, texmemsize); + if (ti->tm[FX_TMU0] && ti->tm[FX_TMU1]) { + fxMesa->stats.memTexUpload += texmemsize; + + for (i = FX_largeLodValue(ti->info), l = ti->minLevel; + i <= FX_smallLodValue(ti->info); i++, l++) { + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU0, + ti->tm[FX_TMU0]->startAddr, + FX_valueToLod(i), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_ODD, + ti->mipmapLevel[l].data); + + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU1, + ti->tm[FX_TMU1]->startAddr, + FX_valueToLod(i), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_EVEN, + ti->mipmapLevel[l].data); + } + } + break; + case FX_TMU_BOTH: + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info)); + ti->tm[FX_TMU0] = fxTMAllocTexMem(fxMesa, FX_TMU0, texmemsize); + if (ti->tm[FX_TMU0]) + fxMesa->stats.memTexUpload += texmemsize; + + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info)); + ti->tm[FX_TMU1] = fxTMAllocTexMem(fxMesa, FX_TMU1, texmemsize); + if (ti->tm[FX_TMU0] && ti->tm[FX_TMU1]) { + fxMesa->stats.memTexUpload += texmemsize; + + for (i = FX_largeLodValue(ti->info), l = ti->minLevel; + i <= FX_smallLodValue(ti->info); i++, l++) { + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU0, + ti->tm[FX_TMU0]->startAddr, + FX_valueToLod(i), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[l].data); + + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU1, + ti->tm[FX_TMU1]->startAddr, + FX_valueToLod(i), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[l].data); + } + } + break; + default: + fprintf(stderr, + "fx Driver: internal error in fxTMMoveInTM() -> wrong tmu (%d)\n", + where); + return; /* used to abort here */ + } + + fxMesa->stats.texUpload++; + + ti->isInTM = GL_TRUE; +} + + +void +fxTMMoveInTM(fxMesaContext fxMesa, struct gl_texture_object *tObj, + GLint where) +{ + BEGIN_BOARD_LOCK(fxMesa); + fxTMMoveInTM_NoLock(fxMesa, tObj, where); + END_BOARD_LOCK(fxMesa); +} + + +void +fxTMReloadMipMapLevel(GLcontext *ctx, struct gl_texture_object *tObj, + GLint level) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + GrLOD_t lodlevel; + GLint tmu; + + if (!ti->validated) { + gl_problem(ctx, "internal error in fxTMReloadMipMapLevel() -> not validated\n"); + return; + } + + tmu = (int) ti->whichTMU; + fxTMMoveInTM(fxMesa, tObj, tmu); + + fxTexGetInfo(ctx, ti->mipmapLevel[0].width, ti->mipmapLevel[0].height, + &lodlevel, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +#ifdef FX_GLIDE3 + lodlevel -= level; +#else + lodlevel += level; +#endif + switch (tmu) { + case FX_TMU0: + case FX_TMU1: + FX_grTexDownloadMipMapLevel(fxMesa, tmu, + ti->tm[tmu]->startAddr, + FX_valueToLod(FX_lodToValue(lodlevel)), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[level].data); + break; + case FX_TMU_SPLIT: + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU0, + ti->tm[GR_TMU0]->startAddr, + FX_valueToLod(FX_lodToValue(lodlevel)), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_ODD, + ti->mipmapLevel[level].data); + + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU1, + ti->tm[GR_TMU1]->startAddr, + FX_valueToLod(FX_lodToValue(lodlevel)), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_EVEN, + ti->mipmapLevel[level].data); + break; + case FX_TMU_BOTH: + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU0, + ti->tm[GR_TMU0]->startAddr, + FX_valueToLod(FX_lodToValue(lodlevel)), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[level].data); + + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU1, + ti->tm[GR_TMU1]->startAddr, + FX_valueToLod(FX_lodToValue(lodlevel)), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[level].data); + break; + + default: + fprintf(stderr, + "fx Driver: internal error in fxTMReloadMipMapLevel() -> wrong tmu (%d)\n", + tmu); + break; + } +} + +#if 0 +/* + * This doesn't work. It can't work for compressed textures. + */ +void +fxTMReloadSubMipMapLevel(GLcontext *ctx, + struct gl_texture_object *tObj, + GLint level, GLint yoffset, GLint height) +{ + fxMesaContext fxMesa = FX_CONTEXT(ctx); + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + GrLOD_t lodlevel; + unsigned short *data; + GLint tmu; + + if (!ti->validated) { + gl_problem(ctx, "fx Driver: internal error in fxTMReloadSubMipMapLevel() -> not validated\n"); + return; + } + + tmu = (int) ti->whichTMU; + fxTMMoveInTM(fxMesa, tObj, tmu); + + fxTexGetInfo(ctx, ti->mipmapLevel[0].width, ti->mipmapLevel[0].height, + &lodlevel, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + data = ti->mipmapLevel[level].data + + yoffset * ti->mipmapLevel[level].width * + ti->mipmapLevel[level].texelSize; + + switch (tmu) { + case FX_TMU0: + case FX_TMU1: + FX_grTexDownloadMipMapLevelPartial(fxMesa, tmu, + ti->tm[tmu]->startAddr, + FX_valueToLod(FX_lodToValue + (lodlevel) + level), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, data, + yoffset, yoffset + height - 1); + break; + case FX_TMU_SPLIT: + FX_grTexDownloadMipMapLevelPartial(fxMesa, GR_TMU0, + ti->tm[FX_TMU0]->startAddr, + FX_valueToLod(FX_lodToValue + (lodlevel) + level), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_ODD, data, + yoffset, yoffset + height - 1); + + FX_grTexDownloadMipMapLevelPartial(fxMesa, GR_TMU1, + ti->tm[FX_TMU1]->startAddr, + FX_valueToLod(FX_lodToValue + (lodlevel) + level), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_EVEN, data, + yoffset, yoffset + height - 1); + break; + case FX_TMU_BOTH: + FX_grTexDownloadMipMapLevelPartial(fxMesa, GR_TMU0, + ti->tm[FX_TMU0]->startAddr, + FX_valueToLod(FX_lodToValue + (lodlevel) + level), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, data, + yoffset, yoffset + height - 1); + + FX_grTexDownloadMipMapLevelPartial(fxMesa, GR_TMU1, + ti->tm[FX_TMU1]->startAddr, + FX_valueToLod(FX_lodToValue + (lodlevel) + level), + FX_largeLodLog2(ti->info), + FX_aspectRatioLog2(ti->info), + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, data, + yoffset, yoffset + height - 1); + break; + default: + fprintf(stderr, + "fx Driver: internal error in fxTMReloadSubMipMapLevel() -> wrong tmu (%d)\n", + tmu); + return; + } +} +#endif + +/* + * Move the given texture out of hardware texture memory. + */ +void +fxTMMoveOutTM(fxMesaContext fxMesa, struct gl_texture_object *tObj) +{ + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxTMMoveOutTM(%x (%d))\n", (GLuint) tObj, + tObj->Name); + } + + if (!ti->isInTM) + return; + + switch (ti->whichTMU) { + case FX_TMU0: + case FX_TMU1: + fxTMRemoveRange(fxMesa, (int) ti->whichTMU, ti->tm[ti->whichTMU]); + break; + case FX_TMU_SPLIT: + case FX_TMU_BOTH: + fxTMRemoveRange(fxMesa, FX_TMU0, ti->tm[FX_TMU0]); + fxTMRemoveRange(fxMesa, FX_TMU1, ti->tm[FX_TMU1]); + break; + default: + fprintf(stderr, "fx Driver: internal error in fxTMMoveOutTM()\n"); + return; + } + + ti->isInTM = GL_FALSE; + ti->whichTMU = FX_TMU_NONE; +} + + +/* + * Called via glDeleteTexture to delete a texture object. + */ +void +fxTMFreeTexture(fxMesaContext fxMesa, struct gl_texture_object *tObj) +{ + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + int i; + + fxTMMoveOutTM(fxMesa, tObj); + + for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { + if (ti->mipmapLevel[i].data) { + FREE(ti->mipmapLevel[i].data); + ti->mipmapLevel[i].data = NULL; + } + } + switch (ti->whichTMU) { + case FX_TMU0: + case FX_TMU1: + fxTMDeleteRangeNode(fxMesa, ti->tm[ti->whichTMU]); + break; + case FX_TMU_SPLIT: + case FX_TMU_BOTH: + fxTMDeleteRangeNode(fxMesa, ti->tm[FX_TMU0]); + fxTMDeleteRangeNode(fxMesa, ti->tm[FX_TMU1]); + break; + } +} + + +/* + * Initialize texture memory. + * We take care of one or both TMU's here. + */ +void +fxTMInit(fxMesaContext fxMesa) +{ + const char *extensions = FX_grGetString(fxMesa, GR_EXTENSION); + + fxMesa->texBindNumber = 0; + fxMesa->tmPool = NULL; + + /* On Voodoo4 and later there's a UMA texture memory instead of + * separate TMU0 and TMU1 segments. We setup UMA mode here if + * possible. + */ + if (strstr(extensions, " TEXUMA disabled for now")) { + FxU32 start, end; + fxMesa->umaTexMemory = GL_TRUE; + FX_grEnable(fxMesa, GR_TEXTURE_UMA_EXT); + start = FX_grTexMinAddress(fxMesa, 0); + end = FX_grTexMaxAddress(fxMesa, 0); + fxMesa->freeTexMem[0] = end - start; + fxMesa->tmFree[0] = fxTMNewRangeNode(fxMesa, start, end); + } + else { + const int numTMUs = fxMesa->haveTwoTMUs ? 2 : 1; + int tmu; + fxMesa->umaTexMemory = GL_FALSE; + for (tmu = 0; tmu < numTMUs; tmu++) { + FxU32 start = FX_grTexMinAddress(fxMesa, tmu); + FxU32 end = FX_grTexMaxAddress(fxMesa, tmu); + fxMesa->freeTexMem[tmu] = end - start; + fxMesa->tmFree[tmu] = fxTMNewRangeNode(fxMesa, start, end); + } + } + +} + + +/* + * Clean-up texture memory before destroying context. + */ +void +fxTMClose(fxMesaContext fxMesa) +{ + const int numTMUs = fxMesa->haveTwoTMUs ? 2 : 1; + int tmu; + MemRange *tmp, *next; + + /* Deallocate the pool of free MemRange nodes */ + tmp = fxMesa->tmPool; + while (tmp) { + next = tmp->next; + FREE(tmp); + tmp = next; + } + + /* Delete the texture memory block MemRange nodes */ + for (tmu = 0; tmu < numTMUs; tmu++) { + tmp = fxMesa->tmFree[tmu]; + while (tmp) { + next = tmp->next; + FREE(tmp); + tmp = next; + } + } +} + + +/* + * After a context switch this function will be called to restore + * texture memory for the new context. + */ +void +fxTMRestoreTextures_NoLock(fxMesaContext ctx) +{ + tfxTexInfo *ti; + struct gl_texture_object *tObj; + int i, where; + + tObj = ctx->glCtx->Shared->TexObjectList; + while (tObj) { + ti = fxTMGetTexInfo(tObj); + if (ti && ti->isInTM) { + for (i = 0; i < MAX_TEXTURE_UNITS; i++) + if (ctx->glCtx->Texture.Unit[i].Current == tObj) { + /* Force the texture onto the board, as it could be in use */ + where = ti->whichTMU; + fxTMMoveOutTM_NoLock(ctx, tObj); + fxTMMoveInTM_NoLock(ctx, tObj, where); + break; + } + if (i == MAX_TEXTURE_UNITS) /* Mark the texture as off the board */ + fxTMMoveOutTM_NoLock(ctx, tObj); + } + tObj = tObj->Next; + } +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxtexman.h b/xc/lib/GL/mesa/src/drv/tdfx/fxtexman.h new file mode 100644 index 000000000..77b106db6 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxtexman.h @@ -0,0 +1,28 @@ +#ifndef FXTEXMAN_H +#define FXTEXMAN_H + + +#define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData)) + +#define fxTMMoveOutTM_NoLock fxTMMoveOutTM + +extern void fxTMReloadMipMapLevel(GLcontext *, struct gl_texture_object *, + GLint); +extern void fxTMReloadSubMipMapLevel(GLcontext *, + struct gl_texture_object *, GLint, GLint, + GLint); + +extern void fxTMInit(fxMesaContext ctx); + +extern void fxTMClose(fxMesaContext ctx); + +extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx); + +extern void fxTMMoveInTM(fxMesaContext, struct gl_texture_object *, GLint); + +extern void fxTMMoveOutTM(fxMesaContext, struct gl_texture_object *); + +extern void fxTMFreeTexture(fxMesaContext, struct gl_texture_object *); + + +#endif diff --git a/xc/extras/Mesa/src/FX/fxtrifuncs.c b/xc/lib/GL/mesa/src/drv/tdfx/fxtrifuncs.c index 4b349b31b..2ff250835 100644 --- a/xc/extras/Mesa/src/FX/fxtrifuncs.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxtrifuncs.c @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -46,12 +44,6 @@ /* fxtris.c - 3Dfx VooDoo triangle functions */ -#ifdef HAVE_CONFIG_H -#include "conf.h" -#endif - -#if defined(FX) - #include "fxdrv.h" #include "../mmath.h" @@ -59,9 +51,9 @@ /* Is this enough? Do we need more triangle funcs? */ -static triangle_func tri_tab[0x40]; /* only 0x20 actually used */ -static quad_func quad_tab[0x40]; /* only 0x20 actually used */ -static line_func line_tab[0x40]; /* less than 0x20 used */ +static triangle_func tri_tab[0x40]; /* only 0x20 actually used */ +static quad_func quad_tab[0x40]; /* only 0x20 actually used */ +static line_func line_tab[0x40]; /* less than 0x20 used */ static points_func points_tab[0x40]; /* less than 0x20 used */ #define IND (0) @@ -196,177 +188,177 @@ static points_func points_tab[0x40]; /* less than 0x20 used */ #include "fxtritmp.h" #endif -void fxDDTrifuncInit() +void +fxDDTrifuncInit() { - init(); - init_offset(); - init_twoside(); - init_twoside_offset(); - init_front_back(); - init_front_back_offset(); - init_front_back_twoside(); - init_front_back_twoside_offset(); - init_flat(); - init_flat_offset(); - init_flat_twoside(); - init_flat_twoside_offset(); - init_flat_front_back(); - init_flat_front_back_offset(); - init_flat_front_back_twoside(); - init_flat_front_back_twoside_offset(); + init(); + init_offset(); + init_twoside(); + init_twoside_offset(); + init_front_back(); + init_front_back_offset(); + init_front_back_twoside(); + init_front_back_twoside_offset(); + init_flat(); + init_flat_offset(); + init_flat_twoside(); + init_flat_twoside_offset(); + init_flat_front_back(); + init_flat_front_back_offset(); + init_flat_front_back_twoside(); + init_flat_front_back_twoside_offset(); #if 0 - init_aa(); - init_aa_offset(); - init_aa_twoside(); - init_aa_twoside_offset(); - init_aa_front_back(); - init_aa_front_back_offset(); - init_aa_front_back_twoside(); - init_aa_front_back_twoside_offset(); - init_aa_flat(); - init_aa_flat_offset(); - init_aa_flat_twoside(); - init_aa_flat_twoside_offset(); - init_aa_flat_front_back(); - init_aa_flat_front_back_offset(); - init_aa_flat_front_back_twoside(); - init_aa_flat_front_back_twoside_offset(); + init_aa(); + init_aa_offset(); + init_aa_twoside(); + init_aa_twoside_offset(); + init_aa_front_back(); + init_aa_front_back_offset(); + init_aa_front_back_twoside(); + init_aa_front_back_twoside_offset(); + init_aa_flat(); + init_aa_flat_offset(); + init_aa_flat_twoside(); + init_aa_flat_twoside_offset(); + init_aa_flat_front_back(); + init_aa_flat_front_back_offset(); + init_aa_flat_front_back_twoside(); + init_aa_flat_front_back_twoside_offset(); #endif } -void fxPrintRenderState( const char *msg, GLuint state ) +void +fxPrintRenderState(const char *msg, GLuint state) { - fprintf(stderr, "%s: (%x) %s%s%s%s%s%s\n", - msg, state, - (state & FX_ANTIALIAS) ? "antialias, " : "", - (state & FX_FLAT) ? "flat, " : "", - (state & FX_TWOSIDE) ? "twoside, " : "", - (state & FX_OFFSET) ? "offset, " : "", - (state & FX_FRONT_BACK) ? "front-back, " : "", - (state & FX_FALLBACK) ? "fallback" : ""); + fprintf(stderr, "%s: (%x) %s%s%s%s%s%s\n", + msg, state, + (state & FX_ANTIALIAS) ? "antialias, " : "", + (state & FX_FLAT) ? "flat, " : "", + (state & FX_TWOSIDE) ? "twoside, " : "", + (state & FX_OFFSET) ? "offset, " : "", + (state & FX_FRONT_BACK) ? "front-back, " : "", + (state & FX_FALLBACK) ? "fallback" : ""); } -void fxPrintHintState( const char *msg, GLuint state ) +void +fxPrintHintState(const char *msg, GLuint state) { - fprintf(stderr, "%s: (%x) %s %s%s %s%s\n", - msg, state, - (state & GR_STWHINT_W_DIFF_FBI) ? "w-fbi, " : "", - (state & GR_STWHINT_W_DIFF_TMU0) ? "w-tmu0, " : "", - (state & GR_STWHINT_ST_DIFF_TMU0) ? "st-tmu0, " : "", - (state & GR_STWHINT_W_DIFF_TMU1) ? "w-tmu1, " : "", - (state & GR_STWHINT_ST_DIFF_TMU1) ? "st-tmu1, " : ""); + fprintf(stderr, "%s: (%x) %s %s%s %s%s\n", + msg, state, + (state & GR_STWHINT_W_DIFF_FBI) ? "w-fbi, " : "", + (state & GR_STWHINT_W_DIFF_TMU0) ? "w-tmu0, " : "", + (state & GR_STWHINT_ST_DIFF_TMU0) ? "st-tmu0, " : "", + (state & GR_STWHINT_W_DIFF_TMU1) ? "w-tmu1, " : "", + (state & GR_STWHINT_ST_DIFF_TMU1) ? "st-tmu1, " : ""); } -void fxDDChooseRenderState( GLcontext *ctx ) +void +fxDDChooseRenderState(GLcontext * ctx) { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLuint ind = 0; - GLuint flags = ctx->TriangleCaps; - - ctx->IndirectTriangles &= ~DD_SW_RASTERIZE; - - if (flags) { - if (fxMesa->render_index & FX_OFFSET) - FX_grDepthBiasLevel(0); - - if (flags & (DD_SELECT|DD_FEEDBACK)) { - fxMesa->PointsFunc = 0; - fxMesa->LineFunc = 0; - fxMesa->TriangleFunc = 0; - fxMesa->QuadFunc = 0; - fxMesa->render_index = FX_FALLBACK; - ctx->IndirectTriangles |= DD_SW_RASTERIZE; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint ind = 0; + GLuint flags = ctx->TriangleCaps; + + ctx->IndirectTriangles &= ~DD_SW_RASTERIZE; + + if (flags) { + if (fxMesa->render_index & FX_OFFSET) + FX_grDepthBiasLevel(fxMesa, 0); + + if (flags & (DD_SELECT | DD_FEEDBACK)) { + fxMesa->PointsFunc = 0; + fxMesa->LineFunc = 0; + fxMesa->TriangleFunc = 0; + fxMesa->QuadFunc = 0; + fxMesa->render_index = FX_FALLBACK; + ctx->IndirectTriangles |= DD_SW_RASTERIZE; #if 0 - fprintf(stderr, "Fallback select|feeback\n"); + fprintf(stderr, "Fallback select|feeback\n"); #endif - return; - } - - if (flags & DD_FLATSHADE) ind |= FX_FLAT; - if (flags & DD_TRI_LIGHT_TWOSIDE) ind |= FX_TWOSIDE; - if (flags & DD_MULTIDRAW) ind |= FX_FRONT_BACK; - if (flags & (DD_POINT_ATTEN|DD_POINT_SMOOTH)) { - ind |= FX_FALLBACK; -#if 0 - if (flags&DD_POINT_ATTEN) - fprintf(stderr, "Fallback point atten\n"); - if (flags&DD_POINT_SMOOTH) - fprintf(stderr, "Fallback point smooth\n"); + return; + } + + if (flags & DD_FLATSHADE) + ind |= FX_FLAT; + if (flags & DD_TRI_LIGHT_TWOSIDE) + ind |= FX_TWOSIDE; +#if 000 + /* XXX this is rather broken, don't use it. */ + if (flags & DD_MULTIDRAW) + ind |= FX_FRONT_BACK; +#else + if (flags & DD_MULTIDRAW) + ctx->IndirectTriangles |= DD_SW_RASTERIZE; #endif - } - - fxMesa->render_index = ind; - fxMesa->PointsFunc = points_tab[ind]; - if (ind&FX_FALLBACK) - ctx->IndirectTriangles |= DD_POINT_SW_RASTERIZE; - ind &= ~(FX_ANTIALIAS|FX_FALLBACK); - if (flags & (DD_LINE_STIPPLE|DD_LINE_SMOOTH)) { - ind |= FX_FALLBACK; + if (flags & (DD_POINT_ATTEN | DD_POINT_SMOOTH)) { + ind |= FX_FALLBACK; #if 0 - if (flags&DD_LINE_STIPPLE) - fprintf(stderr, "Fallback line stipple\n"); - if (flags&DD_LINE_SMOOTH) - fprintf(stderr, "Fallback line smooth\n"); + if (flags & DD_POINT_ATTEN) + fprintf(stderr, "Fallback point atten\n"); + if (flags & DD_POINT_SMOOTH) + fprintf(stderr, "Fallback point smooth\n"); #endif - } + } - fxMesa->render_index |= ind; - fxMesa->LineFunc = line_tab[ind]; - if (ind&FX_FALLBACK) - ctx->IndirectTriangles |= DD_LINE_SW_RASTERIZE; - ind &= ~(FX_ANTIALIAS|FX_FALLBACK); + fxMesa->render_index = ind; + fxMesa->PointsFunc = points_tab[ind]; + if (ind & FX_FALLBACK) + ctx->IndirectTriangles |= DD_POINT_SW_RASTERIZE; + ind &= ~(FX_ANTIALIAS | FX_FALLBACK); - if (flags & DD_TRI_OFFSET) ind |= FX_OFFSET; - if (flags & (DD_TRI_UNFILLED|DD_TRI_STIPPLE|DD_TRI_SMOOTH)) { - ind |= FX_FALLBACK; + if (flags & (DD_LINE_STIPPLE | DD_LINE_SMOOTH)) { + ind |= FX_FALLBACK; #if 0 - if (flags&DD_TRI_UNFILLED) - fprintf(stderr, "Fallback tri unfilled\n"); - if (flags&DD_TRI_STIPPLE) - fprintf(stderr, "Fallback tri stippled\n"); - if (flags&DD_TRI_SMOOTH) - fprintf(stderr, "Fallback tri smooth\n"); + if (flags & DD_LINE_STIPPLE) + fprintf(stderr, "Fallback line stipple\n"); + if (flags & DD_LINE_SMOOTH) + fprintf(stderr, "Fallback line smooth\n"); #endif - } - - fxMesa->render_index |= ind; - fxMesa->TriangleFunc = tri_tab[ind]; - fxMesa->QuadFunc = quad_tab[ind]; - - if (ind&FX_FALLBACK) - ctx->IndirectTriangles |= DD_TRI_SW_RASTERIZE | DD_QUAD_SW_RASTERIZE; - } - else if (fxMesa->render_index) - { - if (fxMesa->render_index & FX_OFFSET) - FX_grDepthBiasLevel(0); - - fxMesa->render_index = 0; - fxMesa->PointsFunc = points_tab[0]; - fxMesa->LineFunc = line_tab[0]; - fxMesa->TriangleFunc = tri_tab[0]; - fxMesa->QuadFunc = quad_tab[0]; - } - - if (MESA_VERBOSE&(VERBOSE_STATE|VERBOSE_DRIVER)) - fxPrintRenderState("fxmesa: Render state", fxMesa->render_index); -} - -#else - - -/* - * Need this to provide at least one external definition. - */ - -extern int gl_fx_dummy_function_tris(void); -int gl_fx_dummy_function_tris(void) -{ - return 0; + } + + fxMesa->render_index |= ind; + fxMesa->LineFunc = line_tab[ind]; + if (ind & FX_FALLBACK) + ctx->IndirectTriangles |= DD_LINE_SW_RASTERIZE; + ind &= ~(FX_ANTIALIAS | FX_FALLBACK); + + if (flags & DD_TRI_OFFSET) + ind |= FX_OFFSET; + if (flags & (DD_TRI_UNFILLED | DD_TRI_STIPPLE | DD_TRI_SMOOTH)) { + ind |= FX_FALLBACK; +#if 0 + if (flags & DD_TRI_UNFILLED) + fprintf(stderr, "Fallback tri unfilled\n"); + if (flags & DD_TRI_STIPPLE) + fprintf(stderr, "Fallback tri stippled\n"); + if (flags & DD_TRI_SMOOTH) + fprintf(stderr, "Fallback tri smooth\n"); +#endif + } + + fxMesa->render_index |= ind; + fxMesa->TriangleFunc = tri_tab[ind]; + fxMesa->QuadFunc = quad_tab[ind]; + + if (ind & FX_FALLBACK) + ctx->IndirectTriangles |= + DD_TRI_SW_RASTERIZE | DD_QUAD_SW_RASTERIZE; + } + else if (fxMesa->render_index) { + if (fxMesa->render_index & FX_OFFSET) + FX_grDepthBiasLevel(fxMesa, 0); + + fxMesa->render_index = 0; + fxMesa->PointsFunc = points_tab[0]; + fxMesa->LineFunc = line_tab[0]; + fxMesa->TriangleFunc = tri_tab[0]; + fxMesa->QuadFunc = quad_tab[0]; + } + + if (MESA_VERBOSE & (VERBOSE_STATE | VERBOSE_DRIVER)) + fxPrintRenderState("fxmesa: Render state", fxMesa->render_index); } - -#endif /* FX */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxtritmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxtritmp.h new file mode 100644 index 000000000..6e6cb0a13 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxtritmp.h @@ -0,0 +1,445 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +static void TAG(fx_tri) (GLcontext * ctx, GLuint e1, GLuint e2, GLuint e3, + GLuint pv) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GrVertex *v1 = (GrVertex *) gWin[e1].f; + GrVertex *v2 = (GrVertex *) gWin[e2].f; + GrVertex *v3 = (GrVertex *) gWin[e3].f; + + (void) fxMesa; + + if (IND & (FX_TWOSIDE | FX_OFFSET)) { + GLfloat ex = v1->x - v3->x; + GLfloat ey = v1->y - v3->y; + GLfloat fx = v2->x - v3->x; + GLfloat fy = v2->y - v3->y; + GLfloat c = ex * fy - ey * fx; + + if (IND & FX_TWOSIDE) { + GLuint facing = (c < 0.0) ^ ctx->Polygon.FrontBit; + GLubyte(*color)[4] = VB->Color[facing]->data; + if (IND & FX_FLAT) { + GOURAUD2(v1, color[pv]); + GOURAUD2(v2, color[pv]); + GOURAUD2(v3, color[pv]); + } + else { + GOURAUD2(v1, color[e1]); + GOURAUD2(v2, color[e2]); + GOURAUD2(v3, color[e3]); + } + } + + /* Should apply a factor to ac to compensate for different x/y + * scaling introduced in the Viewport matrix. + * + * The driver should supply scaling factors for 'factor' and 'units'. + */ + if (IND & FX_OFFSET) { + GLfloat offset = ctx->Polygon.OffsetUnits; + + if (c * c > 1e-16) { + GLfloat factor = ctx->Polygon.OffsetFactor; + GLfloat ez = v1->ooz - v3->ooz; + GLfloat fz = v2->ooz - v3->ooz; + GLfloat a = ey * fz - ez * fy; + GLfloat b = ez * fx - ex * fz; + GLfloat ic = 1.0 / c; + GLfloat ac = a * ic; + GLfloat bc = b * ic; + if (ac < 0.0F) + ac = -ac; + if (bc < 0.0F) + bc = -bc; + offset += MAX2(ac, bc) * factor; + } + /* Probably a lot quicker just to nudge the z values and put + * them back afterwards. + */ + FX_grDepthBiasLevel(fxMesa, (int) offset); + } + } + else if (IND & FX_FLAT) { + GLubyte(*color)[4] = VB->Color[0]->data; + GOURAUD2(v1, color[pv]); + GOURAUD2(v2, color[pv]); + GOURAUD2(v3, color[pv]); + } + + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + } + + if (IND & FX_ANTIALIAS) + FX_grAADrawTriangle(fxMesa, v1, v2, v3, FXTRUE, FXTRUE, FXTRUE); + else + FX_grDrawTriangle(fxMesa, v1, v2, v3); + + /* Might be quicker to do two passes, one for each buffer? + */ + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + + if (ctx->Depth.Mask) + FX_grDepthMask(fxMesa, FXTRUE); + + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + + if (IND & FX_ANTIALIAS) + FX_grAADrawTriangle(fxMesa, v1, v2, v3, FXTRUE, FXTRUE, FXTRUE); + else + FX_grDrawTriangle(fxMesa, v1, v2, v3); + } +} + + +/* Not worth the space? + */ +static void TAG(fx_quad) (GLcontext * ctx, GLuint e1, GLuint e2, GLuint e3, + GLuint e4, GLuint pv) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GrVertex *v1 = (GrVertex *) gWin[e1].f; + GrVertex *v2 = (GrVertex *) gWin[e2].f; + GrVertex *v3 = (GrVertex *) gWin[e3].f; + GrVertex *v4 = (GrVertex *) gWin[e4].f; + + (void) fxMesa; + + if (IND & (FX_TWOSIDE | FX_OFFSET)) { + GLfloat ex = v3->x - v1->x; + GLfloat ey = v3->y - v1->y; + GLfloat fx = v4->x - v2->x; + GLfloat fy = v4->y - v2->y; + GLfloat c = ex * fy - ey * fx; + + if (IND & FX_TWOSIDE) { + GLuint facing = (c < 0.0) ^ ctx->Polygon.FrontBit; + GLubyte(*color)[4] = VB->Color[facing]->data; + if (IND & FX_FLAT) { + GOURAUD2(v1, color[pv]); + GOURAUD2(v2, color[pv]); + GOURAUD2(v3, color[pv]); + GOURAUD2(v4, color[pv]); + } + else { + GOURAUD2(v1, color[e1]); + GOURAUD2(v2, color[e2]); + GOURAUD2(v3, color[e3]); + GOURAUD2(v4, color[e4]); + } + } + + /* Should apply a factor to ac to compensate for different x/y + * scaling introduced in the Viewport matrix. + * + * The driver should supply scaling factors for 'factor' and 'units'. + */ + if (IND & FX_OFFSET) { + GLfloat offset = ctx->Polygon.OffsetUnits; + + if (c * c > 1e-16) { + GLfloat factor = ctx->Polygon.OffsetFactor; + GLfloat ez = v3->ooz - v1->ooz; + GLfloat fz = v4->ooz - v2->ooz; + GLfloat a = ey * fz - ez * fy; + GLfloat b = ez * fx - ex * fz; + GLfloat ic = 1.0 / c; + GLfloat ac = a * ic; + GLfloat bc = b * ic; + if (ac < 0.0F) + ac = -ac; + if (bc < 0.0F) + bc = -bc; + offset += MAX2(ac, bc) * factor; + } + /* Probably a lot quicker just to nudge the z values and put + * them back afterwards. + */ + FX_grDepthBiasLevel(fxMesa, (int) offset); + } + } + else if (IND & FX_FLAT) { + GLubyte(*color)[4] = VB->Color[0]->data; + GOURAUD2(v1, color[pv]); + GOURAUD2(v2, color[pv]); + GOURAUD2(v3, color[pv]); + GOURAUD2(v4, color[pv]); + } + + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + } + + if (IND & FX_ANTIALIAS) { + FX_grAADrawTriangle(fxMesa, v1, v2, v4, FXTRUE, FXTRUE, FXTRUE); + FX_grAADrawTriangle(fxMesa, v2, v3, v4, FXTRUE, FXTRUE, FXTRUE); + } + else { + FX_grDrawTriangle(fxMesa, v1, v2, v4); + FX_grDrawTriangle(fxMesa, v2, v3, v4); + } + + /* Might be quicker to do two passes, one for each buffer? + */ + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + + if (ctx->Depth.Mask) + FX_grDepthMask(fxMesa, FXTRUE); + + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + + if (IND & FX_ANTIALIAS) { + FX_grAADrawTriangle(fxMesa, v1, v2, v4, FXTRUE, FXTRUE, FXTRUE); + FX_grAADrawTriangle(fxMesa, v2, v3, v4, FXTRUE, FXTRUE, FXTRUE); + } + else { + FX_grDrawTriangle(fxMesa, v1, v2, v4); + FX_grDrawTriangle(fxMesa, v2, v3, v4); + } + } +} + +#define DRAW_LINE(fxMesa, tmp0, tmp1, width) \ + if (width <= 1.0) { \ + FX_grDrawLine(fxMesa, tmp0, tmp1); \ + } \ + else { \ + GrVertex verts[4]; \ + float dx, dy, ix, iy; \ + \ + dx = tmp0->x - tmp1->x; \ + dy = tmp0->y - tmp1->y; \ + \ + if (dx * dx > dy * dy) { \ + iy = width * .5; \ + ix = 0; \ + } \ + else { \ + iy = 0; \ + ix = width * .5; \ + } \ + \ + verts[0] = *tmp0; \ + verts[1] = *tmp0; \ + verts[2] = *tmp1; \ + verts[3] = *tmp1; \ + \ + verts[0].x = tmp0->x - ix; \ + verts[0].y = tmp0->y - iy; \ + \ + verts[1].x = tmp0->x + ix; \ + verts[1].y = tmp0->y + iy; \ + \ + verts[2].x = tmp1->x + ix; \ + verts[2].y = tmp1->y + iy; \ + \ + verts[3].x = tmp1->x - ix; \ + verts[3].y = tmp1->y - iy; \ + \ + FX_grDrawPolygonVertexList(fxMesa, 4, verts); \ + } + + +#if (IND & FX_OFFSET) == 0 +static void TAG(fx_line) (GLcontext * ctx, GLuint e1, GLuint e2, GLuint pv) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + struct vertex_buffer *VB = ctx->VB; + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GLubyte(*const color)[4] = VB->ColorPtr->data; + GrVertex *v1 = (GrVertex *) gWin[e1].f; + GrVertex *v2 = (GrVertex *) gWin[e2].f; + GLfloat w = ctx->Line.Width * .5; + + if (IND & FX_FLAT) { + v1->r = v2->r = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][0]); + v1->g = v2->g = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][1]); + v1->b = v2->b = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][2]); + v1->a = v2->a = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[pv][3]); + } + else if (IND & FX_TWOSIDE) { + /* XXX use signed area of the polygon to determine front/back color choice */ + GOURAUD2(v1, color[e1]); + GOURAUD2(v2, color[e2]); + } + + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + } + + if (IND & FX_ANTIALIAS) + FX_grAADrawLine(fxMesa, v1, v2); + else + DRAW_LINE(fxMesa, v1, v2, w); + + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + + if (ctx->Depth.Mask) + FX_grDepthMask(fxMesa, FXTRUE); + + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + + if (IND & FX_ANTIALIAS) + FX_grAADrawLine(fxMesa, v1, v2); + else + DRAW_LINE(fxMesa, v1, v2, w); + } +} +#endif + + +#if (IND & FX_OFFSET) == 0 + +/* + * Draw large points (size > 1) with a polygon. + */ +#define DRAW_POINT(i, radius, color) \ + do { \ + GrVertex verts[4], *tmp; \ + tmp = (GrVertex *) gWin[i].f; \ + tmp->r = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[0]); \ + tmp->g = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[1]); \ + tmp->b = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[2]); \ + tmp->a = UBYTE_COLOR_TO_FLOAT_255_COLOR(color[3]); \ + verts[0] = *tmp; \ + verts[1] = *tmp; \ + verts[2] = *tmp; \ + verts[3] = *tmp; \ + verts[0].x = verts[3].x = tmp->x + radius; \ + verts[0].y = verts[1].y = tmp->y + radius; \ + verts[2].x = verts[1].x = tmp->x - radius; \ + verts[2].y = verts[3].y = tmp->y - radius; \ + FX_grDrawPolygonVertexList(fxMesa, 4, verts); \ + } while (0) + + +static void TAG(fx_points) (GLcontext * ctx, GLuint first, GLuint last) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + const struct vertex_buffer *VB = ctx->VB; + const fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; + GLubyte (*color)[4] = VB->ColorPtr->data; + GLuint i; + const GLfloat radius = ctx->Point.Size * .5; + + (void) color; + (void) fxMesa; + + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + FX_grDepthMask(fxMesa, FXFALSE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_BACKBUFFER); + } + + if (!VB->ClipOrMask) { + for (i = first; i <= last; i++) { + DRAW_POINT(i, radius, color[i]); + } + } + else { + for (i = first; i <= last; i++) { + if (VB->ClipMask[i] == 0) { + DRAW_POINT(i, radius, color[i]); + } + } + } + + if (IND & FX_FRONT_BACK) { + FX_grColorMaskv(ctx, ctx->Color.ColorMask); + if (ctx->Depth.Mask) + FX_grDepthMask(fxMesa, FXTRUE); + FX_grRenderBuffer(fxMesa, GR_BUFFER_FRONTBUFFER); + + if (!VB->ClipOrMask) { + for (i = first; i <= last; i++) { + DRAW_POINT(i, radius, color[i]); + } + } + else { + for (i = first; i <= last; i++) { + if (VB->ClipMask[i] == 0) { + DRAW_POINT(i, radius, color[i]); + } + } + } + } +} + +#endif + + + +static void TAG(init) (void) +{ + tri_tab[IND] = TAG(fx_tri); + quad_tab[IND] = TAG(fx_quad); + +#if ((IND & FX_OFFSET) == 0) + line_tab[IND] = TAG(fx_line); + points_tab[IND] = TAG(fx_points); +#else + line_tab[IND] = line_tab[IND & ~FX_OFFSET]; + points_tab[IND] = points_tab[IND & ~FX_OFFSET]; +#endif +} + +#undef IND +#undef TAG +#undef FLAT_COLOR +#undef DRAW_POINT diff --git a/xc/extras/Mesa/src/FX/fxvs_tmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxvs_tmp.h index d9001db5e..29e050940 100644 --- a/xc/extras/Mesa/src/FX/fxvs_tmp.h +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxvs_tmp.h @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -116,69 +114,71 @@ #define INCR I6 #define FIXUP F7 -static void NAME(struct vertex_buffer *VB, GLuint start, GLuint end) +static void +NAME(struct vertex_buffer *VB, GLuint start, GLuint end) { - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - - if (fxMesa->new_state) - fxSetupFXUnits( ctx ); - - { - const float snapper = (3L<<18); - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLfloat *v = gWin[start].f; - GLfloat *vend = gWin[end].f; - VARS; - - (void) gWin; - (void) fxMesa; - (void) snapper; - - if (VB->ClipOrMask) { - GLubyte *clipmask = &VB->ClipMask[start]; - for (;v!=vend;v+=16,clipmask++ INCR) { - if (*clipmask == 0) { - DO_SETUP; - } - } - } - else { - for (;v!=vend;v+=16 INCR) { - DO_SETUP; - } - } - - if (ctx->FogMode == FOG_FRAGMENT && ctx->ProjectionMatrix.m[15] != 0.0F) { - /* need to compute W values for fogging purposes */ - const GLfloat m10 = ctx->ProjectionMatrix.m[10]; - const GLfloat m14 = ctx->ProjectionMatrix.m[14]; - const GLfloat v10 = ctx->Viewport.WindowMap.m[10]; - const GLfloat v14 = ctx->Viewport.WindowMap.m[14]; + GLcontext *ctx = VB->ctx; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + if (fxMesa->new_state) + fxSetupFXUnits(ctx); + + { + const float snapper = (3L << 18); + fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; GLfloat *v = gWin[start].f; - GLfloat *win = VB->Win.data[start]; + GLfloat *vend = gWin[end].f; + VARS; + + (void) gWin; + (void) fxMesa; + (void) snapper; + if (VB->ClipOrMask) { - GLubyte *clipmask = &VB->ClipMask[start]; - for (;v!=vend;v+=16,clipmask++, win+=4) { - if (*clipmask == 0) { - GLfloat zNDC = (win[2] - v14) / v10; - GLfloat zEye = (zNDC - m14) / m10; - v[OOWCOORD] = -1.0F / zEye; - } - } + GLubyte *clipmask = &VB->ClipMask[start]; + for (; v != vend; v += 16, clipmask++ INCR) { + if (*clipmask == 0) { + DO_SETUP; + } + } } else { - for (;v!=vend;v+=16, win+=4) { - GLfloat zNDC = (win[2] - v14) / v10; - GLfloat zEye = (zNDC - m14) / m10; - v[OOWCOORD] = -1.0F / zEye; - } + for (; v != vend; v += 16 INCR) { + DO_SETUP; + } + } + + if (ctx->FogMode == FOG_FRAGMENT + && ctx->ProjectionMatrix.m[15] != 0.0F) { + /* need to compute W values for fogging purposes */ + const GLfloat m10 = ctx->ProjectionMatrix.m[10]; + const GLfloat m14 = ctx->ProjectionMatrix.m[14]; + const GLfloat v10 = ctx->Viewport.WindowMap.m[10]; + const GLfloat v14 = ctx->Viewport.WindowMap.m[14]; + GLfloat *v = gWin[start].f; + GLfloat *win = VB->Win.data[start]; + if (VB->ClipOrMask) { + GLubyte *clipmask = &VB->ClipMask[start]; + for (; v != vend; v += 16, clipmask++, win += 4) { + if (*clipmask == 0) { + GLfloat zNDC = (win[2] - v14) / v10; + GLfloat zEye = (zNDC - m14) / m10; + v[OOWCOORD] = -1.0F / zEye; + } + } + } + else { + for (; v != vend; v += 16, win += 4) { + GLfloat zNDC = (win[2] - v14) / v10; + GLfloat zEye = (zNDC - m14) / m10; + v[OOWCOORD] = -1.0F / zEye; + } + } } - } - /* rare - I hope */ - FIXUP; - } + /* rare - I hope */ + FIXUP; + } } @@ -212,4 +212,3 @@ static void NAME(struct vertex_buffer *VB, GLuint start, GLuint end) #undef IND #undef NAME - diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxvsetup.c b/xc/lib/GL/mesa/src/drv/tdfx/fxvsetup.c new file mode 100644 index 000000000..12738bb0a --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxvsetup.c @@ -0,0 +1,577 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +/* fxvsetup.c - 3Dfx VooDoo vertices setup functions */ + + +#include "fxdrv.h" +#include "fxtexman.h" +#include "fxsetup.h" +#include "mmath.h" +#include "pipeline.h" +#include "fxvsetup.h" + + +void +fxPrintSetupFlags(const char *msg, GLuint flags) +{ + fprintf(stderr, "%s: %d %s%s%s%s%s%s\n", + msg, + flags, + (flags & SETUP_XY) ? " xy," : "", + (flags & SETUP_Z) ? " z," : "", + (flags & SETUP_W) ? " w," : "", + (flags & SETUP_RGBA) ? " rgba," : "", + (flags & SETUP_TMU0) ? " tmu0," : "", + (flags & SETUP_TMU1) ? " tmu1," : ""); +} + +static void +project_texcoords(struct vertex_buffer *VB, + GLuint tmu_nr, GLuint tc_nr, GLuint start, GLuint count) +{ + fxVertex *v = FX_DRIVER_DATA(VB)->verts + start; + GrTmuVertex *tmu = &(((GrVertex *) v->f)->tmuvtx[tmu_nr]); + GLvector4f *vec = VB->TexCoordPtr[tc_nr]; + + GLuint i; + GLuint stride = vec->stride; + GLfloat *data = VEC_ELT(vec, GLfloat, start); + + for (i = start; i < count; i++, STRIDE_F(data, stride), v++) { + tmu->oow = v->f[OOWCOORD] * data[3]; + tmu = (GrTmuVertex *) ((char *) tmu + sizeof(fxVertex)); + } +} + + +static void +copy_w(struct vertex_buffer *VB, GLuint tmu_nr, GLuint start, GLuint count) +{ + fxVertex *v = FX_DRIVER_DATA(VB)->verts + start; + GrTmuVertex *tmu = &(((GrVertex *) v->f)->tmuvtx[tmu_nr]); + GLuint i; + + for (i = start; i < count; i++, v++) { + tmu->oow = v->f[OOWCOORD]; + tmu = (GrTmuVertex *) ((char *) tmu + sizeof(fxVertex)); + } +} + + +static tfxSetupFunc setupfuncs[0x40]; + + + + +#define IND SETUP_XY +#define NAME fxsetupXY +#include "fxvs_tmp.h" + +#define IND (SETUP_XY|SETUP_Z) +#define NAME fxsetupXYZ +#include "fxvs_tmp.h" + +#define IND (SETUP_XY|SETUP_W) +#define NAME fxsetupXYW +#include "fxvs_tmp.h" + +#define IND (SETUP_XY|SETUP_Z|SETUP_W) +#define NAME fxsetupXYZW +#include "fxvs_tmp.h" + +#define IND (SETUP_RGBA|SETUP_XY) +#define NAME fxsetupXYRGBA +#include "fxvs_tmp.h" + +#define IND (SETUP_RGBA|SETUP_XY|SETUP_Z) +#define NAME fxsetupXYZRGBA +#include "fxvs_tmp.h" + +#define IND (SETUP_RGBA|SETUP_XY|SETUP_W) +#define NAME fxsetupXYWRGBA +#include "fxvs_tmp.h" + +#define IND (SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W) +#define NAME fxsetupXYZWRGBA +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU0|SETUP_XY|SETUP_W) +#define NAME fxsetupXYWT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU0|SETUP_XY|SETUP_Z|SETUP_W) +#define NAME fxsetupXYZWT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_XY|SETUP_W) +#define NAME fxsetupXYWT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_XY|SETUP_Z|SETUP_W) +#define NAME fxsetupXYZWT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_W) +#define NAME fxsetupXYWRGBAT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W) +#define NAME fxsetupXYZWRGBAT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_W) +#define NAME fxsetupXYWRGBAT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA|SETUP_XY|SETUP_Z|SETUP_W) +#define NAME fxsetupXYZWRGBAT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_RGBA) +#define NAME fxsetupRGBA +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU0) +#define NAME fxsetupT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1) +#define NAME fxsetupT1 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_TMU0) +#define NAME fxsetupT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU0|SETUP_RGBA) +#define NAME fxsetupRGBAT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_RGBA) +#define NAME fxsetupRGBAT1 +#include "fxvs_tmp.h" + +#define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA) +#define NAME fxsetupRGBAT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_RGBA) +#define NAME fxsetupWRGBA +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_TMU0) +#define NAME fxsetupWT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_TMU1) +#define NAME fxsetupWT1 +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_TMU1|SETUP_TMU0) +#define NAME fxsetupWT0T1 +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_TMU0|SETUP_RGBA) +#define NAME fxsetupWRGBAT0 +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_TMU1|SETUP_RGBA) +#define NAME fxsetupWRGBAT1 +#include "fxvs_tmp.h" + +#define IND (SETUP_W|SETUP_TMU1|SETUP_TMU0|SETUP_RGBA) +#define NAME fxsetupWRGBAT0T1 +#include "fxvs_tmp.h" + + + +void +fxDDSetupInit(void) +{ + setupfuncs[SETUP_XY] = fxsetupXY; + setupfuncs[SETUP_XY | SETUP_Z] = fxsetupXYZ; + setupfuncs[SETUP_XY | SETUP_W] = fxsetupXYW; + setupfuncs[SETUP_XY | SETUP_Z | SETUP_W] = fxsetupXYZW; + + setupfuncs[SETUP_RGBA | SETUP_XY] = fxsetupXYRGBA; + setupfuncs[SETUP_RGBA | SETUP_XY | SETUP_Z] = fxsetupXYZRGBA; + setupfuncs[SETUP_RGBA | SETUP_XY | SETUP_W] = fxsetupXYWRGBA; + setupfuncs[SETUP_RGBA | SETUP_XY | SETUP_Z | SETUP_W] = fxsetupXYZWRGBA; + + /* If we have texture and xy then we must have w. + * If we have texture1 and w then we must have texture 0. + */ + setupfuncs[SETUP_TMU0 | SETUP_XY | SETUP_W] = fxsetupXYWT0; + setupfuncs[SETUP_TMU0 | SETUP_XY | SETUP_Z | SETUP_W] = fxsetupXYZWT0; + + setupfuncs[SETUP_TMU1 | SETUP_TMU0 | SETUP_XY | SETUP_W] = fxsetupXYWT0T1; + setupfuncs[SETUP_TMU1 | SETUP_TMU0 | SETUP_XY | SETUP_Z | SETUP_W] = + fxsetupXYZWT0T1; + + setupfuncs[SETUP_TMU0 | SETUP_RGBA | SETUP_XY | SETUP_W] = + fxsetupXYWRGBAT0; + setupfuncs[SETUP_TMU0 | SETUP_RGBA | SETUP_XY | SETUP_Z | SETUP_W] = + fxsetupXYZWRGBAT0; + + setupfuncs[SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA | SETUP_XY | SETUP_W] = + fxsetupXYWRGBAT0T1; + setupfuncs[SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA | SETUP_XY | SETUP_Z | + SETUP_W] = fxsetupXYZWRGBAT0T1; + + /* If we don't have xy then we can't have z... w is still a possibility. + */ + setupfuncs[SETUP_RGBA] = fxsetupRGBA; + setupfuncs[SETUP_TMU0] = fxsetupT0; + setupfuncs[SETUP_TMU1] = fxsetupT1; + setupfuncs[SETUP_TMU1 | SETUP_TMU0] = fxsetupT0T1; + setupfuncs[SETUP_TMU0 | SETUP_RGBA] = fxsetupRGBAT0; + setupfuncs[SETUP_TMU1 | SETUP_RGBA] = fxsetupRGBAT1; + setupfuncs[SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA] = fxsetupRGBAT0T1; + + setupfuncs[SETUP_W | SETUP_RGBA] = fxsetupWRGBA; + setupfuncs[SETUP_W | SETUP_TMU0] = fxsetupWT0; + setupfuncs[SETUP_W | SETUP_TMU1] = fxsetupWT1; + setupfuncs[SETUP_W | SETUP_TMU1 | SETUP_TMU0] = fxsetupWT0T1; + setupfuncs[SETUP_W | SETUP_TMU0 | SETUP_RGBA] = fxsetupWRGBAT0; + setupfuncs[SETUP_W | SETUP_TMU1 | SETUP_RGBA] = fxsetupWRGBAT1; + setupfuncs[SETUP_W | SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA] = + fxsetupWRGBAT0T1; + +} + + + +tfxSetupFunc +fxDDChooseSetupFunction(GLcontext * ctx) +{ + GLuint setupindex = SETUP_XY | SETUP_Z; + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + + fxMesa->setupindex = 0; + + if (ctx->RenderMode != GL_RENDER) + return 0; + + fxMesa->tmu_source[0] = 0; + fxMesa->tmu_source[1] = 1; + + fxMesa->tex_dest[0] = SETUP_TMU0; + fxMesa->tex_dest[1] = SETUP_TMU1; + + if (ctx->Light.ShadeModel == GL_SMOOTH && !ctx->Light.Model.TwoSide) + setupindex |= SETUP_RGBA; + + if (ctx->Fog.Enabled && ctx->FogMode == FOG_FRAGMENT) + setupindex |= SETUP_RGBA | SETUP_W; + + if ((ctx->Texture.ReallyEnabled & (TEXTURE0_2D | TEXTURE0_3D)) == + TEXTURE0_2D) { + /* This doesn't work for non-RGBA textures + if (ctx->Texture.Unit[0].EnvMode == GL_REPLACE) + setupindex &= ~SETUP_RGBA; + */ + setupindex |= SETUP_TMU0 | SETUP_W; + } + + if ((ctx->Texture.ReallyEnabled & (TEXTURE1_2D | TEXTURE1_3D)) == + TEXTURE1_2D) { + setupindex |= SETUP_TMU1 | SETUP_W; + if (setupindex & SETUP_TMU0) { /* both TMUs in use */ + struct gl_texture_object *tObj = ctx->Texture.Unit[0].CurrentD[2]; + tfxTexInfo *ti = fxTMGetTexInfo(tObj); + + if (ti->whichTMU != FX_TMU0) { /* TMU0 and TMU1 are swapped */ + fxMesa->tmu_source[0] = 1; + fxMesa->tex_dest[1] = SETUP_TMU0; + fxMesa->tmu_source[1] = 0; + fxMesa->tex_dest[0] = SETUP_TMU1; + } + } + } + + if (ctx->Color.BlendEnabled) + setupindex |= SETUP_RGBA; + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_PIPELINE | VERBOSE_STATE)) + fxPrintSetupFlags("fxmesa: vertex setup function", setupindex); + + fxMesa->setupindex = setupindex; + fxMesa->view_clip_tri = fxTriViewClipTab[setupindex & 0x7]; + fxMesa->clip_tri_stride = fxTriClipStrideTab[setupindex & 0x7]; + return setupfuncs[setupindex]; +} + +void +fxDDDoRasterSetup(struct vertex_buffer *VB) +{ + GLcontext *ctx = VB->ctx; + FX_DRIVER_DATA(VB)->last_vert = FX_DRIVER_DATA(VB)->verts + VB->Count; + +#if 0 /* leaving this out fixes the Heretic2 stray polygon bug */ + if ((ctx->IndirectTriangles & DD_SW_RASTERIZE) == DD_SW_RASTERIZE) { + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + fxMesa->setupdone = 0; + return; + } +#endif + + if (VB->Type == VB_CVA_PRECALC) + fxDDPartialRasterSetup(VB); + else if (ctx->Driver.RasterSetup) /* NULL if in feedback/selection mode */ + ctx->Driver.RasterSetup(VB, VB->CopyStart, VB->Count); + +} + + +/* + * Need to check that merge&render will work before allowing this to + * happen here. Therefore - need to know that this will be fired when + * we get a forbidden input in the elt pipeline - and therefore need to check + * whether we have one *now*. Similarly need to know if state changes cause + * size4 texcoords to be introduced. + */ +void +fxDDCheckPartialRasterSetup(GLcontext * ctx, struct gl_pipeline_stage *d) +{ + fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; + GLuint tmp = fxMesa->setupdone; + + d->type = 0; + d->pre_forbidden_inputs = 0; + fxMesa->setupdone = 0; /* cleared if we return */ + + /* Indirect triangles must be rendered via the immediate pipeline. + * If all rasterization is software, no need to set up. + */ + if ((ctx->Array.Summary & VERT_OBJ_ANY) == 0) + return; + + if ((ctx->IndirectTriangles & DD_SW_SETUP) || + (ctx->IndirectTriangles & DD_SW_RASTERIZE) == DD_SW_RASTERIZE) + return; + + if ((ctx->Texture.ReallyEnabled & 0xf) && + !(ctx->Array.Flags & VERT_TEX0_ANY)) { + if (ctx->TextureMatrix[0].type == MATRIX_GENERAL || + ctx->TextureMatrix[0].type == MATRIX_PERSPECTIVE || + (ctx->Texture.Unit[0].TexGenEnabled & Q_BIT)) + return; + + d->pre_forbidden_inputs |= VERT_TEX0_4; + } + + if ((ctx->Texture.ReallyEnabled & 0xf0) && + !(ctx->Array.Flags & VERT_TEX1_ANY)) { + if (ctx->TextureMatrix[1].type == MATRIX_GENERAL || + ctx->TextureMatrix[1].type == MATRIX_PERSPECTIVE || + (ctx->Texture.Unit[1].TexGenEnabled & Q_BIT)) + return; + + d->pre_forbidden_inputs |= VERT_TEX1_4; + } + + + fxMesa->setupdone = tmp; + d->inputs = 0; + d->outputs = VERT_SETUP_PART; + d->type = PIPE_PRECALC; +} + + +/* Will be different every time - no point in trying to precalc the + * function to call. + */ +void +fxDDPartialRasterSetup(struct vertex_buffer *VB) +{ + GLuint new = VB->pipeline->new_outputs; + fxMesaContext fxMesa = (fxMesaContext) VB->ctx->DriverCtx; + GLuint ind = 0; + + FX_DRIVER_DATA(VB)->last_vert = FX_DRIVER_DATA(VB)->verts + VB->Count; + + if (new & VERT_WIN) { + new = VB->pipeline->outputs; + ind |= SETUP_XY | SETUP_W | SETUP_Z; + } + + if (new & VERT_TEX0_ANY) + ind |= SETUP_W | fxMesa->tex_dest[0]; + + if (new & VERT_TEX1_ANY) + ind |= SETUP_W | fxMesa->tex_dest[1]; + + if (new & VERT_RGBA) + ind |= SETUP_W | SETUP_RGBA; + + if ((new & VERT_WIN) == 0) + ind &= ~(fxMesa->setupdone & SETUP_W); + + fxMesa->setupdone &= ~ind; + ind &= fxMesa->setupindex; + fxMesa->setupdone |= ind; + + if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_PIPELINE)) { + gl_print_vert_flags("new outputs", VB->pipeline->new_outputs); + fxPrintSetupFlags("fxmesa: partial setup function", ind); + } + + if (ind) + setupfuncs[ind] (VB, VB->Start, VB->Count); +} + +/* Almost certainly never called. + */ +void +fxDDResizeVB(struct vertex_buffer *VB, GLuint size) +{ + struct tfxMesaVertexBuffer *fvb = FX_DRIVER_DATA(VB); + + while (fvb->size < size) + fvb->size *= 2; + + ALIGN_FREE(VB->ClipMask); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * fvb->size, 4); + + FREE(fvb->vert_store); + fvb->vert_store = MALLOC(sizeof(fxVertex) * fvb->size + 31); + if (!fvb->vert_store || !VB->ClipMask) { + fprintf(stderr, "fx Driver: out of memory !\n"); + return; + } + fvb->verts = (fxVertex *) (((unsigned long) fvb->vert_store + 31) & ~31); + + gl_vector1ui_free(&fvb->clipped_elements); + gl_vector1ui_alloc(&fvb->clipped_elements, VEC_WRITABLE, fvb->size, 32); + + if (!fvb->clipped_elements.start) + goto memerror; + + return; + memerror: + fprintf(stderr, "fx Driver: out of memory !\n"); +} + + +void +fxDDRegisterVB(struct vertex_buffer *VB) +{ + struct tfxMesaVertexBuffer *fvb; + + fvb = (struct tfxMesaVertexBuffer *) calloc(1, sizeof(*fvb)); + + /* This looks like it allocates a lot of memory, but it basically + * just sets an upper limit on how much can be used - nothing like + * this amount will ever be turned into 'real' memory. + */ + if (VB->Type == VB_CVA_PRECALC) { + fvb->size = VB->Size * 5; + fvb->vert_store = MALLOC(sizeof(fxVertex) * fvb->size + 31); + if (!fvb->vert_store) + goto memerror; +#if defined(FX_GLIDE3) + fvb->triangle_b = MALLOC(sizeof(GrVertex *) * 4 * fvb->size + 31); + if (!fvb->triangle_b) + goto memerror; + fvb->strips_b = MALLOC(sizeof(GrVertex *) * 4 * fvb->size + 31); + if (!fvb->strips_b) + goto memerror; +#endif + fvb->verts = + (fxVertex *) (((unsigned long) fvb->vert_store + 31) & ~31); + gl_vector1ui_alloc(&fvb->clipped_elements, VEC_WRITABLE, fvb->size, + 32); + if (!fvb->clipped_elements.start) + goto memerror; + + ALIGN_FREE(VB->ClipMask); + VB->ClipMask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte) * fvb->size, 4); + if (!VB->ClipMask) + goto memerror; + + } + else { + fvb->vert_store = MALLOC(sizeof(fxVertex) * (VB->Size + 12) + 31); + if (!fvb->vert_store) + goto memerror; +#if defined(FX_GLIDE3) + fvb->triangle_b = MALLOC(sizeof(GrVertex *) * 4 * fvb->size + 31); + if (!fvb->triangle_b) + goto memerror; + fvb->strips_b = MALLOC(sizeof(GrVertex *) * 4 * fvb->size + 31); + if (!fvb->strips_b) + goto memerror; +#endif + fvb->verts = + (fxVertex *) (((unsigned long) fvb->vert_store + 31) & ~31); + fvb->size = VB->Size + 12; + } + + + VB->driver_data = fvb; + return; + memerror: + fprintf(stderr, "fx Driver: out of memory !\n"); +} + + +void +fxDDUnregisterVB(struct vertex_buffer *VB) +{ + struct tfxMesaVertexBuffer *fvb = FX_DRIVER_DATA(VB); + + if (fvb) { + if (fvb->vert_store) + FREE(fvb->vert_store); + gl_vector1ui_free(&fvb->clipped_elements); + FREE(fvb); +#if defined(FX_GLIDE3) + if (fvb->strips_b) + FREE(fvb->strips_b); + if (fvb->triangle_b) + FREE(fvb->triangle_b); +#endif + VB->driver_data = 0; + } +} diff --git a/xc/extras/Mesa/src/FX/fxvsetup.h b/xc/lib/GL/mesa/src/drv/tdfx/fxvsetup.h index 48123c46b..9c50f1cc9 100644 --- a/xc/extras/Mesa/src/FX/fxvsetup.h +++ b/xc/lib/GL/mesa/src/drv/tdfx/fxvsetup.h @@ -1,5 +1,3 @@ -/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */ - /* * Mesa 3-D graphics library * Version: 3.3 @@ -47,7 +45,7 @@ #define _FXVSETUP_H_ -#define VARS_W +#define VARS_W #define VARS_Z @@ -73,9 +71,9 @@ #define VARS_RGBA \ GLubyte *color = VEC_ELT(VB->ColorPtr, GLubyte, start); \ - GLuint col_stride = VB->ColorPtr->stride; + GLuint col_stride = VB->ColorPtr->stride; -#define VARS_XY GLfloat *win = VB->Win.data[start]; +#define VARS_XY GLfloat *win = VB->Win.data[start]; #define INCR_XY win += 4 @@ -83,12 +81,12 @@ #ifdef FX_V2 # define DO_SETUP_XY \ v[XCOORD]=win[0]; \ - v[YCOORD]=win[1]; + v[YCOORD]=win[1]; #else #ifdef DRIVERTS # define DO_SETUP_XY \ v[XCOORD]=win[0]+fxMesa->x_offset; \ - v[YCOORD]=win[1]+fxMesa->y_delta; + v[YCOORD]=win[1]+fxMesa->y_delta; #else # if (defined(__linux__) && defined(__i386__)) || defined(macintosh) # define DO_SETUP_XY { \ @@ -118,7 +116,7 @@ { \ v[S0COORD]=sscale0*tmu0_data[0]*v[OOWCOORD]; \ v[T0COORD]=tscale0*tmu0_data[1]*v[OOWCOORD]; \ -} +} #define INCR_TMU0 STRIDE_F(tmu0_data, tmu0_stride) @@ -133,7 +131,7 @@ #if FX_USE_PARGB #define DO_SETUP_RGBA \ { GET_PARGB(v) = color[ACOMP] << 24 | color[RCOMP] << 16 | color[GCOMP] << 8 | color[BCOMP];} - + #else #define DO_SETUP_RGBA \ { \ @@ -155,14 +153,14 @@ if (tmu0_sz == 4) { \ project_texcoords( VB, 0, tmu0_source, start, end ); \ hs |= GR_STWHINT_W_DIFF_TMU0; \ - } + } #define _FIXUP_TMU1 \ if (tmu1_sz == 4) { \ project_texcoords( VB, 1, tmu1_source, start, end ); \ hs |= GR_STWHINT_W_DIFF_TMU1; \ - } + } #define _FIXUP_TMU01 \ @@ -181,7 +179,7 @@ #define _FIXUP_POST \ if (hs != fxMesa->stw_hint_state) { \ fxMesa->stw_hint_state = hs; \ - FX_grHints(GR_HINT_STWHINT, hs); \ + FX_grHints(fxMesa, GR_HINT_STWHINT, hs); \ } diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c index 70e7bbbb8..cfa099433 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c @@ -36,74 +36,60 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <X11/Xlibint.h> #include "xf86dri.h" #include "tdfx_dri.h" -#include "tdfx_init.h" +#include "fxdrv.h" + #ifdef DEBUG_LOCKING -char *prevLockFile=0; -int prevLockLine=0; +char *prevLockFile = 0; +int prevLockLine = 0; #endif -static void performMagic(__DRIscreenPrivate *driScrnPriv) +static void +performMagic(__DRIscreenPrivate * driScrnPriv) { - tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *)driScrnPriv->private; - TDFXDRIPtr gDRIPriv = (TDFXDRIPtr)driScrnPriv->pDevPriv; - - gPriv->regs.handle=gDRIPriv->regs; - gPriv->regs.size=gDRIPriv->regsSize; - gPriv->deviceID=gDRIPriv->deviceID; - gPriv->width=gDRIPriv->width; - gPriv->height=gDRIPriv->height; - gPriv->mem=gDRIPriv->mem; - gPriv->cpp=gDRIPriv->cpp; - gPriv->stride=gDRIPriv->stride; - gPriv->fifoOffset=gDRIPriv->fifoOffset; - gPriv->fifoSize=gDRIPriv->fifoSize; - gPriv->fbOffset=gDRIPriv->fbOffset; - gPriv->backOffset=gDRIPriv->backOffset; - gPriv->depthOffset=gDRIPriv->depthOffset; - gPriv->textureOffset=gDRIPriv->textureOffset; - gPriv->textureSize=gDRIPriv->textureSize; + tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *) driScrnPriv->private; + TDFXDRIPtr gDRIPriv = (TDFXDRIPtr) driScrnPriv->pDevPriv; + + gPriv->regs.handle = gDRIPriv->regs; + gPriv->regs.size = gDRIPriv->regsSize; + gPriv->deviceID = gDRIPriv->deviceID; + gPriv->width = gDRIPriv->width; + gPriv->height = gDRIPriv->height; + gPriv->mem = gDRIPriv->mem; + gPriv->cpp = gDRIPriv->cpp; + gPriv->stride = gDRIPriv->stride; + gPriv->fifoOffset = gDRIPriv->fifoOffset; + gPriv->fifoSize = gDRIPriv->fifoSize; + gPriv->fbOffset = gDRIPriv->fbOffset; + gPriv->backOffset = gDRIPriv->backOffset; + gPriv->depthOffset = gDRIPriv->depthOffset; + gPriv->textureOffset = gDRIPriv->textureOffset; + gPriv->textureSize = gDRIPriv->textureSize; } -GLboolean tdfxMapAllRegions(__DRIscreenPrivate *driScrnPriv) +GLboolean +tdfxMapAllRegions(__DRIscreenPrivate * driScrnPriv) { - tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *)driScrnPriv->private; - + tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *) driScrnPriv->private; + /* First, pick apart pDevPriv & friends */ performMagic(driScrnPriv); - if (drmMap(driScrnPriv->fd, gPriv->regs.handle, gPriv->regs.size, - &gPriv->regs.map)) { - return GL_FALSE; + if (drmMap(driScrnPriv->fd, gPriv->regs.handle, gPriv->regs.size, + &gPriv->regs.map)) { + return GL_FALSE; } return GL_TRUE; } -void tdfxUnmapAllRegions(__DRIscreenPrivate *driScrnPriv) +void +tdfxUnmapAllRegions(__DRIscreenPrivate * driScrnPriv) { - tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *)driScrnPriv->private; + tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *) driScrnPriv->private; drmUnmap(gPriv->regs.map, gPriv->regs.size); } -/* - * Shutdown Glide library - */ -void fxCloseHardware(void) -{ - if (getenv("MESA_FX_INFO")) { - GrSstPerfStats_t st; - - FX_grSstPerfStats(&st); - fprintf(stderr,"Pixels Stats:\n"); - fprintf(stderr," # pixels processed (minus buffer clears): %u\n",(unsigned)st.pixelsIn); - fprintf(stderr," # pixels not drawn due to chroma key test failure: %u\n",(unsigned)st.chromaFail); - fprintf(stderr," # pixels not drawn due to depth test failure: %u\n",(unsigned)st.zFuncFail); - fprintf(stderr," # pixels not drawn due to alpha test failure: %u\n",(unsigned)st.aFuncFail); - fprintf(stderr," # pixels drawn (including buffer clears and LFB writes): %u\n",(unsigned)st.pixelsOut); - } - FX_grGlideShutdown(); -} #endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.h deleted file mode 100644 index 251992d00..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.h +++ /dev/null @@ -1,228 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Daryll Strauss <daryll@precisioninsight.com> - * - */ - -#ifndef _TDFX_INIT_H_ -#define _TDFX_INIT_H_ - -#ifdef GLX_DIRECT_RENDERING - -#include <sys/time.h> -#include <glide.h> -#include "dri_tmm.h" -#include "dri_mesaint.h" -#include "dri_mesa.h" -#include "dri_xmesaapi.h" - - -typedef struct { - drmHandle handle; - drmSize size; - drmAddress map; -} tdfxRegion, *tdfxRegionPtr; - -typedef struct { - tdfxRegion regs; - int deviceID; - int width; - int height; - int mem; - int cpp; - int stride; - int fifoOffset; - int fifoSize; - int fbOffset; - int backOffset; - int depthOffset; - int textureOffset; - int textureSize; - __DRIscreenPrivate *driScrnPriv; -} tdfxScreenPrivate; - -typedef struct { - volatile int fifoPtr; - volatile int fifoRead; - volatile int fifoOwner; - volatile int ctxOwner; - volatile int texOwner; -} TDFXSAREAPriv; - -/* KW: The extra stuff we need to add to an fxContext to make it - * equivalent to a tdfxContextPrivate struct. It may be nice to - * package this up in a struct, but in the meantime this means we - * don't have to be merging stuff by hand between unrelated files. - * - * PLEASE NOTE: if you add stuff here, you have to make sure you only - * try to access it from places which are protected by tests for - * defined(GLX_DIRECT_RENDERING) or defined(XFree86Server). - */ -#define DRI_FX_CONTEXT \ - drmContext hHWContext; \ - int numClipRects; \ - XF86DRIClipRectPtr pClipRects; \ - tdfxScreenPrivate *tdfxScrnPriv; - -typedef struct tfxMesaContext tdfxContextPrivate; - -#include "fxdrv.h" - -extern GLboolean tdfxMapAllRegions(__DRIscreenPrivate *driScrnPriv); -extern void tdfxUnmapAllRegions(__DRIscreenPrivate *driScrnPriv); -extern GLboolean tdfxInitHW(__DRIdrawablePrivate *driDrawPrivate, - tdfxContextPrivate *cPriv); - -extern void XMesaWindowMoved(void); -extern void XMesaUpdateState(int windowMoved); -extern void XMesaSetSAREA(void); - -/* This is the private interface between Glide and DRI */ -extern void grDRIOpen(char *pFB, char *pRegs, int deviceID, - int width, int height, - int mem, int cpp, int stride, - int fifoOffset, int fifoSize, - int fbOffset, int backOffset, int depthOffset, - int textureOffset, int textureSize, - volatile int *fifoPtr, volatile int *fifoRead); -extern void grDRIPosition(int x, int y, int w, int h, - int numClip, XF86DRIClipRectPtr pClip); -extern void grDRILostContext(void); -extern void grDRIImportFifo(int fifoPtr, int fifoRead); -extern void grDRIInvalidateAll(void); -extern void grDRIResetSAREA(void); - -extern __DRIcontextPrivate *gCC; -/*000extern tdfxContextPrivate *gCCPriv;*/ - -/* You can turn this on to find locking conflicts. -#define DEBUG_LOCKING -*/ - -#ifdef DEBUG_LOCKING -extern char *prevLockFile; -extern int prevLockLine; -#define DEBUG_LOCK() \ - do { \ - prevLockFile=(__FILE__); \ - prevLockLine=(__LINE__); \ - } while (0) -#define DEBUG_RESET() \ - do { \ - prevLockFile=0; \ - prevLockLine=0; \ - } while (0) -#define DEBUG_CHECK_LOCK() \ - do { \ - if (prevLockFile) { \ - fprintf(stderr, "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \ - prevLockFile, prevLockLine, __FILE__, __LINE__); \ - exit(1); \ - } \ - } while (0) -#else -#define DEBUG_LOCK() -#define DEBUG_RESET() -#define DEBUG_CHECK_LOCK() -#endif - -/* !!! We may want to separate locks from locks with validation. - This could be used to improve performance for those things - commands that do not do any drawing !!! */ - -#define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret) \ - do { \ - DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ - if (__ret) drmGetLock(fd,context,0); \ - } while(0) - -/* Lock the hardware using the global current context */ -#define LOCK_HARDWARE() \ - do { \ - char __ret=0; \ - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; \ - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; \ - DEBUG_CHECK_LOCK(); \ - DRM_CAS(&sPriv->pSAREA->lock, dPriv->driContextPriv->hHWContext, \ - DRM_LOCK_HELD|dPriv->driContextPriv->hHWContext, __ret); \ - if (__ret) { \ - int stamp; \ - drmGetLock(sPriv->fd, dPriv->driContextPriv->hHWContext, 0); \ - stamp=dPriv->lastStamp; \ - XMESA_VALIDATE_DRAWABLE_INFO(gCC->display, sPriv, dPriv); \ - if (*(dPriv->pStamp)!=stamp) XMesaUpdateState(GL_TRUE); \ - else XMesaUpdateState(GL_FALSE); \ - } \ - DEBUG_LOCK(); \ - } while (0) - -/* Unlock the hardware using the global current context */ -#define UNLOCK_HARDWARE() \ - do { \ - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; \ - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; \ - XMesaSetSAREA(); \ - DRM_UNLOCK(sPriv->fd, &sPriv->pSAREA->lock, \ - dPriv->driContextPriv->hHWContext); \ - DEBUG_RESET(); \ - } while (0) - -#define BEGIN_BOARD_LOCK() LOCK_HARDWARE() -#define END_BOARD_LOCK() UNLOCK_HARDWARE() - -/* - This pair of macros makes a loop over the drawing operations - so it is not self contained and doesn't have the nice single - statement semantics of most macros -*/ -#define BEGIN_CLIP_LOOP() \ - do { \ - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; \ - int _nc; \ - LOCK_HARDWARE(); \ - _nc = dPriv->numClipRects; \ - while (_nc--) { \ - tdfxContextPrivate *gCCPriv = \ - (tdfxContextPrivate *) gCC->driverPrivate; \ - if (gCCPriv->needClip) { \ - gCCPriv->clipMinX=dPriv->pClipRects[_nc].x1; \ - gCCPriv->clipMaxX=dPriv->pClipRects[_nc].x2; \ - gCCPriv->clipMinY=dPriv->pClipRects[_nc].y1; \ - gCCPriv->clipMaxY=dPriv->pClipRects[_nc].y2; \ - fxSetScissorValues(gCCPriv->glCtx); \ - } - -#define END_CLIP_LOOP() \ - } \ - UNLOCK_HARDWARE(); \ - } while (0) - -#endif -#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_inithw.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_inithw.c index 0bafa3190..13806c6e7 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_inithw.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_inithw.c @@ -33,67 +33,63 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifdef GLX_DIRECT_RENDERING -#include "tdfx_init.h" #include <glide.h> +#include "fxdrv.h" -GLboolean tdfxInitHW(__DRIdrawablePrivate *driDrawPriv, - tdfxContextPrivate *fxMesa) + +GLboolean +tdfxInitHW(__DRIdrawablePrivate * driDrawPriv, fxMesaContext fxMesa) { - /* KW: Would be nice to make one of these a member of the other. - */ - __DRIscreenPrivate *driScrnPriv = driDrawPriv->driScreenPriv; - tdfxScreenPrivate *sPriv = (tdfxScreenPrivate*)driScrnPriv->private; + /* KW: Would be nice to make one of these a member of the other. + */ + __DRIscreenPrivate *driScrnPriv = driDrawPriv->driScreenPriv; + tdfxScreenPrivate *sPriv = (tdfxScreenPrivate *) driScrnPriv->private; #ifdef DEBUG_LOCKING - fprintf(stderr, "Debug locking enabled\n"); + fprintf(stderr, "Debug locking enabled\n"); #endif - - if (fxMesa->initDone) return GL_TRUE; - fxMesa->width=driDrawPriv->w; - fxMesa->height=driDrawPriv->h; + if (fxMesa->initDone) + return GL_TRUE; - /* We have to use a light lock here, because we can't do any glide - operations yet. No use of FX_* functions in this function. */ - DRM_LIGHT_LOCK(driScrnPriv->fd, &driScrnPriv->pSAREA->lock, - driDrawPriv->driContextPriv->hHWContext); - FX_grGlideInit_NoLock(); + fxMesa->width = driDrawPriv->w; + fxMesa->height = driDrawPriv->h; - fxMesa->board = 0; - FX_grSstSelect_NoLock(fxMesa->board); + /* We have to use a light lock here, because we can't do any glide + operations yet. No use of FX_* functions in this function. */ + DRM_LIGHT_LOCK(driScrnPriv->fd, &driScrnPriv->pSAREA->lock, + driDrawPriv->driContextPriv->hHWContext); + FX_grGlideInit_NoLock(); - if (sPriv->deviceID==0x3) - fxMesa->haveTwoTMUs=GL_FALSE; - else - fxMesa->haveTwoTMUs=GL_TRUE; + fxMesa->board = 0; + FX_grSstSelect_NoLock(fxMesa->board); - /* !!! We are forcing these !!! */ - fxMesa->haveAlphaBuffer=GL_FALSE; - fxMesa->haveGlobalPaletteTexture=GL_FALSE; + if (sPriv->deviceID == 0x3) + fxMesa->haveTwoTMUs = GL_FALSE; + else + fxMesa->haveTwoTMUs = GL_TRUE; - fxMesa->glideContext = FX_grSstWinOpen_NoLock((FxU32)-1, GR_RESOLUTION_NONE, - GR_REFRESH_NONE, - GR_COLORFORMAT_ABGR, - GR_ORIGIN_LOWER_LEFT, 2, 1); + /* !!! We are forcing these !!! */ + fxMesa->haveAlphaBuffer = GL_FALSE; + fxMesa->haveGlobalPaletteTexture = GL_FALSE; - grDRIResetSAREA(); - DRM_UNLOCK(driScrnPriv->fd, &driScrnPriv->pSAREA->lock, - driDrawPriv->driContextPriv->hHWContext); + fxMesa->glideContext = + FX_grSstWinOpen_NoLock((FxU32) - 1, GR_RESOLUTION_NONE, + GR_REFRESH_NONE, GR_COLORFORMAT_ABGR, + GR_ORIGIN_LOWER_LEFT, 2, 1); - fxMesa->needClip=1; + grDRIResetSAREA(); + DRM_UNLOCK(driScrnPriv->fd, &driScrnPriv->pSAREA->lock, + driDrawPriv->driContextPriv->hHWContext); - if (!fxMesa->glideContext || !fxDDInitFxMesaContext( fxMesa )) - return GL_FALSE; + fxMesa->needClip = 1; - fxInitPixelTables(fxMesa, GL_FALSE); /* Load tables of pixel colors */ + if (!fxMesa->glideContext || !fxDDInitFxMesaContext(fxMesa)) + return GL_FALSE; - fxMesa->initDone=GL_TRUE; - return GL_TRUE; + fxMesa->initDone = GL_TRUE; + return GL_TRUE; } #endif - - - - diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c index b40f0f054..4977c3e44 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c @@ -27,95 +27,106 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* * Authors: - * Daryll Strauss <daryll@precisioninsight.com> - * Brian E. Paul <brian@precisioninsight.com> + * Daryll Strauss <daryll@valinux.com> + * Brian E. Paul <brianp@valinux.com> */ #ifdef GLX_DIRECT_RENDERING #include <X11/Xlibint.h> #include <glide.h> -#include "tdfx_init.h" +#include "fxdrv.h" #include "context.h" #include "matrix.h" #include "mmath.h" #include "vbxform.h" +#include "fxtexman.h" -__DRIcontextPrivate *gCC = 0; +/* including xf86PciInfo.h causes a bunch of errors */ +#ifndef PCI_CHIP_VOODOO5 +#define PCI_CHIP_VOODOO5 0x0009 +#endif -GLboolean XMesaInitDriver(__DRIscreenPrivate *sPriv) +GLboolean +XMesaInitDriver(__DRIscreenPrivate * sPriv) { - tdfxScreenPrivate *gsp; - - /* Check the DRI version */ - { - int major, minor, patch; - if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) { - if (major != 3 || minor != 0 || patch < 0) { - char msg[1000]; - sprintf(msg, "3dfx DRI driver expected DRI version 3.0.x but got version %d.%d.%d", major, minor, patch); - __driMesaMessage(msg); - return GL_FALSE; - } - } - } - - /* Check that the DDX driver version is compatible */ - if (sPriv->ddxMajor != 1 || - sPriv->ddxMinor != 0 || - sPriv->ddxPatch < 0) { - char msg[1000]; - sprintf(msg, "3dfx DRI driver expected DDX driver version 1.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch); - __driMesaMessage(msg); - return GL_FALSE; - } - - /* Check that the DRM driver version is compatible */ - if (sPriv->drmMajor != 1 || - sPriv->drmMinor != 0 || - sPriv->drmPatch < 0) { - char msg[1000]; - sprintf(msg, "3dfx DRI driver expected DRM driver version 1.0.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch); - __driMesaMessage(msg); - return GL_FALSE; - } - - /* Allocate the private area */ - gsp = (tdfxScreenPrivate *)Xmalloc(sizeof(tdfxScreenPrivate)); - if (!gsp) - return GL_FALSE; - - gsp->driScrnPriv = sPriv; - - sPriv->private = (void *) gsp; - - if (!tdfxMapAllRegions(sPriv)) { - Xfree(gsp); - sPriv->private = NULL; - return GL_FALSE; - } - - return GL_TRUE; + tdfxScreenPrivate *gsp; + + /* Check the DRI version */ + { + int major, minor, patch; + if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) { + if (major != 3 || minor != 0 || patch < 0) { + char msg[1000]; + sprintf(msg, + "3dfx DRI driver expected DRI version 3.0.x but got version %d.%d.%d", + major, minor, patch); + __driMesaMessage(msg); + return GL_FALSE; + } + } + } + + /* Check that the DDX driver version is compatible */ + if (sPriv->ddxMajor != 1 || sPriv->ddxMinor != 0 || sPriv->ddxPatch < 0) { + char msg[1000]; + sprintf(msg, + "3dfx DRI driver expected DDX driver version 1.0.x but got version %d.%d.%d", + sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch); + __driMesaMessage(msg); + return GL_FALSE; + } + + /* Check that the DRM driver version is compatible */ + if (sPriv->drmMajor != 1 || sPriv->drmMinor != 0 || sPriv->drmPatch < 0) { + char msg[1000]; + sprintf(msg, + "3dfx DRI driver expected DRM driver version 1.0.x but got version %d.%d.%d", + sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch); + __driMesaMessage(msg); + return GL_FALSE; + } + + /* Allocate the private area */ + gsp = (tdfxScreenPrivate *) Xmalloc(sizeof(tdfxScreenPrivate)); + if (!gsp) + return GL_FALSE; + + gsp->driScrnPriv = sPriv; + + sPriv->private = (void *) gsp; + + if (!tdfxMapAllRegions(sPriv)) { + Xfree(gsp); + sPriv->private = NULL; + return GL_FALSE; + } + + return GL_TRUE; } -void XMesaResetDriver(__DRIscreenPrivate *sPriv) + +void +XMesaResetDriver(__DRIscreenPrivate * sPriv) { - tdfxUnmapAllRegions(sPriv); - Xfree(sPriv->private); - sPriv->private = NULL; + tdfxUnmapAllRegions(sPriv); + Xfree(sPriv->private); + sPriv->private = NULL; } -GLvisual *XMesaCreateVisual(Display *dpy, - __DRIscreenPrivate *driScrnPriv, - const XVisualInfo *visinfo, - const __GLXvisualConfig *config) + +GLvisual * +XMesaCreateVisual(Display * dpy, + __DRIscreenPrivate * driScrnPriv, + const XVisualInfo * visinfo, + const __GLXvisualConfig * config) { - /* Drivers may change the args to _mesa_create_visual() in order to - * setup special visuals. - */ - return _mesa_create_visual( config->rgba, + /* Drivers may change the args to _mesa_create_visual() in order to + * setup special visuals. + */ + return _mesa_create_visual(config->rgba, config->doubleBuffer, config->stereo, _mesa_bitcount(visinfo->red_mask), @@ -129,276 +140,359 @@ GLvisual *XMesaCreateVisual(Display *dpy, config->accumGreenSize, config->accumBlueSize, config->accumAlphaSize, - 0 /* num samples */ ); + 0 /* num samples */ + ); } -GLboolean XMesaCreateContext(Display *dpy, GLvisual *mesaVis, - __DRIcontextPrivate *driContextPriv) +GLboolean +XMesaCreateContext(Display * dpy, GLvisual * mesaVis, + __DRIcontextPrivate * driContextPriv) { - tdfxContextPrivate *cPriv; - __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv; - tdfxScreenPrivate *sPriv = (tdfxScreenPrivate *)driScrnPriv->private; - TDFXSAREAPriv *saPriv; - /*int **fifoPtr;*/ - - cPriv = (tdfxContextPrivate *)Xmalloc(sizeof(tdfxContextPrivate)); - if (!cPriv) { - return GL_FALSE; - } - - cPriv->hHWContext = driContextPriv->hHWContext; - cPriv->tdfxScrnPriv = sPriv; - /* deviceID = 0x05 = Voodoo3 */ - /* deviceID = 0x09 = Voodoo5 (and Voodoo5?) */ - cPriv->haveHwStencil = sPriv->deviceID == 0x9 && sPriv->cpp == 4; - - cPriv->glVis=mesaVis; - cPriv->glBuffer=gl_create_framebuffer(mesaVis, - GL_FALSE, /* software depth buffer? */ - mesaVis->StencilBits > 0 && !cPriv->haveHwStencil, - mesaVis->AccumRedBits > 0, - GL_FALSE /* software alpha channel */ - ); - - cPriv->screen_width=sPriv->width; - cPriv->screen_height=sPriv->height; - cPriv->new_state = ~0; - - cPriv->glCtx = driContextPriv->mesaContext; - cPriv->initDone=GL_FALSE; - - saPriv=(TDFXSAREAPriv*)((char*)driScrnPriv->pSAREA+sizeof(XF86DRISAREARec)); - grDRIOpen(driScrnPriv->pFB, sPriv->regs.map, sPriv->deviceID, - sPriv->width, sPriv->height, sPriv->mem, sPriv->cpp, sPriv->stride, - sPriv->fifoOffset, sPriv->fifoSize, sPriv->fbOffset, - sPriv->backOffset, sPriv->depthOffset, sPriv->textureOffset, - sPriv->textureSize, &saPriv->fifoPtr, &saPriv->fifoRead); - - driContextPriv->driverPrivate = (void *) cPriv; - - return GL_TRUE; + fxMesaContext fxMesa; + __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv; + tdfxScreenPrivate *sPriv = (tdfxScreenPrivate *) driScrnPriv->private; + TDFXSAREAPriv *saPriv; + + fxMesa = (fxMesaContext) Xmalloc(sizeof(struct tfxMesaContext)); + if (!fxMesa) { + return GL_FALSE; + } + + fxMesa->hHWContext = driContextPriv->hHWContext; + fxMesa->tdfxScrnPriv = sPriv; + /* deviceID = 0x05 = Voodoo3 */ + /* deviceID = 0x09 = Voodoo5 (and Voodoo4?) */ + fxMesa->isNapalm = sPriv->deviceID == PCI_CHIP_VOODOO5; + fxMesa->haveHwStencil = fxMesa->isNapalm && sPriv->cpp == 4; + + + fxMesa->glVis = mesaVis; + fxMesa->screen_width = sPriv->width; + fxMesa->screen_height = sPriv->height; + fxMesa->new_state = ~0; + fxMesa->driContextPriv = driContextPriv; + fxMesa->glCtx = driContextPriv->mesaContext; + fxMesa->initDone = GL_FALSE; + + saPriv = + (TDFXSAREAPriv *) ((char *) driScrnPriv->pSAREA + + sizeof(XF86DRISAREARec)); + grDRIOpen(driScrnPriv->pFB, sPriv->regs.map, sPriv->deviceID, + sPriv->width, sPriv->height, sPriv->mem, sPriv->cpp, + sPriv->stride, sPriv->fifoOffset, sPriv->fifoSize, + sPriv->fbOffset, sPriv->backOffset, sPriv->depthOffset, + sPriv->textureOffset, sPriv->textureSize, &saPriv->fifoPtr, + &saPriv->fifoRead); + + driContextPriv->driverPrivate = (void *) fxMesa; + + return GL_TRUE; } -void XMesaDestroyContext(__DRIcontextPrivate *driContextPriv) + +void +XMesaDestroyContext(__DRIcontextPrivate * driContextPriv) { - tdfxContextPrivate *cPriv = (tdfxContextPrivate *) driContextPriv->driverPrivate; - if (cPriv) { - XFree(cPriv); - driContextPriv->driverPrivate = NULL; - } - - if (driContextPriv == gCC) { - gCC = 0; - } + fxMesaContext fxMesa = (fxMesaContext) driContextPriv->driverPrivate; + if (fxMesa) { + XFree(fxMesa); + driContextPriv->driverPrivate = NULL; + } } -GLframebuffer *XMesaCreateWindowBuffer( Display *dpy, - __DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, - GLvisual *mesaVis) +GLframebuffer * +XMesaCreateWindowBuffer(Display * dpy, + __DRIscreenPrivate * driScrnPriv, + __DRIdrawablePrivate * driDrawPriv, + GLvisual * mesaVis) { - return gl_create_framebuffer(mesaVis, - GL_FALSE, /* software depth buffer? */ - mesaVis->StencilBits > 0, - mesaVis->AccumRedBits > 0, - GL_FALSE /* software alpha channel? */ - ); + return gl_create_framebuffer(mesaVis, + GL_FALSE, /* software depth buffer? */ + mesaVis->StencilBits > 0, + mesaVis->AccumRedBits > 0, + GL_FALSE /* software alpha channel? */ + ); } -GLframebuffer *XMesaCreatePixmapBuffer( Display *dpy, - __DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, - GLvisual *mesaVis) +GLframebuffer * +XMesaCreatePixmapBuffer(Display * dpy, + __DRIscreenPrivate * driScrnPriv, + __DRIdrawablePrivate * driDrawPriv, + GLvisual * mesaVis) { #if 0 - /* Different drivers may have different combinations of hardware and - * software ancillary buffers. - */ - return gl_create_framebuffer(mesaVis, - GL_FALSE, /* software depth buffer? */ - mesaVis->StencilBits > 0, - mesaVis->AccumRedBits > 0, - mesaVis->AlphaBits > 0 - ); + /* Different drivers may have different combinations of hardware and + * software ancillary buffers. + */ + return gl_create_framebuffer(mesaVis, + GL_FALSE, /* software depth buffer? */ + mesaVis->StencilBits > 0, + mesaVis->AccumRedBits > 0, + mesaVis->AlphaBits > 0); #else - return NULL; /* not implemented yet */ + return NULL; /* not implemented yet */ #endif } -void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv) +void +XMesaSwapBuffers(__DRIdrawablePrivate * driDrawPriv) { - FxI32 result; + GET_CURRENT_CONTEXT(ctx); + fxMesaContext fxMesa = 0; + + if (!driDrawPriv->mesaBuffer->Visual->DBflag) + return; /* can't swap a single-buffered window */ + + /* If the current context's drawable matches the given drawable + * we have to do a glFinish (per the GLX spec). + */ + if (ctx) { + __DRIdrawablePrivate *curDrawPriv; + fxMesa = FX_CONTEXT(ctx); + curDrawPriv = fxMesa->driContextPriv->driDrawablePriv; + if (curDrawPriv == driDrawPriv) { + /* swapping window bound to current context, flush first */ + FLUSH_VB(ctx, "swap buffers"); + BEGIN_BOARD_LOCK(fxMesa); + } + else { + /* make fxMesa context current */ + grGlideGetState((GrState *) fxMesa->state); + fxMesa = (fxMesaContext) driDrawPriv->driContextPriv->driverPrivate; + BEGIN_BOARD_LOCK(fxMesa); + grSstSelect(fxMesa->board); + grGlideSetState((GrState *) fxMesa->state); + } + } + + #ifdef STATS - int stalls; - extern int texSwaps; - static int prevStalls=0; + { + int stalls; + static int prevStalls = 0; + stalls = grFifoGetStalls(); + if (stalls != prevStalls) { + fprintf(stderr, "%d stalls occurred\n", stalls - prevStalls); + prevStalls = stalls; + } + if (texSwaps) { + fprintf(stderr, "%d texture swaps occurred\n", texSwaps); + texSwaps = 0; + } + } #endif - tdfxContextPrivate *gCCPriv; - /* - ** NOT_DONE: This assumes buffer is currently bound to a context. - ** This needs to be able to swap buffers when not currently bound. - */ - if (gCC == NULL) - return; - gCCPriv = (tdfxContextPrivate *) gCC->driverPrivate; + /* XXX prototype grDRISwapClipRects() function may not be + * needed after all + */ +#if 0 + FX_grDRIBufferSwap(fxMesa, fxMesa->swapInterval); +#elif 1 + grDRIBufferSwap(fxMesa->swapInterval); +#else + grDRISwapClipRects(fxMesa->swapInterval, + driDrawPriv->numClipRects, + driDrawPriv->pClipRects); +#endif - FLUSH_VB( gCCPriv->glCtx, "swap buffers" ); - if (gCC->mesaContext->Visual->DBflag) { -#ifdef STATS - stalls=grFifoGetStalls(); - if (stalls!=prevStalls) { - fprintf(stderr, "%d stalls occurred\n", stalls-prevStalls); - prevStalls=stalls; - } - if (texSwaps) { - fprintf(stderr, "%d texture swaps occurred\n", texSwaps); - texSwaps=0; +#if 0 + { + FxI32 result; + do { + result = FX_grGetInteger(FX_PENDING_BUFFERSWAPS); + } while (result > fxMesa->maxPendingSwapBuffers); } #endif - FX_grDRIBufferSwap(gCCPriv->swapInterval); - do { - result = FX_grGetInteger(FX_PENDING_BUFFERSWAPS); - } while (result > gCCPriv->maxPendingSwapBuffers); - gCCPriv->stats.swapBuffer++; - } -} + fxMesa->stats.swapBuffer++; -GLboolean XMesaUnbindContext(__DRIcontextPrivate *driContextPriv) -{ - if (driContextPriv && driContextPriv == gCC) { - tdfxContextPrivate *gCCPriv; - gCCPriv = (tdfxContextPrivate *) gCC->driverPrivate; - FX_grGlideGetState((GrState*)gCCPriv->state); - } - return GL_TRUE; + + if (ctx) { + if (ctx->DriverCtx != fxMesa) { + /* restore original context */ + fxMesa = FX_CONTEXT(ctx); + grSstSelect(fxMesa->board); + grGlideSetState((GrState *) fxMesa->state); + } + END_BOARD_LOCK(fxMesa); + } } -GLboolean XMesaMakeCurrent(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv) + +GLboolean +XMesaUnbindContext(__DRIcontextPrivate * driContextPriv) { - if (driContextPriv) { - tdfxContextPrivate *gCCPriv; + GET_CURRENT_CONTEXT(ctx); + if (driContextPriv && driContextPriv->mesaContext == ctx) { + fxMesaContext fxMesa = FX_CONTEXT(ctx); + FX_grGlideGetState(fxMesa, (GrState *) fxMesa->state); + } + return GL_TRUE; +} - gCC = driContextPriv; - gCCPriv = (tdfxContextPrivate *)driContextPriv->driverPrivate; - if (!gCCPriv->initDone) { - if (!tdfxInitHW(driDrawPriv, gCCPriv)) - return GL_FALSE; - gCCPriv->width=0; - XMesaWindowMoved(); - FX_grGlideGetState((GrState*)gCCPriv->state); +/* + * This function sends the window position and cliprect list to + * Glide for the given context. + */ +static void +XMesaWindowMoved(fxMesaContext fxMesa) +{ + __DRIdrawablePrivate *dPriv = fxMesa->driContextPriv->driDrawablePriv; + GLcontext *ctx = fxMesa->glCtx; + + grDRIPosition(dPriv->x, dPriv->y, dPriv->w, dPriv->h, + dPriv->numClipRects, dPriv->pClipRects); + fxMesa->numClipRects = dPriv->numClipRects; + fxMesa->pClipRects = dPriv->pClipRects; + if (dPriv->x != fxMesa->x_offset || dPriv->y != fxMesa->y_offset || + dPriv->w != fxMesa->width || dPriv->h != fxMesa->height) { + fxMesa->x_offset = dPriv->x; + fxMesa->y_offset = dPriv->y; + fxMesa->width = dPriv->w; + fxMesa->height = dPriv->h; + fxMesa->y_delta = + fxMesa->screen_height - fxMesa->y_offset - fxMesa->height; } - else { - FX_grSstSelect(gCCPriv->board); - FX_grGlideSetState((GrState*)gCCPriv->state); - XMesaWindowMoved(); + switch (dPriv->numClipRects) { + case 0: + fxMesa->clipMinX = dPriv->x; + fxMesa->clipMaxX = dPriv->x + dPriv->w; + fxMesa->clipMinY = dPriv->y; + fxMesa->clipMaxY = dPriv->y + dPriv->h; + fxSetScissorValues(ctx); + fxMesa->needClip = 0; + break; + case 1: + fxMesa->clipMinX = dPriv->pClipRects[0].x1; + fxMesa->clipMaxX = dPriv->pClipRects[0].x2; + fxMesa->clipMinY = dPriv->pClipRects[0].y1; + fxMesa->clipMaxY = dPriv->pClipRects[0].y2; + fxSetScissorValues(ctx); + fxMesa->needClip = 0; + break; + default: + fxMesa->needClip = 1; } - - gl_make_current2(gCCPriv->glCtx, driDrawPriv->mesaBuffer, driReadPriv->mesaBuffer); - - fxSetupDDPointers(gCCPriv->glCtx); - if (!gCCPriv->glCtx->Viewport.Width) - gl_Viewport(gCCPriv->glCtx, 0, 0, driDrawPriv->w, driDrawPriv->h); - } - else { - gl_make_current(0,0); - gCC = NULL; - } - return GL_TRUE; } -void XMesaWindowMoved(void) +GLboolean +XMesaMakeCurrent(__DRIcontextPrivate * driContextPriv, + __DRIdrawablePrivate * driDrawPriv, + __DRIdrawablePrivate * driReadPriv) { - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; - tdfxContextPrivate *gCCPriv = (tdfxContextPrivate *) gCC->driverPrivate; - GLcontext *ctx = gCCPriv->glCtx; - - grDRIPosition(dPriv->x, dPriv->y, dPriv->w, dPriv->h, - dPriv->numClipRects, dPriv->pClipRects); - gCCPriv->numClipRects=dPriv->numClipRects; - gCCPriv->pClipRects=dPriv->pClipRects; - if (dPriv->x!=gCCPriv->x_offset || dPriv->y!=gCCPriv->y_offset || - dPriv->w!=gCCPriv->width || dPriv->h!=gCCPriv->height) { - gCCPriv->x_offset=dPriv->x; - gCCPriv->y_offset=dPriv->y; - gCCPriv->width=dPriv->w; - gCCPriv->height=dPriv->h; - gCCPriv->y_delta=gCCPriv->screen_height-gCCPriv->y_offset-gCCPriv->height; - } - gCCPriv->needClip=1; - switch (dPriv->numClipRects) { - case 0: - gCCPriv->clipMinX=dPriv->x; - gCCPriv->clipMaxX=dPriv->x+dPriv->w; - gCCPriv->clipMinY=dPriv->y; - gCCPriv->clipMaxY=dPriv->y+dPriv->h; - fxSetScissorValues(ctx); - gCCPriv->needClip=0; - break; - case 1: - gCCPriv->clipMinX=dPriv->pClipRects[0].x1; - gCCPriv->clipMaxX=dPriv->pClipRects[0].x2; - gCCPriv->clipMinY=dPriv->pClipRects[0].y1; - gCCPriv->clipMaxY=dPriv->pClipRects[0].y2; - fxSetScissorValues(ctx); - gCCPriv->needClip=0; - break; - default: - } + if (driContextPriv) { + fxMesaContext fxMesa; + + fxMesa = (fxMesaContext) driContextPriv->driverPrivate; + + if (!fxMesa->initDone) { + if (!tdfxInitHW(driDrawPriv, fxMesa)) + return GL_FALSE; + fxMesa->width = 0; + XMesaWindowMoved(fxMesa); + FX_grGlideGetState(fxMesa, (GrState *) fxMesa->state); + } + else { + FX_grSstSelect(fxMesa, fxMesa->board); + FX_grGlideSetState(fxMesa, (GrState *) fxMesa->state); + XMesaWindowMoved(fxMesa); + } + + assert(fxMesa->glCtx == driContextPriv->mesaContext); + + gl_make_current2(fxMesa->glCtx, driDrawPriv->mesaBuffer, + driReadPriv->mesaBuffer); + + if (!fxMesa->glCtx->Viewport.Width) + gl_Viewport(fxMesa->glCtx, 0, 0, driDrawPriv->w, driDrawPriv->h); + } + else { + gl_make_current(0, 0); + } + return GL_TRUE; } + /* This is called from within the LOCK_HARDWARE routine */ -void XMesaUpdateState(int windowMoved) +void +XMesaUpdateState(fxMesaContext fxMesa) { - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; - tdfxContextPrivate *gCCPriv = (tdfxContextPrivate *) gCC->driverPrivate; - TDFXSAREAPriv *saPriv=(TDFXSAREAPriv*)(((char*)sPriv->pSAREA)+sizeof(XF86DRISAREARec)); - - /* fprintf(stderr, "In FifoPtr=%d FifoRead=%d\n", saPriv->fifoPtr, saPriv->fifoRead); */ - if (saPriv->fifoOwner!=dPriv->driContextPriv->hHWContext) { - grDRIImportFifo(saPriv->fifoPtr, saPriv->fifoRead); - } - if (saPriv->ctxOwner!=dPriv->driContextPriv->hHWContext) { - /* This sequence looks a little odd. Glide mirrors the state, and - when you get the state you are forcing the mirror to be up to - date, and then getting a copy from the mirror. You can then force - that state onto the hardware when you set the state. */ - void *state; - state=malloc(FX_grGetInteger_NoLock(FX_GLIDE_STATE_SIZE)); - FX_grGlideGetState_NoLock(state); - FX_grGlideSetState_NoLock(state); - free(state); - } - if (saPriv->texOwner!=dPriv->driContextPriv->hHWContext) { - fxTMRestoreTextures_NoLock(gCCPriv); - } - if (windowMoved) - XMesaWindowMoved(); + __DRIcontextPrivate *cPriv = fxMesa->driContextPriv; + __DRIdrawablePrivate *dPriv = cPriv->driDrawablePriv; + __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; + TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) (((char *) sPriv->pSAREA) + + sizeof(XF86DRISAREARec)); + int stamp; + char ret; + + DEBUG_CHECK_LOCK(); + DRM_CAS(&sPriv->pSAREA->lock, dPriv->driContextPriv->hHWContext, + DRM_LOCK_HELD | dPriv->driContextPriv->hHWContext, ret); + if (!ret) { + DEBUG_LOCK(); + return; + } + drmGetLock(sPriv->fd, dPriv->driContextPriv->hHWContext, 0); + stamp = dPriv->lastStamp; + /* This macro will update dPriv's cliprects if needed */ + XMESA_VALIDATE_DRAWABLE_INFO(cPriv->display, sPriv, dPriv); + /* fprintf(stderr, "In FifoPtr=%d FifoRead=%d\n", saPriv->fifoPtr, saPriv->fifoRead); */ + if (saPriv->fifoOwner != dPriv->driContextPriv->hHWContext) { + grDRIImportFifo(saPriv->fifoPtr, saPriv->fifoRead); + } + if (saPriv->ctxOwner != dPriv->driContextPriv->hHWContext) { + /* This sequence looks a little odd. Glide mirrors the state, and + when you get the state you are forcing the mirror to be up to + date, and then getting a copy from the mirror. You can then force + that state onto the hardware when you set the state. */ + void *state; + state = malloc(FX_grGetInteger_NoLock(FX_GLIDE_STATE_SIZE)); + FX_grGlideGetState_NoLock(state); + FX_grGlideSetState_NoLock(state); + free(state); + } + if (saPriv->texOwner != dPriv->driContextPriv->hHWContext) { + fxTMRestoreTextures_NoLock(fxMesa); + } +#if 0 + if (*dPriv->pStamp != stamp) +#else + if (*dPriv->pStamp != stamp || + saPriv->ctxOwner != dPriv->driContextPriv->hHWContext) +#endif + XMesaWindowMoved(fxMesa); + DEBUG_LOCK(); } -void XMesaSetSAREA(void) + +/* + * XXX is this used by anyone? + */ +#if 000 +static void +XMesaSetSAREA(void) { - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; - TDFXSAREAPriv *saPriv=(TDFXSAREAPriv*)(((char*)sPriv->pSAREA)+sizeof(XF86DRISAREARec)); - - saPriv->fifoOwner=dPriv->driContextPriv->hHWContext; - saPriv->ctxOwner=dPriv->driContextPriv->hHWContext; - saPriv->texOwner=dPriv->driContextPriv->hHWContext; - grDRIResetSAREA(); - /* fprintf(stderr, "Out FifoPtr=%d FifoRead=%d\n", saPriv->fifoPtr, saPriv->fifoRead); */ + __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; + __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; + TDFXSAREAPriv *saPriv = + (TDFXSAREAPriv *) (((char *) sPriv->pSAREA) + + sizeof(XF86DRISAREARec)); + + saPriv->fifoOwner = dPriv->driContextPriv->hHWContext; + saPriv->ctxOwner = dPriv->driContextPriv->hHWContext; + saPriv->texOwner = dPriv->driContextPriv->hHWContext; + grDRIResetSAREA(); + /* fprintf(stderr, "Out FifoPtr=%d FifoRead=%d\n", saPriv->fifoPtr, saPriv->fifoRead); */ } +#endif + extern void __driRegisterExtensions(void); /* silence compiler warning */ @@ -406,17 +500,18 @@ extern void __driRegisterExtensions(void); /* silence compiler warning */ /* This function is called by libGL.so as soon as libGL.so is loaded. * This is where we'd register new extension functions with the dispatcher. */ -void __driRegisterExtensions(void) +void +__driRegisterExtensions(void) { #if 0 - /* Example. Also look in fxdd.c for more details. */ - { - const int _gloffset_FooBarEXT = 555; /* just an example number! */ - if (_glapi_add_entrypoint("glFooBarEXT", _gloffset_FooBarEXT)) { - void *f = glXGetProcAddressARB("glFooBarEXT"); - assert(f); - } - } + /* Example. Also look in fxdd.c for more details. */ + { + const int _gloffset_FooBarEXT = 555; /* just an example number! */ + if (_glapi_add_entrypoint("glFooBarEXT", _gloffset_FooBarEXT)) { + void *f = glXGetProcAddressARB("glFooBarEXT"); + assert(f); + } + } #endif } diff --git a/xc/programs/Xserver/GL/dri/dri.c b/xc/programs/Xserver/GL/dri/dri.c index 2d1ee7bc9..fce294b2e 100644 --- a/xc/programs/Xserver/GL/dri/dri.c +++ b/xc/programs/Xserver/GL/dri/dri.c @@ -113,6 +113,8 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) if (fd < 0) { /* failed to open DRM */ pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; + DRIDrvMsg(pScreen->myNum, X_INFO, + "[drm] drmOpen failed\n"); return FALSE; } @@ -139,6 +141,9 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pDRIPriv->directRenderingSupport = FALSE; pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; drmClose(pDRIPriv->drmFD); + DRIDrvMsg(pScreen->myNum, X_INFO, + "[drm] drmSetBusid failed (%d, %s)\n", + pDRIPriv->drmFD, pDRIPriv->pDriverInfo->busIdString); return FALSE; } @@ -158,6 +163,8 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pDRIPriv->directRenderingSupport = FALSE; pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; drmClose(pDRIPriv->drmFD); + DRIDrvMsg(pScreen->myNum, X_INFO, + "[drm] drmAddMap failed\n"); return FALSE; } DRIDrvMsg(pScreen->myNum, X_INFO, @@ -172,6 +179,8 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pDRIPriv->directRenderingSupport = FALSE; pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; drmClose(pDRIPriv->drmFD); + DRIDrvMsg(pScreen->myNum, X_INFO, + "[drm] drmMap failed\n"); return FALSE; } DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] mapped SAREA 0x%08lx to %p\n", @@ -188,6 +197,8 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL; drmUnmap(pDRIPriv->pSAREA, pDRIPriv->pDriverInfo->SAREASize); drmClose(pDRIPriv->drmFD); + DRIDrvMsg(pScreen->myNum, X_INFO, + "[drm] drmAddMap failed\n"); return FALSE; } DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] framebuffer handle = 0x%08lx\n", @@ -1430,7 +1441,11 @@ static void DRISpinLockTimeout(drmLock *lock, int val, unsigned long timeout /* in mS */) { int count = 10000; +#ifndef __alpha__ char ret; +#else + int ret; +#endif long s_secs, s_usecs; long f_secs, f_usecs; long msecs; diff --git a/xc/programs/Xserver/GL/dri/sarea.h b/xc/programs/Xserver/GL/dri/sarea.h index 8fffebef8..24ce045e0 100644 --- a/xc/programs/Xserver/GL/dri/sarea.h +++ b/xc/programs/Xserver/GL/dri/sarea.h @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/GL/dri/sarea.h,v 1.1 1999/06/14 07:31:20 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/GL/dri/sarea.h,v 1.4 2000/02/23 04:46:52 martin Exp $ */ /************************************************************************** Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. @@ -31,13 +31,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * Kevin E. Martin <kevin@precisioninsight.com> * Jens Owen <jens@precisioninsight.com> * - * $PI: xc/programs/Xserver/GL/dri/sarea.h,v 1.9 1999/05/19 01:26:35 martin Exp $ */ #ifndef _SAREA_H_ #define _SAREA_H_ -#define SAREA_MAX 0x1000 +/* SAREA area needs to be at least a page */ +#ifdef __alpha__ +#define SAREA_MAX 0x2000 +#else +#define SAREA_MAX 0x1000 +#endif + #define SAREA_MAX_DRAWABLES 256 #define SAREA_DRAWABLE_CLAIMED_ENTRY 0x80000000 diff --git a/xc/programs/Xserver/GL/dri/xf86dri.c b/xc/programs/Xserver/GL/dri/xf86dri.c index 4fd33c2ec..b35e5680b 100644 --- a/xc/programs/Xserver/GL/dri/xf86dri.c +++ b/xc/programs/Xserver/GL/dri/xf86dri.c @@ -449,6 +449,8 @@ ProcXF86DRIGetDrawableInfo( if (rep.numClipRects) rep.length += sizeof(XF86DRIClipRectRec) * rep.numClipRects; + rep.length = ((rep.length + 3) & ~3) >> 2; + WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), (char *)&rep); if (rep.numClipRects) { @@ -502,7 +504,7 @@ ProcXF86DRIGetDeviceInfo( if (rep.devPrivateSize) { rep.length = (SIZEOF(xXF86DRIGetDeviceInfoReply) - SIZEOF(xGenericReply) + - ((rep.devPrivateSize + 3) & ~3)); + ((rep.devPrivateSize + 3) & ~3)) >> 2; } WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), (char *)&rep); diff --git a/xc/programs/Xserver/GL/mesa/src/Imakefile b/xc/programs/Xserver/GL/mesa/src/Imakefile index 59b2c4c14..509077014 100644 --- a/xc/programs/Xserver/GL/mesa/src/Imakefile +++ b/xc/programs/Xserver/GL/mesa/src/Imakefile @@ -355,6 +355,7 @@ LinkSourceFile(zoom.h,$(MESASRCDIR)/src) INCLUDES = -I. -I../include -I$(SERVERSRC)/include -I$(XINCLUDESRC) \ -I../../include -I../../glx + DEFINES = $(GLX_DEFINES) /*-DUSE_X86_ASM */ #if DoLoadableServer diff --git a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_accel.c b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_accel.c index a38e8abe6..6429ccc1c 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_accel.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_accel.c @@ -73,6 +73,8 @@ static void TDFXSubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, int skipleft); static void TDFXSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno); +void TDFXSelectBuffer(TDFXPtr pTDFX, int which); + void TDFXNeedSync(ScrnInfoPtr pScrn) { TDFXPtr pTDFX = TDFXPTR(pScrn); @@ -161,12 +163,22 @@ TDFXSetLFBConfig(TDFXPtr pTDFX) { } else { int chip; int stride, bits; + int TileAperturePitch, lg2TileAperturePitch; if (pTDFX->cpp==2) stride=pTDFX->stride; else stride=4*pTDFX->stride/pTDFX->cpp; bits=pTDFX->backOffset>>12; + for (lg2TileAperturePitch = 0, TileAperturePitch = 1024; + (lg2TileAperturePitch < 5) && + TileAperturePitch < stride; + lg2TileAperturePitch += 1, TileAperturePitch <<= 1); +#if 0 + fprintf(stderr, "Using %d (== lg2(%d)-10) for tile aperture pitch\n", + lg2TileAperturePitch, TileAperturePitch); + fprintf(stderr, "stride == %d\n", stride); +#endif for (chip=0; chip<pTDFX->numChips; chip++) { TDFXWriteChipLongMMIO(pTDFX, chip, LFBMEMORYCONFIG, (bits&0x1FFF) | - SST_RAW_LFB_ADDR_STRIDE_4K | + SST_RAW_LFB_ADDR_STRIDE(lg2TileAperturePitch) | ((bits&0x6000)<<10) | ((stride+127)/128)<<SST_RAW_LFB_TILE_STRIDE_SHIFT); } diff --git a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c index d41141490..0831c92b4 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_dri.c @@ -127,9 +127,10 @@ TDFXInitVisualConfigs(ScreenPtr pScreen) } } if (i!=numConfigs) { - ErrorF("Incorrect initialization of visuals\n"); + xf86DrvMsg(pScreen->myNum, X_ERROR, + "Incorrect initialization of visuals\n"); return FALSE; - } else ErrorF("Created %d visuals\n", numConfigs); + } break; /* 16bpp */ case 24: @@ -224,7 +225,7 @@ TDFXInitVisualConfigs(ScreenPtr pScreen) xf86DrvMsg(pScreen->myNum, X_ERROR, "Incorrect initialization of visuals\n"); return FALSE; - } else ErrorF("Created %d visuals\n", numConfigs); + } break; } pTDFX->numVisualConfigs = numConfigs; @@ -263,12 +264,21 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) switch (pScrn->bitsPerPixel) { case 8: + xf86DrvMsg(pScreen->myNum, X_ERROR, + "DRI not supported in 8 bpp mode, disabling DRI.\n"); return FALSE; case 16: break; case 24: + xf86DrvMsg(pScreen->myNum, X_ERROR, + "DRI not supported in 24 bpp mode, disabling DRI.\n"); + return FALSE; case 32: - if (pTDFX->ChipType<=PCI_CHIP_VOODOO3) return FALSE; + if (pTDFX->ChipType<=PCI_CHIP_VOODOO3) { + xf86DrvMsg(pScreen->myNum, X_ERROR, + "DRI requires Voodoo3 or later, disabling DRI.\n"); + return FALSE; + } } /* Check that the GLX, DRI, and DRM modules have been loaded by testing @@ -295,8 +305,12 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) } pDRIInfo = DRICreateInfoRec(); - if (!pDRIInfo) - return FALSE; + if (!pDRIInfo) { + xf86DrvMsg(pScreen->myNum, X_ERROR, + "DRICreatInfoRect() failed, disabling DRI.\n"); + return FALSE; + } + pTDFX->pDRIInfo = pDRIInfo; pDRIInfo->drmDriverName = TDFXKernelDriverName; @@ -336,13 +350,14 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) * in the SAREA header */ if (sizeof(XF86DRISAREARec)+sizeof(TDFXSAREAPriv)>SAREA_MAX) { - xf86DrvMsg(pScreen->myNum, X_ERROR, "Data does not fit in SAREA\n"); + xf86DrvMsg(pScreen->myNum, X_ERROR, "Data does not fit in SAREA\n"); return FALSE; } pDRIInfo->SAREASize = SAREA_MAX; #endif if (!(pTDFXDRI = (TDFXDRIPtr)xnfcalloc(sizeof(TDFXDRIRec),1))) { + xf86DrvMsg(pScreen->myNum, X_ERROR, "DRI memory allocation failed, disabling DRI.\n"); DRIDestroyInfoRec(pTDFX->pDRIInfo); pTDFX->pDRIInfo=0; return FALSE; @@ -363,6 +378,8 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) pDRIInfo->devPrivate=0; DRIDestroyInfoRec(pTDFX->pDRIInfo); pTDFX->pDRIInfo=0; + xf86DrvMsg(pScreen->myNum, X_ERROR, "DRIScreenInit failed, disabling DRI.\n"); + return FALSE; } @@ -391,6 +408,7 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) if (drmAddMap(pTDFX->drmSubFD, (drmHandle)pTDFX->MMIOAddr[0], pTDFXDRI->regsSize, DRM_REGISTERS, 0, &pTDFXDRI->regs)<0) { TDFXDRICloseScreen(pScreen); + xf86DrvMsg(pScreen->myNum, X_ERROR, "drmAddMap failed, disabling DRI.\n"); return FALSE; } xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] Registers = 0x%08lx\n", @@ -398,6 +416,7 @@ Bool TDFXDRIScreenInit(ScreenPtr pScreen) if (!(TDFXInitVisualConfigs(pScreen))) { TDFXDRICloseScreen(pScreen); + xf86DrvMsg(pScreen->myNum, X_ERROR, "TDFXInitVisualConfigs failed, disabling DRI.\n"); return FALSE; } xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configs initialized\n" ); diff --git a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c index 55de9b066..3f0aee798 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c +++ b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_driver.c @@ -636,7 +636,6 @@ TDFXPreInit(ScrnInfoPtr pScrn, int flags) ClockRangePtr clockRanges; int i; MessageType from; - char *mod=0, *reqSym=0; int flags24; rgb defaultWeight = {0, 0, 0}; pciVideoPtr match; @@ -663,7 +662,7 @@ TDFXPreInit(ScrnInfoPtr pScrn, int flags) if (flags & PROBE_DETECT) { TDFXProbeDDC(pScrn, pTDFX->pEnt->index); - return FALSE; + return TRUE; } /* The vgahw module should be loaded here when needed */ @@ -1195,7 +1194,10 @@ CalcPLL(int freq, int *f_out, int isBanshee) { maxm=24; } else { minm=1; - maxm=64; + maxm=57; /* This used to be 64, alas it seems the last 8 (funny that ?) + * values cause jittering at lower resolutions. I've not done + * any calculations to what the adjustment affects clock ranges, + * but I can still run at 1600x1200@75Hz */ } for (n=1; n<256; n++) { f_cur=REFFREQ*(n+2); @@ -1604,15 +1606,6 @@ static void allocateMemory(ScrnInfoPtr pScrn) { pTDFX = TDFXPTR(pScrn); pTDFX->stride = pScrn->displayWidth*pTDFX->cpp; - /* Layout the memory. Start with all the ram */ - memRemaining=pScrn->videoRam<<10; - /* Remove the cursor space */ - memRemaining-=4096; - /* Remove the main screen and offscreen pixmaps */ - memRemaining-=pTDFX->stride*(pScrn->virtualY+128); - /* Remove one scanline for page alignment */ - memRemaining-=4095; - /* Remove the back and Z buffers */ if (pTDFX->cpp!=3) { screenSizeInTiles=calcBufferSize(pScrn->virtualX, pScrn->virtualY, TRUE, pTDFX->cpp); @@ -1622,41 +1615,77 @@ static void allocateMemory(ScrnInfoPtr pScrn) { screenSizeInTiles=calcBufferSize(pScrn->virtualX, pScrn->virtualY, TRUE, 4); } - memRemaining-=screenSizeInTiles*2; - - /* Give all the rest to textures, rounded down to a page */ - texSize=memRemaining&~0xFFF; - - /* Make sure fifo has CMDFIFO_PAGES<fifoSize<255 pages */ - if (memRemaining-texSize<CMDFIFO_PAGES<<12) - texSize=(memRemaining-(CMDFIFO_PAGES<<12))&~0xFFF; - /* Fifo uses the remaining space up to 255 pages */ - fifoSize = (memRemaining-texSize)&~0xFFF; - if (fifoSize>255<<12) fifoSize=255<<12; - - /* Assign the variables */ - /* Cursor */ - pTDFX->cursorOffset=0; /* Size 1024 bytes */ - - /* Point the fifo at the first page */ + memRemaining=((pScrn->videoRam<<10) - 1) &~ 0xFFF; + /* Note that a page is 4096 bytes, and a */ + /* tile is 32 x 128 = 4096 bytes. So, */ + /* page and tile boundaries are the same */ + /* Place the depth offset first, forcing */ + /* it to be on an *odd* page boundary. */ + pTDFX->depthOffset = (memRemaining - screenSizeInTiles) &~ 0xFFF; + if ((pTDFX->depthOffset & (0x1 << 12)) == 0) { +#if 0 + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Changing depth offset from 0x%08x to 0x%08x\n", + pTDFX->depthOffset, + pTDFX->depthOffset - (0x1 << 12)); +#endif + pTDFX->depthOffset -= (0x1 << 12); + } + /* Now, place the back buffer, forcing it */ + /* to be on an *even* page boundary. */ + pTDFX->backOffset = (pTDFX->depthOffset - screenSizeInTiles) &~ 0xFFF; + if (pTDFX->backOffset & (0x1 << 12)) { +#if 0 + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Changing back offset from 0x%08x to 0x%08x\n", + pTDFX->backOffset, + pTDFX->backOffset - (0x1 << 12)); +#endif + pTDFX->backOffset -= (0x1 << 12); + } + /* Now, place the front buffer, forcing */ + /* it to be on a page boundary too, just */ + /* for giggles. */ + pTDFX->fbOffset + = (pTDFX->backOffset - (pScrn->virtualY+128)*pTDFX->stride) &~ 0xFFF; + /* Give the cmd fifo at least */ + /* CMDFIFO_PAGES pages, but no more than */ + /* 255. */ + fifoSize = ((255 <= CMDFIFO_PAGES) ? 255 : CMDFIFO_PAGES) << 12; + /* We give 4096 bytes to the cursor, fifoSize to the */ + /* FIFO, and everything to textures. */ + texSize = (pTDFX->fbOffset - fifoSize - 4096); + pTDFX->texOffset = pTDFX->fbOffset - texSize; + pTDFX->texSize = texSize; pTDFX->fifoOffset = 4096; pTDFX->fifoSize = fifoSize; - - /* Textures */ - pTDFX->texOffset = pTDFX->fifoOffset+fifoSize; - pTDFX->texSize = texSize; - - /* Frame buffer */ - pTDFX->fbOffset=pTDFX->texOffset+pTDFX->texSize; - - /* Back buffer */ - pTDFX->backOffset=pTDFX->fbOffset+(pScrn->virtualY+128)*pTDFX->stride; - /* Round off to a page */ - pTDFX->backOffset=(pTDFX->backOffset+4095)&~0xFFF; - - /* Depth buffer */ - pTDFX->depthOffset=pTDFX->backOffset+screenSizeInTiles; - + pTDFX->cursorOffset = 0; +#if 0 + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Cursor Offset: [0x%08X,0x%08X)\n", + pTDFX->cursorOffset, + pTDFX->cursorOffset+1024); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Fifo Offset: [0x%08X, 0x%08X)\n", + pTDFX->fifoOffset, + pTDFX->fifoOffset+fifoSize); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Texture Offset: [0x%08X, 0x%08X)\n", + pTDFX->texOffset, + pTDFX->texOffset + texSize); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Front Buffer Offset: [0x%08X, 0x%08X)\n", + pTDFX->fbOffset, + pTDFX->fbOffset + (pScrn->virtualY+128)*pTDFX->stride); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "BackOffset: [0x%08X, 0x%08X)\n", + pTDFX->backOffset, + pTDFX->backOffset+screenSizeInTiles); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "DepthOffset: [0x%08X, 0x%08X)\n", + pTDFX->depthOffset, + pTDFX->depthOffset+screenSizeInTiles); +#endif /* 0/1 */ xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Textures Memory %0.02f MB\n", (float)texSize/1024.0/1024.0); } diff --git a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfxdefs.h b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfxdefs.h index ed177cb5a..b5ea9f908 100644 --- a/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfxdefs.h +++ b/xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfxdefs.h @@ -52,8 +52,26 @@ #define MEM_TYPE_SGRAM 0 #define MEM_TYPE_SDRAM 1 +/* + * SST_RAW_LFB_ADDR_STRIDE(Lg2SizeInK) takes the + * lfbMemoryConfig value for SGRAMStrideInTiles. This + * is given by this table: + * SGRAMStrideInBytes lfbMemoryConfig Value + * ================== ===================== + * 1k 0 + * 2k 1 + * 4k 2 + * 8k 3 + * 16k 4 + * + * FWIW, the right hand column is log2(left hand column)-10 + */ #define SST_RAW_LFB_ADDR_STRIDE_SHIFT 13 -#define SST_RAW_LFB_ADDR_STRIDE_4K 0x2<<SST_RAW_LFB_ADDR_STRIDE_SHIFT +#define SST_RAW_LFB_ADDR_STRIDE(Lg2SizeInK) \ + ((Lg2SizeInK)<<SST_RAW_LFB_ADDR_STRIDE_SHIFT) +#define SST_RAW_LFB_ADDR_STRIDE_4K SST_RAW_LFB_ADDR_STRIDE(2) +#define SST_RAW_LFB_ADDR_STRIDE_8K SST_RAW_LFB_ADDR_STRIDE(3) +#define SST_RAW_LFB_ADDR_STRIDE_16K SST_RAW_LFB_ADDR_STRIDE(4) #define SST_RAW_LFB_TILE_STRIDE_SHIFT 16 #define BLIT_LEFT 1 diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux index fb39374a6..7fe57f8e3 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux @@ -126,6 +126,7 @@ SIS := $(shell gcc -E -nostdinc -I$(TREE) picker.c 2>/dev/null \ | grep -s 'SIS = ' | cut -d' ' -f3) PARAMS := $(shell if fgrep kill_fasync $(TREE)/linux/fs.h \ | egrep -q '(band|int, int)'; then echo 3; else echo 2; fi) +MACHINE := $(shell echo `uname -m`) ifeq ($(AGP),0) AGP := $(shell gcc -E -nostdinc -I$(TREE) picker.c 2>/dev/null \ | grep -s 'AGP_MODULE = ' | cut -d' ' -f3) @@ -134,7 +135,11 @@ endif ifeq ($(AGP),1) MODCFLAGS += -DCONFIG_AGP -DCONFIG_AGP_MODULE DRMOBJS += agpsupport.o -MODS += mga.o i810.o +MODS += mga.o +ifeq ($(MACHINE),i386) +MODS += i810.o +endif + MGAOBJS= mga_drv.o mga_dma.o mga_bufs.o mga_state.o mga_context.o MGAHEADERS= mga_drv.h $(DRMHEADERS) @@ -159,6 +164,7 @@ endif all::;@echo === KERNEL HEADERS IN $(TREE) all::;@echo === SMP=${SMP} MODVERSIONS=${MODVERSIONS} AGP=${AGP} SIS=${SIS} all::;@echo === kill_fasync has $(PARAMS) parameters +all::;@echo === Compiling for machine $(MACHINE) all:: $(LIBS) $(MODS) $(PROGS) endif diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drmP.h b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drmP.h index d6de193d2..2bfd4befa 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drmP.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drmP.h @@ -33,6 +33,12 @@ #define _DRM_P_H_ #ifdef __KERNEL__ +#ifdef __alpha__ +/* add include of current.h so that "current" is defined + * before static inline funcs in wait.h. Doing this so we + * can build the DRM (part of PI DRI). 4/21/2000 S + B */ +#include <asm/current.h> +#endif /* __alpha__ */ #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> @@ -47,6 +53,9 @@ #include <linux/sched.h> #include <linux/smp_lock.h> /* For (un)lock_kernel */ #include <linux/mm.h> +#ifdef __alpha__ +#include <asm/pgtable.h> /* For pte_wrprotect */ +#endif #include <asm/io.h> #include <asm/mman.h> #include <asm/uaccess.h> @@ -147,6 +156,71 @@ typedef struct wait_queue *wait_queue_head_t; #ifndef __HAVE_ARCH_CMPXCHG /* Include this here so that driver can be used with older kernels. */ +#if defined(__alpha__) +static __inline__ unsigned long +__cmpxchg_u32(volatile int *m, int old, int new) +{ + unsigned long prev, cmp; + + __asm__ __volatile__( + "1: ldl_l %0,%2\n" + " cmpeq %0,%3,%1\n" + " beq %1,2f\n" + " mov %4,%1\n" + " stl_c %1,%2\n" + " beq %1,3f\n" + "2: mb\n" + ".subsection 2\n" + "3: br 1b\n" + ".previous" + : "=&r"(prev), "=&r"(cmp), "=m"(*m) + : "r"((long) old), "r"(new), "m"(*m)); + + return prev; +} + +static __inline__ unsigned long +__cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new) +{ + unsigned long prev, cmp; + + __asm__ __volatile__( + "1: ldq_l %0,%2\n" + " cmpeq %0,%3,%1\n" + " beq %1,2f\n" + " mov %4,%1\n" + " stq_c %1,%2\n" + " beq %1,3f\n" + "2: mb\n" + ".subsection 2\n" + "3: br 1b\n" + ".previous" + : "=&r"(prev), "=&r"(cmp), "=m"(*m) + : "r"((long) old), "r"(new), "m"(*m)); + + return prev; +} + +static __inline__ unsigned long +__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) +{ + switch (size) { + case 4: + return __cmpxchg_u32(ptr, old, new); + case 8: + return __cmpxchg_u64(ptr, old, new); + } + return old; +} +#define cmpxchg(ptr,o,n) \ + ({ \ + __typeof__(*(ptr)) _o_ = (o); \ + __typeof__(*(ptr)) _n_ = (n); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ + (unsigned long)_n_, sizeof(*(ptr))); \ + }) + +#elif __i386__ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) { @@ -177,6 +251,7 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, #define cmpxchg(ptr,o,n) \ ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o), \ (unsigned long)(n),sizeof(*(ptr)))) +#endif /* i386 & alpha */ #endif /* Macros to make printk easier */ diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c index f80fb4893..ca35a9f43 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c @@ -416,7 +416,9 @@ void mga_fire_primary(drm_device_t *dev, drm_mga_prim_buf_t *prim) } } +#ifdef __i386__ mga_flush_write_combine(); +#endif atomic_inc(&dev_priv->pending_bufs); MGA_WRITE(MGAREG_PRIMADDRESS, phys_head | TT_GENERAL); MGA_WRITE(MGAREG_PRIMEND, (phys_head + num_dwords * 4) | use_agp); @@ -813,8 +815,10 @@ static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) { /* Poll for the first buffer to insure that * the status register will be correct */ - + +#ifdef __i386__ mga_flush_write_combine(); +#endif MGA_WRITE(MGAREG_PRIMADDRESS, phys_head | TT_GENERAL); MGA_WRITE(MGAREG_PRIMEND, ((phys_head + num_dwords * 4) | diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_drv.h b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_drv.h index 1360cf638..6feba09a6 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_drv.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_drv.h @@ -295,7 +295,7 @@ drm_mga_prim_buf_t *tmp_buf = \ num_dwords + 1 + outcount, ADRINDEX(reg), val); \ if( ++outcount == 4) { \ outcount = 0; \ - dma_ptr[0] = *(u32 *)tempIndex; \ + dma_ptr[0] = *(unsigned long *)tempIndex; \ dma_ptr+=5; \ num_dwords += 5; \ } \ diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c index 0c2f57299..8925cbfff 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_state.c @@ -218,8 +218,8 @@ static void mgaG400EmitTex1(drm_mga_private_t * dev_priv, int source ) /* This takes 25 dwords */ - PRIMOUTREG(MGAREG_TEXCTL2, - regs[MGA_TEXREG_CTL2] | TMC_map1_enable | 0x00008000); + PRIMOUTREG(MGAREG_TEXCTL2, regs[MGA_TEXREG_CTL2] | TMC_map1_enable | + 0x00008000); PRIMOUTREG(MGAREG_TEXCTL, regs[MGA_TEXREG_CTL]); PRIMOUTREG(MGAREG_TEXFILTER, regs[MGA_TEXREG_FILTER]); PRIMOUTREG(MGAREG_TEXBORDERCOL, regs[MGA_TEXREG_BORDERCOL]); @@ -873,7 +873,9 @@ int mga_clear_bufs(struct inode *inode, struct file *filp, clear.clear_color_mask, clear.clear_depth_mask); PRIMUPDATE(dev_priv); +#ifdef __i386__ mga_flush_write_combine(); +#endif mga_dma_schedule(dev, 1); return 0; } @@ -903,7 +905,9 @@ int mga_swap_bufs(struct inode *inode, struct file *filp, PRIMUPDATE(dev_priv); set_bit(MGA_BUF_SWAP_PENDING, &dev_priv->current_prim->buffer_status); +#ifdef __i386__ mga_flush_write_combine(); +#endif mga_dma_schedule(dev, 1); return 0; } @@ -951,7 +955,9 @@ int mga_iload(struct inode *inode, struct file *filp, AGEBUF(dev_priv, buf_priv); buf_priv->discard = 1; mga_freelist_put(dev, buf); +#ifdef __i386__ mga_flush_write_combine(); +#endif mga_dma_schedule(dev, 1); return 0; } @@ -999,7 +1005,9 @@ int mga_vertex(struct inode *inode, struct file *filp, mga_dma_dispatch_vertex(dev, buf); PRIMUPDATE(dev_priv); +#ifdef __i386__ mga_flush_write_combine(); +#endif mga_dma_schedule(dev, 1); return 0; } @@ -1046,7 +1054,9 @@ int mga_indices(struct inode *inode, struct file *filp, mga_dma_dispatch_indices(dev, buf, indices.start, indices.end); PRIMUPDATE(dev_priv); +#ifdef __i386__ mga_flush_write_combine(); +#endif mga_dma_schedule(dev, 1); return 0; } diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/r128_dma.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/r128_dma.c index bcba67826..696353d6e 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/r128_dma.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/r128_dma.c @@ -480,8 +480,10 @@ static int r128_submit_packets_ring_secure(drm_device_t *dev, dev_priv->ring_start, write * sizeof(u32)); +#ifdef __i386__ /* Make sure WC cache has been flushed */ r128_flush_write_combine(); +#endif dev_priv->sarea_priv->ring_write = write; R128_WRITE(R128_PM4_BUFFER_DL_WPTR, write); @@ -583,8 +585,10 @@ static int r128_submit_packets_ring(drm_device_t *dev, dev_priv->ring_start, write * sizeof(u32)); +#ifdef __i386__ /* Make sure WC cache has been flushed */ r128_flush_write_combine(); +#endif dev_priv->sarea_priv->ring_write = write; R128_WRITE(R128_PM4_BUFFER_DL_WPTR, write); @@ -752,8 +756,10 @@ static int r128_send_vertbufs(drm_device_t *dev, drm_r128_vertex_t *v) r128_mark_vertbufs_done(dev); } +#ifdef __i386__ /* Make sure WC cache has been flushed (if in PIO mode) */ if (!dev_priv->cce_is_bm_mode) r128_flush_write_combine(); +#endif /* FIXME: Add support for sending vertex buffer to the CCE here instead of in client code. The v->prim holds the primitive diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c index 10c2222cc..c561f01f3 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/drm/xf86drm.c @@ -502,7 +502,8 @@ int drmAddMap(int fd, map.offset = offset; #ifdef __alpha__ - if (type != DRM_SHM) + /* Make sure we add the bus_base to all but shm */ + if (type != DRM_SHM) map.offset += BUS_BASE; #endif map.size = size; diff --git a/xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h b/xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h index 032023c45..19a86ac8d 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h @@ -203,6 +203,33 @@ typedef struct { unsigned int a[100]; } __drm_dummy_lock_t; } while (0) #endif +#if __GNUC__ >= 2 && defined(__alpha__) + +#define DRM_CAS(lock, old, new, ret) \ + do { \ + int old32; \ + int cur32; \ + __asm__ __volatile__( \ + " mb\n" \ + " zap %4, 0xF0, %0\n" \ + " ldl_l %1, %2\n" \ + " zap %1, 0xF0, %1\n" \ + " cmpeq %0, %1, %1\n" \ + " beq %1, 1f\n" \ + " bis %5, %5, %1\n" \ + " stl_c %1, %2\n" \ + "1: xor %1, 1, %1\n" \ + " stl %1, %3" \ + : "+r" (old32), \ + "+&r" (cur32), \ + "=m" (__drm_dummy_lock(lock)),\ + "=m" (ret) \ + : "r" (old), \ + "r" (new)); \ + } while(0) + +#endif + #ifdef __sparc__ #define DRM_CAS(lock,old,new,__ret) \ do { register unsigned int __old __asm("o0"); \ @@ -229,9 +256,15 @@ do { register unsigned int __old __asm("o0"); \ #define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */ #endif +#ifdef __alpha__ +#define DRM_CAS_RESULT(_result) int _result +#else +#define DRM_CAS_RESULT(_result) char _result +#endif + #define DRM_LIGHT_LOCK(fd,lock,context) \ do { \ - char __ret; \ + DRM_CAS_RESULT(__ret); \ DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ if (__ret) drmGetLock(fd,context,0); \ } while(0) @@ -240,7 +273,7 @@ do { register unsigned int __old __asm("o0"); \ benchmarking only. */ #define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \ do { \ - char __ret; \ + DRM_CAS_RESULT(__ret); \ DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ if (__ret) drmGetLock(fd,context,0); \ else ++count; \ @@ -254,7 +287,7 @@ do { register unsigned int __old __asm("o0"); \ #define DRM_UNLOCK(fd,lock,context) \ do { \ - char __ret; \ + DRM_CAS_RESULT(__ret); \ DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \ if (__ret) drmUnlock(fd,context); \ } while(0) @@ -262,7 +295,7 @@ do { register unsigned int __old __asm("o0"); \ /* Simple spin locks */ #define DRM_SPINLOCK(spin,val) \ do { \ - char __ret; \ + DRM_CAS_RESULT(__ret); \ do { \ DRM_CAS(spin,0,val,__ret); \ if (__ret) while ((spin)->lock); \ @@ -271,7 +304,7 @@ do { register unsigned int __old __asm("o0"); \ #define DRM_SPINLOCK_TAKE(spin,val) \ do { \ - char __ret; \ + DRM_CAS_RESULT(__ret); \ int cur; \ do { \ cur = (*spin).lock; \ @@ -291,7 +324,7 @@ do { register unsigned int __old __asm("o0"); \ #define DRM_SPINUNLOCK(spin,val) \ do { \ - char __ret; \ + DRM_CAS_RESULT(__ret); \ if ((*spin).lock == val) { /* else server stole lock */ \ do { \ DRM_CAS(spin,val,0,__ret); \ |