home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / texstate.c < prev    next >
C/C++ Source or Header  |  2000-01-07  |  35KB  |  1,181 lines

  1. /* $Id: texstate.c,v 1.4.2.3 1999/12/21 17:22:39 keithw Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  8.  * 
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  * 
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  * 
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  */
  26.  
  27.  
  28.  
  29. #ifdef PC_HEADER
  30. #include "all.h"
  31. #else
  32. #ifndef XFree86Server
  33. #include <assert.h>
  34. #include <stdio.h>
  35. #else
  36. #include "GL/xf86glx.h"
  37. #endif
  38. #include "context.h"
  39. #include "enums.h"
  40. #include "extensions.h"
  41. #include "macros.h"
  42. #include "matrix.h"
  43. #include "texobj.h"
  44. #include "texstate.h"
  45. #include "texture.h"
  46. #include "types.h"
  47. #include "xform.h"
  48. #endif
  49.  
  50.  
  51.  
  52. #ifdef SPECIALCAST
  53. /* Needed for an Amiga compiler */
  54. #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
  55. #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
  56. #else
  57. /* all other compilers */
  58. #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
  59. #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
  60. #endif
  61.  
  62.  
  63.  
  64.  
  65. /**********************************************************************/
  66. /*                       Texture Environment                          */
  67. /**********************************************************************/
  68.  
  69.  
  70. void gl_TexEnvfv( GLcontext *ctx,
  71.                   GLenum target, GLenum pname, const GLfloat *param )
  72. {
  73.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  74.  
  75.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv");
  76.  
  77.    if (target!=GL_TEXTURE_ENV) {
  78.       gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
  79.       return;
  80.    }
  81.  
  82.    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
  83.       fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",  
  84.           gl_lookup_enum_by_nr(target),
  85.           gl_lookup_enum_by_nr(pname),
  86.           *param,
  87.           gl_lookup_enum_by_nr((GLenum) (GLint) *param));
  88.  
  89.  
  90.    if (pname==GL_TEXTURE_ENV_MODE) {
  91.       GLenum mode = (GLenum) (GLint) *param;
  92.       switch (mode) {
  93.          case GL_ADD:
  94.         if (!ctx->Texture.ExtAddEnv) {
  95.            if (gl_extension_is_enabled(ctx, "GL_EXT_texture_env_add")) 
  96.           ctx->Texture.ExtAddEnv = 1;
  97.            else {
  98.           gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
  99.           return;
  100.            }
  101.         }
  102.         /* FALLTHROUGH */
  103.      case GL_MODULATE:
  104.      case GL_BLEND:
  105.      case GL_DECAL:
  106.      case GL_REPLACE:
  107.         if (texUnit->EnvMode == mode)
  108.                return;  /* no change */
  109.  
  110.         if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_TEXTURE))
  111.            fprintf(stderr, "glTexEnv: old mode %s, new mode %s\n",
  112.                gl_lookup_enum_by_nr(texUnit->EnvMode),
  113.                gl_lookup_enum_by_nr(mode));
  114.  
  115.         texUnit->EnvMode = mode;
  116.         ctx->NewState |= NEW_TEXTURE_ENV;
  117.         break;
  118.      default:
  119.         gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
  120.         return;
  121.       }
  122.    }
  123.    else if (pname==GL_TEXTURE_ENV_COLOR) {
  124.       texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
  125.       texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
  126.       texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
  127.       texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
  128.    }
  129.    else {
  130.       gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
  131.       return;
  132.    }
  133.  
  134.    /* Tell device driver about the new texture environment */
  135.    if (ctx->Driver.TexEnv) {
  136.       (*ctx->Driver.TexEnv)( ctx, pname, param );
  137.    }
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144. void gl_GetTexEnvfv( GLcontext *ctx,
  145.                      GLenum target, GLenum pname, GLfloat *params )
  146. {
  147.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  148.    if (target!=GL_TEXTURE_ENV) {
  149.       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
  150.       return;
  151.    }
  152.    switch (pname) {
  153.       case GL_TEXTURE_ENV_MODE:
  154.          *params = ENUM_TO_FLOAT(texUnit->EnvMode);
  155.      break;
  156.       case GL_TEXTURE_ENV_COLOR:
  157.      COPY_4FV( params, texUnit->EnvColor );
  158.      break;
  159.       default:
  160.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
  161.    }
  162. }
  163.  
  164.  
  165. void gl_GetTexEnviv( GLcontext *ctx,
  166.                      GLenum target, GLenum pname, GLint *params )
  167. {
  168.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  169.    if (target!=GL_TEXTURE_ENV) {
  170.       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
  171.       return;
  172.    }
  173.    switch (pname) {
  174.       case GL_TEXTURE_ENV_MODE:
  175.          *params = (GLint) texUnit->EnvMode;
  176.      break;
  177.       case GL_TEXTURE_ENV_COLOR:
  178.      params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
  179.      params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
  180.      params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
  181.      params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
  182.      break;
  183.       default:
  184.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
  185.    }
  186. }
  187.  
  188.  
  189.  
  190.  
  191. /**********************************************************************/
  192. /*                       Texture Parameters                           */
  193. /**********************************************************************/
  194.  
  195.  
  196. void gl_TexParameterfv( GLcontext *ctx,
  197.                         GLenum target, GLenum pname, const GLfloat *params )
  198. {
  199.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  200.    GLenum eparam = (GLenum) (GLint) params[0];
  201.    struct gl_texture_object *texObj;
  202.  
  203.    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
  204.       fprintf(stderr, "texPARAM %s %s %d...\n", 
  205.           gl_lookup_enum_by_nr(target),
  206.           gl_lookup_enum_by_nr(pname),
  207.           eparam);
  208.  
  209.  
  210.    switch (target) {
  211.       case GL_TEXTURE_1D:
  212.          texObj = texUnit->CurrentD[1];
  213.          break;
  214.       case GL_TEXTURE_2D:
  215.          texObj = texUnit->CurrentD[2];
  216.          break;
  217.       case GL_TEXTURE_3D_EXT:
  218.          texObj = texUnit->CurrentD[3];
  219.          break;
  220.       default:
  221.          gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
  222.          return;
  223.    }
  224.  
  225.    switch (pname) {
  226.       case GL_TEXTURE_MIN_FILTER:
  227.          /* A small optimization */
  228.          if (texObj->MinFilter == eparam)
  229.             return;
  230.  
  231.          if (eparam==GL_NEAREST || eparam==GL_LINEAR
  232.              || eparam==GL_NEAREST_MIPMAP_NEAREST
  233.              || eparam==GL_LINEAR_MIPMAP_NEAREST
  234.              || eparam==GL_NEAREST_MIPMAP_LINEAR
  235.              || eparam==GL_LINEAR_MIPMAP_LINEAR) {
  236.             texObj->MinFilter = eparam;
  237.             ctx->NewState |= NEW_TEXTURING;
  238.          }
  239.          else {
  240.             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  241.             return;
  242.          }
  243.          break;
  244.       case GL_TEXTURE_MAG_FILTER:
  245.          /* A small optimization */
  246.          if (texObj->MagFilter == eparam)
  247.             return;
  248.  
  249.          if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
  250.             texObj->MagFilter = eparam;
  251.             ctx->NewState |= NEW_TEXTURING;
  252.          }
  253.          else {
  254.             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  255.             return;
  256.          }
  257.          break;
  258.       case GL_TEXTURE_WRAP_S:
  259.          if (texObj->WrapS == eparam)
  260.             return;
  261.  
  262.          if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
  263.             texObj->WrapS = eparam;
  264.             ctx->NewState |= NEW_TEXTURING;
  265.          }
  266.          else {
  267.             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  268.             return;
  269.          }
  270.          break;
  271.       case GL_TEXTURE_WRAP_T:
  272.          if (texObj->WrapT == eparam)
  273.             return;
  274.  
  275.          if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
  276.             texObj->WrapT = eparam;
  277.             ctx->NewState |= NEW_TEXTURING;
  278.          }
  279.          else {
  280.             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  281.             return;
  282.          }
  283.          break;
  284.       case GL_TEXTURE_WRAP_R_EXT:
  285.          if (texObj->WrapR == eparam)
  286.             return;
  287.  
  288.          if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
  289.             texObj->WrapR = eparam;
  290.             ctx->NewState |= NEW_TEXTURING;
  291.          }
  292.          else {
  293.             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  294.          }
  295.          break;
  296.       case GL_TEXTURE_BORDER_COLOR:
  297.          texObj->BorderColor[0] = (GLubyte) CLAMP((GLint)(params[0]*255.0), 0, 255);
  298.          texObj->BorderColor[1] = (GLubyte) CLAMP((GLint)(params[1]*255.0), 0, 255);
  299.          texObj->BorderColor[2] = (GLubyte) CLAMP((GLint)(params[2]*255.0), 0, 255);
  300.          texObj->BorderColor[3] = (GLubyte) CLAMP((GLint)(params[3]*255.0), 0, 255);
  301.          break;
  302.       case GL_TEXTURE_MIN_LOD:
  303.          texObj->MinLod = params[0];
  304.          ctx->NewState |= NEW_TEXTURING;
  305.          break;
  306.       case GL_TEXTURE_MAX_LOD:
  307.          texObj->MaxLod = params[0];
  308.          ctx->NewState |= NEW_TEXTURING;
  309.          break;
  310.       case GL_TEXTURE_BASE_LEVEL:
  311.          if (params[0] < 0.0) {
  312.             gl_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  313.             return;
  314.          }
  315.          texObj->BaseLevel = (GLint) params[0];
  316.          ctx->NewState |= NEW_TEXTURING;
  317.          break;
  318.       case GL_TEXTURE_MAX_LEVEL:
  319.          if (params[0] < 0.0) {
  320.             gl_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  321.             return;
  322.          }
  323.          texObj->MaxLevel = (GLint) params[0];
  324.          ctx->NewState |= NEW_TEXTURING;
  325.          break;
  326.       case GL_TEXTURE_PRIORITY:
  327.          /* (keithh@netcomuk.co.uk) */
  328.          texObj->Priority = CLAMP( params[0], 0.0F, 1.0F );
  329.          break;
  330.       default:
  331.          gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" );
  332.          return;
  333.    }
  334.  
  335.    gl_put_texobj_on_dirty_list( ctx, texObj );
  336.  
  337.    if (ctx->Driver.TexParameter) {
  338.       (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
  339.    }
  340. }
  341.  
  342.  
  343.  
  344. void gl_GetTexLevelParameterfv( GLcontext *ctx, GLenum target, GLint level,
  345.                                 GLenum pname, GLfloat *params )
  346. {
  347.    GLint iparam;
  348.    gl_GetTexLevelParameteriv( ctx, target, level, pname, &iparam );
  349.    *params = (GLfloat) iparam;
  350. }
  351.  
  352.  
  353.  
  354. void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level,
  355.                                 GLenum pname, GLint *params )
  356. {
  357.    const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  358.    const struct gl_texture_image *img = NULL;
  359.    GLuint dimensions;
  360.  
  361.    if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
  362.       gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
  363.       return;
  364.    }
  365.  
  366.    switch (target) {
  367.       case GL_TEXTURE_1D:
  368.          img = texUnit->CurrentD[1]->Image[level];
  369.          dimensions = 1;
  370.          break;
  371.       case GL_TEXTURE_2D:
  372.          img = texUnit->CurrentD[2]->Image[level];
  373.          dimensions = 2;
  374.          break;
  375.       case GL_TEXTURE_3D:
  376.          img = texUnit->CurrentD[3]->Image[level];
  377.          dimensions = 3; 
  378.         break;
  379.       case GL_PROXY_TEXTURE_1D:
  380.          img = ctx->Texture.Proxy1D->Image[level];
  381.          dimensions = 1;
  382.          break;
  383.       case GL_PROXY_TEXTURE_2D:
  384.          img = ctx->Texture.Proxy2D->Image[level];
  385.          dimensions = 2;
  386.          break;
  387.       case GL_PROXY_TEXTURE_3D:
  388.          img = ctx->Texture.Proxy3D->Image[level];
  389.          dimensions = 3;
  390.          break;
  391.       default:
  392.      gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
  393.          return;
  394.    }
  395.  
  396.    if (!img) {
  397.       if (pname == GL_TEXTURE_COMPONENTS)
  398.          *params = 1;
  399.       else
  400.          *params = 0;
  401.       return;
  402.    }
  403.  
  404.    switch (pname) {
  405.       case GL_TEXTURE_WIDTH:
  406.          *params = img->Width;
  407.          return;
  408.       case GL_TEXTURE_HEIGHT:
  409.          if (dimensions > 1) {
  410.             *params = img->Height;
  411.          }
  412.          else {
  413.             gl_error( ctx, GL_INVALID_ENUM,
  414.                       "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
  415.          }
  416.          return;
  417.       case GL_TEXTURE_DEPTH:
  418.          if (dimensions > 2) {
  419.             *params = img->Depth;
  420.          }
  421.          else {
  422.             gl_error( ctx, GL_INVALID_ENUM,
  423.                       "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
  424.          }
  425.          return;
  426.       case GL_TEXTURE_COMPONENTS:
  427.          *params = img->IntFormat;
  428.          return;
  429.       case GL_TEXTURE_BORDER:
  430.          *params = img->Border;
  431.          return;
  432.       case GL_TEXTURE_RED_SIZE:
  433.          *params = img->RedBits;
  434.          return;
  435.       case GL_TEXTURE_GREEN_SIZE:
  436.          *params = img->GreenBits;
  437.          return;
  438.       case GL_TEXTURE_BLUE_SIZE:
  439.          *params = img->BlueBits;
  440.          return;
  441.       case GL_TEXTURE_ALPHA_SIZE:
  442.          *params = img->AlphaBits;
  443.          return;
  444.       case GL_TEXTURE_INTENSITY_SIZE:
  445.          *params = img->IntensityBits;
  446.          return;
  447.       case GL_TEXTURE_LUMINANCE_SIZE:
  448.          *params = img->LuminanceBits;
  449.          return;
  450.       case GL_TEXTURE_INDEX_SIZE_EXT:
  451.          *params = img->IndexBits;
  452.          return;
  453.       default:
  454.          gl_error( ctx, GL_INVALID_ENUM,
  455.                    "glGetTexLevelParameter[if]v(pname)" );
  456.    }
  457. }
  458.  
  459.  
  460.  
  461.  
  462. void gl_GetTexParameterfv( GLcontext *ctx,
  463.                            GLenum target, GLenum pname, GLfloat *params )
  464. {
  465.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  466.    struct gl_texture_object *obj;
  467.  
  468.    switch (target) {
  469.       case GL_TEXTURE_1D:
  470.          obj = texUnit->CurrentD[1];
  471.          break;
  472.       case GL_TEXTURE_2D:
  473.          obj = texUnit->CurrentD[2];
  474.          break;
  475.       case GL_TEXTURE_3D_EXT:
  476.          obj = texUnit->CurrentD[3];
  477.          break;
  478.       default:
  479.          gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
  480.          return;
  481.    }
  482.  
  483.    switch (pname) {
  484.       case GL_TEXTURE_MAG_FILTER:
  485.      *params = ENUM_TO_FLOAT(obj->MagFilter);
  486.      break;
  487.       case GL_TEXTURE_MIN_FILTER:
  488.          *params = ENUM_TO_FLOAT(obj->MinFilter);
  489.          break;
  490.       case GL_TEXTURE_WRAP_S:
  491.          *params = ENUM_TO_FLOAT(obj->WrapS);
  492.          break;
  493.       case GL_TEXTURE_WRAP_T:
  494.          *params = ENUM_TO_FLOAT(obj->WrapT);
  495.          break;
  496.       case GL_TEXTURE_WRAP_R_EXT:
  497.          *params = ENUM_TO_FLOAT(obj->WrapR);
  498.          break;
  499.       case GL_TEXTURE_BORDER_COLOR:
  500.          params[0] = obj->BorderColor[0] / 255.0F;
  501.          params[1] = obj->BorderColor[1] / 255.0F;
  502.          params[2] = obj->BorderColor[2] / 255.0F;
  503.          params[3] = obj->BorderColor[3] / 255.0F;
  504.          break;
  505.       case GL_TEXTURE_RESIDENT:
  506.          *params = ENUM_TO_FLOAT(GL_TRUE);
  507.          break;
  508.       case GL_TEXTURE_PRIORITY:
  509.          *params = obj->Priority;
  510.          break;
  511.       case GL_TEXTURE_MIN_LOD:
  512.          *params = obj->MinLod;
  513.          break;
  514.       case GL_TEXTURE_MAX_LOD:
  515.          *params = obj->MaxLod;
  516.          break;
  517.       case GL_TEXTURE_BASE_LEVEL:
  518.          *params = (GLfloat) obj->BaseLevel;
  519.          break;
  520.       case GL_TEXTURE_MAX_LEVEL:
  521.          *params = (GLfloat) obj->MaxLevel;
  522.          break;
  523.       default:
  524.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
  525.    }
  526. }
  527.  
  528.  
  529. void gl_GetTexParameteriv( GLcontext *ctx,
  530.                            GLenum target, GLenum pname, GLint *params )
  531. {
  532.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  533.    struct gl_texture_object *obj;
  534.  
  535.    switch (target) {
  536.       case GL_TEXTURE_1D:
  537.          obj = texUnit->CurrentD[1];
  538.          break;
  539.       case GL_TEXTURE_2D:
  540.          obj = texUnit->CurrentD[2];
  541.          break;
  542.       case GL_TEXTURE_3D_EXT:
  543.          obj = texUnit->CurrentD[3];
  544.          break;
  545.       default:
  546.          gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
  547.          return;
  548.    }
  549.  
  550.    switch (pname) {
  551.       case GL_TEXTURE_MAG_FILTER:
  552.          *params = (GLint) obj->MagFilter;
  553.          break;
  554.       case GL_TEXTURE_MIN_FILTER:
  555.          *params = (GLint) obj->MinFilter;
  556.          break;
  557.       case GL_TEXTURE_WRAP_S:
  558.          *params = (GLint) obj->WrapS;
  559.          break;
  560.       case GL_TEXTURE_WRAP_T:
  561.          *params = (GLint) obj->WrapT;
  562.          break;
  563.       case GL_TEXTURE_WRAP_R_EXT:
  564.          *params = (GLint) obj->WrapR;
  565.          break;
  566.       case GL_TEXTURE_BORDER_COLOR:
  567.          {
  568.             GLfloat color[4];
  569.             color[0] = obj->BorderColor[0] / 255.0F;
  570.             color[1] = obj->BorderColor[1] / 255.0F;
  571.             color[2] = obj->BorderColor[2] / 255.0F;
  572.             color[3] = obj->BorderColor[3] / 255.0F;
  573.             params[0] = FLOAT_TO_INT( color[0] );
  574.             params[1] = FLOAT_TO_INT( color[1] );
  575.             params[2] = FLOAT_TO_INT( color[2] );
  576.             params[3] = FLOAT_TO_INT( color[3] );
  577.          }
  578.          break;
  579.       case GL_TEXTURE_RESIDENT:
  580.          *params = (GLint) GL_TRUE;
  581.          break;
  582.       case GL_TEXTURE_PRIORITY:
  583.          *params = (GLint) obj->Priority;
  584.          break;
  585.       case GL_TEXTURE_MIN_LOD:
  586.          *params = (GLint) obj->MinLod;
  587.          break;
  588.       case GL_TEXTURE_MAX_LOD:
  589.          *params = (GLint) obj->MaxLod;
  590.          break;
  591.       case GL_TEXTURE_BASE_LEVEL:
  592.          *params = obj->BaseLevel;
  593.          break;
  594.       case GL_TEXTURE_MAX_LEVEL:
  595.          *params = obj->MaxLevel;
  596.          break;
  597.       default:
  598.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
  599.    }
  600. }
  601.  
  602.  
  603.  
  604.  
  605. /**********************************************************************/
  606. /*                    Texture Coord Generation                        */
  607. /**********************************************************************/
  608.  
  609.  
  610. void gl_TexGenfv( GLcontext *ctx,
  611.                   GLenum coord, GLenum pname, const GLfloat *params )
  612. {
  613.    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
  614.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
  615.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexGenfv");
  616.  
  617.    if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
  618.       fprintf(stderr, "texGEN %s %s %x...\n", 
  619.           gl_lookup_enum_by_nr(coord),
  620.           gl_lookup_enum_by_nr(pname),
  621.           *(int *)params);
  622.  
  623.    switch( coord ) {
  624.       case GL_S:
  625.          if (pname==GL_TEXTURE_GEN_MODE) {
  626.         GLenum mode = (GLenum) (GLint) *params;
  627.         switch (mode) {
  628.         case GL_OBJECT_LINEAR:
  629.            texUnit->GenModeS = mode;
  630.            texUnit->GenBitS = TEXGEN_OBJ_LINEAR;
  631.            break;
  632.         case GL_EYE_LINEAR:
  633.            texUnit->GenModeS = mode;
  634.            texUnit->GenBitS = TEXGEN_EYE_LINEAR;
  635.            break;
  636.         case GL_REFLECTION_MAP_NV:
  637.            texUnit->GenModeS = mode;
  638.            texUnit->GenBitS = TEXGEN_REFLECTION_MAP_NV;
  639.            break;
  640.         case GL_NORMAL_MAP_NV:
  641.            texUnit->GenModeS = mode;
  642.            texUnit->GenBitS = TEXGEN_NORMAL_MAP_NV;
  643.            break;
  644.         case GL_SPHERE_MAP:
  645.            texUnit->GenModeS = mode;
  646.            texUnit->GenBitS = TEXGEN_SPHERE_MAP;
  647.            break;
  648.         default:
  649.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  650.            return;
  651.         }
  652.      }
  653.      else if (pname==GL_OBJECT_PLANE) {
  654.         texUnit->ObjectPlaneS[0] = params[0];
  655.         texUnit->ObjectPlaneS[1] = params[1];
  656.         texUnit->ObjectPlaneS[2] = params[2];
  657.         texUnit->ObjectPlaneS[3] = params[3];
  658.      }
  659.      else if (pname==GL_EYE_PLANE) {
  660.             /* Transform plane equation by the inverse modelview matrix */
  661.             if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
  662.                gl_matrix_analyze( &ctx->ModelView );
  663.             }
  664.             gl_transform_vector( texUnit->EyePlaneS, params,
  665.                                  ctx->ModelView.inv );
  666.      }
  667.      else {
  668.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  669.         return;
  670.      }
  671.      break;
  672.       case GL_T:
  673.          if (pname==GL_TEXTURE_GEN_MODE) {
  674.         GLenum mode = (GLenum) (GLint) *params;
  675.         switch(mode) {
  676.         case GL_OBJECT_LINEAR:
  677.            texUnit->GenModeT = GL_OBJECT_LINEAR;
  678.            texUnit->GenBitT = TEXGEN_OBJ_LINEAR;
  679.            break;
  680.         case GL_EYE_LINEAR:
  681.            texUnit->GenModeT = GL_EYE_LINEAR;
  682.            texUnit->GenBitT = TEXGEN_EYE_LINEAR;
  683.            break;
  684.         case GL_REFLECTION_MAP_NV:
  685.            texUnit->GenModeT = GL_REFLECTION_MAP_NV;
  686.            texUnit->GenBitT = TEXGEN_REFLECTION_MAP_NV;
  687.            break;
  688.         case GL_NORMAL_MAP_NV:
  689.            texUnit->GenModeT = GL_NORMAL_MAP_NV;
  690.            texUnit->GenBitT = TEXGEN_NORMAL_MAP_NV;
  691.            break;
  692.         case GL_SPHERE_MAP:
  693.            texUnit->GenModeT = GL_SPHERE_MAP;
  694.            texUnit->GenBitT = TEXGEN_SPHERE_MAP;
  695.            break;
  696.         default:
  697.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  698.            return;
  699.         }
  700.      }
  701.      else if (pname==GL_OBJECT_PLANE) {
  702.         texUnit->ObjectPlaneT[0] = params[0];
  703.         texUnit->ObjectPlaneT[1] = params[1];
  704.         texUnit->ObjectPlaneT[2] = params[2];
  705.         texUnit->ObjectPlaneT[3] = params[3];
  706.      }
  707.      else if (pname==GL_EYE_PLANE) {
  708.             /* Transform plane equation by the inverse modelview matrix */
  709.             if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
  710.                gl_matrix_analyze( &ctx->ModelView );
  711.             }
  712.             gl_transform_vector( texUnit->EyePlaneT, params,
  713.                                  ctx->ModelView.inv );
  714.      }
  715.      else {
  716.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  717.         return;
  718.      }
  719.      break;
  720.       case GL_R:
  721.          if (pname==GL_TEXTURE_GEN_MODE) {
  722.         GLenum mode = (GLenum) (GLint) *params;
  723.         switch (mode) {
  724.         case GL_OBJECT_LINEAR:
  725.            texUnit->GenModeR = GL_OBJECT_LINEAR;
  726.            texUnit->GenBitR = TEXGEN_OBJ_LINEAR;
  727.            break;
  728.         case GL_REFLECTION_MAP_NV:
  729.            texUnit->GenModeR = GL_REFLECTION_MAP_NV;
  730.            texUnit->GenBitR = TEXGEN_REFLECTION_MAP_NV;
  731.            break;
  732.         case GL_NORMAL_MAP_NV:
  733.            texUnit->GenModeR = GL_NORMAL_MAP_NV;
  734.            texUnit->GenBitR = TEXGEN_NORMAL_MAP_NV;
  735.            break;
  736.         case GL_EYE_LINEAR:
  737.            texUnit->GenModeR = GL_EYE_LINEAR;
  738.            texUnit->GenBitR = TEXGEN_EYE_LINEAR;
  739.            break;
  740.         default:
  741.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  742.            return;
  743.         }
  744.      }
  745.      else if (pname==GL_OBJECT_PLANE) {
  746.         texUnit->ObjectPlaneR[0] = params[0];
  747.         texUnit->ObjectPlaneR[1] = params[1];
  748.         texUnit->ObjectPlaneR[2] = params[2];
  749.         texUnit->ObjectPlaneR[3] = params[3];
  750.      }
  751.      else if (pname==GL_EYE_PLANE) {
  752.             /* Transform plane equation by the inverse modelview matrix */
  753.             if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
  754.                gl_matrix_analyze( &ctx->ModelView );
  755.             }
  756.             gl_transform_vector( texUnit->EyePlaneR, params,
  757.                                  ctx->ModelView.inv );
  758.      }
  759.      else {
  760.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  761.         return;
  762.      }
  763.      break;
  764.       case GL_Q:
  765.          if (pname==GL_TEXTURE_GEN_MODE) {
  766.         GLenum mode = (GLenum) (GLint) *params;
  767.         switch (mode) {
  768.         case GL_OBJECT_LINEAR: 
  769.            texUnit->GenModeQ = GL_OBJECT_LINEAR;
  770.            texUnit->GenBitQ = TEXGEN_OBJ_LINEAR;
  771.            break;
  772.         case GL_EYE_LINEAR:
  773.            texUnit->GenModeQ = GL_EYE_LINEAR;
  774.            texUnit->GenBitQ = TEXGEN_EYE_LINEAR;
  775.            break;
  776.         default:
  777.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  778.            return;
  779.         }
  780.      }
  781.      else if (pname==GL_OBJECT_PLANE) {
  782.         texUnit->ObjectPlaneQ[0] = params[0];
  783.         texUnit->ObjectPlaneQ[1] = params[1];
  784.         texUnit->ObjectPlaneQ[2] = params[2];
  785.         texUnit->ObjectPlaneQ[3] = params[3];
  786.      }
  787.      else if (pname==GL_EYE_PLANE) {
  788.             /* Transform plane equation by the inverse modelview matrix */
  789.             if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
  790.                gl_matrix_analyze( &ctx->ModelView );
  791.             }
  792.             gl_transform_vector( texUnit->EyePlaneQ, params,
  793.                                  ctx->ModelView.inv );
  794.      }
  795.      else {
  796.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  797.         return;
  798.      }
  799.      break;
  800.       default:
  801.          gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
  802.      return;
  803.    }
  804.  
  805.    ctx->NewState |= NEW_TEXTURING;
  806. }
  807.  
  808.  
  809.  
  810. void gl_GetTexGendv( GLcontext *ctx,
  811.                      GLenum coord, GLenum pname, GLdouble *params )
  812. {
  813.    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
  814.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
  815.  
  816.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGendv");
  817.  
  818.    switch( coord ) {
  819.       case GL_S:
  820.          if (pname==GL_TEXTURE_GEN_MODE) {
  821.             params[0] = ENUM_TO_DOUBLE(texUnit->GenModeS);
  822.      }
  823.      else if (pname==GL_OBJECT_PLANE) {
  824.             COPY_4V( params, texUnit->ObjectPlaneS );
  825.      }
  826.      else if (pname==GL_EYE_PLANE) {
  827.             COPY_4V( params, texUnit->EyePlaneS );
  828.      }
  829.      else {
  830.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  831.         return;
  832.      }
  833.      break;
  834.       case GL_T:
  835.          if (pname==GL_TEXTURE_GEN_MODE) {
  836.             params[0] = ENUM_TO_DOUBLE(texUnit->GenModeT);
  837.      }
  838.      else if (pname==GL_OBJECT_PLANE) {
  839.             COPY_4V( params, texUnit->ObjectPlaneT );
  840.      }
  841.      else if (pname==GL_EYE_PLANE) {
  842.             COPY_4V( params, texUnit->EyePlaneT );
  843.      }
  844.      else {
  845.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  846.         return;
  847.      }
  848.      break;
  849.       case GL_R:
  850.          if (pname==GL_TEXTURE_GEN_MODE) {
  851.             params[0] = ENUM_TO_DOUBLE(texUnit->GenModeR);
  852.      }
  853.      else if (pname==GL_OBJECT_PLANE) {
  854.             COPY_4V( params, texUnit->ObjectPlaneR );
  855.      }
  856.      else if (pname==GL_EYE_PLANE) {
  857.             COPY_4V( params, texUnit->EyePlaneR );
  858.      }
  859.      else {
  860.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  861.         return;
  862.      }
  863.      break;
  864.       case GL_Q:
  865.          if (pname==GL_TEXTURE_GEN_MODE) {
  866.             params[0] = ENUM_TO_DOUBLE(texUnit->GenModeQ);
  867.      }
  868.      else if (pname==GL_OBJECT_PLANE) {
  869.             COPY_4V( params, texUnit->ObjectPlaneQ );
  870.      }
  871.      else if (pname==GL_EYE_PLANE) {
  872.             COPY_4V( params, texUnit->EyePlaneQ );
  873.      }
  874.      else {
  875.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  876.         return;
  877.      }
  878.      break;
  879.       default:
  880.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
  881.      return;
  882.    }
  883. }
  884.  
  885.  
  886.  
  887. void gl_GetTexGenfv( GLcontext *ctx,
  888.                      GLenum coord, GLenum pname, GLfloat *params )
  889. {
  890.    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
  891.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
  892.  
  893.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGenfv");
  894.  
  895.    switch( coord ) {
  896.       case GL_S:
  897.          if (pname==GL_TEXTURE_GEN_MODE) {
  898.             params[0] = ENUM_TO_FLOAT(texUnit->GenModeS);
  899.      }
  900.      else if (pname==GL_OBJECT_PLANE) {
  901.             COPY_4V( params, texUnit->ObjectPlaneS );
  902.      }
  903.      else if (pname==GL_EYE_PLANE) {
  904.             COPY_4V( params, texUnit->EyePlaneS );
  905.      }
  906.      else {
  907.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  908.         return;
  909.      }
  910.      break;
  911.       case GL_T:
  912.          if (pname==GL_TEXTURE_GEN_MODE) {
  913.             params[0] = ENUM_TO_FLOAT(texUnit->GenModeT);
  914.      }
  915.      else if (pname==GL_OBJECT_PLANE) {
  916.             COPY_4V( params, texUnit->ObjectPlaneT );
  917.      }
  918.      else if (pname==GL_EYE_PLANE) {
  919.             COPY_4V( params, texUnit->EyePlaneT );
  920.      }
  921.      else {
  922.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  923.         return;
  924.      }
  925.      break;
  926.       case GL_R:
  927.          if (pname==GL_TEXTURE_GEN_MODE) {
  928.             params[0] = ENUM_TO_FLOAT(texUnit->GenModeR);
  929.      }
  930.      else if (pname==GL_OBJECT_PLANE) {
  931.             COPY_4V( params, texUnit->ObjectPlaneR );
  932.      }
  933.      else if (pname==GL_EYE_PLANE) {
  934.             COPY_4V( params, texUnit->EyePlaneR );
  935.      }
  936.      else {
  937.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  938.         return;
  939.      }
  940.      break;
  941.       case GL_Q:
  942.          if (pname==GL_TEXTURE_GEN_MODE) {
  943.             params[0] = ENUM_TO_FLOAT(texUnit->GenModeQ);
  944.      }
  945.      else if (pname==GL_OBJECT_PLANE) {
  946.             COPY_4V( params, texUnit->ObjectPlaneQ );
  947.      }
  948.      else if (pname==GL_EYE_PLANE) {
  949.             COPY_4V( params, texUnit->EyePlaneQ );
  950.      }
  951.      else {
  952.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  953.         return;
  954.      }
  955.      break;
  956.       default:
  957.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
  958.      return;
  959.    }
  960. }
  961.  
  962.  
  963.  
  964. void gl_GetTexGeniv( GLcontext *ctx,
  965.                      GLenum coord, GLenum pname, GLint *params )
  966. {
  967.    GLuint tUnit = ctx->Texture.CurrentTransformUnit;
  968.    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
  969.  
  970.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGeniv");
  971.  
  972.    switch( coord ) {
  973.       case GL_S:
  974.          if (pname==GL_TEXTURE_GEN_MODE) {
  975.             params[0] = texUnit->GenModeS;
  976.      }
  977.      else if (pname==GL_OBJECT_PLANE) {
  978.             params[0] = (GLint) texUnit->ObjectPlaneS[0];
  979.             params[1] = (GLint) texUnit->ObjectPlaneS[1];
  980.             params[2] = (GLint) texUnit->ObjectPlaneS[2];
  981.             params[3] = (GLint) texUnit->ObjectPlaneS[3];
  982.      }
  983.      else if (pname==GL_EYE_PLANE) {
  984.             params[0] = (GLint) texUnit->EyePlaneS[0];
  985.             params[1] = (GLint) texUnit->EyePlaneS[1];
  986.             params[2] = (GLint) texUnit->EyePlaneS[2];
  987.             params[3] = (GLint) texUnit->EyePlaneS[3];
  988.      }
  989.      else {
  990.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  991.         return;
  992.      }
  993.      break;
  994.       case GL_T:
  995.          if (pname==GL_TEXTURE_GEN_MODE) {
  996.             params[0] = (GLint) texUnit->GenModeT;
  997.      }
  998.      else if (pname==GL_OBJECT_PLANE) {
  999.             params[0] = (GLint) texUnit->ObjectPlaneT[0];
  1000.             params[1] = (GLint) texUnit->ObjectPlaneT[1];
  1001.             params[2] = (GLint) texUnit->ObjectPlaneT[2];
  1002.             params[3] = (GLint) texUnit->ObjectPlaneT[3];
  1003.      }
  1004.      else if (pname==GL_EYE_PLANE) {
  1005.             params[0] = (GLint) texUnit->EyePlaneT[0];
  1006.             params[1] = (GLint) texUnit->EyePlaneT[1];
  1007.             params[2] = (GLint) texUnit->EyePlaneT[2];
  1008.             params[3] = (GLint) texUnit->EyePlaneT[3];
  1009.      }
  1010.      else {
  1011.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1012.         return;
  1013.      }
  1014.      break;
  1015.       case GL_R:
  1016.          if (pname==GL_TEXTURE_GEN_MODE) {
  1017.             params[0] = (GLint) texUnit->GenModeR;
  1018.      }
  1019.      else if (pname==GL_OBJECT_PLANE) {
  1020.             params[0] = (GLint) texUnit->ObjectPlaneR[0];
  1021.             params[1] = (GLint) texUnit->ObjectPlaneR[1];
  1022.             params[2] = (GLint) texUnit->ObjectPlaneR[2];
  1023.             params[3] = (GLint) texUnit->ObjectPlaneR[3];
  1024.      }
  1025.      else if (pname==GL_EYE_PLANE) {
  1026.             params[0] = (GLint) texUnit->EyePlaneR[0];
  1027.             params[1] = (GLint) texUnit->EyePlaneR[1];
  1028.             params[2] = (GLint) texUnit->EyePlaneR[2];
  1029.             params[3] = (GLint) texUnit->EyePlaneR[3];
  1030.      }
  1031.      else {
  1032.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1033.         return;
  1034.      }
  1035.      break;
  1036.       case GL_Q:
  1037.          if (pname==GL_TEXTURE_GEN_MODE) {
  1038.             params[0] = (GLint) texUnit->GenModeQ;
  1039.      }
  1040.      else if (pname==GL_OBJECT_PLANE) {
  1041.             params[0] = (GLint) texUnit->ObjectPlaneQ[0];
  1042.             params[1] = (GLint) texUnit->ObjectPlaneQ[1];
  1043.             params[2] = (GLint) texUnit->ObjectPlaneQ[2];
  1044.             params[3] = (GLint) texUnit->ObjectPlaneQ[3];
  1045.      }
  1046.      else if (pname==GL_EYE_PLANE) {
  1047.             params[0] = (GLint) texUnit->EyePlaneQ[0];
  1048.             params[1] = (GLint) texUnit->EyePlaneQ[1];
  1049.             params[2] = (GLint) texUnit->EyePlaneQ[2];
  1050.             params[3] = (GLint) texUnit->EyePlaneQ[3];
  1051.      }
  1052.      else {
  1053.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1054.         return;
  1055.      }
  1056.      break;
  1057.       default:
  1058.          gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
  1059.      return;
  1060.    }
  1061. }
  1062.  
  1063.  
  1064. /* GL_ARB_multitexture */
  1065. void gl_ActiveTexture( GLcontext *ctx, GLenum target )
  1066. {
  1067.    GLint maxUnits = ctx->Const.MaxTextureUnits;
  1068.  
  1069.    ASSERT_OUTSIDE_BEGIN_END( ctx, "glActiveTextureARB" );
  1070.  
  1071.    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
  1072.       fprintf(stderr, "glActiveTexture %s\n", 
  1073.           gl_lookup_enum_by_nr(target));
  1074.  
  1075.    if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
  1076.       GLint texUnit = target - GL_TEXTURE0_ARB;
  1077.       ctx->Texture.CurrentUnit = texUnit;
  1078.       ctx->Texture.CurrentTransformUnit = texUnit;
  1079.       if (ctx->Driver.ActiveTexture) {
  1080.          (*ctx->Driver.ActiveTexture)( ctx, (GLuint) texUnit );
  1081.       }
  1082.    }
  1083.    else {
  1084.       gl_error(ctx, GL_INVALID_OPERATION, "glActiveTextureARB(target)");
  1085.    }
  1086. }
  1087.  
  1088.  
  1089. /* GL_ARB_multitexture */
  1090. void gl_ClientActiveTexture( GLcontext *ctx, GLenum target )
  1091. {
  1092.    GLint maxUnits = ctx->Const.MaxTextureUnits;
  1093.  
  1094.    ASSERT_OUTSIDE_BEGIN_END( ctx, "glClientActiveTextureARB" );
  1095.  
  1096.    if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
  1097.       GLint texUnit = target - GL_TEXTURE0_ARB;
  1098.       ctx->Array.ActiveTexture = texUnit;
  1099.    }
  1100.    else {
  1101.       gl_error(ctx, GL_INVALID_OPERATION, "glActiveTextureARB(target)");
  1102.    }
  1103. }
  1104.  
  1105.  
  1106.  
  1107. /*
  1108.  * Put the given texture object into the list of dirty texture objects.
  1109.  * When a texture object is dirty we have to reexamine it for completeness
  1110.  * and perhaps choose a different texture sampling function.
  1111.  */
  1112. void gl_put_texobj_on_dirty_list( GLcontext *ctx, struct gl_texture_object *t )
  1113. {
  1114.    ASSERT(ctx);
  1115.    ASSERT(t);
  1116.    /* Only insert if not already in the dirty list.
  1117.     * The Dirty flag is only set iff the texture object is in the dirty list.
  1118.     */
  1119.    if (!t->Dirty) {
  1120.       ASSERT(t->NextDirty == NULL);
  1121.       t->Dirty = GL_TRUE;
  1122.       t->NextDirty = ctx->Shared->DirtyTexObjList;
  1123.       ctx->Shared->DirtyTexObjList = t;
  1124.    }
  1125. #ifdef DEBUG
  1126.    else {
  1127.       /* make sure t is in the list */
  1128.       struct gl_texture_object *obj = ctx->Shared->DirtyTexObjList;
  1129.       while (obj) {
  1130.          if (obj == t) {
  1131.             return;
  1132.          }
  1133.          obj = obj->NextDirty;
  1134.       }
  1135.       gl_problem(ctx, "Error in gl_put_texobj_on_dirty_list");
  1136.    }
  1137. #endif
  1138. }
  1139.  
  1140.  
  1141. /*
  1142.  * Remove a texture object from the dirty texture list.
  1143.  */
  1144. void gl_remove_texobj_from_dirty_list( struct gl_shared_state *shared,
  1145.                                        struct gl_texture_object *tObj )
  1146. {
  1147.    struct gl_texture_object *t, *prev = NULL;
  1148.    ASSERT(shared);
  1149.    ASSERT(tObj);
  1150.    for (t = shared->DirtyTexObjList; t; t = t->NextDirty) {
  1151.       if (t == tObj) {
  1152.          if (prev) {
  1153.             prev->NextDirty = t->NextDirty;
  1154.          }
  1155.          else {
  1156.             shared->DirtyTexObjList = t->NextDirty;
  1157.          }
  1158.          return;
  1159.       }
  1160.       prev = t;
  1161.    }
  1162. }
  1163.  
  1164.  
  1165. /*
  1166.  * This is called by gl_update_state() if the NEW_TEXTURING bit in
  1167.  * ctx->NewState is unit.
  1168.  */
  1169. void gl_update_dirty_texobjs( GLcontext *ctx )
  1170. {
  1171.    struct gl_texture_object *t, *next;
  1172.    for (t = ctx->Shared->DirtyTexObjList; t; t = next) {
  1173.       next = t->NextDirty;
  1174.       gl_test_texture_object_completeness(ctx, t);
  1175.       gl_set_texture_sampler(t);
  1176.       t->NextDirty = NULL;
  1177.       t->Dirty = GL_FALSE;
  1178.    }
  1179.    ctx->Shared->DirtyTexObjList = NULL;
  1180. }
  1181.