home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / wrpDisplay.c < prev    next >
C/C++ Source or Header  |  1999-09-23  |  34KB  |  1,057 lines

  1. /*
  2.  * $Id: $ 
  3.  */
  4.  
  5. /*
  6.  * Mesa 3-D graphics library
  7.  * Version:  3.1
  8.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. /*
  26.  * $Log:  $
  27.  */
  28.  
  29. #undef    NO_CONTEXT_AVAILABLE
  30. #include <AOS/amigamesa.h>
  31. #include "AOS/accessArray.h"
  32. #include "AOS/cybDisplay/intern.h"
  33.  
  34. #ifdef    AOS_WARP3D
  35. #define    LockHardware(td, td_ctx)    \
  36.     if (!TstF(td->flags, TD_LOCKED)) {    \
  37.       W3D_LockHardware(td_ctx);        \
  38.       SetF(td->flags, TD_LOCKED);    \
  39.     }
  40.  
  41. #define    UnLockHardware(td, td_ctx)    \
  42.     if (TstF(td->flags, TD_LOCKED)) {    \
  43.       W3D_UnLockHardware(td_ctx);    \
  44.       ClrF(td->flags, TD_LOCKED);    \
  45.     }
  46.  
  47. #define    FlushHardware(td, td_ctx)    \
  48.   if (TstF(td->flags, TD_DIRTY)) {    \
  49.     W3D_Flush(td_ctx);            \
  50.     ClrF(td->flags, TD_DIRTY);        \
  51.   }
  52.  
  53. /**********************************************************************/
  54. /*****                Miscellaneous device driver funcs           *****/
  55. /**********************************************************************/
  56.  
  57. const char *wrpRendererString(void)
  58. {
  59.   return "Warp3D CyberGraphX standard\n";
  60. }
  61.  
  62. const char *wrpRendererStringDB(void)
  63. {
  64.   return "Warp3D CyberGraphX fast\n";
  65. }
  66.  
  67. GLbitfield wrpClearTD(GLcontext * ctx, GLbitfield mask,
  68.               GLboolean all, GLint x, GLint y, GLint width, GLint height)
  69. {
  70.   struct TDdriver *TDdriver;
  71.   W3D_Context *TDcontext;
  72.  
  73.   DEBUGOUT(1, "wrpClearTD()\n");
  74.  
  75.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  76.   TDcontext = TDdriver->td_ctx;
  77.  
  78.   if (TstF(TDdriver->flags, TD_ACTIVE) &&
  79.       TstF(TDdriver->flags, TD_ZBUFFER | TD_SBUFFER)) {
  80.     LockHardware(TDdriver, TDcontext);
  81.  
  82.     if (TstF(TDdriver->flags, TD_ZBUFFER) &&
  83.     TstF(mask, GL_DEPTH_BUFFER_BIT)) {
  84.       if (!((ctx->Visual->DepthBits) || !ctx->Depth.Mask)) {
  85.     W3D_Double clearvalue = (W3D_Double) ctx->Depth.Clear;
  86.  
  87.     W3D_ClearZBuffer(TDcontext, &clearvalue);
  88.     SetF(TDdriver->flags, TD_DIRTY);
  89.     ClrF(mask, GL_DEPTH_BUFFER_BIT);
  90.       }
  91.     }
  92.  
  93.     if (TstF(TDdriver->flags, TD_SBUFFER) &&
  94.     TstF(mask, GL_STENCIL_BUFFER_BIT)) {
  95.       if (!(ctx->Visual->StencilBits == 0)) {
  96.         GLuint sclr = ctx->Stencil.Clear;
  97.  
  98.     W3D_ClearStencilBuffer(TDcontext, (ULONG *)&sclr);
  99.     SetF(TDdriver->flags, TD_DIRTY);
  100.     ClrF(mask, GL_STENCIL_BUFFER_BIT);
  101.       }
  102.     }
  103.   }
  104.   else
  105.     W3D_Flush(TDcontext);
  106.  
  107.   return mask;
  108. }
  109.  
  110. GLbitfield wrpClear(GLcontext * ctx, GLbitfield mask, GLboolean all,
  111.             GLint x, GLint y, GLint width, GLint height)
  112. {
  113.   mask = cybClear(ctx, mask, all, x, y, width, height);
  114.   return wrpClearTD(ctx, mask, all, x, y, width, height);
  115. }
  116.  
  117. void wrpSetIndex(GLcontext * ctx, GLuint index)
  118. {
  119.   amigaMesaContext amesa;
  120.  
  121.   /*
  122.    * Set the amesa color index. 
  123.    */
  124.  
  125.   amesa = (amigaMesaContext) ctx->DriverCtx;
  126.  
  127.   DEBUGOUT(1, "wrpSetIndex(%d)\n", index);
  128.  
  129.   cybSetIndex(ctx, index);
  130.   W3D_SetCurrentColor(amesa->TDdriver->td_ctx, &amesa->TDdriver->Palette[amesa->pixel & 0xFF]);
  131.   W3D_SetCurrentPen(amesa->TDdriver->td_ctx, amesa->pixel & 0xFF);
  132. }
  133.  
  134. void wrpSetColor(GLcontext * ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
  135. {
  136.   amigaMesaContext amesa;
  137.   W3D_Color TDcol;
  138.  
  139.   /*
  140.    * Set the current RGBA color. 
  141.    * r is in 0..255.RedScale 
  142.    * g is in 0..255.GreenScale 
  143.    * b is in 0..255.BlueScale 
  144.    * a is in 0..255.AlphaScale 
  145.    */
  146.  
  147.   amesa = (amigaMesaContext) ctx->DriverCtx;
  148.  
  149.   DEBUGOUT(1, "wrpSetColor(%d, %d, %d, %d)\n", r, g, b, a);
  150.  
  151.   cybSetColor(ctx, r, g, b, a);
  152.   TC_Color(TDcol, r, g, b, a);
  153.   W3D_SetCurrentColor(amesa->TDdriver->td_ctx, &TDcol);
  154.   W3D_SetCurrentPen(amesa->TDdriver->td_ctx, amesa->pixel & 0x000000FF);
  155. }
  156.  
  157. /*
  158.  * OPTIONAL FUNCTION: 
  159.  * Implements glLogicOp if possible.  Return GL_TRUE if the device driver
  160.  * can perform the operation, otherwise return GL_FALSE.  If GL_FALSE
  161.  * is returned, the logic op will be done in software by Mesa.
  162.  */
  163. GLboolean wrpLogicOp(GLcontext * ctx, GLenum op)
  164. {
  165.   switch (op) {
  166.     case GL_CLEAR:
  167.     case GL_SET:
  168.     case GL_COPY:
  169.     case GL_COPY_INVERTED:
  170.     case GL_NOOP:
  171.     case GL_INVERT:
  172.     case GL_AND:
  173.     case GL_NAND:
  174.     case GL_OR:
  175.     case GL_NOR:
  176.     case GL_XOR:
  177.     case GL_EQUIV:
  178.     case GL_AND_REVERSE:
  179.     case GL_AND_INVERTED:
  180.     case GL_OR_REVERSE:
  181.     case GL_OR_INVERTED:
  182.     default:
  183.       break;
  184.   }
  185.  
  186.   return GL_TRUE;
  187. }
  188.  
  189. #include "wrpDisplay/wrpFastLines.c"
  190. #include "wrpDisplay/wrpFastPixels.c"
  191. #include "wrpDisplay/wrpFastPoints.c"
  192. #include "wrpDisplay/wrpFastTriangles.c"
  193.  
  194. #include "wrpDisplay/wrpSetup.c"
  195. #include "wrpDisplay/wrpVertex.c"
  196. #include "wrpDisplay/wrpFastRaster.c"
  197.  
  198. #include "wrpDisplay/wrpDepth.c"
  199. #include "wrpDisplay/wrpFog.c"
  200. #include "wrpDisplay/wrpTexture.c"
  201.  
  202. GLint wrpGetParameteri(const GLcontext * ctx, GLint param)
  203. {
  204. #if 0
  205.   switch (param) {
  206.     case DD_MAX_TEXTURE_SIZE:
  207.       return MAX_TEXTURE_SIZE;
  208.     case DD_MAX_TEXTURES:
  209.       return MAX_TEX_SETS;
  210.     case DD_MAX_TEXTURE_COORD_SETS:
  211.       return MAX_TEX_COORD_SETS;
  212.     case DD_HAVE_HARDWARE_FOG:
  213.       return 1;
  214.   }
  215. #endif
  216.   return 0;
  217. }
  218.  
  219. void wrpNearFar(GLcontext * ctx, GLfloat nearVal, GLfloat farVal)
  220. {
  221.   struct TDdriver *TDdriver;
  222.  
  223.   DEBUGOUT(1, "wrpNearFar()\n");
  224.  
  225.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  226.  
  227.   TDdriver->near = nearVal;
  228.   TDdriver->far = farVal;
  229.   if (nearVal < 1)
  230.     TDdriver->wscale = 1.0;
  231.   else
  232.     TDdriver->wscale = nearVal;
  233.  
  234.   wrpSetupFog(ctx);
  235. }
  236.  
  237. /**********************************************************************/
  238.  
  239. void wrpStandardSwapBuffer(amigaMesaContext amesa)
  240. {
  241.   struct TDdriver *TDdriver = amesa->TDdriver;
  242.   W3D_Context *TDcontext = TDdriver->td_ctx;
  243.  
  244.   DEBUGOUT(1, "wrpStandardSwapBuffer(0x%08x)\n", amesa);
  245.  
  246.   switch (W3D_Flush(TDcontext)) {
  247.     case W3D_NOGFXMEM:    SetF(TDdriver->flags, TD_NOVMEM);    break;
  248.     case W3D_NOTVISIBLE:ClrF(TDdriver->flags, TD_ACTIVE);    break;
  249.     default:                            break;
  250.   }    
  251.  
  252.   W3D_FlushFrame(TDcontext);
  253.   UnLockHardware(TDdriver, TDcontext);
  254.  
  255.   if (!TstF(TDdriver->flags, TD_ACTIVE) &&
  256.       (W3D_GetDriverState(TDdriver->td_ctx) == W3D_SUCCESS)) {
  257.     SetF(TDdriver->flags, TD_ACTIVE);
  258.     SetF(amesa->gl_ctx->NewState, NEW_DRVSTATE0);
  259.   }
  260.  
  261.   (*amesa->SwapBuffer) (amesa);
  262.   W3D_SetDrawRegion(TDcontext, amesa->rp->BitMap, 0, &TDdriver->scissor);
  263. }
  264.  
  265. void wrpStandardDispose(amigaMesaContext amesa)
  266. {
  267.   struct TDdriver *TDdriver;
  268.  
  269.   DEBUGOUT(1, "wrpStandardDispose(0x%08x)\n", amesa);
  270.  
  271.   if ((TDdriver = amesa->TDdriver)) {
  272.     struct gl_texture_object *TDtex = amesa->gl_ctx->Shared->TexObjectList;
  273.  
  274.     W3D_Flush(TDdriver->td_ctx);
  275.     while (TDtex) {
  276.       wrpDeleteTexture(amesa->gl_ctx, TDtex);
  277.       TDtex = TDtex->Next;
  278.     }
  279.  
  280.     if (TstF(TDdriver->flags, TD_ZBUFFER))
  281.       W3D_FreeZBuffer(TDdriver->td_ctx);
  282.  
  283.     W3D_DestroyContext(TDdriver->td_ctx);
  284.     FreeVecPooled(amesaPool, (ULONG *)TDdriver);
  285.     amesa->TDdriver = NULL;
  286.   }
  287. }
  288.  
  289. /**********************************************************************/
  290. /*****                  amiga/Mesa Private Functions              *****/
  291. /**********************************************************************/
  292.  
  293. GLboolean wrpContextSupported(GLcontext * ctx)
  294. {
  295.   amigaMesaContext amesa;
  296.   struct TDdriver *TDdriver;
  297.   W3D_Context *TDcontext;
  298.  
  299.   DEBUGOUT(1, "wrpContextSupported()\n");
  300.  
  301.   amesa = (amigaMesaContext) ctx->DriverCtx;
  302.   TDdriver = amesa->TDdriver;
  303.   TDcontext = TDdriver->td_ctx;
  304.  
  305.   if (!(ctx->NewState & (~NEW_LIGHTING)))
  306.     return GL_TRUE;
  307.  
  308.   /* TODO: remove, as soon as flat shading works correctly */
  309.   if (amesa->depth <= 8)
  310.     return GL_FALSE;
  311.  
  312.   /* color index mode currently not supported (would need some
  313.    * adaptions to the color conversion tables)
  314.    */
  315.   if (!TstF(amesa->visual->flags, VISUAL_RGBMODE))
  316.     return GL_FALSE;
  317.  
  318.   /* depth buffer allocation */
  319.   if (ctx->Depth.Test)
  320.     return GL_FALSE;
  321.  
  322.   /* general check: HW ready? */
  323.   if (!TstF(TDdriver->flags, TD_ACTIVE))
  324.     return GL_FALSE;
  325.  
  326.   /* TODO: implement general check, as soon as available */
  327. #if 0
  328.   if (W3D_Query(TDcontext, W3D_Q_DRAW_TRIANGLE, NULL) == W3D_NOTHING_SUPPORTED)
  329.     return GL_FALSE;
  330. #endif
  331.   if (ctx->Color.DrawBuffer == GL_NONE)
  332.     return GL_FALSE;
  333.  
  334.   /* texture mapping check */
  335.   /* TODO: support 3d textures */
  336.   if (ctx->Texture.Enabled && ctx->Texture.Enabled != TEXTURE0_2D)
  337.     return GL_FALSE;
  338.  
  339.   if (ctx->Texture.Enabled) {
  340.     struct gl_texture_object *curTex = ctx->Texture.Unit[0].Current;
  341.     GLenum envmode = ctx->Texture.Unit[0].EnvMode;
  342.  
  343.     if (TstF(TDdriver->flags, TD_NOVMEM))
  344.       return GL_FALSE;
  345.  
  346.     if (!curTex->Image[0])
  347.       return GL_FALSE;
  348.  
  349.     if (W3D_Query(TDcontext, W3D_Q_TEXMAPPING, NULL) != W3D_FULLY_SUPPORTED)
  350.       return GL_FALSE;
  351.  
  352.     if (ctx->Hint.PerspectiveCorrection == GL_FASTEST) {
  353.       if (((curTex->WrapS == GL_REPEAT) || (curTex->WrapT == GL_REPEAT)) &&
  354.     (W3D_Query(TDcontext, W3D_Q_LINEAR_REPEAT, NULL) != W3D_FULLY_SUPPORTED))
  355.     return GL_FALSE;
  356.  
  357.       if (!TstF(TDdriver->flags, TD_NOCLAMP)) {
  358.     if (((curTex->WrapS != GL_REPEAT) ||
  359.          (curTex->WrapT != GL_REPEAT)) &&
  360.         (W3D_Query(TDcontext, W3D_Q_LINEAR_CLAMP, NULL) != W3D_FULLY_SUPPORTED))
  361.       return GL_FALSE;
  362.       }
  363.  
  364.       if ((curTex->WrapS != curTex->WrapT) &&
  365.       (W3D_Query(TDcontext, W3D_Q_WRAP_ASYM, NULL) != W3D_FULLY_SUPPORTED))
  366.     return GL_FALSE;
  367.  
  368.       if (curTex->Image[0]->Width > W3D_Query(TDcontext, W3D_Q_MAXTEXWIDTH, NULL))
  369.     return GL_FALSE;
  370.  
  371.       if (curTex->Image[0]->Height > W3D_Query(TDcontext, W3D_Q_MAXTEXHEIGHT, NULL))
  372.     return GL_FALSE;
  373.     }
  374.     else {
  375.       if (W3D_Query(TDcontext, W3D_Q_PERSPECTIVE, NULL) != W3D_FULLY_SUPPORTED)
  376.     return GL_FALSE;
  377.  
  378.       if (((curTex->WrapS == GL_REPEAT) || (curTex->WrapT == GL_REPEAT)) &&
  379.       (W3D_Query(TDcontext, W3D_Q_PERSP_REPEAT, NULL) != W3D_FULLY_SUPPORTED))
  380.     return GL_FALSE;
  381.  
  382.       if (!TstF(TDdriver->flags, TD_NOCLAMP)) {
  383.     if (((curTex->WrapS != GL_REPEAT) || (curTex->WrapT != GL_REPEAT)) &&
  384.       (W3D_Query(TDcontext, W3D_Q_PERSP_CLAMP, NULL) != W3D_FULLY_SUPPORTED))
  385.       return GL_FALSE;
  386.       }
  387.  
  388.       if ((curTex->WrapS != curTex->WrapT) &&
  389.       (W3D_Query(TDcontext, W3D_Q_WRAP_ASYM, NULL) != W3D_FULLY_SUPPORTED))
  390.     return GL_FALSE;
  391.  
  392.       if (curTex->Image[0]->Width > W3D_Query(TDcontext, W3D_Q_MAXTEXWIDTH_P, NULL))
  393.     return GL_FALSE;
  394.  
  395.       if (curTex->Image[0]->Height > W3D_Query(TDcontext, W3D_Q_MAXTEXHEIGHT_P, NULL))
  396.     return GL_FALSE;
  397.     }
  398.  
  399.     if (((curTex->MinFilter == GL_LINEAR) ||
  400.      (curTex->MinFilter == GL_LINEAR_MIPMAP_NEAREST) ||
  401.      (curTex->MinFilter == GL_LINEAR_MIPMAP_LINEAR) ||
  402.      (curTex->MagFilter == GL_LINEAR)) &&
  403.     (W3D_Query(TDcontext, W3D_Q_BILINEARFILTER, NULL) != W3D_FULLY_SUPPORTED))
  404.       return GL_FALSE;
  405.  
  406.     if (((curTex->MinFilter == GL_NEAREST_MIPMAP_NEAREST) ||
  407.      (curTex->MinFilter == GL_NEAREST_MIPMAP_LINEAR) ||
  408.      (curTex->MinFilter == GL_LINEAR_MIPMAP_NEAREST) ||
  409.      (curTex->MinFilter == GL_LINEAR_MIPMAP_LINEAR)) &&
  410.     (W3D_Query(TDcontext, W3D_Q_MIPMAPPING, NULL) != W3D_FULLY_SUPPORTED))
  411.       return GL_FALSE;
  412.  
  413.     if (((curTex->MinFilter == GL_NEAREST_MIPMAP_LINEAR) ||
  414.      (curTex->MinFilter == GL_LINEAR_MIPMAP_LINEAR)) &&
  415.     (W3D_Query(TDcontext, W3D_Q_MMFILTER, NULL) != W3D_FULLY_SUPPORTED))
  416.       return GL_FALSE;
  417.  
  418.     if ((envmode == GL_REPLACE) &&
  419.     (W3D_Query(TDcontext, W3D_Q_ENV_REPLACE, NULL) != W3D_FULLY_SUPPORTED))
  420.       return GL_FALSE;
  421.  
  422.     if ((envmode == GL_DECAL) &&
  423.     (W3D_Query(TDcontext, W3D_Q_ENV_DECAL, NULL) != W3D_FULLY_SUPPORTED))
  424.       return GL_FALSE;
  425.  
  426.     if ((envmode == GL_MODULATE) &&
  427.     (W3D_Query(TDcontext, W3D_Q_ENV_MODULATE, NULL) != W3D_FULLY_SUPPORTED))
  428.       return GL_FALSE;
  429.  
  430.     if ((envmode == GL_BLEND) &&
  431.     (W3D_Query(TDcontext, W3D_Q_ENV_BLEND, NULL) != W3D_FULLY_SUPPORTED))
  432.       return GL_FALSE;
  433.  
  434.     if ((curTex->Image[0]->Width != curTex->Image[0]->Height) && (!TstF(TDdriver->flags, TD_RECTTEX)))
  435.       return GL_FALSE;
  436.  
  437.     if (!TDdriver->GLtex)
  438.       return GL_FALSE;
  439.     else {
  440.       struct gl_texture_image *TDintex;
  441.       struct gl_texture_object *TDouttex = TDdriver->GLtex;
  442.       GLuint GLformat = 0, TDformat = 0;
  443.       GLenum format;
  444.       GLshort i = MAX_TEXTURE_LEVELS;
  445.  
  446.       if (!(TDintex = TDouttex->Image[0]))
  447.     return GL_FALSE;
  448.  
  449.       switch (format = TDintex->Format) {
  450.     case GL_ALPHA:          GLformat = W3D_A8;        break;
  451.     case GL_LUMINANCE:      GLformat = W3D_L8;        break;
  452.     case GL_LUMINANCE_ALPHA:  GLformat = W3D_L8A8;        break;
  453.     case GL_INTENSITY:      GLformat = W3D_I8;        break;
  454.     case GL_RGB:          GLformat = W3D_R8G8B8;    break;
  455.     case GL_RGBA:          GLformat = W3D_A8R8G8B8;    break;
  456.     case GL_COLOR_INDEX:
  457.     default:          return GL_FALSE;        break;
  458.       }
  459.  
  460.       if (amesa->depth <= 8)
  461.     TDformat = W3D_CHUNKY;
  462.  
  463.       if (W3D_GetTexFmtInfo(TDcontext, GLformat, TDformat) & W3D_TEXFMT_UNSUPPORTED)
  464.     return GL_FALSE;
  465.  
  466.       /* all mipmap levels must have the same format */
  467.       while (--i >= 0)
  468.     if (TDouttex->Image[i] && (TDouttex->Image[i]->Format != format))
  469.       return GL_FALSE;
  470.  
  471.       if (!(((W3Dtexobj *) (TDouttex->DriverData))->texture))
  472.     return GL_FALSE;                            /* no W3D texture object exists */
  473.     }
  474.   }
  475.  
  476.   /* gouraud / flat shading check */
  477.   if (ctx->Light.ShadeModel == GL_SMOOTH) {
  478.     if (W3D_Query(TDcontext, W3D_Q_GOURAUDSHADING, NULL) != W3D_FULLY_SUPPORTED)
  479.       return GL_FALSE;
  480.   }
  481.   else {
  482.     if (W3D_Query(TDcontext, W3D_Q_FLATSHADING, NULL) != W3D_FULLY_SUPPORTED)
  483.       return GL_FALSE;
  484.   }
  485.  
  486.   /* depth buffer check */
  487.   if (ctx->Depth.Test) {
  488.     if (W3D_Query(TDcontext, W3D_Q_ZBUFFER, NULL) != W3D_FULLY_SUPPORTED)
  489.       return GL_FALSE;
  490.  
  491.     if (W3D_Query(TDcontext, W3D_Q_ZCOMPAREMODES, NULL) != W3D_FULLY_SUPPORTED)
  492.       return GL_FALSE;
  493.  
  494.     if (ctx->Depth.Mask) {
  495.       if (W3D_Query(TDcontext, W3D_Q_ZBUFFERUPDATE, NULL) != W3D_FULLY_SUPPORTED)
  496.     return GL_FALSE;
  497.     }
  498.   }
  499.  
  500.   /* alpha test check */
  501.   if (ctx->Color.AlphaEnabled) {
  502.     if (W3D_Query(TDcontext, W3D_Q_ALPHATEST, NULL) != W3D_FULLY_SUPPORTED)
  503.       return GL_FALSE;
  504.  
  505.     if (W3D_Query(TDcontext, W3D_Q_ALPHATESTMODES, NULL) != W3D_FULLY_SUPPORTED)
  506.       return GL_FALSE;
  507.   }
  508.  
  509.   /* blending check */
  510.   if (ctx->Color.BlendEnabled) {
  511.     GLuint TDsfactor = 0, TDdfactor = 0;
  512.  
  513.     if (W3D_Query(TDcontext, W3D_Q_BLENDING, NULL) == W3D_NOT_SUPPORTED)
  514.       return GL_FALSE;
  515.  
  516.     switch (ctx->Color.BlendSrcRGB) {
  517.       case GL_ZERO:            TDsfactor = W3D_ZERO;                break;
  518.       case GL_ONE:            TDsfactor = W3D_ONE;                break;
  519.       case GL_DST_COLOR:        TDsfactor = W3D_DST_COLOR;            break;
  520.       case GL_ONE_MINUS_DST_COLOR:    TDsfactor = W3D_ONE_MINUS_DST_COLOR;        break;
  521.       case GL_SRC_ALPHA:        TDsfactor = W3D_SRC_ALPHA;            break;
  522.       case GL_ONE_MINUS_SRC_ALPHA:    TDsfactor = W3D_ONE_MINUS_SRC_ALPHA;        break;
  523.       case GL_DST_ALPHA:        TDsfactor = W3D_DST_ALPHA;            break;
  524.       case GL_ONE_MINUS_DST_ALPHA:    TDsfactor = W3D_ONE_MINUS_DST_ALPHA;        break;
  525.       case GL_SRC_ALPHA_SATURATE:    TDsfactor = W3D_SRC_ALPHA_SATURATE;        break;
  526.       case GL_CONSTANT_COLOR:        TDsfactor = W3D_CONSTANT_COLOR;            break;
  527.       case GL_ONE_MINUS_CONSTANT_COLOR:    TDsfactor = W3D_ONE_MINUS_CONSTANT_COLOR;    break;
  528.       case GL_CONSTANT_ALPHA:        TDsfactor = W3D_CONSTANT_ALPHA;            break;
  529.       case GL_ONE_MINUS_CONSTANT_ALPHA:    TDsfactor = W3D_ONE_MINUS_CONSTANT_ALPHA;    break;
  530.       default:                return GL_FALSE;                break;
  531.     }
  532.  
  533.     switch (ctx->Color.BlendDstRGB) {
  534.       case GL_ZERO:            TDdfactor = W3D_ZERO;                break;
  535.       case GL_ONE:            TDdfactor = W3D_ONE;                break;
  536.       case GL_SRC_COLOR:        TDdfactor = W3D_SRC_COLOR;            break;
  537.       case GL_ONE_MINUS_SRC_COLOR:    TDdfactor = W3D_ONE_MINUS_SRC_COLOR;        break;
  538.       case GL_SRC_ALPHA:        TDdfactor = W3D_SRC_ALPHA;            break;
  539.       case GL_ONE_MINUS_SRC_ALPHA:    TDdfactor = W3D_ONE_MINUS_SRC_ALPHA;        break;
  540.       case GL_DST_ALPHA:        TDdfactor = W3D_DST_ALPHA;            break;
  541.       case GL_ONE_MINUS_DST_ALPHA:    TDdfactor = W3D_ONE_MINUS_DST_ALPHA;        break;
  542.       case GL_CONSTANT_COLOR:        TDdfactor = W3D_CONSTANT_COLOR;            break;
  543.       case GL_ONE_MINUS_CONSTANT_COLOR:    TDdfactor = W3D_ONE_MINUS_CONSTANT_COLOR;    break;
  544.       case GL_CONSTANT_ALPHA:        TDdfactor = W3D_CONSTANT_ALPHA;            break;
  545.       case GL_ONE_MINUS_CONSTANT_ALPHA:    TDdfactor = W3D_ONE_MINUS_CONSTANT_ALPHA;    break;
  546.       default:                return GL_FALSE;                break;
  547.     }
  548.  
  549.     if (W3D_SetBlendMode(TDcontext, TDsfactor, TDdfactor) != W3D_SUCCESS)
  550.       return GL_FALSE;
  551.  
  552.     if (W3D_Query(TDcontext, W3D_Q_BLEND_DECAL_FOG, NULL) != W3D_FULLY_SUPPORTED) {
  553.       GLenum envmode = ctx->Texture.Unit[0].EnvMode;
  554.  
  555.       if (ctx->Texture.Enabled && ctx->Fog.Enabled && (envmode == GL_DECAL))
  556.     return GL_FALSE;
  557.     }
  558.   }
  559.  
  560.   /* fogging check */
  561.   if (ctx->Fog.Enabled) {
  562.     if (W3D_Query(TDcontext, W3D_Q_FOGGING, NULL) != W3D_FULLY_SUPPORTED)
  563.       return GL_FALSE;
  564.  
  565.     switch (ctx->Fog.Mode) {
  566.       case GL_LINEAR:
  567.     if (W3D_Query(TDcontext, W3D_Q_LINEAR, NULL) != W3D_FULLY_SUPPORTED) {
  568.       if (TstF(TDdriver->flags, TD_NICEFOG))
  569.         return GL_FALSE;
  570.       else {
  571.         if (W3D_Query(TDcontext, W3D_Q_INTERPOLATED, NULL) != W3D_FULLY_SUPPORTED)
  572.           return GL_FALSE;
  573.       }
  574.     }
  575.     break;
  576.       case GL_EXP:
  577.     if (W3D_Query(TDcontext, W3D_Q_EXPONENTIAL, NULL) != W3D_FULLY_SUPPORTED)
  578.       return GL_FALSE;
  579.     break;
  580.       case GL_EXP2:
  581.     if (W3D_Query(TDcontext, W3D_Q_S_EXPONENTIAL, NULL) != W3D_FULLY_SUPPORTED)
  582.       return GL_FALSE;
  583.       default:
  584.     break;
  585.     }
  586.   }
  587.  
  588.   /* scissor check */
  589.   if (ctx->Scissor.Enabled) {
  590.     if (W3D_Query(TDcontext, W3D_Q_SCISSOR, NULL) != W3D_FULLY_SUPPORTED)
  591.       return GL_FALSE;
  592.   }
  593.  
  594.   /* logic op check */
  595.   if ((ctx->Color.IndexLogicOpEnabled) || (ctx->Color.ColorLogicOpEnabled)) {
  596.     if (W3D_Query(TDcontext, W3D_Q_LOGICOP, NULL) != W3D_FULLY_SUPPORTED)
  597.       return GL_FALSE;
  598.   }
  599.  
  600.   /* masking check */
  601.   if (!(((*(GLuint *) ctx->Color.ColorMask == 0xffffffff) ||
  602.      (*(GLuint *) ctx->Color.ColorMask == 0xffffff00)) &&
  603.     ((ctx->Color.IndexMask & 0xff) == 0xff))) {
  604.     if (W3D_Query(TDcontext, W3D_Q_MASKING, NULL) != W3D_FULLY_SUPPORTED)
  605.       return GL_FALSE;
  606.   }
  607.  
  608.   /* stencil check */
  609.   if (ctx->Stencil.Enabled) {
  610.     if (W3D_Query(TDcontext, W3D_Q_STENCILBUFFER, NULL) != W3D_FULLY_SUPPORTED)
  611.       return GL_FALSE;
  612.  
  613.     if (W3D_Query(TDcontext, W3D_Q_STENCIL_FUNC, NULL) != W3D_FULLY_SUPPORTED)
  614.       return GL_FALSE;
  615.  
  616.     if (W3D_Query(TDcontext, W3D_Q_STENCIL_MASK, NULL) != W3D_FULLY_SUPPORTED)
  617.       return GL_FALSE;
  618.  
  619.     if (W3D_Query(TDcontext, W3D_Q_STENCIL_SFAIL, NULL) != W3D_FULLY_SUPPORTED)
  620.       return GL_FALSE;
  621.  
  622.     if (W3D_Query(TDcontext, W3D_Q_STENCIL_DPFAIL, NULL) != W3D_FULLY_SUPPORTED)
  623.       return GL_FALSE;
  624.  
  625.     if (W3D_Query(TDcontext, W3D_Q_STENCIL_DPPASS, NULL) != W3D_FULLY_SUPPORTED)
  626.       return GL_FALSE;
  627.  
  628.     if (ctx->Stencil.WriteMask != ((1 << STENCIL_BITS) - 1)) {
  629.       if (W3D_Query(TDcontext, W3D_Q_STENCIL_WRMASK, NULL) != W3D_FULLY_SUPPORTED)
  630.     return GL_FALSE;
  631.     }
  632.   }
  633.  
  634.   /* TODO: support specular highlighting completely */
  635.   if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
  636.     return GL_FALSE;
  637.  
  638.   return GL_TRUE;
  639. }
  640.  
  641. /**********************************************************************/
  642.  
  643. void wrpSetupDriver(GLcontext * ctx)
  644. {
  645.   amigaMesaContext amesa;
  646.   struct TDdriver *TDdriver;
  647.   W3D_Context *TDcontext;
  648.  
  649.   DEBUGOUT(1, "wrpSetupDriver()\n");
  650.  
  651.   amesa = (amigaMesaContext) ctx->DriverCtx;
  652.   TDdriver = amesa->TDdriver;
  653.   TDcontext = TDdriver->td_ctx;
  654.  
  655.   /* texmapping setup */
  656.   /* TODO: support 3d textures */
  657.   W3D_WaitIdle(TDcontext);
  658.  
  659.   if (ctx->Texture.Enabled) {
  660.     W3D_SetState(TDcontext, W3D_TEXMAPPING, W3D_ENABLE);
  661.  
  662.     if (ctx->Hint.PerspectiveCorrection == GL_FASTEST)
  663.       W3D_SetState(TDcontext, W3D_PERSPECTIVE, W3D_DISABLE);
  664.     else {
  665.       if (!(TDdriver->flags & 0x20000000))
  666.     W3D_SetState(TDcontext, W3D_PERSPECTIVE, W3D_ENABLE);
  667.       else
  668.     W3D_SetState(TDcontext, W3D_PERSPECTIVE, W3D_DISABLE);
  669.     }
  670.   }
  671.   else
  672.     W3D_SetState(TDcontext, W3D_TEXMAPPING, W3D_DISABLE);
  673.  
  674.   /* gouraud / flat shading setup */
  675.   if (ctx->Light.ShadeModel == GL_SMOOTH)
  676.     W3D_SetState(TDcontext, W3D_GOURAUD, W3D_ENABLE);
  677.   else
  678.     W3D_SetState(TDcontext, W3D_GOURAUD, W3D_DISABLE);
  679.  
  680.   /* depth buffer setup */
  681.   if (ctx->Depth.Test) {
  682.     ULONG zmode = 0;
  683.  
  684.     if (!(TDdriver->flags & 0x80000000))
  685.       W3D_SetState(TDcontext, W3D_ZBUFFER, W3D_ENABLE);
  686.  
  687.     if (!(TDdriver->flags & 0x40000000)) {
  688.       if (ctx->Depth.Mask)
  689.     W3D_SetState(TDcontext, W3D_ZBUFFERUPDATE, W3D_ENABLE);
  690.       else
  691.     W3D_SetState(TDcontext, W3D_ZBUFFERUPDATE, W3D_DISABLE);
  692.     }
  693.  
  694.     switch (ctx->Depth.Func) {
  695.       case GL_NEVER:    zmode = W3D_Z_NEVER;    break;
  696.       case GL_LESS:    zmode = W3D_Z_LESS;    break;
  697.       case GL_GEQUAL:    zmode = W3D_Z_GEQUAL;    break;
  698.       case GL_LEQUAL:    zmode = W3D_Z_LEQUAL;    break;
  699.       case GL_GREATER:    zmode = W3D_Z_GREATER;    break;
  700.       case GL_NOTEQUAL:    zmode = W3D_Z_NOTEQUAL;    break;
  701.       case GL_EQUAL:    zmode = W3D_Z_EQUAL;    break;
  702.       case GL_ALWAYS:    zmode = W3D_Z_ALWAYS;    break;
  703.       default:                    break;
  704.     }
  705.  
  706.     W3D_SetZCompareMode(TDcontext, zmode);
  707.   }
  708.   else {
  709.     W3D_SetState(TDcontext, W3D_ZBUFFER, W3D_DISABLE);
  710.     W3D_SetState(TDcontext, W3D_ZBUFFERUPDATE, W3D_DISABLE);
  711.   }
  712.  
  713.   /* alpha test setup */
  714.   if (ctx->Color.AlphaEnabled) {
  715.     W3D_Float ref;
  716.     GLuint amode = 0;
  717.  
  718.     W3D_SetState(TDcontext, W3D_ALPHATEST, W3D_ENABLE);
  719.     ref = (((GLfloat) ctx->Color.AlphaRef) - 0.5) / 255.0;
  720.  
  721.     switch (ctx->Color.AlphaFunc) {
  722.       case GL_NEVER:    amode = W3D_A_NEVER;    break;
  723.       case GL_LESS:    amode = W3D_A_LESS;    break;
  724.       case GL_GEQUAL:    amode = W3D_A_GEQUAL;    break;
  725.       case GL_LEQUAL:    amode = W3D_A_LEQUAL;    break;
  726.       case GL_GREATER:    amode = W3D_A_GREATER;    break;
  727.       case GL_NOTEQUAL:    amode = W3D_A_NOTEQUAL;    break;
  728.       case GL_EQUAL:    amode = W3D_A_EQUAL;    break;
  729.       case GL_ALWAYS:    amode = W3D_A_ALWAYS;    break;
  730.       default:                    break;
  731.     }
  732.  
  733.     W3D_SetAlphaMode(TDcontext, amode, &ref);
  734.   }
  735.   else
  736.     W3D_SetState(TDcontext, W3D_ALPHATEST, W3D_DISABLE);
  737.  
  738.   /* blending check */
  739.   if (ctx->Color.BlendEnabled) {
  740.     GLuint srcfactor = 0, destfactor = 0;
  741.  
  742.     W3D_SetState(TDcontext, W3D_BLENDING, W3D_ENABLE);
  743.  
  744.     switch (ctx->Color.BlendSrcRGB) {
  745.       case GL_ZERO:            srcfactor = W3D_ZERO;                break;
  746.       case GL_ONE:            srcfactor = W3D_ONE;                break;
  747.       case GL_DST_COLOR:        srcfactor = W3D_DST_COLOR;            break;
  748.       case GL_ONE_MINUS_DST_COLOR:    srcfactor = W3D_ONE_MINUS_DST_COLOR;        break;
  749.       case GL_SRC_ALPHA:        srcfactor = W3D_SRC_ALPHA;            break;
  750.       case GL_ONE_MINUS_SRC_ALPHA:    srcfactor = W3D_ONE_MINUS_SRC_ALPHA;        break;
  751.       case GL_DST_ALPHA:        srcfactor = W3D_DST_ALPHA;            break;
  752.       case GL_ONE_MINUS_DST_ALPHA:    srcfactor = W3D_ONE_MINUS_DST_ALPHA;        break;
  753.       case GL_SRC_ALPHA_SATURATE:    srcfactor = W3D_SRC_ALPHA_SATURATE;        break;
  754.       case GL_CONSTANT_COLOR:        srcfactor = W3D_CONSTANT_COLOR;            break;
  755.       case GL_ONE_MINUS_CONSTANT_COLOR:    srcfactor = W3D_ONE_MINUS_CONSTANT_COLOR;    break;
  756.       case GL_CONSTANT_ALPHA:        srcfactor = W3D_CONSTANT_ALPHA;            break;
  757.       case GL_ONE_MINUS_CONSTANT_ALPHA:    srcfactor = W3D_ONE_MINUS_CONSTANT_ALPHA;    break;
  758.       default:                                        break;
  759.     }
  760.  
  761.     switch (ctx->Color.BlendDstRGB) {
  762.       case GL_ZERO:            destfactor = W3D_ZERO;                break;
  763.       case GL_ONE:            destfactor = W3D_ONE;                break;
  764.       case GL_SRC_COLOR:        destfactor = W3D_SRC_COLOR;            break;
  765.       case GL_ONE_MINUS_SRC_COLOR:    destfactor = W3D_ONE_MINUS_SRC_COLOR;        break;
  766.       case GL_SRC_ALPHA:        destfactor = W3D_SRC_ALPHA;            break;
  767.       case GL_ONE_MINUS_SRC_ALPHA:    destfactor = W3D_ONE_MINUS_SRC_ALPHA;        break;
  768.       case GL_DST_ALPHA:        destfactor = W3D_DST_ALPHA;            break;
  769.       case GL_ONE_MINUS_DST_ALPHA:    destfactor = W3D_ONE_MINUS_DST_ALPHA;        break;
  770.       case GL_CONSTANT_COLOR:        destfactor = W3D_CONSTANT_COLOR;        break;
  771.       case GL_ONE_MINUS_CONSTANT_COLOR:    destfactor = W3D_ONE_MINUS_CONSTANT_COLOR;    break;
  772.       case GL_CONSTANT_ALPHA:        destfactor = W3D_CONSTANT_ALPHA;        break;
  773.       case GL_ONE_MINUS_CONSTANT_ALPHA:    destfactor = W3D_ONE_MINUS_CONSTANT_ALPHA;    break;
  774.       default:                                        break;
  775.     }
  776.  
  777.     W3D_SetBlendMode(TDcontext, srcfactor, destfactor);
  778.   }
  779.   else
  780.     W3D_SetState(TDcontext, W3D_BLENDING, W3D_DISABLE);
  781.  
  782.   /* fogging check */
  783.   if (ctx->Fog.Enabled) {
  784.     W3D_SetState(TDcontext, W3D_FOGGING, W3D_ENABLE);
  785.  
  786.     wrpSetupFog(ctx);
  787.   }
  788.   else
  789.     W3D_SetState(TDcontext, W3D_FOGGING, W3D_DISABLE);
  790.  
  791.   /* antialiasing setup */
  792.   if (ctx->Point.SmoothFlag)
  793.     W3D_SetState(TDcontext, W3D_ANTI_POINT, W3D_ENABLE);
  794.   else
  795.     W3D_SetState(TDcontext, W3D_ANTI_POINT, W3D_DISABLE);
  796.  
  797.   if (ctx->Line.SmoothFlag)
  798.     W3D_SetState(TDcontext, W3D_ANTI_LINE, W3D_ENABLE);
  799.   else
  800.     W3D_SetState(TDcontext, W3D_ANTI_LINE, W3D_DISABLE);
  801.  
  802.   if (ctx->Polygon.SmoothFlag)
  803.     W3D_SetState(TDcontext, W3D_ANTI_POLYGON, W3D_ENABLE);
  804.   else
  805.     W3D_SetState(TDcontext, W3D_ANTI_POLYGON, W3D_DISABLE);
  806.  
  807.   /* dithering setup */
  808.   if (!(ctx->NoDither) && (ctx->Color.DitherFlag))
  809.     W3D_SetState(TDcontext, W3D_DITHERING, W3D_ENABLE);
  810.   else
  811.     W3D_SetState(TDcontext, W3D_DITHERING, W3D_DISABLE);
  812.  
  813.   /* scissor setup */
  814.   if (ctx->Scissor.Enabled) {
  815.     TDdriver->scissor.left = ctx->Scissor.X;
  816.     TDdriver->scissor.top = amesa->height - ctx->Scissor.Y - ctx->Scissor.Height;
  817.     TDdriver->scissor.width = ctx->Scissor.Width;
  818.     TDdriver->scissor.height = ctx->Scissor.Height;
  819.  
  820.     W3D_SetState(TDcontext, W3D_SCISSOR, W3D_ENABLE);
  821.     W3D_SetScissor(TDcontext, &TDdriver->scissor);
  822.   }
  823.   else {
  824.     TDdriver->scissor.left = 0;
  825.     TDdriver->scissor.top = 0;
  826.     TDdriver->scissor.width = amesa->width;
  827.     TDdriver->scissor.height = amesa->height;
  828.  
  829.     W3D_SetState(TDcontext, W3D_SCISSOR, W3D_DISABLE);
  830.     /* small workaround to fix W3DV2 Prototype problem */
  831.     W3D_SetScissor(TDcontext, &TDdriver->scissor);
  832.   }
  833.  
  834.   /* logic op setup */
  835.   if ((ctx->Color.IndexLogicOpEnabled) || (ctx->Color.ColorLogicOpEnabled)) {
  836.     GLuint operation = 0;
  837.  
  838.     W3D_SetState(TDcontext, W3D_LOGICOP, W3D_ENABLE);
  839.     switch (ctx->Color.LogicOp) {
  840.       case GL_CLEAR:        operation = W3D_LO_CLEAR;        break;
  841.       case GL_SET:        operation = W3D_LO_SET;            break;
  842.       case GL_COPY:        operation = W3D_LO_COPY;        break;
  843.       case GL_COPY_INVERTED:    operation = W3D_LO_COPY_INVERTED;    break;
  844.       case GL_NOOP:        operation = W3D_LO_NOOP;        break;
  845.       case GL_INVERT:        operation = W3D_LO_INVERT;        break;
  846.       case GL_AND:        operation = W3D_LO_AND;            break;
  847.       case GL_NAND:        operation = W3D_LO_NAND;        break;
  848.       case GL_OR:        operation = W3D_LO_OR;            break;
  849.       case GL_NOR:        operation = W3D_LO_NOR;            break;
  850.       case GL_XOR:        operation = W3D_LO_XOR;            break;
  851.       case GL_EQUIV:        operation = W3D_LO_EQUIV;        break;
  852.       case GL_AND_REVERSE:    operation = W3D_LO_AND_REVERSE;        break;
  853.       case GL_AND_INVERTED:    operation = W3D_LO_AND_INVERTED;    break;
  854.       case GL_OR_REVERSE:    operation = W3D_LO_OR_REVERSE;        break;
  855.       case GL_OR_INVERTED:    operation = W3D_LO_OR_INVERTED;        break;
  856.       default:                                break;
  857.     }
  858.  
  859.     W3D_SetLogicOp(TDcontext, operation);
  860.   }
  861.   else
  862.     W3D_SetState(TDcontext, W3D_LOGICOP, W3D_DISABLE);
  863.  
  864.   /* masking setup */
  865.   if (ctx->Visual->RGBAflag) {
  866.     W3D_Bool r, g, b, a;
  867.  
  868.     r = (ctx->Color.ColorMask[RCOMP] == 0xff);
  869.     g = (ctx->Color.ColorMask[GCOMP] == 0xff);
  870.     b = (ctx->Color.ColorMask[BCOMP] == 0xff);
  871.     a = (ctx->Color.ColorMask[ACOMP] == 0xff);
  872.  
  873.     W3D_SetColorMask(TDcontext, r, g, b, a);
  874.   }
  875.   else
  876.     W3D_SetPenMask(TDcontext, (ULONG) ctx->Color.IndexMask);
  877.  
  878.   /* stencil setup */
  879.   if (ctx->Stencil.Enabled) {
  880.     ULONG stfunc = 0, stwmask, stref, stmask;
  881.     ULONG stop_fail = 0, stop_zfail = 0, stop_zpass = 0;
  882.     
  883.     W3D_SetState(TDcontext, W3D_STENCILBUFFER, W3D_ENABLE);
  884.     stref = ctx->Stencil.Ref;
  885.     stmask = ctx->Stencil.ValueMask;
  886.     stwmask = ctx->Stencil.WriteMask;
  887.  
  888.     switch (ctx->Stencil.Function) {
  889.       case GL_NEVER:    stfunc = W3D_ST_NEVER;        break;
  890.       case GL_LESS:    stfunc = W3D_ST_LESS;        break;
  891.       case GL_LEQUAL:    stfunc = W3D_ST_LEQUAL;        break;
  892.       case GL_GREATER:    stfunc = W3D_ST_GREATER;    break;
  893.       case GL_GEQUAL:    stfunc = W3D_ST_GEQUAL;        break;
  894.       case GL_EQUAL:    stfunc = W3D_ST_EQUAL;        break;
  895.       case GL_NOTEQUAL:    stfunc = W3D_ST_NOTEQUAL;    break;
  896.       case GL_ALWAYS:    stfunc = W3D_ST_ALWAYS;        break;
  897.       default:                        break;
  898.     }
  899.  
  900.     switch (ctx->Stencil.FailFunc) {
  901.       case GL_KEEP:    stop_fail = W3D_ST_KEEP;    break;
  902.       case GL_ZERO:    stop_fail = W3D_ST_ZERO;    break;
  903.       case GL_REPLACE:    stop_fail = W3D_ST_REPLACE;    break;
  904.       case GL_INCR:    stop_fail = W3D_ST_INCR;    break;
  905.       case GL_DECR:    stop_fail = W3D_ST_DECR;    break;
  906.       case GL_INVERT:    stop_fail = W3D_ST_INVERT;    break;
  907.       default:                        break;
  908.     }
  909.  
  910.     switch (ctx->Stencil.ZFailFunc) {
  911.       case GL_KEEP:    stop_zfail = W3D_ST_KEEP;    break;
  912.       case GL_ZERO:    stop_zfail = W3D_ST_ZERO;    break;
  913.       case GL_REPLACE:    stop_zfail = W3D_ST_REPLACE;    break;
  914.       case GL_INCR:    stop_zfail = W3D_ST_INCR;    break;
  915.       case GL_DECR:    stop_zfail = W3D_ST_DECR;    break;
  916.       case GL_INVERT:    stop_zfail = W3D_ST_INVERT;    break;
  917.       default:                        break;
  918.     }
  919.  
  920.     switch (ctx->Stencil.ZPassFunc) {
  921.       case GL_KEEP:    stop_zpass = W3D_ST_KEEP;    break;
  922.       case GL_ZERO:    stop_zpass = W3D_ST_ZERO;    break;
  923.       case GL_REPLACE:    stop_zpass = W3D_ST_REPLACE;    break;
  924.       case GL_INCR:    stop_zpass = W3D_ST_INCR;    break;
  925.       case GL_DECR:    stop_zpass = W3D_ST_DECR;    break;
  926.       case GL_INVERT:    stop_zpass = W3D_ST_INVERT;    break;
  927.       default:                        break;
  928.     }
  929.  
  930.     W3D_SetStencilFunc(TDcontext,stfunc,stref,stmask);
  931.     W3D_SetStencilOp(TDcontext,stop_fail,stop_zfail,stop_zpass);
  932.     W3D_SetWriteMask(TDcontext,stwmask);
  933.   }
  934.   else
  935.     W3D_SetState(TDcontext,W3D_STENCILBUFFER,W3D_DISABLE);
  936.  
  937.   /* TODO: support specular highlighting as soon as supported by W3D */
  938. }
  939.  
  940. /*
  941.  * Initialize all the pointers in the DD struct.  Do this whenever   
  942.  * a new TDcontext is made current or we change buffers via setBuffer! 
  943.  */
  944. void wrpStandardDDPointers(GLcontext * ctx)
  945. {
  946.   amigaMesaContext amesa;
  947.   struct TDdriver *TDdriver;
  948.   W3D_Context *TDcontext;
  949.   palMode trueColor;
  950.   GLboolean ctxSupport = GL_TRUE;
  951.  
  952.   DEBUGOUT(1, "wrpStandardDDPointers()\n");
  953.  
  954.   amesa = (amigaMesaContext) ctx->DriverCtx;
  955.   TDdriver = amesa->TDdriver;
  956.   TDcontext = TDdriver->td_ctx;
  957.   trueColor = amesa->trueColor;
  958.  
  959.   ctx->Driver.RendererString = wrpRendererString;
  960.  
  961.   ctx->Driver.UpdateState = wrpStandardDDPointers;
  962.   ctx->Driver.ClearIndex = cybClearIndex;
  963.   ctx->Driver.ClearColor = cybClearColor;
  964.   ctx->Driver.Clear = wrpClear;
  965.  
  966.   ctx->Driver.Index = wrpSetIndex;
  967.   ctx->Driver.Color = wrpSetColor;
  968.  
  969.   ctx->Driver.IndexMask = cybIndexMask;
  970.   ctx->Driver.ColorMask = cybColorMask;
  971.   ctx->Driver.LogicOp = wrpLogicOp;
  972.  
  973.   ctx->Driver.SetBuffer = cmnSetBuffer;
  974.   ctx->Driver.GetBufferSize = cmnStandardResize;
  975.  
  976.   ctx->Driver.RenderStart = cmnRenderStart;
  977.   ctx->Driver.RenderFinish = cmnRenderFinish;
  978.   ctx->Driver.Dither = NULL;
  979.   ctx->Driver.Flush = cmnFlush;
  980.  
  981.   if ((ctxSupport = wrpContextSupported(ctx))) {
  982.     ctx->Driver.PointsFunc = wrpChoosePointsFunction(ctx);
  983.     ctx->Driver.LineFunc = wrpChooseLineFunction(ctx);
  984.     ctx->Driver.TriangleFunc = wrpChooseTriangleFunction(ctx);
  985.     ctx->Driver.QuadFunc = wrpChooseQuadFunction(ctx);
  986. /*  ctx->Driver.RectFunc = wrpChooseRectFunction(ctx); */
  987.     ctx->Driver.RasterSetup = wrpChooseRasterSetupFunction(ctx);
  988.  
  989.     TDdriver->LineStripFunc = wrpChooseLineStripFunction(ctx);
  990.     TDdriver->TriStripFunc = wrpChooseTriStripFunction(ctx);
  991.     TDdriver->TriFanFunc = wrpChooseTriFanFunction(ctx);
  992.   }
  993.  
  994.   /* Pixel/span writing functions: */
  995.   ctx->Driver.WriteRGBASpan = cybWriteRGBASpan;
  996.   ctx->Driver.WriteRGBSpan = cybWriteRGBSpan;
  997.   ctx->Driver.WriteCI32Span = cybWriteCI32Span;
  998.   ctx->Driver.WriteCI8Span = cybWriteCI8Span;
  999.   ctx->Driver.WriteMonoRGBASpan = cybWriteMonoCISpan;
  1000.   ctx->Driver.WriteMonoCISpan = cybWriteMonoCISpan;
  1001.  
  1002.   ctx->Driver.WriteRGBAPixels = cybWriteRGBAPixel;
  1003.   ctx->Driver.WriteCI32Pixels = cybWriteCI32Pixel;
  1004.   ctx->Driver.WriteMonoRGBAPixels = cybWriteMonoCIPixel;
  1005.   ctx->Driver.WriteMonoCIPixels = cybWriteMonoCIPixel;
  1006.  
  1007.   /* Pixel/span reading functions: */
  1008.   ctx->Driver.ReadRGBASpan = cybReadRGBASpan;
  1009.   ctx->Driver.ReadCI32Span = IS_SHIFT(trueColor) ? cyb8ReadCI32Span :
  1010.                  IS_MATCH(trueColor) ? cybGReadCI32Span :
  1011.                            cybDReadCI32Span;
  1012.  
  1013.   ctx->Driver.ReadRGBAPixels = cybReadRGBAPixel;
  1014.   ctx->Driver.ReadCI32Pixels = IS_SHIFT(trueColor) ? cyb8ReadCI32Pixel :
  1015.                    IS_MATCH(trueColor) ? cybGReadCI32Pixel :
  1016.                              cybDReadCI32Pixel;
  1017.  
  1018.   /* internal Warp3D-support */
  1019. /*ctx->Driver.GetParameteri = wrpGetParameteri; */
  1020.   ctx->Driver.NearFar = wrpNearFar;
  1021.   ctx->Driver.TexEnv = wrpTexEnv;
  1022.   ctx->Driver.TexImage = wrpTexImage;
  1023.   ctx->Driver.TexSubImage = wrpTexSubImage;
  1024.   ctx->Driver.TexParameter = wrpTexParameter;
  1025.   ctx->Driver.BindTexture = wrpBindTexture;
  1026.   ctx->Driver.DeleteTexture = wrpDeleteTexture;
  1027.  
  1028.   W3D_Hint(TDcontext, W3D_H_TEXMAPPING,        W3D_H_NICE);
  1029.   W3D_Hint(TDcontext, W3D_H_MIPMAPPING,        W3D_H_NICE);
  1030.   W3D_Hint(TDcontext, W3D_H_BILINEARFILTER,    W3D_H_NICE);
  1031.   W3D_Hint(TDcontext, W3D_H_MMFILTER,        W3D_H_NICE);
  1032.   W3D_Hint(TDcontext, W3D_H_PERSPECTIVE,    W3D_H_NICE);
  1033.  
  1034.   if (ctx->Visual->DepthBits) {
  1035.     if (W3D_AllocZBuffer(TDcontext) != W3D_SUCCESS)
  1036.       /* TODO: CyberGfx-FallBack */;
  1037.     else
  1038.       SetF(TDdriver->flags, TD_ZBUFFER);
  1039.   }
  1040.  
  1041.   if (ctxSupport) {
  1042.     if (ctx->NewState & (~NEW_LIGHTING))
  1043.       wrpSetupDriver(ctx);
  1044.     TDdriver->height = (W3D_Float) amesa->height;
  1045.   }
  1046.  
  1047.   if (ctx->Buffer && !ctx->Buffer->Depth) {
  1048.     gl_alloc_depth_buffer(ctx);
  1049.     gl_clear_depth_buffer(ctx);
  1050.   }
  1051.  
  1052.   W3D_Flush(TDdriver->td_ctx);
  1053. }
  1054.  
  1055. #undef DEBUGPRINT
  1056. #endif
  1057.