home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-3_1.lha / src / AOS / wrpDisplay / wrpFastLines.c < prev    next >
Encoding:
Text File  |  1999-09-23  |  10.0 KB  |  337 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. /*****            Accelerated point, line, polygon rendering      *****/
  27. /**********************************************************************/
  28.  
  29. void wrpDrawLineFlat(GLcontext * ctx, GLuint v1, GLuint v2, GLuint pv)
  30. {
  31.   struct TDdriver *TDdriver;
  32.   struct vertex_buffer *VB;
  33.   W3D_Context *TDcontext;
  34.   W3D_Line line;
  35.   W3D_Color TDcol;
  36.  
  37.   DEBUGOUT(1, "wrpDrawLineFlat()\n");
  38.  
  39.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  40.   TDcontext = TDdriver->td_ctx;
  41.   VB = ctx->VB;
  42.  
  43.   LockHardware(TDdriver, TDcontext);
  44.  
  45.   TC_Color(TDcol, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], VB->ColorPtr->data[pv][3]);
  46.   W3D_SetCurrentColor(TDcontext, &TDcol);
  47.  
  48.   if (v2 - 1 == v1) {
  49.     /* optimization, very ugly style */
  50.     W3D_Line *lineptr = (W3D_Line *) (&TDdriver->vbuffer[v1]);
  51.     W3D_Texture *texsave = lineptr->tex;
  52.     W3D_Float widthsave = lineptr->linewidth;
  53.     W3D_Bool patternenable = lineptr->st_enable;
  54.     unsigned short patternsave = lineptr->st_pattern;
  55.     int factorsave = lineptr->st_factor;
  56.  
  57.     lineptr->tex = TDdriver->TDtex;
  58.  
  59.     if (!ctx->Line.StippleFlag) {
  60.       lineptr->st_enable = TRUE;
  61.       lineptr->st_pattern = (unsigned short)(ctx->Line.StipplePattern);
  62.       lineptr->st_factor = (int)(ctx->Line.StippleFactor);
  63.     }
  64.     else
  65.       lineptr->st_enable = FALSE;
  66.  
  67.     lineptr->linewidth = (W3D_Float) ctx->Line.Width;
  68.  
  69.     if (W3D_DrawLine(TDcontext, lineptr) != W3D_SUCCESS)
  70.       ClrF(TDdriver->flags, TD_ACTIVE);
  71.     SetF(TDdriver->flags, TD_DIRTY);
  72.  
  73.     lineptr->tex = texsave;
  74.     lineptr->linewidth = widthsave;
  75.     lineptr->st_enable = patternenable;
  76.     lineptr->st_pattern = patternsave;
  77.     lineptr->st_factor = factorsave;
  78.   }
  79.   else {
  80.     line.tex = TDdriver->TDtex;
  81.  
  82.     if (!ctx->Line.StippleFlag) {
  83.       line.st_enable = TRUE;
  84.       line.st_pattern = (unsigned short)(ctx->Line.StipplePattern);
  85.       line.st_factor = (int)(ctx->Line.StippleFactor);
  86.     }
  87.     else
  88.       line.st_enable = FALSE;
  89.  
  90.     line.linewidth = (W3D_Float) ctx->Line.Width;
  91.  
  92.     TDdriver->CopyVertex(&line.v1, &TDdriver->vbuffer[v1]);
  93.     TDdriver->CopyVertex(&line.v2, &TDdriver->vbuffer[v2]);
  94.  
  95.     if (W3D_DrawLine(TDcontext, &line) != W3D_SUCCESS)
  96.       ClrF(TDdriver->flags, TD_ACTIVE);
  97.     SetF(TDdriver->flags, TD_DIRTY);
  98.   }
  99. }
  100.  
  101. void wrpDrawLineSmooth(GLcontext * ctx, GLuint v1, GLuint v2, GLuint pv)
  102. {
  103.   struct TDdriver *TDdriver;
  104.   struct vertex_buffer *VB;
  105.   W3D_Context *TDcontext;
  106.   W3D_Line line;
  107.  
  108.   DEBUGOUT(1, "wrpDrawLineSmooth()\n");
  109.  
  110.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  111.   TDcontext = TDdriver->td_ctx;
  112.   VB = ctx->VB;
  113.  
  114.   LockHardware(TDdriver, TDcontext);
  115.  
  116.   if (v2 - 1 == v1) {
  117.     /* optimization, very ugly style */
  118.     W3D_Line *lineptr = (W3D_Line *) (&TDdriver->vbuffer[v1]);
  119.     W3D_Texture *texsave = lineptr->tex;
  120.     W3D_Float widthsave = lineptr->linewidth;
  121.     W3D_Bool patternenable = lineptr->st_enable;
  122.     unsigned short patternsave = lineptr->st_pattern;
  123.     int factorsave = lineptr->st_factor;
  124.  
  125.     lineptr->tex = TDdriver->TDtex;
  126.  
  127.     if (!ctx->Line.StippleFlag) {
  128.       lineptr->st_enable = TRUE;
  129.       lineptr->st_pattern = (unsigned short)(ctx->Line.StipplePattern);
  130.       lineptr->st_factor = (int)(ctx->Line.StippleFactor);
  131.     }
  132.     else
  133.       lineptr->st_enable = FALSE;
  134.  
  135.     lineptr->linewidth = (W3D_Float) ctx->Line.Width;
  136.  
  137.     if (W3D_DrawLine(TDcontext, lineptr) != W3D_SUCCESS)
  138.       ClrF(TDdriver->flags, TD_ACTIVE);
  139.     SetF(TDdriver->flags, TD_DIRTY);
  140.  
  141.     lineptr->tex = texsave;
  142.     lineptr->linewidth = widthsave;
  143.     lineptr->st_enable = patternenable;
  144.     lineptr->st_pattern = patternsave;
  145.     lineptr->st_factor = factorsave;
  146.   }
  147.   else {
  148.     line.tex = TDdriver->TDtex;
  149.  
  150.     if (!ctx->Line.StippleFlag) {
  151.       line.st_enable = TRUE;
  152.       line.st_pattern = (unsigned short)(ctx->Line.StipplePattern);
  153.       line.st_factor = (int)(ctx->Line.StippleFactor);
  154.     }
  155.     else
  156.       line.st_enable = FALSE;
  157.  
  158.     line.linewidth = (W3D_Float) ctx->Line.Width;
  159.     TDdriver->CopyVertex(&line.v1, &TDdriver->vbuffer[v1]);
  160.     TDdriver->CopyVertex(&line.v2, &TDdriver->vbuffer[v2]);
  161.  
  162.     if (W3D_DrawLine(TDcontext, &line) != W3D_SUCCESS)
  163.       ClrF(TDdriver->flags, TD_ACTIVE);
  164.     SetF(TDdriver->flags, TD_DIRTY);
  165.   }
  166. }
  167.  
  168. void wrpDrawLineSmoothTwo(GLcontext * ctx, GLuint v1, GLuint v2, GLuint pv)
  169. {
  170.   struct TDdriver *TDdriver;
  171.   struct vertex_buffer *VB;
  172.   W3D_Context *TDcontext;
  173.   W3D_Line line;
  174.  
  175.   DEBUGOUT(1, "wrpDrawLineSmoothTwo()\n");
  176.  
  177.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  178.   TDcontext = TDdriver->td_ctx;
  179.   VB = ctx->VB;
  180.  
  181.   LockHardware(TDdriver, TDcontext);
  182.  
  183.   line.tex = TDdriver->TDtex;
  184.  
  185.   if (!ctx->Line.StippleFlag) {
  186.     line.st_enable = TRUE;
  187.     line.st_pattern = (unsigned short)(ctx->Line.StipplePattern);
  188.     line.st_factor = (int)(ctx->Line.StippleFactor);
  189.   }
  190.   else
  191.     line.st_enable = FALSE;
  192.  
  193.   line.linewidth = (W3D_Float) ctx->Line.Width;
  194.   TDdriver->CopyVertex(&line.v1, &TDdriver->vbuffer[v1]);
  195.   TDdriver->CopyVertex(&line.v2, &TDdriver->vbuffer[v2]);
  196.  
  197.   TC_Color(line.v1.color, VB->ColorPtr->data[v1][0], VB->ColorPtr->data[v1][1], VB->ColorPtr->data[v1][2], VB->ColorPtr->data[v1][3]);
  198.   TC_Color(line.v2.color, VB->ColorPtr->data[v2][0], VB->ColorPtr->data[v2][1], VB->ColorPtr->data[v2][2], VB->ColorPtr->data[v2][3]);
  199.  
  200.   if (W3D_DrawLine(TDcontext, &line) != W3D_SUCCESS)
  201.     ClrF(TDdriver->flags, TD_ACTIVE);
  202.   SetF(TDdriver->flags, TD_DIRTY);
  203. }
  204.  
  205. line_func wrpChooseLineFunction(GLcontext * ctx)
  206. {
  207.   struct TDdriver *TDdriver;
  208.   W3D_Context *TDcontext;
  209.  
  210.   DEBUGOUT(1, "wrpChooseLineFunction()\n");
  211.  
  212.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  213.   TDcontext = TDdriver->td_ctx;
  214.  
  215.   if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE, NULL) != W3D_FULLY_SUPPORTED)
  216.     return NULL;
  217.  
  218.   if (ctx->Line.SmoothFlag) {
  219.     if (W3D_Query(TDcontext, W3D_Q_ANTI_LINE, NULL) != W3D_FULLY_SUPPORTED)
  220.       return NULL;
  221.   }
  222.  
  223.   if ((ctx->Color.AlphaEnabled) || (ctx->Color.BlendEnabled) ||
  224.       (ctx->Fog.Enabled) || (ctx->Color.IndexLogicOpEnabled) ||
  225.       (ctx->Color.ColorLogicOpEnabled)) {
  226.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_FX, NULL) != W3D_FULLY_SUPPORTED)
  227.       return NULL;
  228.   }
  229.  
  230.   if (ctx->Texture.Enabled)
  231.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_TEX, NULL) != W3D_FULLY_SUPPORTED)
  232.       return NULL;
  233.  
  234.   if (ctx->Line.Width != 1.0f)
  235.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_X, NULL) != W3D_FULLY_SUPPORTED)
  236.       return NULL;
  237.  
  238.   if (ctx->Line.StippleFlag)
  239.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_ST, NULL) != W3D_FULLY_SUPPORTED)
  240.       return NULL;
  241.  
  242.   if (ctx->Light.ShadeModel == GL_SMOOTH) {
  243.     if (ctx->Light.Model.TwoSide)
  244.       return wrpDrawLineSmoothTwo;
  245.  
  246.     return wrpDrawLineSmooth;
  247.   }
  248.  
  249.   return wrpDrawLineFlat;
  250. }
  251.  
  252. /**********************************************************************/
  253. /*****            Accelerated point, line, polygon rendering      *****/
  254. /**********************************************************************/
  255.  
  256. /* draw line strips
  257.  * this is never called, when two-sided lighting is enabled
  258.  * this is not called when flat shading is enabled, except
  259.  * when texture mapping is enabled and the env variable NOFLAT
  260.  * is set (which results in wrong behaviour, if the constant
  261.  * color is not always white and GL_DECAL/GL_MODULATE are used)
  262.  */
  263.  
  264. void wrpDrawLineStrip(GLcontext * ctx, GLuint first, GLuint last)
  265. {
  266.   struct TDdriver *TDdriver;
  267.   W3D_Context *TDcontext;
  268.   W3D_Lines line;
  269.  
  270.   DEBUGOUT(1, "wrpDrawLineStrip()\n");
  271.  
  272.   if (last - first < 1)
  273.     return;
  274.  
  275.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  276.   TDcontext = TDdriver->td_ctx;
  277.  
  278.   LockHardware(TDdriver, TDcontext);
  279.  
  280.   line.vertexcount = last - first + 1;
  281.   line.v = (&TDdriver->vbuffer[first]);
  282.   line.tex = TDdriver->TDtex;
  283.  
  284.   if (!ctx->Line.StippleFlag) {
  285.     line.st_enable = TRUE;
  286.     line.st_pattern = (unsigned short)(ctx->Line.StipplePattern);
  287.     line.st_factor = (int)(ctx->Line.StippleFactor);
  288.   }
  289.   else
  290.     line.st_enable = FALSE;
  291.  
  292.   if (W3D_DrawLineStrip(TDcontext, &line) != W3D_SUCCESS)
  293.     ClrF(TDdriver->flags, TD_ACTIVE);
  294.   SetF(TDdriver->flags, TD_DIRTY);
  295. }
  296.  
  297. linestrip_func wrpChooseLineStripFunction(GLcontext * ctx)
  298. {
  299.   struct TDdriver *TDdriver;
  300.   W3D_Context *TDcontext;
  301.  
  302.   DEBUGOUT(1, "wrpChooseLineStripFunction()\n");
  303.  
  304.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  305.   TDcontext = TDdriver->td_ctx;
  306.  
  307.   if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE, NULL) != W3D_FULLY_SUPPORTED)
  308.     return NULL;
  309.  
  310.   if (ctx->Line.SmoothFlag)
  311.     if (W3D_Query(TDcontext, W3D_Q_ANTI_LINE, NULL) != W3D_FULLY_SUPPORTED)
  312.       return NULL;
  313.  
  314.   if ((ctx->Color.AlphaEnabled) || (ctx->Color.BlendEnabled) ||
  315.       (ctx->Fog.Enabled) || (ctx->Color.IndexLogicOpEnabled) ||
  316.       (ctx->Color.ColorLogicOpEnabled))
  317.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_FX, NULL) != W3D_FULLY_SUPPORTED)
  318.       return NULL;
  319.  
  320.   if (ctx->Texture.Enabled)
  321.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_TEX, NULL) != W3D_FULLY_SUPPORTED)
  322.       return NULL;
  323.  
  324.   if (ctx->Line.Width != 1.0f)
  325.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_X, NULL) != W3D_FULLY_SUPPORTED)
  326.       return NULL;
  327.  
  328.   if (ctx->Line.StippleFlag)
  329.     if (W3D_Query(TDcontext, W3D_Q_DRAW_LINE_ST, NULL) != W3D_FULLY_SUPPORTED)
  330.       return NULL;
  331.  
  332.   if (ctx->Light.Model.TwoSide)
  333.     return NULL;
  334.  
  335.   return wrpDrawLineStrip;
  336. }
  337.