home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / texstate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  30.1 KB  |  1,113 lines

  1. /* $Id: texstate.c,v 1.8 1997/10/13 23:56:01 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.5
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: texstate.c,v $
  26.  * Revision 1.8  1997/10/13 23:56:01  brianp
  27.  * replaced UpdateTexture() call with TexParameter()
  28.  *
  29.  * Revision 1.7  1997/09/29 23:28:14  brianp
  30.  * updated for new device driver texture functions
  31.  *
  32.  * Revision 1.6  1997/09/27 00:14:39  brianp
  33.  * added GL_EXT_paletted_texture extension
  34.  *
  35.  * Revision 1.5  1997/07/24 01:25:34  brianp
  36.  * changed precompiled header symbol from PCH to PC_HEADER
  37.  *
  38.  * Revision 1.4  1997/05/28 03:26:49  brianp
  39.  * added precompiled header (PCH) support
  40.  *
  41.  * Revision 1.3  1997/05/03 00:53:28  brianp
  42.  * misc changes related to new texture object sampling function pointer
  43.  *
  44.  * Revision 1.2  1997/04/28 23:34:39  brianp
  45.  * simplified gl_update_texture_state()
  46.  *
  47.  * Revision 1.1  1997/04/14 01:59:54  brianp
  48.  * Initial revision
  49.  *
  50.  */
  51.  
  52.  
  53. #ifdef PC_HEADER
  54. #include "all.h"
  55. #else
  56. #include "context.h"
  57. #include "macros.h"
  58. #include "matrix.h"
  59. #include "texobj.h"
  60. #include "texstate.h"
  61. #include "texture.h"
  62. #include "types.h"
  63. #include "xform.h"
  64. #endif
  65.  
  66. #define BOOL_TO_FLOAT(X)        ( (GLfloat)(GLint) (X) )
  67. #define BOOL_TO_DOUBLE(X)        ( (GLdouble)(GLint) (X) )
  68.  
  69.  
  70. /**********************************************************************/
  71. /*                       Texture Environment                          */
  72. /**********************************************************************/
  73.  
  74.  
  75.  
  76. void gl_TexEnvfv( GLcontext *ctx,
  77.           GLenum target, GLenum pname, const GLfloat *param )
  78. {
  79.    if (INSIDE_BEGIN_END(ctx)) {
  80.       gl_error( ctx, GL_INVALID_OPERATION, "glTexEnv" );
  81.       return;
  82.    }
  83.  
  84.    if (target!=GL_TEXTURE_ENV) {
  85.       gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
  86.       return;
  87.    }
  88.  
  89.    if (pname==GL_TEXTURE_ENV_MODE) {
  90.       GLenum mode = (GLenum) (GLint) *param;
  91.       switch (mode) {
  92.      case GL_MODULATE:
  93.      case GL_BLEND:
  94.      case GL_DECAL:
  95.      case GL_REPLACE:
  96.         ctx->Texture.EnvMode = mode;
  97.         break;
  98.      default:
  99.         gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
  100.         return;
  101.       }
  102.    }
  103.    else if (pname==GL_TEXTURE_ENV_COLOR) {
  104.       ctx->Texture.EnvColor[0] = CLAMP( param[0], 0.0, 1.0 );
  105.       ctx->Texture.EnvColor[1] = CLAMP( param[1], 0.0, 1.0 );
  106.       ctx->Texture.EnvColor[2] = CLAMP( param[2], 0.0, 1.0 );
  107.       ctx->Texture.EnvColor[3] = CLAMP( param[3], 0.0, 1.0 );
  108.    }
  109.    else {
  110.       gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
  111.       return;
  112.    }
  113.  
  114.    /* Tell device driver about the new texture environment */
  115.    if (ctx->Driver.TexEnv) {
  116.       (*ctx->Driver.TexEnv)( ctx, pname, param );
  117.    }
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124. void gl_GetTexEnvfv( GLcontext *ctx,
  125.              GLenum target, GLenum pname, GLfloat *params )
  126. {
  127.    if (target!=GL_TEXTURE_ENV) {
  128.       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
  129.       return;
  130.    }
  131.    switch (pname) {
  132.       case GL_TEXTURE_ENV_MODE:
  133.      *params = BOOL_TO_FLOAT( ctx->Texture.EnvMode );
  134.      break;
  135.       case GL_TEXTURE_ENV_COLOR:
  136.      COPY_4V( params, ctx->Texture.EnvColor );
  137.      break;
  138.       default:
  139.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
  140.    }
  141. }
  142.  
  143.  
  144. void gl_GetTexEnviv( GLcontext *ctx,
  145.              GLenum target, GLenum pname, GLint *params )
  146. {
  147.    if (target!=GL_TEXTURE_ENV) {
  148.       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
  149.       return;
  150.    }
  151.    switch (pname) {
  152.       case GL_TEXTURE_ENV_MODE:
  153.      *params = (GLint) ctx->Texture.EnvMode;
  154.      break;
  155.       case GL_TEXTURE_ENV_COLOR:
  156.      params[0] = FLOAT_TO_INT( ctx->Texture.EnvColor[0] );
  157.      params[1] = FLOAT_TO_INT( ctx->Texture.EnvColor[1] );
  158.      params[2] = FLOAT_TO_INT( ctx->Texture.EnvColor[2] );
  159.      params[3] = FLOAT_TO_INT( ctx->Texture.EnvColor[3] );
  160.      break;
  161.       default:
  162.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
  163.    }
  164. }
  165.  
  166.  
  167.  
  168.  
  169. /**********************************************************************/
  170. /*                       Texture Parameters                           */
  171. /**********************************************************************/
  172.  
  173.  
  174. void gl_TexParameterfv( GLcontext *ctx,
  175.             GLenum target, GLenum pname, const GLfloat *params )
  176. {
  177.    GLenum eparam = (GLenum) (GLint) params[0];
  178.    struct gl_texture_object *texObj;
  179.  
  180.    switch (target) {
  181.       case GL_TEXTURE_1D:
  182.      texObj = ctx->Texture.Current1D;
  183.      break;
  184.       case GL_TEXTURE_2D:
  185.      texObj = ctx->Texture.Current2D;
  186.      break;
  187.       case GL_TEXTURE_3D_EXT:
  188.      texObj = ctx->Texture.Current3D;
  189.      break;
  190.       default:
  191.      gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
  192.      return;
  193.    }
  194.  
  195.    switch (pname) {
  196.       case GL_TEXTURE_MIN_FILTER:
  197.      if (eparam==GL_NEAREST || eparam==GL_LINEAR
  198.          || eparam==GL_NEAREST_MIPMAP_NEAREST
  199.          || eparam==GL_LINEAR_MIPMAP_NEAREST
  200.          || eparam==GL_NEAREST_MIPMAP_LINEAR
  201.          || eparam==GL_LINEAR_MIPMAP_LINEAR) {
  202.         texObj->MinFilter = eparam;
  203.         ctx->NewState |= NEW_TEXTURING;
  204.      }
  205.      else {
  206.         gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  207.         return;
  208.      }
  209.      break;
  210.       case GL_TEXTURE_MAG_FILTER:
  211.      if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
  212.         texObj->MagFilter = eparam;
  213.         ctx->NewState |= NEW_TEXTURING;
  214.      }
  215.      else {
  216.         gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  217.         return;
  218.      }
  219.      break;
  220.       case GL_TEXTURE_WRAP_S:
  221.      if (eparam==GL_CLAMP || eparam==GL_REPEAT) {
  222.         texObj->WrapS = eparam;
  223.      }
  224.      else {
  225.         gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  226.         return;
  227.      }
  228.      break;
  229.       case GL_TEXTURE_WRAP_T:
  230.      if (eparam==GL_CLAMP || eparam==GL_REPEAT) {
  231.         texObj->WrapT = eparam;
  232.      }
  233.      else {
  234.         gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  235.         return;
  236.      }
  237.      break;
  238.       case GL_TEXTURE_WRAP_R_EXT:
  239.      if (eparam==GL_CLAMP || eparam==GL_REPEAT) {
  240.         texObj->WrapR = eparam;
  241.      }
  242.      else {
  243.         gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
  244.      }
  245.      break;
  246.       case GL_TEXTURE_BORDER_COLOR:
  247.      texObj->BorderColor[0] = CLAMP((GLint)(params[0]*255.0), 0, 255);
  248.      texObj->BorderColor[1] = CLAMP((GLint)(params[1]*255.0), 0, 255);
  249.      texObj->BorderColor[2] = CLAMP((GLint)(params[2]*255.0), 0, 255);
  250.      texObj->BorderColor[3] = CLAMP((GLint)(params[3]*255.0), 0, 255);
  251.      break;
  252.       default:
  253.      gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" );
  254.      return;
  255.    }
  256.  
  257.    texObj->Dirty = GL_TRUE;
  258.  
  259.    if (ctx->Driver.TexParameter) {
  260.       (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
  261.    }
  262. }
  263.  
  264.  
  265.  
  266. void gl_GetTexLevelParameterfv( GLcontext *ctx, GLenum target, GLint level,
  267.                 GLenum pname, GLfloat *params )
  268. {
  269.    GLint iparam;
  270.  
  271.    gl_GetTexLevelParameteriv( ctx, target, level, pname, &iparam );
  272.    *params = (GLfloat) iparam;
  273. }
  274.  
  275.  
  276.  
  277. void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level,
  278.                 GLenum pname, GLint *params )
  279. {
  280.    struct gl_texture_image *tex;
  281.  
  282.    if (level<0 || level>=MAX_TEXTURE_LEVELS) {
  283.       gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
  284.       return;
  285.    }
  286.  
  287.    switch (target) {
  288.       case GL_TEXTURE_1D:
  289.      tex = ctx->Texture.Current1D->Image[level];
  290.      switch (pname) {
  291.         case GL_TEXTURE_WIDTH:
  292.            *params = tex->Width;
  293.            break;
  294.         case GL_TEXTURE_COMPONENTS:
  295.            *params = tex->Format;
  296.            break;
  297.         case GL_TEXTURE_BORDER:
  298.            *params = tex->Border;
  299.            break;
  300.         case GL_TEXTURE_RED_SIZE:
  301.         case GL_TEXTURE_GREEN_SIZE:
  302.         case GL_TEXTURE_BLUE_SIZE:
  303.         case GL_TEXTURE_ALPHA_SIZE:
  304.         case GL_TEXTURE_INTENSITY_SIZE:
  305.         case GL_TEXTURE_LUMINANCE_SIZE:
  306.            *params = 8;  /* 8-bits */
  307.            break;
  308.         case GL_TEXTURE_INDEX_SIZE_EXT:
  309.            *params = 8;
  310.            break;
  311.         default:
  312.            gl_error( ctx, GL_INVALID_ENUM,
  313.              "glGetTexLevelParameter[if]v(pname)" );
  314.      }
  315.      break;
  316.       case GL_TEXTURE_2D:
  317.      tex = ctx->Texture.Current2D->Image[level];
  318.      switch (pname) {
  319.         case GL_TEXTURE_WIDTH:
  320.            *params = tex->Width;
  321.            break;
  322.         case GL_TEXTURE_HEIGHT:
  323.            *params = tex->Height;
  324.            break;
  325.         case GL_TEXTURE_COMPONENTS:
  326.            *params = tex->Format;
  327.            break;
  328.         case GL_TEXTURE_BORDER:
  329.            *params = tex->Border;
  330.            break;
  331.         case GL_TEXTURE_RED_SIZE:
  332.         case GL_TEXTURE_GREEN_SIZE:
  333.         case GL_TEXTURE_BLUE_SIZE:
  334.         case GL_TEXTURE_ALPHA_SIZE:
  335.         case GL_TEXTURE_INTENSITY_SIZE:
  336.         case GL_TEXTURE_LUMINANCE_SIZE:
  337.            *params = 8;  /* 8-bits */
  338.            break;
  339.         case GL_TEXTURE_INDEX_SIZE_EXT:
  340.            *params = 8;
  341.            break;
  342.         default:
  343.            gl_error( ctx, GL_INVALID_ENUM,
  344.              "glGetTexLevelParameter[if]v(pname)" );
  345.      }
  346.      break;
  347.       case GL_TEXTURE_3D_EXT:
  348.      tex = ctx->Texture.Current3D->Image[level];
  349.      switch (pname) {
  350.         case GL_TEXTURE_WIDTH:
  351.            *params = tex->Width;
  352.            break;
  353.         case GL_TEXTURE_HEIGHT:
  354.            *params = tex->Height;
  355.            break;
  356.         case GL_TEXTURE_DEPTH_EXT:
  357.            *params = tex->Depth;
  358.            break;
  359.         case GL_TEXTURE_COMPONENTS:
  360.            *params = tex->Format;
  361.            break;
  362.         case GL_TEXTURE_BORDER:
  363.            *params = tex->Border;
  364.            break;
  365.         case GL_TEXTURE_INDEX_SIZE_EXT:
  366.            *params = 8;
  367.            break;
  368.         default:
  369.            gl_error( ctx, GL_INVALID_ENUM,
  370.              "glGetTexLevelParameter[if]v(pname)" );
  371.      }
  372.      break;
  373.       case GL_PROXY_TEXTURE_1D:
  374.      tex = ctx->Texture.Proxy1D->Image[level];
  375.      switch (pname) {
  376.         case GL_TEXTURE_WIDTH:
  377.            *params = tex->Width;
  378.            break;
  379.         case GL_TEXTURE_COMPONENTS:
  380.            *params = tex->Format;
  381.            break;
  382.         case GL_TEXTURE_BORDER:
  383.            *params = tex->Border;
  384.            break;
  385.         case GL_TEXTURE_RED_SIZE:
  386.         case GL_TEXTURE_GREEN_SIZE:
  387.         case GL_TEXTURE_BLUE_SIZE:
  388.         case GL_TEXTURE_ALPHA_SIZE:
  389.         case GL_TEXTURE_INTENSITY_SIZE:
  390.         case GL_TEXTURE_LUMINANCE_SIZE:
  391.            *params = 8;  /* 8-bits */
  392.            break;
  393.         case GL_TEXTURE_INDEX_SIZE_EXT:
  394.            *params = 8;
  395.            break;
  396.         default:
  397.            gl_error( ctx, GL_INVALID_ENUM,
  398.              "glGetTexLevelParameter[if]v(pname)" );
  399.      }
  400.      break;
  401.       case GL_PROXY_TEXTURE_2D:
  402.      tex = ctx->Texture.Proxy2D->Image[level];
  403.      switch (pname) {
  404.         case GL_TEXTURE_WIDTH:
  405.            *params = tex->Width;
  406.            break;
  407.         case GL_TEXTURE_HEIGHT:
  408.            *params = tex->Height;
  409.            break;
  410.         case GL_TEXTURE_COMPONENTS:
  411.            *params = tex->Format;
  412.            break;
  413.         case GL_TEXTURE_BORDER:
  414.            *params = tex->Border;
  415.            break;
  416.         case GL_TEXTURE_RED_SIZE:
  417.         case GL_TEXTURE_GREEN_SIZE:
  418.         case GL_TEXTURE_BLUE_SIZE:
  419.         case GL_TEXTURE_ALPHA_SIZE:
  420.         case GL_TEXTURE_INTENSITY_SIZE:
  421.         case GL_TEXTURE_LUMINANCE_SIZE:
  422.            *params = 8;  /* 8-bits */
  423.            break;
  424.         case GL_TEXTURE_INDEX_SIZE_EXT:
  425.            *params = 8;
  426.            break;
  427.         default:
  428.            gl_error( ctx, GL_INVALID_ENUM,
  429.              "glGetTexLevelParameter[if]v(pname)" );
  430.      }
  431.      break;
  432.       case GL_PROXY_TEXTURE_3D_EXT:
  433.      tex = ctx->Texture.Proxy3D->Image[level];
  434.      switch (pname) {
  435.         case GL_TEXTURE_WIDTH:
  436.            *params = tex->Width;
  437.            break;
  438.         case GL_TEXTURE_HEIGHT:
  439.            *params = tex->Height;
  440.            break;
  441.         case GL_TEXTURE_DEPTH_EXT:
  442.            *params = tex->Depth;
  443.            break;
  444.         case GL_TEXTURE_COMPONENTS:
  445.            *params = tex->Format;
  446.            break;
  447.         case GL_TEXTURE_BORDER:
  448.            *params = tex->Border;
  449.            break;
  450.         case GL_TEXTURE_RED_SIZE:
  451.         case GL_TEXTURE_GREEN_SIZE:
  452.         case GL_TEXTURE_BLUE_SIZE:
  453.         case GL_TEXTURE_ALPHA_SIZE:
  454.         case GL_TEXTURE_INTENSITY_SIZE:
  455.         case GL_TEXTURE_LUMINANCE_SIZE:
  456.            *params = 8;  /* 8-bits */
  457.            break;
  458.         case GL_TEXTURE_INDEX_SIZE_EXT:
  459.            *params = 8;
  460.            break;
  461.         default:
  462.            gl_error( ctx, GL_INVALID_ENUM,
  463.              "glGetTexLevelParameter[if]v(pname)" );
  464.      }
  465.      break;
  466.      default:
  467.      gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
  468.    }     
  469. }
  470.  
  471.  
  472.  
  473.  
  474. void gl_GetTexParameterfv( GLcontext *ctx,
  475.                GLenum target, GLenum pname, GLfloat *params )
  476. {
  477.    switch (target) {
  478.       case GL_TEXTURE_1D:
  479.      switch (pname) {
  480.         case GL_TEXTURE_MAG_FILTER:
  481.            *params = BOOL_TO_FLOAT( ctx->Texture.Current1D->MagFilter );
  482.            break;
  483.         case GL_TEXTURE_MIN_FILTER:
  484.            *params = BOOL_TO_FLOAT( ctx->Texture.Current1D->MinFilter );
  485.            break;
  486.         case GL_TEXTURE_WRAP_S:
  487.            *params = BOOL_TO_FLOAT( ctx->Texture.Current1D->WrapS );
  488.            break;
  489.         case GL_TEXTURE_WRAP_T:
  490.            *params = BOOL_TO_FLOAT( ctx->Texture.Current1D->WrapT );
  491.            break;
  492.         case GL_TEXTURE_BORDER_COLOR:
  493.            params[0] = ctx->Texture.Current1D->BorderColor[0] / 255.0f;
  494.            params[1] = ctx->Texture.Current1D->BorderColor[1] / 255.0f;
  495.            params[2] = ctx->Texture.Current1D->BorderColor[2] / 255.0f;
  496.            params[3] = ctx->Texture.Current1D->BorderColor[3] / 255.0f;
  497.            break;
  498.         case GL_TEXTURE_RESIDENT:
  499.            *params = BOOL_TO_FLOAT( GL_TRUE );
  500.            break;
  501.         case GL_TEXTURE_PRIORITY:
  502.            *params = ctx->Texture.Current1D->Priority;
  503.            break;
  504.         default:
  505.            gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
  506.      }
  507.      break;
  508.       case GL_TEXTURE_2D:
  509.      switch (pname) {
  510.         case GL_TEXTURE_MAG_FILTER:
  511.            *params = BOOL_TO_FLOAT( ctx->Texture.Current2D->MagFilter );
  512.            break;
  513.         case GL_TEXTURE_MIN_FILTER:
  514.            *params = BOOL_TO_FLOAT( ctx->Texture.Current2D->MinFilter );
  515.            break;
  516.         case GL_TEXTURE_WRAP_S:
  517.            *params = BOOL_TO_FLOAT( ctx->Texture.Current2D->WrapS );
  518.            break;
  519.         case GL_TEXTURE_WRAP_T:
  520.            *params = BOOL_TO_FLOAT( ctx->Texture.Current2D->WrapT );
  521.            break;
  522.         case GL_TEXTURE_BORDER_COLOR:
  523.            params[0] = ctx->Texture.Current2D->BorderColor[0] / 255.0f;
  524.            params[1] = ctx->Texture.Current2D->BorderColor[1] / 255.0f;
  525.            params[2] = ctx->Texture.Current2D->BorderColor[2] / 255.0f;
  526.            params[3] = ctx->Texture.Current2D->BorderColor[3] / 255.0f;
  527.            break;
  528.         case GL_TEXTURE_RESIDENT:
  529.            *params = BOOL_TO_FLOAT( GL_TRUE );
  530.            break;
  531.         case GL_TEXTURE_PRIORITY:
  532.            *params = ctx->Texture.Current2D->Priority;
  533.            break;
  534.         default:
  535.            gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
  536.      }
  537.      break;
  538.       case GL_TEXTURE_3D_EXT:
  539.      switch (pname) {
  540.         case GL_TEXTURE_MAG_FILTER:
  541.            *params = BOOL_TO_FLOAT( ctx->Texture.Current3D->MagFilter );
  542.            break;
  543.         case GL_TEXTURE_MIN_FILTER:
  544.            *params = BOOL_TO_FLOAT( ctx->Texture.Current3D->MinFilter );
  545.            break;
  546.         case GL_TEXTURE_WRAP_S:
  547.            *params = BOOL_TO_FLOAT( ctx->Texture.Current3D->WrapS );
  548.            break;
  549.         case GL_TEXTURE_WRAP_T:
  550.            *params = BOOL_TO_FLOAT( ctx->Texture.Current3D->WrapT );
  551.            break;
  552.         case GL_TEXTURE_WRAP_R_EXT:
  553.            *params = BOOL_TO_FLOAT( ctx->Texture.Current3D->WrapR );
  554.            break;
  555.         case GL_TEXTURE_BORDER_COLOR:
  556.            params[0] = ctx->Texture.Current3D->BorderColor[0] / 255.0f;
  557.            params[1] = ctx->Texture.Current3D->BorderColor[1] / 255.0f;
  558.            params[2] = ctx->Texture.Current3D->BorderColor[2] / 255.0f;
  559.            params[3] = ctx->Texture.Current3D->BorderColor[3] / 255.0f;
  560.            break;
  561.         case GL_TEXTURE_RESIDENT:
  562.            *params = BOOL_TO_FLOAT( GL_TRUE );
  563.            break;
  564.         case GL_TEXTURE_PRIORITY:
  565.            *params = ctx->Texture.Current3D->Priority;
  566.            break;
  567.         default:
  568.            gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
  569.      }
  570.      break;
  571.       default:
  572.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)" );
  573.    }
  574. }
  575.  
  576.  
  577. void gl_GetTexParameteriv( GLcontext *ctx,
  578.                GLenum target, GLenum pname, GLint *params )
  579. {
  580.    switch (target) {
  581.       case GL_TEXTURE_1D:
  582.      switch (pname) {
  583.         case GL_TEXTURE_MAG_FILTER:
  584.            *params = (GLint) ctx->Texture.Current1D->MagFilter;
  585.            break;
  586.         case GL_TEXTURE_MIN_FILTER:
  587.            *params = (GLint) ctx->Texture.Current1D->MinFilter;
  588.            break;
  589.         case GL_TEXTURE_WRAP_S:
  590.            *params = (GLint) ctx->Texture.Current1D->WrapS;
  591.            break;
  592.         case GL_TEXTURE_WRAP_T:
  593.            *params = (GLint) ctx->Texture.Current1D->WrapT;
  594.            break;
  595.         case GL_TEXTURE_BORDER_COLOR:
  596.            {
  597.           GLfloat color[4];
  598.           color[0] = ctx->Texture.Current1D->BorderColor[0]/255.0;
  599.           color[1] = ctx->Texture.Current1D->BorderColor[1]/255.0;
  600.           color[2] = ctx->Texture.Current1D->BorderColor[2]/255.0;
  601.           color[3] = ctx->Texture.Current1D->BorderColor[3]/255.0;
  602.           params[0] = FLOAT_TO_INT( color[0] );
  603.           params[1] = FLOAT_TO_INT( color[1] );
  604.           params[2] = FLOAT_TO_INT( color[2] );
  605.           params[3] = FLOAT_TO_INT( color[3] );
  606.            }
  607.            break;
  608.         case GL_TEXTURE_RESIDENT:
  609.            *params = (GLint) GL_TRUE;
  610.            break;
  611.         case GL_TEXTURE_PRIORITY:
  612.            *params = (GLint) ctx->Texture.Current1D->Priority;
  613.            break;
  614.         default:
  615.            gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
  616.      }
  617.      break;
  618.       case GL_TEXTURE_2D:
  619.      switch (pname) {
  620.         case GL_TEXTURE_MAG_FILTER:
  621.            *params = (GLint) ctx->Texture.Current2D->MagFilter;
  622.            break;
  623.         case GL_TEXTURE_MIN_FILTER:
  624.            *params = (GLint) ctx->Texture.Current2D->MinFilter;
  625.            break;
  626.         case GL_TEXTURE_WRAP_S:
  627.            *params = (GLint) ctx->Texture.Current2D->WrapS;
  628.            break;
  629.         case GL_TEXTURE_WRAP_T:
  630.            *params = (GLint) ctx->Texture.Current2D->WrapT;
  631.            break;
  632.         case GL_TEXTURE_BORDER_COLOR:
  633.            {
  634.           GLfloat color[4];
  635.           color[0] = ctx->Texture.Current2D->BorderColor[0]/255.0;
  636.           color[1] = ctx->Texture.Current2D->BorderColor[1]/255.0;
  637.           color[2] = ctx->Texture.Current2D->BorderColor[2]/255.0;
  638.           color[3] = ctx->Texture.Current2D->BorderColor[3]/255.0;
  639.           params[0] = FLOAT_TO_INT( color[0] );
  640.           params[1] = FLOAT_TO_INT( color[1] );
  641.           params[2] = FLOAT_TO_INT( color[2] );
  642.           params[3] = FLOAT_TO_INT( color[3] );
  643.            }
  644.            break;
  645.         case GL_TEXTURE_RESIDENT:
  646.            *params = (GLint) GL_TRUE;
  647.            break;
  648.         case GL_TEXTURE_PRIORITY:
  649.            *params = (GLint) ctx->Texture.Current2D->Priority;
  650.            break;
  651.         default:
  652.            gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
  653.      }
  654.      break;
  655.       case GL_TEXTURE_3D_EXT:
  656.      switch (pname) {
  657.         case GL_TEXTURE_MAG_FILTER:
  658.            *params = (GLint) ctx->Texture.Current3D->MagFilter;
  659.            break;
  660.         case GL_TEXTURE_MIN_FILTER:
  661.            *params = (GLint) ctx->Texture.Current3D->MinFilter;
  662.            break;
  663.         case GL_TEXTURE_WRAP_S:
  664.            *params = (GLint) ctx->Texture.Current3D->WrapS;
  665.            break;
  666.         case GL_TEXTURE_WRAP_T:
  667.            *params = (GLint) ctx->Texture.Current3D->WrapT;
  668.            break;
  669.         case GL_TEXTURE_WRAP_R_EXT:
  670.            *params = (GLint) ctx->Texture.Current3D->WrapR;
  671.            break;
  672.         case GL_TEXTURE_BORDER_COLOR:
  673.            {
  674.           GLfloat color[4];
  675.           color[0] = ctx->Texture.Current3D->BorderColor[0]/255.0;
  676.           color[1] = ctx->Texture.Current3D->BorderColor[1]/255.0;
  677.           color[2] = ctx->Texture.Current3D->BorderColor[2]/255.0;
  678.           color[3] = ctx->Texture.Current3D->BorderColor[3]/255.0;
  679.           params[0] = FLOAT_TO_INT( color[0] );
  680.           params[1] = FLOAT_TO_INT( color[1] );
  681.           params[2] = FLOAT_TO_INT( color[2] );
  682.           params[3] = FLOAT_TO_INT( color[3] );
  683.            }
  684.            break;
  685.         case GL_TEXTURE_RESIDENT:
  686.            *params = (GLint) GL_TRUE;
  687.            break;
  688.         case GL_TEXTURE_PRIORITY:
  689.            *params = (GLint) ctx->Texture.Current3D->Priority;
  690.            break;
  691.         default:
  692.            gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
  693.      }
  694.      break;
  695.       default:
  696.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)" );
  697.    }
  698. }
  699.  
  700.  
  701.  
  702.  
  703. /**********************************************************************/
  704. /*                    Texture Coord Generation                        */
  705. /**********************************************************************/
  706.  
  707.  
  708. void gl_TexGenfv( GLcontext *ctx,
  709.           GLenum coord, GLenum pname, const GLfloat *params )
  710. {
  711.    if (INSIDE_BEGIN_END(ctx)) {
  712.       gl_error( ctx, GL_INVALID_OPERATION, "glTexGenfv" );
  713.       return;
  714.    }
  715.  
  716.    switch( coord ) {
  717.       case GL_S:
  718.      if (pname==GL_TEXTURE_GEN_MODE) {
  719.         GLenum mode = (GLenum) (GLint) *params;
  720.         if (mode==GL_OBJECT_LINEAR ||
  721.         mode==GL_EYE_LINEAR ||
  722.         mode==GL_SPHERE_MAP) {
  723.            ctx->Texture.GenModeS = mode;
  724.         }
  725.         else {
  726.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  727.            return;
  728.         }
  729.      }
  730.      else if (pname==GL_OBJECT_PLANE) {
  731.         ctx->Texture.ObjectPlaneS[0] = params[0];
  732.         ctx->Texture.ObjectPlaneS[1] = params[1];
  733.         ctx->Texture.ObjectPlaneS[2] = params[2];
  734.         ctx->Texture.ObjectPlaneS[3] = params[3];
  735.      }
  736.      else if (pname==GL_EYE_PLANE) {
  737.         /* Transform plane equation by the inverse modelview matrix */
  738.         if (ctx->NewModelViewMatrix) {
  739.            gl_analyze_modelview_matrix(ctx);
  740.         }
  741.         gl_transform_vector( ctx->Texture.EyePlaneS, params,
  742.                  ctx->ModelViewInv );
  743.      }
  744.      else {
  745.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  746.         return;
  747.      }
  748.      break;
  749.       case GL_T:
  750.      if (pname==GL_TEXTURE_GEN_MODE) {
  751.         GLenum mode = (GLenum) (GLint) *params;
  752.         if (mode==GL_OBJECT_LINEAR ||
  753.         mode==GL_EYE_LINEAR ||
  754.         mode==GL_SPHERE_MAP) {
  755.            ctx->Texture.GenModeT = mode;
  756.         }
  757.         else {
  758.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  759.            return;
  760.         }
  761.      }
  762.      else if (pname==GL_OBJECT_PLANE) {
  763.         ctx->Texture.ObjectPlaneT[0] = params[0];
  764.         ctx->Texture.ObjectPlaneT[1] = params[1];
  765.         ctx->Texture.ObjectPlaneT[2] = params[2];
  766.         ctx->Texture.ObjectPlaneT[3] = params[3];
  767.      }
  768.      else if (pname==GL_EYE_PLANE) {
  769.         /* Transform plane equation by the inverse modelview matrix */
  770.         if (ctx->NewModelViewMatrix) {
  771.            gl_analyze_modelview_matrix(ctx);
  772.         }
  773.         gl_transform_vector( ctx->Texture.EyePlaneT, params,
  774.                  ctx->ModelViewInv );
  775.      }
  776.      else {
  777.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  778.         return;
  779.      }
  780.      break;
  781.       case GL_R:
  782.      if (pname==GL_TEXTURE_GEN_MODE) {
  783.         GLenum mode = (GLenum) (GLint) *params;
  784.         if (mode==GL_OBJECT_LINEAR ||
  785.         mode==GL_EYE_LINEAR) {
  786.            ctx->Texture.GenModeR = mode;
  787.         }
  788.         else {
  789.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  790.            return;
  791.         }
  792.      }
  793.      else if (pname==GL_OBJECT_PLANE) {
  794.         ctx->Texture.ObjectPlaneR[0] = params[0];
  795.         ctx->Texture.ObjectPlaneR[1] = params[1];
  796.         ctx->Texture.ObjectPlaneR[2] = params[2];
  797.         ctx->Texture.ObjectPlaneR[3] = params[3];
  798.      }
  799.      else if (pname==GL_EYE_PLANE) {
  800.         /* Transform plane equation by the inverse modelview matrix */
  801.         if (ctx->NewModelViewMatrix) {
  802.            gl_analyze_modelview_matrix(ctx);
  803.         }
  804.         gl_transform_vector( ctx->Texture.EyePlaneR, params,
  805.                  ctx->ModelViewInv );
  806.      }
  807.      else {
  808.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  809.         return;
  810.      }
  811.      break;
  812.       case GL_Q:
  813.      if (pname==GL_TEXTURE_GEN_MODE) {
  814.         GLenum mode = (GLenum) (GLint) *params;
  815.         if (mode==GL_OBJECT_LINEAR ||
  816.         mode==GL_EYE_LINEAR) {
  817.            ctx->Texture.GenModeQ = mode;
  818.         }
  819.         else {
  820.            gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
  821.            return;
  822.         }
  823.      }
  824.      else if (pname==GL_OBJECT_PLANE) {
  825.         ctx->Texture.ObjectPlaneQ[0] = params[0];
  826.         ctx->Texture.ObjectPlaneQ[1] = params[1];
  827.         ctx->Texture.ObjectPlaneQ[2] = params[2];
  828.         ctx->Texture.ObjectPlaneQ[3] = params[3];
  829.      }
  830.      else if (pname==GL_EYE_PLANE) {
  831.         /* Transform plane equation by the inverse modelview matrix */
  832.         if (ctx->NewModelViewMatrix) {
  833.            gl_analyze_modelview_matrix(ctx);
  834.         }
  835.         gl_transform_vector( ctx->Texture.EyePlaneQ, params,
  836.                  ctx->ModelViewInv );
  837.      }
  838.      else {
  839.         gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
  840.         return;
  841.      }
  842.      break;
  843.       default:
  844.      gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
  845.      return;
  846.    }
  847.  
  848.    ctx->NewState |= NEW_TEXTURING;
  849.    {
  850.     int i = 0;
  851.     i++;
  852.    }
  853. }
  854.  
  855.  
  856.  
  857. void gl_GetTexGendv( GLcontext *ctx,
  858.              GLenum coord, GLenum pname, GLdouble *params )
  859. {
  860.    if (INSIDE_BEGIN_END(ctx)) {
  861.       gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGendv" );
  862.       return;
  863.    }
  864.  
  865.    switch( coord ) {
  866.       case GL_S:
  867.      if (pname==GL_TEXTURE_GEN_MODE) {
  868.         params[0] = BOOL_TO_DOUBLE(ctx->Texture.GenModeS);
  869.      }
  870.      else if (pname==GL_OBJECT_PLANE) {
  871.         COPY_4V( params, ctx->Texture.ObjectPlaneS );
  872.      }
  873.      else if (pname==GL_EYE_PLANE) {
  874.         COPY_4V( params, ctx->Texture.EyePlaneS );
  875.      }
  876.      else {
  877.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  878.         return;
  879.      }
  880.      break;
  881.       case GL_T:
  882.      if (pname==GL_TEXTURE_GEN_MODE) {
  883.         params[0] = BOOL_TO_DOUBLE(ctx->Texture.GenModeT);
  884.      }
  885.      else if (pname==GL_OBJECT_PLANE) {
  886.         COPY_4V( params, ctx->Texture.ObjectPlaneT );
  887.      }
  888.      else if (pname==GL_EYE_PLANE) {
  889.         COPY_4V( params, ctx->Texture.EyePlaneT );
  890.      }
  891.      else {
  892.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  893.         return;
  894.      }
  895.      break;
  896.       case GL_R:
  897.      if (pname==GL_TEXTURE_GEN_MODE) {
  898.         params[0] = BOOL_TO_DOUBLE(ctx->Texture.GenModeR);
  899.      }
  900.      else if (pname==GL_OBJECT_PLANE) {
  901.         COPY_4V( params, ctx->Texture.ObjectPlaneR );
  902.      }
  903.      else if (pname==GL_EYE_PLANE) {
  904.         COPY_4V( params, ctx->Texture.EyePlaneR );
  905.      }
  906.      else {
  907.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  908.         return;
  909.      }
  910.      break;
  911.       case GL_Q:
  912.      if (pname==GL_TEXTURE_GEN_MODE) {
  913.         params[0] = BOOL_TO_DOUBLE(ctx->Texture.GenModeQ);
  914.      }
  915.      else if (pname==GL_OBJECT_PLANE) {
  916.         COPY_4V( params, ctx->Texture.ObjectPlaneQ );
  917.      }
  918.      else if (pname==GL_EYE_PLANE) {
  919.         COPY_4V( params, ctx->Texture.EyePlaneQ );
  920.      }
  921.      else {
  922.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
  923.         return;
  924.      }
  925.      break;
  926.       default:
  927.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
  928.      return;
  929.    }
  930. }
  931.  
  932.  
  933.  
  934. void gl_GetTexGenfv( GLcontext *ctx,
  935.              GLenum coord, GLenum pname, GLfloat *params )
  936. {
  937.    if (INSIDE_BEGIN_END(ctx)) {
  938.       gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGenfv" );
  939.       return;
  940.    }
  941.  
  942.    switch( coord ) {
  943.       case GL_S:
  944.      if (pname==GL_TEXTURE_GEN_MODE) {
  945.         params[0] = BOOL_TO_FLOAT(ctx->Texture.GenModeS);
  946.      }
  947.      else if (pname==GL_OBJECT_PLANE) {
  948.         COPY_4V( params, ctx->Texture.ObjectPlaneS );
  949.      }
  950.      else if (pname==GL_EYE_PLANE) {
  951.         COPY_4V( params, ctx->Texture.EyePlaneS );
  952.      }
  953.      else {
  954.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  955.         return;
  956.      }
  957.      break;
  958.       case GL_T:
  959.      if (pname==GL_TEXTURE_GEN_MODE) {
  960.         params[0] = BOOL_TO_FLOAT(ctx->Texture.GenModeT);
  961.      }
  962.      else if (pname==GL_OBJECT_PLANE) {
  963.         COPY_4V( params, ctx->Texture.ObjectPlaneT );
  964.      }
  965.      else if (pname==GL_EYE_PLANE) {
  966.         COPY_4V( params, ctx->Texture.EyePlaneT );
  967.      }
  968.      else {
  969.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  970.         return;
  971.      }
  972.      break;
  973.       case GL_R:
  974.      if (pname==GL_TEXTURE_GEN_MODE) {
  975.         params[0] = BOOL_TO_FLOAT(ctx->Texture.GenModeR);
  976.      }
  977.      else if (pname==GL_OBJECT_PLANE) {
  978.         COPY_4V( params, ctx->Texture.ObjectPlaneR );
  979.      }
  980.      else if (pname==GL_EYE_PLANE) {
  981.         COPY_4V( params, ctx->Texture.EyePlaneR );
  982.      }
  983.      else {
  984.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  985.         return;
  986.      }
  987.      break;
  988.       case GL_Q:
  989.      if (pname==GL_TEXTURE_GEN_MODE) {
  990.         params[0] = BOOL_TO_FLOAT(ctx->Texture.GenModeQ);
  991.      }
  992.      else if (pname==GL_OBJECT_PLANE) {
  993.         COPY_4V( params, ctx->Texture.ObjectPlaneQ );
  994.      }
  995.      else if (pname==GL_EYE_PLANE) {
  996.         COPY_4V( params, ctx->Texture.EyePlaneQ );
  997.      }
  998.      else {
  999.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
  1000.         return;
  1001.      }
  1002.      break;
  1003.       default:
  1004.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
  1005.      return;
  1006.    }
  1007. }
  1008.  
  1009.  
  1010.  
  1011. void gl_GetTexGeniv( GLcontext *ctx,
  1012.              GLenum coord, GLenum pname, GLint *params )
  1013. {
  1014.    if (INSIDE_BEGIN_END(ctx)) {
  1015.       gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGeniv" );
  1016.       return;
  1017.    }
  1018.  
  1019.    switch( coord ) {
  1020.       case GL_S:
  1021.      if (pname==GL_TEXTURE_GEN_MODE) {
  1022.         params[0] = ctx->Texture.GenModeS;
  1023.      }
  1024.      else if (pname==GL_OBJECT_PLANE) {
  1025.         COPY_4V( params, ctx->Texture.ObjectPlaneS );
  1026.      }
  1027.      else if (pname==GL_EYE_PLANE) {
  1028.         COPY_4V( params, ctx->Texture.EyePlaneS );
  1029.      }
  1030.      else {
  1031.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1032.         return;
  1033.      }
  1034.      break;
  1035.       case GL_T:
  1036.      if (pname==GL_TEXTURE_GEN_MODE) {
  1037.         params[0] = ctx->Texture.GenModeT;
  1038.      }
  1039.      else if (pname==GL_OBJECT_PLANE) {
  1040.         COPY_4V( params, ctx->Texture.ObjectPlaneT );
  1041.      }
  1042.      else if (pname==GL_EYE_PLANE) {
  1043.         COPY_4V( params, ctx->Texture.EyePlaneT );
  1044.      }
  1045.      else {
  1046.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1047.         return;
  1048.      }
  1049.      break;
  1050.       case GL_R:
  1051.      if (pname==GL_TEXTURE_GEN_MODE) {
  1052.         params[0] = ctx->Texture.GenModeR;
  1053.      }
  1054.      else if (pname==GL_OBJECT_PLANE) {
  1055.         COPY_4V( params, ctx->Texture.ObjectPlaneR );
  1056.      }
  1057.      else if (pname==GL_EYE_PLANE) {
  1058.         COPY_4V( params, ctx->Texture.EyePlaneR );
  1059.      }
  1060.      else {
  1061.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1062.         return;
  1063.      }
  1064.      break;
  1065.       case GL_Q:
  1066.      if (pname==GL_TEXTURE_GEN_MODE) {
  1067.         params[0] = ctx->Texture.GenModeQ;
  1068.      }
  1069.      else if (pname==GL_OBJECT_PLANE) {
  1070.         COPY_4V( params, ctx->Texture.ObjectPlaneQ );
  1071.      }
  1072.      else if (pname==GL_EYE_PLANE) {
  1073.         COPY_4V( params, ctx->Texture.EyePlaneQ );
  1074.      }
  1075.      else {
  1076.         gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
  1077.         return;
  1078.      }
  1079.      break;
  1080.       default:
  1081.      gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
  1082.      return;
  1083.    }
  1084. }
  1085.  
  1086.  
  1087.  
  1088. /*
  1089.  * This is called by gl_update_state() if the NEW_TEXTURING bit in
  1090.  * ctx->NewState is set.
  1091.  */
  1092. void gl_update_texture_state( GLcontext *ctx )
  1093. {
  1094.    struct gl_texture_object *t;
  1095.  
  1096.    if (ctx->Texture.Enabled & TEXTURE_3D)
  1097.       ctx->Texture.Current = ctx->Texture.Current3D;
  1098.    else if (ctx->Texture.Enabled & TEXTURE_2D)
  1099.       ctx->Texture.Current = ctx->Texture.Current2D;
  1100.    else if (ctx->Texture.Enabled & TEXTURE_1D)
  1101.       ctx->Texture.Current = ctx->Texture.Current1D;
  1102.    else
  1103.       ctx->Texture.Current = NULL;
  1104.  
  1105.    for (t = ctx->Shared->TexObjectList; t; t = t->Next) {
  1106.       if (t->Dirty) {
  1107.      gl_test_texture_object_completeness(t);
  1108.      gl_set_texture_sampler(t);
  1109.      t->Dirty = GL_FALSE;
  1110.       }
  1111.    }
  1112. }
  1113.